Skip to content

Commit

Permalink
Fix "tsp vs install" command (#3743)
Browse files Browse the repository at this point in the history
fixes #3615
  • Loading branch information
RodgeFu authored Jul 6, 2024
1 parent b7b36ab commit 53836c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/fix-install-vs-extension-2024-6-3-17-17-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/compiler"
---

Fix 'typespec vs install' command on windows
13 changes: 11 additions & 2 deletions packages/compiler/src/core/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,23 @@ export function run(
command += ".cmd";
}

const useShell = process.platform === "win32";
const hasSpace = command.includes(" ");
let commandToSpawn = command;
if (useShell && hasSpace) {
// for command having space (which should be a path), we need to wrap it into " for it to be executed properly in shell
// but for short command like 'npm', we shouldn't wrap it which would trigger error
commandToSpawn = `"${command}"`;
logger.trace(`Command to spawn updated to: ${commandToSpawn}\n`);
}
const finalOptions: SpawnSyncOptionsWithStringEncoding = {
encoding: "utf-8",
stdio: "inherit",
shell: process.platform === "win32",
shell: useShell,
...(options ?? {}),
};

const proc = spawnSync(command, commandArgs, finalOptions);
const proc = spawnSync(commandToSpawn, commandArgs, finalOptions);
logger.trace(inspect(proc, { depth: null }));

if (proc.error) {
Expand Down

0 comments on commit 53836c5

Please sign in to comment.