Skip to content
Myr

node.js

This file

Path

lib/arguments/node.js

42 lines · 1.3 KiB · JavaScript

Last changed by

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

History of this file

Take it

Split files (#837)ehmickybefore adoption672c2d7

lines 1–4why, one step back
1import {execPath, execArgv} from 'node:process';
2import {basename, resolve} from 'node:path';3import {safeNormalizeFileUrl} from './cwd.js';4

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

line 5why, one step back
5export const mapNode = ({options}) => {

Split files (#837)ehmickybefore adoption672c2d7

lines 6–9why, one step back
6 if (options.node === false) {
7 throw new TypeError('The "node" option cannot be false with `execaNode()`.');8 }9

Allow template strings with all methods (#933)ehmickybefore adoption8074d85

lines 10–11why, one step back
10 return {options: {...options, node: true}};
11};

Split files (#837)ehmickybefore adoption672c2d7

lines 12–26why, one step back
12
13export const handleNodeOption = (file, args, {14 node: shouldHandleNode = false,15 nodePath = execPath,16 nodeOptions = execArgv.filter(arg => !arg.startsWith('--inspect')),17 cwd,18 execPath: formerNodePath,19 ...options20}) => {21 if (formerNodePath !== undefined) {22 throw new TypeError('The "execPath" option has been removed. Please use the "nodePath" option instead.');23 }2425 const normalizedNodePath = safeNormalizeFileUrl(nodePath, 'The "nodePath" option');26 const resolvedNodePath = resolve(cwd, normalizedNodePath);

Improve interaction of the `preferLocal`, `node` and `nodePath` options (#841)ehmickybefore adoptionb965682

line 27why, one step back
27 const newOptions = {...options, nodePath: resolvedNodePath, node: shouldHandleNode, cwd};

Split files (#837)ehmickybefore adoption672c2d7

lines 28–42why, one step back
28
29 if (!shouldHandleNode) {30 return [file, args, newOptions];31 }3233 if (basename(file, '.exe') === 'node') {34 throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');35 }3637 return [38 resolvedNodePath,39 [...nodeOptions, file, ...args],40 {ipc: true, ...newOptions, shell: false},41 ];42};