diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ce90126..48814d8ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Features: - Add support for Presets v9, which enables more macro expansion for the `include` field. [#3946](https://github.com/microsoft/vscode-cmake-tools/issues/3946) +Improvements: + +- Ensure that any uses of `proc.spawn` work, especially for .bat and .cmd files, due to VS Code updating to Node 20. [#4037](https://github.com/microsoft/vscode-cmake-tools/issues/4037) + Bug Fixes: - Fix our setting of `isUserPreset` for presets, only set it to `true` if it's defined in a user presets file. [#4059](https://github.com/microsoft/vscode-cmake-tools/issues/4059) diff --git a/src/proc.ts b/src/proc.ts index fb4bf0973..1c042412c 100644 --- a/src/proc.ts +++ b/src/proc.ts @@ -95,7 +95,7 @@ export interface ExecutionResult { export interface ExecutionOptions { environment?: Environment; - shell?: boolean; + shell?: boolean | string; silent?: boolean; cwd?: string; encoding?: BufferEncoding; @@ -113,6 +113,18 @@ export function buildCmdStr(command: string, args?: string[]): string { return cmdarr.map(a => /[ \n\r\f;\t]/.test(a) ? `"${a}"` : a).join(' '); } +export function determineShell(command: string): string | boolean { + if (command.endsWith('.cmd') || command.endsWith('.bat')) { + return 'cmd'; + } + + if (command.endsWith('.ps1')) { + return 'powershell'; + } + + return false; +} + /** * Execute a command and return the result * @param command The binary to execute @@ -146,6 +158,11 @@ export function execute(command: string, args?: string[], outputConsumer?: Outpu log.debug(localize('execution.environment', ' with environment: {0}', JSON.stringify(final_env))); } } + + if (process.platform === "win32" && options.shell === undefined) { + options.shell = determineShell(command); + } + const spawn_opts: proc.SpawnOptions = { env: final_env, shell: !!options.shell