@dbx-tools/projen 0.6.194 → 0.6.196

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env -S bun
2
+ /** Verify that every committed package version matches the workspace VERSION. */
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { exec, project } from "@dbx-tools/core";
6
+ import { find } from "@dbx-tools/path";
7
+ import { json, log, object } from "@dbx-tools/shared-core";
8
+ import { parse } from "smol-toml";
9
+ import { recordedPackages } from "../src/packages.ts";
10
+ import { readWorkspaceVersion } from "../src/workspace-version.ts";
11
+
12
+ const logger = log.logger("projen:version-check");
13
+
14
+ function manifestVersion(path: string): string | undefined {
15
+ const manifest = json.parseRecord(readFileSync(path, "utf8"));
16
+ return typeof manifest?.version === "string" ? manifest.version : undefined;
17
+ }
18
+
19
+ function pythonVersion(path: string): string | undefined {
20
+ const manifest = parse(readFileSync(path, "utf8")) as {
21
+ project?: { version?: unknown };
22
+ };
23
+ return typeof manifest.project?.version === "string" ? manifest.project.version : undefined;
24
+ }
25
+
26
+ function cargoVersions(root: string): Array<{ name: string; version: string }> {
27
+ if (!existsSync(join(root, "Cargo.toml"))) return [];
28
+ const locked = existsSync(join(root, "Cargo.lock"));
29
+ const result = exec.spawnSync(
30
+ "cargo",
31
+ ["metadata", ...(locked ? ["--locked"] : []), "--format-version", "1", "--no-deps"],
32
+ {
33
+ cwd: root,
34
+ stdout: "capture",
35
+ stderr: "inherit",
36
+ stdin: "ignore",
37
+ check: true,
38
+ },
39
+ );
40
+ const metadata = json.parseRecord(result.stdout ?? "");
41
+ if (!Array.isArray(metadata?.packages)) return [];
42
+ return metadata.packages.flatMap((candidate) => {
43
+ if (
44
+ !object.isRecord(candidate) ||
45
+ typeof candidate.name !== "string" ||
46
+ typeof candidate.version !== "string"
47
+ ) {
48
+ return [];
49
+ }
50
+ return [{ name: candidate.name, version: candidate.version }];
51
+ });
52
+ }
53
+
54
+ function main(): void {
55
+ const root = project.root() ?? process.cwd();
56
+ const version = readWorkspaceVersion(root);
57
+ const mismatches: string[] = [];
58
+ const check = (name: string, actual: string | undefined): void => {
59
+ if (actual !== version) mismatches.push(`${name}: ${actual ?? "missing"} != ${version}`);
60
+ };
61
+
62
+ check("package.json", manifestVersion(join(root, "package.json")));
63
+ for (const pkg of recordedPackages(root)) {
64
+ check(`${pkg.path}/package.json`, manifestVersion(join(pkg.dir, "package.json")));
65
+ const barrel = join(pkg.dir, "index.ts");
66
+ if (existsSync(barrel)) {
67
+ const actual = /export const PACKAGE_VERSION = "([^"]+)";/.exec(
68
+ readFileSync(barrel, "utf8"),
69
+ )?.[1];
70
+ check(`${pkg.path}/index.ts`, actual);
71
+ }
72
+ }
73
+
74
+ for (const path of find.findFiles("**/pyproject.toml", { cwd: root })) {
75
+ check(path, pythonVersion(join(root, path)));
76
+ }
77
+ for (const pkg of cargoVersions(root)) check(`Cargo package ${pkg.name}`, pkg.version);
78
+
79
+ if (mismatches.length > 0) {
80
+ throw new Error(`Workspace version mismatch:\n${mismatches.join("\n")}`);
81
+ }
82
+ logger.success(`all workspace versions match ${version}`);
83
+ }
84
+
85
+ main();