mirror of
https://github.com/react/react-native.git
synced 2026-09-28 13:23:09 +08:00
Introduce "headerPrefix" codegen option (#41956)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41956 By default, generated Cxx sources for components all end up in same directory. However the include declarations in them look like this: ``` #include <react/renderer/components/${libraryName}/ShadowNodes.h> ``` And not like this: ``` #include "ShadowNodes.h" ``` This works fine with Buck because it supports header prefixes. To get this working with CocoaPods we define additional `HEADER_SEARCH_PATHS` for our `React-Codegen` pod. This approach will not work if we want to generate code at the library level and check in the artifacts. That's because we don't have control over the Podspec there, and can't inject those additional `HEADER_SEARCH_PATHS`. This diff adds the `headerPrefix` argument to the codegen entry point. It is `react/renderer/components/${libraryName}` by default, but can become empty if we want to generate code at the library level, and don't want to deal with this nested header structure. *Note:* `RNCodegen` runs all the generators [in a loop](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/generators/RNCodegen.js#L263-L275), assuming that the all have same function signature So I had to add the `headerPrefix` argument to all the generators, even to the ones that don't really need it. Changelog: [General][Added] - Introduce "headerPrefix" codegen option. Reviewed By: zeyap Differential Revision: D51811596 fbshipit-source-id: c5c3e1e571c7c4ea2f5354eb9a7b0df6b917fc0c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b00569c9f5
commit
dae4a11e90
Vendored
+7
-1
@@ -25,7 +25,13 @@ fixtures.forEach(fixture => {
|
||||
it(`GenerateComponentDescriptorH can generate for '${fixture}'`, () => {
|
||||
const libName = 'RNCodegenModuleFixtures';
|
||||
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
|
||||
const output = generator.generate(libName, schema);
|
||||
const output = generator.generate(
|
||||
libName,
|
||||
schema,
|
||||
undefined,
|
||||
false,
|
||||
`react/renderer/components/${libName}/`,
|
||||
);
|
||||
expect(Object.fromEntries(output)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+7
-1
@@ -25,7 +25,13 @@ fixtures.forEach(fixture => {
|
||||
it(`GenerateEventEmitterCpp can generate for '${fixture}'`, () => {
|
||||
const libName = 'RNCodegenModuleFixtures';
|
||||
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
|
||||
const output = generator.generate(libName, schema);
|
||||
const output = generator.generate(
|
||||
libName,
|
||||
schema,
|
||||
undefined,
|
||||
false,
|
||||
`react/renderer/components/${libName}/`,
|
||||
);
|
||||
expect(Object.fromEntries(output)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+7
-1
@@ -25,7 +25,13 @@ fixtures.forEach(fixture => {
|
||||
it(`GeneratePropsCpp can generate for '${fixture}'`, () => {
|
||||
const libName = 'RNCodegenModuleFixtures';
|
||||
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
|
||||
const output = generator.generate(libName, schema);
|
||||
const output = generator.generate(
|
||||
libName,
|
||||
schema,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${libName}/`,
|
||||
);
|
||||
expect(Object.fromEntries(output)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+7
-1
@@ -24,7 +24,13 @@ fixtures.forEach(fixture => {
|
||||
it(`GenerateShadowNodeCpp can generate for '${fixture}'`, () => {
|
||||
const libName = 'RNCodegenModuleFixtures';
|
||||
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
|
||||
const output = generator.generate(libName, schema, undefined, false);
|
||||
const output = generator.generate(
|
||||
libName,
|
||||
schema,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${libName}/`,
|
||||
);
|
||||
expect(Object.fromEntries(output)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+7
-1
@@ -24,7 +24,13 @@ fixtures.forEach(fixture => {
|
||||
it(`GenerateShadowNodeH can generate for '${fixture}'`, () => {
|
||||
const libName = 'RNCodegenModuleFixtures';
|
||||
const schema = parser.parseFile(`${FIXTURE_DIR}/${fixture}`);
|
||||
const output = generator.generate(libName, schema, undefined, false);
|
||||
const output = generator.generate(
|
||||
libName,
|
||||
schema,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${libName}/`,
|
||||
);
|
||||
expect(Object.fromEntries(output)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+23
-10
@@ -77,6 +77,7 @@ type LibraryOptions = $ReadOnly<{
|
||||
outputDirectory: string,
|
||||
packageName?: string, // Some platforms have a notion of package, which should be configurable.
|
||||
assumeNonnull: boolean,
|
||||
useLocalIncludePaths?: boolean,
|
||||
}>;
|
||||
|
||||
type SchemasOptions = $ReadOnly<{
|
||||
@@ -232,16 +233,24 @@ module.exports = {
|
||||
outputDirectory,
|
||||
packageName,
|
||||
assumeNonnull,
|
||||
useLocalIncludePaths,
|
||||
}: LibraryOptions,
|
||||
{generators, test}: LibraryConfig,
|
||||
): boolean {
|
||||
schemaValidator.validate(schema);
|
||||
|
||||
const defaultHeaderPrefix = 'react/renderer/components';
|
||||
const headerPrefix =
|
||||
useLocalIncludePaths === true
|
||||
? ''
|
||||
: `${defaultHeaderPrefix}/${libraryName}/`;
|
||||
function composePath(intermediate: string) {
|
||||
return path.join(outputDirectory, intermediate, libraryName);
|
||||
}
|
||||
|
||||
const componentIOSOutput = composePath('react/renderer/components/');
|
||||
const componentIOSOutput = composePath(
|
||||
useLocalIncludePaths === true ? '' : defaultHeaderPrefix,
|
||||
);
|
||||
const modulesIOSOutput = composePath('./');
|
||||
|
||||
const outputFoldersForGenerators = {
|
||||
@@ -262,15 +271,19 @@ module.exports = {
|
||||
|
||||
for (const name of generators) {
|
||||
for (const generator of LIBRARY_GENERATORS[name]) {
|
||||
generator(libraryName, schema, packageName, assumeNonnull).forEach(
|
||||
(contents: string, fileName: string) => {
|
||||
generatedFiles.push({
|
||||
name: fileName,
|
||||
content: contents,
|
||||
outputDir: outputFoldersForGenerators[name],
|
||||
});
|
||||
},
|
||||
);
|
||||
generator(
|
||||
libraryName,
|
||||
schema,
|
||||
packageName,
|
||||
assumeNonnull,
|
||||
headerPrefix,
|
||||
).forEach((contents: string, fileName: string) => {
|
||||
generatedFiles.push({
|
||||
name: fileName,
|
||||
content: contents,
|
||||
outputDir: outputFoldersForGenerators[name],
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return checkOrWriteFiles(generatedFiles, test);
|
||||
|
||||
+5
-4
@@ -17,10 +17,10 @@ type FilesOutput = Map<string, string>;
|
||||
|
||||
const FileTemplate = ({
|
||||
componentDescriptors,
|
||||
libraryName,
|
||||
headerPrefix,
|
||||
}: {
|
||||
componentDescriptors: string,
|
||||
libraryName: string,
|
||||
headerPrefix: string,
|
||||
}) => `
|
||||
/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
@@ -33,7 +33,7 @@ const FileTemplate = ({
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/${libraryName}/ShadowNodes.h>
|
||||
#include <${headerPrefix}ShadowNodes.h>
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
|
||||
namespace facebook::react {
|
||||
@@ -54,6 +54,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'ComponentDescriptors.h';
|
||||
|
||||
@@ -85,7 +86,7 @@ module.exports = {
|
||||
|
||||
const replacedTemplate = FileTemplate({
|
||||
componentDescriptors,
|
||||
libraryName,
|
||||
headerPrefix: headerPrefix ?? '',
|
||||
});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
+1
@@ -380,6 +380,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'RCTComponentViewHelpers.h';
|
||||
|
||||
|
||||
+5
-4
@@ -31,12 +31,12 @@ type ComponentCollection = $ReadOnly<{
|
||||
|
||||
const FileTemplate = ({
|
||||
events,
|
||||
libraryName,
|
||||
extraIncludes,
|
||||
headerPrefix,
|
||||
}: {
|
||||
events: string,
|
||||
libraryName: string,
|
||||
extraIncludes: Set<string>,
|
||||
headerPrefix: string,
|
||||
}) => `
|
||||
/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
@@ -47,7 +47,7 @@ const FileTemplate = ({
|
||||
* ${'@'}generated by codegen project: GenerateEventEmitterCpp.js
|
||||
*/
|
||||
|
||||
#include <react/renderer/components/${libraryName}/EventEmitters.h>
|
||||
#include <${headerPrefix}EventEmitters.h>
|
||||
${[...extraIncludes].join('\n')}
|
||||
|
||||
namespace facebook::react {
|
||||
@@ -411,6 +411,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const moduleComponents: ComponentCollection = Object.keys(schema.modules)
|
||||
.map(moduleName => {
|
||||
@@ -442,9 +443,9 @@ module.exports = {
|
||||
|
||||
const fileName = 'EventEmitters.cpp';
|
||||
const replacedTemplate = FileTemplate({
|
||||
libraryName,
|
||||
events: componentEmitters,
|
||||
extraIncludes,
|
||||
headerPrefix: headerPrefix ?? '',
|
||||
});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
+1
@@ -311,6 +311,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const moduleComponents: ComponentCollection = Object.keys(schema.modules)
|
||||
.map(moduleName => {
|
||||
|
||||
+5
-4
@@ -18,13 +18,13 @@ const {convertDefaultTypeToString, getImports} = require('./CppHelpers');
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
const FileTemplate = ({
|
||||
libraryName,
|
||||
imports,
|
||||
componentClasses,
|
||||
headerPrefix,
|
||||
}: {
|
||||
libraryName: string,
|
||||
imports: string,
|
||||
componentClasses: string,
|
||||
headerPrefix: string,
|
||||
}) => `
|
||||
/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
@@ -35,7 +35,7 @@ const FileTemplate = ({
|
||||
* ${'@'}generated by codegen project: GeneratePropsCpp.js
|
||||
*/
|
||||
|
||||
#include <react/renderer/components/${libraryName}/Props.h>
|
||||
#include <${headerPrefix}Props.h>
|
||||
${imports}
|
||||
|
||||
namespace facebook::react {
|
||||
@@ -104,6 +104,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'Props.cpp';
|
||||
const allImports: Set<string> = new Set([
|
||||
@@ -151,8 +152,8 @@ module.exports = {
|
||||
|
||||
const replacedTemplate = FileTemplate({
|
||||
componentClasses: componentProps,
|
||||
libraryName,
|
||||
imports: Array.from(allImports).sort().join('\n').trim(),
|
||||
headerPrefix: headerPrefix ?? '',
|
||||
});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
@@ -706,6 +706,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'Props.h';
|
||||
|
||||
|
||||
+1
@@ -297,6 +297,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
// TODO: This doesn't support custom package name yet.
|
||||
const normalizedPackageName = 'com.facebook.react.viewmanagers';
|
||||
|
||||
+1
@@ -237,6 +237,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
// TODO: This doesn't support custom package name yet.
|
||||
const normalizedPackageName = 'com.facebook.react.viewmanagers';
|
||||
|
||||
+5
-4
@@ -16,11 +16,11 @@ import type {SchemaType} from '../../CodegenSchema';
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
const FileTemplate = ({
|
||||
libraryName,
|
||||
componentNames,
|
||||
headerPrefix,
|
||||
}: {
|
||||
libraryName: string,
|
||||
componentNames: string,
|
||||
headerPrefix: string,
|
||||
}) => `
|
||||
/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
@@ -31,7 +31,7 @@ const FileTemplate = ({
|
||||
* ${'@'}generated by codegen project: GenerateShadowNodeCpp.js
|
||||
*/
|
||||
|
||||
#include <react/renderer/components/${libraryName}/ShadowNodes.h>
|
||||
#include <${headerPrefix}ShadowNodes.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
@@ -51,6 +51,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'ShadowNodes.cpp';
|
||||
|
||||
@@ -85,7 +86,7 @@ module.exports = {
|
||||
|
||||
const replacedTemplate = FileTemplate({
|
||||
componentNames,
|
||||
libraryName,
|
||||
headerPrefix: headerPrefix ?? '',
|
||||
});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
+7
-10
@@ -16,13 +16,11 @@ import type {SchemaType} from '../../CodegenSchema';
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
const FileTemplate = ({
|
||||
imports,
|
||||
libraryName,
|
||||
componentClasses,
|
||||
headerPrefix,
|
||||
}: {
|
||||
imports: string,
|
||||
libraryName: string,
|
||||
componentClasses: string,
|
||||
headerPrefix: string,
|
||||
}) => `
|
||||
/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
@@ -35,8 +33,9 @@ const FileTemplate = ({
|
||||
|
||||
#pragma once
|
||||
|
||||
${imports}#include <react/renderer/components/${libraryName}/Props.h>
|
||||
#include <react/renderer/components/${libraryName}/States.h>
|
||||
#include <${headerPrefix}EventEmitters.h>
|
||||
#include <${headerPrefix}Props.h>
|
||||
#include <${headerPrefix}States.h>
|
||||
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
@@ -72,6 +71,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'ShadowNodes.h';
|
||||
|
||||
@@ -109,12 +109,9 @@ module.exports = {
|
||||
.filter(Boolean)
|
||||
.join('\n\n');
|
||||
|
||||
const eventEmitterImport = `#include <react/renderer/components/${libraryName}/EventEmitters.h>\n`;
|
||||
|
||||
const replacedTemplate = FileTemplate({
|
||||
componentClasses: moduleResults,
|
||||
libraryName,
|
||||
imports: eventEmitterImport,
|
||||
headerPrefix: headerPrefix ?? '',
|
||||
});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
+5
-4
@@ -16,11 +16,11 @@ import type {SchemaType} from '../../CodegenSchema';
|
||||
type FilesOutput = Map<string, string>;
|
||||
|
||||
const FileTemplate = ({
|
||||
libraryName,
|
||||
stateClasses,
|
||||
headerPrefix,
|
||||
}: {
|
||||
libraryName: string,
|
||||
stateClasses: string,
|
||||
headerPrefix: string,
|
||||
}) => `
|
||||
/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
@@ -30,7 +30,7 @@ const FileTemplate = ({
|
||||
*
|
||||
* ${'@'}generated by codegen project: GenerateStateCpp.js
|
||||
*/
|
||||
#include <react/renderer/components/${libraryName}/States.h>
|
||||
#include <${headerPrefix}States.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
@@ -47,6 +47,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'States.cpp';
|
||||
|
||||
@@ -81,8 +82,8 @@ module.exports = {
|
||||
.join('\n');
|
||||
|
||||
const replacedTemplate = FileTemplate({
|
||||
libraryName,
|
||||
stateClasses,
|
||||
headerPrefix: headerPrefix ?? '',
|
||||
});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
@@ -70,6 +70,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'States.h';
|
||||
|
||||
|
||||
@@ -171,6 +171,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const fileName = 'Tests.cpp';
|
||||
const allImports = new Set([
|
||||
|
||||
+9
-1
@@ -21,7 +21,15 @@ describe('GenerateComponentDescriptorH', () => {
|
||||
const fixture = fixtures[fixtureName];
|
||||
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
|
||||
expect(
|
||||
generator.generate(
|
||||
fixtureName,
|
||||
fixture,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${fixtureName}/`,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+9
-1
@@ -21,7 +21,15 @@ describe('GenerateEventEmitterCpp', () => {
|
||||
const fixture = fixtures[fixtureName];
|
||||
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
|
||||
expect(
|
||||
generator.generate(
|
||||
fixtureName,
|
||||
fixture,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${fixtureName}/`,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+9
-1
@@ -21,7 +21,15 @@ describe('GeneratePropsCpp', () => {
|
||||
const fixture = fixtures[fixtureName];
|
||||
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
|
||||
expect(
|
||||
generator.generate(
|
||||
fixtureName,
|
||||
fixture,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${fixtureName}/`,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+7
-1
@@ -22,7 +22,13 @@ describe('GenerateShadowNodeCpp', () => {
|
||||
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
expect(
|
||||
generator.generate(fixtureName, fixture, 'SampleSpec'),
|
||||
generator.generate(
|
||||
fixtureName,
|
||||
fixture,
|
||||
'SampleSpec',
|
||||
false,
|
||||
`react/renderer/components/${fixtureName}/`,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+9
-1
@@ -21,7 +21,15 @@ describe('GenerateShadowNodeH', () => {
|
||||
const fixture = fixtures[fixtureName];
|
||||
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
|
||||
expect(
|
||||
generator.generate(
|
||||
fixtureName,
|
||||
fixture,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${fixtureName}/`,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+9
-1
@@ -21,7 +21,15 @@ describe('GenerateStateCpp', () => {
|
||||
const fixture = fixtures[fixtureName];
|
||||
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
|
||||
expect(
|
||||
generator.generate(
|
||||
fixtureName,
|
||||
fixture,
|
||||
'',
|
||||
false,
|
||||
`react/renderer/components/${fixtureName}/`,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -234,6 +234,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = getModules(schema);
|
||||
|
||||
|
||||
@@ -611,6 +611,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = getModules(schema);
|
||||
|
||||
|
||||
+1
@@ -441,6 +441,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const files = new Map<string, string>();
|
||||
const nativeModules = getModules(schema);
|
||||
|
||||
@@ -422,6 +422,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = getModules(schema);
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean = false,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = getModules(schema);
|
||||
const modules = Object.keys(nativeModules)
|
||||
|
||||
+1
@@ -118,6 +118,7 @@ module.exports = {
|
||||
schema: SchemaType,
|
||||
packageName?: string,
|
||||
assumeNonnull: boolean,
|
||||
headerPrefix?: string,
|
||||
): FilesOutput {
|
||||
const nativeModules = getModules(schema);
|
||||
|
||||
|
||||
+1
-1
@@ -263,7 +263,7 @@ class ProjectUtilsTest {
|
||||
@Test
|
||||
fun needsCodegenFromPackageJson_withCodegenConfigInModel_returnsTrue() {
|
||||
val project = createProject()
|
||||
val model = ModelPackageJson("1000.0.0", ModelCodegenConfig(null, null, null, null))
|
||||
val model = ModelPackageJson("1000.0.0", ModelCodegenConfig(null, null, null, null, false))
|
||||
|
||||
assertTrue(project.needsCodegenFromPackageJson(model))
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,6 +83,6 @@ describe('generateSpec', () => {
|
||||
libraryType,
|
||||
);
|
||||
|
||||
expect(mkdirpSyncInvoked).toBe(3);
|
||||
expect(mkdirpSyncInvoked).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -226,13 +226,14 @@ function generateSchemaInfo(library) {
|
||||
};
|
||||
}
|
||||
|
||||
function generateCode(iosOutputDir, schemaInfo) {
|
||||
function generateCode(iosOutputDir, schemaInfo, includesGeneratedCode) {
|
||||
const tmpDir = fs.mkdtempSync(
|
||||
path.join(os.tmpdir(), schemaInfo.library.config.name),
|
||||
);
|
||||
const tmpOutputDir = path.join(tmpDir, 'out');
|
||||
fs.mkdirSync(tmpOutputDir, {recursive: true});
|
||||
|
||||
const useLocalIncludePaths = includesGeneratedCode;
|
||||
generateSpecsCLIExecutor.generateSpecFromInMemorySchema(
|
||||
'ios',
|
||||
schemaInfo.schema,
|
||||
@@ -240,6 +241,7 @@ function generateCode(iosOutputDir, schemaInfo) {
|
||||
schemaInfo.library.config.name,
|
||||
'com.facebook.fbreact.specs',
|
||||
schemaInfo.library.config.type,
|
||||
useLocalIncludePaths,
|
||||
);
|
||||
|
||||
// Finally, copy artifacts to the final output directory.
|
||||
@@ -256,9 +258,9 @@ function generateSchemaInfos(libraries) {
|
||||
return libraries.map(generateSchemaInfo);
|
||||
}
|
||||
|
||||
function generateNativeCode(iosOutputDir, schemaInfos) {
|
||||
function generateNativeCode(iosOutputDir, schemaInfos, includesGeneratedCode) {
|
||||
return schemaInfos.map(schemaInfo => {
|
||||
generateCode(iosOutputDir, schemaInfo);
|
||||
generateCode(iosOutputDir, schemaInfo, includesGeneratedCode);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -381,6 +383,7 @@ function execute(projectRoot, baseOutputPath) {
|
||||
schemaInfos.filter(schemaInfo =>
|
||||
mustGenerateNativeCode(projectRoot, schemaInfo),
|
||||
),
|
||||
pkgJsonIncludesGeneratedCode(pkgJson),
|
||||
);
|
||||
|
||||
if (!pkgJsonIncludesGeneratedCode(pkgJson)) {
|
||||
|
||||
@@ -36,12 +36,6 @@ function createOutputDirectoryIfNeeded(outputDirectory, libraryName) {
|
||||
mkdirp.sync(outputDirectory);
|
||||
}
|
||||
|
||||
function createFolderIfDefined(folder) {
|
||||
if (folder) {
|
||||
mkdirp.sync(folder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function read a JSON schema from a path and parses it.
|
||||
* It throws if the schema don't exists or it can't be parsed.
|
||||
@@ -77,25 +71,17 @@ function generateSpecFromInMemorySchema(
|
||||
libraryName,
|
||||
packageName,
|
||||
libraryType,
|
||||
useLocalIncludePaths,
|
||||
) {
|
||||
validateLibraryType(libraryType);
|
||||
createOutputDirectoryIfNeeded(outputDirectory, libraryName);
|
||||
function composePath(intermediate) {
|
||||
return path.join(outputDirectory, intermediate, libraryName);
|
||||
}
|
||||
|
||||
// These are hardcoded and should not be changed.
|
||||
// The codegen creates some C++ code with #include directive
|
||||
// which uses these paths. Those directive are not customizable yet.
|
||||
createFolderIfDefined(composePath('react/renderer/components/'));
|
||||
createFolderIfDefined(composePath('./'));
|
||||
|
||||
utils.getCodegen().generate(
|
||||
{
|
||||
libraryName,
|
||||
schema,
|
||||
outputDirectory,
|
||||
packageName,
|
||||
useLocalIncludePaths,
|
||||
},
|
||||
{
|
||||
generators: GENERATORS[libraryType][platform],
|
||||
|
||||
Reference in New Issue
Block a user