diff options
author | Gar <gar+gh@danger.computer> | 2021-05-06 20:02:16 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-05-06 20:02:42 +0300 |
commit | d01ce5e132cb4661698012fd5017753c2bdb660b (patch) | |
tree | c6dbf5f773720a99067ff2c98d6c309734be3a4e /node_modules | |
parent | 3b84a855dd1ee5d1477e89beb101c69f5e079427 (diff) |
libnpmexec@1.1.0
* feat: add walk up dir lookup to satisfy local bins
Diffstat (limited to 'node_modules')
-rw-r--r-- | node_modules/libnpmexec/CHANGELOG.md | 9 | ||||
-rw-r--r-- | node_modules/libnpmexec/README.md | 2 | ||||
-rw-r--r-- | node_modules/libnpmexec/lib/file-exists.js | 29 | ||||
-rw-r--r-- | node_modules/libnpmexec/lib/index.js | 16 | ||||
-rw-r--r-- | node_modules/libnpmexec/package.json | 7 |
5 files changed, 50 insertions, 13 deletions
diff --git a/node_modules/libnpmexec/CHANGELOG.md b/node_modules/libnpmexec/CHANGELOG.md index fe3ac0def..28cb71028 100644 --- a/node_modules/libnpmexec/CHANGELOG.md +++ b/node_modules/libnpmexec/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## v1.1.0 + +- Add add walk up dir lookup logic to satisfy local bins, +similar to `@npmcli/run-script` + +## v1.0.1 + +- Fix `scriptShell` option name. + ## v1.0.0 - Initial implementation, moves the code that used to live in the **npm cli**, diff --git a/node_modules/libnpmexec/README.md b/node_modules/libnpmexec/README.md index a436c9a5a..fb7a77176 100644 --- a/node_modules/libnpmexec/README.md +++ b/node_modules/libnpmexec/README.md @@ -31,7 +31,7 @@ await libexec({ - `call`: An alternative command to run when using `packages` option **String**, defaults to empty string. - `cache`: The path location to where the npm cache folder is placed **String** - `color`: Output should use color? **Boolean**, defaults to `false` - - `localBin`: Location to the `node_modules/.bin` folder of the local project **String**, defaults to empty string. + - `localBin`: Location to the `node_modules/.bin` folder of the local project to start scanning for bin files **String**, defaults to `./node_modules/.bin`. **libexec** will walk up the directory structure looking for `node_modules/.bin` folders in parent folders that might satisfy the current `arg` and will use that bin if found. - `locationMsg`: Overrides "at location" message when entering interactive mode **String** - `log`: Sets an optional logger **Object**, defaults to `proc-log` module usage. - `globalBin`: Location to the global space bin folder, same as: `$(npm bin -g)` **String**, defaults to empty string. diff --git a/node_modules/libnpmexec/lib/file-exists.js b/node_modules/libnpmexec/lib/file-exists.js new file mode 100644 index 000000000..a115be14b --- /dev/null +++ b/node_modules/libnpmexec/lib/file-exists.js @@ -0,0 +1,29 @@ +const { resolve } = require('path') +const { promisify } = require('util') +const stat = promisify(require('fs').stat) +const walkUp = require('walk-up-path') + +const fileExists = (file) => stat(file) + .then((stat) => stat.isFile()) + .catch(() => false) + +const localFileExists = async (dir, binName, root = '/') => { + root = resolve(root).toLowerCase() + + for (const path of walkUp(resolve(dir))) { + const binDir = resolve(path, 'node_modules', '.bin') + + if (await fileExists(resolve(binDir, binName))) + return binDir + + if (path.toLowerCase() === root) + return false + } + + return false +} + +module.exports = { + fileExists, + localFileExists, +} diff --git a/node_modules/libnpmexec/lib/index.js b/node_modules/libnpmexec/lib/index.js index 906a0b540..0bab753f9 100644 --- a/node_modules/libnpmexec/lib/index.js +++ b/node_modules/libnpmexec/lib/index.js @@ -1,7 +1,6 @@ -const { delimiter, resolve } = require('path') +const { delimiter, dirname, resolve } = require('path') const { promisify } = require('util') const read = promisify(require('read')) -const stat = promisify(require('fs').stat) const Arborist = require('@npmcli/arborist') const ciDetect = require('@npmcli/ci-detect') @@ -12,15 +11,12 @@ const pacote = require('pacote') const readPackageJson = require('read-package-json-fast') const cacheInstallDir = require('./cache-install-dir.js') +const { fileExists, localFileExists } = require('./file-exists.js') const getBinFromManifest = require('./get-bin-from-manifest.js') const manifestMissing = require('./manifest-missing.js') const noTTY = require('./no-tty.js') const runScript = require('./run-script.js') -const fileExists = (file) => stat(file) - .then((stat) => stat.isFile()) - .catch(() => false) - /* istanbul ignore next */ const PATH = ( process.env.PATH || process.env.Path || process.env.path @@ -31,7 +27,7 @@ const exec = async (opts) => { args = [], call = '', color = false, - localBin = '', + localBin = resolve('./node_modules/.bin'), locationMsg = undefined, globalBin = '', output, @@ -72,8 +68,10 @@ const exec = async (opts) => { // the behavior of treating the single argument as a package name if (needPackageCommandSwap) { let binExists = false - if (await fileExists(`${localBin}/${args[0]}`)) { - pathArr.unshift(localBin) + const dir = dirname(dirname(localBin)) + const localBinPath = await localFileExists(dir, args[0]) + if (localBinPath) { + pathArr.unshift(localBinPath) binExists = true } else if (await fileExists(`${globalBin}/${args[0]}`)) { pathArr.unshift(globalBin) diff --git a/node_modules/libnpmexec/package.json b/node_modules/libnpmexec/package.json index 1b7d24103..bc5c0483a 100644 --- a/node_modules/libnpmexec/package.json +++ b/node_modules/libnpmexec/package.json @@ -1,6 +1,6 @@ { "name": "libnpmexec", - "version": "1.0.1", + "version": "1.1.0", "files": [ "lib" ], @@ -46,7 +46,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "eslint-plugin-standard": "^5.0.0", - "tap": "^15.0.2" + "tap": "^15.0.6" }, "dependencies": { "@npmcli/arborist": "^2.3.0", @@ -58,6 +58,7 @@ "pacote": "^11.3.1", "proc-log": "^1.0.0", "read": "^1.0.7", - "read-package-json-fast": "^2.0.2" + "read-package-json-fast": "^2.0.2", + "walk-up-path": "^1.0.0" } } |