libnpmexec 3.0.1 → 4.0.0
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/README.md +0 -1
- package/lib/cache-install-dir.js +2 -1
- package/lib/file-exists.js +4 -2
- package/lib/get-bin-from-manifest.js +4 -2
- package/lib/index.js +13 -10
- package/lib/manifest-missing.js +4 -2
- package/lib/run-script.js +6 -6
- package/package.json +23 -19
package/README.md
CHANGED
|
@@ -35,7 +35,6 @@ await libexec({
|
|
|
35
35
|
- `color`: Output should use color? **Boolean**, defaults to `false`
|
|
36
36
|
- `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.
|
|
37
37
|
- `locationMsg`: Overrides "at location" message when entering interactive mode **String**
|
|
38
|
-
- `log`: Sets an optional logger **Object**, defaults to `proc-log` module usage.
|
|
39
38
|
- `globalBin`: Location to the global space bin folder, same as: `$(npm bin -g)` **String**, defaults to empty string.
|
|
40
39
|
- `output`: A function to print output to **Function**
|
|
41
40
|
- `packages`: A list of packages to be used (possibly fetch from the registry) **Array<String>**, defaults to `[]`
|
package/lib/cache-install-dir.js
CHANGED
|
@@ -3,8 +3,9 @@ const crypto = require('crypto')
|
|
|
3
3
|
const { resolve } = require('path')
|
|
4
4
|
|
|
5
5
|
const cacheInstallDir = ({ npxCache, packages }) => {
|
|
6
|
-
if (!npxCache)
|
|
6
|
+
if (!npxCache) {
|
|
7
7
|
throw new Error('Must provide a valid npxCache path')
|
|
8
|
+
}
|
|
8
9
|
|
|
9
10
|
// only packages not found in ${prefix}/node_modules
|
|
10
11
|
return resolve(npxCache, getHash(packages))
|
package/lib/file-exists.js
CHANGED
|
@@ -13,11 +13,13 @@ const localFileExists = async (dir, binName, root = '/') => {
|
|
|
13
13
|
for (const path of walkUp(resolve(dir))) {
|
|
14
14
|
const binDir = resolve(path, 'node_modules', '.bin')
|
|
15
15
|
|
|
16
|
-
if (await fileExists(resolve(binDir, binName)))
|
|
16
|
+
if (await fileExists(resolve(binDir, binName))) {
|
|
17
17
|
return binDir
|
|
18
|
+
}
|
|
18
19
|
|
|
19
|
-
if (path.toLowerCase() === root)
|
|
20
|
+
if (path.toLowerCase() === root) {
|
|
20
21
|
return false
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
return false
|
|
@@ -3,13 +3,15 @@ const getBinFromManifest = (mani) => {
|
|
|
3
3
|
// otherwise if there's 1 bin or all bin value is the same (alias), use
|
|
4
4
|
// that, otherwise fail
|
|
5
5
|
const bin = mani.bin || {}
|
|
6
|
-
if (new Set(Object.values(bin)).size === 1)
|
|
6
|
+
if (new Set(Object.values(bin)).size === 1) {
|
|
7
7
|
return Object.keys(bin)[0]
|
|
8
|
+
}
|
|
8
9
|
|
|
9
10
|
// XXX probably a util to parse this better?
|
|
10
11
|
const name = mani.name.replace(/^@[^/]+\//, '')
|
|
11
|
-
if (bin[name])
|
|
12
|
+
if (bin[name]) {
|
|
12
13
|
return name
|
|
14
|
+
}
|
|
13
15
|
|
|
14
16
|
// XXX need better error message
|
|
15
17
|
throw Object.assign(new Error('could not determine executable to run'), {
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,8 @@ const read = promisify(require('read'))
|
|
|
4
4
|
|
|
5
5
|
const Arborist = require('@npmcli/arborist')
|
|
6
6
|
const ciDetect = require('@npmcli/ci-detect')
|
|
7
|
-
const
|
|
7
|
+
const log = require('proc-log')
|
|
8
|
+
const npmlog = require('npmlog')
|
|
8
9
|
const mkdirp = require('mkdirp-infer-owner')
|
|
9
10
|
const npa = require('npm-package-arg')
|
|
10
11
|
const pacote = require('pacote')
|
|
@@ -39,7 +40,6 @@ const exec = async (opts) => {
|
|
|
39
40
|
yes = undefined,
|
|
40
41
|
...flatOptions
|
|
41
42
|
} = opts
|
|
42
|
-
const log = flatOptions.log || logger
|
|
43
43
|
|
|
44
44
|
// dereferences values because we manipulate it later
|
|
45
45
|
const packages = [..._packages]
|
|
@@ -50,7 +50,6 @@ const exec = async (opts) => {
|
|
|
50
50
|
color,
|
|
51
51
|
flatOptions,
|
|
52
52
|
locationMsg,
|
|
53
|
-
log,
|
|
54
53
|
output,
|
|
55
54
|
path,
|
|
56
55
|
pathArr,
|
|
@@ -59,8 +58,9 @@ const exec = async (opts) => {
|
|
|
59
58
|
})
|
|
60
59
|
|
|
61
60
|
// nothing to maybe install, skip the arborist dance
|
|
62
|
-
if (!call && !args.length && !packages.length)
|
|
61
|
+
if (!call && !args.length && !packages.length) {
|
|
63
62
|
return await _run()
|
|
63
|
+
}
|
|
64
64
|
|
|
65
65
|
const needPackageCommandSwap = args.length && !packages.length
|
|
66
66
|
// if there's an argument and no package has been explicitly asked for
|
|
@@ -79,8 +79,9 @@ const exec = async (opts) => {
|
|
|
79
79
|
binExists = true
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if (binExists)
|
|
82
|
+
if (binExists) {
|
|
83
83
|
return await _run()
|
|
84
|
+
}
|
|
84
85
|
|
|
85
86
|
packages.push(args[0])
|
|
86
87
|
}
|
|
@@ -109,8 +110,9 @@ const exec = async (opts) => {
|
|
|
109
110
|
})
|
|
110
111
|
}))
|
|
111
112
|
|
|
112
|
-
if (needPackageCommandSwap)
|
|
113
|
+
if (needPackageCommandSwap) {
|
|
113
114
|
args[0] = getBinFromManifest(manis[0])
|
|
115
|
+
}
|
|
114
116
|
|
|
115
117
|
// figure out whether we need to install stuff, or if local is fine
|
|
116
118
|
const localArb = new Arborist({
|
|
@@ -150,8 +152,9 @@ const exec = async (opts) => {
|
|
|
150
152
|
if (add.length) {
|
|
151
153
|
if (!yes) {
|
|
152
154
|
// set -n to always say no
|
|
153
|
-
if (yes === false)
|
|
155
|
+
if (yes === false) {
|
|
154
156
|
throw new Error('canceled')
|
|
157
|
+
}
|
|
155
158
|
|
|
156
159
|
if (noTTY() || ciDetect()) {
|
|
157
160
|
log.warn('exec', `The following package${
|
|
@@ -165,11 +168,11 @@ const exec = async (opts) => {
|
|
|
165
168
|
const prompt = `Need to install the following packages:\n${
|
|
166
169
|
addList
|
|
167
170
|
}Ok to proceed? `
|
|
168
|
-
|
|
169
|
-
log.clearProgress()
|
|
171
|
+
npmlog.clearProgress()
|
|
170
172
|
const confirm = await read({ prompt, default: 'y' })
|
|
171
|
-
if (confirm.trim().toLowerCase().charAt(0) !== 'y')
|
|
173
|
+
if (confirm.trim().toLowerCase().charAt(0) !== 'y') {
|
|
172
174
|
throw new Error('canceled')
|
|
175
|
+
}
|
|
173
176
|
}
|
|
174
177
|
}
|
|
175
178
|
await arb.reify({
|
package/lib/manifest-missing.js
CHANGED
|
@@ -3,12 +3,14 @@ const manifestMissing = ({ tree, manifest }) => {
|
|
|
3
3
|
// true means we need to install it
|
|
4
4
|
const child = tree.children.get(manifest.name)
|
|
5
5
|
// if no child, we have to load it
|
|
6
|
-
if (!child)
|
|
6
|
+
if (!child) {
|
|
7
7
|
return true
|
|
8
|
+
}
|
|
8
9
|
|
|
9
10
|
// if no version/tag specified, allow whatever's there
|
|
10
|
-
if (manifest._from === `${manifest.name}@`)
|
|
11
|
+
if (manifest._from === `${manifest.name}@`) {
|
|
11
12
|
return false
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
// otherwise the version has to match what we WOULD get
|
|
14
16
|
return child.version !== manifest.version
|
package/lib/run-script.js
CHANGED
|
@@ -4,6 +4,8 @@ const chalk = require('chalk')
|
|
|
4
4
|
const ciDetect = require('@npmcli/ci-detect')
|
|
5
5
|
const runScript = require('@npmcli/run-script')
|
|
6
6
|
const readPackageJson = require('read-package-json-fast')
|
|
7
|
+
const npmlog = require('npmlog')
|
|
8
|
+
const log = require('proc-log')
|
|
7
9
|
const noTTY = require('./no-tty.js')
|
|
8
10
|
|
|
9
11
|
const nocolor = {
|
|
@@ -18,7 +20,6 @@ const run = async ({
|
|
|
18
20
|
color,
|
|
19
21
|
flatOptions,
|
|
20
22
|
locationMsg,
|
|
21
|
-
log,
|
|
22
23
|
output = () => {},
|
|
23
24
|
path,
|
|
24
25
|
pathArr,
|
|
@@ -41,16 +42,16 @@ const run = async ({
|
|
|
41
42
|
},
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
log.disableProgress()
|
|
45
|
+
npmlog.disableProgress()
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
48
|
if (script === scriptShell) {
|
|
49
49
|
const isTTY = !noTTY()
|
|
50
50
|
|
|
51
51
|
if (isTTY) {
|
|
52
|
-
if (ciDetect())
|
|
52
|
+
if (ciDetect()) {
|
|
53
53
|
return log.warn('exec', 'Interactive mode disabled in CI environment')
|
|
54
|
+
}
|
|
54
55
|
|
|
55
56
|
locationMsg = locationMsg || ` at location:\n${colorize.dim(runPath)}`
|
|
56
57
|
|
|
@@ -78,8 +79,7 @@ const run = async ({
|
|
|
78
79
|
stdio: 'inherit',
|
|
79
80
|
})
|
|
80
81
|
} finally {
|
|
81
|
-
|
|
82
|
-
log.enableProgress()
|
|
82
|
+
npmlog.enableProgress()
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libnpmexec",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"files": [
|
|
5
|
+
"bin",
|
|
5
6
|
"lib"
|
|
6
7
|
],
|
|
7
8
|
"main": "lib/index.js",
|
|
@@ -28,38 +29,41 @@
|
|
|
28
29
|
],
|
|
29
30
|
"license": "ISC",
|
|
30
31
|
"scripts": {
|
|
31
|
-
"lint": "eslint
|
|
32
|
-
"
|
|
33
|
-
"test": "tap
|
|
34
|
-
"snap": "tap
|
|
32
|
+
"lint": "eslint '**/*.js'",
|
|
33
|
+
"posttest": "npm run lint",
|
|
34
|
+
"test": "tap",
|
|
35
|
+
"snap": "tap",
|
|
35
36
|
"preversion": "npm test",
|
|
36
37
|
"postversion": "npm publish",
|
|
37
|
-
"prepublishOnly": "git push origin --follow-tags"
|
|
38
|
+
"prepublishOnly": "git push origin --follow-tags",
|
|
39
|
+
"postlint": "npm-template-check",
|
|
40
|
+
"lintfix": "npm run lint -- --fix"
|
|
38
41
|
},
|
|
39
42
|
"tap": {
|
|
40
43
|
"color": true,
|
|
41
|
-
"check-coverage": true
|
|
44
|
+
"check-coverage": true,
|
|
45
|
+
"files": "test/*.js"
|
|
42
46
|
},
|
|
43
47
|
"devDependencies": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"eslint-plugin-import": "^2.22.1",
|
|
47
|
-
"eslint-plugin-node": "^11.1.0",
|
|
48
|
-
"eslint-plugin-promise": "^5.1.0",
|
|
49
|
-
"eslint-plugin-standard": "^5.0.0",
|
|
48
|
+
"@npmcli/template-oss": "^2.4.2",
|
|
49
|
+
"bin-links": "^3.0.0",
|
|
50
50
|
"tap": "^15.0.6"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@npmcli/arborist": "^
|
|
54
|
-
"@npmcli/ci-detect": "^
|
|
55
|
-
"@npmcli/run-script": "^
|
|
53
|
+
"@npmcli/arborist": "^5.0.0",
|
|
54
|
+
"@npmcli/ci-detect": "^2.0.0",
|
|
55
|
+
"@npmcli/run-script": "^3.0.0",
|
|
56
56
|
"chalk": "^4.1.0",
|
|
57
57
|
"mkdirp-infer-owner": "^2.0.0",
|
|
58
|
-
"npm-package-arg": "^
|
|
59
|
-
"
|
|
60
|
-
"
|
|
58
|
+
"npm-package-arg": "^9.0.0",
|
|
59
|
+
"npmlog": "^6.0.1",
|
|
60
|
+
"pacote": "^13.0.2",
|
|
61
|
+
"proc-log": "^2.0.0",
|
|
61
62
|
"read": "^1.0.7",
|
|
62
63
|
"read-package-json-fast": "^2.0.2",
|
|
63
64
|
"walk-up-path": "^1.0.0"
|
|
65
|
+
},
|
|
66
|
+
"templateOSS": {
|
|
67
|
+
"version": "2.4.3"
|
|
64
68
|
}
|
|
65
69
|
}
|