Whatever you do β don't look up
Stop requirejs' search path from looking higher than a given directory. This behaviour is should prevent your application from finding modules installed globally, or on a higher level directory, like in a mono-repo containing many packages.
describe('my-tests', () => {
require('dont-look-up')(__dirname);
it('Should only traverse up to current root directory', () => { ... });
});
Consider the following tree
βββ repository
Β Β βββ package
Β Β βΒ Β βββ index.js
Β Β βΒ Β βββ package.json
Β Β βΒ Β βββ node_modules
Β Β βΒ Β βββ child-level-module
Β Β βββ index.js
Β Β βββ package.json
Β Β βββ node_modules
Β Β βββ parent-level-module
package/index.js |
---|
require('parent-level-module'); // works
require('child-level-module'); // works
With "don't look up"
require('dont-look-up')(__dirname);
require('parent-level-module'); // throws error
require('child-level-module'); // works