-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlibrary-info.ts
42 lines (33 loc) · 1.21 KB
/
library-info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { NormalizedPackageJson, PackageJson } from "read-pkg-up";
import readPkgUp from "read-pkg-up";
const valueOrUnknown = (value: string | undefined) => value ?? "unknown";
const packageJson: PackageJson | NormalizedPackageJson = readPkgUp.sync({ cwd: __dirname })?.packageJson ?? {};
const version = valueOrUnknown(packageJson.version);
export function getDevDependency(packageName: string): string | undefined {
const { devDependencies = {} } = packageJson;
return devDependencies[packageName];
}
export function getDependency(packageName: string): string | undefined {
const { dependencies = {} } = packageJson;
return dependencies[packageName];
}
export const LibraryInfo = {
/**
* The name of this package
*/
NAME: "@guardian/cdk",
/**
* The current version of `@guardian/cdk`.
*/
VERSION: version,
/**
* The version of the `aws-cdk-lib` library used by `@guardian/cdk`.
* You need to match this version exactly.
*/
AWS_CDK_VERSION: valueOrUnknown(getDependency("aws-cdk-lib")),
/**
* The version of the `constructs` library used by `@guardian/cdk`.
* You need to match this version exactly.
*/
CONSTRUCTS_VERSION: valueOrUnknown(getDependency("constructs")),
};