libnpmexec 8.1.1 → 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/file-exists.js +2 -2
- package/lib/index.js +34 -19
- package/package.json +2 -2
package/lib/file-exists.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { mkdir } = require('fs/promises')
|
|
3
|
+
const { mkdir } = require('node:fs/promises')
|
|
4
4
|
const Arborist = require('@npmcli/arborist')
|
|
5
5
|
const ciInfo = require('ci-info')
|
|
6
|
-
const crypto = require('crypto')
|
|
6
|
+
const crypto = require('node:crypto')
|
|
7
7
|
const { log, input } = require('proc-log')
|
|
8
8
|
const npa = require('npm-package-arg')
|
|
9
9
|
const pacote = require('pacote')
|
|
@@ -14,7 +14,7 @@ const getBinFromManifest = require('./get-bin-from-manifest.js')
|
|
|
14
14
|
const noTTY = require('./no-tty.js')
|
|
15
15
|
const runScript = require('./run-script.js')
|
|
16
16
|
const isWindows = require('./is-windows.js')
|
|
17
|
-
const { dirname, resolve } = require('path')
|
|
17
|
+
const { dirname, resolve } = require('node:path')
|
|
18
18
|
|
|
19
19
|
const binPaths = []
|
|
20
20
|
|
|
@@ -73,6 +73,11 @@ const missingFromTree = async ({ spec, tree, flatOptions, isNpxTree }) => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
// see if the package.json at `path` has an entry that matches `cmd`
|
|
77
|
+
const hasPkgBin = (path, cmd, flatOptions) =>
|
|
78
|
+
pacote.manifest(path, flatOptions)
|
|
79
|
+
.then(manifest => manifest?.bin?.[cmd]).catch(() => null)
|
|
80
|
+
|
|
76
81
|
const exec = async (opts) => {
|
|
77
82
|
const {
|
|
78
83
|
args = [],
|
|
@@ -89,6 +94,13 @@ const exec = async (opts) => {
|
|
|
89
94
|
...flatOptions
|
|
90
95
|
} = opts
|
|
91
96
|
|
|
97
|
+
let pkgPaths = opts.pkgPath
|
|
98
|
+
if (typeof pkgPaths === 'string') {
|
|
99
|
+
pkgPaths = [pkgPaths]
|
|
100
|
+
}
|
|
101
|
+
if (!pkgPaths) {
|
|
102
|
+
pkgPaths = ['.']
|
|
103
|
+
}
|
|
92
104
|
let yes = opts.yes
|
|
93
105
|
const run = () => runScript({
|
|
94
106
|
args,
|
|
@@ -106,28 +118,31 @@ const exec = async (opts) => {
|
|
|
106
118
|
return run()
|
|
107
119
|
}
|
|
108
120
|
|
|
121
|
+
// Look in the local tree too
|
|
122
|
+
pkgPaths.push(path)
|
|
123
|
+
|
|
109
124
|
let needPackageCommandSwap = (args.length > 0) && (packages.length === 0)
|
|
110
125
|
// If they asked for a command w/o specifying a package, see if there is a
|
|
111
126
|
// bin that directly matches that name:
|
|
112
|
-
// - in
|
|
113
|
-
// - in the local tree
|
|
127
|
+
// - in any local packages (pkgPaths can have workspaces in them or just the root)
|
|
128
|
+
// - in the local tree (path)
|
|
114
129
|
// - globally
|
|
115
130
|
if (needPackageCommandSwap) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
131
|
+
// Local packages and local tree
|
|
132
|
+
for (const p of pkgPaths) {
|
|
133
|
+
if (await hasPkgBin(p, args[0], flatOptions)) {
|
|
134
|
+
// we have to install the local package into the npx cache so that its
|
|
135
|
+
// bin links get set up
|
|
136
|
+
flatOptions.installLinks = false
|
|
137
|
+
// args[0] will exist when the package is installed
|
|
138
|
+
packages.push(p)
|
|
139
|
+
yes = true
|
|
140
|
+
needPackageCommandSwap = false
|
|
141
|
+
break
|
|
142
|
+
}
|
|
121
143
|
}
|
|
122
|
-
if (
|
|
123
|
-
//
|
|
124
|
-
// bin links get set up
|
|
125
|
-
flatOptions.installLinks = false
|
|
126
|
-
// args[0] will exist when the package is installed
|
|
127
|
-
packages.push(path)
|
|
128
|
-
yes = true
|
|
129
|
-
needPackageCommandSwap = false
|
|
130
|
-
} else {
|
|
144
|
+
if (needPackageCommandSwap) {
|
|
145
|
+
// no bin entry in local packages or in tree, now we look for binPaths
|
|
131
146
|
const dir = dirname(dirname(localBin))
|
|
132
147
|
const localBinPath = await localFileExists(dir, args[0], '/')
|
|
133
148
|
if (localBinPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libnpmexec",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"bin/",
|
|
6
6
|
"lib/"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"tap": "^16.3.8"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@npmcli/arborist": "^7.5.
|
|
62
|
+
"@npmcli/arborist": "^7.5.3",
|
|
63
63
|
"@npmcli/run-script": "^8.1.0",
|
|
64
64
|
"ci-info": "^4.0.0",
|
|
65
65
|
"npm-package-arg": "^11.0.2",
|