Skip to content

Commit 3d655eb

Browse files
committed
[CHORE] externalize version reported by the client to a JSON file
1 parent bca0b67 commit 3d655eb

File tree

5 files changed

+19
-33
lines changed

5 files changed

+19
-33
lines changed

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

+2-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 The NATS Authors
2+
* Copyright 2021-2024 The NATS Authors
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -12,33 +12,7 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
const src = await Deno.readTextFile("src/node_transport.ts");
16-
const lines = src.split("\n");
17-
const filtered = lines.filter((txt) => {
18-
return txt.indexOf("const VERSION") === 0;
19-
});
20-
let parsed = filtered.map((line) => {
21-
const chunks = line.split(" ");
22-
if (
23-
chunks.length === 4 &&
24-
chunks[0] === "const" &&
25-
chunks[1] === "VERSION" &&
26-
chunks[2] === "="
27-
) {
28-
let v = chunks[3].replace(";", "");
29-
v = JSON.parse(v);
30-
return v;
31-
}
32-
});
33-
parsed = parsed ?? [];
34-
if (parsed.length !== 1) {
35-
console.error(`[ERROR] unexpected number of matches on 'const VERSION'.`);
36-
Deno.exit(1);
37-
}
38-
let VERSION = "";
39-
if (parsed.length === 1) {
40-
VERSION = parsed[0] ?? "";
41-
}
15+
const { VERSION } = JSON.parse(await Deno.readTextFile("src/version.json"));
4216

4317
const pkg = await Deno.readTextFile("package.json");
4418
const m = JSON.parse(pkg);

Diff for: transport-node/src/node_transport.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import { connect as tlsConnect, TlsOptions, TLSSocket } from "tls";
3333
const { resolve } = require("path");
3434
const { readFile, existsSync } = require("fs");
3535
const dns = require("dns");
36-
37-
const VERSION = "2.26.0";
36+
const data = require("./version.json");
37+
export const VERSION = data.version;
3838
const LANG = "nats.js";
3939

4040
export class NodeTransport implements Transport {

Diff for: transport-node/src/version.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "3.0.0-1"
3+
}

Diff for: transport-node/tests/basics_test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const {
2323
"../lib/mod",
2424
);
2525

26+
const {
27+
VERSION,
28+
} = require("../lib/node_transport");
29+
2630
const { Lock } = require("./helpers/lock");
2731
const { NatsServer } = require("./helpers/launcher");
2832
const { jetstreamServerConf } = require("./helpers/jsutil.js");
@@ -33,9 +37,13 @@ describe(
3337
"basics",
3438
{ timeout: 20_000, concurrency: true, forceExit: true },
3539
() => {
40+
it("basics - reported version", async () => {
41+
const pkg = require("../package.json");
42+
assert.equal(VERSION, pkg.version);
43+
});
3644
it("basics - connect default", async () => {
3745
const ns = await NatsServer.start({ port: 4222 });
38-
const nc = await connect();
46+
const nc = await connect({ debug: true });
3947
await nc.flush();
4048
await nc.close();
4149
await ns.stop();

Diff for: transport-node/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
"sourceMap": true,
88
"declaration": true,
99
"allowJs": true,
10-
"removeComments": false
10+
"removeComments": false,
11+
"resolveJsonModule": true
1112
},
1213
"include": [
13-
"src"
14+
"src/**/*"
1415
],
1516
"exclude": [
1617
"transport-node/test/**/*",

0 commit comments

Comments
 (0)