@npmcli/run-script
Advanced tools
Comparing version 2.0.0 to 3.0.0
/* eslint camelcase: "off" */ | ||
const isWindows = require('./is-windows.js') | ||
const setPATH = require('./set-path.js') | ||
const {resolve} = require('path') | ||
const { resolve } = require('path') | ||
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js') | ||
@@ -6,0 +6,0 @@ |
@@ -9,8 +9,9 @@ // https://github.com/npm/rfcs/pull/183 | ||
for (const [key, val] of Object.entries(vals)) { | ||
if (val === undefined) | ||
if (val === undefined) { | ||
continue | ||
else if (val && !Array.isArray(val) && typeof val === 'object') | ||
} else if (val && !Array.isArray(val) && typeof val === 'object') { | ||
packageEnvs(env, val, `${prefix}${key}_`) | ||
else | ||
} else { | ||
env[`${prefix}${key}`] = envVal(val) | ||
} | ||
} | ||
@@ -17,0 +18,0 @@ return env |
@@ -29,9 +29,10 @@ const makeSpawnArgs = require('./make-spawn-args.js') | ||
const {scripts = {}, gypfile} = pkg | ||
const { scripts = {}, gypfile } = pkg | ||
let cmd = null | ||
if (options.cmd) | ||
if (options.cmd) { | ||
cmd = options.cmd | ||
else if (pkg.scripts && pkg.scripts[event]) | ||
} else if (pkg.scripts && pkg.scripts[event]) { | ||
cmd = pkg.scripts[event] + args.map(a => ` ${JSON.stringify(a)}`).join('') | ||
else if ( // If there is no preinstall or install script, default to rebuilding node-gyp packages. | ||
} else if ( | ||
// If there is no preinstall or install script, default to rebuilding node-gyp packages. | ||
event === 'install' && | ||
@@ -42,9 +43,11 @@ !scripts.install && | ||
await isNodeGypPackage(path) | ||
) | ||
) { | ||
cmd = defaultGypInstallScript | ||
else if (event === 'start' && await isServerPackage(path)) | ||
} else if (event === 'start' && await isServerPackage(path)) { | ||
cmd = 'node server.js' + args.map(a => ` ${JSON.stringify(a)}`).join('') | ||
} | ||
if (!cmd) | ||
if (!cmd) { | ||
return { code: 0, signal: null } | ||
} | ||
@@ -71,7 +74,9 @@ if (stdio === 'inherit' && banner !== false) { | ||
if (stdio === 'inherit') | ||
if (stdio === 'inherit') { | ||
signalManager.add(p.process) | ||
} | ||
if (p.stdin) | ||
if (p.stdin) { | ||
p.stdin.end() | ||
} | ||
@@ -86,4 +91,5 @@ return p.catch(er => { | ||
return new Promise((res, rej) => setTimeout(() => rej(er), signalTimeout)) | ||
} else | ||
} else { | ||
throw er | ||
} | ||
}) | ||
@@ -90,0 +96,0 @@ } |
@@ -8,7 +8,7 @@ const rpj = require('read-package-json-fast') | ||
validateOptions(options) | ||
const {pkg, path} = options | ||
const { pkg, path } = options | ||
return pkg ? runScriptPkg(options) | ||
: rpj(path + '/package.json').then(pkg => runScriptPkg({...options, pkg})) | ||
: rpj(path + '/package.json').then(pkg => runScriptPkg({ ...options, pkg })) | ||
} | ||
module.exports = Object.assign(runScript, { isServerPackage }) |
@@ -1,2 +0,2 @@ | ||
const {resolve, dirname} = require('path') | ||
const { resolve, dirname } = require('path') | ||
const isWindows = require('./is-windows.js') | ||
@@ -37,4 +37,5 @@ // the path here is relative, even though it does not need to be | ||
for (const key of Object.keys(env)) { | ||
if (/^path$/i.test(key)) | ||
if (/^path$/i.test(key)) { | ||
env[key] = pathVal | ||
} | ||
} | ||
@@ -41,0 +42,0 @@ |
@@ -6,3 +6,3 @@ const runningProcs = new Set() | ||
'SIGINT', | ||
'SIGTERM' | ||
'SIGTERM', | ||
] | ||
@@ -34,4 +34,5 @@ | ||
runningProcs.add(proc) | ||
if (!handlersInstalled) | ||
if (!handlersInstalled) { | ||
setupListeners() | ||
} | ||
@@ -47,3 +48,3 @@ proc.once('exit', () => { | ||
handleSignal, | ||
forwardedSignals | ||
forwardedSignals, | ||
} |
const validateOptions = options => { | ||
if (typeof options !== 'object' || !options) | ||
if (typeof options !== 'object' || !options) { | ||
throw new TypeError('invalid options object provided to runScript') | ||
} | ||
@@ -15,18 +16,25 @@ const { | ||
if (!event || typeof event !== 'string') | ||
if (!event || typeof event !== 'string') { | ||
throw new TypeError('valid event not provided to runScript') | ||
if (!path || typeof path !== 'string') | ||
} | ||
if (!path || typeof path !== 'string') { | ||
throw new TypeError('valid path not provided to runScript') | ||
if (scriptShell !== undefined && typeof scriptShell !== 'string') | ||
} | ||
if (scriptShell !== undefined && typeof scriptShell !== 'string') { | ||
throw new TypeError('invalid scriptShell option provided to runScript') | ||
if (typeof env !== 'object' || !env) | ||
} | ||
if (typeof env !== 'object' || !env) { | ||
throw new TypeError('invalid env option provided to runScript') | ||
if (typeof stdio !== 'string' && !Array.isArray(stdio)) | ||
} | ||
if (typeof stdio !== 'string' && !Array.isArray(stdio)) { | ||
throw new TypeError('invalid stdio option provided to runScript') | ||
if (!Array.isArray(args) || args.some(a => typeof a !== 'string')) | ||
} | ||
if (!Array.isArray(args) || args.some(a => typeof a !== 'string')) { | ||
throw new TypeError('invalid args option provided to runScript') | ||
if (cmd !== undefined && typeof cmd !== 'string') | ||
} | ||
if (cmd !== undefined && typeof cmd !== 'string') { | ||
throw new TypeError('invalid cmd option provided to runScript') | ||
} | ||
} | ||
module.exports = validateOptions |
{ | ||
"name": "@npmcli/run-script", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)", | ||
"author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)", | ||
"author": "GitHub Inc.", | ||
"license": "ISC", | ||
@@ -13,4 +13,8 @@ "scripts": { | ||
"eslint": "eslint", | ||
"lint": "npm run eslint -- \"lib/**/*.js\"", | ||
"lintfix": "npm run lint -- --fix" | ||
"lint": "eslint '**/*.js'", | ||
"lintfix": "npm run lint -- --fix", | ||
"postlint": "npm-template-check", | ||
"template-copy": "npm-template-copy --force", | ||
"snap": "tap", | ||
"posttest": "npm run lint" | ||
}, | ||
@@ -22,8 +26,4 @@ "tap": { | ||
"devDependencies": { | ||
"eslint": "^7.19.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"minipass": "^3.1.1", | ||
"@npmcli/template-oss": "^2.7.1", | ||
"minipass": "^3.1.6", | ||
"require-inject": "^1.4.4", | ||
@@ -33,10 +33,10 @@ "tap": "^15.0.4" | ||
"dependencies": { | ||
"@npmcli/node-gyp": "^1.0.2", | ||
"@npmcli/node-gyp": "^1.0.3", | ||
"@npmcli/promise-spawn": "^1.3.2", | ||
"node-gyp": "^8.2.0", | ||
"read-package-json-fast": "^2.0.1" | ||
"node-gyp": "^8.4.1", | ||
"read-package-json-fast": "^2.0.3" | ||
}, | ||
"files": [ | ||
"lib/**/*.js", | ||
"lib/node-gyp-bin" | ||
"bin", | ||
"lib" | ||
], | ||
@@ -47,3 +47,9 @@ "main": "lib/run-script.js", | ||
"url": "git+https://github.com/npm/run-script.git" | ||
}, | ||
"engines": { | ||
"node": "^12.13.0 || ^14.15.0 || >=16" | ||
}, | ||
"templateOSS": { | ||
"version": "2.7.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16691
4
282
1
Updated@npmcli/node-gyp@^1.0.3
Updatednode-gyp@^8.4.1