Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Offer Nx's .nx only when it holds what nx reset removes

Țugui Dragoșff930e4c6c5c
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index 2a1d6346..3dd51ba2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -113,6 +113,8 @@ public enum ProjectArtifacts {
case holds(String)
/// Nothing but files with this ending, as Python writes only compiled `.pyc` files into `__pycache__`.
case holdsOnlyFilesEnding(String)
+ /// Nothing but entries with these names, `including` among them.
+ case holdsOnly(Set<String>, including: String)
func holds(at url: URL) -> Bool {
switch self {
@@ -120,6 +122,10 @@ public enum ProjectArtifacts {
var info = stat()
let path = url.appending(path: name).path(percentEncoded: false)
return lstat(path, &info) == 0 && info.st_mode & S_IFMT == S_IFREG
+ case .holdsOnly(let names, let including):
+ let path = url.path(percentEncoded: false)
+ let entries = Set((try? FileManager.default.contentsOfDirectory(atPath: path)) ?? [])
+ return entries.contains(including) && entries.isSubset(of: names)
case .holdsOnlyFilesEnding(let ending):
let entries = (try? FileManager.default.contentsOfDirectory(
at: url, includingPropertiesForKeys: [.isRegularFileKey]
@@ -193,6 +199,13 @@ public enum ProjectArtifacts {
name: ".turbo", markers: ["turbo.json"], tool: "Turborepo", isGeneric: false,
source: "https://turborepo.dev/docs/crafting-your-repository/caching"
),
+ // Only what `nx reset` removes, the cache and the database together: before Nx's #37111 a database row whose
+ // files were gone was a hit that restored nothing. `.nx` can also hold the release plans a team commits.
+ Definition(
+ name: ".nx", markers: ["nx.json"], tool: "Nx", isGeneric: false,
+ source: "https://github.com/nrwl/nx/blob/ead04276f840b920ffab97eb3f809fef2baf130b/packages/nx/src/command-line/reset/reset.ts#L156-L205",
+ proof: .holdsOnly(["cache", "workspace-data"], including: "workspace-data")
+ ),
Definition(
name: ".parcel-cache", markers: ["package.json"], tool: "Parcel", isGeneric: false,
source: "https://parceljs.org/features/cli/"
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index 934aa5a2..43b1cf59 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -416,6 +416,24 @@ struct ProjectArtifactsTests {
#expect(found.first?.isRecommended == true)
}
+ @Test func offersNxsFolderOnlyWhenItHoldsWhatNxResetRemoves() async throws {
+ let directory = try TemporaryDirectory()
+ for project in ["reset", "plans", "cacheOnly"] {
+ try directory.file("\(project)/nx.json", bytes: 16)
+ try directory.file("\(project)/.nx/cache/0123/outputs/main.js", bytes: 400_000)
+ }
+ try directory.file("reset/.nx/workspace-data/nx.db", bytes: 400_000)
+ try directory.file("plans/.nx/workspace-data/nx.db", bytes: 400_000)
+ try directory.file("plans/.nx/version-plans/release.md", bytes: 16)
+ try age(directory.url, days: 60)
+
+ let found = await ProjectArtifacts.scan(roots: [directory.url]).artifacts
+
+ #expect(found.map { "\($0.project.lastPathComponent)/\($0.name)" } == ["reset/.nx"])
+ #expect(found.first?.tool == "Nx")
+ #expect(found.first?.isRecommended == true)
+ }
+
@Test func findsAVirtualEnvironmentUnderAGenericNameOnlyByItsOwnFile() async throws {
let directory = try TemporaryDirectory()
try directory.file("app/pyproject.toml", bytes: 16)
@@ -726,6 +744,7 @@ struct ProjectArtifactsTests {
switch definition.proof {
case .holds(let file): try directory.file("\(artifact)/\(file)")
case .holdsOnlyFilesEnding(let ending): try directory.file("\(artifact)/module\(ending)")
+ case .holdsOnly(_, let including): try directory.file("\(artifact)/\(including)/content")
case nil: try directory.file("\(artifact)/content")
}
expected[artifact] = definition.tool
diff --git a/SAFETY.md b/SAFETY.md
index efad43af..08fc726c 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -334,7 +334,9 @@ Python environment (`.venv`, `venv`) is listed and never selected, since package
and so is Terraform's `.terraform`, which keeps the workspace you chose. A folder whose name says nothing on its own,
such as `target` or `build`, is listed and never selected either. Of a Godot project's `.godot`, only the caches Godot
makes again are offered, `imported` and `shader_cache`: the folder also holds the export passwords and keys
-(`export_credentials.cfg`), which exist nowhere else. Build Artifacts never searches a hidden folder, a Library, or a
+(`export_credentials.cfg`), which exist nowhere else. Nx's `.nx` is offered only when it holds nothing but the cache
+and the database beside it, which `nx reset` removes together, since a team can keep its release plans there. Build
+Artifacts never searches a hidden folder, a Library, or a
folder a tool fills, such as `node_modules`: apps and tools keep there what they install, as an editor keeps each
extension's `package.json` beside the `node_modules` it runs with. A folder chosen to search that is one of those, or
sits inside one, is refused with the reason.