From 20c8f342b1a2c1181428110f71ffa57fc8583b7a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 4 Dec 2023 08:52:34 -0800 Subject: [PATCH 01/12] Stop logging the proc info when a command fails --- eng/scripts/check-format.js | 11 +++-- eng/scripts/cspell.js | 4 +- eng/scripts/dogfood.js | 8 +-- eng/scripts/format.js | 4 +- eng/scripts/helpers.js | 55 +++------------------ eng/scripts/watch.js | 4 +- packages/internal-build-utils/src/common.ts | 20 ++++++++ 7 files changed, 45 insertions(+), 61 deletions(-) diff --git a/eng/scripts/check-format.js b/eng/scripts/check-format.js index 64d2f84911..1f3832c2c9 100644 --- a/eng/scripts/check-format.js +++ b/eng/scripts/check-format.js @@ -1,20 +1,21 @@ // @ts-check import { + CommandFailedError, ensureDotnetVersion, runDotnetFormat, } from "../../packages/internal-build-utils/dist/src/index.js"; -import { CommandFailedError, runPrettier } from "./helpers.js"; +import { runPrettier } from "./helpers.js"; try { - runPrettier("--list-different"); - ensureDotnetVersion({ exitWithSuccessInDevBuilds: true }); - runDotnetFormat("--verify-no-changes"); + await runPrettier("--list-different"); + await ensureDotnetVersion({ exitWithSuccessInDevBuilds: true }); + await runDotnetFormat("--verify-no-changes"); } catch (err) { if (err instanceof CommandFailedError) { console.error( "\nERROR: Files above are not formatted correctly. Run `rush format` and commit the changes." ); - process.exit(err.proc?.status ?? 1); + process.exit(err.proc?.exitCode ?? 1); } throw err; } diff --git a/eng/scripts/cspell.js b/eng/scripts/cspell.js index 3270496ea5..ea32c8a07e 100644 --- a/eng/scripts/cspell.js +++ b/eng/scripts/cspell.js @@ -1,12 +1,12 @@ // @ts-check import { resolve } from "path"; -import { run, xplatCmd } from "../../packages/internal-build-utils/dist/src/index.js"; +import { runOrExit, xplatCmd } from "../../packages/internal-build-utils/dist/src/index.js"; import { repoRoot } from "./helpers.js"; export const cspell = xplatCmd( resolve(repoRoot, "packages/internal-build-utils/node_modules/.bin/cspell") ); -await run( +await runOrExit( cspell, [ "--no-progress", diff --git a/eng/scripts/dogfood.js b/eng/scripts/dogfood.js index adf89f539e..718c03505c 100644 --- a/eng/scripts/dogfood.js +++ b/eng/scripts/dogfood.js @@ -1,4 +1,6 @@ -import { npmForEach, run } from "./helpers.js"; -run("rush", ["update"]); -run("rush", ["build"]); +// @ts-check +import { runOrExit } from "../../packages/internal-build-utils/dist/src/common.js"; +import { npmForEach } from "./helpers.js"; +await runOrExit("rush", ["update"]); +await runOrExit("rush", ["build"]); npmForEach("dogfood"); diff --git a/eng/scripts/format.js b/eng/scripts/format.js index a03feb69ef..87742fde2d 100644 --- a/eng/scripts/format.js +++ b/eng/scripts/format.js @@ -1,10 +1,12 @@ // @ts-check import { ensureDotnetVersion, + exitOnFailedCommand, runDotnetFormat, } from "../../packages/internal-build-utils/dist/src/index.js"; import { runPrettier } from "./helpers.js"; -runPrettier("--write"); + +await exitOnFailedCommand(() => runPrettier("--write")); await ensureDotnetVersion({ exitWithSuccessInDevBuilds: true }); await runDotnetFormat(); diff --git a/eng/scripts/helpers.js b/eng/scripts/helpers.js index 032511121a..470d9fdc21 100644 --- a/eng/scripts/helpers.js +++ b/eng/scripts/helpers.js @@ -1,7 +1,8 @@ -import { spawn, spawnSync } from "child_process"; +// @ts-check import { readFileSync } from "fs"; import { dirname, join, resolve } from "path"; import { fileURLToPath } from "url"; +import { run, runOrExit } from "../../packages/internal-build-utils/dist/src/index.js"; function read(filename) { const txt = readFileSync(filename, "utf-8") @@ -41,7 +42,7 @@ export function npmForEachDependency(cmd, projectDir, options) { forEachProject((name, location, project) => { if (project.scripts[cmd] || cmd === "pack") { const args = cmd === "pack" ? [cmd] : ["run", cmd]; - run("npm", args, { cwd: location, ...options }); + runOrExit("npm", args, { cwd: location, ...options }); } }, deps); } @@ -55,57 +56,13 @@ export function npmForEach(cmd, options) { if (project.scripts[cmd] || cmd === "pack") { const args = cmd === "pack" ? [cmd] : ["run", cmd]; - run("npm", args, { cwd: location, ...options }); + runOrExit("npm", args, { cwd: location, ...options }); } }); } -// We could use { shell: true } to let Windows find .cmd, but that causes other issues. -// It breaks ENOENT checking for command-not-found and also handles command/args with spaces -// poorly. -const isCmdOnWindows = ["rush", "npm", "code", "code-insiders", "docusaurus", tsc, prettier]; - -export class CommandFailedError extends Error { - constructor(msg, proc) { - super(msg); - this.proc = proc; - } -} - -export function run(command, args, options) { - console.log(); - console.log(`> ${command} ${args.join(" ")}`); - - options = { - stdio: "inherit", - sync: true, - throwOnNonZeroExit: true, - ...options, - }; - - if (process.platform === "win32" && isCmdOnWindows.includes(command)) { - command += ".cmd"; - } - - const proc = (options.sync ? spawnSync : spawn)(command, args, options); - if (proc.error) { - if (options.ignoreCommandNotFound && proc.error.code === "ENOENT") { - console.log(`Skipped: Command \`${command}\` not found.`); - } else { - throw proc.error; - } - } else if (options.throwOnNonZeroExit && proc.status !== undefined && proc.status !== 0) { - throw new CommandFailedError( - `Command \`${command} ${args.join(" ")}\` failed with exit code ${proc.status}`, - proc - ); - } - - return proc; -} - -export function runPrettier(...args) { - run( +export async function runPrettier(...args) { + await run( prettier, [ ...args, diff --git a/eng/scripts/watch.js b/eng/scripts/watch.js index 9405bbcbb5..88f4385db9 100644 --- a/eng/scripts/watch.js +++ b/eng/scripts/watch.js @@ -1,2 +1,4 @@ -import { repoRoot, run, tsc } from "./helpers.js"; +import { run } from "../../packages/internal-build-utils/dist/src/index.js"; +import { repoRoot, tsc } from "./helpers.js"; + run(tsc, ["--build", "--watch"], { cwd: repoRoot, sync: false }); diff --git a/packages/internal-build-utils/src/common.ts b/packages/internal-build-utils/src/common.ts index 5f86255487..59b84019fe 100644 --- a/packages/internal-build-utils/src/common.ts +++ b/packages/internal-build-utils/src/common.ts @@ -25,6 +25,26 @@ export interface RunOptions extends SpawnOptions { throwOnNonZeroExit?: boolean; } +/** Run the given command and exit if command return non zero exit code. */ +export async function runOrExit(command: string, args: string[], options?: RunOptions) { + return exitOnFailedCommand(() => run(command, args, options)); +} + +export async function exitOnFailedCommand(cb: () => Promise) { + try { + await cb(); + } catch (e: any) { + if (e instanceof CommandFailedError) { + // eslint-disable-next-line no-console + console.error(e.message); + process.exit(e.proc.exitCode ?? -1); + } else { + throw e; + } + } +} + +/** Run the given command or throw CommandFailedError if the command returns non zero exit code. */ export async function run(command: string, args: string[], options?: RunOptions) { if (!options?.silent) { // eslint-disable-next-line no-console From bbabc4d830f4f8c8e8c089a7baabefc0ac938dae Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 4 Dec 2023 09:09:52 -0800 Subject: [PATCH 02/12] Fix --- common/config/rush/pnpm-lock.yaml | 3 +++ packages/website/.scripts/docusaurus-build.mjs | 2 +- packages/website/package.json | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index b1fb5df1ca..771e8018f7 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -1579,6 +1579,9 @@ importers: '@typespec/http': specifier: workspace:~0.50.0 version: link:../http + '@typespec/internal-build-utils': + specifier: workspace:~0.50.0 + version: link:../internal-build-utils '@typespec/json-schema': specifier: workspace:~0.50.0 version: link:../json-schema diff --git a/packages/website/.scripts/docusaurus-build.mjs b/packages/website/.scripts/docusaurus-build.mjs index 78e267f798..a929ef3d87 100644 --- a/packages/website/.scripts/docusaurus-build.mjs +++ b/packages/website/.scripts/docusaurus-build.mjs @@ -1,10 +1,10 @@ #!/usr/bin/env node // @ts-check +import { run } from "@typespec/internal-build-utils"; import dotenv from "dotenv"; import path from "path"; import { fileURLToPath } from "url"; -import { run } from "../../../eng/scripts/helpers.js"; loadDotenv(); diff --git a/packages/website/package.json b/packages/website/package.json index 7245c420a5..00e674c4ea 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -60,6 +60,7 @@ "playwright": "^1.39.0", "mermaid": "~10.4.0", "@typespec/eslint-config-typespec": "workspace:~0.50.0", + "@typespec/internal-build-utils": "workspace:~0.50.0", "eslint": "^8.49.0", "file-loader": "~6.2.0", "monaco-editor-webpack-plugin": "~7.1.0", From 98c653762fa471a66a9e80cf7a6521227d6226a2 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 4 Dec 2023 09:14:39 -0800 Subject: [PATCH 03/12] changelog --- .../internal-remove-proc-log_2023-12-04-17-14.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json diff --git a/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json b/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json new file mode 100644 index 0000000000..c20d24fb42 --- /dev/null +++ b/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/internal-build-utils", + "comment": "Add `runOrExit` helper to have a cleaner script runner without carying about the failure", + "type": "none" + } + ], + "packageName": "@typespec/internal-build-utils" +} \ No newline at end of file From 45ad3d9199f3775de294195f8ee979fc1f0d915f Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 4 Dec 2023 09:30:17 -0800 Subject: [PATCH 04/12] . --- eng/scripts/merge-coverage.js | 6 ++++-- packages/website/.scripts/docusaurus-build.mjs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/eng/scripts/merge-coverage.js b/eng/scripts/merge-coverage.js index 61c5dc2bc3..d7dd8c0615 100644 --- a/eng/scripts/merge-coverage.js +++ b/eng/scripts/merge-coverage.js @@ -1,6 +1,8 @@ +// @ts-check import { copyFileSync, existsSync, mkdirSync, readdirSync } from "fs"; import { join } from "path"; -import { forEachProject, repoRoot, run } from "./helpers.js"; +import { runOrExit } from "../../packages/internal-build-utils/dist/src/index.js"; +import { forEachProject, repoRoot } from "./helpers.js"; // Create folder to collect all coverage files const rootCoverageTmp = join(repoRoot, "coverage", "tmp"); @@ -18,7 +20,7 @@ forEachProject((name, location, project) => { }); // Generate merged report -run( +await runOrExit( "npm", [ "exec", diff --git a/packages/website/.scripts/docusaurus-build.mjs b/packages/website/.scripts/docusaurus-build.mjs index a929ef3d87..4c94038c76 100644 --- a/packages/website/.scripts/docusaurus-build.mjs +++ b/packages/website/.scripts/docusaurus-build.mjs @@ -1,7 +1,7 @@ #!/usr/bin/env node // @ts-check -import { run } from "@typespec/internal-build-utils"; +import { runOrExit } from "@typespec/internal-build-utils"; import dotenv from "dotenv"; import path from "path"; import { fileURLToPath } from "url"; @@ -13,7 +13,7 @@ if (process.env.TYPESPEC_SKIP_DOCUSAURUS_BUILD?.toLowerCase() === "true") { process.exit(0); } -run("docusaurus", ["build"]); +await runOrExit("docusaurus", ["build"]); function loadDotenv() { const dirname = path.dirname(fileURLToPath(import.meta.url)); From 144c11b86e65ab78a92c3303f268f7bcf79a41af Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 4 Dec 2023 09:54:19 -0800 Subject: [PATCH 05/12] fix --- eng/scripts/check-for-changed-files.js | 5 ++-- packages/internal-build-utils/src/common.ts | 26 ++++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/eng/scripts/check-for-changed-files.js b/eng/scripts/check-for-changed-files.js index 3b10e472c2..d5194f3661 100644 --- a/eng/scripts/check-for-changed-files.js +++ b/eng/scripts/check-for-changed-files.js @@ -1,6 +1,7 @@ -import { run } from "./helpers.js"; +// @ts-check +import { runOrExit } from "../../packages/internal-build-utils/dist/src/common.js"; -const proc = run("git", ["status", "--porcelain"], { +const proc = await runOrExit("git", ["status", "--porcelain"], { encoding: "utf-8", stdio: [null, "pipe", "pipe"], }); diff --git a/packages/internal-build-utils/src/common.ts b/packages/internal-build-utils/src/common.ts index 59b84019fe..92053fc303 100644 --- a/packages/internal-build-utils/src/common.ts +++ b/packages/internal-build-utils/src/common.ts @@ -26,13 +26,17 @@ export interface RunOptions extends SpawnOptions { } /** Run the given command and exit if command return non zero exit code. */ -export async function runOrExit(command: string, args: string[], options?: RunOptions) { +export async function runOrExit( + command: string, + args: string[], + options?: RunOptions +): Promise { return exitOnFailedCommand(() => run(command, args, options)); } -export async function exitOnFailedCommand(cb: () => Promise) { +export async function exitOnFailedCommand(cb: () => Promise): Promise { try { - await cb(); + return await cb(); } catch (e: any) { if (e instanceof CommandFailedError) { // eslint-disable-next-line no-console @@ -45,7 +49,11 @@ export async function exitOnFailedCommand(cb: () => Promise) { } /** Run the given command or throw CommandFailedError if the command returns non zero exit code. */ -export async function run(command: string, args: string[], options?: RunOptions) { +export async function run( + command: string, + args: string[], + options?: RunOptions +): Promise { if (!options?.silent) { // eslint-disable-next-line no-console console.log(); @@ -72,18 +80,24 @@ export async function run(command: string, args: string[], options?: RunOptions) if (options.ignoreCommandNotFound && e.code === "ENOENT") { // eslint-disable-next-line no-console console.log(`Skipped: Command \`${command}\` not found.`); - return { exitCode: 0, stdout: "", stderr: "" }; + return { exitCode: 0, stdout: "", stderr: "" } as any; } else { throw e; } } } +export interface ExecResult { + exitCode: number; + stdout: string; + stderr: string; + proc: ChildProcess; +} export async function execAsync( command: string, args: string[], options: SpawnOptions -): Promise<{ exitCode: number; stdout: string; stderr: string; proc: ChildProcess }> { +): Promise { const child = spawn(command, args, options); return new Promise((resolve, reject) => { From f533c616bb21dd1b73f5b1cd71885e6803c17f28 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 4 Dec 2023 10:20:16 -0800 Subject: [PATCH 06/12] fix --- e2e/e2e-tests.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/e2e/e2e-tests.js b/e2e/e2e-tests.js index 8a330c9ac7..4e908515fe 100644 --- a/e2e/e2e-tests.js +++ b/e2e/e2e-tests.js @@ -1,18 +1,19 @@ // @ts-check import { existsSync, readdirSync, rmSync, writeFileSync } from "fs"; import { join } from "path"; -import { repoRoot, run } from "../eng/scripts/helpers.js"; +import { repoRoot } from "../eng/scripts/helpers.js"; +import { runOrExit } from "../packages/internal-build-utils/dist/src/index.js"; const e2eTestDir = join(repoRoot, "e2e"); const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx"; -function main() { +async function main() { printInfo(); cleanE2EDirectory(); const packages = packPackages(); console.log("Check packages exists"); - run("ls", [`${repoRoot}/common/temp/artifacts/packages`]); + await runOrExit("ls", [`${repoRoot}/common/temp/artifacts/packages`]); console.log("Check cli is working"); runTypeSpec(packages["@typespec/compiler"], ["--help"], { cwd: e2eTestDir }); @@ -21,21 +22,21 @@ function main() { testBasicLatest(packages); testBasicCurrentTgz(packages); } -main(); +await main(); function printInfo() { console.log("-".repeat(100)); console.log("Npm Version: "); - run("npm", ["-v"]); + runOrExit("npm", ["-v"]); console.log("-".repeat(100)); } function cleanE2EDirectory() { - run("git", ["clean", "-xfd"], { cwd: e2eTestDir }); + runOrExit("git", ["clean", "-xfd"], { cwd: e2eTestDir }); } -function packPackages() { - run("rush", ["publish", "--publish", "--pack", "--include-all"]); +async function packPackages() { + await runOrExit("rush", ["publish", "--publish", "--pack", "--include-all"]); const outputFolder = join(repoRoot, "common/temp/artifacts/packages"); const files = readdirSync(outputFolder); console.log("Built packages:", files); @@ -58,8 +59,8 @@ function packPackages() { }; } -function runTypeSpec(compilerTgz, args, options) { - run(npxCmd, ["-y", "-p", compilerTgz, "tsp", ...args], { ...options }); +async function runTypeSpec(compilerTgz, args, options) { + await runOrExit(npxCmd, ["-y", "-p", compilerTgz, "tsp", ...args], { ...options }); } function testBasicLatest(packages) { From 8528507565b8ecf2016c7e1364aaa5039e6c5eb5 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 5 Dec 2023 09:58:30 -0800 Subject: [PATCH 07/12] test --- e2e/e2e-tests.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/e2e/e2e-tests.js b/e2e/e2e-tests.js index 4e908515fe..839db8e6dd 100644 --- a/e2e/e2e-tests.js +++ b/e2e/e2e-tests.js @@ -10,7 +10,7 @@ const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx"; async function main() { printInfo(); cleanE2EDirectory(); - const packages = packPackages(); + const packages = await packPackages(); console.log("Check packages exists"); await runOrExit("ls", [`${repoRoot}/common/temp/artifacts/packages`]); @@ -83,7 +83,7 @@ function testBasicLatest(packages) { expectOpenApiOutput(outputDir); } -function testBasicCurrentTgz(packages) { +async function testBasicCurrentTgz(packages) { const basicCurrentDir = join(e2eTestDir, "basic-current"); const outputDir = join(basicCurrentDir, "tsp-output"); console.log("Clearing basic-current"); @@ -107,13 +107,17 @@ function testBasicCurrentTgz(packages) { console.log("Generated package.json for basic-current"); console.log("Installing basic-current dependencies"); - runTypeSpec(packages["@typespec/compiler"], ["install"], { cwd: basicCurrentDir }); + await runTypeSpec(packages["@typespec/compiler"], ["install"], { cwd: basicCurrentDir }); console.log("Installed basic-current dependencies"); console.log(`Running tsp compile . in "${basicCurrentDir}"`); - runTypeSpec(packages["@typespec/compiler"], ["compile", ".", "--emit", "@typespec/openapi3"], { - cwd: basicCurrentDir, - }); + await runTypeSpec( + packages["@typespec/compiler"], + ["compile", ".", "--emit", "@typespec/openapi3"], + { + cwd: basicCurrentDir, + } + ); console.log("Completed tsp compile ."); expectOpenApiOutput(outputDir); From 225b87d0c052b881b65524a2b44b0fbe83ed6c13 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 5 Dec 2023 10:55:44 -0800 Subject: [PATCH 08/12] . --- e2e/e2e-tests.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/e2e/e2e-tests.js b/e2e/e2e-tests.js index 839db8e6dd..532f6e8182 100644 --- a/e2e/e2e-tests.js +++ b/e2e/e2e-tests.js @@ -9,18 +9,18 @@ const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx"; async function main() { printInfo(); - cleanE2EDirectory(); + await cleanE2EDirectory(); const packages = await packPackages(); console.log("Check packages exists"); await runOrExit("ls", [`${repoRoot}/common/temp/artifacts/packages`]); console.log("Check cli is working"); - runTypeSpec(packages["@typespec/compiler"], ["--help"], { cwd: e2eTestDir }); + await runTypeSpec(packages["@typespec/compiler"], ["--help"], { cwd: e2eTestDir }); console.log("Cli is working"); - testBasicLatest(packages); - testBasicCurrentTgz(packages); + await testBasicLatest(packages); + await testBasicCurrentTgz(packages); } await main(); @@ -31,8 +31,8 @@ function printInfo() { console.log("-".repeat(100)); } -function cleanE2EDirectory() { - runOrExit("git", ["clean", "-xfd"], { cwd: e2eTestDir }); +async function cleanE2EDirectory() { + await runOrExit("git", ["clean", "-xfd"], { cwd: e2eTestDir }); } async function packPackages() { @@ -63,7 +63,7 @@ async function runTypeSpec(compilerTgz, args, options) { await runOrExit(npxCmd, ["-y", "-p", compilerTgz, "tsp", ...args], { ...options }); } -function testBasicLatest(packages) { +async function testBasicLatest(packages) { const basicLatestDir = join(e2eTestDir, "basic-latest"); const outputDir = join(basicLatestDir, "tsp-output"); console.log("Clearing basic-latest output"); @@ -71,13 +71,17 @@ function testBasicLatest(packages) { console.log("Cleared basic-latest output"); console.log("Installing basic-latest dependencies"); - runTypeSpec(packages["@typespec/compiler"], ["install"], { cwd: basicLatestDir }); + await runTypeSpec(packages["@typespec/compiler"], ["install"], { cwd: basicLatestDir }); console.log("Installed basic-latest dependencies"); console.log("Running tsp compile ."); - runTypeSpec(packages["@typespec/compiler"], ["compile", ".", "--emit", "@typespec/openapi3"], { - cwd: basicLatestDir, - }); + await runTypeSpec( + packages["@typespec/compiler"], + ["compile", ".", "--emit", "@typespec/openapi3"], + { + cwd: basicLatestDir, + } + ); console.log("Completed tsp compile ."); expectOpenApiOutput(outputDir); From 0a7ab7190d442aaef0f88d470ca0e9510f38627e Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 5 Dec 2023 11:18:47 -0800 Subject: [PATCH 09/12] resolve --- packages/internal-build-utils/src/common.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/internal-build-utils/src/common.ts b/packages/internal-build-utils/src/common.ts index 92053fc303..f6e9a43d60 100644 --- a/packages/internal-build-utils/src/common.ts +++ b/packages/internal-build-utils/src/common.ts @@ -48,6 +48,8 @@ export async function exitOnFailedCommand(cb: () => Promise): Promise { } } +const isCmdOnWindows = ["rush", "npm", "code", "code-insiders", "docusaurus", "tsc", "prettier"]; + /** Run the given command or throw CommandFailedError if the command returns non zero exit code. */ export async function run( command: string, @@ -67,6 +69,13 @@ export async function run( ...options, }; + if ( + (process.platform === "win32" && isCmdOnWindows.includes(command)) || + isCmdOnWindows.some((x) => command.endsWith(`/${x}`)) + ) { + command += ".cmd"; + } + try { const result = await execAsync(command, args, options); if (options.throwOnNonZeroExit && result.exitCode !== undefined && result.exitCode !== 0) { From 8b35b7eee169fce8158263c93af35d4450a5b04c Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 5 Dec 2023 11:43:37 -0800 Subject: [PATCH 10/12] . --- packages/internal-build-utils/src/common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/internal-build-utils/src/common.ts b/packages/internal-build-utils/src/common.ts index f6e9a43d60..30e00a4ffd 100644 --- a/packages/internal-build-utils/src/common.ts +++ b/packages/internal-build-utils/src/common.ts @@ -70,8 +70,8 @@ export async function run( }; if ( - (process.platform === "win32" && isCmdOnWindows.includes(command)) || - isCmdOnWindows.some((x) => command.endsWith(`/${x}`)) + process.platform === "win32" && + (isCmdOnWindows.includes(command) || isCmdOnWindows.some((x) => command.endsWith(`/${x}`))) ) { command += ".cmd"; } From 7b67d4e09ffcaa071f545e650ab0456087fd54d6 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 18 Dec 2023 14:59:19 -0800 Subject: [PATCH 11/12] fix update --- common/config/rush/pnpm-lock.yaml | 2 +- packages/website/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 8fcebd883b..04711497e2 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -1584,7 +1584,7 @@ importers: specifier: workspace:~0.51.0 version: link:../http '@typespec/internal-build-utils': - specifier: workspace:~0.50.0 + specifier: workspace:~0.51.0 version: link:../internal-build-utils '@typespec/json-schema': specifier: workspace:~0.51.0 diff --git a/packages/website/package.json b/packages/website/package.json index 7a92755d6e..8e9b6e8f92 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -60,7 +60,7 @@ "playwright": "^1.39.0", "mermaid": "~10.4.0", "@typespec/eslint-config-typespec": "workspace:~0.51.0", - "@typespec/internal-build-utils": "workspace:~0.50.0", + "@typespec/internal-build-utils": "workspace:~0.51.0", "eslint": "^8.55.0", "file-loader": "~6.2.0", "monaco-editor-webpack-plugin": "~7.1.0", From 0a586d8641b21ff4613a8860f00369ff53d492cf Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 4 Jan 2024 10:44:05 -0800 Subject: [PATCH 12/12] Update common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json Co-authored-by: Brian Terlson --- .../internal-remove-proc-log_2023-12-04-17-14.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json b/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json index c20d24fb42..b789ad5076 100644 --- a/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json +++ b/common/changes/@typespec/internal-build-utils/internal-remove-proc-log_2023-12-04-17-14.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@typespec/internal-build-utils", - "comment": "Add `runOrExit` helper to have a cleaner script runner without carying about the failure", + "comment": "Add `runOrExit` helper to have a cleaner script runner without caring about the failure", "type": "none" } ],