Skip to content

refactor(packaging): prune declaration and source-map artifacts in one walk - #17659

Merged
nwparker merged 2 commits into
stablyai:mainfrom
nwparker:nwparker/unify-packaged-filename-prunes
Aug 31, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
nwparker:nwparker/unify-packaged-filename-prunes

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

What

config/packaged-runtime-node-modules.cjs had two functions that were byte-identical apart from their regex, and each did its own full recursive walk of packaged Resources/node_modules (~1.7s per walk locally):

They are now one walk with the OR of both predicates:

function isPrunablePackagedRuntimeArtifact(filename) {
  return TYPE_DECLARATION_ARTIFACT_RE.test(filename) || JS_SOURCE_MAP_ARTIFACT_RE.test(filename)
}

Behavior is unchanged

The same set of files is deleted, no more and no less. The two regexes are disjoint — a .d.ts.map never ends in .js.map — so a single pass over the tree deletes exactly the union the two passes deleted. The predicate stays filename-based, so metadata.json.map still 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 single prunePackagedRuntimeTypeAndSourceMapArtifacts, with the two call sites in the tests updated. prunePackagedRuntimeNodeModules is untouched from the caller's perspective.

Bonus reorder

prunePackagedZodSources now runs before the filename walk instead of last. zod/src is 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.cjs against 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 nested bundle.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.

aggregate old==new: true (14 survivors)
filename prunes old(2 walks)==new(1 walk): true
deleted:
  node_modules/deep/a/b/c/bundle.min.js.map
  node_modules/pkg/dist/index.cjs.map
  node_modules/pkg/dist/index.d.cts
  node_modules/pkg/dist/index.d.cts.map
  node_modules/pkg/dist/index.d.mts
  node_modules/pkg/dist/index.d.mts.map
  node_modules/pkg/dist/index.d.ts
  node_modules/pkg/dist/index.d.ts.map
  node_modules/pkg/dist/index.js.map
  node_modules/pkg/dist/index.mjs.map
  node_modules/zod/src/nested.d.ts
  node_modules/zod/src/nested.js.map
survivors:
  node_modules/pkg/README.md
  node_modules/pkg/dist/data.map
  node_modules/pkg/dist/index.cjs
  node_modules/pkg/dist/index.js
  node_modules/pkg/dist/index.mjs
  node_modules/pkg/dist/index.ts
  node_modules/pkg/dist/notes.d.txt
  node_modules/pkg/dist/weird.js.map.bak
  node_modules/pkg/metadata.json.map
  node_modules/pkg/native/binding.node
  node_modules/pkg/package.json
  node_modules/sherpa-onnx-darwin-arm64/libonnxruntime.1.23.2.dylib
  node_modules/sherpa-onnx-darwin-arm64/libonnxruntime.dylib
  node_modules/sherpa-onnx-darwin-arm64/sherpa-onnx.node
  node_modules/zod/index.cjs
  node_modules/zod/src/index.ts
names matching BOTH regexes (must be empty): []
EQUIVALENT

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 generated stem x extension combinations (including adversarial stems like x.d, y.js, z.d.ts) — no filename matches both.

Coverage

Both behaviors stay pinned:

  • .js.map / .cjs.map / .mjs.map pruned across every packaged dep, metadata.json.map survives (packaged-source-map-prune.test.mjs)
  • .d.ts / .d.cts / .d.cts.map / .d.mts.map pruned (electron-builder-config.test.mjs, now also covering .d.cts.map)
  • the "leaves declaration maps to the other prune" test became "removes type declarations and declaration maps in the same walk" — it now asserts electron-updater/out is reduced to main.js alone
  • the aggregate test through prunePackagedRuntimeNodeModules is unchanged and still passes

Verification

  • pnpm test config/scripts/packaged-source-map-prune.test.mjs config/scripts/electron-builder-config.test.mjs — 41 passed
  • pnpm exec oxlint <changed files> — clean
  • oxfmt --check — clean
  • pnpm tc — clean

…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-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR consolidates declaration and JavaScript source-map pruning into one recursive traversal while preserving the aggregate packaging entry point.

  • Deletes Zod sources before traversing packaged dependencies.
  • Replaces two internal pruning helpers with one combined helper.
  • Updates packaging tests to cover the combined behavior and additional declaration artifact variants.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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

@coderabbitai

coderabbitai Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 13 minutes.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 595f27a4-4d18-48ac-9c4e-11ee7ccb6bc2

📥 Commits

Reviewing files that changed from the base of the PR and between eb19f69 and 6b6b14d.

📒 Files selected for processing (2)
  • config/packaged-runtime-node-modules.cjs
  • config/scripts/electron-builder-config.test.mjs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 171a5e91-60ce-4e70-b700-d955bcec5bda

📥 Commits

Reviewing files that changed from the base of the PR and between e22c4ee and eb19f69.

📒 Files selected for processing (3)
  • config/packaged-runtime-node-modules.cjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/packaged-source-map-prune.test.mjs

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The packaged runtime cleanup replaces separate type-declaration and source-map pruning helpers with prunePackagedRuntimeTypeAndSourceMapArtifacts. Cleanup removes Zod sources before the combined traversal and then prunes Sherpa ONNX artifacts. Module exports and tests use the new helper. Test fixtures now include declaration source maps and verify that declaration files, maps, and JavaScript source maps are removed while runtime files remain.

Merge Risk: ⚪ Minimal · up to eb19f

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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… 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 …
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: combining declaration and source-map artifact pruning into one walk.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — prunePackagedRuntimeTypeDeclarations and prunePackagedRuntimeSourceMaps collapse into prunePackagedRuntimeTypeAndSourceMapArtifacts, using the OR of the two existing disjoint filename regexes; the exported surface and both test call sites are updated.
  • Prune reorder — prunePackagedZodSources now runs before the filename walk (deletes zod/src wholesale, so the walk no longer traverses it); prunePackagedSherpaOnnx still runs after the walk, unchanged in effect.
  • Test coverage — the declaration-map test now asserts the combined prune leaves electron-updater/out with only main.js, and the electron-builder config test adds a .d.cts.map fixture.

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).

Pullfrog  | View workflow run | Using 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — isPrunablePackagedRuntimeArtifact becomes isPrunableTypeOrSourceMapArtifact; 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.mts fixture so the m branch 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).

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 97eb762 into stablyai:main Aug 31, 2026
51 of 53 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant