Skip to content

Commit 4a4fdc0

Browse files
authored
Fix twoslash in AppHostBuilder; source-control twoslash .d.ts bundle (#741)
The homepage AppHostBuilder component rendered a ts(2307) 'Cannot find module ./.modules/aspire.js' error in the TypeScript view on production, while MDX fenced samples on /get-started/first-app/ worked fine. Root cause: Starlight's <Code> component resolves expressive-code config through astro-expressive-code's virtual module, which loses the runtime extraFiles VFS state in production builds; MDX fences flow through rehype-expressive-code with the live ec.config.mjs instance intact. Changes: - Remove meta=twoslash from AppHostBuilder.astro (not desired there anyway). - Relocate the generated aspire.d.ts bundle from transient .twoslash-types/ to source-controlled src/frontend/src/data/twoslash/aspire.d.ts so diffs are reviewable and dev/build startup is faster (no pre-build generation step). - Chain generate-twoslash-types.ts to run at the tail of update-ts-api.ts so the bundle stays in sync with src/data/ts-modules/*.json. - Drop pnpm twoslash-types from dev/start/build scripts in package.json; keep the manual pnpm twoslash-types script for ad-hoc refreshes. - Update ec.config.mjs, the vitest generator test, .gitignore, and the update-integrations SKILL.md to match the new location and workflow. Validated: unit tests pass (6/6); Playwright crawl against localhost:4321 across 22 docs pages with twoslash blocks reports 0 twoslash errors and rendered hovers intact.
1 parent 4b397e4 commit 4a4fdc0

9 files changed

Lines changed: 17753 additions & 16 deletions

File tree

.github/skills/update-integrations/SKILL.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The aspire.dev site maintains three key data locations:
1515
- **`src/frontend/src/data/integration-docs.json`** — Mappings from package names to site-relative documentation URLs.
1616
- **`src/frontend/src/data/pkgs/`** — Per-package API reference JSON files (e.g. `Aspire.Hosting.Redis.13.1.2.json`) generated by the `PackageJsonGenerator` tool. These feed the auto-generated API reference pages at `/reference/api/`.
1717
- **`src/frontend/src/data/ts-modules/`** — Per-package TypeScript API reference JSON files (e.g. `Aspire.Hosting.Redis.13.2.0.json`) generated by the `AtsJsonGenerator` tool. These feed the auto-generated TypeScript API reference pages at `/reference/api/typescript/`.
18+
- **`src/frontend/src/data/twoslash/aspire.d.ts`** — A single consolidated TypeScript declaration bundle generated from the `ts-modules` JSON by `scripts/generate-twoslash-types.ts`. Consumed by `expressive-code-twoslash` to provide hover tooltips for TypeScript code samples in the docs. **Source-controlled** — commit the diff whenever `ts-modules` changes.
1819

1920
This skill keeps the documentation mappings in sync with the package catalog and regenerates both the C# and TypeScript API reference data.
2021

@@ -200,6 +201,12 @@ The companion `generate-ts-api-json.ps1` script reads the generated C# package J
200201

201202
When a TypeScript module is regenerated for a new package version, stale `ts-modules` JSON files for older versions of that same package are deleted automatically.
202203

204+
After the JSON is refreshed, `update-ts-api` automatically chains `generate-twoslash-types.ts` to rebuild `src/frontend/src/data/twoslash/aspire.d.ts`. This bundle is source-controlled and its diff must be committed alongside the `ts-modules` JSON changes — without it, docs hover tooltips fall back to `any`. If you only need to refresh the bundle (e.g. after a generator script change) without running the full SDK dump, use:
205+
206+
```bash
207+
cd src/frontend && pnpm twoslash-types
208+
```
209+
203210
### 6. Verify all links
204211

205212
For every entry in the updated `integration-docs.json`:
@@ -247,3 +254,4 @@ After running this skill, the agent should report:
247254
- Any packages that could not be mapped (flagged for manual review)
248255
- Number of API reference JSON files generated (success / failed / skipped)
249256
- Any packages that failed API generation, with reasons
257+
- Confirmation that `src/frontend/src/data/twoslash/aspire.d.ts` was refreshed (and that the diff will be committed)

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ test-results/
2020
.astro/
2121
.cache/
2222
.netlify/
23-
.twoslash-types/
2423
tmp/
2524

2625
# Logs

src/frontend/ec.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import ecTwoSlash from 'expressive-code-twoslash';
88
import { pluginDisableCopy } from './src/expressive-code-plugins/disable-copy.mjs';
99

1010
const __dirname = dirname(fileURLToPath(import.meta.url));
11-
const ASPIRE_TYPES_PATH = resolve(__dirname, '.twoslash-types/aspire.d.ts');
11+
const ASPIRE_TYPES_PATH = resolve(__dirname, 'src/data/twoslash/aspire.d.ts');
1212
const aspireTypes = existsSync(ASPIRE_TYPES_PATH)
1313
? readFileSync(ASPIRE_TYPES_PATH, 'utf8')
1414
: '';
1515

1616
if (!aspireTypes) {
1717
// Non-fatal — twoslash blocks that import the SDK will just show `any`.
1818
// Run `pnpm twoslash-types` to refresh.
19-
console.warn('[ec] .twoslash-types/aspire.d.ts missing — run `pnpm twoslash-types`');
19+
console.warn('[ec] src/data/twoslash/aspire.d.ts missing — run `pnpm twoslash-types`');
2020
}
2121

2222
/** @type {import('@astrojs/starlight/expressive-code').StarlightExpressiveCodeOptions} */

src/frontend/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"git-env": "node ./scripts/write-git-env.mjs",
1818
"check-data": "node ./scripts/check-data-files.mjs",
1919
"twoslash-types": "tsx ./scripts/generate-twoslash-types.ts",
20-
"dev": "pnpm git-env && pnpm check-data && pnpm twoslash-types && astro dev",
21-
"dev:host": "pnpm git-env && pnpm check-data && pnpm twoslash-types && astro dev --host",
22-
"start": "pnpm git-env && pnpm check-data && pnpm twoslash-types && astro dev",
23-
"start:host": "pnpm git-env && pnpm check-data && pnpm twoslash-types && astro dev --host",
24-
"build": "pnpm git-env && pnpm twoslash-types && astro build",
25-
"build:skip-search": "pnpm git-env && pnpm twoslash-types && astro build --mode skip-search",
26-
"build:production": "pnpm git-env && pnpm twoslash-types && astro build --mode production",
20+
"dev": "pnpm git-env && pnpm check-data && astro dev",
21+
"dev:host": "pnpm git-env && pnpm check-data && astro dev --host",
22+
"start": "pnpm git-env && pnpm check-data && astro dev",
23+
"start:host": "pnpm git-env && pnpm check-data && astro dev --host",
24+
"build": "pnpm git-env && astro build",
25+
"build:skip-search": "pnpm git-env && astro build --mode skip-search",
26+
"build:production": "pnpm git-env && astro build --mode production",
2727
"preview": "astro preview",
2828
"preview:host": "astro preview --host",
2929
"astro": "pnpm git-env && astro",

src/frontend/scripts/generate-twoslash-types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* in the docs get accurate hover tooltips.
55
*
66
* Reads: src/data/ts-modules/*.json (produced by update-ts-api.ts)
7-
* Writes: .twoslash-types/aspire.d.ts
7+
* Writes: src/data/twoslash/aspire.d.ts (source-controlled — commit updates
8+
* after regenerating).
89
*/
910

1011
import { readdirSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
@@ -14,7 +15,7 @@ import { fileURLToPath } from 'url';
1415
const __dirname = dirname(fileURLToPath(import.meta.url));
1516
const MODULES_DIR = resolve(__dirname, '..', 'src', 'data', 'ts-modules');
1617
const PKGS_DIR = resolve(__dirname, '..', 'src', 'data', 'pkgs');
17-
const OUTPUT_DIR = resolve(__dirname, '..', '.twoslash-types');
18+
const OUTPUT_DIR = resolve(__dirname, '..', 'src', 'data', 'twoslash');
1819
const OUTPUT_FILE = resolve(OUTPUT_DIR, 'aspire.d.ts');
1920

2021
interface Parameter {

src/frontend/scripts/update-ts-api.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ function main(): void {
7979
console.error('❌ Generation failed:', getErrorMessage(error));
8080
process.exit(1);
8181
}
82+
83+
// Refresh the twoslash .d.ts bundle so docs hover tooltips stay in sync
84+
// with the regenerated ts-modules JSON. The bundle is source-controlled
85+
// at src/data/twoslash/aspire.d.ts — commit the diff alongside the JSON.
86+
const generatorScript = resolve(__dirname, 'generate-twoslash-types.ts');
87+
const tsxBin = resolve(__dirname, '..', 'node_modules', 'tsx', 'dist', 'cli.mjs');
88+
console.log('🔄 Regenerating twoslash .d.ts bundle...');
89+
try {
90+
execFileSync(process.execPath, [tsxBin, generatorScript], {
91+
stdio: 'inherit',
92+
cwd: resolve(__dirname, '..'),
93+
});
94+
console.log('✅ Twoslash types refreshed (src/data/twoslash/aspire.d.ts).');
95+
} catch (error: unknown) {
96+
console.error('❌ Twoslash type generation failed:', getErrorMessage(error));
97+
process.exit(1);
98+
}
8299
}
83100

84101
main();

src/frontend/src/components/AppHostBuilder.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ await builder.build().run();`,
12151215
data-variant={key}
12161216
style={key === 'frontend' ? '' : 'display: none;'}
12171217
>
1218-
<Code code={code} lang="ts" title="apphost.ts" meta="twoslash" />
1218+
<Code code={code} lang="ts" title="apphost.ts" />
12191219
</div>
12201220
))
12211221
}

0 commit comments

Comments
 (0)