Skip to content

Commit 2c06cee

Browse files
nlffritzy
authored andcommittedJun 22, 2022
deps: @npmcli/run-script@4.1.0
1 parent 2e50cb8 commit 2c06cee

23 files changed

+65
-483
lines changed
 

‎node_modules/@npmcli/run-script/lib/make-spawn-args.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/* eslint camelcase: "off" */
22
const isWindows = require('./is-windows.js')
33
const setPATH = require('./set-path.js')
4+
const { chmodSync: chmod, unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
5+
const { tmpdir } = require('os')
46
const { resolve } = require('path')
7+
const which = require('which')
58
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
9+
const escape = require('./escape.js')
610

711
const makeSpawnArgs = options => {
812
const {
@@ -12,11 +16,28 @@ const makeSpawnArgs = options => {
1216
env = {},
1317
stdio,
1418
cmd,
19+
args = [],
1520
stdioString = false,
1621
} = options
1722

23+
let scriptFile
24+
let script = ''
1825
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
19-
const args = isCmd ? ['/d', '/s', '/c', cmd] : ['-c', cmd]
26+
if (isCmd) {
27+
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.cmd`)
28+
script += '@echo off\n'
29+
script += `${cmd} ${args.map((arg) => escape.cmd(arg)).join(' ')}`
30+
} else {
31+
const shellPath = which.sync(scriptShell)
32+
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.sh`)
33+
script += `#!${shellPath}\n`
34+
script += `${cmd} ${args.map((arg) => escape.sh(arg)).join(' ')}`
35+
}
36+
writeFile(scriptFile, script)
37+
if (!isCmd) {
38+
chmod(scriptFile, '0775')
39+
}
40+
const spawnArgs = isCmd ? ['/d', '/s', '/c', scriptFile] : ['-c', scriptFile]
2041

2142
const spawnOpts = {
2243
env: setPATH(path, {
@@ -34,7 +55,14 @@ const makeSpawnArgs = options => {
3455
...(isCmd ? { windowsVerbatimArguments: true } : {}),
3556
}
3657

37-
return [scriptShell, args, spawnOpts]
58+
const cleanup = () => {
59+
// delete the script, this is just a best effort
60+
try {
61+
unlink(scriptFile)
62+
} catch (err) {}
63+
}
64+
65+
return [scriptShell, spawnArgs, spawnOpts, cleanup]
3866
}
3967

4068
module.exports = makeSpawnArgs

‎node_modules/@npmcli/run-script/lib/run-script-pkg.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const runScriptPkg = async options => {
3131
if (options.cmd) {
3232
cmd = options.cmd
3333
} else if (pkg.scripts && pkg.scripts[event]) {
34-
cmd = pkg.scripts[event] + args.map(a => ` ${JSON.stringify(a)}`).join('')
34+
cmd = pkg.scripts[event]
3535
} else if (
3636
// If there is no preinstall or install script, default to rebuilding node-gyp packages.
3737
event === 'install' &&
@@ -42,7 +42,7 @@ const runScriptPkg = async options => {
4242
) {
4343
cmd = defaultGypInstallScript
4444
} else if (event === 'start' && await isServerPackage(path)) {
45-
cmd = 'node server.js' + args.map(a => ` ${JSON.stringify(a)}`).join('')
45+
cmd = 'node server.js'
4646
}
4747

4848
if (!cmd) {
@@ -54,15 +54,18 @@ const runScriptPkg = async options => {
5454
console.log(bruce(pkg._id, event, cmd))
5555
}
5656

57-
const p = promiseSpawn(...makeSpawnArgs({
57+
const [spawnShell, spawnArgs, spawnOpts, cleanup] = makeSpawnArgs({
5858
event,
5959
path,
6060
scriptShell,
6161
env: packageEnvs(env, pkg),
6262
stdio,
6363
cmd,
64+
args,
6465
stdioString,
65-
}), {
66+
})
67+
68+
const p = promiseSpawn(spawnShell, spawnArgs, spawnOpts, {
6669
event,
6770
script: cmd,
6871
pkgid: pkg._id,
@@ -88,7 +91,7 @@ const runScriptPkg = async options => {
8891
} else {
8992
throw er
9093
}
91-
})
94+
}).finally(cleanup)
9295
}
9396

9497
module.exports = runScriptPkg

‎node_modules/@npmcli/run-script/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/run-script",
3-
"version": "3.0.2",
3+
"version": "4.1.0",
44
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
55
"author": "GitHub Inc.",
66
"license": "ISC",
@@ -23,7 +23,7 @@
2323
},
2424
"devDependencies": {
2525
"@npmcli/eslint-config": "^3.0.1",
26-
"@npmcli/template-oss": "3.2.2",
26+
"@npmcli/template-oss": "3.5.0",
2727
"minipass": "^3.1.6",
2828
"require-inject": "^1.4.4",
2929
"tap": "^16.0.1"
@@ -48,6 +48,6 @@
4848
},
4949
"templateOSS": {
5050
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
51-
"version": "3.2.2"
51+
"version": "3.5.0"
5252
}
5353
}

‎node_modules/pacote/node_modules/@npmcli/run-script/LICENSE

-15
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/is-server-package.js

-12
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/is-windows.js

-2
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/make-spawn-args.js

-68
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp

-2
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/node-gyp-bin/node-gyp.cmd

-1
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/package-envs.js

-26
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/run-script-pkg.js

-97
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/run-script.js

-14
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/set-path.js

-45
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/signal-manager.js

-47
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/validate-options.js

-39
This file was deleted.

‎node_modules/pacote/node_modules/@npmcli/run-script/package.json

-53
This file was deleted.

‎package-lock.json

+19-47
Original file line numberDiff line numberDiff line change

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@npmcli/fs": "^2.1.0",
6363
"@npmcli/map-workspaces": "^2.0.3",
6464
"@npmcli/package-json": "^2.0.0",
65-
"@npmcli/run-script": "^3.0.1",
65+
"@npmcli/run-script": "^4.1.0",
6666
"abbrev": "~1.1.1",
6767
"archy": "~1.0.0",
6868
"cacache": "^16.1.1",

‎workspaces/arborist/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@npmcli/name-from-folder": "^1.0.1",
1212
"@npmcli/node-gyp": "^2.0.0",
1313
"@npmcli/package-json": "^2.0.0",
14-
"@npmcli/run-script": "^3.0.0",
14+
"@npmcli/run-script": "^4.1.0",
1515
"bin-links": "^3.0.0",
1616
"cacache": "^16.0.6",
1717
"common-ancestor-path": "^1.0.1",

‎workspaces/libnpmexec/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"dependencies": {
5858
"@npmcli/arborist": "^5.0.0",
5959
"@npmcli/ci-detect": "^2.0.0",
60-
"@npmcli/run-script": "^3.0.0",
60+
"@npmcli/run-script": "^4.1.0",
6161
"chalk": "^4.1.0",
6262
"mkdirp-infer-owner": "^2.0.0",
6363
"npm-package-arg": "^9.0.1",

‎workspaces/libnpmpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"bugs": "https://github.com/npm/libnpmpack/issues",
3939
"homepage": "https://npmjs.com/package/libnpmpack",
4040
"dependencies": {
41-
"@npmcli/run-script": "^3.0.0",
41+
"@npmcli/run-script": "^4.1.0",
4242
"npm-package-arg": "^9.0.1",
4343
"pacote": "^13.6.1"
4444
},

‎workspaces/libnpmversion/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"dependencies": {
3939
"@npmcli/git": "^3.0.0",
40-
"@npmcli/run-script": "^3.0.0",
40+
"@npmcli/run-script": "^4.1.0",
4141
"json-parse-even-better-errors": "^2.3.1",
4242
"proc-log": "^2.0.0",
4343
"semver": "^7.3.7"

0 commit comments

Comments
 (0)
Please sign in to comment.