Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/seven-berries-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bob-the-bundler": patch
---

Run typescript tsc commands in sequence instead of in parallel to avoid race conditions where the `.bob/cjs` or `.bob/esm` folder is missing.
31 changes: 17 additions & 14 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,32 @@ function compilerOptionsToArgs(
return args;
}

function assertTypeScriptBuildResult(result: execa.ExecaReturnValue<string>) {
if (result.exitCode !== 0) {
console.log("TypeScript compiler exited with non-zero exit code.");
console.log(result.stdout);
throw new Error("TypeScript compiler exited with non-zero exit code.");
}
}

async function buildTypeScript(buildPath: string) {
const results = await Promise.all([
execa("npx", [
assertTypeScriptBuildResult(
await execa("npx", [
"tsc",
...compilerOptionsToArgs(typeScriptCompilerOptions("esm")),
"--outDir",
join(buildPath, "esm"),
]),
execa("npx", [
])
);

assertTypeScriptBuildResult(
await execa("npx", [
"tsc",
...compilerOptionsToArgs(typeScriptCompilerOptions("cjs")),
"--outDir",
join(buildPath, "cjs"),
]),
]);

for (const result of results) {
if (result.exitCode !== 0) {
console.log("TypeScript compiler exited with non-zero exit code.");
console.log(result.stdout);
throw new Error("TypeScript compiler exited with non-zero exit code.");
}
}
])
);
}

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