override-require
v1.1.1
Published
Overrides Node.js module resolution logic.
Downloads
2,161,742
Readme
override-require
Overrides Node.js module resolution logic.
Usage
import overrideRequire from 'override-require';
// Setup a callback used to determine whether a specific `require` invocation
// needs to be overridden.
const isOverride = (request: string, parent: Object): boolean => {};
// Setup a callback used to handle an overridden `require` invocation.
const resolveRequest = (request: string, parent: Object): any => {};
const restoreOriginalModuleLoader = overrideRequire(isOverride, resolveRequest);
// Restore the original module loader.
restoreOriginalModuleLoader();
Example
import overrideRequire from 'override-require';
const isOverride = (request) => {
return request === 'vm';
};
const resolveRequest = (request) => {
return 'test';
};
const restoreOriginalModuleLoader = restoreOriginalRequire(isOverride, resolveRequest);
require('vm');
// string 'test'
require('events');
// class EventEmitter
restoreOriginalModuleLoader();
require('vm');
// object vm