-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(nodejs): add root and workspace for yarn
packages
#8535
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
feat(nodejs): add root and workspace for yarn
packages
#8535
Conversation
- add root package (parse package.json) - add workspaces (parse workspace package.json files) - add workspaces as children of root package
yarn
packages
- use name|name@version for IDs - use hash of packagejson.Package if name is empty - rename types to ftypes - update tests
- restructure yarn paragraph - add info about root/workspace packages
Packages: types.Packages{ | ||
Packages: ftypes.Packages{ | ||
{ | ||
ID: "4b1aec5d292e8d22", |
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.
Perhaps we want to add some prefix for hash.
We also will need to use hash for cargo.
So it can be one prefix for all type, or we can relate prefix with type.
The name is empty. Is it intentional? I thought it would be possible to retrieve the workspace name from the |
@@ -25,7 +27,7 @@ import ( | |||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer" | |||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/language" | |||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/language/nodejs/license" | |||
"github.com/aquasecurity/trivy/pkg/fanal/types" | |||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types" |
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.
Any reasons for renaming it?
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 often use types
and ftypes
in the same file, so I'm used to using ftypes
.
To make it more uniform - I made this change.
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.
Ideally, we should not use pkg/types
under fanal
as all necessary types for fanal
are defined in pkg/fanal/types
. So, they will not conflict. Also, I think we can rename it once they actually conflict.
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.
If you want to rename it, I don't mind it, but can we change it in another PR? I want to focus on changes for this enhancement. It currently looks like there are many changes on GitHub, and I need to carefully distinguish which lines are changes due to ftypes
and which lines are related to the actual feature additions.
Additionally, for a personal reason, since I am reviewing this while traveling and do not have a large display, I have to scroll a lot to skip the ftypes
changes.
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.
No problem. It's not really important for me.
Also you're right - yarn analyzer package is already in fanal,
so it's not necessary to point it out again.
I returned types
in 9fb33ff
https://docs.npmjs.com/cli/v11/configuring-npm/package-json#name So possible cases when package.json from workspace doesn't have name/version
But perhaps we need to update logic for purl (don't create purl, if name is empty) |
It can be, but is it the default behavior? I mean I'm wondering if the workspace name will be empty by default. I didn't get how it works by default from the document. |
IIUC (i didn't find info about cli flags) - you need to add workspace dir into root package.json manually ( So you need to create yarn has I tested a bit: But IIRC - i already saw empty names in |
If an empty name is an edge case, I think it's better to use a normal case in the documentation and PR examples. Of course, it's okay to mention that empty names are also supported, but if they are not the typical case, it would be better to explain them as an exception. |
I thought you want to change logic for these cases. About docs - i think your are right. There is no need to confuse users once again. |
- don't create purl, if pkg doesn't have name
…ling - Updated test case naming for consistency. - Refactored yarn dependency analysis to enhance clarity and functionality. - Introduced methods for resolving root and workspace dependencies. - Improved error handling and logging for package.json parsing. - Removed deprecated dependency structures and streamlined the code. This refactor aims to enhance the maintainability and performance of the yarn analyzer.
…tionships - Updated package ID assignment logic to use file paths when package.json lacks a name or version. - Refactored workspace relationship assignments for improved clarity. - Removed deprecated methods related to package ID generation.
- Updated the documentation for Yarn dependency analysis to clarify the handling of additional files and package relationships. - Added sections on development dependencies and license detection to provide comprehensive coverage of Yarn's functionality. - Improved clarity in the explanation of how Trivy analyzes `package.json` files alongside `yarn.lock`.
In the end, I used the file path as the package ID when the name or version is empty. Using a hash value would also be possible, but since file paths are used in package-lock.json in npm, I thought this approach would be more common in Node.js projects. Cases where the name or version is empty are rare, so let's start with this simple approach for now. If any issues come up, we can switch to using hashes. |
Description
We added
workspace
relationship.So we can add
Root
andWorkspace
packages foryarn
.See #8012 for more details.
example:
TODO:
DependsOn
, if--include-dev-deps
flag is not exist.Related issues
workspace
relationship for them #8012Checklist