fix(auto-update-checker): add bun.lock handling to invalidatePackage()
- Removes package from node_modules, package.json dependencies, AND bun.lock (workspaces.dependencies + packages) - Fixes issue where 'update available' notification appeared but actual update didn't happen on restart due to bun.lock pinning old version - Added BunLockfile interface and stripTrailingCommas helper for JSON parsing 🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -3,6 +3,49 @@ import * as path from "node:path"
|
|||||||
import { CACHE_DIR, PACKAGE_NAME } from "./constants"
|
import { CACHE_DIR, PACKAGE_NAME } from "./constants"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
|
|
||||||
|
interface BunLockfile {
|
||||||
|
workspaces?: {
|
||||||
|
""?: {
|
||||||
|
dependencies?: Record<string, string>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packages?: Record<string, unknown>
|
||||||
|
}
|
||||||
|
|
||||||
|
function stripTrailingCommas(json: string): string {
|
||||||
|
return json.replace(/,(\s*[}\]])/g, "$1")
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFromBunLock(packageName: string): boolean {
|
||||||
|
const lockPath = path.join(CACHE_DIR, "bun.lock")
|
||||||
|
if (!fs.existsSync(lockPath)) return false
|
||||||
|
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync(lockPath, "utf-8")
|
||||||
|
const lock = JSON.parse(stripTrailingCommas(content)) as BunLockfile
|
||||||
|
let modified = false
|
||||||
|
|
||||||
|
if (lock.workspaces?.[""]?.dependencies?.[packageName]) {
|
||||||
|
delete lock.workspaces[""].dependencies[packageName]
|
||||||
|
modified = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lock.packages?.[packageName]) {
|
||||||
|
delete lock.packages[packageName]
|
||||||
|
modified = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
fs.writeFileSync(lockPath, JSON.stringify(lock, null, 2))
|
||||||
|
log(`[auto-update-checker] Removed from bun.lock: ${packageName}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return modified
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function invalidatePackage(packageName: string = PACKAGE_NAME): boolean {
|
export function invalidatePackage(packageName: string = PACKAGE_NAME): boolean {
|
||||||
try {
|
try {
|
||||||
const pkgDir = path.join(CACHE_DIR, "node_modules", packageName)
|
const pkgDir = path.join(CACHE_DIR, "node_modules", packageName)
|
||||||
@@ -10,6 +53,7 @@ export function invalidatePackage(packageName: string = PACKAGE_NAME): boolean {
|
|||||||
|
|
||||||
let packageRemoved = false
|
let packageRemoved = false
|
||||||
let dependencyRemoved = false
|
let dependencyRemoved = false
|
||||||
|
let lockRemoved = false
|
||||||
|
|
||||||
if (fs.existsSync(pkgDir)) {
|
if (fs.existsSync(pkgDir)) {
|
||||||
fs.rmSync(pkgDir, { recursive: true, force: true })
|
fs.rmSync(pkgDir, { recursive: true, force: true })
|
||||||
@@ -28,7 +72,9 @@ export function invalidatePackage(packageName: string = PACKAGE_NAME): boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!packageRemoved && !dependencyRemoved) {
|
lockRemoved = removeFromBunLock(packageName)
|
||||||
|
|
||||||
|
if (!packageRemoved && !dependencyRemoved && !lockRemoved) {
|
||||||
log(`[auto-update-checker] Package not found, nothing to invalidate: ${packageName}`)
|
log(`[auto-update-checker] Package not found, nothing to invalidate: ${packageName}`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user