diff --git a/.changeset/dry-socks-flow.md b/.changeset/dry-socks-flow.md new file mode 100644 index 00000000..2621ca7f --- /dev/null +++ b/.changeset/dry-socks-flow.md @@ -0,0 +1,5 @@ +--- +"draupnir": patch +--- + +Make unit tests and lint commands work cross platform diff --git a/.changeset/few-apples-tickle.md b/.changeset/few-apples-tickle.md new file mode 100644 index 00000000..a2090b18 --- /dev/null +++ b/.changeset/few-apples-tickle.md @@ -0,0 +1,6 @@ +--- +"draupnir": minor +--- + +Migrate Describe Version / Branch to dedicated scripts for true cross platform +development compatibility. diff --git a/apps/draupnir/package.json b/apps/draupnir/package.json index ce4a9b98..93db789f 100644 --- a/apps/draupnir/package.json +++ b/apps/draupnir/package.json @@ -10,10 +10,10 @@ "scripts": { "build": "tsc --project test/tsconfig.json && npm run build:assets", "build:assets": "npm run describe-version && npm run describe-branch", - "describe-version": "(git describe > version.txt.tmp && mv version.txt.tmp version.txt) || true && rm -f version.txt.tmp", - "describe-branch": "(git rev-parse --abbrev-ref HEAD > branch.txt.tmp && mv branch.txt.tmp branch.txt) || true && rm -f branch.txt.tmp", + "describe-version": "node scripts/write-build-info.cjs version", + "describe-branch": "node scripts/write-build-info.cjs branch", "harness-registration": "node dist/appservice/cli.js -r -u \"http://host.docker.internal:9000\" --enable-source-maps", - "test:unit": "mocha --require './test/tsnode.cjs' --forbid-only 'test/unit/**/*.{ts,tsx}'", + "test:unit": "mocha --require \"./test/tsnode.cjs\" --forbid-only \"test/unit/**/*.{ts,tsx}\"", "test:unit:single": "mocha --require test/tsnode.cjs", "test:integration": "NODE_ENV=harness mocha --require test/tsnode.cjs --async-stack-traces --forbid-only --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/**/*Test.ts\" -- --draupnir-config ../../config/harness.yaml", "test:integration:single": "NODE_ENV=harness mocha --require test/tsnode.cjs --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json -- --draupnir-config ../../config/harness.yaml", diff --git a/apps/draupnir/scripts/write-build-info.cjs b/apps/draupnir/scripts/write-build-info.cjs new file mode 100644 index 00000000..a9f37184 --- /dev/null +++ b/apps/draupnir/scripts/write-build-info.cjs @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2026 Catalan Lover +// +// SPDX-License-Identifier: 0BSD + +// Cross-platform replacement for the old mv/rm shell one-liners (Windows cmd.exe has neither). +const { execSync } = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); + +const targets = { + version: { + command: "git describe", + file: path.join(__dirname, "..", "version.txt"), + }, + branch: { + command: "git rev-parse --abbrev-ref HEAD", + file: path.join(__dirname, "..", "branch.txt"), + }, +}; + +function writeBuildInfo(target) { + const { command, file } = targets[target]; + try { + const output = execSync(command, { encoding: "utf-8" }).trim(); + fs.writeFileSync(file, output + "\n"); + } catch { + // git may be unavailable, this may not be a repo, or there may be no tags/HEAD. + // config.ts already falls back to package.json's version / a default message. + } +} + +const target = process.argv[2]; +if (!targets[target]) { + console.error( + `Usage: node write-build-info.cjs <${Object.keys(targets).join("|")}>` + ); + process.exit(1); +} +writeBuildInfo(target); diff --git a/package.json b/package.json index 0f0c9c6b..17d39ad4 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build:all": "tsc -b tsconfig.all.json && npm run --workspaces build:assets --if-present", "build:clean": "tsc -b --clean", "test": "npm run --workspaces test --if-present && npm run -w apps/draupnir test:unit", - "lint": "eslint --cache 'packages/**/*.{ts,tsx}' 'apps/**/*.{ts,tsx}' && prettier --cache --ignore-unknown --check ." + "lint": "eslint --cache \"packages/**/*.{ts,tsx}\" \"apps/**/*.{ts,tsx}\" && prettier --cache --ignore-unknown --check ." }, "devDependencies": { "@changesets/cli": "^2.30.0",