Skip to content

fix(core): detect package manager properly using @nx/devkit (Fixes #74)#79

Merged
michaelbe812 merged 1 commit intomainfrom
fix/74-package-manager-detection
Jan 21, 2026
Merged

fix(core): detect package manager properly using @nx/devkit (Fixes #74)#79
michaelbe812 merged 1 commit intomainfrom
fix/74-package-manager-detection

Conversation

@michaelbe812
Copy link
Contributor

Summary

  • Replace custom package manager detection with @nx/devkit's detectPackageManager and getPackageManagerCommand functions
  • The previous implementation checked for globally available binaries (pnpm -v, yarn -v) which didn't respect the project's actual configuration
  • Now correctly detects based on lock files (package-lock.json, yarn.lock, pnpm-lock.yaml) and packageManager field in package.json

Test plan

  • All existing auto-installer tests pass (21 tests)
  • All core package tests pass (154 tests)
  • All plugin-openapi tests pass (32 tests)
  • Linting passes for core and plugin-openapi packages
  • Verify detectPackageManager() returns correct value based on lock file

Closes #74

🤖 Generated with Claude Code

Replace custom package manager detection heuristic with @nx/devkit's
detectPackageManager and getPackageManagerCommand functions. The previous
implementation checked for globally available binaries (pnpm -v, yarn -v)
which didn't respect the project's actual package manager configuration
based on lock files or packageManager field in package.json.

Now correctly detects:
- npm when package-lock.json exists
- yarn when yarn.lock exists
- pnpm when pnpm-lock.yaml exists
- Also respects packageManager field in package.json

Closes #74

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@michaelbe812
Copy link
Contributor Author

Code Review Summary ✅

Overview

This is a well-implemented fix that correctly addresses issue #74. The change from custom package manager detection to using @nx/devkit's built-in functions is the right approach.

What I Reviewed

  • ✅ Implementation in auto-installer.ts - Clean delegation to @nx/devkit
  • ✅ Test coverage in auto-installer.spec.ts - Properly mocks @nx/devkit functions
  • ✅ All tests pass (154 tests in core package)
  • ✅ Linting passes

Key Improvements

  1. Correct approach - Using @nx/devkit's detectPackageManager properly checks:

    • Lock files (pnpm-lock.yaml, yarn.lock, package-lock.json)
    • packageManager field in package.json
  2. Simpler implementation - Reduced from ~18 lines to ~4 lines of logic

  3. More reliable - Previous implementation checked for globally available binaries (pnpm -v, yarn -v) which could incorrectly detect a package manager not actually used by the project

  4. Maintains API compatibility - Re-exports PackageManager type correctly

  5. Good documentation - Clear JSDoc comment explaining the function

Code Quality

The implementation is clean and follows best practices. Tests properly isolate the unit under test by mocking @nx/devkit dependencies.

Verdict: LGTM! Ready to merge. 🎉


Automated code review by Claude Code

@michaelbe812 michaelbe812 merged commit e631837 into main Jan 21, 2026
1 check passed
@michaelbe812 michaelbe812 deleted the fix/74-package-manager-detection branch January 21, 2026 12:50
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.

nx-plugin-openapi/core: Package manager not detected properly

1 participant