Skip to content

Commit 086c1a8

Browse files
authored
fix: race conditions of tsc (#96)
1 parent 714c80d commit 086c1a8

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

.changeset/seven-berries-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bob-the-bundler": patch
3+
---
4+
5+
Run typescript tsc commands in sequence instead of in parallel to avoid race conditions where the `.bob/cjs` or `.bob/esm` folder is missing.

src/commands/build.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,32 @@ function compilerOptionsToArgs(
6464
return args;
6565
}
6666

67+
function assertTypeScriptBuildResult(result: execa.ExecaReturnValue<string>) {
68+
if (result.exitCode !== 0) {
69+
console.log("TypeScript compiler exited with non-zero exit code.");
70+
console.log(result.stdout);
71+
throw new Error("TypeScript compiler exited with non-zero exit code.");
72+
}
73+
}
74+
6775
async function buildTypeScript(buildPath: string) {
68-
const results = await Promise.all([
69-
execa("npx", [
76+
assertTypeScriptBuildResult(
77+
await execa("npx", [
7078
"tsc",
7179
...compilerOptionsToArgs(typeScriptCompilerOptions("esm")),
7280
"--outDir",
7381
join(buildPath, "esm"),
74-
]),
75-
execa("npx", [
82+
])
83+
);
84+
85+
assertTypeScriptBuildResult(
86+
await execa("npx", [
7687
"tsc",
7788
...compilerOptionsToArgs(typeScriptCompilerOptions("cjs")),
7889
"--outDir",
7990
join(buildPath, "cjs"),
80-
]),
81-
]);
82-
83-
for (const result of results) {
84-
if (result.exitCode !== 0) {
85-
console.log("TypeScript compiler exited with non-zero exit code.");
86-
console.log(result.stdout);
87-
throw new Error("TypeScript compiler exited with non-zero exit code.");
88-
}
89-
}
91+
])
92+
);
9093
}
9194

9295
export const buildCommand = createCommand<{}, {}>((api) => {

0 commit comments

Comments
 (0)