Overrides Node.js module resolution logic.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.scripts
declarations
src
test
.babelrc
.conventional-changelog-lintrc
.eslintrc
.flowconfig
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
package.json

README.md

override-require

Travis build status Coveralls NPM version Canonical Code Style

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