diff --git a/package.json b/package.json index a5ba9db5e..c8a745a21 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "build:cli": "tsc -p tsconfig.src.json", "typecheck:cli": "tsc -p tsconfig.cli.json", "prepare": "if command -v tsc >/dev/null 2>&1 || [ -x node_modules/.bin/tsc ]; then npm run build:cli; fi && npm install --omit=dev --ignore-scripts 2>/dev/null || true && if [ -d .git ]; then if command -v prek >/dev/null 2>&1; then prek install; elif [ -d node_modules/@j178/prek ]; then echo \"ERROR: prek package found but binary not in PATH\" && exit 1; else echo \"Skipping git hook setup (prek not installed)\"; fi; fi", - "prepublishOnly": "cd nemoclaw && env -u npm_config_global -u npm_config_prefix -u npm_config_omit npm install --ignore-scripts && ./node_modules/.bin/tsc" + "prepublishOnly": "git describe --tags --match 'v*' | sed 's/^v//' > .version && test -s .version && cd nemoclaw && env -u npm_config_global -u npm_config_prefix -u npm_config_omit npm install --ignore-scripts && ./node_modules/.bin/tsc" }, "dependencies": { "p-retry": "^4.6.2", @@ -26,6 +26,7 @@ "p-retry" ], "files": [ + ".version", "bin/", "nemoclaw/dist/", "nemoclaw/openclaw.plugin.json", diff --git a/src/lib/version.test.ts b/src/lib/version.test.ts index 66bfbd577..6da6952a7 100644 --- a/src/lib/version.test.ts +++ b/src/lib/version.test.ts @@ -30,6 +30,18 @@ describe("lib/version", () => { rmSync(join(testDir, ".version")); }); + it("regression #1239: returns .version even when package.json is stale", () => { + // npm-published tarballs ship with a stale package.json version (0.1.0) + // and a .version file stamped from the git tag at publish time. The + // installed CLI must report the .version contents, not the package.json + // semver. See issue #1239. + writeFileSync(join(testDir, "package.json"), JSON.stringify({ version: "0.1.0" })); + writeFileSync(join(testDir, ".version"), "0.0.2"); + expect(getVersion({ rootDir: testDir })).toBe("0.0.2"); + rmSync(join(testDir, ".version")); + writeFileSync(join(testDir, "package.json"), JSON.stringify({ version: "1.2.3" })); + }); + it("returns a string", () => { expect(typeof getVersion({ rootDir: testDir })).toBe("string"); });