fix: verify prebuild Info.plist and prove the Babel plugin's .js/.node precedence (#424) - #449
Closed
kraenhansen wants to merge 2 commits into
Closed
fix: verify prebuild Info.plist and prove the Babel plugin's .js/.node precedence (#424)#449kraenhansen wants to merge 2 commits into
kraenhansen wants to merge 2 commits into
Conversation
…de fixture Closes #424. - verify-prebuilds.mts now reads the Info.plist it finds inside each .framework, asserting CFBundleExecutable matches the framework's library name and CFBundleIdentifier matches the default writeFrameworkInfoPlist derives (com.callstackincubator.node-api.<libraryName>, escaped), since none of the examples pass --apple-bundle-identifier. escapeBundleIdentifier is now exported from react-native-node-api's node entrypoint so the verifier (a consumer of the package, like any addon author) can reuse it. - The babel plugin's "does not touch required JS files" test now includes a sibling my-addon.apple.node/my-addon.node fixture alongside my-addon.js, per the TODO. That exposed a real bug: isNodeApiModule didn't check whether a same-named .js/.cjs/.mjs/.json file would already satisfy require() before considering .node prebuilds, so the plugin rewrote calls Node's own resolution would never route to the addon. Fixed by deferring to a colliding source file when the module path has no explicit .node extension. 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 this in favor of #450, which builds on @wanxiankai's earlier #426 (the first PR to fix #424) plus the improvements this PR made (moving the fix into Generated by Claude Code |
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 #424.
verify-prebuildsnow reads theInfo.plistit findsverifyApplePrebuildused tocontinuepastInfo.plistwithout reading it. It now parses it with@expo/plist(already a dependency elsewhere in the repo) and asserts, via a smallverifyFrameworkInfoPlisthelper:CFBundleExecutablematches the framework's library name (the.frameworkdirectory's basename)CFBundleIdentifiermatchesescapeBundleIdentifier("com.callstackincubator.node-api." + libraryName)— the defaultwriteFrameworkInfoPlist(packages/host/src/node/prebuilds/apple.ts) writes when no--apple-bundle-identifieris passed, which is hownode-addon-examplesbuildsescapeBundleIdentifieris now exported fromreact-native-node-api's publicnodeentrypoint so the verify script (a consumer of the package, like any addon author) can import it rather than re-deriving the escaping rule. The parsed plist is validated with azodschema rather than accessed asany, matching how the rest of the codebase validates untrusted structured data.Note on the
@expo/plistimport: it's a CJS package with anexport default.verify-prebuilds.mtsis genuine ESM (.mts), so Node's real CJS/ESM interop binds the default import to the wholemodule.exports, nesting the actual{ parse, build }API one.defaultdeeper — confirmed empirically against Node's own module loader, and againsttsx(the runner this script actually uses), not just againsttsc.The Babel plugin test now proves its own claim — and that found a real bug
"and does not touch required JS files" asserted the plugin leaves
require('./my-addon')alone, but the fixture had nomy-addon.*.nodefor the plugin to have found in the first place — the assertion passed for the wrong reason. Adding a siblingmy-addon.apple.node/my-addon.node(as theTODOasked, following the same fixture pattern used by every other test in the file) makes the test exercise real precedence between a.jsfile and a same-named addon, and it failed:isNodeApiModuledidn't check whether a same-named.js/.cjs/.mjs/.jsonfile would already satisfyrequire()before considering.nodeprebuilds, so the plugin rewrote a call that Node's own resolution would never route to the addon.Fixed
isNodeApiModuleto defer to a colliding source file when the module path has no explicit.nodeextension, matching Node's own resolution order (.js/.jsonbefore.node). Explicitrequire('./my-addon.node')calls are untouched by this check, since there's no resolution ambiguity to defer to.Verification
pnpm run build,pnpm run lint,pnpm run prettier:checkall cleanpackages/host's full test suite: only the same 4 permission-based tests fail, and they fail identically onnextbefore this change (this sandbox runs as root, so permission-removal tests can't produce the expected effect) — no new failuresverifyFrameworkInfoPlistlogic (both match and mismatch-detection paths) against a realInfo.plistwritten bycreateAppleFramework, run both directly withnodeand throughtsx(the actual runnerverify-prebuilds.mtsuses) —install_name_toolisn't available on Linux, so the check reads the file right after it's written, before that stepreact-native-node-api(theisNodeApiModulefix + new export); none needed fornode-addon-examples, which is privatecc @kraenhansen for review.
🤖 Generated with Claude Code
Generated by Claude Code