-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvalidate-package-version.mjs
More file actions
45 lines (37 loc) · 1.1 KB
/
validate-package-version.mjs
File metadata and controls
45 lines (37 loc) · 1.1 KB
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
43
44
45
import {glob} from "node:fs/promises"
import path from "node:path"
async function main(expectedVersion) {
// biome-ignore lint/style/noParameterAssign: ignore
expectedVersion = expectedVersion.startsWith("v")
? expectedVersion.split("v")[1]
: expectedVersion
if (!/^\d+.\d+.\d+(-alpha\.\d+)?$/.test(expectedVersion)) {
throw new Error(`Invalid version '${expectedVersion}'`)
}
const packages = glob("packages/*/package.json")
console.info(`checking all packages are version ${expectedVersion}`)
for await (const it of packages) {
const {private: isPrivate, version} = (
await import(path.join("..", it), {with: {type: "json"}})
).default
if (isPrivate) {
console.info(`skipping private package ${it}`)
continue
} else {
console.info(`checking ${it}`)
}
if (version !== expectedVersion) {
throw new Error(
`Package ${it} has version ${version} but should be ${expectedVersion}`,
)
}
}
}
try {
await main(process.argv[2])
console.info("success")
process.exit(0)
} catch (err) {
console.error(err)
process.exit(1)
}