fix: stamp build commit metadata
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user