Skip to content

Commit ea44995

Browse files
wraithgarnlf
authored andcommitted
fix: properly find locally/globally/npxCache packages
Lots of bugfixes here, we properly parse ranges and versions, and we also now work with git repos and gists, and know when they are already installed.
1 parent d0be9a2 commit ea44995

File tree

11 files changed

+480
-155
lines changed

11 files changed

+480
-155
lines changed

docs/content/commands/npm-exec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ $ npm exec -- foo@latest bar --package=@npmcli/foo
127127
* Default:
128128
* Type: String (can be set multiple times)
129129

130-
The package to install for [`npm exec`](/commands/npm-exec)
130+
The package or packages to install for [`npm exec`](/commands/npm-exec)
131131

132132
<!-- automatically generated, do not edit manually -->
133133
<!-- see lib/utils/config/definitions.js -->

docs/content/using-npm/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ Directory in which `npm pack` will save tarballs.
12441244
* Default:
12451245
* Type: String (can be set multiple times)
12461246

1247-
The package to install for [`npm exec`](/commands/npm-exec)
1247+
The package or packages to install for [`npm exec`](/commands/npm-exec)
12481248

12491249
<!-- automatically generated, do not edit manually -->
12501250
<!-- see lib/utils/config/definitions.js -->

lib/commands/exec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ class Exec extends BaseCommand {
4949
static isShellout = true
5050

5151
async exec (_args, { locationMsg, runPath } = {}) {
52+
// This is where libnpmexec will look for locally installed packages
5253
const path = this.npm.localPrefix
5354

55+
// This is where libnpmexec will actually run the scripts from
5456
if (!runPath) {
5557
runPath = process.cwd()
5658
}

lib/utils/config/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ define('package', {
14701470
hint: '<package-spec>',
14711471
type: [String, Array],
14721472
description: `
1473-
The package to install for [\`npm exec\`](/commands/npm-exec)
1473+
The package or packages to install for [\`npm exec\`](/commands/npm-exec)
14741474
`,
14751475
flatten,
14761476
})

tap-snapshots/test/lib/utils/config/definitions.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ exports[`test/lib/utils/config/definitions.js TAP > config description for packa
13161316
* Default:
13171317
* Type: String (can be set multiple times)
13181318
1319-
The package to install for [\`npm exec\`](/commands/npm-exec)
1319+
The package or packages to install for [\`npm exec\`](/commands/npm-exec)
13201320
`
13211321

13221322
exports[`test/lib/utils/config/definitions.js TAP > config description for package-lock 1`] = `

workspaces/libnpmexec/lib/cache-install-dir.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

workspaces/libnpmexec/lib/file-exists.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
const { resolve } = require('path')
2-
const { promisify } = require('util')
3-
const stat = promisify(require('fs').stat)
2+
const fs = require('@npmcli/fs')
43
const walkUp = require('walk-up-path')
54

6-
const fileExists = (file) => stat(file)
7-
.then((res) => res.isFile())
8-
.catch(() => false)
9-
10-
const localFileExists = async (dir, binName, root = '/') => {
11-
root = resolve(root).toLowerCase()
5+
const fileExists = async (file) => {
6+
try {
7+
const res = await fs.stat(file)
8+
return res.isFile()
9+
} catch {
10+
return false
11+
}
12+
}
1213

13-
for (const path of walkUp(resolve(dir))) {
14+
const localFileExists = async (dir, binName, root) => {
15+
for (const path of walkUp(dir)) {
1416
const binDir = resolve(path, 'node_modules', '.bin')
1517

1618
if (await fileExists(resolve(binDir, binName))) {
1719
return binDir
1820
}
1921

20-
if (path.toLowerCase() === root) {
22+
if (path.toLowerCase() === resolve(root).toLowerCase()) {
2123
return false
2224
}
2325
}

0 commit comments

Comments
 (0)