Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Bun's cache is selected only while no project links into it
Țugui Dragoș57f2596a50b6
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swiftindex 73d60644..a698ac96 100644--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift@@ -67,10 +67,21 @@ public enum DeveloperCaches {struct Folder {let path: Stringlet kind: DeveloperEnvironment.ContentKind+ /// A store the tool can turn on inside the folder, which projects then link into. While an entry by that+ /// name is there, a link included, the folder is listed without a checkmark: moving it breaks them.+ let storeInside: String?- init(_ path: String, _ kind: DeveloperEnvironment.ContentKind) {+ init(_ path: String, _ kind: DeveloperEnvironment.ContentKind, storeInside: String? = nil) {self.path = pathself.kind = kind+ self.storeInside = storeInside+ }++ /// What the folder at `url` holds now: installed packages once its store is there, `kind` otherwise.+ func kind(at url: URL) -> DeveloperEnvironment.ContentKind {+ guard let storeInside else { return kind }+ let store = url.appending(path: storeInside).path(percentEncoded: false)+ return (try? FileManager.default.attributesOfItem(atPath: store)) != nil ? .environments : kind}}@@ -136,7 +147,9 @@ public enum DeveloperCaches {Folder("Library/Caches/pnpm", .cache),]),Definition(id: "bun", name: "Bun", systemImage: "cube", appBundleIdentifiers: [], folders: [- Folder(".bun/install/cache", .downloads),+ // Bun's global virtual store, once turned on, is `links`, and every project's `node_modules` then points+ // into it (Bun's documentation, "Global virtual store").+ Folder(".bun/install/cache", .downloads, storeInside: "links"),]),Definition(id: "deno", name: "Deno", systemImage: "chevron.left.forwardslash.chevron.right", appBundleIdentifiers: [], folders: [Folder("Library/Caches/deno", .downloads),@@ -476,7 +489,7 @@ public enum DeveloperCaches {let contents = await measure(url)locations.append(DeveloperEnvironment.Location(url: url,- kind: folder.kind,+ kind: folder.kind(at: url),size: contents.flatMap { $0.couldNotBeRead ? nil : $0.size },couldNotBeRead: contents?.couldNotBeRead == true))diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swiftindex 7caef622..0f4a5297 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift@@ -284,6 +284,28 @@ struct DeveloperCachesTests {#expect(suggested == ["pnpm"], "a store installed packages link into was suggested")}+ /// Bun's cache is a plain download cache until its global store is turned on: then `links` inside it is what+ /// every project's `node_modules` points into, and the whole folder is listed without a checkmark. A store+ /// moved to another disk leaves `links` as a link, which projects still reach through the cache.+ @Test func bunsCacheIsSelectedOnlyWhileNoProjectLinksIntoIt() async throws {+ for (hasStore, storeIsALink) in [(false, false), (true, false), (true, true)] {+ let directory = try TemporaryDirectory()+ try directory.file(".bun/install/cache/[email protected]@@@1/package.json", bytes: 400_000)+ if storeIsALink {+ let elsewhere = try directory.directory("Volumes/Fast/bun-links")+ try FileManager.default.createSymbolicLink(at: directory.url.appending(path: ".bun/install/cache/links"), withDestinationURL: elsewhere)+ } else if hasStore {+ try directory.file(".bun/install/cache/links/[email protected]/node_modules/react/index.js", bytes: 4_096)+ }++ let bun = try #require(await DeveloperCaches.scan(homeDirectory: directory.url).first { $0.id == "bun" })++ #expect(bun.locations.count == 1)+ #expect(bun.locations.first?.isRecommended == !hasStore, "links inside: \(hasStore)")+ #expect(bun.locations.first?.kind == (hasStore ? .environments : .downloads))+ }+ }+@Test func aScanOnlyEverReturnsFoldersInsideTheHomeItIsGiven() async throws {let directory = try TemporaryDirectory()let outside = try TemporaryDirectory()