Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit f09808f

Browse files
authored
Merge pull request #60 from MomentQYC/patch-2
fix: 无法获取package.json中版本信息
2 parents 66a349b + ccfe223 commit f09808f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/service/version.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ const PACKAGE_JSON = "package.json";
99

1010
export function initVersionManager() {
1111
try {
12-
GlobalVariable.set("version", "Unknown");
13-
if (fs.existsSync(PACKAGE_JSON)) {
14-
const data: any = JSON.parse(fs.readFileSync(PACKAGE_JSON, { encoding: "utf-8" }));
15-
if (data.version) {
16-
GlobalVariable.set("version", data.version);
12+
const packagePaths = [PACKAGE_JSON, "../package.json"];
13+
let version = "Unknown";
14+
15+
for (const packagePath of packagePaths) {
16+
if (fs.existsSync(packagePath)) {
17+
const data = JSON.parse(fs.readFileSync(packagePath, { encoding: "utf-8" }));
18+
if (data.version) {
19+
version = data.version;
20+
break;
21+
}
1722
}
1823
}
24+
25+
GlobalVariable.set("version", version);
1926
} catch (error) {
2027
logger.error($t("version.versionDetectErr"), error);
2128
}

0 commit comments

Comments
 (0)