1/**
2 * Entry point for the benchmark. The app hands this command to whoever is
3 * running the demo, so it has to survive landing on a machine with an older
4 * Node than this repo develops against: Node only strips TypeScript types by
5 * default from 22.18 / 23.6 / 24 on, and without stripping it cannot load
6 * scripts/bench.ts at all — not even far enough to print a useful error.
7 *
8 * So this wrapper is plain JS, and re-executes itself with the flag when the
9 * running Node has stripping available but off (22.6 through 22.17).
10 */
11import { spawnSync } from 'node:child_process';
12import { fileURLToPath } from 'node:url';
14if (process.features.typescript) {
15 await import('./bench.ts');
16} else {
17 const entry = fileURLToPath(new URL('./bench.ts', import.meta.url));
18 const result = spawnSync(
19 process.execPath,
20 [
21 '--experimental-strip-types',
22 '--disable-warning=ExperimentalWarning',
23 entry,
24 ...process.argv.slice(2),
25 ],
26 { stdio: 'inherit' },
27 );
28 // exit code 9 is node's "bad option": this Node predates type stripping
29 if (result.error || result.status === 9) {
30 console.error(
31 `bench: Node ${process.versions.node} cannot run this project's TypeScript sources.\n` +
32 ' Node 22.6+ can with --experimental-strip-types; 22.18, 23.6 and 24+ do it by default.',
33 );
34 process.exit(1);
35 }
36 process.exit(result.status ?? 1);
37}