Repository navigation
fix(electron): drop packages the target platform cannot run - #48
Merged
Merged
Conversation
`@reflink/reflink` declares eight platform siblings as optional dependencies and the installer places whichever matches the machine running the install. That machine is not the target. Read off the packaged bundle built here, a `--platform=win32` build would carry `@reflink/reflink-darwin-arm64` -- a Mach-O `.node` in a Windows application -- and a `darwin-x64` build would carry it too, an arm64 binary in an x64 bundle. It arrives three optional dependencies below anything this package imports: `node-llama-cpp` -> `ipull` -> `@reflink/reflink`. Nothing named it, and the two prune hooks that already existed each know one scope by name. What this is NOT: a bundle observed in the wild. On a mismatched target `pruneLlamaBackends` throws first, because only the host's `@node-llama-cpp` package is installed and its plan then keeps nothing. So the wrong-platform copy is masked today by an unrelated hook erroring earlier, which is an accident rather than a property. A cross build could not be run here to see past it: the Electron download for win32 times out from this network. `platformPackagePlan` reads the `os` and `cpu` fields npm publishes, so it needs no knowledge of any package and covers the next one without an edit. It implements npm's actual rule rather than list membership: a list may EXCLUDE, written `!win32`, and one made only of exclusions admits everything it does not name. Reading `"os": ["!win32"]` as an allow-list would drop that package from every build. `mas` is treated as darwin, and a universal build keeps a package either slice needs -- both of which a single-value comparison gets wrong by dropping native code from a bundle that builds cleanly. Three places, one function. `forge.config.ts` deletes what the plan drops, last of the three hooks so the two that throw on a layout change report first. `verify-package.mjs` stops expecting what was dropped, and adds the half that a prune doing nothing would still pass: every packed manifest is read back off the archive and asserted to admit the target. That is 189 of them, against 162 closure placements, so it judges what the copy placed as well as what the closure named. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's in the closure
@reflink/reflinkdeclares eight platform siblings as optional dependencies. The installer places whichever one matches the machine running the install — and that machine is not the target.Read off the bundle actually built here (189 packed manifests), running the new plan against four targets:
darwin-arm64darwin-x64@reflink/reflink-darwin-arm64— declares cpu arm64, not x64win32-x64@node-llama-cpp/mac-arm64-metal,@reflink/reflink-darwin-arm64linux-x64@node-llama-cpp/mac-arm64-metal,@reflink/reflink-darwin-arm64@reflink/reflink-darwin-arm64is a Mach-O.node. It reaches the closure three optional dependencies below anything this package imports:node-llama-cpp→ipull→@reflink/reflink. Nothing named it, because the two prune hooks that already existed each know one scope by name.What this is not
I did not observe a foreign bundle ship. On a mismatched target
pruneLlamaBackendsthrows first — only the host's@node-llama-cpppackage is installed, so its plan keeps nothing and the build dies with@node-llama-cpp ships nothing usable by win32-x64. The wrong-platform copy is masked today by an unrelated hook erroring earlier, which is an accident rather than a property.I could not get past it to see the real thing: the Electron binary download for win32 times out from this network. So the table above is the plan evaluated against the real closure, not a bundle I unpacked.
That makes this hardening plus a new assertion, not a fix for a bug caught in the act. Worth having on both counts, but I'd rather label it accurately.
The rule
platformPackagePlanreads theosandcpufields npm publishes, so it needs no knowledge of any package and covers the next one without an edit.llamaPackagePlanis the same rule written for one scope by parsing its names.It implements npm's actual semantics rather than list membership:
!win32"os": ["!win32"]as an allow-list would drop that package from every buildanymatches everything; a bare string is a list of onemasis a darwin buildThe last two are single-value comparisons that would drop native code from a bundle that still builds cleanly.
Three places, one function
forge.config.tsdeletes what the plan drops — last of the three hooks, so the two that throw on an upstream layout change report first and this stays a backstop rather than removing what they came to inspect.verify-package.mjsstops expecting what the build dropped (otherwise a correct prune fails the check), and adds the half a prune that silently did nothing would still pass: every packed manifest is read back off the archive and asserted to admit the target. 189 of them against 162 closure placements, so it judges what the copy placed as well as what the closure named.tests/platform-packages.test.ts— 17 cases over the plan and the matcher.Verification
vitest run: 1141 passed, 68 files.tsc --noEmitclean.eslint .clean.verify:package:all 162 closure placements this target runs are packed,189 packed manifest(s) were read,all 189 packed package(s) run on darwin-arm64. Nothing is dropped on this target, which is the correct answer for it.