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 introduces package manager detection for Cedar projects, allowing the toolchain to adapt its behaviour for yarn, pnpm, and npm. A new getPackageManager() function in @cedarjs/project-config inspects the project root for well-known lock files (yarn.lock, pnpm-lock.yaml, package-lock.json) and caches the result. Two consumer utilities are added: workspacePackageVersion() in @cedarjs/cli-helpers (returns workspace:* or * depending on the PM) and prettyPrintCedarCommand() (formats the correct CLI invocation). Both packages expose the new helpers as separate export conditions so consumers can import them without pulling in the full package.
Key observations:
The fallback 'yarn' return in getPackageManager() does not set packageManagerCache, so repeated calls on a project with no lock file will re-stat the filesystem on every invocation — unlike every other branch in the function.
installAndBuild() and the ESLint cleanup step in packageHandler.js still hard-code yarn despite the file being modified to consume workspacePackageVersion(); pnpm/npm users will get a yarn: command not found error during generate package.
Minor typo in the test describe label: 'worspacePackageVersion' → 'workspacePackageVersion'.
Minor typo in the JSDoc comment: managager → manager.
Confidence Score: 4/5
Safe to merge for yarn users; the cache-miss fallback is a correctness issue worth fixing before this ships for pnpm/npm users.
The core detection and consumer utilities are sound and well-tested. The cache-miss on the fallback path is a real bug (inconsistent with the rest of the function and causes unnecessary I/O), but it only affects projects with no lock file — an unusual scenario. The hardcoded yarn calls in packageHandler.js are pre-existing and the PR explicitly marks itself as "Start on" work, so they are expected gaps rather than regressions. One targeted fix (caching the fallback) would bring this to a clean merge.
packages/project-config/src/packageManager.ts (cache-miss on fallback), packages/cli/src/commands/generate/package/packageHandler.js (remaining hardcoded yarn calls)
Important Files Changed
Filename
Overview
packages/project-config/src/packageManager.ts
New module that detects the active package manager by checking for lock files; has a cache-miss bug on the fallback 'yarn' path and a typo in the JSDoc.
Correctly switches the workspace dependency version string to use the detected PM, but the installAndBuild and ESLint cleanup helpers in the same file still hard-code yarn.
packages/project-config/src/prisma.ts
Now uses prettyPrintCedarCommand for the user-facing error message; straightforward, correct change.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[getPackageManager called] --> B{packageManagerCache set?}
B -- Yes --> C[Return cached value]
B -- No --> D{yarn.lock exists?}
D -- Yes --> E[cache = 'yarn', return 'yarn']
D -- No --> F{pnpm-lock.yaml exists?}
F -- Yes --> G[cache = 'pnpm', return 'pnpm']
F -- No --> H{package-lock.json exists?}
H -- Yes --> I[cache = 'npm', return 'npm']
H -- No --> J[return 'yarn' ⚠️ NOT cached]
subgraph consumers
K[workspacePackageVersion] -->|npm → '*' / else → 'workspace:*'| L[packageHandler.js]
M[prettyPrintCedarCommand] -->|npm → npx / else → pm name| N[prisma.ts error message]
end
E & G & I & J --> consumers
Loading
Comments Outside Diff (1)
packages/cli/src/commands/generate/package/packageHandler.js, line 354-359 (link)
Hardcoded yarn calls not yet updated
This PR starts wiring up package-manager detection, but installAndBuild still invokes execa('yarn', ...) unconditionally (lines 356–358). A user running generate package with pnpm or npm would get a yarn: command not found error at install time. A similar issue exists at line 602 where execa.sync('yarn', ['eslint', ...]) is also hardcoded.
Since the PR description marks this as the start of multi-PM support, you may be intentionally deferring these, but it is worth tracking so the feature doesn't ship in a partially-functional state for npm/pnpm users.
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
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.
Start on making Cedar work with both yarn, pnpm and npm