File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
javascript/ql/lib/semmle/javascript Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,25 @@ class PackageJson extends JsonObject {
12
12
this .isTopLevel ( )
13
13
}
14
14
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
+ }
17
34
18
35
/** Gets the version of this package. */
19
36
string getVersion ( ) { result = this .getPropStringValue ( "version" ) }
You can’t perform that action at this time.
0 commit comments