Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate magic resolving of cdnjs and github "URLs" #3671

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 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, path string, parts []string) (string, error) {
func cdnjs(logger logrus.FieldLogger, specifier 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, path string, parts []string) (string, erro
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, path)
version, specifier)
}
backupFilename = ver.Files[0]
for _, file := range ver.Files {
Expand All @@ -70,5 +70,7 @@ func cdnjs(logger logrus.FieldLogger, path string, parts []string) (string, erro
}
}

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

import "github.com/sirupsen/logrus"

func github(_ logrus.FieldLogger, _ string, parts []string) (string, error) {
func github(logger logrus.FieldLogger, specifier string, parts []string) (string, error) {
username := parts[0]
repo := parts[1]
filepath := parts[2]
return "https://raw.githubusercontent.com/" + username + "/" + repo + "/master/" + filepath, nil
realURL := "https://raw.githubusercontent.com/" + username + "/" + repo + "/master/" + filepath
logger.Warnf(magicURLsDeprecationWarning, specifier, "github", realURL)
return realURL, 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."
Copy link
Contributor

@codebien codebien Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."
const magicURLsDeprecationWarning = "Specifier %q was resolved by a non-conventional %s loader. " +
"The used %q loader is deprecated and will be removed in k6 v0.53.0. Please, use the real URL %q instead."

In any case, my feeling is that non-conventional isn't clear enough information. Is there a de-facto list of conventional loaders for JavaScript that I'm not aware of?
I don't think we define somewhere the k6 conventional (supported?) loaders. We should explicit them here or in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't - and there is no documentation about cdnjs and github loaders for years at this point - we did drop it from every documentation like 3+ years ago.

I do agree - but IMO us making this message be more specific likely will have no benefit. I have not seen anyone use the github ones ever and the cdnjs ones seems to be used very rarely.

So my expectation is most people will never see this message.

If you have a concrete simple fix - I am all for it, but my only other proposal was "magic" (with quotes) and I think that is even less obvious.

I would also argue that most people will agree that pure paths and URLs are the "conventional" specifiers even if the specification has left this completely unspecified 😉 😉

Loading