node.js
This file
Path
lib/arguments/node.js
46 lines · 1.4 KiB · JavaScript
Last changed by
Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–3why, one step back1import {execPath, execArgv} from 'node:process';2import {basename, resolve} from 'node:path';3import {execa} from '../async.js';Improve input validation (#838)ehmickybefore adoption8ee137c
line 4why, one step back4import {normalizeArguments} from './options.js';Split files (#837)ehmickybefore adoption672c2d7
lines 5–7why, one step back5import {safeNormalizeFileUrl} from './cwd.js';67export function execaNode(file, args, options) {Improve input validation (#838)ehmickybefore adoption8ee137c
line 8why, one step back8 [file, args, options] = normalizeArguments(file, args, options);Split files (#837)ehmickybefore adoption672c2d7
lines 9–30why, one step back910 if (options.node === false) {11 throw new TypeError('The "node" option cannot be false with `execaNode()`.');12 }1314 return execa(file, args, {...options, node: true});15}1617export const handleNodeOption = (file, args, {18 node: shouldHandleNode = false,19 nodePath = execPath,20 nodeOptions = execArgv.filter(arg => !arg.startsWith('--inspect')),21 cwd,22 execPath: formerNodePath,23 ...options24}) => {25 if (formerNodePath !== undefined) {26 throw new TypeError('The "execPath" option has been removed. Please use the "nodePath" option instead.');27 }2829 const normalizedNodePath = safeNormalizeFileUrl(nodePath, 'The "nodePath" option');30 const resolvedNodePath = resolve(cwd, normalizedNodePath);Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682
line 31why, one step back31 const newOptions = {...options, nodePath: resolvedNodePath, node: shouldHandleNode, cwd};Split files (#837)ehmickybefore adoption672c2d7
lines 32–46why, one step back3233 if (!shouldHandleNode) {34 return [file, args, newOptions];35 }3637 if (basename(file, '.exe') === 'node') {38 throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');39 }4041 return [42 resolvedNodePath,43 [...nodeOptions, file, ...args],44 {ipc: true, ...newOptions, shell: false},45 ];46};