(file, commandArguments, options)
| 8 | On 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 | */ |
| 10 | export 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` |
| 23 | const directlyExecutableRegExp = /\.(?:com|exe)$/i; |
no test coverage detected