Skip to content

Fix TypeScript AppHost package manager detection - #16558

Merged
Sébastien Ros (sebastienros) merged 5 commits into
microsoft:mainfrom
sebastienros:sebastienros/sebros-template-yarn
Apr 30, 2026
Merged

Fix TypeScript AppHost package manager detection#16558
Sébastien Ros (sebastienros) merged 5 commits into
microsoft:mainfrom
sebastienros:sebastienros/sebros-template-yarn

Conversation

@sebastienros

Copy link
Copy Markdown
Contributor

TypeScript AppHost package-manager detection could accidentally inherit a distant parent yarn.lock, causing npm-based generated projects to run through Yarn. This is especially visible for aspire new TypeScript starter projects created under a repository that already has a top-level Yarn marker.

This change treats package-lock.json as an npm marker, limits package-manager probing to the AppHost directory plus one eligible parent, and skips parent probing when that parent is the filesystem root or user home directory. The resolver now logs the exact marker used for the package-manager decision, which should make future diagnosis easier.

Tests added/updated cover npm lockfile detection, parent-only probing, root/home parent skipping, and the debug reason log.

Validation:

./dotnet.sh test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.TypeScriptAppHostToolchainResolverTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"

Treat package-lock.json as an npm marker and limit parent directory package manager probing to the AppHost directory's direct parent. Log the marker used to select the TypeScript AppHost package manager.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

🚀 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 -- 16558

Or

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

@davidfowl

Copy link
Copy Markdown
Collaborator

Would these tests have caught the problem?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes TypeScript AppHost package-manager detection in the Aspire CLI to avoid accidentally inheriting unrelated workspace markers (e.g., a distant yarn.lock), which could cause npm-based generated projects to run via Yarn. It also adds diagnostic logging to make future resolution behavior easier to understand.

Changes:

  • Update TypeScript AppHost toolchain resolution to treat package-lock.json as an npm marker and limit probing to the AppHost directory plus (at most) one eligible parent, skipping root/home.
  • Add debug logging that records the exact marker/reason used to select the package manager.
  • Add/update tests covering npm lockfile detection, limited parent probing behavior, root/home parent skipping, and the debug “reason” log.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Projects/TypeScriptAppHostToolchainResolverTests.cs Adds/updates unit tests for package manager marker precedence, parent probing limits, and debug logging behavior.
src/Aspire.Cli/Utils/EnvironmentChecker/TypeScriptAppHostToolingCheck.cs Passes a logger into toolchain resolution so the new debug reasoning is emitted during environment checks.
src/Aspire.Cli/Scaffolding/ScaffoldingService.cs Passes a logger into toolchain resolution (and adjusts helper method) so scaffolding/install flows emit the new debug reasoning.
src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Implements the new marker detection rules, adds package-lock.json handling, parent probing constraints, and “reason” logging support.
src/Aspire.Cli/Projects/GuestAppHostProject.cs Passes a logger into toolchain resolution so Guest runtime creation emits the new debug reasoning.

Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Outdated
Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Outdated
Use OS-appropriate path comparison when deciding whether to skip root and home parent directories for package manager detection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebastienros

Sébastien Ros (sebastienros) commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Yes, the new test Resolve_WhenPackageLockExists_ReturnsNpm creates a parent yarn file and ensures it still picks up npm because of the local hint (package-lock.json)

Keep yarn markers ahead of package-lock.json within the same candidate directory while still allowing a local npm lockfile to beat parent-directory yarn markers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Outdated
Only use file-based yarn markers for TypeScript AppHost package manager detection and update the resolver test accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Re-running the failed jobs in the CI workflow for this pull request because 2 jobs were identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

Matched test failure patterns (1 test)
  • Aspire.Cli.EndToEnd.Tests.DashboardOtelTracesTests.DashboardRunWithOtelTracesReturnsNoTraces — MCR registry rate limiting (HTTP 403)

Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Outdated
Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs
Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Outdated

@IEvangelist David Pine (IEvangelist) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approval

Targeted, well-scoped fix for the cross-workspace package-manager bleed-through. The follow-up commits also addressed the case-sensitivity, Yarn-vs-package-lock.json precedence, and .yarn directory feedback nicely.

A few non-blocking nits inline — including one question about whether limiting parent probing to a single directory is too aggressive for nested-workspace AppHost layouts.

Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs Outdated
Comment thread src/Aspire.Cli/Projects/TypeScriptAppHostToolchainResolver.cs
Comment thread tests/Aspire.Cli.Tests/Projects/TypeScriptAppHostToolchainResolverTests.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sebastienros
Sébastien Ros (sebastienros) merged commit 7468a03 into microsoft:main Apr 30, 2026
285 checks passed
@sebastienros
Sébastien Ros (sebastienros) deleted the sebastienros/sebros-template-yarn branch April 30, 2026 13:57
@github-actions github-actions Bot added this to the 13.4 milestone Apr 30, 2026
@sebastienros

Copy link
Copy Markdown
Contributor Author

/backport to release/13.3

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.3 (link to workflow run)

Nell Shamrell-Harrington (nellshamrell) pushed a commit to nellshamrell/aspire that referenced this pull request May 18, 2026
* Fix TypeScript package manager detection

Treat package-lock.json as an npm marker and limit parent directory package manager probing to the AppHost directory's direct parent. Log the marker used to select the TypeScript AppHost package manager.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix TypeScript AppHost path comparisons

Use OS-appropriate path comparison when deciding whether to skip root and home parent directories for package manager detection.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Preserve same-directory yarn marker precedence

Keep yarn markers ahead of package-lock.json within the same candidate directory while still allowing a local npm lockfile to beat parent-directory yarn markers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Remove yarn directory package manager hint

Only use file-based yarn markers for TypeScript AppHost package manager detection and update the resolver test accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Address TypeScript toolchain review feedback

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators May 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants