diff --git a/packages/metro-bundler/react-packager.js b/packages/metro-bundler/react-packager.js index 24d001c1..457a877f 100644 --- a/packages/metro-bundler/react-packager.js +++ b/packages/metro-bundler/react-packager.js @@ -34,6 +34,7 @@ type Options = { projectRoots: Array, reporter?: Reporter, +sourceExts: ?Array, + +transformModulePath: string, watch?: boolean, }; diff --git a/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js b/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js index 5a171a80..bfcfa787 100644 --- a/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js +++ b/packages/metro-bundler/src/Bundler/__tests__/Bundler-test.js @@ -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, diff --git a/packages/metro-bundler/src/Bundler/index.js b/packages/metro-bundler/src/Bundler/index.js index d64820e9..bf88f784 100644 --- a/packages/metro-bundler/src/Bundler/index.js +++ b/packages/metro-bundler/src/Bundler/index.js @@ -133,7 +133,7 @@ type Options = {| +reporter: Reporter, +resetCache: boolean, +sourceExts: Array, - +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 = - crypto.createHash('sha1').update(transformModuleStr).digest('hex'); - } catch (error) { - transformModuleHash = ''; - } + const transformModuleStr = fs.readFileSync(opts.transformModulePath); + const transformModuleHash = + crypto.createHash('sha1').update(transformModuleStr).digest('hex'); 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, { diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 9fb3fe80..0e0f5371 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -75,7 +75,7 @@ type Options = { resetCache?: boolean, silent?: boolean, +sourceExts: ?Array, - transformModulePath?: string, + +transformModulePath: string, transformTimeoutInterval?: number, watch?: boolean, }; @@ -131,7 +131,7 @@ class Server { resetCache: boolean, silent: boolean, +sourceExts: Array, - transformModulePath: void | string, + +transformModulePath: string, transformTimeoutInterval: ?number, watch: boolean, };