UNPKG

675 BJavaScriptView Raw
1"use strict";
2
3const existsSync = require('fs').existsSync;
4const 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
13const search_paths = module.paths || [];
14
15search_paths.unshift(path.join(process.cwd(), 'node_modules'));
16
17module.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};