Skip to content

fiverr/dont_look_up_package

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

don't look up

NPM

Stop requirejs from traversing at a certain point

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', () => { ... });
});

Example

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