Construct the class and create hooks into require.
The modules that should be injected from the runtime instance
The modules that should be injected from the runtime instance
Reference to the original require function.
Reference to the regular expression used to match modules.
This property was added to make testing easier.
Reference to the static singleton instance.
Create hooks for the specified modules to be injected at runtime.
An array of modules to inject from the host application.
Restore the default node require hook.
This regular expression is used by the module loader to escape any valid characters that might be present in provided modules.
Generated using TypeDoc
This class will allow imperative to intercept calls by plugins so that it can provide them with the runtime instance of imperative / base cli when necessary.
Currently this loader is only available from Imperative's internals but work could be done to make this a true standalone package that either Imperative depends on or ships as a separate folder under packages.
// Initializing the loader PluginRequireProvider.createPluginHooks(["module-a", "module-b"]);
// Now in all places of the application, module-a and module-b will be loaded // from the package location of require.main (I.E the Host Package). This // is useful when the Host Package has some sort of plugin infrastructure that // might require modules to be injected to the plugins.
// So this will always be the Host Package module regardless of where it was // called from. require("module-a");
// But this will act as normal require("module-c");
// It is not necessary to cleanup the module loader before exiting. Your // application lifecycle may require it to be brought up and down during the // course of execution. With this in mind, a method has been provided to remove // the hooks created by
createPluginHooks
.// Calling this PluginRequirePriovider.destroyPluginHooks();
// Will now cause this to act as normal regardless of how it would have been // injected before. require("module-b");