* Get the capabilities by reading the version from package_graph.json. * * Returns `undefined` if the graph/version cannot be read.
(logger: Logger, packageFile: string)
| 17 | * Returns `undefined` if the graph/version cannot be read. |
| 18 | */ |
| 19 | function getCapabilitiesFromVersionInPackageGraph(logger: Logger, packageFile: string): DartTestCapabilities | undefined { |
| 20 | const packageGraphFile = path.join(path.dirname(packageFile), "package_graph.json"); |
| 21 | |
| 22 | try { |
| 23 | const packageGraphJson = fs.readFileSync(packageGraphFile, "utf8"); |
| 24 | const packageGraph = JSON.parse(packageGraphJson) as PackageGraphJson; |
| 25 | const testVersion = packageGraph.packages?.find((pkg) => pkg.name === "test")?.version; |
| 26 | |
| 27 | if (!testVersion) |
| 28 | return undefined; |
| 29 | |
| 30 | if (semver.valid(testVersion)) |
| 31 | return new DartTestCapabilities(testVersion); |
| 32 | |
| 33 | logger.warn(`Failed to parse pkg:test version number from ${packageGraphFile}: ${testVersion}`); |
| 34 | } catch (e: any) { |
| 35 | if (e?.code !== "ENOENT") |
| 36 | logger.warn(`Failed to read pkg:test version number from ${packageGraphFile}: ${e}`); |
| 37 | } |
| 38 | |
| 39 | return undefined; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Gets the pkg:test capabilities for a Dart project. |
no test coverage detected