From 60cbddbd47b0b455219c8450702304ef99d98611 Mon Sep 17 00:00:00 2001 From: Vyacheslav Starostin <32613074+vstarostin@users.noreply.github.com> Date: Mon, 7 Oct 2024 11:55:20 +0500 Subject: [PATCH] `npm config` doesn't fail when `workspaces` enabled (#5120) * Add -ws=false -iwr to npm config get registry * Add -ws=false -iwr to npm config set registry * Fix test * Fix test --------- Co-authored-by: Manjunath --- cmd/npmExecuteScripts_test.go | 2 +- pkg/npm/npm.go | 4 ++-- pkg/npm/npm_test.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/npmExecuteScripts_test.go b/cmd/npmExecuteScripts_test.go index af1b7f828a..3c7bf6e995 100644 --- a/cmd/npmExecuteScripts_test.go +++ b/cmd/npmExecuteScripts_test.go @@ -148,7 +148,7 @@ func TestNpmExecuteScripts(t *testing.T) { if assert.NoError(t, err) { if assert.Equal(t, 4, len(utils.execRunner.Calls)) { - assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "registry"}}, utils.execRunner.Calls[0]) + assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "registry", "-ws=false", "-iwr"}}, utils.execRunner.Calls[0]) assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"ci"}}, utils.execRunner.Calls[1]) assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"run", "ci-build"}}, utils.execRunner.Calls[3]) } diff --git a/pkg/npm/npm.go b/pkg/npm/npm.go index 4c8130c9b6..6e36ace72f 100644 --- a/pkg/npm/npm.go +++ b/pkg/npm/npm.go @@ -96,7 +96,7 @@ func (exec *Execute) SetNpmRegistries() error { var buffer bytes.Buffer execRunner.Stdout(&buffer) - err := execRunner.RunExecutable("npm", "config", "get", npmRegistry) + err := execRunner.RunExecutable("npm", "config", "get", npmRegistry, "-ws=false", "-iwr") execRunner.Stdout(log.Writer()) if err != nil { return err @@ -109,7 +109,7 @@ func (exec *Execute) SetNpmRegistries() error { if exec.Options.DefaultNpmRegistry != "" && registryRequiresConfiguration(preConfiguredRegistry, "https://registry.npmjs.org") { log.Entry().Info("npm registry " + npmRegistry + " was not configured, setting it to " + exec.Options.DefaultNpmRegistry) - err = execRunner.RunExecutable("npm", "config", "set", npmRegistry, exec.Options.DefaultNpmRegistry) + err = execRunner.RunExecutable("npm", "config", "set", npmRegistry, exec.Options.DefaultNpmRegistry, "-ws=false", "-iwr") if err != nil { return err } diff --git a/pkg/npm/npm_test.go b/pkg/npm/npm_test.go index 52ef6e085a..ea4677ee3c 100644 --- a/pkg/npm/npm_test.go +++ b/pkg/npm/npm_test.go @@ -299,7 +299,7 @@ func TestNpm(t *testing.T) { utils := newNpmMockUtilsBundle() utils.AddFile("package.json", []byte("{\"scripts\": { \"ci-lint\": \"exit 0\" } }")) utils.AddFile(filepath.Join("src", "package.json"), []byte("{\"scripts\": { \"ci-build\": \"exit 0\" } }")) - utils.execRunner = &mock.ExecMockRunner{StdoutReturn: map[string]string{"npm config get registry": "undefined"}} + utils.execRunner = &mock.ExecMockRunner{StdoutReturn: map[string]string{"npm config get registry -ws=false -iwr": "undefined"}} options := ExecutorOptions{} options.DefaultNpmRegistry = "https://example.org/npm" @@ -311,8 +311,8 @@ func TestNpm(t *testing.T) { if assert.NoError(t, err) { if assert.Equal(t, 2, len(utils.execRunner.Calls)) { - assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "registry"}}, utils.execRunner.Calls[0]) - assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "set", "registry", exec.Options.DefaultNpmRegistry}}, utils.execRunner.Calls[1]) + assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "get", "registry", "-ws=false", "-iwr"}}, utils.execRunner.Calls[0]) + assert.Equal(t, mock.ExecCall{Exec: "npm", Params: []string{"config", "set", "registry", exec.Options.DefaultNpmRegistry, "-ws=false", "-iwr"}}, utils.execRunner.Calls[1]) } } })