|
| 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