JS: More efficient nested package naming#19516
Merged
asgerf merged 2 commits intogithub:mainfrom May 22, 2025
Merged
Conversation
5a652d5 to
317e61d
Compare
Contributor
There was a problem hiding this comment.
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 simplifiedgetPackageName()to correctly handle nested package naming. - Updated
UnresolvableImport.qlto 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.