Repository navigation
feat: support devEngines.packageManager detection - #248
Conversation
Detect the package manager from the `devEngines.packageManager` field in package.json as a fallback after the `packageManager` field. https://docs.npmjs.com/cli/v11/configuring-npm/package-json#devengines Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds devEngines.packageManager detection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/detect.test.ts (1)
53-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLet the helper keep lockfile detection configurable.
Hard-coding
ignoreLockFile: truemeans this suite can't cover the regression where an unsupporteddevEngines.packageManager.nameshould fall through to implicit file detection. Accepting per-test overrides here would make that case easy to pin down.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/detect.test.ts` around lines 53 - 60, The detectFrom helper in detect.test.ts hard-codes ignoreLockFile, which prevents tests from covering lockfile-based fallback behavior. Update the helper so individual tests can override detectPackageManager options, especially ignoreLockFile, while still defaulting includeParentDirs and the temporary directory setup. This will let the suite pin down the devEngines.packageManager.name fallback case using detectPackageManager and detectFrom.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/_utils.ts`:
- Around line 325-340: The `parsePackageManagerField` helper in `src/_utils.ts`
is still allowing a bare hyphen through the `VALID_PM_NAME_RE` path, so treat
`"-"` as invalid before returning a package manager name. Update the early
validation in `parsePackageManagerField` so `"-"` is rejected the same way as
other invalid values, and make sure the sanitizing branch still handles it
consistently without returning `{ name: "-" }`.
In `@src/package-manager.ts`:
- Around line 129-145: The devEngines handling in package-manager.ts is
returning too early even when the resolved name is not one of the supported
entries in packageManagers. Update the logic around the devEngines.name branch
so it only returns a package manager result when a matching supported manager is
found via packageManagers.find, and otherwise falls through to the later
detection/lockfile logic instead of returning { name, command: name } for an
unsupported manager.
---
Nitpick comments:
In `@test/detect.test.ts`:
- Around line 53-60: The detectFrom helper in detect.test.ts hard-codes
ignoreLockFile, which prevents tests from covering lockfile-based fallback
behavior. Update the helper so individual tests can override
detectPackageManager options, especially ignoreLockFile, while still defaulting
includeParentDirs and the temporary directory setup. This will let the suite pin
down the devEngines.packageManager.name fallback case using detectPackageManager
and detectFrom.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8823889d-df12-4abc-b695-4c2ec8d43c5c
📒 Files selected for processing (5)
README.mdsrc/_utils.tssrc/package-manager.tstest/_utils.test.tstest/detect.test.ts
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds support for detecting the package manager from the
devEngines.packageManagerfield inpackage.json.Detection precedence is now:
packageManagerfielddevEngines.packageManagerfield (new)Details
devEngines.packageManagermay be a single object or an array of objects — the first entry is used.versionis a semver range (e.g.^9.0.0) rather than a pinned version, so the major version is derived from the first numeric segment (correctly resolving e.g. Yarn berry vs classic).packageManagerfield still takes precedence when both are present.packageManagerfield, emitting awarningsentry for abnormal characters.Tests
parseDevEnginesPackageManager(object/array/no-version/sanitization/empty cases).packageManagerprecedence.🤖 Generated with Claude Code
Summary by CodeRabbit
devEngines.packageManagerfrompackage.json.devEnginesinput shapes (including array-first-entry behavior) and parses semver-range versions to derive amajorVersion.packageManagerwhen both sources are present.