Fix .js/.node precedence in isNodeApiModule; dedupe Info.plist checks (builds on #426) - #450
Closed
kraenhansen wants to merge 3 commits into
Closed
Fix .js/.node precedence in isNodeApiModule; dedupe Info.plist checks (builds on #426)#450kraenhansen wants to merge 3 commits into
kraenhansen wants to merge 3 commits into
Conversation
- Replace the Babel-transform-time require.resolve() guard with a check inside isNodeApiModule itself, so the fix lives in the shared utility (also used by findNodeAddonForBindings) instead of duplicating Node's module resolution algorithm via a second, independent code path that could diverge from what Metro actually resolves at runtime. - Verify the Info.plist contents with a zod schema instead of ad hoc "in" checks on an untyped object, matching how the rest of the repo validates untrusted structured data. - Reuse the exported escapeBundleIdentifier instead of re-deriving the bundle-identifier escaping regex inline in the verify script, so the two can't silently drift apart. Closes #424 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q1k6UQJPPaqKEKmnsRUatt
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q1k6UQJPPaqKEKmnsRUatt
Collaborator
Author
|
Closing as I pushed to #426 instead. |
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.
Summary
This builds directly on @wanxiankai's #426 (branch
fix/verify-prebuild-fixtures, included here as the first commit) with a few refinements on top. It closes #424, superseding #448 and #449 (two independent attempts at the same fix, opened before this one was aware #426 already existed).What's on top of #426
.js/.nodeprecedence fix intoisNodeApiModule(packages/host/src/node/path-utils.ts) instead of guarding the Babel plugin'srequire()rewrite withcreateRequire(this.filename).resolve(id). Reasons:isNodeApiModuleis the shared utility (also used byfindNodeAddonForBindings), so fixing it there benefits every caller instead of only the plugin'srequire()handling.createRequire(...).resolve()runs Node's own CommonJS resolution algorithm at Babel-transform time to predict what React Native's Metro bundler will resolve at runtime — but Metro doesn't use Node's resolver (it has its own, with platform extensions, Haste, etc.), so the two can diverge. Checking for a same-named.js/.cjs/.mjs/.jsonsibling file directly is simpler and doesn't depend on that assumption holding.Info.plistwith azodschema instead of ad hoc"key" in objchecks on anunknownvalue, matching how the rest of the codebase validates untrusted structured data (zodis already a dependency across several packages).escapeBundleIdentifier(now re-exported fromreact-native-node-api'snodeentrypoint) instead of re-deriving the bundle-identifier escaping regex inline inverify-prebuilds.mts, so the verifier can't silently drift out of sync with whatwriteFrameworkInfoPlistactually writes.Test plan
pnpm install && pnpm run build— cleanpnpm --filter react-native-node-api test— theplugin,isNodeApiModule, andescapeBundleIdentifiersuites pass; the only failures are 4 pre-existing permission-based tests that fail identically with and without this diff (confirmed viagit stash) because this sandbox runs as rootpnpm exec tsc --build packages/node-addon-examples/tsconfig.node-scripts.json— clean (type-checksverify-prebuilds.mts)pnpm exec eslinton all changed files — cleanpnpm run prettier:check— cleanCloses #424
cc @kraenhansen for review.
🤖 Generated with Claude Code
Generated by Claude Code