-
Notifications
You must be signed in to change notification settings - Fork 10
Loader class
The loader class which is responsible for importing the functions from other languages with all the internal logic to handle that, split into their own separate member functions making it easy to swap implementations using inheritance.
-
name
: Name of the loader. -
config
: The configuration for the loader.-
extension
: The file extension for the source file you want to create the loader for. (Use vertical bar|
to add multiple extensions for the same loader i.e.so|dylib|dll
). -
buildCommand(importPath: string, outDir: string)
: A lambda function that returns an array of default commands that tells hyperimport to execute them to build the source file (Can be overridden by the user per file import). The arguments help in getting reference inside the commands array.-
importPath
: The path of the source file being imported. -
outDir
: The value of theoutDir
defined below.
-
-
outDir(importPath: string)
: A lambda function that returns the path of the output directory where the compiled library will be created.
-
The name of the loader.
All member functions are asynchronous.
Builds the source file imported by the user into a shared library which will be dlopen
ed using the FFI API.
Runs at the beginning of initConfig()
and asks for the build command and output directory from the user. The default values are used if the user presses enter for both of them without providing any value. The output directory is then created.
Generates config.ts for the imported source file and using the unix command nm
, the exported symbols are extracted from the shared library and added to the config with an empty argument list and void return type by default.
Invokes initConfigPre()
to ask for the build command and output directory for the source file, then invokes build()
to build the source file using the provided build command or the default command and then invokes initConfigTypes()
to generate config.ts and types.d.ts to add type definitions for the imported source file.
Checks when the source file was modified and compares it against the lastModified
saved in the config directory. If it's different, the source file was hence changed, so build()
is invoked to recompile the shared library with the new changes.
Imports the symbols for the source file defined in config.ts. If it's not found, it means the source file isn't configured yet and hence invokes initConfig()
to create the configuration for the source file.
Runs just before the shared library is dlopen
ed using FFI API.
Returns a BunPlugin instance which is going to be consumed by Bun.plugin
when hyperimport loads it.