Debian Codegraph @

lib/require-first-in-tree.js

raw
1 "use strict";
2
3 var path = require("path")
4 , isModuleNotFoundError = require("ncjsm/is-module-not-found-error");
5
6 var dirname = path.dirname, sep = path.sep;
7
8 module.exports = function (modulePath, currentPath, topPath) {
9 while (currentPath !== topPath) {
10 var currentModulePath = currentPath + sep + modulePath;
11 try {
12 return require(currentModulePath);
13 } catch (error) {
14 if (!isModuleNotFoundError(error, currentModulePath)) throw error;
15 }
16 currentPath = dirname(currentPath);
17 }
18 return null;
19 };