libnpmexec 2.0.0 → 3.0.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.
@@ -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))
@@ -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
@@ -59,8 +59,9 @@ const exec = async (opts) => {
59
59
  })
60
60
 
61
61
  // nothing to maybe install, skip the arborist dance
62
- if (!call && !args.length && !packages.length)
62
+ if (!call && !args.length && !packages.length) {
63
63
  return await _run()
64
+ }
64
65
 
65
66
  const needPackageCommandSwap = args.length && !packages.length
66
67
  // if there's an argument and no package has been explicitly asked for
@@ -79,8 +80,9 @@ const exec = async (opts) => {
79
80
  binExists = true
80
81
  }
81
82
 
82
- if (binExists)
83
+ if (binExists) {
83
84
  return await _run()
85
+ }
84
86
 
85
87
  packages.push(args[0])
86
88
  }
@@ -109,8 +111,9 @@ const exec = async (opts) => {
109
111
  })
110
112
  }))
111
113
 
112
- if (needPackageCommandSwap)
114
+ if (needPackageCommandSwap) {
113
115
  args[0] = getBinFromManifest(manis[0])
116
+ }
114
117
 
115
118
  // figure out whether we need to install stuff, or if local is fine
116
119
  const localArb = new Arborist({
@@ -150,8 +153,9 @@ const exec = async (opts) => {
150
153
  if (add.length) {
151
154
  if (!yes) {
152
155
  // set -n to always say no
153
- if (yes === false)
156
+ if (yes === false) {
154
157
  throw new Error('canceled')
158
+ }
155
159
 
156
160
  if (noTTY() || ciDetect()) {
157
161
  log.warn('exec', `The following package${
@@ -165,9 +169,13 @@ const exec = async (opts) => {
165
169
  const prompt = `Need to install the following packages:\n${
166
170
  addList
167
171
  }Ok to proceed? `
172
+ if (typeof log.clearProgress === 'function') {
173
+ log.clearProgress()
174
+ }
168
175
  const confirm = await read({ prompt, default: 'y' })
169
- if (confirm.trim().toLowerCase().charAt(0) !== 'y')
176
+ if (confirm.trim().toLowerCase().charAt(0) !== 'y') {
170
177
  throw new Error('canceled')
178
+ }
171
179
  }
172
180
  }
173
181
  await arb.reify({
@@ -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
@@ -41,16 +41,18 @@ const run = async ({
41
41
  },
42
42
  }
43
43
 
44
- if (log && log.disableProgress)
44
+ if (log && log.disableProgress) {
45
45
  log.disableProgress()
46
+ }
46
47
 
47
48
  try {
48
49
  if (script === scriptShell) {
49
50
  const isTTY = !noTTY()
50
51
 
51
52
  if (isTTY) {
52
- if (ciDetect())
53
+ if (ciDetect()) {
53
54
  return log.warn('exec', 'Interactive mode disabled in CI environment')
55
+ }
54
56
 
55
57
  locationMsg = locationMsg || ` at location:\n${colorize.dim(runPath)}`
56
58
 
@@ -78,8 +80,9 @@ const run = async ({
78
80
  stdio: 'inherit',
79
81
  })
80
82
  } finally {
81
- if (log && log.enableProgress)
83
+ if (log && log.enableProgress) {
82
84
  log.enableProgress()
85
+ }
83
86
  }
84
87
  }
85
88
 
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "libnpmexec",
3
- "version": "2.0.0",
3
+ "version": "3.0.2",
4
4
  "files": [
5
+ "bin",
5
6
  "lib"
6
7
  ],
7
8
  "main": "lib/index.js",
8
9
  "engines": {
9
- "node": ">=10"
10
+ "node": "^12.13.0 || ^14.15.0 || >=16"
10
11
  },
11
12
  "description": "npm exec (npx) programmatic API",
12
13
  "repository": "https://github.com/npm/libnpmexec",
@@ -28,37 +29,39 @@
28
29
  ],
29
30
  "license": "ISC",
30
31
  "scripts": {
31
- "lint": "eslint lib/*.js",
32
- "pretest": "npm run lint",
33
- "test": "tap test/*.js",
34
- "snap": "tap test/*.js",
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
- "check-coverage": true
43
+ "color": true,
44
+ "check-coverage": true,
45
+ "files": "test/*.js"
41
46
  },
42
47
  "devDependencies": {
43
48
  "bin-links": "^2.2.1",
44
- "eslint": "^7.24.0",
45
- "eslint-plugin-import": "^2.22.1",
46
- "eslint-plugin-node": "^11.1.0",
47
- "eslint-plugin-promise": "^5.1.0",
48
- "eslint-plugin-standard": "^5.0.0",
49
49
  "tap": "^15.0.6"
50
50
  },
51
51
  "dependencies": {
52
- "@npmcli/arborist": "^2.3.0",
52
+ "@npmcli/arborist": "^4.0.0",
53
53
  "@npmcli/ci-detect": "^1.3.0",
54
- "@npmcli/run-script": "^1.8.4",
54
+ "@npmcli/run-script": "^2.0.0",
55
55
  "chalk": "^4.1.0",
56
56
  "mkdirp-infer-owner": "^2.0.0",
57
57
  "npm-package-arg": "^8.1.2",
58
- "pacote": "^11.3.1",
58
+ "pacote": "^12.0.0",
59
59
  "proc-log": "^1.0.0",
60
60
  "read": "^1.0.7",
61
61
  "read-package-json-fast": "^2.0.2",
62
62
  "walk-up-path": "^1.0.0"
63
+ },
64
+ "templateOSS": {
65
+ "version": "2.4.1"
63
66
  }
64
67
  }