Skip to content

Commit 5eecbb6

Browse files
committed
Harden twoslash config against silent regressions
Two small defensive changes on top of #741: - Throw instead of warn when src/data/twoslash/aspire.d.ts is missing. Since #741 source-controls the bundle, a missing file means the tree is corrupted — catching that at build time beats silently shipping samples that can't resolve `./.modules/aspire.js`. - Flip noErrorValidation to false so unannotated TS errors fail the build rather than rendering as squigglies in the shipped HTML. Samples that deliberately illustrate a compiler error can opt in with `// @errors: <codes>`; otherwise an error means the sample (or the generated SDK shape) is wrong and should be fixed, not shown to readers. Verified with a full build: zero unannotated errors across the current docs.
1 parent 4a4fdc0 commit 5eecbb6

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/frontend/ec.config.mjs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ import { pluginDisableCopy } from './src/expressive-code-plugins/disable-copy.mj
99

1010
const __dirname = dirname(fileURLToPath(import.meta.url));
1111
const ASPIRE_TYPES_PATH = resolve(__dirname, 'src/data/twoslash/aspire.d.ts');
12-
const aspireTypes = existsSync(ASPIRE_TYPES_PATH)
13-
? readFileSync(ASPIRE_TYPES_PATH, 'utf8')
14-
: '';
1512

16-
if (!aspireTypes) {
17-
// Non-fatal — twoslash blocks that import the SDK will just show `any`.
18-
// Run `pnpm twoslash-types` to refresh.
19-
console.warn('[ec] src/data/twoslash/aspire.d.ts missing — run `pnpm twoslash-types`');
13+
// The bundle is source-controlled (see #741), so a missing file means the
14+
// tree is corrupted — not a normal path. Fail the build rather than silently
15+
// shipping samples that can't resolve `./.modules/aspire.js`.
16+
if (!existsSync(ASPIRE_TYPES_PATH)) {
17+
throw new Error(
18+
`[ec] src/data/twoslash/aspire.d.ts not found at ${ASPIRE_TYPES_PATH}. ` +
19+
'Run `pnpm twoslash-types` to regenerate it from src/data/ts-modules.'
20+
);
2021
}
22+
const aspireTypes = readFileSync(ASPIRE_TYPES_PATH, 'utf8');
2123

2224
/** @type {import('@astrojs/starlight/expressive-code').StarlightExpressiveCodeOptions} */
2325
export default {
@@ -49,15 +51,17 @@ export default {
4951
// an explicit `lib` array breaks those references in the VFS.
5052
},
5153
handbookOptions: {
52-
// Keep type squigglies rendered inline but don't fail the build when
53-
// a sample has unannotated compiler errors — the generated SDK is a
54-
// best-effort shape and docs samples shouldn't need `// @errors` tags.
55-
noErrorValidation: true,
54+
// Fail the build on unannotated TS errors instead of rendering them
55+
// as squigglies in shipped HTML. Blocks that deliberately illustrate
56+
// a compiler error must opt in with `// @errors: <codes>`; otherwise
57+
// an error means the sample (or the generated SDK shape) is wrong
58+
// and should be fixed, not rendered to readers.
59+
noErrorValidation: false,
5660
},
5761
// Virtual files merged into the Twoslash VFS. The Aspire SDK types
5862
// are declared at `.modules/aspire.ts` so docs samples that import
5963
// `'./.modules/aspire.js'` resolve against the real API surface.
60-
extraFiles: aspireTypes ? { '.modules/aspire.ts': aspireTypes } : {},
64+
extraFiles: { '.modules/aspire.ts': aspireTypes },
6165
},
6266
}),
6367
],

0 commit comments

Comments
 (0)