react-native-macos 0.76.9 → 0.76.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/Libraries/Blob/RCTBlobManager.h +0 -0
  2. package/Libraries/Blob/RCTBlobManager.mm +0 -0
  3. package/Libraries/Components/TextInput/TextInputState.js +5 -1
  4. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +0 -0
  5. package/Libraries/Core/ReactNativeVersion.js +1 -1
  6. package/Libraries/Inspector/NetworkOverlay.js +1 -1
  7. package/Libraries/Lists/FillRateHelper.js +3 -3
  8. package/Libraries/Lists/FlatList.d.ts +1 -1
  9. package/Libraries/Lists/FlatList.js +2 -2
  10. package/Libraries/Lists/SectionList.d.ts +1 -1
  11. package/Libraries/Lists/SectionList.js +2 -2
  12. package/Libraries/Lists/SectionListModern.js +2 -2
  13. package/Libraries/Lists/ViewabilityHelper.js +3 -3
  14. package/Libraries/Lists/VirtualizeUtils.js +2 -2
  15. package/Libraries/Lists/VirtualizedList.js +3 -3
  16. package/Libraries/Lists/VirtualizedListContext.js +2 -2
  17. package/Libraries/Lists/VirtualizedSectionList.js +3 -3
  18. package/Libraries/Modal/Modal.js +1 -1
  19. package/Libraries/StyleSheet/normalizeColor.js +0 -0
  20. package/Libraries/Text/Text.d.ts +1 -0
  21. package/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +1 -1
  22. package/Libraries/Utilities/ReactNativeTestTools.js +1 -1
  23. package/React/Base/RCTJavaScriptLoader.h +0 -0
  24. package/React/Base/RCTJavaScriptLoader.mm +0 -0
  25. package/React/Base/RCTVersion.m +1 -1
  26. package/React/CoreModules/RCTLogBoxView.mm +4 -1
  27. package/React/DevSupport/RCTPausedInDebuggerOverlayController.mm +82 -14
  28. package/React/Views/RCTViewKeyboardEvent.m +24 -0
  29. package/ReactAndroid/gradle.properties +1 -1
  30. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  31. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  32. package/local-cli/cli.js +0 -0
  33. package/package.json +5 -4
  34. package/scripts/compose-source-maps.js +0 -0
  35. package/scripts/featureflags/README.md +156 -0
  36. package/scripts/featureflags/index.js +14 -0
  37. package/scripts/ios-configure-glog.sh +0 -0
  38. package/scripts/node-binary.sh +0 -0
  39. package/scripts/packager.sh +0 -0
  40. package/scripts/react-native-xcode.sh +0 -0
  41. package/scripts/react_native_pods_utils/script_phases.sh +0 -0
  42. package/scripts/xcode/ccache-clang++.sh +0 -0
  43. package/scripts/xcode/ccache-clang.sh +0 -0
  44. package/scripts/xcode/with-environment.sh +0 -0
  45. package/types/index.d.ts +1 -1
  46. package/scripts/cocoapods/autolinking.rb +0 -206
  47. package/scripts/cocoapods/autolinking_utils.rb +0 -25
  48. package/scripts/cocoapods/codegen.rb +0 -59
  49. package/scripts/cocoapods/codegen_script_phase_extractor.rb +0 -13
  50. package/scripts/cocoapods/codegen_utils.rb +0 -363
  51. package/scripts/cocoapods/fabric.rb +0 -18
  52. package/scripts/cocoapods/helpers.rb +0 -148
  53. package/scripts/cocoapods/jsengine.rb +0 -33
  54. package/scripts/cocoapods/local_podspec_patch.rb +0 -51
  55. package/scripts/cocoapods/new_architecture.rb +0 -193
  56. package/scripts/cocoapods/privacy_manifest_utils.rb +0 -194
  57. package/scripts/cocoapods/runtime.rb +0 -18
  58. package/scripts/cocoapods/spm.rb +0 -94
  59. package/scripts/cocoapods/utils.rb +0 -723
  60. package/scripts/codegen/codegen-utils.js +0 -51
  61. package/scripts/codegen/generate-artifacts-executor.js +0 -815
  62. package/scripts/codegen/generate-specs-cli-executor.js +0 -128
  63. package/scripts/codegen/templates/RCTModulesConformingToProtocolsProviderH.template +0 -18
  64. package/scripts/codegen/templates/RCTModulesConformingToProtocolsProviderMM.template +0 -33
  65. package/sdks/hermes-engine/hermes-engine.podspec +0 -161
  66. package/sdks/hermes-engine/hermes-utils.rb +0 -285
  67. package/sdks/hermes-engine/utils/build-apple-framework.sh +0 -225
  68. package/sdks/hermes-engine/utils/build-hermes-xcode.sh +0 -100
  69. package/sdks/hermes-engine/utils/build-hermesc-xcode.sh +0 -18
  70. package/sdks/hermes-engine/utils/build-ios-framework.sh +0 -85
  71. package/sdks/hermes-engine/utils/build-mac-framework.sh +0 -22
  72. package/sdks/hermes-engine/utils/copy-hermes-xcode.sh +0 -7
  73. package/sdks/hermes-engine/utils/create-dummy-hermes-xcframework.sh +0 -32
  74. package/sdks/hermes-engine/utils/replace_hermes_version.js +0 -106
@@ -1,815 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- */
9
-
10
- 'use strict';
11
-
12
- /**
13
- * This script crawls through a React Native application's dependencies and invokes the codegen
14
- * for any libraries that require it.
15
- * To enable codegen support, the library should include a config in the codegenConfig key
16
- * in a package.json file.
17
- */
18
-
19
- const utils = require('./codegen-utils');
20
- const generateSpecsCLIExecutor = require('./generate-specs-cli-executor');
21
- const {execSync} = require('child_process');
22
- const fs = require('fs');
23
- const glob = require('glob');
24
- const mkdirp = require('mkdirp');
25
- const os = require('os');
26
- const path = require('path');
27
-
28
- const REACT_NATIVE_REPOSITORY_ROOT = path.join(
29
- __dirname,
30
- '..',
31
- '..',
32
- '..',
33
- '..',
34
- );
35
- const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..');
36
- const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`;
37
- const RNCORE_CONFIGS = {
38
- ios: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'),
39
- android: path.join(
40
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
41
- 'ReactAndroid',
42
- 'build',
43
- 'generated',
44
- 'source',
45
- 'codegen',
46
- ),
47
- };
48
- const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
49
- rncore: RNCORE_CONFIGS,
50
- FBReactNativeSpec: {
51
- ios: null,
52
- android: path.join(
53
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
54
- 'ReactAndroid',
55
- 'build',
56
- 'generated',
57
- 'source',
58
- 'codegen',
59
- ),
60
- },
61
- };
62
- const REACT_NATIVE = 'react-native';
63
- const REACT_NATIVE_MACOS = 'react-native-macos';
64
-
65
- const MODULES_PROTOCOLS_H_TEMPLATE_PATH = path.join(
66
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
67
- 'scripts',
68
- 'codegen',
69
- 'templates',
70
- 'RCTModulesConformingToProtocolsProviderH.template',
71
- );
72
-
73
- const MODULES_PROTOCOLS_MM_TEMPLATE_PATH = path.join(
74
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
75
- 'scripts',
76
- 'codegen',
77
- 'templates',
78
- 'RCTModulesConformingToProtocolsProviderMM.template',
79
- );
80
-
81
- // HELPERS
82
-
83
- function pkgJsonIncludesGeneratedCode(pkgJson) {
84
- return pkgJson.codegenConfig && pkgJson.codegenConfig.includesGeneratedCode;
85
- }
86
-
87
- function isReactNativeCoreLibrary(libraryName) {
88
- return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER;
89
- }
90
-
91
- function readPkgJsonInDirectory(dir) {
92
- const pkgJsonPath = path.join(dir, 'package.json');
93
- if (!fs.existsSync(pkgJsonPath)) {
94
- throw `[Codegen] Error: ${pkgJsonPath} does not exist.`;
95
- }
96
- return JSON.parse(fs.readFileSync(pkgJsonPath));
97
- }
98
-
99
- function printDeprecationWarningIfNeeded(dependency) {
100
- // [macOS]
101
- if (dependency === REACT_NATIVE || dependency === REACT_NATIVE_MACOS) {
102
- return;
103
- }
104
- console.log(`[Codegen] CodegenConfig Deprecated Setup for ${dependency}.
105
- The configuration file still contains the codegen in the libraries array.
106
- If possible, replace it with a single object.
107
- `);
108
- console.debug(`BEFORE:
109
- {
110
- // ...
111
- "codegenConfig": {
112
- "libraries": [
113
- {
114
- "name": "libName1",
115
- "type": "all|components|modules",
116
- "jsSrcsRoot": "libName1/js"
117
- },
118
- {
119
- "name": "libName2",
120
- "type": "all|components|modules",
121
- "jsSrcsRoot": "libName2/src"
122
- }
123
- ]
124
- }
125
- }
126
-
127
- AFTER:
128
- {
129
- "codegenConfig": {
130
- "name": "libraries",
131
- "type": "all",
132
- "jsSrcsRoot": "."
133
- }
134
- }
135
- `);
136
- }
137
-
138
- // Reading Libraries
139
- function extractLibrariesFromConfigurationArray(configFile, dependencyPath) {
140
- return configFile.codegenConfig.libraries.map(config => {
141
- return {
142
- config,
143
- libraryPath: dependencyPath,
144
- };
145
- });
146
- }
147
-
148
- function extractLibrariesFromJSON(configFile, dependencyPath) {
149
- if (configFile.codegenConfig == null) {
150
- return [];
151
- }
152
- console.log(`[Codegen] Found ${configFile.name}`);
153
- if (configFile.codegenConfig.libraries == null) {
154
- const config = configFile.codegenConfig;
155
- return [
156
- {
157
- libraryName: configFile.name,
158
- config,
159
- libraryPath: dependencyPath,
160
- },
161
- ];
162
- } else {
163
- printDeprecationWarningIfNeeded(configFile.name);
164
- return extractLibrariesFromConfigurationArray(configFile, dependencyPath);
165
- }
166
- }
167
-
168
- const APPLE_PLATFORMS = ['ios', 'macos', 'tvos', 'visionos'];
169
-
170
- // Cocoapods specific platform keys
171
- function getCocoaPodsPlatformKey(platformName) {
172
- if (platformName === 'macos') {
173
- return 'osx';
174
- }
175
- return platformName;
176
- }
177
-
178
- function extractSupportedApplePlatforms(dependency, dependencyPath) {
179
- console.log('[Codegen] Searching for podspec in the project dependencies.');
180
- const podspecs = glob.sync('*.podspec', {cwd: dependencyPath});
181
-
182
- if (podspecs.length === 0) {
183
- return;
184
- }
185
-
186
- // Take the first podspec found
187
- const podspec = fs.readFileSync(
188
- path.join(dependencyPath, podspecs[0]),
189
- 'utf8',
190
- );
191
-
192
- /**
193
- * Podspec can have platforms defined in two ways:
194
- * 1. `spec.platforms = { :ios => "11.0", :tvos => "11.0" }`
195
- * 2. `s.ios.deployment_target = "11.0"`
196
- * `s.tvos.deployment_target = "11.0"`
197
- */
198
- const supportedPlatforms = podspec
199
- .split('\n')
200
- .filter(
201
- line => line.includes('platform') || line.includes('deployment_target'),
202
- )
203
- .join('');
204
-
205
- // Generate a map of supported platforms { [platform]: true/false }
206
- const supportedPlatformsMap = APPLE_PLATFORMS.reduce(
207
- (acc, platform) => ({
208
- ...acc,
209
- [platform]: supportedPlatforms.includes(
210
- getCocoaPodsPlatformKey(platform),
211
- ),
212
- }),
213
- {},
214
- );
215
-
216
- const supportedPlatformsList = Object.keys(supportedPlatformsMap).filter(
217
- key => supportedPlatformsMap[key],
218
- );
219
-
220
- if (supportedPlatformsList.length > 0) {
221
- console.log(
222
- `[Codegen] Supported Apple platforms: ${supportedPlatformsList.join(
223
- ', ',
224
- )} for ${dependency}`,
225
- );
226
- }
227
-
228
- return supportedPlatformsMap;
229
- }
230
-
231
- function findExternalLibraries(pkgJson, projectRoot) {
232
- const dependencies = {
233
- ...pkgJson.dependencies,
234
- ...pkgJson.devDependencies,
235
- ...pkgJson.peerDependencies,
236
- };
237
- // Determine which of these are codegen-enabled libraries
238
- console.log(
239
- '[Codegen] Searching for codegen-enabled libraries in the project dependencies.',
240
- );
241
- // Handle third-party libraries
242
- return Object.keys(dependencies).flatMap(dependency => {
243
- try {
244
- const configFilePath = require.resolve(
245
- path.join(dependency, 'package.json'),
246
- {paths: [projectRoot]},
247
- );
248
- const configFile = JSON.parse(fs.readFileSync(configFilePath));
249
- const codegenConfigFileDir = path.dirname(configFilePath);
250
- return extractLibrariesFromJSON(configFile, codegenConfigFileDir);
251
- } catch (e) {
252
- return [];
253
- }
254
- });
255
- }
256
-
257
- function readRNConfigJSFile(projectRoot) {
258
- const rnConfigFileName = 'react-native.config.js';
259
-
260
- const rnConfigFilePath = path.resolve(projectRoot, rnConfigFileName);
261
-
262
- if (!fs.existsSync(rnConfigFilePath)) {
263
- return [];
264
- }
265
- return require(rnConfigFilePath);
266
- }
267
-
268
- function findLibrariesFromReactNativeConfig(projectRoot) {
269
- console.log(
270
- `\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in react-native.config.js`,
271
- );
272
-
273
- const rnConfig = readRNConfigJSFile(projectRoot);
274
-
275
- if (rnConfig.dependencies == null) {
276
- return [];
277
- }
278
- return Object.keys(rnConfig.dependencies).flatMap(name => {
279
- const dependencyConfig = rnConfig.dependencies[name];
280
-
281
- if (!dependencyConfig.root) {
282
- return [];
283
- }
284
- const codegenConfigFileDir = path.resolve(
285
- projectRoot,
286
- dependencyConfig.root,
287
- );
288
- let configFile;
289
- try {
290
- configFile = readPkgJsonInDirectory(codegenConfigFileDir);
291
- } catch {
292
- return [];
293
- }
294
-
295
- return extractLibrariesFromJSON(configFile, codegenConfigFileDir);
296
- });
297
- }
298
-
299
- // Function to look for libraries explicitly unlinked from the app
300
- // through the react-native.config.js file.
301
- // If this happens, it might be that the app does not need
302
- // to generate code for that library as it won't be used by that platform
303
- // @return { [libraryName: string]: [platform: string] }
304
- function findNotLinkedLibraries(projectRoot) {
305
- const rnConfig = readRNConfigJSFile(projectRoot);
306
-
307
- if (rnConfig.dependencies == null) {
308
- return {};
309
- }
310
-
311
- let notLinkedLibraries = {};
312
-
313
- Object.keys(rnConfig.dependencies).forEach(name => {
314
- const dependency = rnConfig.dependencies[name];
315
- let notLinkedPlatforms = [];
316
-
317
- // dependency.platforms might not be defined, as the format
318
- // {
319
- // "dependencies": {
320
- // "dependency-name": {
321
- // "root": "path/to/dependency",
322
- // }
323
- // }
324
- // }
325
- // is also supported.
326
- // In this case, we assume that the library is linked to all platforms.
327
- // We don't consider the case were `dependency-name.root` is equal to `null`, because that
328
- // means that the library is not linked to the app at all, and in that case the dependency
329
- // should be removed by the user.
330
- dependency.platforms &&
331
- Object.keys(dependency.platforms).forEach(platform => {
332
- if (dependency.platforms[platform] == null) {
333
- notLinkedPlatforms.push(platform);
334
- }
335
- });
336
- notLinkedLibraries[name] = notLinkedPlatforms;
337
- });
338
- return notLinkedLibraries;
339
- }
340
-
341
- function findProjectRootLibraries(pkgJson, projectRoot) {
342
- console.log('[Codegen] Searching for codegen-enabled libraries in the app.');
343
-
344
- if (pkgJson.codegenConfig == null) {
345
- console.log(
346
- '[Codegen] The "codegenConfig" field is not defined in package.json. Assuming there is nothing to generate at the app level.',
347
- );
348
- return [];
349
- }
350
-
351
- if (typeof pkgJson.codegenConfig !== 'object') {
352
- throw '[Codegen] The "codegenConfig" field must be an Object.';
353
- }
354
-
355
- return extractLibrariesFromJSON(pkgJson, projectRoot);
356
- }
357
-
358
- // CodeGen
359
- function buildCodegenIfNeeded() {
360
- if (!fs.existsSync(CODEGEN_REPO_PATH)) {
361
- return;
362
- }
363
- // Assuming we are working in the react-native repo. We might need to build the codegen.
364
- // This will become unnecessary once we start using Babel Register for the codegen package.
365
- const libPath = path.join(CODEGEN_REPO_PATH, 'lib');
366
- if (fs.existsSync(libPath) && fs.readdirSync(libPath).length > 0) {
367
- return;
368
- }
369
- console.log('[Codegen] Building react-native-codegen package.');
370
- execSync('yarn install', {
371
- cwd: CODEGEN_REPO_PATH,
372
- stdio: 'inherit',
373
- });
374
- execSync('yarn build', {
375
- cwd: CODEGEN_REPO_PATH,
376
- stdio: 'inherit',
377
- });
378
- }
379
-
380
- function readOutputDirFromPkgJson(pkgJson, platform) {
381
- const codegenConfig = pkgJson.codegenConfig;
382
- if (codegenConfig == null || typeof codegenConfig !== 'object') {
383
- return null;
384
- }
385
- const outputDir = codegenConfig.outputDir;
386
- if (outputDir == null) {
387
- return null;
388
- }
389
- if (typeof outputDir === 'string') {
390
- return outputDir;
391
- }
392
- if (typeof outputDir === 'object') {
393
- return outputDir[platform];
394
- }
395
- return null;
396
- }
397
-
398
- function defaultOutputPathForAndroid(baseOutputPath) {
399
- return path.join(
400
- baseOutputPath,
401
- 'android',
402
- 'app',
403
- 'build',
404
- 'generated',
405
- 'source',
406
- 'codegen',
407
- );
408
- }
409
-
410
- function defaultOutputPathForIOS(baseOutputPath) {
411
- return path.join(baseOutputPath, 'build', 'generated', 'ios');
412
- }
413
-
414
- function computeOutputPath(projectRoot, baseOutputPath, pkgJson, platform) {
415
- if (baseOutputPath == null) {
416
- const outputDirFromPkgJson = readOutputDirFromPkgJson(pkgJson, platform);
417
- if (outputDirFromPkgJson != null) {
418
- baseOutputPath = path.join(projectRoot, outputDirFromPkgJson);
419
- } else {
420
- baseOutputPath = projectRoot;
421
- }
422
- }
423
- if (pkgJsonIncludesGeneratedCode(pkgJson)) {
424
- // Don't create nested directories for libraries to make importing generated headers easier.
425
- return baseOutputPath;
426
- }
427
- if (platform === 'android') {
428
- return defaultOutputPathForAndroid(baseOutputPath);
429
- }
430
- if (platform === 'ios') {
431
- return defaultOutputPathForIOS(baseOutputPath);
432
- }
433
- return baseOutputPath;
434
- }
435
-
436
- function reactNativeCoreLibraryOutputPath(libraryName, platform) {
437
- return CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName]
438
- ? CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName][platform]
439
- : null;
440
- }
441
-
442
- function generateSchemaInfo(library, platform) {
443
- const pathToJavaScriptSources = path.join(
444
- library.libraryPath,
445
- library.config.jsSrcsDir,
446
- );
447
- console.log(`[Codegen] Processing ${library.config.name}`);
448
-
449
- const supportedApplePlatforms = extractSupportedApplePlatforms(
450
- library.config.name,
451
- library.libraryPath,
452
- );
453
-
454
- // Generate one schema for the entire library...
455
- return {
456
- library: library,
457
- supportedApplePlatforms,
458
- schema: utils
459
- .getCombineJSToSchema()
460
- .combineSchemasInFileList(
461
- [pathToJavaScriptSources],
462
- platform,
463
- /NativeSampleTurboModule/,
464
- ),
465
- };
466
- }
467
-
468
- function shouldSkipGenerationForRncore(schemaInfo, platform) {
469
- if (platform !== 'ios' || schemaInfo.library.config.name !== 'rncore') {
470
- return false;
471
- }
472
- const rncoreOutputPath = path.join(
473
- RNCORE_CONFIGS.ios,
474
- 'react',
475
- 'renderer',
476
- 'components',
477
- 'rncore',
478
- );
479
- const rncoreAbsolutePath = path.resolve(rncoreOutputPath);
480
- return (
481
- rncoreAbsolutePath.includes('node_modules') &&
482
- fs.existsSync(rncoreAbsolutePath) &&
483
- fs.readdirSync(rncoreAbsolutePath).length > 0
484
- );
485
- }
486
-
487
- function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) {
488
- if (shouldSkipGenerationForRncore(schemaInfo, platform)) {
489
- console.log(
490
- '[Codegen - rncore] Skipping iOS code generation for rncore as it has been generated already.',
491
- );
492
- return;
493
- }
494
-
495
- const libraryName = schemaInfo.library.config.name;
496
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), libraryName));
497
- const tmpOutputDir = path.join(tmpDir, 'out');
498
- fs.mkdirSync(tmpOutputDir, {recursive: true});
499
-
500
- console.log(
501
- `[Codegen] Generating Native Code for ${libraryName} - ${platform}`,
502
- );
503
- const useLocalIncludePaths = includesGeneratedCode;
504
- generateSpecsCLIExecutor.generateSpecFromInMemorySchema(
505
- platform,
506
- schemaInfo.schema,
507
- tmpOutputDir,
508
- libraryName,
509
- 'com.facebook.fbreact.specs',
510
- schemaInfo.library.config.type,
511
- useLocalIncludePaths,
512
- );
513
-
514
- // Finally, copy artifacts to the final output directory.
515
- const outputDir =
516
- reactNativeCoreLibraryOutputPath(libraryName, platform) ?? outputPath;
517
- fs.mkdirSync(outputDir, {recursive: true});
518
- fs.cpSync(tmpOutputDir, outputDir, {recursive: true});
519
- console.log(`[Codegen] Generated artifacts: ${outputDir}`);
520
- }
521
-
522
- function generateSchemaInfos(libraries) {
523
- return libraries.map(generateSchemaInfo);
524
- }
525
-
526
- function generateNativeCode(
527
- outputPath,
528
- schemaInfos,
529
- includesGeneratedCode,
530
- platform,
531
- ) {
532
- return schemaInfos.map(schemaInfo => {
533
- generateCode(outputPath, schemaInfo, includesGeneratedCode, platform);
534
- });
535
- }
536
-
537
- function rootCodegenTargetNeedsThirdPartyComponentProvider(pkgJson, platform) {
538
- return !pkgJsonIncludesGeneratedCode(pkgJson) && platform === 'ios';
539
- }
540
-
541
- function dependencyNeedsThirdPartyComponentProvider(
542
- schemaInfo,
543
- platform,
544
- appCodegenConfigSpec,
545
- ) {
546
- // Filter the react native core library out.
547
- // In the future, core library and third party library should
548
- // use the same way to generate/register the fabric components.
549
- // We also have to filter out the the components defined in the app
550
- // because the RCTThirdPartyComponentProvider is generated inside Fabric,
551
- // which lives in a different target from the app and it has no visibility over
552
- // the symbols defined in the app.
553
- return (
554
- !isReactNativeCoreLibrary(schemaInfo.library.config.name, platform) &&
555
- schemaInfo.library.config.name !== appCodegenConfigSpec
556
- );
557
- }
558
-
559
- function mustGenerateNativeCode(includeLibraryPath, schemaInfo) {
560
- // If library's 'codegenConfig' sets 'includesGeneratedCode' to 'true',
561
- // then we assume that native code is shipped with the library,
562
- // and we don't need to generate it.
563
- return (
564
- schemaInfo.library.libraryPath === includeLibraryPath ||
565
- !schemaInfo.library.config.includesGeneratedCode
566
- );
567
- }
568
-
569
- function createComponentProvider(schemas, supportedApplePlatforms) {
570
- console.log('[Codegen] Creating component provider.');
571
- const outputDir = path.join(
572
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
573
- 'React',
574
- 'Fabric',
575
- );
576
- mkdirp.sync(outputDir);
577
- utils.getCodegen().generateFromSchemas(
578
- {
579
- schemas: schemas,
580
- outputDirectory: outputDir,
581
- supportedApplePlatforms,
582
- },
583
- {
584
- generators: ['providerIOS'],
585
- },
586
- );
587
- console.log(`[Codegen] Generated provider in: ${outputDir}`);
588
- }
589
-
590
- function findCodegenEnabledLibraries(pkgJson, projectRoot) {
591
- const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot);
592
- if (pkgJsonIncludesGeneratedCode(pkgJson)) {
593
- return projectLibraries;
594
- } else {
595
- return [
596
- ...projectLibraries,
597
- ...findExternalLibraries(pkgJson, projectRoot),
598
- ...findLibrariesFromReactNativeConfig(projectRoot),
599
- ];
600
- }
601
- }
602
-
603
- function generateCustomURLHandlers(libraries, outputDir) {
604
- const customImageURLLoaderClasses = libraries
605
- .flatMap(
606
- library =>
607
- library?.config?.ios?.modulesConformingToProtocol?.RCTImageURLLoader,
608
- )
609
- .filter(Boolean)
610
- .map(className => `@"${className}"`)
611
- .join(',\n\t\t');
612
-
613
- const customImageDataDecoderClasses = libraries
614
- .flatMap(
615
- library =>
616
- library?.config?.ios?.modulesConformingToProtocol?.RCTImageDataDecoder,
617
- )
618
- .filter(Boolean)
619
- .map(className => `@"${className}"`)
620
- .join(',\n\t\t');
621
-
622
- const customURLHandlerClasses = libraries
623
- .flatMap(
624
- library =>
625
- library?.config?.ios?.modulesConformingToProtocol?.RCTURLRequestHandler,
626
- )
627
- .filter(Boolean)
628
- .map(className => `@"${className}"`)
629
- .join(',\n\t\t');
630
-
631
- const template = fs.readFileSync(MODULES_PROTOCOLS_MM_TEMPLATE_PATH, 'utf8');
632
- const finalMMFile = template
633
- .replace(/{imageURLLoaderClassNames}/, customImageURLLoaderClasses)
634
- .replace(/{imageDataDecoderClassNames}/, customImageDataDecoderClasses)
635
- .replace(/{requestHandlersClassNames}/, customURLHandlerClasses);
636
-
637
- fs.writeFileSync(
638
- path.join(outputDir, 'RCTModulesConformingToProtocolsProvider.mm'),
639
- finalMMFile,
640
- );
641
-
642
- const templateH = fs.readFileSync(MODULES_PROTOCOLS_H_TEMPLATE_PATH, 'utf8');
643
- fs.writeFileSync(
644
- path.join(outputDir, 'RCTModulesConformingToProtocolsProvider.h'),
645
- templateH,
646
- );
647
- }
648
-
649
- // It removes all the empty files and empty folders
650
- // it finds, starting from `filepath`, recursively.
651
- //
652
- // This function is needed since, after aligning the codegen between
653
- // iOS and Android, we have to create empty folders in advance and
654
- // we don't know whether they will be populated up until the end of the process.
655
- //
656
- // @parameter filepath: the root path from which we want to remove the empty files and folders.
657
- function cleanupEmptyFilesAndFolders(filepath) {
658
- const stats = fs.statSync(filepath);
659
-
660
- if (stats.isFile() && stats.size === 0) {
661
- fs.rmSync(filepath);
662
- return;
663
- } else if (stats.isFile()) {
664
- return;
665
- }
666
-
667
- const dirContent = fs.readdirSync(filepath);
668
- dirContent.forEach(contentPath =>
669
- cleanupEmptyFilesAndFolders(path.join(filepath, contentPath)),
670
- );
671
-
672
- // The original folder may be filled with empty folders
673
- // if that the case, we would also like to remove the parent.
674
- // Hence, we need to read the folder again.
675
- const newContent = fs.readdirSync(filepath);
676
- if (newContent.length === 0) {
677
- fs.rmdirSync(filepath);
678
- return;
679
- }
680
- }
681
-
682
- function generateRNCoreComponentsIOS(projectRoot /*: string */) /*: void*/ {
683
- const ios = 'ios';
684
- buildCodegenIfNeeded();
685
- const pkgJson = readPkgJsonInDirectory(projectRoot);
686
- const rncoreLib = findProjectRootLibraries(pkgJson, projectRoot).filter(
687
- library => library.config.name === 'rncore',
688
- )[0];
689
- if (!rncoreLib) {
690
- throw new Error(
691
- "[Codegen] Can't find rncore library. Failed to generate rncore artifacts",
692
- );
693
- }
694
- const rncoreSchemaInfo = generateSchemaInfo(rncoreLib, ios);
695
- generateCode('', rncoreSchemaInfo, false, ios);
696
- }
697
-
698
- // Execute
699
-
700
- /**
701
- * This function is the entry point for the codegen. It:
702
- * - reads the package json
703
- * - extracts the libraries
704
- * - setups the CLI to generate the code
705
- * - generate the code
706
- *
707
- * @parameter projectRoot: the directory with the app source code, where the package.json lives.
708
- * @parameter baseOutputPath: the base output path for the CodeGen.
709
- * @parameter targetPlatform: the target platform. Supported values: 'android', 'ios', 'all'.
710
- * @throws If it can't find a config file for react-native.
711
- * @throws If it can't find a CodeGen configuration in the file.
712
- * @throws If it can't find a cli for the CodeGen.
713
- */
714
- function execute(projectRoot, targetPlatform, baseOutputPath) {
715
- try {
716
- console.log(
717
- `[Codegen] Analyzing ${path.join(projectRoot, 'package.json')}`,
718
- );
719
-
720
- const supportedPlatforms = ['android', 'ios'];
721
- if (
722
- targetPlatform !== 'all' &&
723
- !supportedPlatforms.includes(targetPlatform)
724
- ) {
725
- throw new Error(
726
- `Invalid target platform: ${targetPlatform}. Supported values are: ${supportedPlatforms.join(
727
- ', ',
728
- )}, all`,
729
- );
730
- }
731
-
732
- const pkgJson = readPkgJsonInDirectory(projectRoot);
733
-
734
- buildCodegenIfNeeded();
735
-
736
- const libraries = findCodegenEnabledLibraries(pkgJson, projectRoot);
737
-
738
- if (libraries.length === 0) {
739
- console.log('[Codegen] No codegen-enabled libraries found.');
740
- return;
741
- }
742
-
743
- let platforms =
744
- targetPlatform === 'all' ? supportedPlatforms : [targetPlatform];
745
-
746
- const notLinkedLibraries = findNotLinkedLibraries(projectRoot);
747
-
748
- for (const platform of platforms) {
749
- const outputPath = computeOutputPath(
750
- projectRoot,
751
- baseOutputPath,
752
- pkgJson,
753
- platform,
754
- );
755
-
756
- const schemaInfos = generateSchemaInfos(
757
- libraries.filter(library => {
758
- const unlinkedPlatforms = notLinkedLibraries[library.libraryName];
759
- if (unlinkedPlatforms && unlinkedPlatforms.includes(platform)) {
760
- console.log(
761
- `[Codegen - ${library.libraryName}] Skipping Codegen on ${platform}`,
762
- );
763
- return false;
764
- }
765
- return true;
766
- }),
767
- );
768
-
769
- generateNativeCode(
770
- outputPath,
771
- schemaInfos.filter(schemaInfo =>
772
- mustGenerateNativeCode(projectRoot, schemaInfo),
773
- ),
774
- pkgJsonIncludesGeneratedCode(pkgJson),
775
- platform,
776
- );
777
-
778
- if (
779
- rootCodegenTargetNeedsThirdPartyComponentProvider(pkgJson, platform)
780
- ) {
781
- const filteredSchemas = schemaInfos.filter(schemaInfo =>
782
- dependencyNeedsThirdPartyComponentProvider(
783
- schemaInfo,
784
- platform,
785
- pkgJson.codegenConfig?.name,
786
- ),
787
- );
788
- const schemas = filteredSchemas.map(schemaInfo => schemaInfo.schema);
789
- const supportedApplePlatforms = filteredSchemas.map(
790
- schemaInfo => schemaInfo.supportedApplePlatforms,
791
- );
792
-
793
- createComponentProvider(schemas, supportedApplePlatforms);
794
- generateCustomURLHandlers(libraries, outputPath);
795
- }
796
-
797
- cleanupEmptyFilesAndFolders(outputPath);
798
- }
799
- } catch (err) {
800
- console.error(err);
801
- process.exitCode = 1;
802
- }
803
-
804
- console.log('[Codegen] Done.');
805
- return;
806
- }
807
-
808
- module.exports = {
809
- execute,
810
- generateRNCoreComponentsIOS,
811
- // exported for testing purposes only:
812
- _extractLibrariesFromJSON: extractLibrariesFromJSON,
813
- _cleanupEmptyFilesAndFolders: cleanupEmptyFilesAndFolders,
814
- _extractSupportedApplePlatforms: extractSupportedApplePlatforms,
815
- };