You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR makes the Cedar CLI package-manager-agnostic by introducing a set of helper functions (add(), install(), dedupe(), dedupeIsSupported(), installationErrorMessage(), prettyPrintCedarCommand()) in @cedarjs/cli-helpers/packageManager and updating getPackageManager() in @cedarjs/project-config to detect the active package manager from the npm_config_user_agent environment variable before falling back to lock-file detection. Callers throughout the CLI (installHelpers, setupRscHandler, baremetal, and the upgrade command) are migrated away from hardcoded yarn invocations.
Key changes:
New PM detection priority: env var (npm_config_user_agent) > lock files > default yarn — the env var tells the CLI which package manager actually invoked the current command.
upgrade command: --dedupe option is now hidden for non-yarn users; the dedupeDeps task is correctly skipped for npm/pnpm via the dedupeIsSupported() guard.
dedupe() helper returns undefined for non-yarn PMs: it is used in template literals inside dedupeDeps without an explicit null guard — safe today due to control-flow, but fragile (see inline comment).
No tests for new cli-helpers/packageManager functions: add(), install(), deduce(), etc. are untested (see inline comment).
Confidence Score: 4/5
PR is safe to merge; all previously flagged issues are resolved and the remaining comments are non-blocking style suggestions.
The core logic is sound: the dedupeDeps function is correctly gated so it only runs for yarn, prior critical issues (hardcoded yarn dedupe, afterEach env var coercion) have been addressed, and the env-var-first detection strategy is coherent. The remaining P2 items — no null guard on dedupeCmd() in template literals and missing unit tests for the new helpers — are improvements rather than blockers.
packages/cli/src/commands/upgrade/upgradeHandler.ts (dedupeCmd null safety), packages/cli-helpers/src/packageManager/tests/index.test.ts (missing tests for new helpers)
Important Files Changed
Filename
Overview
packages/project-config/src/packageManager.ts
Adds env var (npm_config_user_agent) as the highest-priority signal for package manager detection, falling back to lock files. The default is now set eagerly at the top, and an isPackageManager type guard is introduced. The old multi-return structure is collapsed into a clean if/else chain.
Migrates from hardcoded yarn to PM-agnostic helpers throughout. The dedupeDeps function is correctly gated (only runs on yarn) so dedupeCmd() will never return undefined in practice, but the template literal use of a nullable return is fragile. Error messages and task titles are now PM-aware.
packages/cli-helpers/src/lib/installHelpers.ts
Correctly replaces hardcoded yarn with getPackageManager() and add(). Minor inconsistency: installPackages hardcodes 'install' instead of calling install(), but this is not a functional issue.
Adds afterEach cleanup and a new test for the env var detection path. The env var restoration correctly handles the undefined case (addressed from a prior review thread).
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[getPackageManager called] --> B{Cache populated?}
B -- Yes --> C[Return cached value]
B -- No --> D[Set default: yarn]
D --> E{npm_config_user_agent\nenv var set?}
E -- Yes, valid PM --> F[Use env var PM\ne.g. yarn / npm / pnpm]
E -- No / unrecognised --> G{yarn.lock exists?}
G -- Yes --> H[Use yarn]
G -- No --> I{pnpm-lock.yaml exists?}
I -- Yes --> J[Use pnpm]
I -- No --> K{package-lock.json exists?}
K -- Yes --> L[Use npm]
K -- No --> M[Fallback: yarn]
F --> N[Cache & return]
H --> N
J --> N
L --> N
M --> N
Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci
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
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.
Add helper methods for getting the package manager specific install, add and dedupe commands