@kylecheng3146/agent-ops 0.1.8 → 0.1.9
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.
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
function readPackageVersion() {
|
|
5
|
+
let directory = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
while (true) {
|
|
7
|
+
try {
|
|
8
|
+
const metadata = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
9
|
+
if (metadata.name === "@kylecheng3146/agent-ops" &&
|
|
10
|
+
typeof metadata.version === "string") {
|
|
11
|
+
return metadata.version;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
// Keep walking until the package root is found.
|
|
16
|
+
}
|
|
17
|
+
const parent = dirname(directory);
|
|
18
|
+
if (parent === directory) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
directory = parent;
|
|
22
|
+
}
|
|
23
|
+
throw new Error("Unable to locate the package version.");
|
|
24
|
+
}
|
|
25
|
+
// package.json is the single source of the published CLI version.
|
|
26
|
+
export const CLI_VERSION = readPackageVersion();
|