Fix TypeScript apphost for CommonJS projects#16538
Draft
sebastienros wants to merge 2 commits intomicrosoft:mainfrom
Draft
Fix TypeScript apphost for CommonJS projects#16538sebastienros wants to merge 2 commits intomicrosoft:mainfrom
sebastienros wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Generate TypeScript AppHosts with an async main wrapper instead of top-level await so brownfield CommonJS projects can compile and run without changing package module semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16538Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16538" |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Aspire’s TypeScript AppHost scaffolding/templates to work in CommonJS projects by removing top-level await usage, while also updating linting and adding regression coverage across scaffold/init scenarios.
Changes:
- Generate TypeScript AppHosts with an
async function main()wrapper and invoke it viavoid main();(instead of top-levelawait). - Update generated/template ESLint flat config to allow
voidwith@typescript-eslint/no-floating-promises(ignoreVoid: true). - Add unit + CLI E2E regression coverage, including an
aspire initscenario for a CommonJS repo.
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 | Asserts the scaffolded apphost.ts uses main() wrapper and ESLint config includes ignoreVoid. |
| tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotTests.cs | Adds E2E verification for aspire init in a CommonJS repo and validates the generated AppHost runs without the TS1309/top-level-await failure. |
| src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptLanguageSupport.cs | Changes scaffolded apphost.ts to avoid top-level await and updates scaffolded ESLint config to allow void usage. |
| src/Aspire.Cli/Templating/Templates/ts-starter/eslint.config.mjs | Allows void usage for no-floating-promises. |
| src/Aspire.Cli/Templating/Templates/ts-starter/apphost.ts | Wraps starter AppHost logic in async function main() and invokes it. |
| src/Aspire.Cli/Templating/Templates/py-starter/eslint.config.mjs | Allows void usage for no-floating-promises. |
| src/Aspire.Cli/Templating/Templates/py-starter/apphost.ts | Wraps starter AppHost logic in async function main() and invokes it. |
Use main().catch(...) in generated TypeScript AppHosts so startup failures produce deterministic diagnostics and a non-zero exit code without relying on unhandled rejections. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16124
async function main()wrapper instead of top-level await so brownfield CommonJS projects work without changing package module semantics.void main()with@typescript-eslint/no-floating-promises.aspire initin existing CommonJS and ESM package configurations.