Skip to content

Commit 0448cf2

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Support .fb Suffix in Native Codegen (#50140)
Summary: Pull Request resolved: #50140 Extends `react-native-codegen` to support the `.fb` filename suffix used to gate source code that is only relevant for Meta internal use cases. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D70808462 fbshipit-source-id: a6772d6504f76724b8474df6799bc69a76a2f81b
1 parent 4de5927 commit 0448cf2

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function expandDirectoriesIntoFiles(
5959
return [file];
6060
}
6161
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
62-
return glob.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
62+
return glob.sync(`${filePattern}/**/*{,.fb}.{js,ts,tsx}`, {
6363
nodir: true,
6464
// TODO: This will remove the need of slash substitution above for Windows,
6565
// but it requires glob@v9+; with the package currenlty relying on

packages/react-native-codegen/src/cli/combine/combine-utils.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,28 @@
1414
const path = require('path');
1515

1616
/**
17-
* This function is used by the CLI to decide whether a JS/TS file has to be processed or not by the Codegen.
18-
* Parameters:
19-
* - file: the path to the file
20-
* - currentPlatform: the current platform for which we are creating the specs
21-
* Returns: `true` if the file can be used to generate some code; `false` otherwise
17+
* This function is used by the CLI to decide whether a JS/TS file has to be
18+
* processed or not by the Codegen.
2219
*
20+
* Parameters:
21+
* - originalFilePath: the path to the file
22+
* - currentPlatform: the platform for which we are creating the specs
23+
* Returns: `true` if the file can be used to generate code; `false` otherwise
2324
*/
2425
function filterJSFile(
25-
file: string,
26+
originalFilePath: string,
2627
currentPlatform: ?string,
2728
excludeRegExp: ?RegExp,
2829
): boolean {
29-
const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
30-
const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
31-
const isNotTest = !file.includes('__tests');
32-
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(file);
33-
const isNotTSTypeDefinition = !file.endsWith('.d.ts');
30+
// Remove `.fb` if it exists (see `react-native.cconf`).
31+
const filePath = originalFilePath.replace(/\.fb(\.|$)/, '$1');
32+
const basename = path.basename(filePath);
33+
34+
const isSpecFile = /^(Native.+|.+NativeComponent)/.test(basename);
35+
const isNotNativeUIManager = !filePath.endsWith('NativeUIManager.js');
36+
const isNotTest = !filePath.includes('__tests');
37+
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(filePath);
38+
const isNotTSTypeDefinition = !filePath.endsWith('.d.ts');
3439

3540
const isValidCandidate =
3641
isSpecFile &&
@@ -39,7 +44,7 @@ function filterJSFile(
3944
isNotTest &&
4045
isNotTSTypeDefinition;
4146

42-
const filenameComponents = path.basename(file).split('.');
47+
const filenameComponents = basename.split('.');
4348
const isPlatformAgnostic = filenameComponents.length === 2;
4449

4550
if (currentPlatform == null) {

0 commit comments

Comments
 (0)