Skip to content

Map unmatched node_modules files - #796

Closed
keshav-space wants to merge 7 commits into
mainfrom
650-npm-lookup
Closed

Map unmatched node_modules files#796
keshav-space wants to merge 7 commits into
mainfrom
650-npm-lookup

Conversation

@keshav-space

@keshav-space keshav-space commented Jul 3, 2023

Copy link
Copy Markdown
Member

Map the 3rd-party files inside node_modules that couldn't be matched to PurlDB due to slight modifications.

@tdruez

tdruez commented Jul 26, 2023

Copy link
Copy Markdown
Contributor

@keshav-space is this PR complete and ready to be reviewed?
If not, please provide the latest status and a list of remaining tasks.

@keshav-space

Copy link
Copy Markdown
Member Author

@keshav-space is this PR complete and ready to be reviewed? If not, please provide the latest status and a list of remaining tasks.

@tdruez PR is complete and ready for review.

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See some nits for your review.

Comment thread scanpipe/pipes/js.py
Comment thread scanpipe/pipes/purldb.py
@pombredanne

Copy link
Copy Markdown
Member

Also can you elaborate in the body of the PR what this is doing?

Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
@keshav-space
keshav-space force-pushed the 650-npm-lookup branch 2 times, most recently from 293ddc5 to 9bd1fc7 Compare August 2, 2023 17:16
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
Comment thread scanpipe/pipes/d2d.py
if package:
package.add_resources(matched)
else:
if results := purldb.fetch_package(purl=str(purl)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure about depending on a purldb call deep within a d2d pipe.
@pombredanne what's your take on this architecture? We've only implemented pipes and steps dedicated to purldb so far.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How is this different? Is this not mostly a purldb step?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or would you want to have a separate step?
@tdruez what alternative approach would you see?

@pombredanne pombredanne Aug 17, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok I get the problem.... @keshav-space @tdruez here my suggestion:

  1. We have directory and we get an npm PURL from this. If we are reaching here, the package instance for this directory does not exist IMHO. We should not reuse randomly the first package.
  2. We should then create a new "skinny" package based on the PURL and assign the resources to it, with extra care for possible nested "node_modules".
  3. If somehow, we have package.json data available nearby on disk, we should use this to enhance the package data
  4. As a completely and new separate step, we could lookup in the PURL for some packages that are missing some details, like license and similar, BUT not in this step. This should be designed carefully in a new issue. Do we want to "enhance" all the packages with PURLDB data? Or is this only for npms? Which field do we update? etc... See Enhance Discovered Packages with PurlDB data #869 to track this

Comment thread scanpipe/pipes/js.py


def get_purl_from_node_module(node_module_directory):
"""Return PURL for given a `node_modules` package directory."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we have some examples of the paths in the docstring?

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here is some extre feedback.

Comment thread scanpipe/pipes/d2d.py
project,
):
"""Map unmatched ``node_modules`` files."""
purl = js.get_purl_from_node_module(to_directory.path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread scanpipe/pipes/d2d.py
namespace="" if not purl.namespace else purl.namespace,
name=purl.name,
version=purl.version,
).first()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this first() call may be problematic.... this may be a package that is for completely unrelated resources, and we may end-up assigning the wrong resources to a package or the resources to the wrong package

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also since we are doing something to create a package, would we ever be in a case where we have an existing package for the same resources that exists? IMHO it would never exist, otherwise why would be doing this work in the first place?

Comment thread scanpipe/pipes/d2d.py
):
"""Map unmatched ``node_modules`` files."""
purl = js.get_purl_from_node_module(to_directory.path)
matched = to_resources.filter(path__startswith=to_directory.path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if we have nested node_modules directories> the nested sub-dirs are for different packages

Comment thread scanpipe/pipes/d2d.py
if package:
package.add_resources(matched)
else:
if results := purldb.fetch_package(purl=str(purl)):

@pombredanne pombredanne Aug 17, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok I get the problem.... @keshav-space @tdruez here my suggestion:

  1. We have directory and we get an npm PURL from this. If we are reaching here, the package instance for this directory does not exist IMHO. We should not reuse randomly the first package.
  2. We should then create a new "skinny" package based on the PURL and assign the resources to it, with extra care for possible nested "node_modules".
  3. If somehow, we have package.json data available nearby on disk, we should use this to enhance the package data
  4. As a completely and new separate step, we could lookup in the PURL for some packages that are missing some details, like license and similar, BUT not in this step. This should be designed carefully in a new issue. Do we want to "enhance" all the packages with PURLDB data? Or is this only for npms? Which field do we update? etc... See Enhance Discovered Packages with PurlDB data #869 to track this

@keshav-space

Copy link
Copy Markdown
Member Author

closing this in favour of #881

@keshav-space
keshav-space deleted the 650-npm-lookup branch March 18, 2024 09:13
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.

3 participants