node.js
This file
Path
lib/methods/node.js
63 lines · 1.8 KiB · JavaScript
Last changed by
Harden some thingsSindre Sorhusbefore adoption4a0a121
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–10why, one step back6export const mapNode = ({options}) => {7 if (options.node === false) {8 throw new TypeError('The "node" option cannot be false with `execaNode()`.');9 }10Harden some thingsSindre Sorhusbefore adoption4a0a121
line 11why, one step back11 return {options: {__proto__: null, ...options, node: true}};Rename files (#977)ehmickybefore adoption4b2e316
lines 12–13why, one step back12};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);Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84
line 31why, one step back31 // Use spread (which only copies own properties) to safely get shell without reading polluted prototypeUpgrade xo (#980)ehmickybefore adoptionccfa412
line 32why, one step back32 const newOptions = {Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84
lines 33–34why, one step back33 __proto__: null,34 shell: false,Upgrade xo (#980)ehmickybefore adoptionccfa412
lines 35–39why, one step back35 ...options,36 nodePath: resolvedNodePath,37 node: shouldHandleNode,38 cwd,39 };Rename files (#977)ehmickybefore adoption4b2e316
lines 40–41why, one step back4041 if (!shouldHandleNode) {Upgrade xo (#980)ehmickybefore adoptionccfa412
line 42why, one step back42 return [file, commandArguments, newOptions];Rename files (#977)ehmickybefore adoption4b2e316
lines 43–44why, one step back43 }44Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 45why, one step back45 if (path.basename(file, '.exe') === 'node') {Rename files (#977)ehmickybefore adoption4b2e316
lines 46–50why, one step back46 throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');47 }4849 return [50 resolvedNodePath,Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84
lines 51–61why, one step back51 [52 ...nodeOptions,53 file,54 ...commandArguments,55 ],56 {57 __proto__: null,58 ipc: true,59 ...newOptions,60 shell: false,61 },Rename files (#977)ehmickybefore adoption4b2e316
lines 62–63why, one step back62 ];63};