Repository navigation
Fix vendored pnpm deployments calling pnpm install instead of pnpm rebuild #964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package pnpm_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| func TestPnpm(t *testing.T) { | ||
| RegisterFailHandler(Fail) | ||
| RunSpecs(t, "Pnpm Suite") | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package pnpm_test | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "os/exec" | ||
| "reflect" | ||
|
|
||
| "github.com/cloudfoundry/libbuildpack" | ||
| "github.com/cloudfoundry/libbuildpack/ansicleaner" | ||
| p "github.com/cloudfoundry/nodejs-buildpack/src/nodejs/pnpm" | ||
| "github.com/golang/mock/gomock" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| //go:generate mockgen -source=pnpm.go --destination=mocks_test.go --package=pnpm_test | ||
|
|
||
| // MockCommand is a hand-written mock matching the pnpm.Command interface. | ||
| type MockCommand struct { | ||
| ctrl *gomock.Controller | ||
| recorder *MockCommandMockRecorder | ||
| } | ||
|
|
||
| type MockCommandMockRecorder struct { | ||
| mock *MockCommand | ||
| } | ||
|
|
||
| func NewMockCommand(ctrl *gomock.Controller) *MockCommand { | ||
| mock := &MockCommand{ctrl: ctrl} | ||
| mock.recorder = &MockCommandMockRecorder{mock} | ||
| return mock | ||
| } | ||
|
|
||
| func (m *MockCommand) EXPECT() *MockCommandMockRecorder { return m.recorder } | ||
|
|
||
| func (m *MockCommand) Execute(dir string, stdout, stderr io.Writer, program string, args ...string) error { | ||
| varargs := []interface{}{dir, stdout, stderr, program} | ||
| for _, a := range args { | ||
| varargs = append(varargs, a) | ||
| } | ||
| ret := m.ctrl.Call(m, "Execute", varargs...) | ||
| ret0, _ := ret[0].(error) | ||
| return ret0 | ||
| } | ||
|
|
||
| func (mr *MockCommandMockRecorder) Execute(arg0, arg1, arg2, arg3 interface{}, arg4 ...interface{}) *gomock.Call { | ||
| varargs := append([]interface{}{arg0, arg1, arg2, arg3}, arg4...) | ||
| return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Execute", reflect.TypeOf((*MockCommand)(nil).Execute), varargs...) | ||
| } | ||
|
|
||
| func (m *MockCommand) Run(cmd *exec.Cmd) error { | ||
| ret := m.ctrl.Call(m, "Run", cmd) | ||
| ret0, _ := ret[0].(error) | ||
| return ret0 | ||
| } | ||
|
|
||
| func (mr *MockCommandMockRecorder) Run(cmd interface{}) *gomock.Call { | ||
| return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockCommand)(nil).Run), cmd) | ||
| } | ||
|
|
||
| var _ = Describe("PNPM", func() { | ||
| var ( | ||
| err error | ||
| buildDir string | ||
| cacheDir string | ||
| pnpm *p.PNPM | ||
| logger *libbuildpack.Logger | ||
| buffer *bytes.Buffer | ||
| mockCtrl *gomock.Controller | ||
| mockCommand *MockCommand | ||
| oldNodeHome string | ||
| ) | ||
|
|
||
| BeforeEach(func() { | ||
| buildDir, err = os.MkdirTemp("", "nodejs-buildpack.build.") | ||
| Expect(err).To(BeNil()) | ||
| cacheDir, err = os.MkdirTemp("", "nodejs-buildpack.cache.") | ||
| Expect(err).To(BeNil()) | ||
|
|
||
| buffer = new(bytes.Buffer) | ||
| logger = libbuildpack.NewLogger(ansicleaner.New(buffer)) | ||
|
|
||
| mockCtrl = gomock.NewController(GinkgoT()) | ||
| mockCommand = NewMockCommand(mockCtrl) | ||
|
|
||
| pnpm = &p.PNPM{ | ||
| Log: logger, | ||
| Command: mockCommand, | ||
| } | ||
|
|
||
| oldNodeHome = os.Getenv("NODE_HOME") | ||
| Expect(os.Setenv("NODE_HOME", "test_node_home")).To(Succeed()) | ||
| }) | ||
|
|
||
| AfterEach(func() { | ||
| mockCtrl.Finish() | ||
| Expect(os.Setenv("NODE_HOME", oldNodeHome)).To(Succeed()) | ||
| Expect(os.RemoveAll(buildDir)).To(Succeed()) | ||
| Expect(os.RemoveAll(cacheDir)).To(Succeed()) | ||
| }) | ||
|
|
||
| Describe("Rebuild", func() { | ||
| It("runs pnpm rebuild with NODE_HOME set", func() { | ||
| mockCommand.EXPECT().Run(gomock.Any()).DoAndReturn(func(cmd *exec.Cmd) error { | ||
| Expect(cmd.Args).To(Equal([]string{"pnpm", "rebuild", "--recursive"})) | ||
| Expect(cmd.Dir).To(Equal(buildDir)) | ||
| Expect(cmd.Env).To(ContainElement("npm_config_nodedir=test_node_home")) | ||
| return nil | ||
| }) | ||
| Expect(pnpm.Rebuild(buildDir)).To(Succeed()) | ||
| Expect(buffer.String()).To(ContainSubstring("Rebuilding any native modules (pnpm)")) | ||
| }) | ||
|
|
||
| It("propagates command errors", func() { | ||
| mockCommand.EXPECT().Run(gomock.Any()).Return(fmt.Errorf("pnpm rebuild failed")) | ||
| Expect(pnpm.Rebuild(buildDir)).To(MatchError("pnpm rebuild failed")) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("Build", func() { | ||
| Context("online mode (no .pnpm-store in buildDir)", func() { | ||
| It("runs pnpm install with cache dir", func() { | ||
| mockCommand.EXPECT().Run(gomock.Any()).DoAndReturn(func(cmd *exec.Cmd) error { | ||
| Expect(cmd.Args).To(Equal([]string{"pnpm", "install", "--no-frozen-lockfile"})) | ||
| Expect(cmd.Dir).To(Equal(buildDir)) | ||
| Expect(cmd.Env).To(ContainElement("PNPM_HOME=" + cacheDir + "/.pnpm-store")) | ||
| return nil | ||
| }) | ||
| Expect(pnpm.Build(buildDir, cacheDir)).To(Succeed()) | ||
| }) | ||
| }) | ||
|
|
||
| Context("offline mode (.pnpm-store exists in buildDir)", func() { | ||
| BeforeEach(func() { | ||
| Expect(os.MkdirAll(buildDir+"/.pnpm-store", 0755)).To(Succeed()) | ||
| }) | ||
|
|
||
| It("runs pnpm install --offline", func() { | ||
| mockCommand.EXPECT().Run(gomock.Any()).DoAndReturn(func(cmd *exec.Cmd) error { | ||
| Expect(cmd.Args).To(Equal([]string{"pnpm", "install", "--no-frozen-lockfile", "--offline"})) | ||
| return nil | ||
| }) | ||
| Expect(pnpm.Build(buildDir, cacheDir)).To(Succeed()) | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test not fit the
itdescription, he no testnpmcalls.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed the test description