add vm uncache command to clear the package cache

This commit is contained in:
Chris Wanstrath 2026-02-21 08:53:06 -08:00
parent 417bb666b2
commit cfe8eab054
2 changed files with 15 additions and 0 deletions

View File

@ -71,4 +71,12 @@ export function register(program: Command) {
await vm.destroy()
console.log("✔ VM destroyed")
})
vmCmd
.command("uncache")
.description("Clear the package cache (next create will re-download)")
.action(async () => {
const had = await vm.clearCache()
console.log(had ? "✔ Package cache cleared" : "No cache to clear")
})
}

View File

@ -337,3 +337,10 @@ export async function destroy(): Promise<void> {
await stop()
await $`container delete ${CONTAINER_NAME}`.nothrow().quiet()
}
/** Clear the package cache so the next create re-downloads everything. */
export async function clearCache(): Promise<boolean> {
const exists = await Bun.file(join(CACHE_DIR, 'bun')).exists()
await $`rm -rf ${CACHE_DIR}`.nothrow().quiet()
return exists
}