fix: add missing await on mkdir and node:module external in esbuild config

- Add await to fs.mkdir() call in generateDevices() (line 60). Without
  this, writeFile can race ahead of directory creation, causing ENOENT
  on clean builds or slower machines.
- Add 'node:module' to the externals array. Node.js treats 'module' and
  'node:module' as distinct specifiers; esbuild fails to resolve the
  prefixed form when bundling for the browser target.

Discovered during Docker builds on ARM64 where the race window is wider
due to slower I/O. Also reproduces on x86_64 with a clean src/pack/.
This commit is contained in:
Gary Ingle 2026-04-12 19:05:14 +02:00 committed by Stewart Allen
commit 6ba7507938

View file

@ -57,7 +57,7 @@ async function generateDevices(dir = '') {
}
}
let dstr = JSON.stringify(devs);
fs.mkdir(path.join(dir, "src", "pack"), { recursive: true });
await fs.mkdir(path.join(dir, "src", "pack"), { recursive: true });
await fs.writeFile(path.join(dir, "src", "pack", "kiri-devs.js"), `export const devices = ${dstr};`);
if (true) {
// create alt artifacts
@ -77,6 +77,7 @@ const rec = {
define: { 'process.env.NODE_ENV': `"${mode}"` },
external: [
'module',
'node:module',
'./constants',
'./voronoi_structures',
'./voronoi_ctypes',