fix(build): bundle both macOS architectures of esbuild's native binary#463
Open
devrosx wants to merge 1 commit into
Open
fix(build): bundle both macOS architectures of esbuild's native binary#463devrosx wants to merge 1 commit into
devrosx wants to merge 1 commit into
Conversation
Closes SuperCmdLabs#462 esbuild's native binary is delivered via optional dependencies that npm resolves to the build host's architecture only. Building on Apple Silicon populates node_modules/@esbuild/ with darwin-arm64 alone; electron-builder then packs the same node_modules into both the x64 and arm64 DMGs, so the x64 DMG ships an unusable arm64 binary. Every extension whose on-demand build invokes esbuild fails on Intel/Rosetta with: You installed esbuild for another platform than the one you're currently using. ... the "@esbuild/darwin-arm64" package is present but this platform needs the "@esbuild/darwin-x64" package instead. The same issue affects the nested esbuild copy under @raycast/api. Changes: - Pin @esbuild/darwin-x64 and @esbuild/darwin-arm64 at 0.19.12 (matching the top-level esbuild) so npm install always brings them in. - Add scripts/ensure-cross-arch-esbuild.mjs, run from postinstall, which walks every esbuild folder in node_modules (handles the nested @raycast/api copy at its own version) and drops in any missing macOS platform binary via npm pack. Idempotent and a no-op outside macOS. Tested by reproducing the failure on macOS x86_64 with SuperCmd 1.0.25 and verifying both binaries land in node_modules after install.
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.
Closes #462
Problem
esbuild ships its native binary via
optionalDependencies(@esbuild/darwin-x64,@esbuild/darwin-arm64, …) — npm only installs the one matching the build host's architecture. The published x64 SuperCmd DMG is built on an Apple Silicon machine, sonode_modules/@esbuild/contains onlydarwin-arm64. electron-builder packs that samenode_modules/into both DMGs, so the x64 DMG ships an arm64 binary that it can't execute.Every extension whose on-demand build invokes esbuild then fails on Intel/Rosetta Macs with the misleading message:
The same problem exists for the nested esbuild copy under
@raycast/api(a different version: 0.25.12 vs the top-level 0.19.12).Confirmed by inspecting a packaged 1.0.25 build:
Fix
Two-part, both small:
Pin both platform packages explicitly in
package.jsonso npm always installs them for the top-level esbuild regardless of the build host:Add
scripts/ensure-cross-arch-esbuild.mjs(run frompostinstall) which walks everyesbuildfolder it finds innode_modules(handles nested copies like@raycast/api/node_modules/esbuildat their own version) andnpm packs the missing@esbuild/darwin-*sibling at the matching version. Idempotent, runs only on macOS, no-op when nothing is missing.The script handles future esbuild version drift (e.g. when
@raycast/apibumps its esbuild dependency) without needing a correspondingpackage.jsonchange.Verification
Reproduced the original failure with SuperCmd 1.0.25 on macOS 13.6 x86_64 (issue #462).
Local smoke test of the script:
Alternatives considered
^0.25.xto deduplicate with@raycast/api's copy. Reduces the number of esbuild instances but is a larger functional change and doesn't itself fix the cross-arch problem.