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 @@ -738,3 +738,52 @@ describe('generateSchemaInfos', () => {
}
});
});

describe('execute with codegen', () => {
beforeEach(() => {
jest.resetModules();
});

it('skips the JS sources of libraries that include generated code', () => {
const mockCombineSchemasInFileList = jest.fn(
(_files: ReadonlyArray<string>, _platform: string) => ({}),
);
const mockGenerateNativeCode = jest.fn();
const mockLibraries = [
{config: {name: 'LibA', jsSrcsDir: 'src'}, libraryPath: '/tmp/libA'},
{
config: {name: 'LibB', jsSrcsDir: 'src', includesGeneratedCode: true},
libraryPath: '/tmp/libB',
},
];
jest.mock('../codegen-utils', () => ({
getCombineJSToSchema: () => ({
combineSchemasInFileList: mockCombineSchemasInFileList,
}),
}));
jest.mock('tinyglobby', () => ({globSync: () => []}));
jest.mock('../generate-artifacts-executor/generateNativeCode', () => ({
generateNativeCode: mockGenerateNativeCode,
}));
jest.mock('../generate-artifacts-executor/utils', () => ({
...jest.requireActual('../generate-artifacts-executor/utils'),
buildCodegenIfNeeded: () => {},
cleanupEmptyFilesAndFolders: () => {},
findCodegenEnabledLibraries: () => mockLibraries,
readPkgJsonInDirectory: () => ({}),
readReactNativeConfig: () => ({}),
}));

const {execute: executeCodegen} = require('../generate-artifacts-executor');

executeCodegen('/tmp/app', 'android', '/tmp/app', 'app');

expect(mockCombineSchemasInFileList).toHaveBeenCalledTimes(1);
expect(mockCombineSchemasInFileList.mock.calls[0][0]).toEqual([
path.join('/tmp/libA', 'src'),
]);
expect(mockGenerateNativeCode.mock.calls[0][1]).toEqual([
expect.objectContaining({library: mockLibraries[0]}),
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@ function execute(
: path.join(outputPath, 'ReactCodegen');

if (runReactNativeCodegen) {
const schemaInfos = generateSchemaInfos(libraries, platform);
const schemaInfos = generateSchemaInfos(
libraries.filter(library =>
mustGenerateNativeCode(projectRoot, library),
),
platform,
);
generateNativeCode(
reactCodegenOutputPath,
schemaInfos.filter(schemaInfo =>
mustGenerateNativeCode(projectRoot, schemaInfo),
),
schemaInfos,
pkgJsonIncludesGeneratedCode(pkgJson),
platform,
forceOutputPath,
Expand Down Expand Up @@ -276,14 +279,14 @@ function defaultOutputPathForIOS(baseOutputPath /*: string */) {

function mustGenerateNativeCode(
includeLibraryPath /*: string */,
schemaInfo /*: $FlowFixMe */,
library /*: $FlowFixMe */,
) {
// If library's 'codegenConfig' sets 'includesGeneratedCode' to 'true',
// then we assume that native code is shipped with the library,
// and we don't need to generate it.
return (
schemaInfo.library.libraryPath === includeLibraryPath ||
!schemaInfo.library.config.includesGeneratedCode
library.libraryPath === includeLibraryPath ||
!library.config.includesGeneratedCode
);
}

Expand Down
Loading