Skip to content

Commit ec39fa7

Browse files
committed
Fix version detection to work from any execution path
The getLocalVersion() function now walks up the directory tree to find the correct package.json instead of assuming a fixed relative path. This fixes version detection when running from dist/lib/, lib/, or when installed in node_modules.
1 parent ac2f4cb commit ec39fa7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/version-checker.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ const __dirname = dirname(__filename)
1212

1313
export function getLocalVersion(): string {
1414
try {
15-
const pkgPath = join(__dirname, '../../package.json')
16-
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
17-
return pkg.version
15+
// Walk up from the current module to find the project's package.json
16+
// This works whether running from dist/lib/, lib/, or installed in node_modules
17+
let dir = __dirname
18+
for (let i = 0; i < 5; i++) {
19+
const pkgPath = join(dir, 'package.json')
20+
try {
21+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
22+
if (pkg.name === '@tarquinen/opencode-dcp') {
23+
return pkg.version
24+
}
25+
} catch {
26+
// Not found at this level, go up
27+
}
28+
dir = join(dir, '..')
29+
}
30+
return '0.0.0'
1831
} catch {
1932
return '0.0.0'
2033
}

0 commit comments

Comments
 (0)