Fix Cross platform building of Draupnir

This commit is contained in:
Catalan Lover
2026-09-18 20:51:04 +02:00
parent 4e949ddd57
commit ff133b665d
5 changed files with 54 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"draupnir": patch
---
Make unit tests and lint commands work cross platform
+6
View File
@@ -0,0 +1,6 @@
---
"draupnir": minor
---
Migrate Describe Version / Branch to dedicated scripts for true cross platform
development compatibility.
+3 -3
View File
@@ -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",
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2026 Catalan Lover <catalanlover@protonmail.com>
//
// 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);
+1 -1
View File
@@ -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",