fix: stamp build commit metadata

This commit is contained in:
Peter Steinberger
2026-01-17 12:30:11 +00:00
parent 25d8043b9d
commit 49c35c752c
4 changed files with 73 additions and 3 deletions

View File

@@ -51,6 +51,18 @@ const readCommitFromPackageJson = () => {
}
};
const readCommitFromBuildInfo = () => {
try {
const require = createRequire(import.meta.url);
const info = require("../build-info.json") as {
commit?: string | null;
};
return formatCommit(info.commit ?? null);
} catch {
return null;
}
};
export const resolveCommitHash = (options: { cwd?: string; env?: NodeJS.ProcessEnv } = {}) => {
if (cachedCommit !== undefined) return cachedCommit;
const env = options.env ?? process.env;
@@ -60,6 +72,11 @@ export const resolveCommitHash = (options: { cwd?: string; env?: NodeJS.ProcessE
cachedCommit = normalized;
return cachedCommit;
}
const buildInfoCommit = readCommitFromBuildInfo();
if (buildInfoCommit) {
cachedCommit = buildInfoCommit;
return cachedCommit;
}
const pkgCommit = readCommitFromPackageJson();
if (pkgCommit) {
cachedCommit = pkgCommit;