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 {
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" ) }
You can’t perform that action at this time.
0 commit comments