load-from-cwd-or-npm
Advanced tools
Comparing version 2.2.0 to 2.2.1
46
index.js
@@ -14,6 +14,28 @@ /*! | ||
const MODULE_ID_ERROR = 'Expected a string of npm package name, for example `glob`, `graceful-fs`'; | ||
const resolveSemverFromNpm = resolveFromNpm('semver'); | ||
const MODULE_ID_ERROR = 'Expected a string of npm package name, for example `glob`, `graceful-fs`'; | ||
function createModuleNotFoundRejection(moduleId, cwd, npmCliDirPath) { | ||
const error = new Error(`Failed to load "${ | ||
moduleId | ||
}" module from the current working directory (${ | ||
cwd | ||
}).${npmCliDirPath ? ` Then tried to load "${ | ||
moduleId | ||
}" from the npm CLI directory (${ | ||
npmCliDirPath | ||
}), but it also failed.` : ''} Install "${moduleId}" and try again. (\`npm install ${moduleId}\`)`); | ||
error.code = 'MODULE_NOT_FOUND'; | ||
error.id = moduleId; | ||
error.triedPaths = {cwd}; | ||
if (npmCliDirPath) { | ||
error.triedPaths.npm = npmCliDirPath; | ||
error.npmVersion = require(path.join(npmCliDirPath, './package.json')).version; | ||
} | ||
return Promise.reject(error); | ||
} | ||
module.exports = function loadFromCwdOrNpm(moduleId, compareFn) { | ||
@@ -76,21 +98,5 @@ if (typeof moduleId !== 'string') { | ||
return npmCliDir().then(npmCliDirPath => { | ||
const err = new Error(`Failed to load "${ | ||
moduleId | ||
}" module from the current working directory (${ | ||
cwd | ||
}). Then tried to load "${ | ||
moduleId | ||
}" from the npm CLI directory (${ | ||
npmCliDirPath | ||
}), but it also failed. Install "${moduleId}" and try again. (\`npm install ${moduleId}\`)`); | ||
err.code = 'MODULE_NOT_FOUND'; | ||
err.id = moduleId; | ||
err.triedPaths = { | ||
cwd, | ||
npm: npmCliDirPath | ||
}; | ||
err.npmVersion = require(path.join(npmCliDirPath, './package.json')).version; | ||
return Promise.reject(err); | ||
return createModuleNotFoundRejection(moduleId, cwd, npmCliDirPath); | ||
}, () => { | ||
return createModuleNotFoundRejection(moduleId, cwd, null); | ||
}); | ||
@@ -97,0 +103,0 @@ } |
{ | ||
"name": "load-from-cwd-or-npm", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Load a module from either CWD or npm CLI directory", | ||
@@ -32,3 +32,3 @@ "repository": "shinnn/load-from-cwd-or-npm", | ||
"dependencies": { | ||
"inspect-with-kind": "^1.0.1", | ||
"inspect-with-kind": "^1.0.2", | ||
"npm-cli-dir": "^2.0.1", | ||
@@ -39,6 +39,8 @@ "optional": "^0.1.3", | ||
"devDependencies": { | ||
"@shinnn/eslint-config-node": "^3.0.0", | ||
"eslint": "^3.19.0", | ||
"@shinnn/eslint-config-node": "^4.0.0", | ||
"clear-module": "^2.1.0", | ||
"eslint": "^4.1.1", | ||
"nyc": "^11.0.2", | ||
"osenv": "0.0.2", | ||
"path-key": "^2.0.1", | ||
"request": "*", | ||
@@ -45,0 +47,0 @@ "semver": "^5.3.0", |
9277
83
11
Updatedinspect-with-kind@^1.0.2