Skip to content

Commit 7f4407c

Browse files
authored
🐛 Version no longer prints 0.0.0 (#37)
1 parent c58e948 commit 7f4407c

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

.changeset/clean-hoops-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@oxa/core": patch
3+
---
4+
5+
Export version statically rather than dynamically

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
33
"changelog": ["@changesets/changelog-github", { "repo": "oxa-dev/oxa" }],
44
"commit": false,
5-
"fixed": [],
5+
"fixed": [["@oxa/core", "oxa"]],
66
"linked": [],
77
"access": "public",
88
"baseBranch": "main",

packages/oxa-core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/version.ts

packages/oxa-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"dist"
1717
],
1818
"scripts": {
19-
"build": "tsc && cp ../../schema/schema.json dist/ && pnpm run build:bundle",
19+
"copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts",
20+
"build": "pnpm run copy:version && tsc && cp ../../schema/schema.json dist/ && pnpm run build:bundle",
2021
"build:bundle": "esbuild src/cli.ts --bundle --platform=node --target=node22 --format=cjs --outfile=dist/cli.bundle.cjs --banner:js='#!/usr/bin/env node' --log-override:empty-import-meta=silent",
2122
"test": "vitest run",
2223
"typecheck": "tsc --noEmit",

packages/oxa-core/src/cli.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
*/
66

77
import { program } from "commander";
8-
import { readFileSync } from "fs";
9-
import { fileURLToPath } from "url";
10-
import { dirname, join } from "path";
8+
import version from "./version.js";
119
import {
1210
validateFile,
1311
validateJson,
@@ -82,24 +80,10 @@ async function readStdin(): Promise<string> {
8280
return Buffer.concat(chunks).toString("utf-8");
8381
}
8482

85-
/**
86-
* Get package version from package.json.
87-
*/
88-
function getVersion(): string {
89-
try {
90-
const __dirname = dirname(fileURLToPath(import.meta.url));
91-
const pkgPath = join(__dirname, "..", "package.json");
92-
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
93-
return pkg.version;
94-
} catch {
95-
return "0.0.0";
96-
}
97-
}
98-
9983
program
10084
.name("oxa")
10185
.description("CLI for validating OXA documents")
102-
.version(getVersion());
86+
.version(version);
10387

10488
program
10589
.command("validate")

0 commit comments

Comments
 (0)