-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: Implement Yarn Berry Analyser #7319
Conversation
Thank you so much for this! This really simplifies our lives with multi-language projects driven by a Maven build (Java backend, JavaScript frontend). Btw, it might also fix #4215. I think this can and should be improved to reduce future maintenance costs. Think about what happens when Yarn releases the next breaking change (like classic --> Berry)? I would like to see a Yarn analyzer abstraction with some sort of auto-detection mechanism. IMO users should only have to set the Can you extract a |
@marcelstoer completely agree - your suggestions are spot on. |
With the updated PR, I have refactored |
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.
LGTM - I left some suggestions around the yarn version number. I prefer to use something like semver4j
as we already have it on the classpath.
core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractYarnAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractYarnAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/owasp/dependencycheck/analyzer/YarnBerryAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/owasp/dependencycheck/analyzer/YarnClassicAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractYarnAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
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 looks like the build failed:
YarnBerryAuditAnalyzerIT.testAnalyzePackageYarn:46 More than 1 dependency should be identified
Do we need to update the workflow itself to include yarn berry?
FWIW the canonical way to run and install yarn 2+ is via corepack and source controlling yarn itself alongside a package.json which defines the version number. https://yarnpkg.com/getting-started/install Although you can use yarn 1 to switch dynamically to yarn 2+.projects if you have to. Ideally the tests should test a project that has package.json etc preconfigured for yarn usage and 'corepack enable' run on the npm install. This has the advantage that specific yarn versions are source controlled alongside the tests in the |
@segovia thanks for the updated version. This is much more maintainable now! |
Thank you all for your feedback and suggestions. With my latest update, I incorporated semver4j and named the magic number 1 as YARN_CLASSIC_MAJOR_VERSION. Concerning the integration test, I suggest putting the latest yarn berry .cjs file somewhere. In my commit, I put it in core/src/test/resources/yarn-berry-audit/.yarn/releases/yarn-4.6.0.cjs, but if you don't want the yarn .cjs to be part of the commit, it could be placed anywhere else. I am not familiar with the container running the tests, but if we add it somewhere specific there, I can reference it in the |
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.
@segovia sorry about the back-and-forth on this one. Can you double-check the comparisons for the String
-> 'int
conversion?
core/src/main/java/org/owasp/dependencycheck/analyzer/YarnClassicAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/owasp/dependencycheck/analyzer/YarnBerryAuditAnalyzer.java
Outdated
Show resolved
Hide resolved
277a13e
to
04ebeb5
Compare
I pushed an update in an attempt to fix the tests. Unfortunately, I am not able to run all the tests locally. In case it fails again, is there some documentation on how to run the tests locally? Or do you have any tips? |
I've been trying to figure out why the test case is failing - locally I've just been using variations of this:
In order for the tests to run on core, utils has to have been packaged in the execution. |
Looking at why the tests were failing and the fix - I don't think the enable/disable function is going to work correctly in the wild. I know how to fix it - but it will take a bit of refactoring. Instead of having two separate analyzers a single analyzer should use the correct mechanism to |
@segovia do you want me to do the refactoring - or do you want to? |
@jeremylong I've taken your feedback into consideration. Now we determine which method to use based on the dependency's directory. Hopefully, this is what you were thinking. In any case, if any further modifications are required, please feel free to adapt. |
24b886f
to
e47b4b2
Compare
@segovia thank you for all your work on this. It might be another day or two before I can do a final review and get this merged. |
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.
LGTM
@segovia thanks for contributing!!!! |
Thanks for the feedback and merging! |
I have implemented an Analyzer to address the issue that DependencyCheck does not work with projects that use yarn berry (#4894). This is a first draft and I would be happy to implement tests and make any other modifications if there is interest to merge this to main.