Skip to content

Commit c0cf0b4

Browse files
committed
JS: support submodules
1 parent 3d41cd5 commit c0cf0b4

File tree

1 file changed

+19
-2
lines changed
  • javascript/ql/lib/semmle/javascript

1 file changed

+19
-2
lines changed

javascript/ql/lib/semmle/javascript/NPM.qll

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,25 @@ class PackageJson extends JsonObject {
1212
this.isTopLevel()
1313
}
1414

15-
/** Gets the name of this package. */
16-
string getPackageName() { result = this.getPropStringValue("name") }
15+
/**
16+
* Gets the name of this package.
17+
* If the package is located under the package `foo` and its relative path is `bar`, it can be `foo/bar`
18+
*/
19+
string getPackageName() {
20+
result = this.getPropStringValue("name")
21+
or
22+
exists(
23+
PackageJson parentPackage, string currentDir, string parentDir, string parentPackageName
24+
|
25+
currentDir = this.getJsonFile().getParentContainer().getAbsolutePath() and
26+
parentDir = parentPackage.getJsonFile().getParentContainer().getAbsolutePath() and
27+
parentPackageName = parentPackage.getPropStringValue("name") and
28+
parentDir.indexOf("node_modules") != -1 and
29+
currentDir != parentDir and
30+
currentDir.indexOf(parentDir) = 0 and
31+
result = parentPackageName + currentDir.suffix(parentDir.length())
32+
)
33+
}
1734

1835
/** Gets the version of this package. */
1936
string getVersion() { result = this.getPropStringValue("version") }

0 commit comments

Comments
 (0)