All files / player-terminal/src sea-main.ts

0% Statements 0/12
0% Branches 0/12
0% Functions 0/2
0% Lines 0/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27                                                     
import { isMainThread, workerData } from 'node:worker_threads';
import { resolveSEAWorkerRole } from './node/sea-worker.ts';
 
// Entry of the SEA bundle (see `scripts/build-sea.ts`). The embedded bundle doubles as the script for the
// gameplay / UI / BGA-video workers: SEA binaries cannot load worker files from disk, so those workers are
// spawned as eval workers re-running an asset copy of this bundle (see `./node/sea-worker.ts`). Dispatch on
// the workerData role marker before the CLI entry gets a chance to run.
function resolveSEAEntryModule(): Promise<unknown> {
  const seaWorkerRole = isMainThread ? undefined : resolveSEAWorkerRole(workerData);
  if (seaWorkerRole === 'node-gameplay-worker') {
    return import('./node/node-gameplay-worker.ts');
  }
  if (seaWorkerRole === 'node-ui-worker') {
    return import('./node/node-ui-worker.ts');
  }
  if (seaWorkerRole === 'bga-video-worker') {
    return import('./bga-video-worker.ts');
  }
  return import('./cli.ts');
}
 
void resolveSEAEntryModule().catch((error: unknown) => {
  const message = error instanceof Error && error.stack ? error.stack : String(error);
  process.stderr.write(`${message}\n`);
  process.exitCode = 1;
});