mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
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
This commit is contained in:
1 parent
834721f124
commit
f46ace878a
3 files changed
+41
-2
No files matched your search
+38
@@ -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<string>, _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');
|
||||
}
|
||||
});
|
||||
});
|
||||
+2
-1
@@ -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(
|
||||
|
||||
@@ -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 =>
|
||||
|
||||
Reference in new issue
Block a user