diff --git a/loader/cdnjs.go b/loader/cdnjs.go index b9a785dea16..f58719c7a50 100644 --- a/loader/cdnjs.go +++ b/loader/cdnjs.go @@ -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] @@ -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 { @@ -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 } diff --git a/loader/github.go b/loader/github.go index 897d10de3d3..028d8c773b6 100644 --- a/loader/github.go +++ b/loader/github.go @@ -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." diff --git a/loader/loader.go b/loader/loader.go index 5f8a1403033..24413512939 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -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) { @@ -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) }