The calculation entry point had three paths: the worker path, one for a window without a Worker, and an in-process one for no window with its own cancellation, replacement and explanation flags. Date analysis had a main-thread fallback too. Only the worker path remains, on the job the caller passes or the default selection, so every rule of an incomplete calculation is decided once. - The lifecycle module no longer checks the window or imports the planner core at runtime; browsers load the core only in the worker bundle. - One registry holds the live supersession callbacks, the latest calculation identity and the latest date analysis. - A browser with a window but no Worker now reports worker-unavailable even for an invalid request, where it reported invalid input first. - The build forces Angular's chunk optimization: with the lazy core chunk gone the build fell under Angular's three-lazy-chunk threshold and the initial bundle was split and grew. Refs #339 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
28 lines
1.0 KiB
JavaScript
28 lines
1.0 KiB
JavaScript
// One script builds both bundles so they share one identifier: the server refuses clients of other builds.
|
|
import { randomUUID } from 'node:crypto';
|
|
|
|
const define = JSON.stringify(randomUUID());
|
|
const args = process.argv.slice(2).filter((arg, index) => index > 0 || arg !== '--');
|
|
|
|
// `ng build` empties its output path, so the server bundle has to come after it.
|
|
const ng = Bun.spawn(
|
|
['bun', 'run', 'ng', 'build', '--define', `PLANNING_BUILD=${define}`, ...args],
|
|
{
|
|
stdio: ['inherit', 'inherit', 'inherit'],
|
|
// Angular skips its chunk optimization below three lazy chunks, which splits the initial bundle.
|
|
env: { NG_BUILD_OPTIMIZE_CHUNKS: '1', ...process.env },
|
|
},
|
|
);
|
|
const code = await ng.exited;
|
|
if (code !== 0) process.exit(code);
|
|
|
|
const result = await Bun.build({
|
|
entrypoints: ['src/server.ts', 'src/app/services/leave-planner.worker.ts'],
|
|
target: 'bun',
|
|
outdir: 'dist/vac-optimizer/server',
|
|
naming: '[name].[ext]',
|
|
define: { PLANNING_BUILD: define },
|
|
});
|
|
for (const log of result.logs) console.log(log);
|
|
if (!result.success) process.exit(1);
|