Skip to content

Commit 6ab5d35

Browse files
committed
Parallelize frontend verification phases
1 parent c5e4836 commit 6ab5d35

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"orbit:test:cli": "node scripts/orbit-cli-tests.mjs",
3939
"orbit:test": "npm run orbit:test:content && npm run orbit:test:cli",
4040
"actions:scope:test": "node --test scripts/orbit-actions-scope-tests.mjs",
41-
"verify:frontend:production": "npm run orbit:test:content && npm run check && npm run og:generate && npm run worker:assets:production:live && ORBIT_DIST_DIR=dist/client npm run site:test && ORBIT_DIST_DIR=dist/client npm run browser:test && npm run production:config:check && npm run worker:bundle:production:live",
41+
"verify:frontend:production": "node scripts/orbit-frontend-production-verify.mjs",
4242
"site:test": "node scripts/orbit-site-tests.mjs",
4343
"browser:test": "node scripts/orbit-browser-tests.mjs",
4444
"og:generate": "node scripts/orbit-og-images.mjs",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
import { spawn } from 'node:child_process';
3+
4+
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
5+
6+
function runScript(script, extraEnv = {}) {
7+
return new Promise((resolve, reject) => {
8+
const child = spawn(npmCommand, ['run', script], {
9+
env: { ...process.env, ...extraEnv },
10+
stdio: 'inherit',
11+
});
12+
13+
child.on('error', reject);
14+
child.on('exit', (code, signal) => {
15+
if (code === 0) {
16+
resolve();
17+
return;
18+
}
19+
reject(new Error(`${script} failed (${signal ?? `exit ${code}`})`));
20+
});
21+
});
22+
}
23+
24+
async function runPhase(label, tasks) {
25+
const results = await Promise.allSettled(tasks.map(({ script, env }) => runScript(script, env)));
26+
const failures = results
27+
.map((result, index) => ({ result, script: tasks[index].script }))
28+
.filter(({ result }) => result.status === 'rejected');
29+
30+
if (failures.length > 0) {
31+
const summary = failures.map(({ script, result }) => `${script}: ${result.reason}`).join('\n');
32+
throw new Error(`${label} phase failed:\n${summary}`);
33+
}
34+
}
35+
36+
await runPhase('source validation', [
37+
{ script: 'orbit:test:content' },
38+
{ script: 'check' },
39+
{ script: 'og:generate' },
40+
]);
41+
42+
await runScript('worker:assets:production:live');
43+
44+
await runPhase('built artifact validation', [
45+
{ script: 'site:test', env: { ORBIT_DIST_DIR: 'dist/client' } },
46+
{ script: 'browser:test', env: { ORBIT_DIST_DIR: 'dist/client' } },
47+
{ script: 'production:config:check' },
48+
{ script: 'worker:bundle:production:live' },
49+
]);

0 commit comments

Comments
 (0)