Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

const fixtures = require('../__fixtures__/fixtures');
const {execute} = require('../generate-artifacts-executor');
const {
generateRCTThirdPartyComponents,
} = require('../generate-artifacts-executor/generateRCTThirdPartyComponents');
const {
extractSupportedApplePlatforms,
} = require('../generate-artifacts-executor/generateSchemaInfos');
Expand All @@ -20,6 +23,7 @@ const {
extractLibrariesFromJSON,
} = require('../generate-artifacts-executor/utils');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');

const rootPath = path.join(__dirname, '../../..');
Expand Down Expand Up @@ -176,6 +180,53 @@ describe('extractSupportedApplePlatforms', () => {
});
});

describe('generateRCTThirdPartyComponents', () => {
it('crawls component libraries without an iOS config', () => {
const libraryPath = fs.mkdtempSync(
path.join(os.tmpdir(), 'react-native-codegen-'),
);
const outputDir = path.join(libraryPath, 'output');

fs.writeFileSync(
path.join(libraryPath, 'package.json'),
JSON.stringify({name: 'component-library'}),
);
fs.writeFileSync(
path.join(libraryPath, 'ExampleComponent.mm'),
`Class<RCTComponentViewProtocol> ExampleComponentCls(void) {
return RCTExampleComponent.class;
}
`,
);

try {
generateRCTThirdPartyComponents(
[
{
config: {
name: 'ComponentLibraryConfig',
type: 'components',
jsSrcsDir: 'src',
},
libraryPath,
},
],
outputDir,
);

const generatedFile = fs.readFileSync(
path.join(outputDir, 'RCTThirdPartyComponentsProvider.mm'),
'utf8',
);
expect(generatedFile).toContain(
'@"ExampleComponent": NSClassFromString(@"RCTExampleComponent"), // component-library',
);
} finally {
fs.rmSync(libraryPath, {recursive: true, force: true});
}
});
});

describe('delete empty files and folders', () => {
beforeEach(() => {
jest.resetModules();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,18 @@ function parseiOSAnnotations(
const map = {};

for (const library of libraries) {
const iosConfig = library?.config?.ios;
if (!iosConfig) {
continue;
}

const libraryName = getLibraryName(library);
map[libraryName] = map[libraryName] || {
library,
modules: {},
components: {},
};

const iosConfig = library?.config?.ios;
if (!iosConfig) {
continue;
}

const {modules, components} = iosConfig;
if (modules) {
for (const [moduleName, annotation] of Object.entries(modules)) {
Expand Down
Loading