react-native-macos 0.77.5 → 0.77.6

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 (61) hide show
  1. package/Libraries/Blob/RCTBlobManager.h +0 -0
  2. package/Libraries/Blob/RCTBlobManager.mm +0 -0
  3. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +0 -0
  4. package/Libraries/Core/ReactNativeVersion.js +1 -1
  5. package/Libraries/StyleSheet/normalizeColor.js +0 -0
  6. package/React/Base/RCTJavaScriptLoader.h +0 -0
  7. package/React/Base/RCTJavaScriptLoader.mm +0 -0
  8. package/React/Base/RCTVersion.m +1 -1
  9. package/React/CoreModules/RCTDevLoadingView.mm +1 -1
  10. package/React/CoreModules/RCTLogBoxView.mm +4 -1
  11. package/React/DevSupport/RCTPausedInDebuggerOverlayController.mm +82 -14
  12. package/ReactAndroid/gradle.properties +1 -1
  13. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  14. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  15. package/local-cli/cli.js +0 -0
  16. package/package.json +3 -3
  17. package/scripts/compose-source-maps.js +0 -0
  18. package/scripts/featureflags/README.md +156 -0
  19. package/scripts/featureflags/index.js +39 -0
  20. package/scripts/ios-configure-glog.sh +0 -0
  21. package/scripts/node-binary.sh +0 -0
  22. package/scripts/packager.sh +0 -0
  23. package/scripts/react-native-xcode.sh +0 -0
  24. package/scripts/react_native_pods_utils/script_phases.sh +0 -0
  25. package/scripts/xcode/ccache-clang++.sh +0 -0
  26. package/scripts/xcode/ccache-clang.sh +0 -0
  27. package/scripts/xcode/with-environment.sh +0 -0
  28. package/scripts/cocoapods/autolinking.rb +0 -206
  29. package/scripts/cocoapods/autolinking_utils.rb +0 -25
  30. package/scripts/cocoapods/codegen.rb +0 -59
  31. package/scripts/cocoapods/codegen_script_phase_extractor.rb +0 -13
  32. package/scripts/cocoapods/codegen_utils.rb +0 -389
  33. package/scripts/cocoapods/fabric.rb +0 -18
  34. package/scripts/cocoapods/helpers.rb +0 -150
  35. package/scripts/cocoapods/jsengine.rb +0 -33
  36. package/scripts/cocoapods/local_podspec_patch.rb +0 -51
  37. package/scripts/cocoapods/new_architecture.rb +0 -194
  38. package/scripts/cocoapods/privacy_manifest_utils.rb +0 -194
  39. package/scripts/cocoapods/runtime.rb +0 -18
  40. package/scripts/cocoapods/spm.rb +0 -94
  41. package/scripts/cocoapods/utils.rb +0 -729
  42. package/scripts/codegen/codegen-utils.js +0 -51
  43. package/scripts/codegen/generate-artifacts-executor.js +0 -982
  44. package/scripts/codegen/generate-specs-cli-executor.js +0 -128
  45. package/scripts/codegen/templates/RCTAppDependencyProviderH.template +0 -25
  46. package/scripts/codegen/templates/RCTAppDependencyProviderMM.template +0 -55
  47. package/scripts/codegen/templates/RCTModulesConformingToProtocolsProviderH.template +0 -18
  48. package/scripts/codegen/templates/RCTModulesConformingToProtocolsProviderMM.template +0 -33
  49. package/scripts/codegen/templates/RCTThirdPartyComponentsProviderH.template +0 -16
  50. package/scripts/codegen/templates/RCTThirdPartyComponentsProviderMM.template +0 -23
  51. package/scripts/codegen/templates/ReactAppDependencyProvider.podspec.template +0 -34
  52. package/sdks/hermes-engine/hermes-engine.podspec +0 -168
  53. package/sdks/hermes-engine/hermes-utils.rb +0 -341
  54. package/sdks/hermes-engine/utils/build-apple-framework.sh +0 -225
  55. package/sdks/hermes-engine/utils/build-hermes-xcode.sh +0 -100
  56. package/sdks/hermes-engine/utils/build-hermesc-xcode.sh +0 -18
  57. package/sdks/hermes-engine/utils/build-ios-framework.sh +0 -90
  58. package/sdks/hermes-engine/utils/build-mac-framework.sh +0 -22
  59. package/sdks/hermes-engine/utils/copy-hermes-xcode.sh +0 -7
  60. package/sdks/hermes-engine/utils/create-dummy-hermes-xcframework.sh +0 -32
  61. package/sdks/hermes-engine/utils/replace_hermes_version.js +0 -106
@@ -1,982 +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 os = require('os');
25
- const path = require('path');
26
-
27
- const REACT_NATIVE_REPOSITORY_ROOT = path.join(
28
- __dirname,
29
- '..',
30
- '..',
31
- '..',
32
- '..',
33
- );
34
- const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..');
35
- const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`;
36
- const RNCORE_CONFIGS = {
37
- ios: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'),
38
- android: path.join(
39
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
40
- 'ReactAndroid',
41
- 'build',
42
- 'generated',
43
- 'source',
44
- 'codegen',
45
- ),
46
- };
47
- const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
48
- rncore: RNCORE_CONFIGS,
49
- FBReactNativeSpec: {
50
- ios: path.join(
51
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
52
- 'React',
53
- 'FBReactNativeSpec',
54
- ),
55
- android: path.join(
56
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
57
- 'ReactAndroid',
58
- 'build',
59
- 'generated',
60
- 'source',
61
- 'codegen',
62
- ),
63
- },
64
- };
65
-
66
- const packageJsonPath = path.join(
67
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
68
- 'package.json',
69
- );
70
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
71
- const REACT_NATIVE = packageJson.name;
72
-
73
- const MODULES_PROTOCOLS_H_TEMPLATE_PATH = path.join(
74
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
75
- 'scripts',
76
- 'codegen',
77
- 'templates',
78
- 'RCTModulesConformingToProtocolsProviderH.template',
79
- );
80
-
81
- const MODULES_PROTOCOLS_MM_TEMPLATE_PATH = path.join(
82
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
83
- 'scripts',
84
- 'codegen',
85
- 'templates',
86
- 'RCTModulesConformingToProtocolsProviderMM.template',
87
- );
88
-
89
- const THIRD_PARTY_COMPONENTS_H_TEMPLATE_PATH = path.join(
90
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
91
- 'scripts',
92
- 'codegen',
93
- 'templates',
94
- 'RCTThirdPartyComponentsProviderH.template',
95
- );
96
-
97
- const THIRD_PARTY_COMPONENTS_MM_TEMPLATE_PATH = path.join(
98
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
99
- 'scripts',
100
- 'codegen',
101
- 'templates',
102
- 'RCTThirdPartyComponentsProviderMM.template',
103
- );
104
-
105
- const APP_DEPENDENCY_PROVIDER_H_TEMPLATE_PATH = path.join(
106
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
107
- 'scripts',
108
- 'codegen',
109
- 'templates',
110
- 'RCTAppDependencyProviderH.template',
111
- );
112
-
113
- const APP_DEPENDENCY_PROVIDER_MM_TEMPLATE_PATH = path.join(
114
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
115
- 'scripts',
116
- 'codegen',
117
- 'templates',
118
- 'RCTAppDependencyProviderMM.template',
119
- );
120
-
121
- const APP_DEPENDENCY_PROVIDER_PODSPEC_TEMPLATE_PATH = path.join(
122
- REACT_NATIVE_PACKAGE_ROOT_FOLDER,
123
- 'scripts',
124
- 'codegen',
125
- 'templates',
126
- 'ReactAppDependencyProvider.podspec.template',
127
- );
128
-
129
- const codegenLog = (text, info = false) => {
130
- // ANSI escape codes for colors and formatting
131
- const reset = '\x1b[0m';
132
- const cyan = '\x1b[36m';
133
- const yellow = '\x1b[33m';
134
- const bold = '\x1b[1m';
135
-
136
- const color = info ? yellow : '';
137
- console.log(`${cyan}${bold}[Codegen]${reset} ${color}${text}${reset}`);
138
- };
139
-
140
- // HELPERS
141
-
142
- function pkgJsonIncludesGeneratedCode(pkgJson) {
143
- return pkgJson.codegenConfig && pkgJson.codegenConfig.includesGeneratedCode;
144
- }
145
-
146
- function isReactNativeCoreLibrary(libraryName) {
147
- return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER;
148
- }
149
-
150
- function readPkgJsonInDirectory(dir) {
151
- const pkgJsonPath = path.join(dir, 'package.json');
152
- if (!fs.existsSync(pkgJsonPath)) {
153
- throw `[Codegen] Error: ${pkgJsonPath} does not exist.`;
154
- }
155
- return JSON.parse(fs.readFileSync(pkgJsonPath));
156
- }
157
-
158
- function printDeprecationWarningIfNeeded(dependency) {
159
- // [macOS]
160
- if (dependency === REACT_NATIVE) {
161
- return;
162
- }
163
- codegenLog(`CodegenConfig Deprecated Setup for ${dependency}.
164
- The configuration file still contains the codegen in the libraries array.
165
- If possible, replace it with a single object.
166
- `);
167
- codegenLog(`BEFORE:
168
- {
169
- // ...
170
- "codegenConfig": {
171
- "libraries": [
172
- {
173
- "name": "libName1",
174
- "type": "all|components|modules",
175
- "jsSrcsRoot": "libName1/js"
176
- },
177
- {
178
- "name": "libName2",
179
- "type": "all|components|modules",
180
- "jsSrcsRoot": "libName2/src"
181
- }
182
- ]
183
- }
184
- }
185
-
186
- AFTER:
187
- {
188
- "codegenConfig": {
189
- "name": "libraries",
190
- "type": "all",
191
- "jsSrcsRoot": "."
192
- }
193
- }
194
- `);
195
- }
196
-
197
- // Reading Libraries
198
- function extractLibrariesFromConfigurationArray(configFile, dependencyPath) {
199
- return configFile.codegenConfig.libraries.map(config => {
200
- return {
201
- config,
202
- libraryPath: dependencyPath,
203
- };
204
- });
205
- }
206
-
207
- function extractLibrariesFromJSON(configFile, dependencyPath) {
208
- if (configFile.codegenConfig == null) {
209
- return [];
210
- }
211
- codegenLog(`Found ${configFile.name}`);
212
- if (configFile.codegenConfig.libraries == null) {
213
- const config = configFile.codegenConfig;
214
- return [
215
- {
216
- config,
217
- libraryPath: dependencyPath,
218
- },
219
- ];
220
- } else {
221
- printDeprecationWarningIfNeeded(configFile.name);
222
- return extractLibrariesFromConfigurationArray(configFile, dependencyPath);
223
- }
224
- }
225
-
226
- const APPLE_PLATFORMS = ['ios', 'macos', 'tvos', 'visionos'];
227
-
228
- // Cocoapods specific platform keys
229
- function getCocoaPodsPlatformKey(platformName) {
230
- if (platformName === 'macos') {
231
- return 'osx';
232
- }
233
- return platformName;
234
- }
235
-
236
- function extractSupportedApplePlatforms(dependency, dependencyPath) {
237
- codegenLog('Searching for podspec in the project dependencies.', true);
238
- const podspecs = glob.sync('*.podspec', {cwd: dependencyPath});
239
-
240
- if (podspecs.length === 0) {
241
- return;
242
- }
243
-
244
- // Take the first podspec found
245
- const podspec = fs.readFileSync(
246
- path.join(dependencyPath, podspecs[0]),
247
- 'utf8',
248
- );
249
-
250
- /**
251
- * Podspec can have platforms defined in two ways:
252
- * 1. `spec.platforms = { :ios => "11.0", :tvos => "11.0" }`
253
- * 2. `s.ios.deployment_target = "11.0"`
254
- * `s.tvos.deployment_target = "11.0"`
255
- */
256
- const supportedPlatforms = podspec
257
- .split('\n')
258
- .filter(
259
- line => line.includes('platform') || line.includes('deployment_target'),
260
- )
261
- .join('');
262
-
263
- // Generate a map of supported platforms { [platform]: true/false }
264
- const supportedPlatformsMap = APPLE_PLATFORMS.reduce(
265
- (acc, platform) => ({
266
- ...acc,
267
- [platform]: supportedPlatforms.includes(
268
- getCocoaPodsPlatformKey(platform),
269
- ),
270
- }),
271
- {},
272
- );
273
-
274
- const supportedPlatformsList = Object.keys(supportedPlatformsMap).filter(
275
- key => supportedPlatformsMap[key],
276
- );
277
-
278
- if (supportedPlatformsList.length > 0) {
279
- codegenLog(
280
- `Supported Apple platforms: ${supportedPlatformsList.join(
281
- ', ',
282
- )} for ${dependency}`,
283
- );
284
- }
285
-
286
- return supportedPlatformsMap;
287
- }
288
-
289
- function findExternalLibraries(pkgJson, projectRoot) {
290
- const dependencies = {
291
- ...pkgJson.dependencies,
292
- ...pkgJson.devDependencies,
293
- ...pkgJson.peerDependencies,
294
- };
295
- // Determine which of these are codegen-enabled libraries
296
- codegenLog(
297
- 'Searching for codegen-enabled libraries in the project dependencies.',
298
- true,
299
- );
300
- // Handle third-party libraries
301
- return Object.keys(dependencies).flatMap(dependency => {
302
- let configFilePath = '';
303
- try {
304
- configFilePath = require.resolve(path.join(dependency, 'package.json'), {
305
- paths: [projectRoot],
306
- });
307
- } catch (e) {
308
- // require.resolve fails if the dependency is a local node module.
309
- if (
310
- dependencies[dependency].startsWith('.') || // handles relative paths
311
- dependencies[dependency].startsWith('/') // handles absolute paths
312
- ) {
313
- configFilePath = path.join(
314
- projectRoot,
315
- pkgJson.dependencies[dependency],
316
- 'package.json',
317
- );
318
- } else {
319
- return [];
320
- }
321
- }
322
- const configFile = JSON.parse(fs.readFileSync(configFilePath));
323
- const codegenConfigFileDir = path.dirname(configFilePath);
324
- return extractLibrariesFromJSON(configFile, codegenConfigFileDir);
325
- });
326
- }
327
-
328
- function findLibrariesFromReactNativeConfig(projectRoot) {
329
- const rnConfigFileName = 'react-native.config.js';
330
-
331
- codegenLog(
332
- `Searching for codegen-enabled libraries in ${rnConfigFileName}`,
333
- true,
334
- );
335
-
336
- const rnConfigFilePath = path.resolve(projectRoot, rnConfigFileName);
337
-
338
- if (!fs.existsSync(rnConfigFilePath)) {
339
- return [];
340
- }
341
- const rnConfig = require(rnConfigFilePath);
342
-
343
- if (rnConfig.dependencies == null) {
344
- return [];
345
- }
346
- return Object.keys(rnConfig.dependencies).flatMap(name => {
347
- const dependencyConfig = rnConfig.dependencies[name];
348
-
349
- if (!dependencyConfig.root) {
350
- return [];
351
- }
352
- const codegenConfigFileDir = path.resolve(
353
- projectRoot,
354
- dependencyConfig.root,
355
- );
356
- let configFile;
357
- try {
358
- configFile = readPkgJsonInDirectory(codegenConfigFileDir);
359
- } catch {
360
- return [];
361
- }
362
-
363
- return extractLibrariesFromJSON(configFile, codegenConfigFileDir);
364
- });
365
- }
366
-
367
- function findProjectRootLibraries(pkgJson, projectRoot) {
368
- codegenLog('Searching for codegen-enabled libraries in the app.', true);
369
-
370
- if (pkgJson.codegenConfig == null) {
371
- codegenLog(
372
- 'The "codegenConfig" field is not defined in package.json. Assuming there is nothing to generate at the app level.',
373
- true,
374
- );
375
- return [];
376
- }
377
-
378
- if (typeof pkgJson.codegenConfig !== 'object') {
379
- throw 'The "codegenConfig" field must be an Object.';
380
- }
381
-
382
- return extractLibrariesFromJSON(pkgJson, projectRoot);
383
- }
384
-
385
- // CodeGen
386
- function buildCodegenIfNeeded() {
387
- if (!fs.existsSync(CODEGEN_REPO_PATH)) {
388
- return;
389
- }
390
- // Assuming we are working in the react-native repo. We might need to build the codegen.
391
- // This will become unnecessary once we start using Babel Register for the codegen package.
392
- const libPath = path.join(CODEGEN_REPO_PATH, 'lib');
393
- if (fs.existsSync(libPath) && fs.readdirSync(libPath).length > 0) {
394
- return;
395
- }
396
- codegenLog('Building react-native-codegen package.', true);
397
- execSync('yarn install', {
398
- cwd: CODEGEN_REPO_PATH,
399
- stdio: 'inherit',
400
- });
401
- execSync('yarn build', {
402
- cwd: CODEGEN_REPO_PATH,
403
- stdio: 'inherit',
404
- });
405
- }
406
-
407
- function readOutputDirFromPkgJson(pkgJson, platform) {
408
- const codegenConfig = pkgJson.codegenConfig;
409
- if (codegenConfig == null || typeof codegenConfig !== 'object') {
410
- return null;
411
- }
412
- const outputDir = codegenConfig.outputDir;
413
- if (outputDir == null) {
414
- return null;
415
- }
416
- if (typeof outputDir === 'string') {
417
- return outputDir;
418
- }
419
- if (typeof outputDir === 'object') {
420
- return outputDir[platform];
421
- }
422
- return null;
423
- }
424
-
425
- function defaultOutputPathForAndroid(baseOutputPath) {
426
- return path.join(
427
- baseOutputPath,
428
- 'android',
429
- 'app',
430
- 'build',
431
- 'generated',
432
- 'source',
433
- 'codegen',
434
- );
435
- }
436
-
437
- function defaultOutputPathForIOS(baseOutputPath) {
438
- return path.join(baseOutputPath, 'build', 'generated', 'ios');
439
- }
440
-
441
- function computeOutputPath(projectRoot, baseOutputPath, pkgJson, platform) {
442
- if (baseOutputPath == null) {
443
- const outputDirFromPkgJson = readOutputDirFromPkgJson(pkgJson, platform);
444
- if (outputDirFromPkgJson != null) {
445
- baseOutputPath = path.join(projectRoot, outputDirFromPkgJson);
446
- } else {
447
- baseOutputPath = projectRoot;
448
- }
449
- }
450
- if (pkgJsonIncludesGeneratedCode(pkgJson)) {
451
- // Don't create nested directories for libraries to make importing generated headers easier.
452
- return baseOutputPath;
453
- }
454
- if (platform === 'android') {
455
- return defaultOutputPathForAndroid(baseOutputPath);
456
- }
457
- if (platform === 'ios') {
458
- return defaultOutputPathForIOS(baseOutputPath);
459
- }
460
- return baseOutputPath;
461
- }
462
-
463
- function reactNativeCoreLibraryOutputPath(libraryName, platform) {
464
- return CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName]
465
- ? CORE_LIBRARIES_WITH_OUTPUT_FOLDER[libraryName][platform]
466
- : null;
467
- }
468
-
469
- function generateSchemaInfo(library, platform) {
470
- const pathToJavaScriptSources = path.join(
471
- library.libraryPath,
472
- library.config.jsSrcsDir,
473
- );
474
- codegenLog(`Processing ${library.config.name}`);
475
-
476
- const supportedApplePlatforms = extractSupportedApplePlatforms(
477
- library.config.name,
478
- library.libraryPath,
479
- );
480
-
481
- // Generate one schema for the entire library...
482
- return {
483
- library: library,
484
- supportedApplePlatforms,
485
- schema: utils
486
- .getCombineJSToSchema()
487
- .combineSchemasInFileList(
488
- [pathToJavaScriptSources],
489
- platform,
490
- /NativeSampleTurboModule/,
491
- ),
492
- };
493
- }
494
-
495
- function shouldSkipGenerationForRncore(schemaInfo, platform) {
496
- if (platform !== 'ios' || schemaInfo.library.config.name !== 'rncore') {
497
- return false;
498
- }
499
- const rncoreOutputPath = CORE_LIBRARIES_WITH_OUTPUT_FOLDER.rncore.ios;
500
- const rncoreAbsolutePath = path.resolve(rncoreOutputPath);
501
- return (
502
- rncoreAbsolutePath.includes('node_modules') &&
503
- fs.existsSync(rncoreAbsolutePath) &&
504
- fs.readdirSync(rncoreAbsolutePath).length > 0
505
- );
506
- }
507
-
508
- function shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform) {
509
- if (
510
- platform !== 'ios' ||
511
- schemaInfo.library.config.name !== 'FBReactNativeSpec'
512
- ) {
513
- return false;
514
- }
515
-
516
- const fbReactNativeSpecOutputPath =
517
- CORE_LIBRARIES_WITH_OUTPUT_FOLDER.FBReactNativeSpec.ios;
518
- const fbReactNativeSpecAbsolutePath = path.resolve(
519
- fbReactNativeSpecOutputPath,
520
- );
521
- return (
522
- fbReactNativeSpecAbsolutePath.includes('node_modules') &&
523
- fs.existsSync(fbReactNativeSpecAbsolutePath) &&
524
- fs.readdirSync(fbReactNativeSpecAbsolutePath).length > 0
525
- );
526
- }
527
-
528
- function generateCode(outputPath, schemaInfo, includesGeneratedCode, platform) {
529
- if (shouldSkipGenerationForRncore(schemaInfo, platform)) {
530
- codegenLog(
531
- '[Codegen - rncore] Skipping iOS code generation for rncore as it has been generated already.',
532
- true,
533
- );
534
- return;
535
- }
536
-
537
- if (shouldSkipGenerationForFBReactNativeSpec(schemaInfo, platform)) {
538
- codegenLog(
539
- '[Codegen - FBReactNativeSpec] Skipping iOS code generation for FBReactNativeSpec as it has been generated already.',
540
- true,
541
- );
542
- return;
543
- }
544
-
545
- const libraryName = schemaInfo.library.config.name;
546
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), libraryName));
547
- const tmpOutputDir = path.join(tmpDir, 'out');
548
- fs.mkdirSync(tmpOutputDir, {recursive: true});
549
-
550
- codegenLog(`Generating Native Code for ${libraryName} - ${platform}`);
551
- const useLocalIncludePaths = includesGeneratedCode;
552
- generateSpecsCLIExecutor.generateSpecFromInMemorySchema(
553
- platform,
554
- schemaInfo.schema,
555
- tmpOutputDir,
556
- libraryName,
557
- 'com.facebook.fbreact.specs',
558
- schemaInfo.library.config.type,
559
- useLocalIncludePaths,
560
- );
561
-
562
- // Finally, copy artifacts to the final output directory.
563
- const outputDir =
564
- reactNativeCoreLibraryOutputPath(libraryName, platform) ?? outputPath;
565
- fs.mkdirSync(outputDir, {recursive: true});
566
- fs.cpSync(tmpOutputDir, outputDir, {recursive: true});
567
- codegenLog(`Generated artifacts: ${outputDir}`);
568
- }
569
-
570
- function generateSchemaInfos(libraries) {
571
- return libraries.map(generateSchemaInfo);
572
- }
573
-
574
- function generateNativeCode(
575
- outputPath,
576
- schemaInfos,
577
- includesGeneratedCode,
578
- platform,
579
- ) {
580
- return schemaInfos.map(schemaInfo => {
581
- generateCode(outputPath, schemaInfo, includesGeneratedCode, platform);
582
- });
583
- }
584
-
585
- function mustGenerateNativeCode(includeLibraryPath, schemaInfo) {
586
- // If library's 'codegenConfig' sets 'includesGeneratedCode' to 'true',
587
- // then we assume that native code is shipped with the library,
588
- // and we don't need to generate it.
589
- return (
590
- schemaInfo.library.libraryPath === includeLibraryPath ||
591
- !schemaInfo.library.config.includesGeneratedCode
592
- );
593
- }
594
-
595
- function findCodegenEnabledLibraries(pkgJson, projectRoot) {
596
- const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot);
597
- if (pkgJsonIncludesGeneratedCode(pkgJson)) {
598
- return projectLibraries;
599
- } else {
600
- return [
601
- ...projectLibraries,
602
- ...findExternalLibraries(pkgJson, projectRoot),
603
- ...findLibrariesFromReactNativeConfig(projectRoot),
604
- ];
605
- }
606
- }
607
-
608
- function generateCustomURLHandlers(libraries, outputDir) {
609
- const customImageURLLoaderClasses = libraries
610
- .flatMap(
611
- library =>
612
- library?.config?.ios?.modulesConformingToProtocol?.RCTImageURLLoader,
613
- )
614
- .filter(Boolean)
615
- .map(className => `@"${className}"`)
616
- .join(',\n\t\t');
617
-
618
- const customImageDataDecoderClasses = libraries
619
- .flatMap(
620
- library =>
621
- library?.config?.ios?.modulesConformingToProtocol?.RCTImageDataDecoder,
622
- )
623
- .filter(Boolean)
624
- .map(className => `@"${className}"`)
625
- .join(',\n\t\t');
626
-
627
- const customURLHandlerClasses = libraries
628
- .flatMap(
629
- library =>
630
- library?.config?.ios?.modulesConformingToProtocol?.RCTURLRequestHandler,
631
- )
632
- .filter(Boolean)
633
- .map(className => `@"${className}"`)
634
- .join(',\n\t\t');
635
-
636
- const template = fs.readFileSync(MODULES_PROTOCOLS_MM_TEMPLATE_PATH, 'utf8');
637
- const finalMMFile = template
638
- .replace(/{imageURLLoaderClassNames}/, customImageURLLoaderClasses)
639
- .replace(/{imageDataDecoderClassNames}/, customImageDataDecoderClasses)
640
- .replace(/{requestHandlersClassNames}/, customURLHandlerClasses);
641
-
642
- fs.mkdirSync(outputDir, {recursive: true});
643
-
644
- fs.writeFileSync(
645
- path.join(outputDir, 'RCTModulesConformingToProtocolsProvider.mm'),
646
- finalMMFile,
647
- );
648
-
649
- const templateH = fs.readFileSync(MODULES_PROTOCOLS_H_TEMPLATE_PATH, 'utf8');
650
- fs.writeFileSync(
651
- path.join(outputDir, 'RCTModulesConformingToProtocolsProvider.h'),
652
- templateH,
653
- );
654
- }
655
-
656
- function generateAppDependencyProvider(outputDir) {
657
- fs.mkdirSync(outputDir, {recursive: true});
658
- codegenLog('Generating RCTAppDependencyProvider');
659
-
660
- const templateH = fs.readFileSync(
661
- APP_DEPENDENCY_PROVIDER_H_TEMPLATE_PATH,
662
- 'utf8',
663
- );
664
- const finalPathH = path.join(outputDir, 'RCTAppDependencyProvider.h');
665
- fs.writeFileSync(finalPathH, templateH);
666
- codegenLog(`Generated artifact: ${finalPathH}`);
667
-
668
- const templateMM = fs.readFileSync(
669
- APP_DEPENDENCY_PROVIDER_MM_TEMPLATE_PATH,
670
- 'utf8',
671
- );
672
- const finalPathMM = path.join(outputDir, 'RCTAppDependencyProvider.mm');
673
- fs.writeFileSync(finalPathMM, templateMM);
674
- codegenLog(`Generated artifact: ${finalPathMM}`);
675
-
676
- // Generate the podspec file
677
- const templatePodspec = fs
678
- .readFileSync(APP_DEPENDENCY_PROVIDER_PODSPEC_TEMPLATE_PATH, 'utf8')
679
- .replace(/{react-native-version}/, packageJson.version)
680
- .replace(/{react-native-licence}/, packageJson.license);
681
- const finalPathPodspec = path.join(
682
- outputDir,
683
- 'ReactAppDependencyProvider.podspec',
684
- );
685
- fs.writeFileSync(finalPathPodspec, templatePodspec);
686
- codegenLog(`Generated podspec: ${finalPathPodspec}`);
687
- }
688
-
689
- function generateRCTThirdPartyComponents(libraries, outputDir) {
690
- fs.mkdirSync(outputDir, {recursive: true});
691
- // Generate Header File
692
- codegenLog('Generating RCTThirdPartyComponentsProvider.h');
693
- const templateH = fs.readFileSync(
694
- THIRD_PARTY_COMPONENTS_H_TEMPLATE_PATH,
695
- 'utf8',
696
- );
697
- const finalPathH = path.join(outputDir, 'RCTThirdPartyComponentsProvider.h');
698
- fs.writeFileSync(finalPathH, templateH);
699
- codegenLog(`Generated artifact: ${finalPathH}`);
700
-
701
- codegenLog('Generating RCTThirdPartyComponentsProvider.mm');
702
- let componentsInLibraries = {};
703
- libraries.forEach(({config, libraryPath}) => {
704
- if (isReactNativeCoreLibrary(config.name) || config.type === 'modules') {
705
- return;
706
- }
707
-
708
- const libraryName = JSON.parse(
709
- fs.readFileSync(path.join(libraryPath, 'package.json')),
710
- ).name;
711
- if (config.ios?.componentProvider) {
712
- componentsInLibraries[libraryName] = Object.keys(
713
- config.ios?.componentProvider,
714
- ).map(componentName => {
715
- return {
716
- componentName,
717
- className: config.ios?.componentProvider[componentName],
718
- };
719
- });
720
- return;
721
- }
722
- codegenLog(`Crawling ${libraryName} library for components`);
723
- // crawl all files and subdirectories for file with the ".mm" extension
724
- const files = findFilesWithExtension(libraryPath, '.mm');
725
-
726
- const componentsMapping = files
727
- .flatMap(file => findRCTComponentViewProtocolClass(file))
728
- .filter(Boolean);
729
-
730
- if (componentsMapping.length !== 0) {
731
- codegenLog(
732
- `[DEPRECATED] ${libraryName} should add the 'ios.componentProvider' property in their codegenConfig`,
733
- true,
734
- );
735
- }
736
-
737
- componentsInLibraries[libraryName] = componentsMapping;
738
- });
739
-
740
- const thirdPartyComponentsMapping = Object.keys(componentsInLibraries)
741
- .flatMap(library => {
742
- const components = componentsInLibraries[library];
743
- return components.map(({componentName, className}) => {
744
- return `\t\t@"${componentName}": NSClassFromString(@"${className}"), // ${library}`;
745
- });
746
- })
747
- .join('\n');
748
- // Generate implementation file
749
- const templateMM = fs
750
- .readFileSync(THIRD_PARTY_COMPONENTS_MM_TEMPLATE_PATH, 'utf8')
751
- .replace(/{thirdPartyComponentsMapping}/, thirdPartyComponentsMapping);
752
- const finalPathMM = path.join(
753
- outputDir,
754
- 'RCTThirdPartyComponentsProvider.mm',
755
- );
756
- fs.writeFileSync(finalPathMM, templateMM);
757
- codegenLog(`Generated artifact: ${finalPathMM}`);
758
- }
759
-
760
- // Given a path, return the paths of all the files with extension .mm in
761
- // the path dir and all its subdirectories.
762
- function findFilesWithExtension(filePath, extension) {
763
- const files = [];
764
- const dir = fs.readdirSync(filePath);
765
- dir.forEach(file => {
766
- const absolutePath = path.join(filePath, file);
767
- // Exclude files provided by react-native
768
- if (absolutePath.includes(`${path.sep}react-native${path.sep}`)) {
769
- return null;
770
- }
771
-
772
- // Skip hidden folders, that starts with `.`
773
- if (absolutePath.includes(`${path.sep}.`)) {
774
- return null;
775
- }
776
-
777
- if (
778
- fs.existsSync(absolutePath) &&
779
- fs.statSync(absolutePath).isDirectory()
780
- ) {
781
- files.push(...findFilesWithExtension(absolutePath, extension));
782
- } else if (file.endsWith(extension)) {
783
- files.push(absolutePath);
784
- }
785
- });
786
- return files;
787
- }
788
-
789
- // Given a filepath, read the file and look for a string that starts with 'Class<RCTComponentViewProtocol> '
790
- // and ends with 'Cls(void)'. Return the string between the two.
791
- function findRCTComponentViewProtocolClass(filepath) {
792
- const fileContent = fs.readFileSync(filepath, 'utf8');
793
- const regex = /Class<RCTComponentViewProtocol> (.*)Cls\(/;
794
- const match = fileContent.match(regex);
795
- if (match) {
796
- const componentName = match[1];
797
-
798
- // split the file by \n
799
- // remove all the lines before the one that matches the regex above
800
- // find the first return statement after that that ends with .class
801
- // return what's between return and `.class`
802
- const lines = fileContent.split('\n');
803
- const signatureIndex = lines.findIndex(line => regex.test(line));
804
- const returnRegex = /return (.*)\.class/;
805
- const classNameMatch = String(lines.slice(signatureIndex)).match(
806
- returnRegex,
807
- );
808
- if (classNameMatch) {
809
- const className = classNameMatch[1];
810
- codegenLog(`Match found ${componentName} -> ${className}`);
811
- return {
812
- componentName,
813
- className,
814
- };
815
- }
816
-
817
- console.warn(
818
- `Could not find class name for component ${componentName}. Register it manually`,
819
- );
820
- return null;
821
- }
822
- return null;
823
- }
824
-
825
- // It removes all the empty files and empty folders
826
- // it finds, starting from `filepath`, recursively.
827
- //
828
- // This function is needed since, after aligning the codegen between
829
- // iOS and Android, we have to create empty folders in advance and
830
- // we don't know whether they will be populated up until the end of the process.
831
- //
832
- // @parameter filepath: the root path from which we want to remove the empty files and folders.
833
- function cleanupEmptyFilesAndFolders(filepath) {
834
- const stats = fs.statSync(filepath);
835
-
836
- if (stats.isFile() && stats.size === 0) {
837
- fs.rmSync(filepath);
838
- return;
839
- } else if (stats.isFile()) {
840
- return;
841
- }
842
-
843
- const dirContent = fs.readdirSync(filepath);
844
- dirContent.forEach(contentPath =>
845
- cleanupEmptyFilesAndFolders(path.join(filepath, contentPath)),
846
- );
847
-
848
- // The original folder may be filled with empty folders
849
- // if that the case, we would also like to remove the parent.
850
- // Hence, we need to read the folder again.
851
- const newContent = fs.readdirSync(filepath);
852
- if (newContent.length === 0) {
853
- fs.rmdirSync(filepath);
854
- return;
855
- }
856
- }
857
-
858
- function generateRNCoreComponentsIOS(projectRoot /*: string */) /*: void*/ {
859
- const ios = 'ios';
860
- buildCodegenIfNeeded();
861
- const pkgJson = readPkgJsonInDirectory(projectRoot);
862
- const rncoreLib = findProjectRootLibraries(pkgJson, projectRoot).filter(
863
- library => library.config.name === 'rncore',
864
- )[0];
865
- if (!rncoreLib) {
866
- throw new Error(
867
- "[Codegen] Can't find rncore library. Failed to generate rncore artifacts",
868
- );
869
- }
870
- const rncoreSchemaInfo = generateSchemaInfo(rncoreLib, ios);
871
- generateCode('', rncoreSchemaInfo, false, ios);
872
- }
873
-
874
- function generateFBReactNativeSpecIOS(projectRoot /*: string */) /*: void*/ {
875
- const ios = 'ios';
876
- buildCodegenIfNeeded();
877
- const pkgJson = readPkgJsonInDirectory(projectRoot);
878
- const fbReactNativeSpecLib = findProjectRootLibraries(
879
- pkgJson,
880
- projectRoot,
881
- ).filter(library => library.config.name === 'FBReactNativeSpec')[0];
882
- if (!fbReactNativeSpecLib) {
883
- throw new Error(
884
- "[Codegen] Can't find FBReactNativeSpec library. Failed to generate rncore artifacts",
885
- );
886
- }
887
- const fbReactNativeSchemaInfo = generateSchemaInfo(fbReactNativeSpecLib, ios);
888
- generateCode('', fbReactNativeSchemaInfo, false, ios);
889
- }
890
-
891
- // Execute
892
-
893
- /**
894
- * This function is the entry point for the codegen. It:
895
- * - reads the package json
896
- * - extracts the libraries
897
- * - setups the CLI to generate the code
898
- * - generate the code
899
- *
900
- * @parameter projectRoot: the directory with the app source code, where the package.json lives.
901
- * @parameter baseOutputPath: the base output path for the CodeGen.
902
- * @parameter targetPlatform: the target platform. Supported values: 'android', 'ios', 'all'.
903
- * @parameter source: the source that is invoking codegen. Supported values: 'app', 'library'.
904
- * @throws If it can't find a config file for react-native.
905
- * @throws If it can't find a CodeGen configuration in the file.
906
- * @throws If it can't find a cli for the CodeGen.
907
- */
908
- function execute(projectRoot, targetPlatform, baseOutputPath, source) {
909
- try {
910
- codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`);
911
-
912
- const supportedPlatforms = ['android', 'ios'];
913
- if (
914
- targetPlatform !== 'all' &&
915
- !supportedPlatforms.includes(targetPlatform)
916
- ) {
917
- throw new Error(
918
- `Invalid target platform: ${targetPlatform}. Supported values are: ${supportedPlatforms.join(
919
- ', ',
920
- )}, all`,
921
- );
922
- }
923
-
924
- const pkgJson = readPkgJsonInDirectory(projectRoot);
925
-
926
- buildCodegenIfNeeded();
927
-
928
- const libraries = findCodegenEnabledLibraries(pkgJson, projectRoot);
929
-
930
- if (libraries.length === 0) {
931
- codegenLog('No codegen-enabled libraries found.', true);
932
- return;
933
- }
934
-
935
- let platforms =
936
- targetPlatform === 'all' ? supportedPlatforms : [targetPlatform];
937
-
938
- for (const platform of platforms) {
939
- const outputPath = computeOutputPath(
940
- projectRoot,
941
- baseOutputPath,
942
- pkgJson,
943
- platform,
944
- );
945
-
946
- const schemaInfos = generateSchemaInfos(libraries);
947
- generateNativeCode(
948
- outputPath,
949
- schemaInfos.filter(schemaInfo =>
950
- mustGenerateNativeCode(projectRoot, schemaInfo),
951
- ),
952
- pkgJsonIncludesGeneratedCode(pkgJson),
953
- platform,
954
- );
955
-
956
- if (source === 'app') {
957
- // These components are only required by apps, not by libraries
958
- generateRCTThirdPartyComponents(libraries, outputPath);
959
- generateCustomURLHandlers(libraries, outputPath);
960
- generateAppDependencyProvider(outputPath);
961
- }
962
-
963
- cleanupEmptyFilesAndFolders(outputPath);
964
- }
965
- } catch (err) {
966
- codegenLog(err);
967
- process.exitCode = 1;
968
- }
969
-
970
- codegenLog('Done.', true);
971
- return;
972
- }
973
-
974
- module.exports = {
975
- execute,
976
- generateRNCoreComponentsIOS,
977
- generateFBReactNativeSpecIOS,
978
- // exported for testing purposes only:
979
- _extractLibrariesFromJSON: extractLibrariesFromJSON,
980
- _cleanupEmptyFilesAndFolders: cleanupEmptyFilesAndFolders,
981
- _extractSupportedApplePlatforms: extractSupportedApplePlatforms,
982
- };