Fix TypeScript AppHost package manager detection - #16558
Fix TypeScript AppHost package manager detection#16558Sébastien Ros (sebastienros) merged 5 commits into
Conversation
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>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16558Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16558" |
|
Would these tests have caught the problem? |
There was a problem hiding this comment.
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.jsonas 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. |
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>
|
Yes, the new test |
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>
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>
|
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.
Matched test failure patterns (1 test)
|
David Pine (IEvangelist)
left a comment
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7468a03
into
microsoft:main
|
/backport to release/13.3 |
|
Started backporting to |
* 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>
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 foraspire newTypeScript starter projects created under a repository that already has a top-level Yarn marker.This change treats
package-lock.jsonas 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: