Skip to content

Commit

Permalink
Redo all of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 2, 2024
1 parent 7b23ce9 commit f570bc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 3 additions & 5 deletions loader/cdnjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type cdnjsEnvelope struct {
}
}

func cdnjs(logger logrus.FieldLogger, specifier string, parts []string) (string, error) {
func cdnjs(logger logrus.FieldLogger, path string, parts []string) (string, error) {
name := parts[0]
version := parts[1]
filename := parts[2]
Expand Down Expand Up @@ -56,7 +56,7 @@ func cdnjs(logger logrus.FieldLogger, specifier string, parts []string) (string,
if len(ver.Files) == 0 {
return "",
fmt.Errorf("cdnjs: no files for version %s of %s, this is a problem with the library or cdnjs not k6",
version, specifier)
version, path)
}
backupFilename = ver.Files[0]
for _, file := range ver.Files {
Expand All @@ -70,7 +70,5 @@ func cdnjs(logger logrus.FieldLogger, specifier string, parts []string) (string,
}
}

realURL := "https://cdnjs.cloudflare.com/ajax/libs/" + name + "/" + version + "/" + filename
logger.Warnf(magicURLsDeprecationWarning, specifier, "cdnjs", realURL)
return realURL, nil
return "https://cdnjs.cloudflare.com/ajax/libs/" + name + "/" + version + "/" + filename, nil
}
9 changes: 2 additions & 7 deletions loader/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ package loader

import "github.com/sirupsen/logrus"

func github(logger logrus.FieldLogger, specifier string, parts []string) (string, error) {
func github(_ logrus.FieldLogger, _ string, parts []string) (string, error) {
username := parts[0]
repo := parts[1]
filepath := parts[2]
realURL := "https://raw.githubusercontent.com/" + username + "/" + repo + "/master/" + filepath
logger.Warnf(magicURLsDeprecationWarning, specifier, "github", realURL)
return realURL, nil
return "https://raw.githubusercontent.com/" + username + "/" + repo + "/master/" + filepath, nil
}

const magicURLsDeprecationWarning = "Specifier %q resolved to use a non-conventional %s loader. " +
"That loader is deprecated and will be removed in v0.53.0. Please use the real URL %q instead."
13 changes: 12 additions & 1 deletion loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func Load(
data, err := fsext.ReadFile(filesystems[scheme], pathOnFs)

if err == nil {
if moduleSpecifier.Opaque != "" {
loaderName, _, _ := pickLoader(moduleSpecifier.Opaque)
logger.Warnf(magicURLsDeprecationWarning, originalModuleSpecifier, loaderName)
}
return &SourceData{URL: moduleSpecifier, Data: data}, nil
}
if !errors.Is(err, fs.ErrNotExist) {
Expand Down Expand Up @@ -203,13 +207,20 @@ func Load(
return result, nil
}

const (
magicURLsDeprecationWarning = "Specifier %q resolved to use a non-conventional %[2]q loader. " +
"The used %[2]q loader is deprecated and will be removed in k6 v0.53.0."
magicURLsDeprecationWarningExtended = magicURLsDeprecationWarning + " Please use the real URL %q instead."
)

func resolveUsingLoaders(logger logrus.FieldLogger, name string) (*url.URL, error) {
_, loader, loaderArgs := pickLoader(name)
loaderName, loader, loaderArgs := pickLoader(name)
if loader != nil {
urlString, err := loader(logger, name, loaderArgs)
if err != nil {
return nil, err
}
logger.Warnf(magicURLsDeprecationWarningExtended, name, loaderName, urlString)
return url.Parse(urlString)
}

Expand Down

0 comments on commit f570bc0

Please sign in to comment.