Skip to content

perf(packaging): prune JS source maps from all packaged node_modules - #17638

Merged
nwparker merged 2 commits into
stablyai:mainfrom
nwparker:nwparker/prune-packaged-source-maps
Aug 31, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
nwparker:nwparker/prune-packaged-source-maps

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Generalizes the @linear/sdk-scoped source-map prune from #17530 into a
single rule over the whole packaged Resources/node_modules, mirroring the
neighboring prunePackagedRuntimeTypeDeclarations.

prunePackagedLinearSdkSourceMaps -> prunePackagedRuntimeSourceMaps,
LINEAR_SDK_SOURCE_MAP_RE -> JS_SOURCE_MAP_ARTIFACT_RE (the pattern was
already generic).

Measured win

Read-only measurement over the exact package set
createPackagedRuntimeNodeModuleResources('darwin') copies:

Package Bytes Files
@linear/sdk (already pruned by #17530) 6674.3 KB 2
js-yaml 540.3 KB 3
electron-updater 319.8 KB 32
builder-util-runtime 107.4 KB 14
node-pty 64.0 KB 19
lazy-val 1.1 KB 1
get-caller-file 0.8 KB 1

Newly recovered: 1033.4 KB (~1.01 MB) across 5 additional packages.
Total under the rule: 7.53 MB.

Safety audit

1. Does anything enable Node source-map support in the packaged app? No.
Repo-wide grep (excluding node_modules) for --enable-source-maps,
setSourceMapsEnabled, source-map-support, sourceMapSupport returns
zero source hits - only pnpm-lock.yaml entries, where
[email protected] is a build-time dependency of app-builder-lib,
not a runtime one. Electron does not enable source-map support by default,
and no NODE_OPTIONS value anywhere sets it (every occurrence is
--max-old-space-size for CI builds, or the build scripts'
appendBuildOldSpaceOption). The shipped CLI launchers
(resources/darwin/bin/orca, resources/linux/bin/orca-ide,
src/main/cli/cli-dev-launcher.ts) actively unset NODE_OPTIONS into
ORCA_NODE_OPTIONS, so even a user with NODE_OPTIONS=--enable-source-maps
in their environment does not turn it on. src/relay/ai-vault-service-spawn
likewise drops NODE_OPTIONS for its sidecar. These files were never read.

2. Do the affected packages require source-map-support themselves? No.
grep -r source-map-support over electron-updater/out,
builder-util-runtime/out, js-yaml, node-pty/lib returns nothing, and
none of them declare it in dependencies. (For the record, even if one did,
source-map-support swallows a missing .map and falls back to the
unmapped frame.)

3. Is any .js.map loaded as data or as a module? No. No
require(...'.js.map') and no .map path read in packaged code. Every
in-repo .js.map string is a test fixture, a comment, or the
out/**/*.map-related build config. The prune is filename-based, so the
test suite pins that a non-JS metadata.json.map survives.

4. Scope safety - can it ever touch the developer's checkout? No.
config/electron-builder.config.cjs afterPack derives resourcesDir
purely from context.appOutDir (<appOutDir>/<Product>.app/Contents/Resources
on darwin, <appOutDir>/resources elsewhere) and throws if it does not
exist. appOutDir is electron-builder's packaged output directory; the repo
root is never on that path, so the walk starts inside dist/ and cannot
reach the checkout's node_modules. The prune additionally no-ops if
<resourcesDir>/node_modules is absent. pruneMatchingFiles cannot escape
the tree either: it uses readdirSync(dir, { withFileTypes: true }) and
recurses only on entry.isDirectory(), deleting only on entry.isFile() -
a Dirent for a symlink reports isSymbolicLink() and false for both, so
symlinks are neither followed nor deleted. This is the same walk the
existing type-declaration prune has been using.

5. Collision with the type-declaration prune? None - the predicates are
disjoint.
TYPE_DECLARATION_ARTIFACT_RE = /\.d\.(?:c|m)?ts(?:\.map)?$/
matches .d.ts.map / .d.cts.map / .d.mts.map;
JS_SOURCE_MAP_ARTIFACT_RE = /\.(?:c|m)?js\.map$/ matches .js.map /
.cjs.map / .mjs.map. No filename can satisfy both. A regression test
asserts that prunePackagedRuntimeSourceMaps leaves main.d.ts.map alone.

6. Debugging impact: negligible. This does remove mapped stack frames for
dependency code in a packaged build - but given #1, Node was never
consuming those maps anyway, so nothing that works today stops working.
Orca's own main-process maps are unaffected: files already contains
'!out/**/*.map', and release-cut bundles out/main/**/*.js.map into the
orca-sourcemaps-<tag>.zip release artifact, which lives outside
node_modules and outside resourcesDir.

Tests

config/scripts/packaged-linear-sdk-prune.test.mjs ->
packaged-source-map-prune.test.mjs (the file is no longer SDK-specific).
Coverage: the SDK case still passes and the pruned SDK still require()s;
js-yaml / node-pty / electron-updater maps are now pruned too;
.d.ts.map survives the source-map prune; metadata.json.map survives both
the direct call and the aggregate prunePackagedRuntimeNodeModules.

Verified with pnpm test config/scripts/packaged-source-map-prune.test.mjs config/scripts/electron-builder-config.test.mjs (41 passed), pnpm exec oxlint, and pnpm tc. No full package build was run.

Generalizes the @linear/sdk-scoped prune to every packaged dependency,
matching the existing type-declaration prune's single-predicate walk over
Resources/node_modules. Recovers ~1.01 MB beyond the SDK.

Nothing in the packaged app enables Node source-map support
(no --enable-source-maps, no setSourceMapsEnabled, no source-map-support
require), and the CLI launchers strip NODE_OPTIONS, so these maps were
never read. Orca's own main-process maps live outside node_modules and
already ship as a separate release artifact.
@greptile-apps

greptile-apps Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR generalizes packaged dependency source-map pruning from @linear/sdk to the complete runtime node_modules tree.

  • Renames the pruning function and source-map predicate to reflect their broader scope.
  • Applies the existing recursive file-pruning walk to all packaged runtime dependencies.
  • Replaces the SDK-specific test suite with coverage for multiple dependencies, declaration maps, non-JavaScript maps, aggregate cleanup, and SDK loading.

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 Broadens packaged JavaScript source-map removal to all runtime dependencies while retaining the existing traversal and file-matching behavior.
config/scripts/packaged-linear-sdk-prune.test.mjs Removes the superseded SDK-specific source-map pruning tests.
config/scripts/packaged-source-map-prune.test.mjs Adds generalized regression coverage for whole-tree source-map pruning and preservation of unrelated map artifacts.

Reviews (2): Last reviewed commit: "Merge branch 'main' into nwparker/prune-..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: d8b5c46e-de52-4cb1-bc55-d58ace29167b

📥 Commits

Reviewing files that changed from the base of the PR and between d641d87 and e49ac53.

📒 Files selected for processing (3)
  • config/packaged-runtime-node-modules.cjs
  • config/scripts/packaged-linear-sdk-prune.test.mjs
  • config/scripts/packaged-source-map-prune.test.mjs
💤 Files with no reviewable changes (1)
  • config/scripts/packaged-linear-sdk-prune.test.mjs

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


📝 Walkthrough

Walkthrough

The runtime cleanup now removes .js.map, .cjs.map, and .mjs.map files across packaged node_modules, instead of limiting removal to @linear/sdk. It preserves non-JavaScript maps, declaration files, runtime files, and package metadata. New tests cover direct pruning, package loading, all fixture dependencies, and aggregate runtime cleanup.

Merge Risk: ⚪ Minimal · up to e49ac

This change removes JavaScript source maps from packaged dependencies while preserving runtime code and unrelated map files. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: pruning JavaScript source maps from all packaged node_modules dependencies.
Description check ✅ Passed The description provides detailed coverage of the change, rationale, measured impact, safety analysis, and tests. It does not include the required linked issue, explicit Visual Proof section with N/A,…
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 coverage of the change, rationale, measured impact, safety analysis, and tests. It does not include the required linked issue, explicit Visual Proof section with N/A, or the template checklist and section headings.

  • Fix all pre-merge checks with AI

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

Generalizes the @linear/sdk-scoped source-map prune into a single rule over the whole packaged Resources/node_modules, renaming prunePackagedLinearSdkSourceMaps → prunePackagedRuntimeSourceMaps and LINEAR_SDK_SOURCE_MAP_RE → JS_SOURCE_MAP_ARTIFACT_RE, and porting the test suite to the broader scope.

  • prunePackagedRuntimeSourceMaps — walks all of Resources/node_modules with the same pruneMatchingFiles helper the type-declaration prune uses, keyed on JS_SOURCE_MAP_ARTIFACT_RE (\.(?:c|m)?js\.map$).
  • Renamed export and call site — prunePackagedRuntimeNodeModules now invokes the generalized prune; the old symbol has no remaining references anywhere in the repo.
  • Test port — packaged-linear-sdk-prune.test.mjs → packaged-source-map-prune.test.mjs, extending coverage to js-yaml / node-pty / electron-updater maps, disjoint-predicate preservation (.d.ts.map survives), and the filename-based metadata.json.map exception.

I independently re-verified the load-bearing safety claims: no source-map-support / --enable-source-maps / setSourceMapsEnabled usage in source (only build-time pnpm-lock entries), '!out/**/*.map' keeps Orca's own maps out of node_modules, and the new test file passes (4 tests).

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

@nwparker
nwparker merged commit 0293ebe into stablyai:main Aug 31, 2026
29 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#17638)

Generalizes the @linear/sdk-scoped prune to every packaged dependency,
matching the existing type-declaration prune's single-predicate walk over
Resources/node_modules. Recovers ~1.01 MB beyond the SDK.

Nothing in the packaged app enables Node source-map support
(no --enable-source-maps, no setSourceMapsEnabled, no source-map-support
require), and the CLI launchers strip NODE_OPTIONS, so these maps were
never read. Orca's own main-process maps live outside node_modules and
already ship as a separate release artifact.
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