Validate TypeScript AppHosts before startup#16689
Conversation
Add a pre-execute runtime hook and use it to run TypeScript type validation before starting or publishing TypeScript AppHosts. Watch mode validates on every restart so startup is not blocked by existing errors while editing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16689Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16689" |
There was a problem hiding this comment.
Pull request overview
Adds a new RuntimeSpec.PreExecute hook to run validation commands before executing guest-language AppHosts, and uses it to type-check TypeScript AppHosts with tsc --noEmit so aspire run/start fails fast instead of partially starting (e.g., launching the dashboard while the AppHost has TS compile errors).
Changes:
- Introduces
RuntimeSpec.PreExecute(public API) and updatesGuestRuntimeto run pre-execution commands beforeExecute/PublishExecute. - Updates TypeScript runtime specs (and toolchain overrides for bun/yarn/pnpm) to run
tsc --noEmit -p tsconfig.apphost.jsonbefore normal execution; watch commands embed the same validation in the watcher restart command. - Adds/updates unit tests to validate
PreExecutebehavior and the generated command lines for TypeScript runtimes.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/TypeScriptLanguageSupportTests.cs | Verifies TypeScript runtime spec now includes pre-execution tsc validation and updated watch exec command. |
| tests/Aspire.Cli.Tests/Projects/TypeScriptAppHostToolchainResolverTests.cs | Extends toolchain resolver tests to assert PreExecute and updated watch command strings; adds pnpm coverage. |
| tests/Aspire.Cli.Tests/Projects/GuestRuntimeTests.cs | Adds tests ensuring PreExecute runs before execute/publish and is skipped when watch spec is used; improves recording launcher. |
| src/Aspire.TypeSystem/RuntimeSpec.cs | Adds new public PreExecute property to runtime spec model. |
| src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptLanguageSupport.cs | Emits PreExecute (npx ... tsc --noEmit) and embeds type-check in the watch nodemon --exec command. |
| src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs | Adds toolchain-specific PreExecute + updates watch commands (notably bun now uses bun x nodemon ...). |
| src/Aspire.Cli/Projects/GuestRuntime.cs | Executes PreExecute before Execute/PublishExecute, skipping it when using WatchExecute; factors env merge into a helper. |
Clarify the PreExecute contract and make Bun typecheck/watch commands use project-local binaries via bun run instead of bun x. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use Yarn run for project-local TypeScript tools so arguments are forwarded correctly, and update the TypeScript publish E2E fixture to use the typed dashboard options shape. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Since this adds around 1s (on an M4) for each run or change (watch) ... should we try |
|
🎬 CLI E2E Test Recordings — 75 recordings uploaded (commit View all recordings
📹 Recordings uploaded automatically from CI run #25239644372 |
|
Does this need to be done up front? Could we instead try to run the AppHost, see the failure, and then run this to give a good error message. That makes it zero cost for good files, which would be the vast majority or the time. |
|
Alternatively, cache the result, and only run the check when the apphost changes |
Description
TypeScript AppHosts currently run through
tsx, which transpiles without type validation. This meansaspire runandaspire startcan launch the dashboard even when the AppHost has TypeScript compile errors, leaving users with a partially started and confusing app.This adds a
PreExecuteruntime hook and uses it for TypeScript AppHosts to runtsc --noEmit -p tsconfig.apphost.jsonbefore normal run and publish execution. Watch mode embeds the same validation into the nodemon restart command so the watcher can still start when there are initial type errors and recover as the user edits.Measured startup impact on a new React TypeScript AppHost template: the added
tsc --noEmit -p tsconfig.apphost.jsonvalidation costs about 0.8s on warm runs, with a cold first run around 1.0s.Example compile error:
With this change,
aspire runstops before the AppHost starts and displays thetscdiagnostic:Fixes #16645
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: