@react-native/codegen 0.74.0-nightly-20231122-d4399c5f1 → 0.74.0-nightly-20231124-c464b215e

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.
@@ -16,8 +16,9 @@ const _require = require('./combine-js-to-schema'),
16
16
  _require.combineSchemasInFileListAndWriteToFile;
17
17
  const _require2 = require('./combine-utils'),
18
18
  parseArgs = _require2.parseArgs;
19
- const _parseArgs = parseArgs(process.argv),
20
- platform = _parseArgs.platform,
21
- outfile = _parseArgs.outfile,
22
- fileList = _parseArgs.fileList;
23
- combineSchemasInFileListAndWriteToFile(fileList, platform, outfile);
19
+ const parsedArgs = parseArgs(process.argv);
20
+ const platform = parsedArgs.platform,
21
+ outfile = parsedArgs.outfile,
22
+ fileList = parsedArgs.fileList,
23
+ exclude = parsedArgs.exclude;
24
+ combineSchemasInFileListAndWriteToFile(fileList, platform, outfile, exclude);
@@ -16,6 +16,8 @@ const {
16
16
  } = require('./combine-js-to-schema');
17
17
  const {parseArgs} = require('./combine-utils');
18
18
 
19
- const {platform, outfile, fileList} = parseArgs(process.argv);
19
+ const parsedArgs = parseArgs(process.argv);
20
20
 
21
- combineSchemasInFileListAndWriteToFile(fileList, platform, outfile);
21
+ const {platform, outfile, fileList, exclude} = parsedArgs;
22
+
23
+ combineSchemasInFileListAndWriteToFile(fileList, platform, outfile, exclude);
@@ -110,7 +110,7 @@ function combineSchemas(files) {
110
110
  },
111
111
  );
112
112
  }
113
- function expandDirectoriesIntoFiles(fileList, platform) {
113
+ function expandDirectoriesIntoFiles(fileList, platform, exclude) {
114
114
  return fileList
115
115
  .flatMap(file => {
116
116
  if (!fs.lstatSync(file).isDirectory()) {
@@ -125,10 +125,14 @@ function expandDirectoriesIntoFiles(fileList, platform) {
125
125
  // windowsPathsNoEscape: true,
126
126
  });
127
127
  })
128
- .filter(element => filterJSFile(element, platform));
128
+ .filter(element => filterJSFile(element, platform, exclude));
129
129
  }
130
- function combineSchemasInFileList(fileList, platform) {
131
- const expandedFileList = expandDirectoriesIntoFiles(fileList, platform);
130
+ function combineSchemasInFileList(fileList, platform, exclude) {
131
+ const expandedFileList = expandDirectoriesIntoFiles(
132
+ fileList,
133
+ platform,
134
+ exclude,
135
+ );
132
136
  const combined = combineSchemas(expandedFileList);
133
137
  if (Object.keys(combined.modules).length === 0) {
134
138
  console.error(
@@ -137,8 +141,13 @@ function combineSchemasInFileList(fileList, platform) {
137
141
  }
138
142
  return combined;
139
143
  }
140
- function combineSchemasInFileListAndWriteToFile(fileList, platform, outfile) {
141
- const combined = combineSchemasInFileList(fileList, platform);
144
+ function combineSchemasInFileListAndWriteToFile(
145
+ fileList,
146
+ platform,
147
+ outfile,
148
+ exclude,
149
+ ) {
150
+ const combined = combineSchemasInFileList(fileList, platform, exclude);
142
151
  const formattedSchema = JSON.stringify(combined, null, 2);
143
152
  fs.writeFileSync(outfile, formattedSchema);
144
153
  }
@@ -51,6 +51,7 @@ function combineSchemas(files: Array<string>): SchemaType {
51
51
  function expandDirectoriesIntoFiles(
52
52
  fileList: Array<string>,
53
53
  platform: ?string,
54
+ exclude: ?RegExp,
54
55
  ): Array<string> {
55
56
  return fileList
56
57
  .flatMap(file => {
@@ -66,14 +67,19 @@ function expandDirectoriesIntoFiles(
66
67
  // windowsPathsNoEscape: true,
67
68
  });
68
69
  })
69
- .filter(element => filterJSFile(element, platform));
70
+ .filter(element => filterJSFile(element, platform, exclude));
70
71
  }
71
72
 
72
73
  function combineSchemasInFileList(
73
74
  fileList: Array<string>,
74
75
  platform: ?string,
76
+ exclude: ?RegExp,
75
77
  ): SchemaType {
76
- const expandedFileList = expandDirectoriesIntoFiles(fileList, platform);
78
+ const expandedFileList = expandDirectoriesIntoFiles(
79
+ fileList,
80
+ platform,
81
+ exclude,
82
+ );
77
83
  const combined = combineSchemas(expandedFileList);
78
84
  if (Object.keys(combined.modules).length === 0) {
79
85
  console.error(
@@ -87,8 +93,9 @@ function combineSchemasInFileListAndWriteToFile(
87
93
  fileList: Array<string>,
88
94
  platform: ?string,
89
95
  outfile: string,
96
+ exclude: ?RegExp,
90
97
  ): void {
91
- const combined = combineSchemasInFileList(fileList, platform);
98
+ const combined = combineSchemasInFileList(fileList, platform, exclude);
92
99
  const formattedSchema = JSON.stringify(combined, null, 2);
93
100
  fs.writeFileSync(outfile, formattedSchema);
94
101
  }
@@ -0,0 +1,78 @@
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
+ 'use strict';
12
+
13
+ const assert = require('assert');
14
+ const fs = require('fs');
15
+ const util = require('util');
16
+ const _util$parseArgs = util.parseArgs({
17
+ options: {
18
+ platform: {
19
+ type: 'string',
20
+ },
21
+ output: {
22
+ type: 'string',
23
+ },
24
+ ['schema-query']: {
25
+ type: 'string',
26
+ },
27
+ },
28
+ }),
29
+ args = _util$parseArgs.values;
30
+ if (!['iOS', 'android'].includes(args.platform)) {
31
+ throw new Error(`Invalid platform ${args.platform}`);
32
+ }
33
+ const platform = args.platform;
34
+ const output = args.output;
35
+ const schemaQuery = args['schema-query'];
36
+ if (!schemaQuery.startsWith('@')) {
37
+ throw new Error(
38
+ "The argument provided to --schema-query must be a filename that starts with '@'.",
39
+ );
40
+ }
41
+ const schemaQueryOutputFile = schemaQuery.replace(/^@/, '');
42
+ const schemaQueryOutput = fs.readFileSync(schemaQueryOutputFile, 'utf8');
43
+ const schemaFiles = schemaQueryOutput.split(' ');
44
+ const modules = {};
45
+ const specNameToFile = {};
46
+ for (const file of schemaFiles) {
47
+ const schema = JSON.parse(fs.readFileSync(file, 'utf8'));
48
+ if (schema.modules) {
49
+ for (const specName in schema.modules) {
50
+ const module = schema.modules[specName];
51
+ if (modules[specName]) {
52
+ assert.deepEqual(
53
+ module,
54
+ modules[specName],
55
+ `App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`,
56
+ );
57
+ }
58
+ if (
59
+ module.excludedPlatforms &&
60
+ module.excludedPlatforms.indexOf(platform) >= 0
61
+ ) {
62
+ continue;
63
+ }
64
+ modules[specName] = module;
65
+ specNameToFile[specName] = file;
66
+ }
67
+ }
68
+ }
69
+ fs.writeFileSync(
70
+ output,
71
+ JSON.stringify(
72
+ {
73
+ modules,
74
+ },
75
+ null,
76
+ 2,
77
+ ),
78
+ );
@@ -0,0 +1,85 @@
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-local
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ import type {
14
+ ComponentSchema,
15
+ NativeModuleSchema,
16
+ SchemaType,
17
+ } from '../../CodegenSchema.js';
18
+
19
+ const assert = require('assert');
20
+ const fs = require('fs');
21
+ const util = require('util');
22
+
23
+ const {values: args} = util.parseArgs({
24
+ options: {
25
+ platform: {
26
+ type: 'string',
27
+ },
28
+ output: {
29
+ type: 'string',
30
+ },
31
+ ['schema-query']: {
32
+ type: 'string',
33
+ },
34
+ },
35
+ });
36
+ if (!['iOS', 'android'].includes(args.platform)) {
37
+ throw new Error(`Invalid platform ${args.platform}`);
38
+ }
39
+ const platform = args.platform;
40
+ const output = args.output;
41
+ const schemaQuery: string = args['schema-query'];
42
+
43
+ if (!schemaQuery.startsWith('@')) {
44
+ throw new Error(
45
+ "The argument provided to --schema-query must be a filename that starts with '@'.",
46
+ );
47
+ }
48
+
49
+ const schemaQueryOutputFile = schemaQuery.replace(/^@/, '');
50
+ const schemaQueryOutput = fs.readFileSync(schemaQueryOutputFile, 'utf8');
51
+
52
+ const schemaFiles = schemaQueryOutput.split(' ');
53
+ const modules: {
54
+ [hasteModuleName: string]: NativeModuleSchema | ComponentSchema,
55
+ } = {};
56
+ const specNameToFile: {[hasteModuleName: string]: string} = {};
57
+
58
+ for (const file of schemaFiles) {
59
+ const schema: SchemaType = JSON.parse(fs.readFileSync(file, 'utf8'));
60
+
61
+ if (schema.modules) {
62
+ for (const specName in schema.modules) {
63
+ const module = schema.modules[specName];
64
+ if (modules[specName]) {
65
+ assert.deepEqual(
66
+ module,
67
+ modules[specName],
68
+ `App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`,
69
+ );
70
+ }
71
+
72
+ if (
73
+ module.excludedPlatforms &&
74
+ module.excludedPlatforms.indexOf(platform) >= 0
75
+ ) {
76
+ continue;
77
+ }
78
+
79
+ modules[specName] = module;
80
+ specNameToFile[specName] = file;
81
+ }
82
+ }
83
+ }
84
+
85
+ fs.writeFileSync(output, JSON.stringify({modules}, null, 2));
@@ -49,26 +49,34 @@ function _arrayWithHoles(arr) {
49
49
  if (Array.isArray(arr)) return arr;
50
50
  }
51
51
  const path = require('path');
52
+ const util = require('util');
52
53
  function parseArgs(args) {
53
- if (args.length > 2 && ['-p', '--platform'].indexOf(args[2]) >= 0) {
54
- const _args$slice = args.slice(4),
55
- _args$slice2 = _toArray(_args$slice),
56
- outfile = _args$slice2[0],
57
- fileList = _args$slice2.slice(1);
58
- return {
59
- platform: args[3],
60
- outfile,
61
- fileList,
62
- };
63
- }
64
- const _args$slice3 = args.slice(2),
65
- _args$slice4 = _toArray(_args$slice3),
66
- outfile = _args$slice4[0],
67
- fileList = _args$slice4.slice(1);
54
+ const parsedArgs = util.parseArgs({
55
+ args: args.slice(2),
56
+ options: {
57
+ platform: {
58
+ short: 'p',
59
+ type: 'string',
60
+ },
61
+ exclude: {
62
+ short: 'e',
63
+ type: 'string',
64
+ },
65
+ },
66
+ allowPositionals: true,
67
+ });
68
+ const _parsedArgs$values = parsedArgs.values,
69
+ platform = _parsedArgs$values.platform,
70
+ exclude = _parsedArgs$values.exclude,
71
+ files = parsedArgs.positionals;
72
+ const _files = _toArray(files),
73
+ outfile = _files[0],
74
+ fileList = _files.slice(1);
68
75
  return {
69
- platform: null,
76
+ platform: platform !== null && platform !== void 0 ? platform : null,
70
77
  outfile,
71
78
  fileList,
79
+ exclude: exclude != null && exclude !== '' ? new RegExp(exclude) : null,
72
80
  };
73
81
  }
74
82
 
@@ -80,18 +88,16 @@ function parseArgs(args) {
80
88
  * Returns: `true` if the file can be used to generate some code; `false` otherwise
81
89
  *
82
90
  */
83
- function filterJSFile(file, currentPlatform) {
91
+ function filterJSFile(file, currentPlatform, excludeRegExp) {
84
92
  const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
85
93
  const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
86
- const isNotNativeSampleTurboModule = !file.endsWith(
87
- 'NativeSampleTurboModule.js',
88
- );
89
94
  const isNotTest = !file.includes('__tests');
95
+ const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(file);
90
96
  const isNotTSTypeDefinition = !file.endsWith('.d.ts');
91
97
  const isValidCandidate =
92
98
  isSpecFile &&
93
99
  isNotNativeUIManager &&
94
- isNotNativeSampleTurboModule &&
100
+ isNotExcluded &&
95
101
  isNotTest &&
96
102
  isNotTSTypeDefinition;
97
103
  const filenameComponents = path.basename(file).split('.');
@@ -12,26 +12,41 @@
12
12
  'use strict';
13
13
 
14
14
  const path = require('path');
15
+ const util = require('util');
15
16
 
16
17
  function parseArgs(args: string[]): {
17
18
  platform: ?string,
18
19
  outfile: string,
19
20
  fileList: string[],
21
+ exclude: ?RegExp,
20
22
  } {
21
- if (args.length > 2 && ['-p', '--platform'].indexOf(args[2]) >= 0) {
22
- const [outfile, ...fileList] = args.slice(4);
23
- return {
24
- platform: args[3],
25
- outfile,
26
- fileList,
27
- };
28
- }
23
+ const parsedArgs = util.parseArgs({
24
+ args: args.slice(2),
25
+ options: {
26
+ platform: {
27
+ short: 'p',
28
+ type: 'string',
29
+ },
30
+ exclude: {
31
+ short: 'e',
32
+ type: 'string',
33
+ },
34
+ },
35
+ allowPositionals: true,
36
+ });
37
+
38
+ const {
39
+ values: {platform, exclude},
40
+ positionals: files,
41
+ } = parsedArgs;
42
+
43
+ const [outfile, ...fileList] = files;
29
44
 
30
- const [outfile, ...fileList] = args.slice(2);
31
45
  return {
32
- platform: null,
46
+ platform: platform ?? null,
33
47
  outfile,
34
48
  fileList,
49
+ exclude: exclude != null && exclude !== '' ? new RegExp(exclude) : null,
35
50
  };
36
51
  }
37
52
 
@@ -43,19 +58,21 @@ function parseArgs(args: string[]): {
43
58
  * Returns: `true` if the file can be used to generate some code; `false` otherwise
44
59
  *
45
60
  */
46
- function filterJSFile(file: string, currentPlatform: ?string): boolean {
61
+ function filterJSFile(
62
+ file: string,
63
+ currentPlatform: ?string,
64
+ excludeRegExp: ?RegExp,
65
+ ): boolean {
47
66
  const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
48
67
  const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
49
- const isNotNativeSampleTurboModule = !file.endsWith(
50
- 'NativeSampleTurboModule.js',
51
- );
52
68
  const isNotTest = !file.includes('__tests');
69
+ const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(file);
53
70
  const isNotTSTypeDefinition = !file.endsWith('.d.ts');
54
71
 
55
72
  const isValidCandidate =
56
73
  isSpecFile &&
57
74
  isNotNativeUIManager &&
58
- isNotNativeSampleTurboModule &&
75
+ isNotExcluded &&
59
76
  isNotTest &&
60
77
  isNotTSTypeDefinition;
61
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/codegen",
3
- "version": "0.74.0-nightly-20231122-d4399c5f1",
3
+ "version": "0.74.0-nightly-20231124-c464b215e",
4
4
  "description": "Code generation tools for React Native",
5
5
  "license": "MIT",
6
6
  "repository": {