Skip to content

Commit ebd52aa

Browse files
committed
feat: implement Workers-safe dependency validation
1 parent b9cbbed commit ebd52aa

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
"coverage": "vitest run --coverage",
171171
"generate": "curl https://raw.githubusercontent.com/google-a2a/A2A/refs/heads/main/specification/json/a2a.json > spec.json && node scripts/generateTypes.js && rm spec.json",
172172
"generate:compat": "curl https://raw.githubusercontent.com/a2aproject/A2A/v0.3.0/specification/json/a2a.json > compat_spec.json && node scripts/generateCompatTypes.js && rm compat_spec.json",
173-
"test-build": "esbuild ./dist/client/index.js ./dist/server/index.js ./dist/index.js ./dist/errors/index.js ./dist/errors/grpc/index.js ./dist/compat/v0_3/index.js ./dist/compat/v0_3/client/index.js ./dist/compat/v0_3/server/index.js --bundle --platform=neutral --outdir=dist/tmp-checks --outbase=./dist",
173+
"test-build": "esbuild ./dist/client/index.js ./dist/server/index.js ./dist/index.js ./dist/errors/index.js ./dist/errors/grpc/index.js ./dist/compat/v0_3/index.js ./dist/compat/v0_3/client/index.js ./dist/compat/v0_3/server/index.js --bundle --platform=neutral --outdir=dist/tmp-checks --outbase=./dist && node scripts/checkWorkersSafeBundles.js",
174174
"itk-agent": "tsx itk/itk_agent.ts"
175175
},
176176
"dependencies": {

scripts/checkWorkersSafeBundles.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Verifies that entrypoints declared Workers-safe never pull in
2+
// Node-only peer deps (`@grpc/grpc-js`) or the pb-generated code
3+
// path (`@bufbuild/protobuf`). Any hit fails the build.
4+
//
5+
// Run after `npm run build && npm run test-build`. Consumed by the
6+
// `test-build` script and the `Run Build Tests` CI workflow.
7+
8+
import { readFileSync } from 'node:fs';
9+
import { resolve } from 'node:path';
10+
11+
// Bundles that MUST NOT reference gRPC or pb at all.
12+
const WORKERS_SAFE_BUNDLES = [
13+
'dist/tmp-checks/index.js',
14+
'dist/tmp-checks/errors/index.js',
15+
'dist/tmp-checks/client/index.js',
16+
'dist/tmp-checks/server/index.js',
17+
'dist/tmp-checks/compat/v0_3/index.js',
18+
'dist/tmp-checks/compat/v0_3/client/index.js',
19+
'dist/tmp-checks/compat/v0_3/server/index.js',
20+
];
21+
22+
const FORBIDDEN = ['@grpc/grpc-js', '@bufbuild/protobuf'];
23+
24+
let failed = false;
25+
for (const rel of WORKERS_SAFE_BUNDLES) {
26+
const abs = resolve(rel);
27+
let content;
28+
try {
29+
content = readFileSync(abs, 'utf8');
30+
} catch (e) {
31+
console.error(
32+
`FAIL: cannot read ${rel} — did you run \`npm run build && esbuild\`? (${e.message})`
33+
);
34+
failed = true;
35+
continue;
36+
}
37+
const hits = FORBIDDEN.filter((needle) => content.includes(needle));
38+
if (hits.length > 0) {
39+
console.error(
40+
`FAIL: ${rel} contains ${hits.join(', ')} — Workers-safe entrypoint must not pull Node-only deps`
41+
);
42+
failed = true;
43+
} else {
44+
console.log(`ok: ${rel} — no Node-only deps`);
45+
}
46+
}
47+
48+
if (failed) process.exit(1);

0 commit comments

Comments
 (0)