Skip to content

Conversation

@eyalk007
Copy link
Collaborator

@eyalk007 eyalk007 commented Jan 27, 2026

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • This pull request is on the dev branch.
  • I used gofmt for formatting the code before submitting the pull request.
  • Update documentation about new features / new supported technologies

Adds Yarn package handler with proper version detection and refactors Node.js utilities for code reuse across npm/Yarn/pnpm.

  • New Yarn handler - Supports Classic (v1) and Berry (v2+) with correct version detection based on lockfile header (not global CLI)
  • Extracted Node.js utilities - Shared code for npm/Yarn/pnpm (JSON updates, lockfile regeneration, rollback logic)
  • Refactored NPM handler - Uses shared utilities, eliminates duplication
  • Deleted old buggy Yarn handler - Fixed critical bug that checked global Yarn version instead of project version

- Add comprehensive Yarn support (Classic v1 and Berry v2+)
  - Detect Yarn version by lockfile header (__metadata: for Berry)
  - Use correct commands per version:
    - Yarn 1: yarn install --ignore-scripts --frozen-lockfile=false
    - Yarn 2+: yarn install --mode update-lockfile
  - Support resolutions section (Yarn-specific)
  - Simplified env vars (CI=true only, flags handle the rest)

- Extract shared Node.js utilities to nodepackageupdaterutils.go
  - UpdatePackageJsonDependency: JSON manipulation with sjson/gjson
  - GetDescriptorsToFixFromVulnerability: Derive package.json from lockfiles
  - UpdatePackageAndRegenerateLock: Orchestration with rollback
  - Shared by npm, Yarn (and future pnpm)

- Refactor npm handler to use shared utilities
  - Reduce code duplication
  - Maintain all existing functionality
  - All tests pass

- Delete old buggy yarnpackagehandler.go
  - Had critical bug: checked global Yarn version instead of project version
  - Replaced with lockfile-based detection

- Add comprehensive test coverage
  - 383 lines of Yarn-specific tests
  - Tests for version detection, JSON updates, resolutions, env isolation
  - All npm tests updated and passing

Net: -282 lines deleted, +671 lines added (new functionality)
- Test GetPackageJsonPathsFromLockfilePaths: path derivation, file checks, edge cases
- Test UpdatePackageInDescriptor: file updates, backup creation, error handling
- Test RegenerateLockfile: success, rollback on failure, rollback failure handling
- Test UpdatePackageAndRegenerateLock: full orchestration, git tracking logic

Total: 366 lines, 12 test cases covering critical rollback logic
@eyalk007 eyalk007 added the improvement Automatically generated release notes label Jan 27, 2026
@eyalk007 eyalk007 self-assigned this Jan 27, 2026
- Only GetDescriptorsToFixFromVulnerability and UpdatePackageAndRegenerateLock are exported (called by npm/Yarn)
- All other functions are now internal (lowercase): getPackageJsonPathsFromLockfilePaths, updatePackageInDescriptor, regenerateLockfile, updatePackageJsonDependency, escapeJsonPathKey
- Revert scanrepository_test.go import ordering to match upstream/v3_er
- All tests passing
- Upgraded from v1.24.2 to v1.26.0
- Also upgraded related dependencies:
  - build-info-go
  - jfrog-cli-core/v2
  - jfrog-cli-artifactory
  - jfrog-client-go
- All tests passing
- Primary: Look for package.json in component locations (Yarn/newer scans)
- Fallback: Look for lockfile and derive package.json path (npm/older scans)
- Verify lockfile exists in same directory before accepting descriptor
- Fixes 'no location evidence found' error for Yarn projects
- All tests passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant