Skip to content

Commit

Permalink
npm config doesn't fail when workspaces enabled (#5120)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
vstarostin and D074360 authored Oct 7, 2024
1 parent ef25e31 commit 60cbddb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/npmExecuteScripts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/npm/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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])
}
}
})
Expand Down

0 comments on commit 60cbddb

Please sign in to comment.