mirror of
https://github.com/react/react-native.git
synced 2026-09-28 05:13:06 +08:00
Summary: An autolinked library's SwiftPM target name is also its header import prefix, so deriving it from the npm package name was wrong for most of the ecosystem (`react-native-svg` publishes `RNSVG`, not `ReactNativeSvg`) and wrong silently — no error, just headers nobody can import under the expected name. ## How: This PR reads the podspec file on scaffolding, and will use the name from the podspec if available. In addition it deprecates the react-native.config.js `spm` section in favor of the library's `package.json` file. ### Configuration A package's SwiftPM settings now live in `swiftpmConfig` in its `package.json`, following `codegenConfig`'s conventions: `name`, `dependencies`, `autolinkingPlugin` and `scaffold` for a library, `modules` and `denyPlugins` for an app. The `spm` block in react-native.config.js is deprecated — still read, so nothing breaks, but it warns once per file and package.json wins field by field. ### Resolving A name resolves from `swiftpmConfig.name`, then the deprecated `spm.name`, then the podspec's `header_dir` or name, then the npm name. The podspec is thereby transitional rather than permanent: `spm scaffold` records the name it derived as `swiftpmConfig.name` in the library's package.json, so the next run needs no podspec to name it. It never overwrites a name the library already declares, never records a name guessed from the npm name, and reports what it did. ### Failsafety A prefix Swift cannot spell is normalized to the identifier SwiftPM would compile it as, with a warning. A reserved name or two deps landing on one name is a hard error naming swiftpmConfig.name as the fix; the scope-borrowing that auto-corrected collisions is removed, since a name the build invents is a name no #import can predict. Collision checks key on SwiftPM's c99 name, so react-native-svg and react_native_svg no longer pass and then compile as one module. ### Implementation Name resolution reads the two podspec fields it needs with the regex parser, so it adds no `pod ipc spec` spawn, and the full read is memoized on the resolved path so one run reads a podspec once across name resolution, header search paths and scaffolding. `rn-tester` and the Apple test library move to the new location. ## Changelog: [IOS] [FIXED] - Read SwiftPM name from podspec and store in package.json when scaffolding Pull Request resolved: https://github.com/react/react-native/pull/58290 Test Plan: ✅ Unit tests Reviewed By: cortinico Differential Revision: D119159904 Pulled By: cipolleschi fbshipit-source-id: 59a7c62ecb601498060a5721f362dae8c5cc92de
28 lines
702 B
JSON
28 lines
702 B
JSON
{
|
|
"name": "react-native-test-library-common",
|
|
"version": "0.87.0-main",
|
|
"description": "Shared JS utilities consumed by react-native-test-library-apple. Used as a fixture for validating autolinking discovery and transitive native dependency resolution in the React Native monorepo.",
|
|
"private": true,
|
|
"main": "index.js",
|
|
"types": "index.d.ts",
|
|
"license": "MIT",
|
|
"files": [
|
|
"index.js",
|
|
"index.d.ts",
|
|
"react-native.config.js",
|
|
"TestLibraryCommon.podspec",
|
|
"TestLibraryCommon.h",
|
|
"TestLibraryCommon.mm"
|
|
],
|
|
"keywords": [
|
|
"react-native",
|
|
"fixture",
|
|
"autolinking",
|
|
"ios",
|
|
"macos"
|
|
],
|
|
"swiftpmConfig": {
|
|
"name": "TestLibraryCommon"
|
|
}
|
|
}
|