npm-run-all2
Advanced tools
Comparing version 6.0.6 to 6.1.0
@@ -13,2 +13,3 @@ /** | ||
const fs = require('fs') | ||
const path = require('path') | ||
@@ -132,2 +133,5 @@ const parseArgs = require('shell-quote').parse | ||
* @param {boolean} options.printName - The flag to print task names before running each task. | ||
* @param {object} options.packageInfo - A package.json's information. | ||
* @param {object} options.packageInfo.body - A package.json's JSON object. | ||
* @param {string} options.packageInfo.path - A package.json's file path. | ||
* @returns {Promise} | ||
@@ -140,54 +144,82 @@ * A promise object which becomes fullfilled when the npm-script is completed. | ||
let cp = null | ||
const promise = new Promise((resolve, reject) => { | ||
ansiStylesPromise.then(({ default: ansiStyles }) => { | ||
const stdin = options.stdin | ||
const stdout = wrapLabeling(task, options.stdout, options.labelState, ansiStyles) | ||
const stderr = wrapLabeling(task, options.stderr, options.labelState, ansiStyles) | ||
const stdinKind = detectStreamKind(stdin, process.stdin) | ||
const stdoutKind = detectStreamKind(stdout, process.stdout) | ||
const stderrKind = detectStreamKind(stderr, process.stderr) | ||
const spawnOptions = { stdio: [stdinKind, stdoutKind, stderrKind] } | ||
// Print task name. | ||
if (options.printName && stdout != null) { | ||
stdout.write(createHeader( | ||
task, | ||
options.packageInfo, | ||
options.stdout.isTTY, | ||
ansiStyles | ||
)) | ||
async function asyncRunTask () { | ||
const { default: ansiStyles } = await ansiStylesPromise | ||
const stdin = options.stdin | ||
const stdout = wrapLabeling(task, options.stdout, options.labelState, ansiStyles) | ||
const stderr = wrapLabeling(task, options.stderr, options.labelState, ansiStyles) | ||
const stdinKind = detectStreamKind(stdin, process.stdin) | ||
const stdoutKind = detectStreamKind(stdout, process.stdout) | ||
const stderrKind = detectStreamKind(stderr, process.stderr) | ||
const spawnOptions = { stdio: [stdinKind, stdoutKind, stderrKind] } | ||
// Print task name. | ||
if (options.printName && stdout != null) { | ||
stdout.write(createHeader( | ||
task, | ||
options.packageInfo, | ||
options.stdout.isTTY, | ||
ansiStyles | ||
)) | ||
} | ||
// Execute. | ||
let npmPath = options.npmPath | ||
if (!npmPath && process.env.npm_execpath) { | ||
const basename = path.basename(process.env.npm_execpath) | ||
let newBasename = basename | ||
if (basename.startsWith('npx')) { | ||
newBasename = basename.replace('npx', 'npm') // eslint-disable-line no-process-env | ||
} else if (basename.startsWith('pnpx')) { | ||
newBasename = basename.replace('pnpx', 'pnpm') // eslint-disable-line no-process-env | ||
} | ||
// Execute. | ||
const npmPath = options.npmPath || path.basename(process.env.npm_execpath).startsWith('npx') // eslint-disable-line no-process-env | ||
? path.join(path.dirname(process.env.npm_execpath), path.basename(process.env.npm_execpath).replace('npx', 'npm')) // eslint-disable-line no-process-env | ||
npmPath = newBasename === basename | ||
? path.join(path.dirname(process.env.npm_execpath), newBasename) | ||
: process.env.npm_execpath // eslint-disable-line no-process-env | ||
const npmPathIsJs = typeof npmPath === 'string' && /\.m?js/.test(path.extname(npmPath)) | ||
const execPath = (npmPathIsJs ? process.execPath : npmPath || 'npm') | ||
const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith('yarn') // eslint-disable-line no-process-env | ||
const spawnArgs = ['run'] | ||
} | ||
if (npmPathIsJs) { | ||
spawnArgs.unshift(npmPath) | ||
const npmPathIsJs = typeof npmPath === 'string' && /\.(c|m)?js/.test(path.extname(npmPath)) | ||
let execPath = (npmPathIsJs ? process.execPath : npmPath || 'npm') | ||
if (!npmPath && !process.env.npm_execpath) { | ||
// When a script is being run via pnpm, npmPath and npm_execpath will be null or undefined | ||
// Attempt to figure out whether we're running via pnpm | ||
const projectRoot = path.dirname(options.packageInfo.path) | ||
const hasPnpmLockfile = fs.existsSync(path.join(projectRoot, 'pnpm-lock.yaml')) | ||
const { status: pnpmFound, output: pnpmWhichOutput } = await spawn('which', 'pnpm', { silent: true }) | ||
if (hasPnpmLockfile && __dirname.split(path.delimiter).includes('.pnpm') && pnpmFound) { | ||
execPath = pnpmWhichOutput | ||
} | ||
if (!isYarn) { | ||
Array.prototype.push.apply(spawnArgs, options.prefixOptions) | ||
} else if (options.prefixOptions.indexOf('--silent') !== -1) { | ||
spawnArgs.push('--silent') | ||
} | ||
Array.prototype.push.apply(spawnArgs, parseArgs(task).map(cleanTaskArg)) | ||
} | ||
cp = spawn(execPath, spawnArgs, spawnOptions) | ||
const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith('yarn') // eslint-disable-line no-process-env | ||
// Piping stdio. | ||
if (stdinKind === 'pipe') { | ||
stdin.pipe(cp.stdin) | ||
} | ||
if (stdoutKind === 'pipe') { | ||
cp.stdout.pipe(stdout, { end: false }) | ||
} | ||
if (stderrKind === 'pipe') { | ||
cp.stderr.pipe(stderr, { end: false }) | ||
} | ||
const spawnArgs = ['run'] | ||
if (npmPathIsJs) { | ||
spawnArgs.unshift(npmPath) | ||
} | ||
if (!isYarn) { | ||
Array.prototype.push.apply(spawnArgs, options.prefixOptions) | ||
} else if (options.prefixOptions.indexOf('--silent') !== -1) { | ||
spawnArgs.push('--silent') | ||
} | ||
Array.prototype.push.apply(spawnArgs, parseArgs(task).map(cleanTaskArg)) | ||
cp = spawn(execPath, spawnArgs, spawnOptions) | ||
// Piping stdio. | ||
if (stdinKind === 'pipe') { | ||
stdin.pipe(cp.stdin) | ||
} | ||
if (stdoutKind === 'pipe') { | ||
cp.stdout.pipe(stdout, { end: false }) | ||
} | ||
if (stderrKind === 'pipe') { | ||
cp.stderr.pipe(stderr, { end: false }) | ||
} | ||
return new Promise((resolve, reject) => { | ||
// Register | ||
@@ -203,4 +235,6 @@ cp.on('error', (err) => { | ||
}) | ||
}) | ||
} | ||
const promise = asyncRunTask() | ||
promise.abort = function abort () { | ||
@@ -207,0 +241,0 @@ if (cp != null) { |
{ | ||
"name": "npm-run-all2", | ||
"version": "6.0.6", | ||
"version": "6.1.0", | ||
"description": "A CLI tool to run multiple npm-scripts in parallel or sequential. (Maintainence fork)", | ||
@@ -5,0 +5,0 @@ "bin": { |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
91291
1760
11