Enable Schema everywhere

Summary: Change the codegen `srcs` to match any `**/*Schema.js`

Reviewed By: TheSavior

Differential Revision: D14401232

fbshipit-source-id: 61e60b1c9ca2f33efacc5caa1903b02a93cc644e
This commit is contained in:
Rick Hanlon
2019-03-13 06:22:12 -07:00
committed by Facebook Github Bot
parent ed5ed23deb
commit bcd259a355
2 changed files with 14 additions and 8 deletions

View File

@@ -35,14 +35,18 @@ jest.mock(
{virtual: true},
);
jest.mock('/test/module/NotASchema', () => ({}), {virtual: true});
test('should combine files', () => {
const files = ['/test/module/SchemaOne', '/test/module/SchemaTwo'];
const files = [
'/test/module/SchemaOne',
'/test/module/SchemaTwo',
'/test/module/NotASchema',
];
expect(combine(files)).toMatchSnapshot();
});
test('should throw for failed require', () => {
test('should not throw for failed require', () => {
const files = ['/test/module/does/not/exist'];
expect(() => combine(files)).toThrow(
"Can't require file at /test/module/does/not/exist",
);
expect(() => combine(files)).not.toThrow();
});

View File

@@ -11,12 +11,12 @@
'use strict';
import type {SchemaType} from '../src/CodegenSchema.js';
function parse(filename: string): SchemaType {
function parse(filename: string): ?SchemaType {
try {
// $FlowFixMe Can't require dynamic variables
return require(filename);
} catch (err) {
throw new Error(`Can't require file at ${filename} ${err}`);
// ignore
}
}
@@ -24,7 +24,9 @@ function combineSchemas(files: Array<string>): SchemaType {
return files.reduce(
(merged, filename) => {
const schema = parse(filename);
merged.modules = {...merged.modules, ...schema.modules};
if (schema && schema.modules) {
merged.modules = {...merged.modules, ...schema.modules};
}
return merged;
},
{modules: {}},