mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00: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
(cherry picked from commit 1cfc5f29a0)
33 lines
845 B
JavaScript
33 lines
845 B
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @noflow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
// Inside the React Native monorepo, we need to explicitly extend the base
|
|
// CLI config as the adjacent package will not be conventionally discovered.
|
|
const config = require('../react-native/react-native.config.js');
|
|
|
|
module.exports = {
|
|
...config,
|
|
reactNativePath: '../react-native',
|
|
project: {
|
|
ios: {
|
|
sourceDir: '.',
|
|
},
|
|
android: {
|
|
sourceDir: '../../',
|
|
// To remove once the CLI fix for manifestPath search path is landed.
|
|
manifestPath:
|
|
'packages/rn-tester/android/app/src/main/AndroidManifest.xml',
|
|
packageName: 'com.facebook.react.uiapp',
|
|
},
|
|
},
|
|
};
|