@react-native/codegen 0.74.0-nightly-20240122-4e92f87df → 0.74.0-nightly-20240124-ccff2bb8d

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.
@@ -222,20 +222,25 @@ module.exports = {
222
222
  }
223
223
  return checkOrWriteFiles(generatedFiles, test);
224
224
  },
225
- generateFromSchemas({schemas, outputDirectory}, {generators, test}) {
225
+ generateFromSchemas(
226
+ {schemas, outputDirectory, supportedApplePlatforms},
227
+ {generators, test},
228
+ ) {
226
229
  Object.keys(schemas).forEach(libraryName =>
227
230
  schemaValidator.validate(schemas[libraryName]),
228
231
  );
229
232
  const generatedFiles = [];
230
233
  for (const name of generators) {
231
234
  for (const generator of SCHEMAS_GENERATORS[name]) {
232
- generator(schemas).forEach((contents, fileName) => {
233
- generatedFiles.push({
234
- name: fileName,
235
- content: contents,
236
- outputDir: outputDirectory,
237
- });
238
- });
235
+ generator(schemas, supportedApplePlatforms).forEach(
236
+ (contents, fileName) => {
237
+ generatedFiles.push({
238
+ name: fileName,
239
+ content: contents,
240
+ outputDir: outputDirectory,
241
+ });
242
+ },
243
+ );
239
244
  }
240
245
  }
241
246
  return checkOrWriteFiles(generatedFiles, test);
@@ -83,6 +83,7 @@ type LibraryOptions = $ReadOnly<{
83
83
  type SchemasOptions = $ReadOnly<{
84
84
  schemas: {[string]: SchemaType},
85
85
  outputDirectory: string,
86
+ supportedApplePlatforms?: {[string]: {[string]: boolean}},
86
87
  }>;
87
88
 
88
89
  type LibraryGenerators =
@@ -289,7 +290,7 @@ module.exports = {
289
290
  return checkOrWriteFiles(generatedFiles, test);
290
291
  },
291
292
  generateFromSchemas(
292
- {schemas, outputDirectory}: SchemasOptions,
293
+ {schemas, outputDirectory, supportedApplePlatforms}: SchemasOptions,
293
294
  {generators, test}: SchemasConfig,
294
295
  ): boolean {
295
296
  Object.keys(schemas).forEach(libraryName =>
@@ -300,13 +301,15 @@ module.exports = {
300
301
 
301
302
  for (const name of generators) {
302
303
  for (const generator of SCHEMAS_GENERATORS[name]) {
303
- generator(schemas).forEach((contents: string, fileName: string) => {
304
- generatedFiles.push({
305
- name: fileName,
306
- content: contents,
307
- outputDir: outputDirectory,
308
- });
309
- });
304
+ generator(schemas, supportedApplePlatforms).forEach(
305
+ (contents: string, fileName: string) => {
306
+ generatedFiles.push({
307
+ name: fileName,
308
+ content: contents,
309
+ outputDir: outputDirectory,
310
+ });
311
+ },
312
+ );
310
313
  }
311
314
  }
312
315
  return checkOrWriteFiles(generatedFiles, test);
@@ -0,0 +1,46 @@
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
+ *
8
+ * @format
9
+ */
10
+
11
+ const APPLE_PLATFORMS_MACRO_MAP = {
12
+ ios: 'TARGET_OS_IOS',
13
+ macos: 'TARGET_OS_OSX',
14
+ tvos: 'TARGET_OS_TV',
15
+ visionos: 'TARGET_OS_VISION',
16
+ };
17
+
18
+ /**
19
+ * Adds compiler macros to the file template to exclude unsupported platforms.
20
+ */
21
+ function generateSupportedApplePlatformsMacro(
22
+ fileTemplate,
23
+ supportedPlatformsMap,
24
+ ) {
25
+ if (!supportedPlatformsMap) {
26
+ return fileTemplate;
27
+ }
28
+ const compilerMacroString = Object.keys(supportedPlatformsMap)
29
+ .reduce((acc, platform) => {
30
+ if (!supportedPlatformsMap[platform]) {
31
+ return [...acc, `!${APPLE_PLATFORMS_MACRO_MAP[platform]}`];
32
+ }
33
+ return acc;
34
+ }, [])
35
+ .join(' && ');
36
+ if (!compilerMacroString) {
37
+ return fileTemplate;
38
+ }
39
+ return `#if ${compilerMacroString}
40
+ ${fileTemplate}
41
+ #endif
42
+ `;
43
+ }
44
+ module.exports = {
45
+ generateSupportedApplePlatformsMacro,
46
+ };
@@ -0,0 +1,50 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ const APPLE_PLATFORMS_MACRO_MAP = {
12
+ ios: 'TARGET_OS_IOS',
13
+ macos: 'TARGET_OS_OSX',
14
+ tvos: 'TARGET_OS_TV',
15
+ visionos: 'TARGET_OS_VISION',
16
+ };
17
+
18
+ /**
19
+ * Adds compiler macros to the file template to exclude unsupported platforms.
20
+ */
21
+ function generateSupportedApplePlatformsMacro(
22
+ fileTemplate: string,
23
+ supportedPlatformsMap: ?{[string]: boolean},
24
+ ): string {
25
+ if (!supportedPlatformsMap) {
26
+ return fileTemplate;
27
+ }
28
+
29
+ const compilerMacroString = Object.keys(supportedPlatformsMap)
30
+ .reduce((acc: string[], platform) => {
31
+ if (!supportedPlatformsMap[platform]) {
32
+ return [...acc, `!${APPLE_PLATFORMS_MACRO_MAP[platform]}`];
33
+ }
34
+ return acc;
35
+ }, [])
36
+ .join(' && ');
37
+
38
+ if (!compilerMacroString) {
39
+ return fileTemplate;
40
+ }
41
+
42
+ return `#if ${compilerMacroString}
43
+ ${fileTemplate}
44
+ #endif
45
+ `;
46
+ }
47
+
48
+ module.exports = {
49
+ generateSupportedApplePlatformsMacro,
50
+ };
@@ -10,6 +10,10 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ const _require = require('./ComponentsProviderUtils'),
14
+ generateSupportedApplePlatformsMacro =
15
+ _require.generateSupportedApplePlatformsMacro;
16
+
13
17
  // File path -> contents
14
18
 
15
19
  const FileTemplate = ({lookupFuncs}) => `
@@ -52,12 +56,16 @@ const LookupFuncTemplate = ({className, libraryName}) =>
52
56
  Class<RCTComponentViewProtocol> ${className}Cls(void) __attribute__((used)); // ${libraryName}
53
57
  `.trim();
54
58
  module.exports = {
55
- generate(schemas) {
59
+ generate(schemas, supportedApplePlatforms) {
56
60
  const fileName = 'RCTThirdPartyFabricComponentsProvider.h';
57
61
  const lookupFuncs = Object.keys(schemas)
58
62
  .map(libraryName => {
59
63
  const schema = schemas[libraryName];
60
- return Object.keys(schema.modules)
64
+ const librarySupportedApplePlatforms =
65
+ supportedApplePlatforms === null || supportedApplePlatforms === void 0
66
+ ? void 0
67
+ : supportedApplePlatforms[libraryName];
68
+ const generatedLookup = Object.keys(schema.modules)
61
69
  .map(moduleName => {
62
70
  const module = schema.modules[moduleName];
63
71
  if (module.type !== 'Component') {
@@ -86,6 +94,10 @@ module.exports = {
86
94
  })
87
95
  .filter(Boolean)
88
96
  .join('\n');
97
+ return generateSupportedApplePlatformsMacro(
98
+ generatedLookup,
99
+ librarySupportedApplePlatforms,
100
+ );
89
101
  })
90
102
  .join('\n');
91
103
  const replacedTemplate = FileTemplate({
@@ -12,6 +12,10 @@
12
12
 
13
13
  import type {SchemaType} from '../../CodegenSchema';
14
14
 
15
+ const {
16
+ generateSupportedApplePlatformsMacro,
17
+ } = require('./ComponentsProviderUtils');
18
+
15
19
  // File path -> contents
16
20
  type FilesOutput = Map<string, string>;
17
21
 
@@ -63,13 +67,18 @@ Class<RCTComponentViewProtocol> ${className}Cls(void) __attribute__((used)); //
63
67
  `.trim();
64
68
 
65
69
  module.exports = {
66
- generate(schemas: {[string]: SchemaType}): FilesOutput {
70
+ generate(
71
+ schemas: {[string]: SchemaType},
72
+ supportedApplePlatforms?: {[string]: {[string]: boolean}},
73
+ ): FilesOutput {
67
74
  const fileName = 'RCTThirdPartyFabricComponentsProvider.h';
68
75
 
69
76
  const lookupFuncs = Object.keys(schemas)
70
77
  .map(libraryName => {
71
78
  const schema = schemas[libraryName];
72
- return Object.keys(schema.modules)
79
+ const librarySupportedApplePlatforms =
80
+ supportedApplePlatforms?.[libraryName];
81
+ const generatedLookup = Object.keys(schema.modules)
73
82
  .map(moduleName => {
74
83
  const module = schema.modules[moduleName];
75
84
  if (module.type !== 'Component') {
@@ -100,6 +109,11 @@ module.exports = {
100
109
  })
101
110
  .filter(Boolean)
102
111
  .join('\n');
112
+
113
+ return generateSupportedApplePlatformsMacro(
114
+ generatedLookup,
115
+ librarySupportedApplePlatforms,
116
+ );
103
117
  })
104
118
  .join('\n');
105
119
 
@@ -10,6 +10,10 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ const _require = require('./ComponentsProviderUtils'),
14
+ generateSupportedApplePlatformsMacro =
15
+ _require.generateSupportedApplePlatformsMacro;
16
+
13
17
  // File path -> contents
14
18
 
15
19
  const FileTemplate = ({lookupMap}) => `
@@ -49,12 +53,16 @@ ${lookupMap}
49
53
  const LookupMapTemplate = ({className, libraryName}) => `
50
54
  {"${className}", ${className}Cls}, // ${libraryName}`;
51
55
  module.exports = {
52
- generate(schemas) {
56
+ generate(schemas, supportedApplePlatforms) {
53
57
  const fileName = 'RCTThirdPartyFabricComponentsProvider.mm';
54
58
  const lookupMap = Object.keys(schemas)
55
59
  .map(libraryName => {
56
60
  const schema = schemas[libraryName];
57
- return Object.keys(schema.modules)
61
+ const librarySupportedApplePlatforms =
62
+ supportedApplePlatforms === null || supportedApplePlatforms === void 0
63
+ ? void 0
64
+ : supportedApplePlatforms[libraryName];
65
+ const generatedLookup = Object.keys(schema.modules)
58
66
  .map(moduleName => {
59
67
  const module = schema.modules[moduleName];
60
68
  if (module.type !== 'Component') {
@@ -82,7 +90,12 @@ module.exports = {
82
90
  });
83
91
  return componentTemplates.length > 0 ? componentTemplates : null;
84
92
  })
85
- .filter(Boolean);
93
+ .filter(Boolean)
94
+ .join('\n');
95
+ return generateSupportedApplePlatformsMacro(
96
+ generatedLookup,
97
+ librarySupportedApplePlatforms,
98
+ );
86
99
  })
87
100
  .join('\n');
88
101
  const replacedTemplate = FileTemplate({
@@ -12,6 +12,10 @@
12
12
 
13
13
  import type {SchemaType} from '../../CodegenSchema';
14
14
 
15
+ const {
16
+ generateSupportedApplePlatformsMacro,
17
+ } = require('./ComponentsProviderUtils');
18
+
15
19
  // File path -> contents
16
20
  type FilesOutput = Map<string, string>;
17
21
 
@@ -60,13 +64,19 @@ const LookupMapTemplate = ({
60
64
  {"${className}", ${className}Cls}, // ${libraryName}`;
61
65
 
62
66
  module.exports = {
63
- generate(schemas: {[string]: SchemaType}): FilesOutput {
67
+ generate(
68
+ schemas: {[string]: SchemaType},
69
+ supportedApplePlatforms?: {[string]: {[string]: boolean}},
70
+ ): FilesOutput {
64
71
  const fileName = 'RCTThirdPartyFabricComponentsProvider.mm';
65
72
 
66
73
  const lookupMap = Object.keys(schemas)
67
74
  .map(libraryName => {
68
75
  const schema = schemas[libraryName];
69
- return Object.keys(schema.modules)
76
+ const librarySupportedApplePlatforms =
77
+ supportedApplePlatforms?.[libraryName];
78
+
79
+ const generatedLookup = Object.keys(schema.modules)
70
80
  .map(moduleName => {
71
81
  const module = schema.modules[moduleName];
72
82
  if (module.type !== 'Component') {
@@ -98,7 +108,13 @@ module.exports = {
98
108
 
99
109
  return componentTemplates.length > 0 ? componentTemplates : null;
100
110
  })
101
- .filter(Boolean);
111
+ .filter(Boolean)
112
+ .join('\n');
113
+
114
+ return generateSupportedApplePlatformsMacro(
115
+ generatedLookup,
116
+ librarySupportedApplePlatforms,
117
+ );
102
118
  })
103
119
  .join('\n');
104
120
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/codegen",
3
- "version": "0.74.0-nightly-20240122-4e92f87df",
3
+ "version": "0.74.0-nightly-20240124-ccff2bb8d",
4
4
  "description": "Code generation tools for React Native",
5
5
  "license": "MIT",
6
6
  "repository": {