mirror of
https://github.com/github/codeql.git
synced 2026-04-24 00:05:14 +02:00
JS: Add some helpers
This commit is contained in:
@@ -75,6 +75,19 @@ class Folder extends Container, Impl::Folder {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an implementation file and/or a typings file from this folder that has the given `stem`.
|
||||
* This could be a single `.ts` file or a pair of `.js` and `.d.ts` files.
|
||||
*/
|
||||
File getJavaScriptFileOrTypings(string stem) {
|
||||
exists(File jsFile | jsFile = this.getJavaScriptFile(stem) |
|
||||
result = jsFile
|
||||
or
|
||||
not jsFile.getFileType().isTypeScript() and
|
||||
result = this.getFile(stem + ".d.ts")
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets a subfolder contained in this folder. */
|
||||
Folder getASubFolder() { result = this.getAChildContainer() }
|
||||
}
|
||||
|
||||
@@ -12,12 +12,21 @@ class PackageJson extends JsonObject {
|
||||
this.isTopLevel()
|
||||
}
|
||||
|
||||
/** Gets the folder containing this `package.json` file. */
|
||||
Folder getFolder() { result = this.getJsonFile().getParentContainer() }
|
||||
|
||||
/**
|
||||
* Gets the name of this package as it appears in the `name` field.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
string getDeclaredPackageName() { result = this.getPropStringValue("name") }
|
||||
|
||||
/**
|
||||
* Gets the name of this package.
|
||||
* If the package is located under the package `pkg1` and its relative path is `foo/bar`, then the resulting package name will be `pkg1/foo/bar`.
|
||||
*/
|
||||
string getPackageName() {
|
||||
result = this.getPropStringValue("name")
|
||||
result = this.getDeclaredPackageName()
|
||||
or
|
||||
exists(
|
||||
PackageJson parentPkg, Container currentDir, Container parentDir, string parentPkgName,
|
||||
|
||||
Reference in New Issue
Block a user