Overrides Node.js module resolution logic.
JavaScript Shell
Latest commit ac99e38 Nov 11, 2016 continuous-deployment chore: release 1.1.1

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