Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-hoops-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@oxa/core": patch
---

Export version statically rather than dynamically
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "oxa-dev/oxa" }],
"commit": false,
"fixed": [],
"fixed": [["@oxa/core", "oxa"]],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking these @nokome.

I assume the types are linked in different ways.

"linked": [],
"access": "public",
"baseBranch": "main",
Expand Down
1 change: 1 addition & 0 deletions packages/oxa-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/version.ts
3 changes: 2 additions & 1 deletion packages/oxa-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"dist"
],
"scripts": {
"build": "tsc && cp ../../schema/schema.json dist/ && pnpm run build:bundle",
"copy:version": "echo \"const version = '\"$npm_package_version\"';\nexport default version;\" > src/version.ts",
"build": "pnpm run copy:version && tsc && cp ../../schema/schema.json dist/ && pnpm run build:bundle",
Comment on lines +19 to +20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Export a version.ts, which is git-ignored. Then import that in code rather than looking to the package.json which failed when I was using it as a stand-alone bin.

"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",
"test": "vitest run",
"typecheck": "tsc --noEmit",
Expand Down
20 changes: 2 additions & 18 deletions packages/oxa-core/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/

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

/**
* Get package version from package.json.
*/
function getVersion(): string {
try {
const __dirname = dirname(fileURLToPath(import.meta.url));
const pkgPath = join(__dirname, "..", "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
return pkg.version;
} catch {
return "0.0.0";
}
}

program
.name("oxa")
.description("CLI for validating OXA documents")
.version(getVersion());
.version(version);

program
.command("validate")
Expand Down