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 797a07ccc2
commit f5abafd17b
4 changed files with 14 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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