Skip to content

Preserve bundled npm dependencies in desktop packages - #3587

Closed
aulneau wants to merge 1 commit into
get-bb:mainfrom
aulneau:fix-desktop-bundled-npm
Closed

aulneau wants to merge 1 commit into
get-bb:mainfrom
aulneau:fix-desktop-bundled-npm

Conversation

@aulneau

@aulneau aulneau commented Sep 12, 2026

Copy link
Copy Markdown

Human comments

What was wrong

Desktop 0.43.0 switched plugin installs to bundled npm 11.16.0 in #3529, but the Electron artifact omitted npm's nested dependency tree. pnpm reports npm without child dependencies, while electron-builder's dependency copier excludes nested node_modules. The installed macOS app fails even on npm --version with exit 7 and Cannot find module 'proc-log'; 60 of npm's 65 direct dependencies cannot resolve. The existing npm check only covered the bb-app tarball, and desktop smoke only exercised the preload/window path.

What changed

Copy npm's nested dependency tree through an explicit desktop file set, preserving it in ASAR/unpacked resources before signing. Run an offline install check through the packaged Electron executable with an empty PATH, a fresh npm cache/config, and lifecycle scripts disabled. Invoke the check in afterPack so packaging fails before signing or uploading artifacts, and repeat it in packaged desktop smoke. Document how to run the npm check without opening a window.

No server/daemon wire, SDK, CLI, or user configuration changes.

How you verified

  • Reproduced the exact exit-7 proc-log error using the installed 0.43.0 app's Electron executable and bundled npm.
  • Built a real macOS arm64 desktop artifact using the pnpm collector and the updated file set. The afterPack check printed Packaged npm 11.16.0 installed a dependency with an empty PATH. Packaging completed successfully; the standalone check also passed.
  • Built again with a temporary configuration removing only the new file set. The new afterPack check failed with Cannot find module 'proc-log', stopping packaging before signing. Production source configuration was unchanged by this negative control.
  • pnpm exec turbo run build typecheck test --filter=@bb/desktop: 52 tasks succeeded; 320 desktop tests passed, 1 skipped. The first sandboxed attempt aborted Electron startup; the desktop-enabled rerun passed.
  • After the hook change, pnpm exec turbo run test --filter=@bb/desktop -- --run test/electron-builder-config.test.ts: 22 tests passed.
  • Formatting and git diff --check passed.
  • Local artifacts were unsigned and never published or installed. Linux execution and signed-release verification remain for CI. The full packaged GUI smoke was not rerun after the user asked to avoid more test windows; the npm check runs entirely in Node mode.

AGENT GENERATED

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @aulneau for the PR. This repo needs approval before a PR. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ) and explain what you want to open a PR for and why. A maintainer then adds you to the allow list. This PR now closes on its own. Reopen it or open a new one after approval.

@github-actions github-actions Bot closed this Sep 12, 2026
SawyerHood added a commit that referenced this pull request Sep 12, 2026
## Human comments

## What was wrong

Desktop 0.43.0 ships npm 11.16.0 without its bundled dependencies.
Electron-builder's pnpm collector treats npm as a leaf, and its
dependency copier excludes nested `node_modules`. Source builds and the
separate bb-app tarball smoke pass, while packaged npm exits 7 with
missing `proc-log` and cannot install or update plugin dependencies.

## What changed

Preserve npm's complete nested dependency tree through an explicit
shared electron-builder file set, before signing. The same file-set
approach was proposed in closed, unmerged #3587.

Gate native-host packaging in `afterPack` on an artifact smoke test, and
repeat it in packaged desktop smoke. The test runs the shipped npm
through bundled Electron with an empty PATH and isolated
HOME/cache/config. It audits required CJS/ESM dependency resolution and
version ranges, imports ESM dependencies, and performs an offline
disposable plugin dependency install and update from 1.0.0 to 2.0.0.
Lockfile contents and actual ESM imports verify both operations;
resource hashes reject bundle mutations. Document standalone npm smoke
and add Turbo prerequisites for local packaging.

No server/daemon wire or public SDK changes.

## How you verified

- On a MacBook Air, both a freshly downloaded signed macOS 0.43.0
release and current-main packaged output lacked 60/65 direct npm
dependencies and exited 7 through their own Electron runtime with no
executables on PATH.
- Fixed real macOS arm64 packaging passes: all 65 direct dependencies,
144 packages including npm, and 348 required CJS/ESM dependency edges.
Offline install/update succeeds and resources remain unchanged. An ad
hoc signed disposable copy still passes strict codesign verification
afterward.
- Negative controls reject removal of the new file set during real
packaging, a missing Chalk ESM implementation file, and a nested
dependency omission that resolves an incompatible minipass version.
- `pnpm exec turbo run package --filter=@bb/desktop`: passed, including
the pre-signing npm gate.
- `pnpm exec turbo run typecheck test --filter=@bb/desktop`: passed; 322
tests passed, 1 existing skip. The sandbox initially aborted the
existing Electron preload test; the macOS-process-enabled rerun passed.
- Formatting, `git diff --check`, and the public-content scan passed.
- The reported self-repair was not reproduced on the shipped
dependency-install path: two attempts failed, all 9,225 release bundle
files remained unchanged, and strict codesign verification still passed.

Independent Linux verification on x86_64/glibc 2.44 at commit
`1d1ec370a90d53d97dc76d5b3998368ecf8aba88`:

- A freshly downloaded official 0.43.0 AppImage reproduces 60/65 missing
dependencies and exit 7 for both version and real offline
dependency-install commands through bundled Electron with an empty PATH.
A repeated install also fails without changing resource hashes; no
self-repair was observed.
- Real Turbo Linux packaging and the final **extracted AppImage
executable** pass all 65 direct dependency, 144 package, and 348 CJS/ESM
dependency-edge checks, including version ranges, offline
install/update, and unchanged resources. Final AppImage SHA256:
`f17e6bf79d3a26b92b6ce26ad2825b81fb5541a1a3d361cc60188d2a3c31024d`.
- Extracted AppImage GUI preload smoke passes under disposable Xvfb; the
official-release baseline passes too.
- Both artifact negative controls fail as intended: missing Chalk ESM
implementation and missing nested minipass dependencies with an
incompatible fallback version.
- Turbo typecheck passes; 322 desktop tests and 81 bb-app tests pass,
with one existing desktop skip. No PR-caused defects or source changes
were needed.

Limitations: Linux AppImage FUSE lifecycle testing is blocked
identically before and after (exit 127; host lacks `/dev/fuse` and
`fusermount`); extracted-artifact checks above pass. macOS packaged GUI
readiness timed out on both before and after artifacts. Developer ID
signing/notarization and full Extensions UI activation were not tested.
The new runtime gate requires a native target host. All verification
used disposable artifacts and fixtures; no installed production app or
store was modified.

Fixes #3566
Fixes #3581
Fixes #3584

> AGENT GENERATED
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