libnpmexec 7.0.10 → 8.1.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 CHANGED
@@ -35,7 +35,6 @@ await libexec({
35
35
  - `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.
36
36
  - `locationMsg`: Overrides "at location" message when entering interactive mode **String**
37
37
  - `globalBin`: Location to the global space bin folder, same as: `$(npm bin -g)` **String**, defaults to empty string.
38
- - `output`: A function to print output to **Function**
39
38
  - `packages`: A list of packages to be used (possibly fetch from the registry) **Array<String>**, defaults to `[]`
40
39
  - `path`: Location to where to read local project info (`package.json`) **String**, defaults to `.`
41
40
  - `runPath`: Location to where to execute the script **String**, defaults to `.`
package/lib/index.js CHANGED
@@ -4,19 +4,16 @@ const { mkdir } = require('fs/promises')
4
4
  const Arborist = require('@npmcli/arborist')
5
5
  const ciInfo = require('ci-info')
6
6
  const crypto = require('crypto')
7
- const log = require('proc-log')
7
+ const { log, input } = require('proc-log')
8
8
  const npa = require('npm-package-arg')
9
- const npmlog = require('npmlog')
10
9
  const pacote = require('pacote')
11
10
  const { read } = require('read')
12
11
  const semver = require('semver')
13
-
14
12
  const { fileExists, localFileExists } = require('./file-exists.js')
15
13
  const getBinFromManifest = require('./get-bin-from-manifest.js')
16
14
  const noTTY = require('./no-tty.js')
17
15
  const runScript = require('./run-script.js')
18
16
  const isWindows = require('./is-windows.js')
19
-
20
17
  const { dirname, resolve } = require('path')
21
18
 
22
19
  const binPaths = []
@@ -84,7 +81,6 @@ const exec = async (opts) => {
84
81
  locationMsg = undefined,
85
82
  globalBin = '',
86
83
  globalPath,
87
- output,
88
84
  // dereference values because we manipulate it later
89
85
  packages: [...packages] = [],
90
86
  path = '.',
@@ -99,7 +95,6 @@ const exec = async (opts) => {
99
95
  call,
100
96
  flatOptions,
101
97
  locationMsg,
102
- output,
103
98
  path,
104
99
  binPaths,
105
100
  runPath,
@@ -245,27 +240,24 @@ const exec = async (opts) => {
245
240
 
246
241
  if (add.length) {
247
242
  if (!yes) {
248
- const missingPackages = add.map(a => `${a.replace(/@$/, '')}`)
243
+ const addList = add.map(a => `${a.replace(/@$/, '')}`)
244
+
249
245
  // set -n to always say no
250
246
  if (yes === false) {
251
247
  // Error message lists missing package(s) when process is canceled
252
248
  /* eslint-disable-next-line max-len */
253
- throw new Error(`npx canceled due to missing packages and no YES option: ${JSON.stringify(missingPackages)}`)
249
+ throw new Error(`npx canceled due to missing packages and no YES option: ${JSON.stringify(addList)}`)
254
250
  }
255
251
 
256
252
  if (noTTY() || ciInfo.isCI) {
257
- log.warn('exec', `The following package${
258
- add.length === 1 ? ' was' : 's were'
259
- } not found and will be installed: ${
260
- add.map((pkg) => pkg.replace(/@$/, '')).join(', ')
261
- }`)
253
+ /* eslint-disable-next-line max-len */
254
+ log.warn('exec', `The following package${add.length === 1 ? ' was' : 's were'} not found and will be installed: ${addList.join(', ')}`)
262
255
  } else {
263
- const addList = missingPackages.join('\n') + '\n'
264
- const prompt = `Need to install the following packages:\n${
265
- addList
266
- }Ok to proceed? `
267
- npmlog.clearProgress()
268
- const confirm = await read({ prompt, default: 'y' })
256
+ const confirm = await input.read(() => read({
257
+ /* eslint-disable-next-line max-len */
258
+ prompt: `Need to install the following packages:\n${addList.join('\n')}\nOk to proceed? `,
259
+ default: 'y',
260
+ }))
269
261
  if (confirm.trim().toLowerCase().charAt(0) !== 'y') {
270
262
  throw new Error('canceled')
271
263
  }
package/lib/run-script.js CHANGED
@@ -1,8 +1,7 @@
1
1
  const ciInfo = require('ci-info')
2
2
  const runScript = require('@npmcli/run-script')
3
3
  const readPackageJson = require('read-package-json-fast')
4
- const npmlog = require('npmlog')
5
- const log = require('proc-log')
4
+ const { log, output } = require('proc-log')
6
5
  const noTTY = require('./no-tty.js')
7
6
 
8
7
  const run = async ({
@@ -10,7 +9,6 @@ const run = async ({
10
9
  call,
11
10
  flatOptions,
12
11
  locationMsg,
13
- output = () => {},
14
12
  path,
15
13
  binPaths,
16
14
  runPath,
@@ -21,8 +19,7 @@ const run = async ({
21
19
 
22
20
  // do the fakey runScript dance
23
21
  // still should work if no package.json in cwd
24
- const realPkg = await readPackageJson(`${path}/package.json`)
25
- .catch(() => ({}))
22
+ const realPkg = await readPackageJson(`${path}/package.json`).catch(() => ({}))
26
23
  const pkg = {
27
24
  ...realPkg,
28
25
  scripts: {
@@ -31,41 +28,34 @@ const run = async ({
31
28
  },
32
29
  }
33
30
 
34
- npmlog.disableProgress()
35
-
36
- try {
37
- if (script === scriptShell) {
38
- if (!noTTY()) {
39
- if (ciInfo.isCI) {
40
- return log.warn('exec', 'Interactive mode disabled in CI environment')
41
- }
31
+ if (script === scriptShell) {
32
+ if (!noTTY()) {
33
+ if (ciInfo.isCI) {
34
+ return log.warn('exec', 'Interactive mode disabled in CI environment')
35
+ }
42
36
 
43
- locationMsg = locationMsg || ` at location:\n${flatOptions.chalk.dim(runPath)}`
37
+ const { chalk } = flatOptions
44
38
 
45
- output(`${
46
- flatOptions.chalk.reset('\nEntering npm script environment')
47
- }${
48
- flatOptions.chalk.reset(locationMsg)
49
- }${
50
- flatOptions.chalk.bold('\nType \'exit\' or ^D when finished\n')
51
- }`)
52
- }
39
+ output.standard(`${
40
+ chalk.reset('\nEntering npm script environment')
41
+ }${
42
+ chalk.reset(locationMsg || ` at location:\n${chalk.dim(runPath)}`)
43
+ }${
44
+ chalk.bold('\nType \'exit\' or ^D when finished\n')
45
+ }`)
53
46
  }
54
- return await runScript({
55
- ...flatOptions,
56
- pkg,
57
- banner: false,
58
- // we always run in cwd, not --prefix
59
- path: runPath,
60
- binPaths,
61
- event: 'npx',
62
- args,
63
- stdio: 'inherit',
64
- scriptShell,
65
- })
66
- } finally {
67
- npmlog.enableProgress()
68
47
  }
48
+ return runScript({
49
+ ...flatOptions,
50
+ pkg,
51
+ // we always run in cwd, not --prefix
52
+ path: runPath,
53
+ binPaths,
54
+ event: 'npx',
55
+ args,
56
+ stdio: 'inherit',
57
+ scriptShell,
58
+ })
69
59
  }
70
60
 
71
61
  module.exports = run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libnpmexec",
3
- "version": "7.0.10",
3
+ "version": "8.1.0",
4
4
  "files": [
5
5
  "bin/",
6
6
  "lib/"
@@ -12,7 +12,7 @@
12
12
  "description": "npm exec (npx) programmatic API",
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/npm/cli.git",
15
+ "url": "git+https://github.com/npm/cli.git",
16
16
  "directory": "workspaces/libnpmexec"
17
17
  },
18
18
  "keywords": [
@@ -60,12 +60,11 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@npmcli/arborist": "^7.2.1",
63
- "@npmcli/run-script": "^7.0.2",
63
+ "@npmcli/run-script": "^8.1.0",
64
64
  "ci-info": "^4.0.0",
65
- "npm-package-arg": "^11.0.1",
66
- "npmlog": "^7.0.1",
67
- "pacote": "^17.0.4",
68
- "proc-log": "^3.0.0",
65
+ "npm-package-arg": "^11.0.2",
66
+ "pacote": "^18.0.1",
67
+ "proc-log": "^4.2.0",
69
68
  "read": "^3.0.1",
70
69
  "read-package-json-fast": "^3.0.2",
71
70
  "semver": "^7.3.7",