load-from-cwd-or-npm
Advanced tools
Comparing version 3.0.1 to 3.0.4
24
index.js
'use strict'; | ||
const {dirname, isAbsolute, join} = require('path'); | ||
const {dirname, join} = require('path'); | ||
@@ -36,12 +36,2 @@ const inspectWithKind = require('inspect-with-kind'); | ||
if (isAbsolute(moduleId)) { | ||
const error = new Error(`${MODULE_ID_ERROR}, but got an absolute path '${ | ||
moduleId | ||
}'. For absolute paths there is no need to use \`load-from-cwd-or-npm\` in favor of Node.js built-in \`require.resolve()\`.`); | ||
error.code = 'ERR_ABSOLUTE_MODULE_ID'; | ||
throw error; | ||
} | ||
const cwd = process.cwd(); | ||
@@ -57,2 +47,4 @@ const modulePkgId = `${moduleId}/package.json`; | ||
} | ||
console.error('The second parameter of `load-from-cwd-or-npm` is deprecated and will be removed in the next major version.'); | ||
} else { | ||
@@ -78,2 +70,10 @@ tasks.push(resolveSemverFromNpm); | ||
} catch (err) { | ||
if (err.code === 'ERR_ABSOLUTE_MODULE_ID') { | ||
err.message = `${MODULE_ID_ERROR}, but got an absolute path '${ | ||
moduleId | ||
}'. For absolute paths there is no need to use \`load-from-cwd-or-npm\` in favor of Node.js built-in \`require.resolve()\`.`; | ||
throw err; | ||
} | ||
const modileFromCwd = optional(moduleId); | ||
@@ -86,3 +86,3 @@ | ||
npmCliDirPath = await npmCliDir(); | ||
} catch (npmCliDirErr) {} | ||
} catch (errUnused) {} // eslint-disable-line no-unused-vars | ||
@@ -89,0 +89,0 @@ const error = new Error(`Failed to load "${ |
{ | ||
"name": "load-from-cwd-or-npm", | ||
"version": "3.0.1", | ||
"version": "3.0.4", | ||
"description": "Load a module from either CWD or npm CLI directory", | ||
"repository": "shinnn/load-from-cwd-or-npm", | ||
"author": "Shinnosuke Watanabe (https://github.com/shinnn)", | ||
"license": "ISC", | ||
"scripts": { | ||
"pretest": "eslint .", | ||
"test": "nyc --reporter=html --reporter=text node test.js" | ||
"test": "nyc node test.js" | ||
}, | ||
"license": "ISC", | ||
"files": [ | ||
@@ -32,4 +32,4 @@ "index.js" | ||
"dependencies": { | ||
"inspect-with-kind": "^1.0.4", | ||
"npm-cli-dir": "^3.0.0", | ||
"inspect-with-kind": "^1.0.5", | ||
"npm-cli-dir": "^3.0.1", | ||
"optional": "^0.1.4", | ||
@@ -39,17 +39,22 @@ "resolve-from-npm": "^3.1.0" | ||
"devDependencies": { | ||
"@shinnn/eslint-config-node": "^6.0.0", | ||
"clear-module": "^2.1.0", | ||
"eslint": "^5.1.0", | ||
"lodash": "^4.17.10", | ||
"nyc": "^12.0.2", | ||
"@babel/code-frame": "^7.0.0", | ||
"@shinnn/eslint-config": "^6.10.4", | ||
"clear-module": "^3.2.0", | ||
"eslint": "^5.16.0", | ||
"lodash": "^4.17.11", | ||
"nyc": "^14.1.1", | ||
"nyc-config-common": "^1.0.1", | ||
"osenv": "0.0.2", | ||
"path-key": "^2.0.1", | ||
"output-file": "^2.0.2", | ||
"path-key": "^3.1.0", | ||
"request": "*", | ||
"semver": "^5.5.0", | ||
"tape": "^4.9.1", | ||
"write-json-file": "^2.3.0" | ||
"semver": "^6.2.0", | ||
"tape": "^4.11.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@shinnn/node" | ||
"extends": "@shinnn" | ||
}, | ||
"nyc": { | ||
"extends": "nyc-config-common" | ||
} | ||
} |
# load-from-cwd-or-npm | ||
[![npm version](https://img.shields.io/npm/v/load-from-cwd-or-npm.svg)](https://www.npmjs.com/package/load-from-cwd-or-npm) | ||
[![Build Status](https://travis-ci.org/shinnn/load-from-cwd-or-npm.svg?branch=master)](https://travis-ci.org/shinnn/load-from-cwd-or-npm) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/fgiptpa87nh51g0v/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/load-from-cwd-or-npm/branch/master) | ||
[![Build Status](https://travis-ci.com/shinnn/load-from-cwd-or-npm.svg?branch=master)](https://travis-ci.com/shinnn/load-from-cwd-or-npm) | ||
[![Coverage Status](https://img.shields.io/coveralls/shinnn/load-from-cwd-or-npm.svg)](https://coveralls.io/github/shinnn/load-from-cwd-or-npm?branch=master) | ||
Load a module from either CWD or [`npm` CLI](https://github.com/npm/npm) directory | ||
Load a module from either CWD or [`npm` CLI](https://github.com/npm/cli) directory | ||
@@ -24,3 +23,3 @@ ```javascript | ||
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm). | ||
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/). | ||
@@ -37,6 +36,5 @@ ``` | ||
### loadFromCwdOrNpm(*moduleId*, [*compareFn*]) | ||
### loadFromCwdOrNpm(*moduleId*) | ||
*moduleId*: `string` (a module ID without path separators (`/`, `\\`)) | ||
*compareFn*: `Function` (a function to compare two package versions) | ||
Return: `Promise<any>` | ||
@@ -86,20 +84,4 @@ | ||
#### compareFn(*cwdPackageVersion*, *npmPackageVersion*) | ||
Default: [node-semver](https://github.com/npm/node-semver)'s [`gte`](https://github.com/npm/node-semver#comparison) method | ||
Used as a comparison function when a module with the given ID exists in both directories. | ||
It takes two `string` arguments, package versions of the CWD one and the npm dependency one. the former will be loaded when `compareFn` returns `true`, otherwise the latter will be loaded. | ||
```javascript | ||
const loadFromCwdOrNpm = require('load-from-cwd-or-npm'); | ||
const semver = require('semver'); | ||
loadFromCwdOrNpm('rimraf', semver.lt); | ||
// inverse to the default behavior (the older will be loaded) | ||
``` | ||
## License | ||
[ISC License](./LICENSE) © 2017 - 2018 Shinnosuke Watanabe |
7937
13
85
Updatedinspect-with-kind@^1.0.5
Updatednpm-cli-dir@^3.0.1