node.js
This file
Path
lib/arguments/node.js
46 lines · 1.4 KiB · JavaScript
Last changed by
Split files (#837)ehmickybefore adoption672c2d7
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–46why, one step back1import {execPath, execArgv} from 'node:process';2import {basename, resolve} from 'node:path';3import {execa} from '../async.js';4import {handleOptionalArguments} from './options.js';5import {safeNormalizeFileUrl} from './cwd.js';67export function execaNode(file, args, options) {8 [args, options] = handleOptionalArguments(args, options);910 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);31 const newOptions = {...options, nodePath: resolvedNodePath, cwd};3233 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};