Skip to content

Commit 954ec1f

Browse files
arbrandesclaude
andcommitted
fix: show git hash when CLI version is a placeholder
When the package.json version is the semantic-release placeholder (0.0.0-dev), the CLI now appends the short git hash in parentheses so the exact checkout is identifiable. For published packages, the real version set by semantic-release is shown as before. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 43f04f0 commit 954ec1f

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

tools/cli/openedx.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22
import chalk from 'chalk';
33

4+
import { execSync } from 'child_process';
45
import { existsSync } from 'fs';
56
import path from 'path';
67
import { CommandTypes, ConfigTypes } from '../types';
@@ -14,14 +15,40 @@ const commandName = process.argv[2];
1415
// remove 'openedx' from process.argv to allow subcommands to read options properly
1516
process.argv.splice(1, 1);
1617

17-
let version;
18+
function getVersion(): string {
19+
// Try to read the version from package.json (works for published packages
20+
// where semantic-release has set the real version).
21+
const candidates = [
22+
path.resolve(__dirname, '../../package.json'),
23+
path.resolve(__dirname, '../../../package.json'),
24+
];
25+
for (const candidate of candidates) {
26+
if (existsSync(candidate)) {
27+
const { version: pkgVersion } = require(candidate);
28+
if (!pkgVersion) {
29+
break;
30+
}
31+
32+
if (!/^0\.0\.0-.+$/.test(pkgVersion)) {
33+
return pkgVersion;
34+
}
35+
36+
// Placeholder version found — likely a local git checkout. Append the
37+
// git hash so the exact checkout is identifiable.
38+
try {
39+
const hash = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();
40+
return `${pkgVersion} (${hash})`;
41+
} catch {
42+
return pkgVersion;
43+
}
44+
}
45+
}
1846

19-
if (existsSync(path.resolve(__dirname, '../../package.json'))) {
20-
version = require('../../package.json').version;
21-
} else if (existsSync(path.resolve(__dirname, '../../../package.json'))) {
22-
version = require('../../../package.json').version;
47+
return '(unknown)';
2348
}
2449

50+
const version = getVersion();
51+
2552
prettyPrintTitle(`Open edX CLI v${version}`);
2653

2754
switch (commandName) {

0 commit comments

Comments
 (0)