1 | ;
|
2 |
|
3 | const existsSync = require('fs').existsSync;
|
4 | const path = require('path');
|
5 |
|
6 | /**
|
7 | * differs from require.resolve as
|
8 | * this will never check against a revision
|
9 | * this will return the package.json folder, not the package entry point
|
10 | */
|
11 |
|
12 | /*istanbul ignore next */ //coverage unreachable but when browserified
|
13 | const search_paths = module.paths || [];
|
14 |
|
15 | search_paths.unshift(path.join(process.cwd(), 'node_modules'));
|
16 |
|
17 | module.exports = function(module_name) {
|
18 | for(var i = 0; i < search_paths.length; i++) {
|
19 | if(existsSync(path.join(search_paths[i], module_name, "package.json")))
|
20 | return path.join(search_paths[i], module_name);
|
21 | }
|
22 | throw "nope";
|
23 | };
|