Skip to content

Commit

Permalink
RN: Support .fb Suffix in Native Codegen
Browse files Browse the repository at this point in the history
Summary:
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]

Differential Revision: D70808462
  • Loading branch information
yungsters authored and facebook-github-bot committed Mar 7, 2025
1 parent aa92fa9 commit 632523c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function expandDirectoriesIntoFiles(
return [file];
}
const filePattern = path.sep === '\\' ? file.replace(/\\/g, '/') : file;
return glob.sync(`${filePattern}/**/*.{js,ts,tsx}`, {
return glob.sync(`${filePattern}/**/*{,.fb}.{js,ts,tsx}`, {
nodir: true,
// TODO: This will remove the need of slash substitution above for Windows,
// but it requires glob@v9+; with the package currenlty relying on
Expand Down
29 changes: 17 additions & 12 deletions packages/react-native-codegen/src/cli/combine/combine-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@
const path = require('path');

/**
* This function is used by the CLI to decide whether a JS/TS file has to be processed or not by the Codegen.
* Parameters:
* - file: the path to the file
* - currentPlatform: the current platform for which we are creating the specs
* Returns: `true` if the file can be used to generate some code; `false` otherwise
* This function is used by the CLI to decide whether a JS/TS file has to be
* processed or not by the Codegen.
*
* Parameters:
* - originalFilePath: the path to the file
* - currentPlatform: the platform for which we are creating the specs
* Returns: `true` if the file can be used to generate code; `false` otherwise
*/
function filterJSFile(
file: string,
originalFilePath: string,
currentPlatform: ?string,
excludeRegExp: ?RegExp,
): boolean {
const isSpecFile = /^(Native.+|.+NativeComponent)/.test(path.basename(file));
const isNotNativeUIManager = !file.endsWith('NativeUIManager.js');
const isNotTest = !file.includes('__tests');
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(file);
const isNotTSTypeDefinition = !file.endsWith('.d.ts');
// Remove `.fb` if it exists (see `react-native.cconf`).
const filePath = originalFilePath.replace(/\.fb(\.|$)/, '$1');
const basename = path.basename(filePath);

const isSpecFile = /^(Native.+|.+NativeComponent)/.test(basename);
const isNotNativeUIManager = !filePath.endsWith('NativeUIManager.js');
const isNotTest = !filePath.includes('__tests');
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(filePath);
const isNotTSTypeDefinition = !filePath.endsWith('.d.ts');

const isValidCandidate =
isSpecFile &&
Expand All @@ -39,7 +44,7 @@ function filterJSFile(
isNotTest &&
isNotTSTypeDefinition;

const filenameComponents = path.basename(file).split('.');
const filenameComponents = basename.split('.');
const isPlatformAgnostic = filenameComponents.length === 2;

if (currentPlatform == null) {
Expand Down

0 comments on commit 632523c

Please sign in to comment.