Skip to content

feat: Add support for 'npm-shrinkwrap.json' #747

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlexLaroche
Copy link
Contributor

What does this MR do ?

This PR adds support for npm-shrinkwrap.json.

Related issues

#697

Other usefull links

https://docs.npmjs.com/cli/v6/configuring-npm/shrinkwrap-json

wantResultMetric: stats.FileRequiredResultOK,
},
{
name: "npm-shrinkwrap.json as path segment",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also add tests for extraction working properly with some example npm.shrinkwrap.json files? See packagelockjson-v1_test.go. You can create a similar file called shrinkwrap_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder how useful this is considering that the files are identical and only the name changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be helpful if we can support this behavior but for the moment, I don't see a clean way to do so.

If both package-lock.json and npm-shrinkwrap.json are present in the root of a project, npm-shrinkwrap.json will take precedence and package-lock.json will be ignored.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that the precedence behavior was added let's add a test for it too

// If both package-lock.json and npm-shrinkwrap.json are present in the root of a project,
// npm-shrinkwrap.json will take precedence and package-lock.json will be ignored.
if filepath.Base(input.Path) == "package-lock.json" {
npmShrinkwrapPath := strings.TrimSuffix(input.Path, "package-lock.json") + "npm-shrinkwrap.json"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use path.Dir instead of strings.TrimSuffix - https://pkg.go.dev/path#Dir

wantResultMetric: stats.FileRequiredResultOK,
},
{
name: "npm-shrinkwrap.json as path segment",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that the precedence behavior was added let's add a test for it too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants