taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 26e8db1685e4bcc641b344a9a1503cd7bdcfd9e7
parent f68162c79380570888a1f6a5046034806466759d
Author: Florian Dold <florian@dold.me>
Date:   Thu, 23 Jul 2026 15:43:49 +0200

build: more robust git rev parsing

Diffstat:
Mpackages/anastasis-cli/build-node.mjs | 13++-----------
Mpackages/merchant-backend-ui/build.mjs | 1+
Mpackages/taler-harness/build.mjs | 16++--------------
Mpackages/taler-wallet-cli/build-node.mjs | 16++--------------
Mpackages/taler-wallet-cli/build-qtart.mjs | 16++--------------
Mpackages/taler-wallet-embedded/build.mjs | 16++--------------
Mpackages/web-util/build.mjs | 15+++------------
Mpackages/web-util/src/index.build.ts | 27++++++++-------------------
8 files changed, 22 insertions(+), 98 deletions(-)

diff --git a/packages/anastasis-cli/build-node.mjs b/packages/anastasis-cli/build-node.mjs @@ -18,6 +18,7 @@ import esbuild from "esbuild"; import path from "node:path"; import fs from "node:fs"; +import { execSync } from 'node:child_process'; const BASE = process.cwd(); @@ -37,17 +38,7 @@ function get_version() { } function git_hash() { - const rev = fs - .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs.readFileSync(path.join(GIT_ROOT, ".git", rev)).toString().trim(); - } + return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } export const buildConfig = { diff --git a/packages/merchant-backend-ui/build.mjs b/packages/merchant-backend-ui/build.mjs @@ -66,6 +66,7 @@ function get_version() { function git_hash() { return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } + function toCamelCaseName(name, lang) { return name .replace(/^[A-Z]/, letter => `${letter.toLowerCase()}`) //first letter lowercase diff --git a/packages/taler-harness/build.mjs b/packages/taler-harness/build.mjs @@ -18,6 +18,7 @@ import esbuild from "esbuild"; import fs from "node:fs"; import path from "node:path"; +import { execSync } from 'node:child_process'; const BASE = process.cwd(); @@ -38,20 +39,7 @@ function get_version() { } function git_hash() { - const rev = fs - .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs - .readFileSync(path.join(GIT_ROOT, ".git", rev)) - .toString() - .trim(); - } + return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } // Still commonjs, because axios doesn't work properly under mjs diff --git a/packages/taler-wallet-cli/build-node.mjs b/packages/taler-wallet-cli/build-node.mjs @@ -18,6 +18,7 @@ import esbuild from "esbuild"; import path from "node:path"; import fs from "node:fs"; +import { execSync } from 'node:child_process'; const BASE = process.cwd(); @@ -37,20 +38,7 @@ function get_version() { } function git_hash() { - const rev = fs - .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs - .readFileSync(path.join(GIT_ROOT, ".git", rev)) - .toString() - .trim(); - } + return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } export const buildConfig = { diff --git a/packages/taler-wallet-cli/build-qtart.mjs b/packages/taler-wallet-cli/build-qtart.mjs @@ -18,6 +18,7 @@ import esbuild from "esbuild"; import path from "node:path"; import fs from "node:fs"; +import { execSync } from 'node:child_process'; const BASE = process.cwd(); @@ -34,20 +35,7 @@ const GIT_HASH = GIT_ROOT === "/" ? undefined : git_hash(); let _package = JSON.parse(fs.readFileSync(path.join(BASE, "package.json"))); function git_hash() { - const rev = fs - .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs - .readFileSync(path.join(GIT_ROOT, ".git", rev)) - .toString() - .trim(); - } + return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } export const buildConfig = { diff --git a/packages/taler-wallet-embedded/build.mjs b/packages/taler-wallet-embedded/build.mjs @@ -18,6 +18,7 @@ import esbuild from "esbuild"; import path from "node:path"; import fs from "node:fs"; +import { execSync } from 'node:child_process'; const BASE = process.cwd(); @@ -37,20 +38,7 @@ function get_version() { } function git_hash() { - const rev = fs - .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs - .readFileSync(path.join(GIT_ROOT, ".git", rev)) - .toString() - .trim(); - } + return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } export const buildConfig = { diff --git a/packages/web-util/build.mjs b/packages/web-util/build.mjs @@ -16,9 +16,10 @@ */ import esbuild from "esbuild"; -import path from "node:path"; import fs from "node:fs"; +import path from "node:path"; import nodeUrl from "node:url"; +import { execSync } from "node:child_process"; const root = path.dirname(nodeUrl.fileURLToPath(import.meta.url)); process.chdir(root); @@ -42,17 +43,7 @@ function get_version() { } function git_hash() { - const rev = fs - .readFileSync(path.join(GIT_ROOT, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs.readFileSync(path.join(GIT_ROOT, ".git", rev)).toString().trim(); - } + return execSync(`git rev-parse HEAD`, { encoding: 'utf-8' }).trim(); } /** diff --git a/packages/web-util/src/index.build.ts b/packages/web-util/src/index.build.ts @@ -1,11 +1,11 @@ import esbuild, { PluginBuild } from "esbuild"; +import { execFileSync } from "node:child_process"; import fs from "node:fs"; -import path from "node:path"; +import { default as nodePath, default as path } from "node:path"; +import nodeUrl from "node:url"; import postcss from "postcss"; -import sass from "sass"; import postcssrc from "postcss-load-config"; -import nodePath from "node:path"; -import nodeUrl from "node:url"; +import sass from "sass"; type Assets = { base: string; @@ -41,21 +41,10 @@ export function getFilesInDirectory(startPath: string, regex?: RegExp): Assets { }; } -function git_hash(root: string) { - const rev = fs - .readFileSync(path.join(root, ".git", "HEAD")) - .toString() - .trim() - .split(/.*[: ]/) - .slice(-1)[0]; - if (rev.indexOf("/") === -1) { - return rev; - } else { - return fs - .readFileSync(path.join(root, ".git", rev)) - .toString() - .trim(); - } +function git_hash(gitRoot: string): string { + return execFileSync("git", ["-C", gitRoot, "rev-parse", "HEAD"], { + encoding: "utf-8", + }).trim(); } // FIXME: Put this into some helper library.