Skip to content

Commit 08fd9cc

Browse files
committed
Fix iOS codegen fallback for libraries without config
1 parent 8e995e8 commit 08fd9cc

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
const fixtures = require('../__fixtures__/fixtures');
1414
const {execute} = require('../generate-artifacts-executor');
15+
const {
16+
generateRCTThirdPartyComponents,
17+
} = require('../generate-artifacts-executor/generateRCTThirdPartyComponents');
1518
const {
1619
extractSupportedApplePlatforms,
1720
} = require('../generate-artifacts-executor/generateSchemaInfos');
@@ -20,6 +23,7 @@ const {
2023
extractLibrariesFromJSON,
2124
} = require('../generate-artifacts-executor/utils');
2225
const fs = require('node:fs');
26+
const os = require('node:os');
2327
const path = require('node:path');
2428

2529
const rootPath = path.join(__dirname, '../../..');
@@ -176,6 +180,53 @@ describe('extractSupportedApplePlatforms', () => {
176180
});
177181
});
178182

183+
describe('generateRCTThirdPartyComponents', () => {
184+
it('crawls component libraries without an iOS config', () => {
185+
const libraryPath = fs.mkdtempSync(
186+
path.join(os.tmpdir(), 'react-native-codegen-'),
187+
);
188+
const outputDir = path.join(libraryPath, 'output');
189+
190+
fs.writeFileSync(
191+
path.join(libraryPath, 'package.json'),
192+
JSON.stringify({name: 'component-library'}),
193+
);
194+
fs.writeFileSync(
195+
path.join(libraryPath, 'ExampleComponent.mm'),
196+
`Class<RCTComponentViewProtocol> ExampleComponentCls(void) {
197+
return RCTExampleComponent.class;
198+
}
199+
`,
200+
);
201+
202+
try {
203+
generateRCTThirdPartyComponents(
204+
[
205+
{
206+
config: {
207+
name: 'ComponentLibraryConfig',
208+
type: 'components',
209+
jsSrcsDir: 'src',
210+
},
211+
libraryPath,
212+
},
213+
],
214+
outputDir,
215+
);
216+
217+
const generatedFile = fs.readFileSync(
218+
path.join(outputDir, 'RCTThirdPartyComponentsProvider.mm'),
219+
'utf8',
220+
);
221+
expect(generatedFile).toContain(
222+
'@"ExampleComponent": NSClassFromString(@"RCTExampleComponent"), // component-library',
223+
);
224+
} finally {
225+
fs.rmSync(libraryPath, {recursive: true, force: true});
226+
}
227+
});
228+
});
229+
179230
describe('delete empty files and folders', () => {
180231
beforeEach(() => {
181232
jest.resetModules();

packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,18 @@ function parseiOSAnnotations(
396396
const map = {};
397397

398398
for (const library of libraries) {
399-
const iosConfig = library?.config?.ios;
400-
if (!iosConfig) {
401-
continue;
402-
}
403-
404399
const libraryName = getLibraryName(library);
405400
map[libraryName] = map[libraryName] || {
406401
library,
407402
modules: {},
408403
components: {},
409404
};
410405

406+
const iosConfig = library?.config?.ios;
407+
if (!iosConfig) {
408+
continue;
409+
}
410+
411411
const {modules, components} = iosConfig;
412412
if (modules) {
413413
for (const [moduleName, annotation] of Object.entries(modules)) {

0 commit comments

Comments
 (0)