|
| 1 | +// Env-var opt-outs that MUST be applied before any `bulletin-deploy` module |
| 2 | +// evaluates. ES-module top-level evaluation is dependency-first + ordered |
| 3 | +// across siblings of the same parent, so importing this module as the very |
| 4 | +// first statement in `src/index.ts` guarantees its side effects run before |
| 5 | +// the `bulletin-deploy` import chain initialises its Sentry / memory-report |
| 6 | +// gates. Plain `process.env.X = "0"` later in `index.ts` is too late — |
| 7 | +// import hoisting would have already loaded Sentry and wired up the |
| 8 | +// threshold-triggered memory report. |
| 9 | +// |
| 10 | +// Why we opt out by default: |
| 11 | +// 1. Sentry buffers breadcrumbs + spans in-memory while it tries to reach |
| 12 | +// its endpoint; on a flaky or long-running deploy this has been seen to |
| 13 | +// balloon `dot`'s RSS. |
| 14 | +// 2. bulletin-deploy's memory-report path calls `v8.getHeapSpaceStatistics()`, |
| 15 | +// which Bun has not implemented. Our CLI ships as a Bun-compiled binary, |
| 16 | +// so reaching that code path kills the deploy with |
| 17 | +// "node:v8 getHeapSpaceStatistics is not yet implemented in Bun." |
| 18 | +// |
| 19 | +// Both gates honour an explicit user override: if the caller sets either |
| 20 | +// env var before invoking `dot`, we leave their choice alone. That lets |
| 21 | +// Parity folks opt back in with `BULLETIN_DEPLOY_TELEMETRY=1 dot deploy` |
| 22 | +// when they want to help debug a deploy. |
| 23 | + |
| 24 | +// Forces ESM module semantics on this otherwise-import-free file. Without it, |
| 25 | +// TS classifies the file as a script and `await import("./bootstrap.js")` |
| 26 | +// resolves to `{ default: undefined }` with no export binding — TS2306 at |
| 27 | +// every callsite in `bootstrap.test.ts`. Keep. |
| 28 | +export {}; |
| 29 | + |
| 30 | +if (process.env.BULLETIN_DEPLOY_TELEMETRY === undefined) { |
| 31 | + process.env.BULLETIN_DEPLOY_TELEMETRY = "0"; |
| 32 | +} |
| 33 | + |
| 34 | +// Defence-in-depth: the memory-report env gate lives inside |
| 35 | +// `maybeWriteMemoryReport`, checked at call time rather than module load. |
| 36 | +// Even if a user explicitly opts telemetry back in, this stops the |
| 37 | +// Bun-incompatible `v8.getHeapSpaceStatistics` call from firing in our |
| 38 | +// Bun-compiled binary. |
| 39 | +if (process.env.BULLETIN_DEPLOY_MEM_REPORT === undefined) { |
| 40 | + process.env.BULLETIN_DEPLOY_MEM_REPORT = "0"; |
| 41 | +} |
0 commit comments