Skip to content

feat(pm): Detect package manager#1451

Merged
Tobbe merged 4 commits intomainfrom
tobbe-feat-detect-package-manager
Mar 24, 2026
Merged

feat(pm): Detect package manager#1451
Tobbe merged 4 commits intomainfrom
tobbe-feat-detect-package-manager

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Mar 24, 2026

Start on making Cedar work with both yarn, pnpm and npm

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 24, 2026

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 2fddc31
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69c311a9eefd9b00072f8af0

@github-actions github-actions Bot added this to the next-release milestone Mar 24, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 24, 2026

Greptile Summary

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: managagermanager.

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.
packages/project-config/src/tests/packageManager.test.ts New test file with good coverage of getPackageManager and prettyPrintCedarCommand; correctly resets the module cache in beforeEach.
packages/cli-helpers/src/packageManager/index.ts New helper that returns the correct workspace version string (workspace:* vs *) based on detected package manager; logic is correct.
packages/cli-helpers/src/packageManager/tests/index.test.ts New test file for workspacePackageVersion; has a typo in the describe label (worspacePackageVersion).
packages/cli/src/commands/generate/package/packageHandler.js 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)

  1. packages/cli/src/commands/generate/package/packageHandler.js, line 354-359 (link)

    P2 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.

Reviews (1): Last reviewed commit: "feat(pm): Detect package manager" | Re-trigger Greptile

Comment thread packages/project-config/src/packageManager.ts
Comment thread packages/cli-helpers/src/packageManager/__tests__/index.test.ts Outdated
Comment thread packages/project-config/src/packageManager.ts Outdated
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 24, 2026

🤖 Nx Cloud AI Fix

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


View your CI Pipeline Execution ↗ for commit 2fddc31

Command Status Duration Result
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 6s View ↗
nx run-many -t test:types ✅ Succeeded 14s View ↗
nx run-many -t build ✅ Succeeded 4m 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-24 23:14:54 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 24, 2026

🤖 Nx Cloud AI Fix

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


View your CI Pipeline Execution ↗ for commit 2c2f7a5

Command Status Duration Result
nx run-many -t build ✅ Succeeded 2m 23s View ↗
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-24 20:31:23 UTC

@Tobbe Tobbe enabled auto-merge (squash) March 24, 2026 22:37
@Tobbe Tobbe merged commit 9e1c4d8 into main Mar 24, 2026
67 of 69 checks passed
@Tobbe Tobbe deleted the tobbe-feat-detect-package-manager branch March 24, 2026 23:14
@github-actions
Copy link
Copy Markdown

The changes in this PR are now available on npm.

Try them out by running yarn cedar upgrade -t 4.0.0-canary.13668

Tobbe added a commit that referenced this pull request Mar 25, 2026
@Tobbe Tobbe modified the milestones: next-release, v3.1.0 Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant