Skip to content

Commit c8e5db1

Browse files
authored
Merge pull request github#3913 from erik-krogh/topmost
Approved by asgerf
2 parents 0bbdc70 + 00e900f commit c8e5db1

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ bindingset[path]
1313
private int countSlashes(string path) { result = count(path.splitAt("/")) - 1 }
1414

1515
/**
16-
* Gets the topmost package.json that appears in the project.
16+
* Gets the topmost named package.json that appears in the project.
1717
*
1818
* There can be multiple results if the there exists multiple package.json that are equally deeply nested in the folder structure.
1919
* Results are limited to package.json files that are at most nested 2 directories deep.
2020
*/
2121
PackageJSON getTopmostPackageJSON() {
2222
result =
2323
min(PackageJSON j |
24-
countSlashes(j.getFile().getRelativePath()) <= 3
24+
countSlashes(j.getFile().getRelativePath()) <= 3 and
25+
exists(j.getPackageName())
2526
|
2627
j order by countSlashes(j.getFile().getRelativePath())
2728
)

javascript/ql/test/library-tests/PackageExports/tests.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
getTopmostPackageJSON
2-
| absent_main/package.json:1:1:3:1 | {\\n " ... t.js"\\n} |
3-
| esmodules/package.json:1:1:3:1 | {\\n " ... n.js"\\n} |
4-
| lib1/package.json:1:1:3:1 | {\\n " ... n.js"\\n} |
52
getAValueExportedBy
63
| absent_main/package.json:1:1:3:1 | {\\n " ... t.js"\\n} | absent_main/index.js:1:1:1:0 | this |
74
| absent_main/package.json:1:1:3:1 | {\\n " ... t.js"\\n} | absent_main/index.js:1:1:1:14 | module.exports |

0 commit comments

Comments
 (0)