Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "tsp vs install" command #3743

Merged
merged 6 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading