Skip to content

Commit

Permalink
fix runtime builds
Browse files Browse the repository at this point in the history
  • Loading branch information
info-miura committed Jan 23, 2025
1 parent 6d02790 commit ba237e6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
},
"[javascript]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit",
},
"editor.defaultFormatter": "biomejs.biome",
"editor.formatOnSave": true,
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
},
Expand Down
67 changes: 67 additions & 0 deletions src/Sekiban.Infrastructure.IndexedDb/Runtime/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// @ts-check

import child_process from "node:child_process";
import fs from "node:fs/promises";
import process from "node:process";

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const obtainLock = async () => {
try {
await fs.mkdir("build-lock");
return true;
} catch (e) {
if (e.code === "EEXIST") {
return false;
}

throw new Error(e.message, { cause: e });
}
};

const releaseLock = async () => await fs.rmdir("build-lock");

const waitAnotherBuild = async () => {
while (true) {
await sleep(1000);

try {
await fs.stat("build-lock");
} catch (e) {
if (e.code === "ENOENT") {
return;
}

throw new Error(e.message, { cause: e });
}
}
};

const main = async () => {
if (!(await obtainLock())) {
// An another build task is running concurrently.
// Wait until it done.
await waitAnotherBuild();
process.exit(0);
}

try {
const restore = child_process.spawnSync("npm", ["install"], {
stdio: "inherit",
});
if (restore.status !== 0) {
process.exit(restore.status);
}

const build = child_process.spawnSync("npm", ["run", "build"], {
stdio: "inherit",
});
if (build.status !== 0) {
process.exit(build.status);
}
} finally {
await releaseLock();
}
};

main();
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
<None Include="..\README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<Target Name="Build runtime" BeforeTargets="DispatchToInnerBuilds">
<Exec Command="npm install" WorkingDirectory="Runtime" />
<Exec Command="npm run build" WorkingDirectory="Runtime" />
<Target Name="Build runtime" BeforeTargets="BeforeBuild">
<Exec Command="node build.js" WorkingDirectory="Runtime" />
</Target>

</Project>

0 comments on commit ba237e6

Please sign in to comment.