Skip to content
Myr

node.js

This file

Path

lib/methods/node.js

63 lines · 1.8 KiB · JavaScript

Last changed by

Harden against prototype pollution (#1223)Sindre Sorhusbefore adoptionf3a2e84

History of this file

Take it

Rename files (#977)ehmickybefore adoption4b2e316

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';

Rename files (#977)ehmickybefore adoption4b2e316

lines 3–4why, one step back
3import {safeNormalizeFileUrl} from '../arguments/file-url.js';
4

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

line 5why, one step back
5// `execaNode()` is a shortcut for `execa(..., {node: true})`

Rename files (#977)ehmickybefore adoption4b2e316

lines 6–13why, one step back
6export 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};13

Add more code comments (#984)ehmickybefore adoptionfdd8a9f

lines 14–16why, one step back
14// 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 back
17export const handleNodeOption = (file, commandArguments, {

Rename files (#977)ehmickybefore adoption4b2e316

lines 18–19why, one step back
18 node: shouldHandleNode = false,
19 nodePath = execPath,

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 20why, one step back
20 nodeOptions = execArgv.filter(nodeOption => !nodeOption.startsWith('--inspect')),

Rename files (#977)ehmickybefore adoption4b2e316

lines 21–29why, one step back
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

Upgrade xo (#980)ehmickybefore adoptionccfa412

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,

Upgrade xo (#980)ehmickybefore adoptionccfa412

lines 35–39why, one step back
35 ...options,
36 nodePath: resolvedNodePath,37 node: shouldHandleNode,38 cwd,39 };

Rename files (#977)ehmickybefore adoption4b2e316

lines 40–41why, one step back
40
41 if (!shouldHandleNode) {

Upgrade xo (#980)ehmickybefore adoptionccfa412

line 42why, one step back
42 return [file, commandArguments, newOptions];

Rename files (#977)ehmickybefore adoption4b2e316

lines 43–44why, one step back
43 }
44

Upgrade dependencies (#1138)ehmickybefore adoptionabd9fd0

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

Rename files (#977)ehmickybefore adoption4b2e316

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 },

Rename files (#977)ehmickybefore adoption4b2e316

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