diff --git a/node_modules/libnpmexec/CHANGELOG.md b/node_modules/libnpmexec/CHANGELOG.md index fe3ac0def623d..28cb71028868e 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 a436c9a5a2bc1..fb7a771760019 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 0000000000000..a115be14b0042 --- /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 906a0b5407c13..0bab753f9fda1 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 1b7d24103be7a..bc5c0483a7de7 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" } } diff --git a/package-lock.json b/package-lock.json index 80c129863d4c1..497fa50ad77c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -103,7 +103,7 @@ "leven": "^3.1.0", "libnpmaccess": "^4.0.2", "libnpmdiff": "^2.0.4", - "libnpmexec": "^1.0.1", + "libnpmexec": "^1.1.0", "libnpmfund": "^1.0.2", "libnpmhook": "^6.0.2", "libnpmorg": "^2.0.2", @@ -4626,9 +4626,9 @@ } }, "node_modules/libnpmexec": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/libnpmexec/-/libnpmexec-1.0.1.tgz", - "integrity": "sha512-YK2kEhZNCcaDEqOIUWjadhJl9MgS69YHgMmGD5P3yntF0UXNOQfEqABoMTZv9ngPOJTJQGlU4Dfp2xb3bpUKzw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/libnpmexec/-/libnpmexec-1.1.0.tgz", + "integrity": "sha512-OWpsPWtD6CAn66JouyjBfhQ9eS1mAtXgZXXd1SoAyUP3Mol+ao9IJ2THcJQcgX96keVmZkUA11uJS5ZNEd9DwA==", "inBundle": true, "dependencies": { "@npmcli/arborist": "^2.3.0", @@ -4640,7 +4640,8 @@ "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" }, "engines": { "node": ">=10" @@ -13693,9 +13694,9 @@ } }, "libnpmexec": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/libnpmexec/-/libnpmexec-1.0.1.tgz", - "integrity": "sha512-YK2kEhZNCcaDEqOIUWjadhJl9MgS69YHgMmGD5P3yntF0UXNOQfEqABoMTZv9ngPOJTJQGlU4Dfp2xb3bpUKzw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/libnpmexec/-/libnpmexec-1.1.0.tgz", + "integrity": "sha512-OWpsPWtD6CAn66JouyjBfhQ9eS1mAtXgZXXd1SoAyUP3Mol+ao9IJ2THcJQcgX96keVmZkUA11uJS5ZNEd9DwA==", "requires": { "@npmcli/arborist": "^2.3.0", "@npmcli/ci-detect": "^1.3.0", @@ -13706,7 +13707,8 @@ "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" } }, "libnpmfund": { diff --git a/package.json b/package.json index 79fc7056892c4..3839d3b30142b 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "leven": "^3.1.0", "libnpmaccess": "^4.0.2", "libnpmdiff": "^2.0.4", - "libnpmexec": "^1.0.1", + "libnpmexec": "^1.1.0", "libnpmfund": "^1.0.2", "libnpmhook": "^6.0.2", "libnpmorg": "^2.0.2",