Skip to content

Commit 9759988

Browse files
authored
Merge pull request #97 from Tarquinen/fix/version-checker-path-resolution
Fix version detection to work from any execution path
2 parents ac2f4cb + a10407a commit 9759988

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
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
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
33
"name": "@tarquinen/opencode-dcp",
4-
"version": "0.4.7",
4+
"version": "0.4.8",
55
"type": "module",
66
"description": "OpenCode plugin that optimizes token usage by pruning obsolete tool outputs from conversation context",
77
"main": "./dist/index.js",

0 commit comments

Comments
 (0)