override-require

1.1.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i override-require

Weekly Downloads

545,775

Version

1.1.1

License

BSD-3-Clause

Last publish

Collaborators

  • gajus