fix(convert): resolve directory pruning failure on Windows due to pat…#148
Conversation
…h separator mismatches
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (3)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{test,spec}.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2026-06-09T18:30:08.038ZApplied to files:
🪛 ast-grep (0.44.1)packages/leadtype/src/convert/convert.test.ts[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) [warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) packages/leadtype/src/convert/convert.ts[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) [warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) 🪛 markdownlint-cli2 (0.23.0).changeset/fuzzy-dodos-prune.md[warning] 5-5: First line in a file should be a top-level heading (MD041, first-line-heading, first-line-h1) 🔇 Additional comments (4)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesWindows prune path normalization
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a Windows-only fix in pruneOrphanedOutputs so that empty parent directories left by pruned .md files are actually removed.
- Normalize parent paths before the prefix check —
orphansare produced by fast-glob, which returns POSIX forward-slash paths on every platform, whileresolve(outDir)returns backslash paths on Windows. The olddir.startsWith(resolvedOutDir + sep)guard therefore never matched on Windows, so empty directories were never swept. Wrapping the parent derivation (resolve(dirname(filePath))and the loop stepresolve(dirname(dir))) normalizes to platform-native separators, restoring correct behavior.
The change is minimal and correct. One harmless redundancy worth noting for a future pass: after the first loop iteration dir is already resolved and dirname of a native path stays native, so the loop-step resolve() is a no-op — not worth changing on its own.
Claude Opus | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a one-line cleanup in pruneOrphanedOutputs that removes the redundant loop-step resolve() flagged by the prior review.
- Drop redundant
resolve()in the directory-sweep loop — the loop step is nowdir = dirname(dir)instead ofdir = resolve(dirname(dir)). Since theparentsset is seeded withresolve(dirname(filePath)),dirstarts as a platform-native path anddirnameof a native path stays native, so the removedresolve()was a no-op. Behavior is unchanged and the Windows prefix check still holds.
Claude Opus | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the delta since the prior pullfrog review (ea63aa0) adds test coverage and a changeset for the Windows directory-pruning fix.
- Extracted
resolvePruneParentDirectoriesseam — parent-dir derivation moved out ofpruneOrphanedOutputsinto an exported helper that accepts an injectablePrunePathApi({ dirname, resolve }), defaulting to the platformnode:pathbindings. Production behavior is unchanged. - Added a Windows-path test — injects
path.win32and asserts that a POSIX (C:/…) and a backslash (C:\…) orphan dedupe to the single native parentC:\repo\public\guides. This exercises the separator normalization on Linux CI, addressing the "no test" gap noted in the prior review. - Added changeset —
leadtypepatchdescribing the Windows pruning fix.
The refactor preserves the original fix's behavior, the test is deterministic on Linux (drive-letter inputs are absolute under path.win32, so resolve never consults cwd), and the injected PrunePathApi is a reasonable seam for cross-platform path testing.
Claude Opus | 𝕏

close:#146
Description
During output pruning (
convertAllMdx --prune), empty parent directories left behind by deleted markdown files were not being deleted on Windows. This was caused by a path separator mismatch between glob output paths (which use/) and resolved output directories (which use\).This PR normalizes all paths to platform-specific format using
path.resolve()before performing prefix/directory matching.Cause
In
pruneOrphanedOutputs, the directory sweep checks if a parent directory is insideoutDirusing: