@@ -19,9 +19,6 @@ import {
1919 appManifest ,
2020 buildGradle ,
2121 podfile ,
22- reactNativeConfigAndroidFlat ,
23- reactNativeConfigAppleFlat ,
24- reactNativeConfigWindowsFlat ,
2522 serialize ,
2623 settingsGradle ,
2724} from "./template.mjs" ;
@@ -120,6 +117,46 @@ export function sortByKeys(obj) {
120117 } , /** @type {Record<string, unknown> } */ ( { } ) ) ;
121118}
122119
120+ /**
121+ * @param {string | string[] } input
122+ * @returns {Platform[] }
123+ */
124+ export function validatePlatforms ( input ) {
125+ const platforms = Array . isArray ( input ) ? input : [ input ] ;
126+
127+ let includesApplePlatforms = false ;
128+ let includesIOS = false ;
129+
130+ for ( const p of platforms ) {
131+ switch ( p ) {
132+ case "ios" :
133+ includesIOS = true ;
134+ break ;
135+
136+ case "macos" :
137+ case "visionos" :
138+ includesApplePlatforms = true ;
139+ break ;
140+
141+ case "android" :
142+ case "windows" :
143+ break ;
144+
145+ default :
146+ throw new Error ( `Unknown platform: ${ p } ` ) ;
147+ }
148+ }
149+
150+ // Autolinking currently assumes that `ios` is always present:
151+ // https://github.com/facebook/react-native/blob/0.76-stable/packages/react-native/scripts/cocoapods/autolinking.rb#L41
152+ // We need to include iOS if we want to target other Apple platforms.
153+ if ( includesApplePlatforms && ! includesIOS ) {
154+ platforms . push ( "ios" ) ;
155+ }
156+
157+ return /** @type {Platform[] } */ ( platforms ) ;
158+ }
159+
123160/**
124161 * Prints a warning message to the console.
125162 * @param {string } message
@@ -182,29 +219,7 @@ export function getPlatformPackage(platform, targetVersion) {
182219 * @param {ConfigureParams } params
183220 * @returns {string | FileCopy }
184221 */
185- export function reactNativeConfig (
186- { name, testAppPath, platforms, flatten } ,
187- fs = nodefs
188- ) {
189- const shouldFlatten = flatten && platforms . length === 1 ;
190- if ( shouldFlatten ) {
191- switch ( platforms [ 0 ] ) {
192- case "android" :
193- return reactNativeConfigAndroidFlat ( ) ;
194-
195- case "ios" :
196- case "macos" :
197- case "visionos" :
198- return reactNativeConfigAppleFlat ( ) ;
199-
200- case "windows" :
201- return reactNativeConfigWindowsFlat ( name ) ;
202-
203- default :
204- throw new Error ( `Unknown platform: ${ platforms [ 0 ] } ` ) ;
205- }
206- }
207-
222+ export function reactNativeConfig ( { name, testAppPath } , fs = nodefs ) {
208223 const config = path . join ( testAppPath , "example" , "react-native.config.js" ) ;
209224 return readTextFile ( config , fs ) . replaceAll ( "Example" , name ) ;
210225}
@@ -235,8 +250,7 @@ export const getConfig = (() => {
235250 fs = nodefs
236251 ) => {
237252 if ( disableCache || typeof configuration === "undefined" ) {
238- const { name, templatePath, testAppPath, targetVersion, flatten, init } =
239- params ;
253+ const { name, templatePath, testAppPath, targetVersion, init } = params ;
240254
241255 // `.gitignore` files are only renamed when published.
242256 const gitignore = [ "_gitignore" , ".gitignore" ] . find ( ( filename ) => {
@@ -431,7 +445,7 @@ export const getConfig = (() => {
431445 scripts : {
432446 "build:windows" :
433447 "npm run mkdist && react-native bundle --entry-file index.js --platform windows --dev true --bundle-output dist/main.windows.bundle --assets-dest dist" ,
434- windows : ` react-native run-windows --sln ${ flatten ? "" : "windows/" } ${ name } .sln` ,
448+ windows : " react-native run-windows" ,
435449 } ,
436450 dependencies : { } ,
437451 } ,
@@ -447,13 +461,11 @@ export const getConfig = (() => {
447461 * @returns Configuration
448462 */
449463export function gatherConfig ( params , disableCache = false ) {
450- const { flatten, platforms, targetVersion } = params ;
451- const shouldFlatten = flatten && platforms . length === 1 ;
452- const options = { ...params , flatten : shouldFlatten } ;
464+ const { platforms, targetVersion } = params ;
453465 const config = ( ( ) => {
454466 return platforms . reduce (
455467 ( config , platform ) => {
456- const platformConfig = getConfig ( options , platform , disableCache ) ;
468+ const platformConfig = getConfig ( params , platform , disableCache ) ;
457469 const dependencies = getPlatformPackage ( platform , targetVersion ) ;
458470 if ( ! dependencies ) {
459471 /* node:coverage ignore next */
@@ -463,23 +475,17 @@ export function gatherConfig(params, disableCache = false) {
463475 return mergeConfig ( config , {
464476 ...platformConfig ,
465477 dependencies,
466- files : shouldFlatten
467- ? platformConfig . files
468- : Object . fromEntries (
469- // Map each file into its platform specific folder, e.g.
470- // `Podfile` -> `ios/Podfile`
471- Object . entries ( platformConfig . files ) . map (
472- ( [ filename , content ] ) => [
473- path . join ( platform , filename ) ,
474- content ,
475- ]
476- )
477- ) ,
478- oldFiles : shouldFlatten
479- ? platformConfig . oldFiles
480- : platformConfig . oldFiles . map ( ( file ) => {
481- return path . join ( platform , file ) ;
482- } ) ,
478+ files : Object . fromEntries (
479+ // Map each file into its platform specific folder, e.g.
480+ // `Podfile` -> `ios/Podfile`
481+ Object . entries ( platformConfig . files ) . map ( ( [ filename , content ] ) => [
482+ path . join ( platform , filename ) ,
483+ content ,
484+ ] )
485+ ) ,
486+ oldFiles : platformConfig . oldFiles . map ( ( file ) => {
487+ return path . join ( platform , file ) ;
488+ } ) ,
483489 } ) ;
484490 } ,
485491 /** @type {Configuration } */ ( {
@@ -500,7 +506,7 @@ export function gatherConfig(params, disableCache = false) {
500506 return config ;
501507 }
502508
503- return mergeConfig ( getConfig ( options , "common" , disableCache ) , config ) ;
509+ return mergeConfig ( getConfig ( params , "common" , disableCache ) , config ) ;
504510}
505511
506512/**
@@ -696,33 +702,9 @@ if (isMain(import.meta.url)) {
696702 const platformChoices = [ "android" , "ios" , "macos" , "windows" ] ;
697703 const defaultPlatforms = platformChoices . join ( ", " ) ;
698704
699- /** @type {(input: string | string[]) => Platform[] } */
700- const validatePlatforms = ( input ) => {
701- const platforms = Array . isArray ( input ) ? input : [ input ] ;
702- for ( const p of platforms ) {
703- switch ( p ) {
704- case "android" :
705- case "ios" :
706- case "macos" :
707- case "visionos" :
708- case "windows" :
709- break ;
710- default :
711- throw new Error ( `Unknown platform: ${ p } ` ) ;
712- }
713- }
714- return /** @type {Platform[] } */ ( platforms ) ;
715- } ;
716-
717705 parseArgs (
718706 "Configures React Test App in an existing package" ,
719707 {
720- flatten : {
721- description :
722- "Flatten the directory structure (when only one platform is selected)" ,
723- type : "boolean" ,
724- default : false ,
725- } ,
726708 force : {
727709 description : "Allow destructive operations" ,
728710 type : "boolean" ,
@@ -750,7 +732,6 @@ if (isMain(import.meta.url)) {
750732 } ,
751733 async ( {
752734 _ : { [ 0 ] : name } ,
753- flatten,
754735 force,
755736 init,
756737 package : packagePath ,
@@ -764,7 +745,6 @@ if (isMain(import.meta.url)) {
764745 testAppPath : fileURLToPath ( new URL ( ".." , import . meta. url ) ) ,
765746 targetVersion,
766747 platforms : validatePlatforms ( platforms ) ,
767- flatten,
768748 force,
769749 init,
770750 } ) ;
0 commit comments