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.

Work in hidden files counts as a change to the project

Țugui Dragoș8d6865d78590
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
index 7d28eea2..4d67c85e 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ProjectArtifacts.swift
@@ -570,6 +570,10 @@ public enum ProjectArtifacts {
/// Files Git updates whenever the repository changes: three reads can answer for a whole repository.
private static let gitMarks = [".git/index", ".git/HEAD", ".git/logs/HEAD"]
+ /// What the read of a project's last change passes by besides its artifacts: Git's own store, which its marks
+ /// answer for, and installed packages, which change when they are installed rather than when anyone works.
+ private static let passedByForActivity: Set<String> = [".git", "node_modules"]
+
/// Stops at the first change within `recentlyActive`, which alone answers the question.
static func lastActivity(in project: URL, ignoring artifacts: Set<String>) -> (date: Date?, isCertain: Bool) {
let cutoff = Date.now.addingTimeInterval(-recentlyActive)
@@ -593,7 +597,7 @@ public enum ProjectArtifacts {
for case let url as URL in enumerator {
let name = url.lastPathComponent
let relative = String(key(of: url).dropFirst(base.count + 1))
- if artifacts.contains(name) || artifacts.contains(relative) || isSkipped(name) {
+ if artifacts.contains(name) || artifacts.contains(relative) || passedByForActivity.contains(name) {
enumerator.skipDescendants()
continue
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
index 6bcd920c..61c03093 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ProjectArtifactsTests.swift
@@ -572,6 +572,37 @@ struct ProjectArtifactsTests {
#expect(!artifact.isRecommended)
}
+ /// Work in a hidden file, in `.github`, or in a folder of the person's own that a tool's table also names is
+ /// work: only the artifacts found and what installed packages bring along are passed by.
+ @Test func countsWorkInHiddenFilesAndFoldersNamedLikeArtifacts() async throws {
+ let directory = try TemporaryDirectory()
+ for project in ["dotenv", "workflow", "notes", "packages"] {
+ try directory.file("\(project)/package.json", bytes: 16)
+ try directory.file("\(project)/node_modules/dep/index.js", bytes: 400_000)
+ }
+ try directory.file("dotenv/.env", bytes: 16)
+ try directory.file("workflow/.github/workflows/ci.yml", bytes: 16)
+ try directory.file("notes/Carthage/notes.md", bytes: 16)
+ try directory.file("packages/tools/node_modules/other/index.js", bytes: 16)
+ try age(directory.url, days: 60)
+ for recent in ["dotenv/.env", "workflow/.github/workflows/ci.yml", "notes/Carthage/notes.md",
+ "packages/tools/node_modules/other/index.js"] {
+ let path = directory.url.appending(path: recent).path(percentEncoded: false)
+ try FileManager.default.setAttributes([.modificationDate: Date.now], ofItemAtPath: path)
+ }
+
+ let found = await ProjectArtifacts.scan(roots: [directory.url]).artifacts
+ func isActive(_ project: String) throws -> Bool {
+ try #require(found.first { $0.project.lastPathComponent == project && $0.name == "node_modules" })
+ .isRecentlyActive
+ }
+
+ #expect(try isActive("dotenv"))
+ #expect(try isActive("workflow"))
+ #expect(try isActive("notes"))
+ #expect(try !isActive("packages"), "a package install is not work on the project")
+ }
+
/// Every git command that changes something writes under `.git`, so three files there tell when the whole
/// repository was last used, without reading a sample of its files.
@Test func readsWhenTheRepositoryWasLastUsed() throws {