Skip to content

Commit a2b6bc5

Browse files
committed
Fix auto-update by removing stale npm lock file
The auto-update feature was failing to install new versions because npm's .package-lock.json file in the cache directory was pinning the old version. This fix removes the lock file before running npm install to force fresh package resolution.
1 parent 066f510 commit a2b6bc5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/version-checker.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,23 @@ export function isOutdated(local: string, remote: string): boolean {
5555
export async function performUpdate(targetVersion: string, logger?: { info: (component: string, message: string, data?: any) => void }): Promise<boolean> {
5656
// OpenCode installs packages to ~/.cache/opencode/node_modules/
5757
const cacheDir = join(homedir(), '.cache', 'opencode')
58+
const packageDir = join(cacheDir, 'node_modules', '@tarquinen', 'opencode-dcp')
5859
const packageSpec = `${PACKAGE_NAME}@${targetVersion}`
5960

6061
logger?.info("version", "Starting auto-update", { targetVersion, cacheDir })
6162

63+
try {
64+
const { rmSync, existsSync } = await import('fs')
65+
const lockFile = join(cacheDir, 'node_modules', '.package-lock.json')
66+
if (existsSync(lockFile)) {
67+
// Remove the lock file to force npm to re-resolve the package
68+
rmSync(lockFile, { force: true })
69+
logger?.info("version", "Removed package-lock.json to force fresh resolution")
70+
}
71+
} catch (err) {
72+
logger?.info("version", "Could not remove lock file", { error: (err as Error).message })
73+
}
74+
6275
return new Promise((resolve) => {
6376
let resolved = false
6477

0 commit comments

Comments
 (0)