Repository navigation
Fix vendored Yarn deployments calling yarn install instead of yarn rebuild - #965
Closed
tnikolova82 wants to merge 1 commit into
Closed
tnikolova82 wants to merge 1 commit into
tnikolova82 wants to merge 1 commit into
Conversation
…build ## Problem Following the same pattern as PR #964 (pnpm vendored fix), Yarn projects with pre-populated `node_modules/` (vendored deployments) incorrectly run `yarn install` instead of `yarn rebuild`. There are two distinct bugs in `BuildDependencies()`: ### Bug 1 — `case s.UseYarn` has priority over `case s.IsVendored` ```go switch { case s.UseYarn: // Matched first, Yarn.Build() runs s.Yarn.Build(...) case s.UsePNPM: s.PNPM.Build(...) case s.IsVendored: // Never reached when yarn.lock is present s.NPM.Rebuild(...) ... } ``` When both flags are set (yarn.lock exists AND node_modules/ exists), `Yarn.Build()` runs `yarn install`, ignoring the pre-populated `node_modules/`. ### Bug 2 — `case s.IsVendored` hardcodes `NPM.Rebuild()` regardless of package manager Even with correct ordering, `case s.IsVendored` always calls `s.NPM.Rebuild()`. A vendored Yarn project should call `Yarn.Rebuild()`. ## Solution 1. **Add `Rebuild(buildDir string) error` to the `Yarn` interface** - Mirrors the npm implementation - Mirrors the pnpm fix from PR #964 2. **Implement `Yarn.Rebuild()` in `src/nodejs/yarn/yarn.go`** - Runs `yarn rebuild` with `NODE_HOME` set via `npm_config_nodedir` - Ensures native modules compile for the CF stack 3. **Add `case s.UseYarn && s.IsVendored` before `case s.UseYarn`** - Vendored detection now takes priority over the package manager install path - Calls `Yarn.Rebuild()` instead of `Yarn.Build()` ## Changes - **`src/nodejs/yarn/yarn.go`**: Add `Rebuild()` method that runs `yarn rebuild` - **`src/nodejs/supply/supply.go`**: - Add `Rebuild(string) error` to the `Yarn` interface - Add `case s.UseYarn && s.IsVendored` case before `case s.UseYarn` - **`src/nodejs/yarn/yarn_test.go`**: Add unit tests for `Rebuild()` - **`src/nodejs/supply/supply_test.go`**: Add vendored yarn test cases - **`src/nodejs/supply/mocks_test.go`**: Add `Rebuild()` mock method ## Test Coverage - [x] Unit test: vendored Yarn project calls `Yarn.Rebuild`, not `Yarn.Build` - [x] Unit test: non-vendored Yarn project calls `Yarn.Build` as before - [x] Unit test: vendored npm project still calls `NPM.Rebuild` (no regression) - [x] Unit test: `Yarn.Rebuild()` runs `yarn rebuild` with NODE_HOME set - [ ] Integration test: push CF app with pre-populated `node_modules/` and `yarn.lock` ## Use Case Teams using `yarn install --production` or workspace vendoring to produce a pre-populated `node_modules/` directory before pushing. The buildpack should detect this and skip the install phase, running `yarn rebuild` instead to recompile any native addons for the CF stack. ## Related - Issue #957: Original bug report for pnpm (also mentioned Yarn has same issue) - PR #964: Fixed pnpm vendored deployments (this PR follows the same pattern) - Completes the vendored deployment fix for all three package managers (npm, yarn, pnpm)
3 of 4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Following the same pattern as PR #964 (pnpm vendored fix), Yarn projects with pre-populated
node_modules/(vendored deployments) incorrectly runyarn installinstead ofyarn rebuild.There are two distinct bugs in
BuildDependencies(), identical to the pnpm issue:Bug 1 —
case s.UseYarnhas priority overcase s.IsVendoredsupply.go#L342–L363When both flags are set:
s.UseYarn = true—yarn.lockexistss.IsVendored = true—node_modules/existsYarn.Build()runsyarn install, ignoring the pre-populatednode_modules/.Bug 2 —
case s.IsVendoredhardcodesNPM.Rebuild()regardless of package managerEven with correct ordering,
case s.IsVendoredatsupply.go#L353always callss.NPM.Rebuild(). A vendored Yarn project should callYarn.Rebuild().Solution
Follows the exact same pattern as PR #964 for pnpm:
Add
Rebuild(buildDir string) errorto theYarninterfaceImplement
Yarn.Rebuild()insrc/nodejs/yarn/yarn.goyarn rebuildwithNODE_HOMEset vianpm_config_nodedirAdd
case s.UseYarn && s.IsVendoredbeforecase s.UseYarnYarn.Rebuild()instead ofYarn.Build()Changes
src/nodejs/yarn/yarn.goRebuild()methodsrc/nodejs/supply/supply.goRebuild(string) errortoYarninterface; add vendored casesrc/nodejs/yarn/yarn_test.goRebuild()src/nodejs/supply/supply_test.gosrc/nodejs/supply/mocks_test.goRebuild()mock methodTest Coverage
Yarn.Rebuild, notYarn.BuildYarn.Buildas beforeNPM.Rebuild(no regression)Yarn.Rebuild()runsyarn rebuildwith NODE_HOME setnode_modules/andyarn.lockUse Case
Teams using
yarn install --productionor workspace vendoring to produce a pre-populatednode_modules/directory before pushing. The buildpack should detect this and skip the install phase, runningyarn rebuildinstead to recompile any native addons for the CF stack.Why This Matters
All three package managers (npm, yarn, pnpm) had the same bug:
Without this fix, vendored Yarn deployments:
yarn installunnecessarily (slow, may fail in offline environments)With this fix, vendored Yarn deployments:
yarn install(faster, works offline)yarn rebuildto recompile native addonsRelated
Notes
This PR was identified during code review of PR #964, which noted:
Testing in PR #964 should also verify Yarn vendored deployments once this is merged.