Skip to content

Commit 199d466

Browse files
committed
fix(engine): derive ENGINE_VERSION instead of hand-syncing it
Same root cause as the package-lock.json/dependency-range fixes already pushed to this branch: ENGINE_VERSION was a hardcoded literal that test/unit/engine-version.test.ts correctly caught as stale against this release's package.json bump. See fix/release-please-lockfile-sync (#4179) for the full story and verification.
1 parent 826b46d commit 199d466

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
/**
2-
* Published semver of `@jsonbored/gittensory-engine`. Keep in lockstep with `package.json` `version`
3-
* (enforced by `test/unit/engine-version.test.ts`).
4-
*/
5-
export const ENGINE_VERSION = "0.1.0";
1+
import { readFileSync } from "node:fs";
2+
import { fileURLToPath, URL } from "node:url";
3+
4+
// Read at runtime instead of a hand-synced literal -- works identically from src/version.ts
5+
// (source, under vitest) and dist/version.js (compiled output): package.json is always the
6+
// direct parent of both directories, and this is a plain file read, not a compile-time import,
7+
// so it isn't subject to tsconfig's rootDir: "src" restriction. URL imported explicitly from
8+
// node:url (not the ambient global) -- they've subtly diverged in this @types/node version
9+
// (Symbol.dispose on URLSearchParamsIterator), which fileURLToPath's overloads reject otherwise.
10+
const ownPackageJsonPath = fileURLToPath(new URL("../package.json", import.meta.url));
11+
const ownPackageJson = JSON.parse(readFileSync(ownPackageJsonPath, "utf8")) as { version: string };
12+
13+
/** Published semver of `@jsonbored/gittensory-engine`, derived from this package's own package.json. */
14+
export const ENGINE_VERSION: string = ownPackageJson.version;

test/unit/gittensory-engine-scaffold.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import enginePkg from "../../packages/gittensory-engine/package.json";
77
describe("gittensory-engine package scaffold", () => {
88
it("declares the published package identity", () => {
99
expect(enginePkg.name).toBe("@jsonbored/gittensory-engine");
10-
expect(enginePkg.version).toBe("0.1.0");
10+
expect(enginePkg.version).toMatch(/^\d+\.\d+\.\d+$/);
1111
expect(enginePkg.type).toBe("module");
1212
expect(enginePkg.license).toBe("AGPL-3.0-only");
1313
expect(enginePkg.publishConfig?.access).toBe("public");

0 commit comments

Comments
 (0)