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.

future

  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.

example
  Proper Use of the Module Loader
  // Ideally this is the first thing that gets called by your application; however, // the module loader can be created and destroyed at any point by your application.

  // 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");

### Hierarchy

- PluginRequireProvider

## Index

### Constructors

- constructor

### Properties

- modules
- origRequire
- regex
- mInstance

### Methods

- createPluginHooks
- destroyPluginHooks
- sanitizeExpression

## Constructors

### Private constructor

- new PluginRequireProvider(modules: string[]): PluginRequireProvider

- - Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:122

  Construct the class and create hooks into require.

  #### Parameters

  - ##### modules: string[]

    The modules that should be injected from the runtime instance

  #### Returns PluginRequireProvider

## Properties

### Private Readonly modules

modules: string[]

- Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:128

The modules that should be injected from the runtime instance

### Private origRequire

origRequire: typeof require

- Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:115

Reference to the original require function.

### Private Readonly regex

regex: RegExp

- Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:122

Reference to the regular expression used to match modules.

This property was added to make testing easier.

### Static Private mInstance

mInstance: PluginRequireProvider

- Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:95

Reference to the static singleton instance.

## Methods

### Static createPluginHooks

- createPluginHooks(modules: string[]): void

- - Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:67

  Create hooks for the specified modules to be injected at runtime.

  throws

    {PluginRequireAlreadyCreatedError} when hooks have already been added.

  #### Parameters

  - ##### modules: string[]

    An array of modules to inject from the host application.

  #### Returns void

### Static destroyPluginHooks

- destroyPluginHooks(): void

- - Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:81

  Restore the default node require hook.

  throws

    {PluginRequireNotCreatedError} when hooks haven't been added.

  #### Returns void

### Static Private sanitizeExpression

- sanitizeExpression(module: string): any

- - Defined in @zowe/imperative/src/imperative/src/plugins/PluginRequireProvider.ts:102

  This regular expression is used by the module loader to escape any valid characters that might be present in provided modules.

  #### Parameters

  - ##### module: string

  #### Returns any

Generated using TypeDoc