Skip to content

Commit add0c88

Browse files
committed
loosen the requirement that the package.json file must be the top-most package.json
1 parent d998d06 commit add0c88

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

javascript/ql/src/semmle/javascript/PackageExports.qll

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,12 @@ DataFlow::ParameterNode getALibraryInputParameter() {
1717
}
1818

1919
/**
20-
* Gets the number of occurrences of "/" in `path`.
21-
*/
22-
bindingset[path]
23-
private int countSlashes(string path) { result = count(path.splitAt("/")) - 1 }
24-
25-
/**
26-
* Gets the topmost named package.json that appears in the project.
27-
*
28-
* There can be multiple results if the there exists multiple package.json that are equally deeply nested in the folder structure.
29-
* Results are limited to package.json files that are at most nested 2 directories deep.
30-
*/
31-
PackageJSON getTopmostPackageJSON() {
32-
result =
33-
min(PackageJSON j |
34-
countSlashes(j.getFile().getRelativePath()) <= 3 and
35-
exists(j.getPackageName())
36-
|
37-
j order by countSlashes(j.getFile().getRelativePath())
38-
)
39-
}
40-
41-
/**
42-
* Gets a value exported by the main module from one of the topmost `package.json` files (see `getTopmostPackageJSON`).
20+
* Gets a value exported by the main module from a named `package.json` file.
4321
* The value is either directly the `module.exports` value, a nested property of `module.exports`, or a method on an exported class.
4422
*/
4523
private DataFlow::Node getAValueExportedByPackage() {
46-
result = getAnExportFromModule(getTopmostPackageJSON().getMainModule())
24+
result =
25+
getAnExportFromModule(any(PackageJSON pack | exists(pack.getPackageName())).getMainModule())
4726
or
4827
result = getAValueExportedByPackage().(DataFlow::PropWrite).getRhs()
4928
or

0 commit comments

Comments
 (0)