Add safe Docker runtime cleanup#2
Conversation
Adds a repeatable --ignore CLI option and support for ~/.config/dev-purge/config.json with an ignore array. Patterns are glob-like (supports ~ and **). Scanner respects ignore patterns when discovering projects and bloat dirs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Useful feature, but this PR overlaps significantly with #3 (ignore-pattern handling) — the two are diverging. Worth resolving before merge. Critical[P0] Overlap with #3, with diverged glob implementation. Both PRs add
Recommend: rebase on top of #3 after that merges and drop the duplicated Should fix[P1] [P1] Docker [P2] [P2] Nice catches
Minor
VerdictBlock on the #3 overlap. Either:
The Docker portion is solid and ready. Don't ship two diverging glob implementations. |
- Make getFlagValue/getFlagValues/positional parsing consistent via a known-flag check, so an ignore value that starts with "-" (e.g. `--ignore -skip`) is captured instead of silently dropped, and a real flag after `--ignore` (e.g. `--ignore --json`) is not swallowed. (P1) - Defer the config.json read into a runtime loadIgnorePatterns() so a slow or hung $XDG_CONFIG_HOME mount can no longer hang `dev-purge --help`. (P2) - Warn on invalid (non-string/empty) config "ignore" entries instead of dropping them silently — predictable behavior for cron-driven runs. (P3) - Guard against a bare "~" expanding to "" in envs with no HOME, which would otherwise compile to a match-everything pattern. (P2) - README: note case-sensitivity of bare-name matching and config validation. (P3) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Adds best-effort cleanup of Docker leftovers alongside the filesystem scan: exited containers (status=exited) and dangling images (dangling=true) only — running containers and tagged images are never targeted. Docker is invoked via execFile with an argv array (no shell) with a 15s timeout. New surface: - `--containers-only` / `--images-only` (mutually exclusive) and `--category containers` / `--category images` to scope to runtime artifacts; runtime-only modes skip the filesystem walk entirely. - `--older-than` is applied to dated artifacts; artifacts with no parseable creation date are kept (safe choice) with a warning explaining why. - Per-item delete with separate success/failure tracking. Rebased on top of LarsenCundric#3 (ignore-pattern handling) so there is a single glob/ignore implementation: the duplicated `globToRegExp`, `--ignore`/config loading, and `canCollectBloatAtDir` root-bloat fix that an earlier version of this branch carried are dropped and inherited from LarsenCundric#3 instead. Review fixes: - error when --containers-only and --images-only are combined - warn (don't silently drop) on unparseable Docker JSON output lines - warn when --older-than keeps an artifact due to an unparseable date - show the real Docker error dimmed when runtime cleanup is skipped - combined early-return so runtime-only runs print/act correctly Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
29dbfca to
60d4a93
Compare
|
Thanks — this was a great review. Force-pushed Critical[P0] Overlap / diverged glob ✅ Should fix[P1] [P1] [P2] [P2] Minor
Ready for re-review. I'll rebase/clean-collapse again right after #3 merges if you'd like a final pure-Docker diff before merging this one. |
|
@LarsenCundric — merge this one after #3 (it’s stacked on it). Ready to merge + ship 🚀Both PRs are MERGEABLE / CLEAN and all review feedback is addressed. Since I only have read access here, the merge + publish are yours to do. Suggested order: No release CI is configured, so step 3–4 are a manual publish by the npm package owner. Happy to prep the version bump as a separate PR if you’d prefer that to be in git first. |
Summary
Adds best-effort Docker runtime cleanup alongside the filesystem scan:
status=exited) and dangling images (dangling=true) only — running containers and tagged images are never targeted--category containers/--category images, or--containers-only/--images-only(mutually exclusive); runtime-only modes skip the filesystem walk--older-thanapplied to dated artifacts; artifacts with no parseable creation date are kept (safe choice) with a warningSafety
status=exitedfilter)dangling=truefilter)execFilewith an argv array (no shell), 15s timeout so a stuck daemon can't hang a cron jobPer @LarsenCundric's review, this is rebased on top of #3 so there is a single glob/ignore implementation. The duplicated
globToRegExp,--ignore/config loading, and thecanCollectBloatAtDirroot-bloat fix that an earlier version of this branch carried are dropped here and inherited from #3.Merge order: #3 first, then this PR. Until #3 lands, the diff above also includes #3's changes (
src/scanner.js, the--ignoreparsing). Once #3 merges, this collapses to justsrc/docker.js, the runtime integration insrc/index.js, and the Docker README section. The earlierpackage-lock.jsonrename noise is also gone.Checks
node --check src/index.js/src/docker.js/src/scanner.js--containers-only,--images-only,--category containers|imagesdry-runs against a live Docker daemon (filesystem walk correctly skipped)--containers-only --images-onlytogether errors (mutually exclusive)