fix(build): install all platform keyring bindings for cross-compile#198
fix(build): install all platform keyring bindings for cross-compile#198
Conversation
Cross-compile runs on a Linux host, which by default skips @napi-rs/keyring optional deps for darwin and win32. Without those bindings present at bundle time, Bun rewrites the require calls to throw stubs, so every non-Linux binary silently fell back to plaintext-file credential storage at runtime. Pass --cpu='*' --os='*' to bun install in the build workflow so every target's native binding is resolvable when the bundler runs, and add a preflight check in scripts/build.ts that fails fast with the fix command if the bindings are still missing.
|
Stack: wyattjoh/fix-keyring-cross-compile Part of a stacked PR chain. Do not merge manually. |
🦋 Changeset detectedLatest commit: ddaa8a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis pull request addresses cross-compilation issues for the clerk CLI's native Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Summary
Cross-compiled macOS and Windows CLI binaries were silently falling back to plaintext-file credential storage instead of using the OS keychain.
Root cause: the build runs on a Linux CI host. Default
bun installskips@napi-rs/keyringoptional deps whoseosorcpufield doesn't match the host, so the darwin and win32 bindings are not innode_moduleswhen the cross-compile runs. Bun then rewrites the unresolvedrequire()calls to throw stubs and the bundle ships without the native binding. At runtime, theimport()fails, the catch swallows the error, and the CLI falls back to~/Library/Application Support/clerk-cli/credentials(chmod 600).Fix
bun install --frozen-lockfile --cpu='*' --os='*'in.github/workflows/build-binaries.ymlso every target's binding is installed before the Linux host bundles each target.scripts/build.tsso localbuild:compile:allruns on a developer Mac also fail fast with the install command if a required binding is missing.Lockfile unchanged;
--frozen-lockfilestill holds.Test plan
ubuntu:24.04+ Bun 1.3.11 container matching CI, then applied the fix and confirmed every target bundle embeds its platform's native.nodeasset.darwin-arm64binary onto a Mac, signed with a real Team ID +scripts/entitlements.plist, and confirmedclerk whoami --verbosereportsfound token in keyring.scripts/build.ts; preflight check fired with the expected error and install hint.bun run format:check,bun run lint,bun run typecheck,bun run testall pass.