Move build-types config into own module (#50450)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50450

Intends to be reused by the incoming `buildApiSnapshot` behaviour.

Changelog: [Internal]

Reviewed By: iwoplaza

Differential Revision: D72306509

fbshipit-source-id: 9e03c95f2469e10c05bdd0be39d4e217a6cc197f
This commit is contained in:
Alex Hunt
2025-04-03 08:31:23 -07:00
committed by Facebook GitHub Bot
parent 293e89e7f6
commit d32ca8e899
2 changed files with 41 additions and 14 deletions
+4 -14
View File
@@ -10,6 +10,7 @@
*/
const {PACKAGES_DIR, REPO_ROOT} = require('../consts');
const {ENTRY_POINT, IGNORE_PATTERNS, TYPES_OUTPUT_DIR} = require('./config');
const getRequireStack = require('./resolution/getRequireStack');
const translatedModuleTemplate = require('./templates/translatedModule.d.ts-template');
const translateSourceFile = require('./translateSourceFile');
@@ -17,15 +18,6 @@ const {promises: fs} = require('fs');
const micromatch = require('micromatch');
const path = require('path');
const OUTPUT_DIR = 'types_generated';
const IGNORE_PATTERNS = [
'**/__{tests,mocks,fixtures,flowtests}__/**',
'**/*.{macos,windows}.js',
];
const ENTRY_POINTS = ['packages/react-native/index.js.flow'];
/**
* Build generated TypeScript types for react-native.
*
@@ -37,9 +29,7 @@ const ENTRY_POINTS = ['packages/react-native/index.js.flow'];
* along with our own pre and post-processing.
*/
async function buildGeneratedTypes(): Promise<void> {
const files = new Set<string>(
ENTRY_POINTS.map(file => path.join(REPO_ROOT, file)),
);
const files = new Set<string>([path.join(REPO_ROOT, ENTRY_POINT)]);
const translatedFiles = new Set<string>();
const dependencyEdges: DependencyEdges = [];
const allErrors: Array<ModuleTranslationError> = [];
@@ -67,7 +57,7 @@ async function buildGeneratedTypes(): Promise<void> {
await fs.copyFile(
path.join(__dirname, 'templates/tsconfig.json'),
path.join(PACKAGES_DIR, 'react-native', OUTPUT_DIR, 'tsconfig.json'),
path.join(PACKAGES_DIR, 'react-native', TYPES_OUTPUT_DIR, 'tsconfig.json'),
);
if (allErrors.length > 0) {
@@ -133,7 +123,7 @@ function getBuildPath(file: string): string {
return path.join(
packageDir,
file
.replace(packageDir, OUTPUT_DIR)
.replace(packageDir, TYPES_OUTPUT_DIR)
.replace(/\.js\.flow$/, '.js')
.replace(/\.js$/, '.d.ts'),
);
+37
View File
@@ -0,0 +1,37 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/
/**
* The root entry point for type generation (main entry point for the
* react-native package).
*/
const ENTRY_POINT = 'packages/react-native/index.js.flow';
/**
* Ignore patterns for source files that should not be considered for
* translation.
*/
const IGNORE_PATTERNS = [
'**/__{tests,mocks,fixtures,flowtests}__/**',
'**/*.{macos,windows}.js',
];
/**
* The output directory name for generated type definitions in each translated
* package.
*/
const TYPES_OUTPUT_DIR = 'types_generated';
module.exports = {
ENTRY_POINT,
IGNORE_PATTERNS,
TYPES_OUTPUT_DIR,
};