Skip to content

Reduce native dependency installs to the host platform - #20420

Merged
nwparker merged 6 commits into
mainfrom
nwparker/pnpm-native
Sep 13, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/pnpm-native

Conversation

@nwparker

@nwparker nwparker commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Every developer checkout and ordinary CI job installed native binaries for macOS, Linux, and Windows on both CPU architectures. Install only what the host can use, and let the few jobs that genuinely package for a second target opt in. On a fresh Apple Silicon install this removes 90 packages and 1.23 GiB of logical package content (53.3%).

What Changed

  • Default supportedArchitectures to the current OS/CPU; local development and ordinary CI inherit it.
  • Scope release installs to what each job actually packages. Every packaging job runs on a runner whose OS matches its target, so no job needs a foreign OS. The four macOS lanes pass --cpu=current,x64,arm64 because the mac config emits x64 and arm64 from an arm64 runner; Windows and Linux packaging use a plain host-only install.
  • pnpm install:release (pnpm install --frozen-lockfile --cpu=current,x64,arm64) covers local cross-architecture packaging, including pnpm build:mac.
  • Add an arch-aware beforePack guard. electron-builder only warns on a missing extraResources source and continues, so a thin install would ship a foreign-architecture slice with no sherpa-onnx-* and no @parcel/watcher-*. The guard fails the build instead, naming every missing package and giving the remedy that fits — another architecture comes from install:release; the os: win32 addons need a Windows host.
  • Allow Electron Builder's config to load without the unused Windows addons; completeness is enforced by the guard, not by config load.
  • Document the policy in docs/reference/pnpm-install-policy.md and .github/CONTRIBUTING.md.

Why

Clean, frozen, script-free, offline installs using the same lockfile and existing pnpm store on macOS arm64 / pnpm 12.0.0:

Measure Broad Host only
Package directories 1,296 1,206
Logical package bytes 2,485,153,773 1,159,396,649
Logical package GiB 2.31 1.08
Single warm-cache install trial 11.98 s 11.25 s

These are logical file bytes, not unique physical disk savings: hardlinks/APFS clones can share storage. Lifecycle builds and Electron downloads were excluded equally. The single timing pair does not establish a speedup; cold-network and Linux/Windows CI timings were not measured. Existing node_modules can retain variants, so reclaiming them requires a fresh install. Shared pnpm caches are not deleted. Full numbers and method are in the policy doc.

Linked Issue

User-requested dependency-install audit; no existing issue supplied.

Visual Proof

N/A — no visual change; dependency installation and packaging configuration only.

Testing

  • Manually validated on macOS arm64 with pnpm 12.0.0.
  • Automated tests updated.
  • Fresh host-only frozen install; confirmed Windows addons and Intel speech package absent.
  • pnpm tc passes all three projects, oxlint clean, changed-code quality gate clean, from a host-only install.
  • Config/packaging test files: 121 passed, 3 Windows-only skipped.
  • Guard exercised directly over darwin/{x64,arm64}, win32/{x64,arm64}, linux/x64: the host target passes and every foreign target fails with the correct missing-package list.
  • Verified against pnpm 12 that a --cpu-widened --frozen-lockfile install adds the missing variants on top of an existing host-only node_modules, and that narrowing back does not prune them.
  • Full suite and Windows/Linux execution remain for CI; signed/cross-target release artifacts were not built locally.

Review

The first revision of this PR kept a broad --os=current,darwin,linux,win32 on every release lane and guarded only Windows packaging. Both were wrong: no packaging job cross-compiles across operating systems, and the platform that could silently ship a broken artifact was macOS, whose dual-architecture build runs on an arm64 host. This revision narrows the release installs to what each runner actually targets and replaces the win32-only check with an arch-aware guard over all platforms.

No dependency versions or lockfile changed. SSH execution, wire formats, folder workspaces, agents, integrations, git providers, and mobile's separate dependency policy are unaffected. No new network execution or security-sensitive runtime behavior. UI review is not applicable.

Cross-platform verification

Rebased onto current main, which vendored the Windows registry addon as the workspace package @orca/windows-registry (#20438). Because a workspace link resolves on every host, @vscode/windows-process-tree is now the only os: win32 npm addon and is what the installed-addon checks key on.

Verified at a63c8399c2b on real hosts, not just CI:

Host Result
macOS arm64 Host-only install; only sherpa-onnx-darwin-arm64 + watcher-darwin-arm64; guard passes darwin/arm64 and fails every foreign target; 117 tests; pnpm tc clean
Linux x64 Host-only install; only sherpa-onnx-linux-x64 + watcher-linux-x64-glibc; @vscode/windows-process-tree absent; guard correct; 107 tests
Windows x64 Host-only install incl. node-gyp rebuild of the vendored addon; only sherpa-onnx-win-x64 + watcher-win32-x64; both addons present; guard passes win32/x64; Windows lane 43/44 files, 371 tests

The one Windows lane failure, src/main/cursor/hook-service.test.ts, is pre-existing: it fails identically on origin/main on that same machine and passes in CI.

Agent skill upstream boundary

  • Not applicable; no upstream skill material copied.

Checklist

  • Focused on native dependency install scope
  • Explained what changed and why, including measurements
  • N/A visual proof with reason
  • Self-reviewed correctness, security, and performance
  • Cross-platform and SSH/remote impact considered
  • Typecheck/lint and focused tests passed locally; full suite and other operating systems left to CI

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: bda3d371-3803-4324-8eda-f29564e70220

📥 Commits

Reviewing files that changed from the base of the PR and between e14bd91 and 23be43e.

📒 Files selected for processing (2)
  • config/scripts/electron-builder-runtime-resources.test.mjs
  • config/scripts/windows-process-tree-gyp-rebuild.test.mjs

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


📝 Walkthrough

Walkthrough

Default pnpm installs now include native optional dependencies for the current OS and CPU only. Release installation retains current, x64, and arm64 CPU variants. CI workflows use host-only installs or macOS CPU-expanded installs as required. Electron packaging validates required native variants before packing and loads Windows resources only when the Windows addons exist. Windows-specific tests are gated or run in the Windows CI lane.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 23be4

The documented install-size comparison may be inaccurate, but this does not block packaging or installation behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: limiting native dependency installs to the host platform.
Description check ✅ Passed The description is detailed, relevant, and covers the change, rationale, testing, cross-platform impact, visual proof, review notes, and checklist. It states that no linked issue was supplied and omit…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 9128aac2-57a1-4e9d-9211-7d8928aa0518

📥 Commits

Reviewing files that changed from the base of the PR and between 775137d and 057e4d7.

📒 Files selected for processing (21)
  • .github/CONTRIBUTING.md
  • .github/workflows/adhoc-mac-build.yml
  • .github/workflows/daily-mac-build.yml
  • .github/workflows/dev-channel-win-build.yml
  • .github/workflows/hourly-mac-build.yml
  • .github/workflows/pr.yml
  • .github/workflows/release-cut.yml
  • .github/workflows/release-mac-build.yml
  • .github/workflows/windows-signing-rehearsal.yml
  • config/electron-builder.config.cjs
  • config/scripts/ci-dependency-download-cache.test.mjs
  • config/scripts/electron-builder-config.test.mjs
  • config/scripts/electron-builder-runtime-resources.test.mjs
  • config/scripts/measure-pnpm-install.mjs
  • config/scripts/package-electron-runtime-contract.test.mjs
  • config/scripts/pr-workflow-parallelism.test.mjs
  • config/scripts/windows-process-tree-gyp-path.test.mjs
  • config/scripts/windows-process-tree-gyp-rebuild.test.mjs
  • docs/reference/pnpm-install-policy.md
  • package.json
  • pnpm-workspace.yaml

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

Comment thread config/scripts/measure-pnpm-install.mjs Outdated
sherpa: ['sherpa-onnx-'],
oxlint: ['@oxlint+', '@oxlint-tsgolint+'],
swc: ['@swc+core-'],
typescript: ['@typescript+']

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Include the unscoped typescript packages in the family measurement.

The script matches virtual-store names with startsWith. The store contains both [email protected] and [email protected], so @typescript+ does not count the compiler packages. Keep the scoped platform-package match and add the unscoped prefix.

Proposed fix
-  typescript: ['`@typescript`+']
+  typescript: ['`@typescript`+', 'typescript@']
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
typescript: ['@typescript+']
typescript: ['@typescript+', 'typescript@']

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

Important

The beforePack guard fails loudly for Windows packaging without the Windows addons, but the equivalent cross-arch failure for local macOS/Linux packaging is unguarded and silent. Worth a look before merge.

Reviewed changes

  • Host-only default install: pnpm-workspace.yaml narrows supportedArchitectures.os/cpu to [current]; the release workflows and the new install:release script opt back into --os=current,darwin,linux,win32 --cpu=current,x64,arm64.
  • Windows packaging guard: config/electron-builder.config.cjs computes windowsRuntimeResources only when both Windows addons are present and throws from beforePack for win32 when they are not.
  • Platform-gated tests: Windows-addon/packaging assertions moved behind process.platform === 'win32' and registered in the PR Windows lane; new tests pin the cross-target flags on release workflows and install:release.
  • Docs/measurement: new docs/reference/pnpm-install-policy.md and config/scripts/measure-pnpm-install.mjs.

ℹ️ Stale comments and docs still describe the old broad install

The default now fetches only the host, so two existing references state behavior that is no longer true and can mislead the next engineer debugging a cross-arch package:

  • config/packaged-runtime-node-modules.cjs:439 — "we package every installed @parcel/watcher-<platform> optional subpackage (supportedArchitectures fetches all)". After this change, "fetches all" is only true under install:release; a default install fetches just the host variant.
  • docs/reference/windows-process-enumeration.md:511-512 — "pnpm installs optional dependencies on every host, and macOS/Linux must never run node-gyp for it". The addon is no longer installed on macOS/Linux at all, so the rationale needs updating.
Technical details
# Stale cross-host install rationale

## Affected sites
- `config/packaged-runtime-node-modules.cjs:438-440` — comment asserts every platform subpackage is installed; only true with the release flags now.
- `docs/reference/windows-process-enumeration.md:510-515` — `allowBuilds` rationale says pnpm installs the Windows addon on every host; it no longer does.

## Required outcome
- Comments/docs should describe the new contract: host-only by default, broad closure only via `pnpm install:release`.

ℹ️ Nitpicks

  • The new page docs/reference/pnpm-install-policy.md has no !docs/reference/pnpm-install-policy.md entry in .gitignore's allow-list, so a clean git add would not pick it up (tracked here only because it was force-added). Per repo convention this is at most a nitpick.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread config/electron-builder.config.cjs Resolved

@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

  • Re-introduced the install-policy documentation (.github/CONTRIBUTING.md, AGENTS.md, new docs/reference/pnpm-install-policy.md, .gitignore allow-list) after the intermediate deletion.
  • Added assertPackagedNativeVariantsInstalled and wired it into beforePack, extending the missing-native build-failure guard from win32 to darwin and linux architectures.
  • Scoped release installs to each runner's actual target (macOS --cpu=current,x64,arm64, other packaging jobs host-only) and removed the unused config/scripts/measure-pnpm-install.mjs.
  • Updated the packaging tests, the supportedArchitectures pin, and the Windows CI lane to match the new contract.

ℹ️ Stale cross-host rationale in windows-process-enumeration.md

The allowBuilds rationale in docs/reference/windows-process-enumeration.md:510-512 still says "pnpm installs optional dependencies on every host", which the narrowed supportedArchitectures makes untrue — the Windows addon is no longer installed on macOS/Linux. The sibling comment in package-electron-runtime-contract.test.mjs was rewritten for this exact reason; this doc was not.

Technical details
# Stale cross-host install rationale

## Affected sites
- `docs/reference/windows-process-enumeration.md:510-512` — `allowBuilds` rationale asserts pnpm installs the Windows addon on every host, so macOS/Linux must never run `node-gyp`. After the host-only narrowing, the addon is not installed off Windows at all.

## Required outcome
- The rationale should describe the new contract: host-only by default, Windows addons arriving only where `os: win32` matches (and built only by the Windows-only rebuild).

## Open questions for the human (optional)
- This was raised in the prior review body; treating it as informational since it is a doc-only polish and does not block merge.

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

@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

  • Routed the two config specs newly added to the Windows lane through the retrying teardown helper: electron-builder-runtime-resources.test.mjs now awaits removeTree(...) and windows-process-tree-gyp-rebuild.test.mjs calls removeTreeSync(...), both from src/shared/windows-transient-lock-removal.ts, satisfying the windows-lane-tree-removal-boundary ratchet.
  • Dropped the now-unused rm/rmSync imports in those two files.

The other two specs added to the same lane (windows-process-tree-gyp-path.test.mjs, package-electron-runtime-contract.test.mjs) contain no raw recursive removals, so the lane is clean. The ratchet and both edited specs pass locally (30 passed, 1 win-only skipped).

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

electron-builder only logs a warning for a missing extraResources source,
so a host-only install silently shipped a foreign-arch slice without its
natives — `pnpm build:mac` on Apple Silicon produced an x64 DMG with no
sherpa-onnx-darwin-x64 and no @parcel/watcher-darwin-x64. The previous
beforePack hook covered only win32.

- Add assertPackagedNativeVariantsInstalled, an arch-aware check over the
  target's sherpa-onnx, @parcel/watcher, and (on Windows) node-gyp addons.
  beforePack now runs it for every platform, with remedies split: another
  architecture comes from install:release, the os:win32 addons need a
  Windows host.
- Drop --os from the release installs. Every packaging job already runs on
  a runner whose OS matches its target, so only the macOS lanes need extra
  breadth, and only on CPU for their x64+arm64 config. Windows and Linux
  packaging return to a plain host-only install.
- Add --frozen-lockfile to install:release so a bare run cannot rewrite
  the lockfile.
- Restore the install policy reference doc and the CONTRIBUTING note, plus
  the rationale comments dropped from the runtime contract test.
- Gate the packaging-closure assertions on whether the Windows addons are
  installed rather than on the host OS, so a cross-arch install exercises
  them off Windows too.
- Make the workflow contract test read `run:` steps as well as retry-action
  commands, and enforce host-only scoping on the non-macOS packaging lanes.
- Remove the unreferenced install measurement script; its numbers live in
  the policy doc.
docs/** is ignored behind a per-file allow-list, so the new reference doc
was only committed via git add -f and future edits would be skipped. Add
it to the allow-list and give it an AGENTS.md entry like every other
tracked reference doc, so the host-only install rule is discoverable
before someone packages a second architecture.
Adding these four specs to the PR Windows lane pulled them into the
windows-lane-tree-removal-boundary ratchet, which failed on 20 raw
recursive removals. On Windows a bare rmSync races a handle the OS has
not released, throwing EPERM after the assertions already passed and
reporting a green test as a lane failure.
main vendored windows-native-registry as the workspace package
@orca/windows-registry (#20438). A workspace link resolves on every
host, so including it in the installed-Windows-addons checks proved
nothing. @vscode/windows-process-tree is the only os: win32 npm addon
left, so it alone decides whether the win32 resource plan resolves.
@nwparker
nwparker force-pushed the nwparker/pnpm-native branch from 23be43e to a63c839 Compare September 13, 2026 03:47

@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

  • Adapted the cross-arch packaging guard to main vendoring the Windows registry addon (#20438): the win32 check in assertPackagedNativeVariantsInstalled now requires only @vscode/windows-process-tree, replacing the stale unscoped windows-native-registry name that no longer resolves.
  • Narrowed the config-load gate for win.extraResources and the windowsAddonsInstalled test gate in electron-builder-runtime-resources.test.mjs to the same single package, since the @orca/windows-registry workspace link resolves on every host and proved nothing.
  • Updated docs/reference/pnpm-install-policy.md to explain why the guard checks one package.

The old unscoped name would have failed every Windows package after the vendoring, so this is a necessary fix rather than a new risk. @orca/windows-registry's binding.gyp declares OS!='win' → type none, confirming off-Windows installs link the package but compile no binary, so the doc's "compiled only on Windows" claim holds. Focused tests pass locally (74 passed across electron-builder-config, electron-builder-runtime-resources, package-electron-runtime-contract).

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

@nwparker
nwparker merged commit e86cba8 into main Sep 13, 2026
35 checks passed
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