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:
parent
105d219935
commit
c44e37bf74
|
@ -68,10 +68,9 @@ function buildBundle(
|
||||||
const sourceExts = (config.getSourceExts && config.getSourceExts()) || [];
|
const sourceExts = (config.getSourceExts && config.getSourceExts()) || [];
|
||||||
const platforms = (config.getPlatforms && config.getPlatforms()) || [];
|
const platforms = (config.getPlatforms && config.getPlatforms()) || [];
|
||||||
|
|
||||||
const transformModulePath =
|
const transformModulePath = args.transformer
|
||||||
args.transformer ? path.resolve(args.transformer) :
|
? path.resolve(args.transformer)
|
||||||
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
|
: config.getTransformModulePath();
|
||||||
undefined;
|
|
||||||
|
|
||||||
const providesModuleNodeModules =
|
const providesModuleNodeModules =
|
||||||
typeof config.getProvidesModuleNodeModules === 'function' ? config.getProvidesModuleNodeModules() :
|
typeof config.getProvidesModuleNodeModules === 'function' ? config.getProvidesModuleNodeModules() :
|
||||||
|
|
|
@ -101,7 +101,7 @@ const defaultConfig: ConfigT = {
|
||||||
getProjectRoots: () => [process.cwd()],
|
getProjectRoots: () => [process.cwd()],
|
||||||
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
|
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
|
||||||
getSourceExts: () => [],
|
getSourceExts: () => [],
|
||||||
getTransformModulePath: () => path.resolve(__dirname, '../../packager/transformer'),
|
getTransformModulePath: () => path.resolve(__dirname, '../../packager/transformer.js'),
|
||||||
getTransformOptions: async () => ({}),
|
getTransformOptions: async () => ({}),
|
||||||
postMinifyProcess: x => x,
|
postMinifyProcess: x => x,
|
||||||
postProcessModules: modules => modules,
|
postProcessModules: modules => modules,
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue