libnpmexec 1.1.0 → 2.0.1

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
@@ -17,7 +17,8 @@ The `npm exec` (`npx`) Programmatic API
17
17
  const libexec = require('libnpmexec')
18
18
  await libexec({
19
19
  args: ['yosay', 'Bom dia!'],
20
- cache: '~/.npm',
20
+ cache: '~/.npm/_cacache',
21
+ npxCache: '~/.npm/_npx',
21
22
  yes: true,
22
23
  })
23
24
  ```
@@ -30,6 +31,7 @@ await libexec({
30
31
  - `args`: List of pkgs to execute **Array<String>**, defaults to `[]`
31
32
  - `call`: An alternative command to run when using `packages` option **String**, defaults to empty string.
32
33
  - `cache`: The path location to where the npm cache folder is placed **String**
34
+ - `npxCache`: The path location to where the npx cache folder is placed **String**
33
35
  - `color`: Output should use color? **Boolean**, defaults to `false`
34
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.
35
37
  - `locationMsg`: Overrides "at location" message when entering interactive mode **String**
@@ -39,7 +41,7 @@ await libexec({
39
41
  - `packages`: A list of packages to be used (possibly fetch from the registry) **Array<String>**, defaults to `[]`
40
42
  - `path`: Location to where to read local project info (`package.json`) **String**, defaults to `.`
41
43
  - `runPath`: Location to where to execute the script **String**, defaults to `.`
42
- - `scriptShell`: Default shell to be used **String**
44
+ - `scriptShell`: Default shell to be used **String**, defaults to `sh` on POSIX systems, `process.env.ComSpec` OR `cmd` on Windows
43
45
  - `yes`: Should skip download confirmation prompt when fetching missing packages from the registry? **Boolean**
44
46
  - `registry`, `cache`, and more options that are forwarded to [@npmcli/arborist](https://github.com/npm/arborist/) and [pacote](https://github.com/npm/pacote/#options) **Object**
45
47
 
@@ -2,17 +2,17 @@ const crypto = require('crypto')
2
2
 
3
3
  const { resolve } = require('path')
4
4
 
5
- const cacheInstallDir = ({ cache, packages }) => {
6
- if (!cache)
7
- throw new Error('Must provide a valid cache path')
5
+ const cacheInstallDir = ({ npxCache, packages }) => {
6
+ if (!npxCache)
7
+ throw new Error('Must provide a valid npxCache path')
8
8
 
9
9
  // only packages not found in ${prefix}/node_modules
10
- return resolve(cache, '_npx', getHash(packages))
10
+ return resolve(npxCache, getHash(packages))
11
11
  }
12
12
 
13
13
  const getHash = (packages) =>
14
14
  crypto.createHash('sha512')
15
- .update(packages.sort((a, b) => a.localeCompare(b)).join('\n'))
15
+ .update(packages.sort((a, b) => a.localeCompare(b, 'en')).join('\n'))
16
16
  .digest('hex')
17
17
  .slice(0, 16)
18
18
 
package/lib/index.js CHANGED
@@ -16,6 +16,7 @@ const getBinFromManifest = require('./get-bin-from-manifest.js')
16
16
  const manifestMissing = require('./manifest-missing.js')
17
17
  const noTTY = require('./no-tty.js')
18
18
  const runScript = require('./run-script.js')
19
+ const isWindows = require('./is-windows.js')
19
20
 
20
21
  /* istanbul ignore next */
21
22
  const PATH = (
@@ -34,7 +35,7 @@ const exec = async (opts) => {
34
35
  packages: _packages = [],
35
36
  path = '.',
36
37
  runPath = '.',
37
- scriptShell = undefined,
38
+ scriptShell = isWindows ? process.env.ComSpec || 'cmd' : 'sh',
38
39
  yes = undefined,
39
40
  ...flatOptions
40
41
  } = opts
@@ -123,8 +124,8 @@ const exec = async (opts) => {
123
124
  manis.some(manifest => manifestMissing({ tree, manifest }))
124
125
 
125
126
  if (needInstall) {
126
- const { cache } = flatOptions
127
- const installDir = cacheInstallDir({ cache, packages })
127
+ const { npxCache } = flatOptions
128
+ const installDir = cacheInstallDir({ npxCache, packages })
128
129
  await mkdirp(installDir)
129
130
  const arb = new Arborist({
130
131
  ...flatOptions,
@@ -143,7 +144,7 @@ const exec = async (opts) => {
143
144
  },
144
145
  }))
145
146
  .map(mani => mani._from)
146
- .sort((a, b) => a.localeCompare(b))
147
+ .sort((a, b) => a.localeCompare(b, 'en'))
147
148
 
148
149
  // no need to install if already present
149
150
  if (add.length) {
@@ -164,6 +165,8 @@ const exec = async (opts) => {
164
165
  const prompt = `Need to install the following packages:\n${
165
166
  addList
166
167
  }Ok to proceed? `
168
+ if (typeof log.clearProgress === 'function')
169
+ log.clearProgress()
167
170
  const confirm = await read({ prompt, default: 'y' })
168
171
  if (confirm.trim().toLowerCase().charAt(0) !== 'y')
169
172
  throw new Error('canceled')
@@ -0,0 +1 @@
1
+ module.exports = process.platform === 'win32'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libnpmexec",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
4
  "files": [
5
5
  "lib"
6
6
  ],
package/CHANGELOG.md DELETED
@@ -1,17 +0,0 @@
1
- # Changelog
2
-
3
- ## v1.1.0
4
-
5
- - Add add walk up dir lookup logic to satisfy local bins,
6
- similar to `@npmcli/run-script`
7
-
8
- ## v1.0.1
9
-
10
- - Fix `scriptShell` option name.
11
-
12
- ## v1.0.0
13
-
14
- - Initial implementation, moves the code that used to live in the **npm cli**,
15
- ref: https://github.com/npm/cli/blob/release/v7.10.0/lib/exec.js into this
16
- separate module, providing a programmatic API to the **npm exec** functionality.
17
-