Skip to content

Commit ebab926

Browse files
committed
Fix missing twoslash types silently shipping to production
Two fixes for the post-#729 regression where the live aspire.dev site shipped TS2307 'Cannot find module ./.modules/aspire.js' errors in rendered HTML: 1. ec.config.mjs: throw instead of warn when .twoslash-types/aspire.d.ts is missing. The previous soft fallback let astro build produce broken HTML whenever the deploy pipeline didn't run `pnpm twoslash-types` first. 2. frontend.esproj: add a BuildFrontendForPublish target that runs `pnpm install --frozen-lockfile` and `pnpm run build` before the Publish target. The JS SDK's BuildCommand is gated off via ShouldRunBuildScript=false (kept that way to keep `aspire run` fast), so without an explicit publish-time hook `dotnet publish` would package a stale or empty dist/.
1 parent 12f1da5 commit ebab926

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/frontend/ec.config.mjs

Lines changed: 10 additions & 8 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, '.twoslash-types/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] .twoslash-types/aspire.d.ts missing — run `pnpm twoslash-types`');
13+
// Missing types cause every `import './.modules/aspire.js'` sample to render
14+
// a TS2307 into the generated HTML. A silent warn here previously shipped
15+
// that error to prod — fail the build instead so the gap is caught in CI/deploy.
16+
if (!existsSync(ASPIRE_TYPES_PATH)) {
17+
throw new Error(
18+
`[ec] .twoslash-types/aspire.d.ts not found at ${ASPIRE_TYPES_PATH}. ` +
19+
'Run `pnpm twoslash-types` before `astro build` (the `pnpm build` script chains both).'
20+
);
2021
}
22+
const aspireTypes = readFileSync(ASPIRE_TYPES_PATH, 'utf8');
2123

2224
/** @type {import('@astrojs/starlight/expressive-code').StarlightExpressiveCodeOptions} */
2325
export default {
@@ -57,7 +59,7 @@ export default {
5759
// Virtual files merged into the Twoslash VFS. The Aspire SDK types
5860
// are declared at `.modules/aspire.ts` so docs samples that import
5961
// `'./.modules/aspire.js'` resolve against the real API surface.
60-
extraFiles: aspireTypes ? { '.modules/aspire.ts': aspireTypes } : {},
62+
extraFiles: { '.modules/aspire.ts': aspireTypes },
6163
},
6264
}),
6365
],

src/frontend/frontend.esproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
<PublishAssetsDirectory>$(MSBuildProjectDirectory)/dist</PublishAssetsDirectory>
44
<BuildCommand>pnpm run build</BuildCommand>
55
<ShouldRunNpmInstall>false</ShouldRunNpmInstall>
6-
<!-- Disables running the build (or compile) script located on package.json during Build -->
6+
<!-- Disables running the build (or compile) script located on package.json during Build.
7+
Keeps `aspire run` / dev `dotnet build` fast; publish runs the build via the
8+
BuildFrontendForPublish target below. -->
79
<ShouldRunBuildScript>false</ShouldRunBuildScript>
810
<IntermediateOutputPath>$(MSBuildProjectDirectory)/obj/$(Configuration)</IntermediateOutputPath>
911
</PropertyGroup>
12+
13+
<!-- Ensure dist/ is freshly produced (and .twoslash-types/aspire.d.ts generated)
14+
whenever this project is published. The JS SDK's BuildCommand is gated off above,
15+
so without this target a `dotnet publish` would package a stale or missing dist. -->
16+
<Target Name="BuildFrontendForPublish" BeforeTargets="Publish">
17+
<Message Importance="high" Text="frontend.esproj: running 'pnpm install --frozen-lockfile' before publish" />
18+
<Exec Command="pnpm install --frozen-lockfile" WorkingDirectory="$(MSBuildProjectDirectory)" />
19+
<Message Importance="high" Text="frontend.esproj: running 'pnpm run build' before publish" />
20+
<Exec Command="pnpm run build" WorkingDirectory="$(MSBuildProjectDirectory)" />
21+
</Target>
1022
</Project>

0 commit comments

Comments
 (0)