JS: check scoped package and normal package

This commit is contained in:
tyage 2023-05-03 13:19:59 +09:00
Родитель be9c8d28b5
Коммит 22f5b7a18b
1 изменённых файлов: 10 добавлений и 4 удалений

Просмотреть файл

@ -19,14 +19,20 @@ class PackageJson extends JsonObject {
string getPackageName() {
result = this.getPropStringValue("name")
or
exists(PackageJson parentPkg, Container currentDir, Container parentDir |
exists(PackageJson parentPkg, Container currentDir, Container parentDir, string parentPkgName |
currentDir = this.getJsonFile().getParentContainer() and
parentDir = parentPkg.getJsonFile().getParentContainer() and
parentDir.getParentContainer+().getBaseName() = "node_modules" and
parentPkgName = parentPkg.getPropStringValue("name") and
(
parentDir.getParentContainer().getBaseName() = "node_modules"
or
// Scoped package is located in node_modules/@scope/pkgname
parentDir.getParentContainer().getParentContainer().getBaseName() = "node_modules" and
exists(parentPkgName.indexOf("/"))
) and
parentDir.getAChildContainer+() = currentDir and
result =
parentPkg.getPropStringValue("name") +
currentDir.getAbsolutePath().suffix(parentDir.getAbsolutePath().length())
parentPkgName + currentDir.getAbsolutePath().suffix(parentDir.getAbsolutePath().length())
)
}