Skip to content

Fix TypeScript apphost for CommonJS projects#16538

Draft
sebastienros wants to merge 2 commits intomicrosoft:mainfrom
sebastienros:sebros/fix-ts-apphost
Draft

Fix TypeScript apphost for CommonJS projects#16538
sebastienros wants to merge 2 commits intomicrosoft:mainfrom
sebastienros:sebros/fix-ts-apphost

Conversation

@sebastienros
Copy link
Copy Markdown
Contributor

@sebastienros sebastienros commented Apr 28, 2026

Fixes #16124

  • Generate TypeScript AppHosts with an async function main() wrapper instead of top-level await so brownfield CommonJS projects work without changing package module semantics.
  • Update generated ESLint config to allow void main() with @typescript-eslint/no-floating-promises.
  • Add regression coverage for scaffolded TypeScript AppHosts and aspire init in existing CommonJS and ESM package configurations.
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>
Copilot AI review requested due to automatic review settings April 28, 2026 23:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16538

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16538"
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via void main(); (instead of top-level await).
  • Update generated/template ESLint flat config to allow void with @typescript-eslint/no-floating-promises (ignoreVoid: true).
  • Add unit + CLI E2E regression coverage, including an aspire init scenario 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.
Comment thread src/Aspire.Hosting.CodeGeneration.TypeScript/TypeScriptLanguageSupport.cs Outdated
Comment thread src/Aspire.Cli/Templating/Templates/ts-starter/apphost.ts Outdated
Comment thread src/Aspire.Cli/Templating/Templates/py-starter/apphost.ts Outdated
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants