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
The walk stopped after 200 commits: lines older than 7cde496 point at it.
Move API reference to its own page (#996)ehmickybefore adoption7cde496
line 1why, one step back1import {execPath, execArgv} from 'node:process';Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 2why, one step back2import path from 'node:path';Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 3–10why, one step back3import {safeNormalizeFileUrl} from '../arguments/file-url.js';45// `execaNode()` is a shortcut for `execa(..., {node: true})`6export 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}};Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 12–29why, one step back12};1314// 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`.17export const handleNodeOption = (file, commandArguments, {18 node: shouldHandleNode = false,19 nodePath = execPath,20 nodeOptions = execArgv.filter(nodeOption => !nodeOption.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');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 prototypeMove API reference to its own page (#996)ehmickybefore adoption7cde496
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,Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 35–44why, one step back35 ...options,36 nodePath: resolvedNodePath,37 node: shouldHandleNode,38 cwd,39 };4041 if (!shouldHandleNode) {42 return [file, commandArguments, newOptions];43 }44Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0
line 45why, one step back45 if (path.basename(file, '.exe') === 'node') {Move API reference to its own page (#996)ehmickybefore adoption7cde496
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 },Move API reference to its own page (#996)ehmickybefore adoption7cde496
lines 62–63why, one step back62 ];63};