MCPcopy Create free account
hub / github.com/sindresorhus/execa / parseCommandFile

Function parseCommandFile

lib/arguments/command-file.js:10–20  ·  view source on GitHub ↗
(file, commandArguments, options)

Source from the content-addressed store, hash-verified

8On Windows, `node:child_process` cannot natively run many kinds of files (`.cmd`, `.bat`, shebang scripts, ...): without a shell it resolves neither `PATHEXT` nor shebangs, and it does not escape arguments. We resolve the command to its full file path and escape its arguments ourselves, so those work without an explicit shell, just like on Unix, where the OS handles all of this for us.
9*/
10export const parseCommandFile = (file, commandArguments, options) => {
11 // The arguments are cloned since a shebang interpreter might be prepended below, which must not mutate the caller's array
12 const parsed = {file, commandArguments: [...commandArguments], options};
13
14 // Under a shell, or on Unix, the OS resolves the file and escapes the arguments itself
15 if (options.shell || process.platform !== 'win32') {
16 return parsed;
17 }
18
19 return escapeWindowsCommand(parsed);
20};
21
22// Only `.exe` and `.com` files can be spawned directly; anything else needs `cmd.exe`
23const directlyExecutableRegExp = /\.(?:com|exe)$/i;

Callers 1

normalizeOptionsFunction · 0.90

Calls 1

escapeWindowsCommandFunction · 0.85

Tested by

no test coverage detected