From f46ace878a004e17b07d00dbd035d92a1ad5900c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Van=20der=20Auwermeulen=20Gr=C3=A9goire?= Date: Fri, 24 Jul 2026 18:19:19 -0700 Subject: [PATCH] codegen: ios platform extensions (#57189) Summary: Currently codegen doesn't pass the platform file extension. This makes it possible to use `NativeModule.ios.ts` and will generate obj-c++ spec files. Root cause: `generateSchemaInfos` called `libraries.map(generateSchemaInfo)`, so `Array.map` passed the array index as the `platform` argument (0, 1, 2, ...) instead of the real platform. That value flows into `combineSchemasInFileList`, which uses it to resolve platform-specific sources, so `.ios.ts` extensions never resolved. This threads the real platform from the per-platform loop in `execute()` through to `generateSchemaInfo`. Changelog: [General] [Fixed] - Codegen: pass the target platform when generating schemas so platform-specific sources (e.g. `NativeModule.ios.ts`) resolve correctly Pull Request resolved: https://github.com/react/react-native/pull/57189 Test Plan: Added a regression test in `generate-artifacts-executor-test.js`: it mocks `combineSchemasInFileList` and asserts `generateSchemaInfos(libraries, 'ios')` forwards `'ios'` (not the array index) for every library. `arc lint` clean; the jest suite runs in CI. Reviewed By: christophpurrer Differential Revision: D113573175 Pulled By: fabriziocucci fbshipit-source-id: 251a22d5cde07fbb76fab1abb10f4fcbcc5c9302 --- .../generate-artifacts-executor-test.js | 38 +++++++++++++++++++ .../generateSchemaInfos.js | 3 +- .../generate-artifacts-executor/index.js | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js index 9c19157e3a5..fa51aebd281 100644 --- a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js +++ b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js @@ -507,3 +507,41 @@ describe('findFilesWithExtension', () => { ]); }); }); + +describe('generateSchemaInfos', () => { + beforeEach(() => { + jest.resetModules(); + }); + + it('forwards the platform (not the array map index) to combineSchemasInFileList', () => { + const mockCombineSchemasInFileList = jest.fn( + (_files: ReadonlyArray, _platform: string) => ({}), + ); + jest.mock('../codegen-utils', () => ({ + getCombineJSToSchema: () => ({ + combineSchemasInFileList: mockCombineSchemasInFileList, + }), + })); + // Avoid touching the filesystem for podspec discovery. + jest.mock('tinyglobby', () => ({globSync: () => []})); + + const { + generateSchemaInfos, + } = require('../generate-artifacts-executor/generateSchemaInfos'); + + const libraries = [ + {config: {name: 'LibA', jsSrcsDir: 'src'}, libraryPath: '/tmp/libA'}, + {config: {name: 'LibB', jsSrcsDir: 'src'}, libraryPath: '/tmp/libB'}, + ]; + + generateSchemaInfos(libraries, 'ios'); + + // Regression guard: previously `libraries.map(generateSchemaInfo)` handed the + // array index to generateSchemaInfo as the platform. Every call must receive + // the real platform string instead. + expect(mockCombineSchemasInFileList).toHaveBeenCalledTimes(2); + for (const call of mockCombineSchemasInFileList.mock.calls) { + expect(call[1]).toBe('ios'); + } + }); +}); diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js index 0b053103b91..64186454841 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/generateSchemaInfos.js @@ -18,9 +18,10 @@ const {globSync} = require('tinyglobby'); function generateSchemaInfos( libraries /*: ReadonlyArray<$FlowFixMe> */, + platform /*: string */, ) /*: Array<$FlowFixMe> */ { // $FlowFixMe[incompatible-type] - return libraries.map(generateSchemaInfo); + return libraries.map(library => generateSchemaInfo(library, platform)); } function generateSchemaInfo( diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js index 7ce38a55a88..553af035a48 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/index.js @@ -139,7 +139,7 @@ function execute( : path.join(outputPath, 'ReactCodegen'); if (runReactNativeCodegen) { - const schemaInfos = generateSchemaInfos(libraries); + const schemaInfos = generateSchemaInfos(libraries, platform); generateNativeCode( reactCodegenOutputPath, schemaInfos.filter(schemaInfo =>