Skip to content

Commit 5387ffc

Browse files
arbrandesclaude
andcommitted
fix: simplify package.json resolution in CLI getVersion()
The compiled CLI always lives at dist/tools/cli/openedx.js, now, so the package root is always exactly three levels up. The previous candidate-list approach included a two-level path that could never match once we adopted this layout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 954ec1f commit 5387ffc

1 file changed

Lines changed: 20 additions & 25 deletions

File tree

tools/cli/openedx.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,30 @@ const commandName = process.argv[2];
1616
process.argv.splice(1, 1);
1717

1818
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-
}
19+
// Read the version from package.json. The compiled CLI lives at
20+
// dist/tools/cli/openedx.js, so the package root is always three levels up.
21+
const pkgJsonPath = path.resolve(__dirname, '../../../package.json');
22+
if (!existsSync(pkgJsonPath)) {
23+
return '(unknown)';
24+
}
3125

32-
if (!/^0\.0\.0-.+$/.test(pkgVersion)) {
33-
return pkgVersion;
34-
}
26+
const { version: pkgVersion } = require(pkgJsonPath);
27+
if (!pkgVersion) {
28+
return '(unknown)';
29+
}
3530

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-
}
31+
if (!/^0\.0\.0-.+$/.test(pkgVersion)) {
32+
return pkgVersion;
4533
}
4634

47-
return '(unknown)';
35+
// Placeholder version found — likely a local git checkout. Append the
36+
// git hash so the exact checkout is identifiable.
37+
try {
38+
const hash = execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).trim();
39+
return `${pkgVersion} (${hash})`;
40+
} catch {
41+
return pkgVersion;
42+
}
4843
}
4944

5045
const version = getVersion();

0 commit comments

Comments
 (0)