Repository navigation
refactor(packaging): prune declaration and source-map artifacts in one walk - #17659
Conversation
…e walk prunePackagedRuntimeTypeDeclarations and prunePackagedRuntimeSourceMaps were byte-identical apart from their regex, and each did its own full recursive walk of packaged Resources/node_modules (~1.7s per walk). Collapse them into prunePackagedRuntimeTypeAndSourceMapArtifacts, which runs a single walk with the OR of both predicates. The two regexes are disjoint (.d.ts.map never ends in .js.map), so one pass deletes exactly the union the two passes deleted. Neither old function had a production caller outside prunePackagedRuntimeNodeModules, so both exports are replaced by the combined one rather than kept as wrappers, which would have reintroduced the duplicate walk. Also moves prunePackagedZodSources ahead of the filename walk: zod/src is removed wholesale, so traversing it first was pure wasted work. The prunes are independent, so the reorder does not change the result.
Greptile SummaryThe PR consolidates declaration and JavaScript source-map pruning into one recursive traversal while preserving the aggregate packaging entry point.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| config/packaged-runtime-node-modules.cjs | Combines two disjoint deletion predicates into one traversal and safely reorders independent cleanup operations. |
| config/scripts/electron-builder-config.test.mjs | Updates the helper import and expands declaration-pruning coverage to additional module declaration variants. |
| config/scripts/packaged-source-map-prune.test.mjs | Updates focused and aggregate tests to verify declaration and source-map removal through the combined helper. |
Reviews (2): Last reviewed commit: "fix: correct the one-walk rationale and ..." | Re-trigger Greptile
|
Warning Review limit reachedNext included review available in 13 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe packaged runtime cleanup replaces separate type-declaration and source-map pruning helpers with Merge Risk: ⚪ Minimal · up to The change combines equivalent packaging cleanup passes and reorders an independent cleanup step without changing the files removed; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed change rationale, behavior equivalence evidence, coverage, and verification results. However, it does not follow the repository template and omits the required Linked Issue entry, Visual Proof or an explicit N/A explanation, Testing checklist, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections. Resolution Restructure the description to include all template sections. Add the required issue reference after "Fixes #", state "N/A" with a brief reason for Visual Proof, complete the Testing checklist, and address the remaining Review, Agent skill upstream boundary, Notes, and Checklist sections. 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
One commit merging the two packaged node_modules prune walks (type-declaration artifacts and JS source maps) into a single recursive walk, plus a reorder that runs prunePackagedZodSources before the walk.
- Single-walk prune —
prunePackagedRuntimeTypeDeclarationsandprunePackagedRuntimeSourceMapscollapse intoprunePackagedRuntimeTypeAndSourceMapArtifacts, using the OR of the two existing disjoint filename regexes; the exported surface and both test call sites are updated. - Prune reorder —
prunePackagedZodSourcesnow runs before the filename walk (deleteszod/srcwholesale, so the walk no longer traverses it);prunePackagedSherpaOnnxstill runs after the walk, unchanged in effect. - Test coverage — the declaration-map test now asserts the combined prune leaves
electron-updater/outwith onlymain.js, and the electron-builder config test adds a.d.cts.mapfixture.
The refactor is behavior-preserving: the two regexes are disjoint, the OR predicate deletes exactly the prior union, and the three prunes touch disjoint file sets so the reorder is safe. Both affected test files pass (41 tests).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
The comment credited predicate disjointness for making the merge safe. That is not the reason and is misleading: it implies a future overlapping predicate would break the collapse. Passes commute because pruneMatchingFiles only deletes files and never removes directories, so the tree it walks is identical each time — verified by running the old two-walk code with the passes reversed and diffing survivors. Also narrow isPrunablePackagedRuntimeArtifact to isPrunableTypeOrSourceMapArtifact (node-pty prebuilds and duplicate sherpa dylibs are prunable runtime artifacts too, but this predicate returns false for them), and add the missing .d.mts fixture so every branch of the (?:c|m)? alternation is exercised against the exact-survivor assertion.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
One follow-up commit since the prior Pullfrog review (eb19f69): it renames the predicate helper, corrects the one-walk rationale, and closes a test coverage gap.
- Predicate rename —
isPrunablePackagedRuntimeArtifactbecomesisPrunableTypeOrSourceMapArtifact; the module's other prunes (node-pty prebuilds, duplicate sherpa dylibs) are also prunable artifacts this predicate returns false for, so the narrower name is accurate. - Corrected rationale — the one-walk comment now credits commutation of file-only deletions rather than predicate disjointness, which would wrongly imply an overlapping predicate breaks the collapse.
- Coverage — the electron-builder config test adds a plain
.d.mtsfixture so thembranch of the(?:c|m)?alternation is exercised against the exact-survivor assertion.
The delta is behavior-neutral (rename, comment, one test fixture) and both affected test files pass (41 tests).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…e walk (stablyai#17659) * refactor(packaging): prune declaration and source-map artifacts in one walk prunePackagedRuntimeTypeDeclarations and prunePackagedRuntimeSourceMaps were byte-identical apart from their regex, and each did its own full recursive walk of packaged Resources/node_modules (~1.7s per walk). Collapse them into prunePackagedRuntimeTypeAndSourceMapArtifacts, which runs a single walk with the OR of both predicates. The two regexes are disjoint (.d.ts.map never ends in .js.map), so one pass deletes exactly the union the two passes deleted. Neither old function had a production caller outside prunePackagedRuntimeNodeModules, so both exports are replaced by the combined one rather than kept as wrappers, which would have reintroduced the duplicate walk. Also moves prunePackagedZodSources ahead of the filename walk: zod/src is removed wholesale, so traversing it first was pure wasted work. The prunes are independent, so the reorder does not change the result. * fix: correct the one-walk rationale and close the .d.mts coverage gap The comment credited predicate disjointness for making the merge safe. That is not the reason and is misleading: it implies a future overlapping predicate would break the collapse. Passes commute because pruneMatchingFiles only deletes files and never removes directories, so the tree it walks is identical each time — verified by running the old two-walk code with the passes reversed and diffing survivors. Also narrow isPrunablePackagedRuntimeArtifact to isPrunableTypeOrSourceMapArtifact (node-pty prebuilds and duplicate sherpa dylibs are prunable runtime artifacts too, but this predicate returns false for them), and add the missing .d.mts fixture so every branch of the (?:c|m)? alternation is exercised against the exact-survivor assertion.

What
config/packaged-runtime-node-modules.cjshad two functions that were byte-identical apart from their regex, and each did its own full recursive walk of packagedResources/node_modules(~1.7s per walk locally):prunePackagedRuntimeTypeDeclarations—/\.d\.(?:c|m)?ts(?:\.map)?$/prunePackagedRuntimeSourceMaps—/\.(?:c|m)?js\.map$/(added in perf(packaging): prune JS source maps from all packaged node_modules #17638)They are now one walk with the OR of both predicates:
Behavior is unchanged
The same set of files is deleted, no more and no less. The two regexes are disjoint — a
.d.ts.mapnever ends in.js.map— so a single pass over the tree deletes exactly the union the two passes deleted. The predicate stays filename-based, sometadata.json.mapstill survives.Exported surface
Neither old function had a production caller outside
prunePackagedRuntimeNodeModules(only tests imported them directly). Keeping them as thin wrappers would have required keeping their separate predicates — and therefore the second walk — so both exports are replaced by the singleprunePackagedRuntimeTypeAndSourceMapArtifacts, with the two call sites in the tests updated.prunePackagedRuntimeNodeModulesis untouched from the caller's perspective.Bonus reorder
prunePackagedZodSourcesnow runs before the filename walk instead of last.zod/srcis deleted wholesale, so the walk was traversing it immediately before it was removed — pure wasted work. The prunes are independent of each other, so the order change does not affect the result (verified by the aggregate equivalence run below).Equivalence evidence
Throwaway script (not committed) built identical fixture trees and ran
git show origin/main:config/packaged-runtime-node-modules.cjsagainst the new file. Fixture covered.d.ts,.d.cts,.d.mts,.d.ts.map,.d.cts.map,.d.mts.map,.js.map,.cjs.map,.mjs.map, a nestedbundle.min.js.map, plus survivors:.js/.cjs/.mjs,metadata.json.map,data.map,weird.js.map.bak,notes.d.txt,index.ts,binding.node,package.json,README.md,zod/src/*, and the sherpa-onnx dylibs.Both comparisons matched exactly: the full
prunePackagedRuntimeNodeModules('darwin','arm64')old-vs-new run, and old's two separate walks vs new's single walk. Regex disjointness was checked over every fixture basename plus generatedstem x extensioncombinations (including adversarial stems likex.d,y.js,z.d.ts) — no filename matches both.Coverage
Both behaviors stay pinned:
.js.map/.cjs.map/.mjs.mappruned across every packaged dep,metadata.json.mapsurvives (packaged-source-map-prune.test.mjs).d.ts/.d.cts/.d.cts.map/.d.mts.mappruned (electron-builder-config.test.mjs, now also covering.d.cts.map)electron-updater/outis reduced tomain.jsaloneprunePackagedRuntimeNodeModulesis unchanged and still passesVerification
pnpm test config/scripts/packaged-source-map-prune.test.mjs config/scripts/electron-builder-config.test.mjs— 41 passedpnpm exec oxlint <changed files>— cleanoxfmt --check— cleanpnpm tc— clean