Skip to content

Commit

Permalink
chore: Always warn user of npm registry deprecation (#966)
Browse files Browse the repository at this point in the history
* chore: Always warn user of npm registry deprecation

* cleanup
  • Loading branch information
tianfeng92 authored Nov 4, 2024
1 parent a41409e commit 070943a
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 56 deletions.
28 changes: 2 additions & 26 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"
"time"

"github.com/Masterminds/semver/v3"
"github.com/fatih/color"
"github.com/mitchellh/mapstructure"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -406,32 +405,9 @@ func (t *Tunnel) SetDefaults() {
}
}

func hasMultiRegistrySupport(framework, version string) bool {
minVersions := map[string]string{
"cypress": "12.14.0",
"playwright-cucumberjs": "1.35.1",
"playwright": "1.35.1",
"testcafe": "2.6.2",
}

v, ok := minVersions[framework]
if !ok {
return true
}
maxVersion := semver.MustParse(v)
curVersion, err := semver.NewVersion(version)
if err != nil {
// if value is non-version (like "package.json"), we assume this is an older version
// as this is, at the moment of the change, the only option possible. This needs to
// be returning false in a future framework update.
return false
}
return curVersion.GreaterThan(maxVersion)
}

// SetDefaults updates npm default values
func (n *Npm) SetDefaults(framework, version string) {
if n.Registry != "" && hasMultiRegistrySupport(framework, version) {
func (n *Npm) SetDefaults() {
if n.Registry != "" {
log.Warn().Msg("npm.registry has been deprecated, please use npm.registries instead")
n.Registries = append(n.Registries, Registry{URL: n.Registry})
}
Expand Down
27 changes: 1 addition & 26 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,39 +303,14 @@ func TestNpm_SetDefaults(t *testing.T) {
{URL: "http://npmjs.org"},
},
},
{
name: "Legacy registry + Newer",
fields: fields{
Registry: "http://npmjs.org",
Registries: []Registry{
{URL: "http://npmjs-2.org"},
},
Framework: "dummy",
FrameworkVersion: "",
},
want: []Registry{
{URL: "http://npmjs-2.org"},
{URL: "http://npmjs.org"},
},
},
{
name: "Do not migrate older versions",
fields: fields{
Registry: "http://npmjs.org",
Registries: []Registry{},
Framework: "cypress",
FrameworkVersion: "12.14.0",
},
want: []Registry{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(*testing.T) {
n := &Npm{
Registry: tt.fields.Registry,
Registries: tt.fields.Registries,
}
n.SetDefaults(tt.fields.Framework, tt.fields.FrameworkVersion)
n.SetDefaults()
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cucumber/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func SetDefaults(p *Project) {

p.Sauce.Tunnel.SetDefaults()
p.Sauce.Metadata.SetDefaultBuild()
p.Npm.SetDefaults(p.Kind, p.Playwright.Version)
p.Npm.SetDefaults()

for k := range p.Suites {
suite := &p.Suites[k]
Expand Down
2 changes: 1 addition & 1 deletion internal/cypress/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (p *Project) SetDefaults() {

p.Sauce.Tunnel.SetDefaults()
p.Sauce.Metadata.SetDefaultBuild()
p.Npm.SetDefaults(p.Kind, p.Cypress.Version)
p.Npm.SetDefaults()

for k := range p.Suites {
s := &p.Suites[k]
Expand Down
2 changes: 1 addition & 1 deletion internal/playwright/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func SetDefaults(p *Project) {

p.Sauce.Tunnel.SetDefaults()
p.Sauce.Metadata.SetDefaultBuild()
p.Npm.SetDefaults(p.Kind, p.Playwright.Version)
p.Npm.SetDefaults()

for k := range p.Suites {
s := &p.Suites[k]
Expand Down
2 changes: 1 addition & 1 deletion internal/testcafe/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func SetDefaults(p *Project) {

p.Sauce.Tunnel.SetDefaults()
p.Sauce.Metadata.SetDefaultBuild()
p.Npm.SetDefaults(p.Kind, p.Testcafe.Version)
p.Npm.SetDefaults()

for k := range p.Suites {
suite := &p.Suites[k]
Expand Down

0 comments on commit 070943a

Please sign in to comment.