-
Notifications
You must be signed in to change notification settings - Fork 69
Harden twoslash config against silent regressions #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,15 +9,17 @@ import { pluginDisableCopy } from './src/expressive-code-plugins/disable-copy.mj | |||||||||||||||||
|
|
||||||||||||||||||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||||||||||||||||||
| const ASPIRE_TYPES_PATH = resolve(__dirname, 'src/data/twoslash/aspire.d.ts'); | ||||||||||||||||||
| const aspireTypes = existsSync(ASPIRE_TYPES_PATH) | ||||||||||||||||||
| ? readFileSync(ASPIRE_TYPES_PATH, 'utf8') | ||||||||||||||||||
| : ''; | ||||||||||||||||||
|
|
||||||||||||||||||
| if (!aspireTypes) { | ||||||||||||||||||
| // Non-fatal — twoslash blocks that import the SDK will just show `any`. | ||||||||||||||||||
| // Run `pnpm twoslash-types` to refresh. | ||||||||||||||||||
| console.warn('[ec] src/data/twoslash/aspire.d.ts missing — run `pnpm twoslash-types`'); | ||||||||||||||||||
| // The bundle is source-controlled (see #741), so a missing file means the | ||||||||||||||||||
| // tree is corrupted — not a normal path. Fail the build rather than silently | ||||||||||||||||||
| // shipping samples that can't resolve `./.modules/aspire.js`. | ||||||||||||||||||
| if (!existsSync(ASPIRE_TYPES_PATH)) { | ||||||||||||||||||
| throw new Error( | ||||||||||||||||||
| `[ec] src/data/twoslash/aspire.d.ts not found at ${ASPIRE_TYPES_PATH}. ` + | ||||||||||||||||||
| 'Run `pnpm twoslash-types` to regenerate it from src/data/ts-modules.' | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
| const aspireTypes = readFileSync(ASPIRE_TYPES_PATH, 'utf8'); | ||||||||||||||||||
|
Comment on lines
+16
to
+22
|
||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
| if (aspireTypes.trim().length === 0) { | |
| throw new Error( | |
| `[ec] src/data/twoslash/aspire.d.ts is empty at ${ASPIRE_TYPES_PATH}. ` + | |
| 'Run `pnpm twoslash-types` to regenerate it from src/data/ts-modules.' | |
| ); | |
| } |
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new behavior, an empty (or whitespace-only) aspire.d.ts will still pass and will populate .modules/aspire.ts with empty content, which can re-introduce the ‘silent regression’ this PR is trying to prevent (imports resolve, but types effectively disappear). Consider validating aspireTypes.trim().length > 0 and throwing with a clear message if it’s empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message includes an absolute path, which can leak runner/workspace paths into public CI logs. Consider switching to a relative path in the message (e.g., relative to
process.cwd()), while still keeping enough context to debug locally.