node.js
This file
Path
lib/methods/node.js
51 lines · 1.6 KiB · JavaScript
Last changed by
Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
History of this fileTake it
Rename files (#977)ehmickybefore adoption4b2e316
line 1why, one step back1import {execPath, execArgv} from 'node:process';Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 2why, one step back2import path from 'node:path';Rename files (#977)ehmickybefore adoption4b2e316
lines 3–4why, one step back3import {safeNormalizeFileUrl} from '../arguments/file-url.js';4Add more code comments (#984)ehmickybefore adoptionfdd8a9f
line 5why, one step back5// `execaNode()` is a shortcut for `execa(..., {node: true})`Rename files (#977)ehmickybefore adoption4b2e316
lines 6–13why, one step back6export const mapNode = ({options}) => {7 if (options.node === false) {8 throw new TypeError('The "node" option cannot be false with `execaNode()`.');9 }1011 return {options: {...options, node: true}};12};13Add more code comments (#984)ehmickybefore adoptionfdd8a9f
lines 14–16why, one step back14// Applies the `node: true` option, and the related `nodePath`/`nodeOptions` options.15// Modifies the file commands/arguments to ensure the same Node binary and flags are re-used.16// Also adds `ipc: true` and `shell: false`.Upgrade xo (#980)ehmickybefore adoptionccfa412
line 17why, one step back17export const handleNodeOption = (file, commandArguments, {Rename files (#977)ehmickybefore adoption4b2e316
lines 18–19why, one step back18 node: shouldHandleNode = false,19 nodePath = execPath,Upgrade xo (#980)ehmickybefore adoptionccfa412
line 20why, one step back20 nodeOptions = execArgv.filter(nodeOption => !nodeOption.startsWith('--inspect')),Rename files (#977)ehmickybefore adoption4b2e316
lines 21–29why, one step back21 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');Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 30why, one step back30 const resolvedNodePath = path.resolve(cwd, normalizedNodePath);Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 31–36why, one step back31 const newOptions = {32 ...options,33 nodePath: resolvedNodePath,34 node: shouldHandleNode,35 cwd,36 };Rename files (#977)ehmickybefore adoption4b2e316
lines 37–38why, one step back3738 if (!shouldHandleNode) {Upgrade xo (#980)ehmickybefore adoptionccfa412
line 39why, one step back39 return [file, commandArguments, newOptions];Rename files (#977)ehmickybefore adoption4b2e316
lines 40–41why, one step back40 }41Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 42why, one step back42 if (path.basename(file, '.exe') === 'node') {Rename files (#977)ehmickybefore adoption4b2e316
lines 43–47why, one step back43 throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');44 }4546 return [47 resolvedNodePath,Upgrade xo (#980)ehmickybefore adoptionccfa412
line 48why, one step back48 [...nodeOptions, file, ...commandArguments],Rename files (#977)ehmickybefore adoption4b2e316
lines 49–51why, one step back49 {ipc: true, ...newOptions, shell: false},50 ];51};