Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than ceb1069 point at it.

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

line 1why, one step back
1import {execPath, execArgv} from 'node:process';

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

line 2why, one step back
2import path from 'node:path';

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

lines 3–10why, one step back
3import {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 }10

Harden some thingsSindre Sorhusbefore adoption4a0a121

line 11why, one step back
11 return {options: {__proto__: null, ...options, node: true}};

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

lines 12–29why, one step back
12};
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 back
30 const resolvedNodePath = path.resolve(cwd, normalizedNodePath);

Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84

line 31why, one step back
31 // Use spread (which only copies own properties) to safely get shell without reading polluted prototype

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

line 32why, one step back
32 const newOptions = {

Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84

lines 33–34why, one step back
33 __proto__: null,
34 shell: false,

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

lines 35–44why, one step back
35 ...options,
36 nodePath: resolvedNodePath,37 node: shouldHandleNode,38 cwd,39 };4041 if (!shouldHandleNode) {42 return [file, commandArguments, newOptions];43 }44

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

line 45why, one step back
45 if (path.basename(file, '.exe') === 'node') {

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

lines 46–50why, one step back
46 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 back
51 [
52 ...nodeOptions,53 file,54 ...commandArguments,55 ],56 {57 __proto__: null,58 ipc: true,59 ...newOptions,60 shell: false,61 },

Re-order sections in API reference (#994)ehmickybefore adoptionceb1069

lines 62–63why, one step back
62 ];
63};