Files
zpan/scripts/app-version.mjs
T
Jasper Van af43701daf fix(version): set app version global in node entry (#418)
* fix(version): resolve app version at runtime in node entry

E2E runs the Node server via tsx, which bypasses the tsup build-time
define, leaving __ZPAN_APP_VERSION__ unset so getAppVersion throws and
/api/licensing/pair returns 500. Resolve the version at runtime via
resolveAppVersion (git describe) when the global is unset; in the built
output the define inlines the constant, so the branch is never reached
and git is not invoked in production. Keeps the git-describe version as
the single source of truth across all paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(version): inject app version into docker build

The Docker build excludes .git from its context (.dockerignore), so the
build-time git describe in build:node would throw and break the image
build. Let resolveAppVersion read ZPAN_APP_VERSION, set it from an
APP_VERSION build arg in the builder stage, and pass the release tag from
the release workflow. git describe stays the default everywhere else, so
the version is unified across CF Workers, tsx, and Docker.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-08 19:29:47 -04:00

18 lines
566 B
JavaScript

import { execSync } from 'node:child_process'
export function resolveAppVersion() {
// The Docker build excludes .git from its context, so git describe cannot run
// there. The release pipeline passes the tag in via ZPAN_APP_VERSION instead.
if (process.env.ZPAN_APP_VERSION) {
return process.env.ZPAN_APP_VERSION
}
return execSync('git describe --tags --always --dirty', {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
}).trim()
}
if (import.meta.url === `file://${process.argv[1]}`) {
process.stdout.write(resolveAppVersion())
}