Merge pull request #5581 from asgerf/js/dependency-info

Approved by esbena
This commit is contained in:
CodeQL CI
2021-04-01 09:07:21 +01:00
committed by GitHub
4 changed files with 35 additions and 11 deletions

View File

@@ -127,18 +127,22 @@ class ExternalNPMDependency extends NPMDependency {
exists(PackageDependencies pkgdeps | this = pkgdeps.getPropValue(result))
}
override string getVersion() {
private string getVersionNumber() {
exists(string versionRange | versionRange = this.(JSONString).getValue() |
// extract a concrete version from the version range; currently,
// we handle exact versions as well as `<=`, `>=`, `~` and `^` ranges
result = versionRange.regexpCapture("(?:[><]=|[=~^])?v?(\\d+(\\.\\d+){1,2})", 1)
or
// if no version is specified, report version `unknown`
result = "unknown" and
(versionRange = "" or versionRange = "*")
)
}
override string getVersion() {
result = getVersionNumber()
or
// if no version is specified or could not be parsed, report version `unknown`
not exists(getVersionNumber()) and
result = "unknown"
}
override Import getAnImport() {
exists(int depth | depth = importsDependency(result, getDeclaringPackage(), this) |
// restrict to those results for which this is the closest matching dependency