refactor: extract duplicated exec, traversal and item-building logic into shared utilities - #83
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
refactor: extract duplicated exec, traversal and item-building logic into shared utilities#83devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Removes ~580 lines of duplicated logic by extracting shared utilities and rewiring every caller. No behavior or output changes.
New utilities:
utils/exec.ts—execCommand(command, args, timeout)(spawn-based, no shell) +findExecutable(candidates); replaces 5 near-identical copies (docker,homebrew,dns-cache,purgeable,timemachine) and 3 copies of the absolute-path binary probe. Absolute candidate paths and arg arrays are preserved, so the$PATH/injection hardening is unchanged; per-call timeouts keep their original values (10s DNS, 60s purge, 30s default).utils/concurrency.ts—mapPool(items, concurrency, fn); replaces the private pool ingit-worktreesand thePromise.race-basedrunWithConcurrencyinscanners/index.ts, which now just wraps it to keep swallowing+logging per-scanner failures.utils/walk.ts—walkFiles(root, { maxDepth, includeHidden }, onFile); replaces the recursive depth-limited traversals inlarge-filesandduplicates(hidden-entry skipping and permission-error swallowing preserved).utils/fs.ts—createPathItem(path, name, { skipEmpty })andcollectDirectoryItems(paths); replace theexists->getSize->stat-> push block repeated in 4 scanners and theif (await exists(dir)) items.push(...await getDirectoryItems(dir))block repeated in 7.utils/size.ts—sumItemSizes(items)for thereduce((sum, i) => sum + i.size, 0)repetition.commands/shared.ts—SAFETY_ICONS(previously defined identically inclean,scan,interactive), plusrunCleanSelections/countSelectedItems/sumSelectedSizefor the clean loop duplicated betweencleanandinteractive.MaintenanceResultmoved tomaintenance/types.ts(it was declared twice and imported fromdns-cachebytimemachine);maintenance/index.tsre-exports it from the new location.Print/formatting code in
cleanvsinteractivewas intentionally left alone — the wording differs, so merging it would change user-visible output.Type of change
Related issue
N/A
Checklist
bun run lintpassesbun run testpasses (no regressions)bun run buildsucceedsutils/walk.test.ts,utils/concurrency.test.ts; 354 tests pass)Notes for reviewer
Worth a look at
runWithConcurrencyinscanners/index.ts: the old version raced promises as it queued them, the new one is a fixed worker pool overmapPool. Same limit and same error handling, but scheduling order differs slightly.Link to Devin session: https://app.devin.ai/sessions/f560eeb632a4468a93f3ce06d0b53cc5
Requested by: @guhcostan