Require transformer options to be present throughout

Summary: `transformModulePath` used to be an optional string, because `ConfigT` allowed for an optional `getTransformModulePath` method. Effectively, we required it to be present. This builds on top of the cleanups around `ConfigT` and gets rid of the flow error suppressions

Reviewed By: jeanlauliac

Differential Revision: D5037466

fbshipit-source-id: bc5c9cbc566e7aa74e7f6397e69fa87cdac7bc00
This commit is contained in:
David Aurelio 2017-05-11 16:37:03 -07:00 committed by Facebook Github Bot
parent 105d219935
commit c44e37bf74
6 changed files with 18 additions and 18 deletions

View File

@ -68,10 +68,9 @@ function buildBundle(
const sourceExts = (config.getSourceExts && config.getSourceExts()) || [];
const platforms = (config.getPlatforms && config.getPlatforms()) || [];
const transformModulePath =
args.transformer ? path.resolve(args.transformer) :
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
undefined;
const transformModulePath = args.transformer
? path.resolve(args.transformer)
: config.getTransformModulePath();
const providesModuleNodeModules =
typeof config.getProvidesModuleNodeModules === 'function' ? config.getProvidesModuleNodeModules() :

View File

@ -101,7 +101,7 @@ const defaultConfig: ConfigT = {
getProjectRoots: () => [process.cwd()],
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
getSourceExts: () => [],
getTransformModulePath: () => path.resolve(__dirname, '../../packager/transformer'),
getTransformModulePath: () => path.resolve(__dirname, '../../packager/transformer.js'),
getTransformOptions: async () => ({}),
postMinifyProcess: x => x,
postProcessModules: modules => modules,

View File

@ -34,6 +34,7 @@ type Options = {
projectRoots: Array<string>,
reporter?: Reporter,
+sourceExts: ?Array<string>,
+transformModulePath: string,
watch?: boolean,
};

View File

@ -25,6 +25,7 @@ jest
.mock('../Bundle')
.mock('../HMRBundle')
.mock('../../Logger')
.mock('/path/to/transformer.js', () => ({}), {virtual: true})
;
var Bundler = require('../');
@ -36,6 +37,7 @@ const os = require('os');
const {any, objectContaining} = expect;
var commonOptions = {
allowBundleUpdates: false,
assetExts: defaults.assetExts,
@ -44,6 +46,7 @@ var commonOptions = {
platforms: defaults.platforms,
resetCache: false,
sourceExts: defaults.sourceExts,
transformModulePath: '/path/to/transformer.js',
watch: false,
};
@ -95,6 +98,10 @@ describe('Bundler', function() {
});
Resolver.load = jest.fn().mockImplementation(opts => Promise.resolve(new Resolver(opts)));
fs.__setMockFilesystem({
'path': {'to': {'transformer.js': ''}},
});
fs.statSync.mockImplementation(function() {
return {
isDirectory: () => true,

View File

@ -133,7 +133,7 @@ type Options = {|
+reporter: Reporter,
+resetCache: boolean,
+sourceExts: Array<string>,
+transformModulePath?: string,
+transformModulePath: string,
+transformTimeoutInterval: ?number,
+watch: boolean,
|};
@ -155,15 +155,9 @@ class Bundler {
opts.projectRoots.forEach(verifyRootExists);
let transformModuleHash;
try {
/* $FlowFixMe: if transformModulePath is null it'll just be caught */
const transformModuleStr = fs.readFileSync(opts.transformModulePath);
transformModuleHash =
const transformModuleHash =
crypto.createHash('sha1').update(transformModuleStr).digest('hex');
} catch (error) {
transformModuleHash = '';
}
const stableProjectRoots = opts.projectRoots.map(p => {
return path.relative(path.join(__dirname, '../../../..'), p);
@ -197,7 +191,6 @@ class Bundler {
const maxWorkerCount = Bundler.getMaxWorkerCount();
this._transformer = new Transformer(
/* $FlowFixMe: in practice it's always here. */
opts.transformModulePath,
maxWorkerCount,
{

View File

@ -75,7 +75,7 @@ type Options = {
resetCache?: boolean,
silent?: boolean,
+sourceExts: ?Array<string>,
transformModulePath?: string,
+transformModulePath: string,
transformTimeoutInterval?: number,
watch?: boolean,
};
@ -131,7 +131,7 @@ class Server {
resetCache: boolean,
silent: boolean,
+sourceExts: Array<string>,
transformModulePath: void | string,
+transformModulePath: string,
transformTimeoutInterval: ?number,
watch: boolean,
};