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

node: Prepare for a larger Npm refactoring #9385

Merged
merged 6 commits into from
Nov 6, 2024

Conversation

fviernau
Copy link
Member

@fviernau fviernau commented Nov 6, 2024

Prepare for re-writing large parts of Npm to solely rely on the npm command output to construct the dependency tree,
which will remove the inheritance between Yarn and Npm. To allow doing that, invert the inheritance between Yarn and Npm as a "temporary" refactoring step.

Also do further minor preparations.

Part of: #9261.

@fviernau fviernau requested a review from a team as a code owner November 6, 2024 10:53
Prepare for re-writing large parts of `Npm` to no more rely on the file
hierarchy of `node_modules` when constructing the dependency tree.

While the same is planned for `Yarn` too, this change is just a
refactoring step which allows to do `Npm` first.

Signed-off-by: Frank Viernau <[email protected]>
As of the recent refactoring of `Pnpm`, the is no more override of this
function in ORT. So, make the function private.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the prepare-for-refactoring-npm branch 2 times, most recently from 5497a72 to f015cc1 Compare November 6, 2024 11:06
@fviernau fviernau enabled auto-merge (rebase) November 6, 2024 11:07
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 56.77083% with 83 lines in your changes missing coverage. Please review.

Project coverage is 66.72%. Comparing base (390a055) to head (92f0710).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...-managers/node/src/main/kotlin/utils/NpmSupport.kt 55.84% 8 Missing and 26 partials ⚠️
...package-managers/node/src/main/kotlin/yarn/Yarn.kt 35.84% 34 Missing ⚠️
...s/package-managers/node/src/main/kotlin/npm/Npm.kt 75.40% 6 Missing and 9 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9385      +/-   ##
============================================
- Coverage     67.67%   66.72%   -0.96%     
- Complexity     1223     1236      +13     
============================================
  Files           244      247       +3     
  Lines          8626     8962     +336     
  Branches        911      974      +63     
============================================
+ Hits           5838     5980     +142     
- Misses         2413     2567     +154     
- Partials        375      415      +40     
Flag Coverage Δ
funTest-non-docker 33.74% <ø> (+0.17%) ⬆️
test 37.12% <56.77%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The functions `parseProject()` and `parsePackage()` are used by mutliple
package managers. Move them to `NpmSupport` which contains common code
to account for that.

Signed-off-by: Frank Viernau <[email protected]>
Align with `pnpm` and `yarn2`.

Signed-off-by: Frank Viernau <[email protected]>
Establish consistency and prepare for an upcoming refactoring of `Npm`
which will add further classes under the `npm` directory.

Signed-off-by: Frank Viernau <[email protected]>
Use an own logger instead of the one from `Npm`.

Signed-off-by: Frank Viernau <[email protected]>
@sschuberth
Copy link
Member

Merging despite the unrelated StackFunTest failure.

@sschuberth sschuberth merged commit ccdcad4 into main Nov 6, 2024
20 of 23 checks passed
@sschuberth sschuberth deleted the prepare-for-refactoring-npm branch November 6, 2024 13:10
@sschuberth
Copy link
Member

Merging despite the unrelated StackFunTest failure.

Oh, crap, sorry @oss-review-toolkit/core-devs, I was mixing this up with #9380 which I intended to merge!

Let me do a retrospective review to see if I need to revert things, or if we can live with the accidental merge.

Sorry again 😞

Copy link
Member

@sschuberth sschuberth left a comment

Choose a reason for hiding this comment

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

I've added a few retrospective comments. I don't think we need to revert the accidental merge, but getting relies to my questions would be nice for the sake of documenting things.

@@ -22,68 +22,41 @@
package org.ossreviewtoolkit.plugins.packagemanagers.node

import java.io.File
import java.util.concurrent.ConcurrentHashMap
Copy link
Member

Choose a reason for hiding this comment

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

Commit message:

While the same is planned for Yarn too, this change is just a refactoring step which allows to do Npm first.

As this refactoring moves around so much code which is hard to review, it would have been nice to explain why Npm is done first. Wouldn't it have been easier to do Yarn first?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doing this for Npm is way more straight forward than doing this for Yarn.
I wanted to do the low hanging fruit first, which also allows to quickly add workspaces support for NPM.

How to best implement this in Yarn I'm not sure. I'm considering to ask Yarn community whether they are open to a contribution to the list command, so that it outputs something which is less complex to process for our purpose.

Copy link
Member

Choose a reason for hiding this comment

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

I'm considering to ask Yarn community whether they are open to a contribution to the list command

But then we would depend on (at least) that Yarn version, which is probably not feasible anyway.

Copy link
Member Author

@fviernau fviernau Nov 6, 2024

Choose a reason for hiding this comment

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

Hm, why would this be problematic? I do remember similar thing for go mod.

Copy link
Member

Choose a reason for hiding this comment

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

Because projects might depend on a lower version of Yarn (for whatever reason), similar to like some projects depend on a lower Version of Gradle.

@@ -26,32 +26,13 @@ import java.io.File
import org.apache.logging.log4j.kotlin.logger

import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory
import org.ossreviewtoolkit.analyzer.PackageManager.Companion.getFallbackProjectName
Copy link
Member

Choose a reason for hiding this comment

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

Commit message:

  • Typo in "mutliple".

@@ -94,7 +95,7 @@ class Npm(
return runCatching {
val process = run(workingDir, "info", "--json", packageName)

parsePackageJson(process.stdout)
org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson(process.stdout)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a FQN now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just a mistake. Haven't noticed it.

@@ -247,8 +247,10 @@ internal fun parsePackage(
return module
}

private val logger = loggerOf(MethodHandles.lookup().lookupClass())
Copy link
Member

@sschuberth sschuberth Nov 6, 2024

Choose a reason for hiding this comment

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

I'd move this to the top to make more clear that all functions could make use of it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree.

@fviernau
Copy link
Member Author

fviernau commented Nov 6, 2024

I've addressed your (@sschuberth) comments where possible with #9389.

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