Skip to content

JS: More efficient nested package naming #19516

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

Merged
merged 2 commits into from
May 22, 2025

Conversation

asgerf
Copy link
Contributor

@asgerf asgerf commented May 19, 2025

Fixes a bad join order in PackageJson.getPackageName() for the case where a package is nested within another package.

Also NpmPackage.getAFile() had a discrepancy between its documentation, which states that files are only associated with their nearest enclosing package, but it actually associated files with all their enclosing packages. It now does what it says in the QLDoc. One of the queries that depended on the old behaviour has been updated accordingly.

@github-actions github-actions bot added the JS label May 19, 2025
@asgerf asgerf force-pushed the js/npm-package-name-join branch from 5a652d5 to 317e61d Compare May 19, 2025 10:53
@asgerf asgerf added the no-change-note-required This PR does not need a change note label May 20, 2025
@asgerf asgerf marked this pull request as ready for review May 20, 2025 09:29
@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 09:29
@asgerf asgerf requested a review from a team as a code owner May 20, 2025 09:29
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors how nested NPM packages are named and aligns file-package associations with documentation by introducing a new helper, updating existing queries, and adjusting tests.

  • Added PackageJson.getEnclosingPackage() and simplified getPackageName() to correctly handle nested package naming.
  • Updated UnresolvableImport.ql to consider all enclosing packages when checking dependencies.
  • Removed an outdated expectation in the NPM library test suite.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
javascript/ql/lib/semmle/javascript/NPM.qll Added getEnclosingPackage, refactored getPackageName, and tweaked packageInternalParent
javascript/ql/src/NodeJS/UnresolvableImport.ql Switched to using getEnclosingPackage*() in the dependency check
javascript/ql/test/library-tests/NPM/tests.expected Removed the stale expected line for the nested sub-module case

Copy link
Contributor

@Napalys Napalys left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

@asgerf asgerf merged commit 9202a1b into github:main May 22, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants