Skip to content

Commit c07bba7

Browse files
committed
version-checks
1 parent 40bdd92 commit c07bba7

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

Diff for: bin/check-bundle-version.ts

+40-18
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import { parseArgs } from "jsr:@std/cli/parse-args";
1818
import { join } from "jsr:@std/path";
1919

20-
async function load(fp: string): Promise<string> {
20+
async function load(fp: string): Promise<{ version: string }> {
2121
const src = await Deno.readTextFile(fp);
22-
const { version } = JSON.parse(src);
23-
return version;
22+
return JSON.parse(src);
2423
}
2524

2625
const argv = parseArgs(
@@ -29,8 +28,10 @@ const argv = parseArgs(
2928
alias: {
3029
"m": ["module"],
3130
"t": ["tag"],
31+
"f": ["fix"],
3232
},
3333
string: ["module", "tag"],
34+
boolean: ["fix"],
3435
},
3536
);
3637

@@ -46,8 +47,9 @@ if (module === null) {
4647
let version: string;
4748

4849
if (module.startsWith("transport-")) {
49-
let packageVersion: string = "";
50-
const versionFile = await load(join(module, "src", "version.json"));
50+
let packageVersion: { version: string } | undefined;
51+
const versionFilePath = join(module, "src", "version.json");
52+
let versionFile = await load(versionFilePath);
5153
switch (module) {
5254
case "transport-node":
5355
packageVersion = await load(join(module, "package.json"));
@@ -68,24 +70,44 @@ if (module.startsWith("transport-")) {
6870
);
6971
Deno.exit(1);
7072
}
71-
if (packageVersion !== versionFile) {
73+
if (packageVersion.version !== versionFile.version) {
74+
if (argv.fix) {
75+
versionFile = { version: packageVersion.version };
76+
await Deno.writeTextFile(
77+
versionFilePath,
78+
JSON.stringify(versionFile, null, 2),
79+
);
80+
console.log(
81+
`[OK] updated ${versionFilePath} to ${packageVersion.version}`,
82+
);
83+
Deno.exit(0);
84+
}
7285
console.error(
73-
`[ERROR] expected versions to match - package: ${packageVersion} src/version.json: ${versionFile}`,
86+
`[ERROR] expected versions to match - package: ${packageVersion.version} src/version.json: ${versionFile.version}`,
7487
);
7588
Deno.exit(1);
7689
}
77-
version = versionFile;
90+
version = versionFile.version;
7891
} else {
7992
const deno = await load(join(module, "deno.json"));
80-
const node = await load(join(module, "package.json"));
93+
version = deno.version;
94+
const nodePackagePath = join(module, "package.json");
95+
const node = await load(nodePackagePath);
8196

82-
if (deno !== node) {
83-
console.error(
84-
`[ERROR] expected versions to match - deno.json: ${deno} package.json: ${node}`,
85-
);
86-
Deno.exit(1);
97+
if (deno.version !== node.version) {
98+
if (argv.fix) {
99+
node.version = deno.version;
100+
await Deno.writeTextFile(nodePackagePath, JSON.stringify(node, null, 2));
101+
console.log(`[OK] updated ${nodePackagePath} to ${deno.version}`);
102+
Deno.exit(0);
103+
} else {
104+
console.error(
105+
`[ERROR] expected versions to match - deno.json: ${deno.version} package.json: ${node.version}`,
106+
);
107+
Deno.exit(1);
108+
}
87109
}
88-
version = deno;
110+
node.version = deno.version;
89111
}
90112

91113
if (argv.tag) {
@@ -94,12 +116,12 @@ if (argv.tag) {
94116
if (tag.startsWith(prefix)) {
95117
tag = tag.substring(prefix.length);
96118
}
97-
if (tag !== version) {
119+
if (tag !== version!) {
98120
console.error(
99-
`[ERROR] expected tag version to match - bundle: ${version} tag: ${argv.tag}}`,
121+
`[ERROR] expected tag version to match - bundle: ${version!} tag: ${argv.tag}}`,
100122
);
101123
Deno.exit(1);
102124
}
103125
}
104-
126+
console.log(`[OK] ${module} version ${version!}`);
105127
Deno.exit(0);

Diff for: core/package.json

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"name": "@nats-io/nats-core",
33
"version": "3.0.0-17",
4-
"files": ["lib/", "esm/"],
4+
"files": [
5+
"lib/",
6+
"esm/"
7+
],
58
"types": "./lib/mod.d.js",
6-
"exports": { ".": "./lib/mod.js", "./internal": "./lib/internal_mod.js" },
9+
"exports": {
10+
".": "./lib/mod.js",
11+
"./internal": "./lib/internal_mod.js"
12+
},
713
"license": "Apache-2.0",
814
"private": false,
915
"scripts": {
@@ -15,13 +21,18 @@
1521
"prepack": "npm run build"
1622
},
1723
"keywords": [],
18-
"author": { "name": "The NATS Authors" },
24+
"author": {
25+
"name": "The NATS Authors"
26+
},
1927
"description": "nats-core library - this library implements all the base functionality for NATS javascript clients",
2028
"dependencies": {
2129
"@nats-io/nkeys": "1.2.0-4",
2230
"@nats-io/nuid": "2.0.1-2",
2331
"shx": "^0.3.4",
2432
"typescript": "^5.4.5"
2533
},
26-
"devDependencies": { "@types/node": "^20.11.30", "typedoc": "^0.25.12" }
34+
"devDependencies": {
35+
"@types/node": "^20.11.30",
36+
"typedoc": "^0.25.12"
37+
}
2738
}

Diff for: obj/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nats-io/obj",
3-
"version": "3.0.0-2",
3+
"version": "3.0.0-1",
44
"files": [
55
"lib/"
66
],

Diff for: services/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nats-io/services",
3-
"version": "3.0.0-2",
3+
"version": "3.0.0-1",
44
"files": [
55
"lib/"
66
],

0 commit comments

Comments
 (0)