Skip to content

Commit

Permalink
deps: @npmcli/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf authored and fritzy committed Jun 22, 2022
1 parent 2e50cb8 commit 2c06cee
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 483 deletions.
32 changes: 30 additions & 2 deletions node_modules/@npmcli/run-script/lib/make-spawn-args.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/* eslint camelcase: "off" */
const isWindows = require('./is-windows.js')
const setPATH = require('./set-path.js')
const { chmodSync: chmod, unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
const { tmpdir } = require('os')
const { resolve } = require('path')
const which = require('which')
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
const escape = require('./escape.js')

const makeSpawnArgs = options => {
const {
Expand All @@ -12,11 +16,28 @@ const makeSpawnArgs = options => {
env = {},
stdio,
cmd,
args = [],
stdioString = false,
} = options

let scriptFile
let script = ''
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
const args = isCmd ? ['/d', '/s', '/c', cmd] : ['-c', cmd]
if (isCmd) {
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.cmd`)
script += '@echo off\n'
script += `${cmd} ${args.map((arg) => escape.cmd(arg)).join(' ')}`
} else {
const shellPath = which.sync(scriptShell)
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.sh`)
script += `#!${shellPath}\n`
script += `${cmd} ${args.map((arg) => escape.sh(arg)).join(' ')}`
}
writeFile(scriptFile, script)
if (!isCmd) {
chmod(scriptFile, '0775')
}
const spawnArgs = isCmd ? ['/d', '/s', '/c', scriptFile] : ['-c', scriptFile]

const spawnOpts = {
env: setPATH(path, {
Expand All @@ -34,7 +55,14 @@ const makeSpawnArgs = options => {
...(isCmd ? { windowsVerbatimArguments: true } : {}),
}

return [scriptShell, args, spawnOpts]
const cleanup = () => {
// delete the script, this is just a best effort
try {
unlink(scriptFile)
} catch (err) {}
}

return [scriptShell, spawnArgs, spawnOpts, cleanup]
}

module.exports = makeSpawnArgs
13 changes: 8 additions & 5 deletions node_modules/@npmcli/run-script/lib/run-script-pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const runScriptPkg = async options => {
if (options.cmd) {
cmd = options.cmd
} else if (pkg.scripts && pkg.scripts[event]) {
cmd = pkg.scripts[event] + args.map(a => ` ${JSON.stringify(a)}`).join('')
cmd = pkg.scripts[event]
} else if (
// If there is no preinstall or install script, default to rebuilding node-gyp packages.
event === 'install' &&
Expand All @@ -42,7 +42,7 @@ const runScriptPkg = async options => {
) {
cmd = defaultGypInstallScript
} else if (event === 'start' && await isServerPackage(path)) {
cmd = 'node server.js' + args.map(a => ` ${JSON.stringify(a)}`).join('')
cmd = 'node server.js'
}

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

const p = promiseSpawn(...makeSpawnArgs({
const [spawnShell, spawnArgs, spawnOpts, cleanup] = makeSpawnArgs({
event,
path,
scriptShell,
env: packageEnvs(env, pkg),
stdio,
cmd,
args,
stdioString,
}), {
})

const p = promiseSpawn(spawnShell, spawnArgs, spawnOpts, {
event,
script: cmd,
pkgid: pkg._id,
Expand All @@ -88,7 +91,7 @@ const runScriptPkg = async options => {
} else {
throw er
}
})
}).finally(cleanup)
}

module.exports = runScriptPkg
6 changes: 3 additions & 3 deletions node_modules/@npmcli/run-script/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@npmcli/run-script",
"version": "3.0.2",
"version": "4.1.0",
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
"author": "GitHub Inc.",
"license": "ISC",
Expand All @@ -23,7 +23,7 @@
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.2.2",
"@npmcli/template-oss": "3.5.0",
"minipass": "^3.1.6",
"require-inject": "^1.4.4",
"tap": "^16.0.1"
Expand All @@ -48,6 +48,6 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "3.2.2"
"version": "3.5.0"
}
}
15 changes: 0 additions & 15 deletions node_modules/pacote/node_modules/@npmcli/run-script/LICENSE

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2c06cee

Please sign in to comment.