diff options
Diffstat (limited to 'node_modules/resolve-from/index.js')
-rw-r--r-- | node_modules/resolve-from/index.js | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/node_modules/resolve-from/index.js b/node_modules/resolve-from/index.js index 434159f17..0dbf11708 100644 --- a/node_modules/resolve-from/index.js +++ b/node_modules/resolve-from/index.js @@ -1,23 +1,35 @@ 'use strict'; -var path = require('path'); -var Module = require('module'); +const path = require('path'); +const Module = require('module'); -module.exports = function (fromDir, moduleId) { - if (typeof fromDir !== 'string' || typeof moduleId !== 'string') { - throw new TypeError('Expected `fromDir` and `moduleId` to be a string'); +const resolveFrom = (fromDir, moduleId, silent) => { + if (typeof fromDir !== 'string') { + throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``); + } + + if (typeof moduleId !== 'string') { + throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``); } fromDir = path.resolve(fromDir); + const fromFile = path.join(fromDir, 'noop.js'); - var fromFile = path.join(fromDir, 'noop.js'); + const resolveFileName = () => Module._resolveFilename(moduleId, { + id: fromFile, + filename: fromFile, + paths: Module._nodeModulePaths(fromDir) + }); - try { - return Module._resolveFilename(moduleId, { - id: fromFile, - filename: fromFile, - paths: Module._nodeModulePaths(fromDir) - }); - } catch (err) { - return null; + if (silent) { + try { + return resolveFileName(); + } catch (err) { + return null; + } } + + return resolveFileName(); }; + +module.exports = (fromDir, moduleId) => resolveFrom(fromDir, moduleId); +module.exports.silent = (fromDir, moduleId) => resolveFrom(fromDir, moduleId, true); |