-
Notifications
You must be signed in to change notification settings - Fork 110
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
fix(npm): improvement logic for lockfile v2-v3 #196
fix(npm): improvement logic for lockfile v2-v3 #196
Conversation
// └─┬ watchpack@1.7.5 | ||
// ├─┬ chokidar@3.5.3 - optional dependency | ||
// │ └── glob-parent@5.1. | ||
dependencies := lo.Assign(pkg.Dependencies, pkg.OptionalDependencies) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you add a test for optional dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can update the existing test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added optional deps to testcases
pkg/nodejs/npm/parse.go
Outdated
@@ -253,6 +260,11 @@ func pkgNameFromPath(path string) string { | |||
// node_modules/string-width | |||
// node_modules/string-width/node_modules/strip-ansi | |||
paths := strings.Split(path, "/") | |||
// deps starting from `@` have pgkName with one `/` | |||
// e.g. path == `node_modules/@babel/plugin-transform-classes` => pkgName == `@babel/plugin-transform-classes` | |||
if strings.HasPrefix(paths[len(paths)-2], "@") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not happen, but I think we should check the length just in case.
if strings.HasPrefix(paths[len(paths)-2], "@") { | |
if len(paths) >= 2 && strings.HasPrefix(paths[len(paths)-2], "@") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Description
node_modules
folder. We also need to include them.e.g.
graph:
/
in package name.e.g. @babel/plugin-transform-classes
these dependencies start from
@
. We need to parse them properly.