heyio 0.1.2 → 0.1.4
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.
- package/dist/update.js +12 -8
- package/package.json +1 -1
package/dist/update.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
|
-
import {
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { dirname, join } from "path";
|
|
4
5
|
const PACKAGE_NAME = "heyio";
|
|
5
6
|
function getInstalledVersion() {
|
|
6
7
|
try {
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// Ask npm what version is installed globally — completely reliable
|
|
9
|
+
const output = execSync(`npm list -g ${PACKAGE_NAME} --depth=0 --json 2>/dev/null`, {
|
|
10
|
+
encoding: "utf-8",
|
|
11
|
+
timeout: 10_000,
|
|
12
|
+
});
|
|
13
|
+
const data = JSON.parse(output);
|
|
14
|
+
return data.dependencies?.[PACKAGE_NAME]?.version ?? "0.0.0";
|
|
11
15
|
}
|
|
12
16
|
catch {
|
|
13
|
-
// Fallback: read
|
|
17
|
+
// Fallback: read package.json relative to this file
|
|
14
18
|
try {
|
|
15
|
-
const
|
|
16
|
-
const pkgPath =
|
|
19
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const pkgPath = join(__dirname, "..", "package.json");
|
|
17
21
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
18
22
|
return pkg.version ?? "0.0.0";
|
|
19
23
|
}
|