Inline Require every module but the preloaded ones

Reviewed By: javache

Differential Revision: D2858983

fb-gh-sync-id: b73de54163d7b75891cb00be96ffb4556d3311a3
This commit is contained in:
Martín Bigio 2016-01-27 07:40:55 -08:00 committed by facebook-github-bot-0
parent 4d834b3cb9
commit d70519d5c5
1 changed files with 46 additions and 19 deletions

View File

@ -143,7 +143,9 @@ class Bundler {
this._assetServer = opts.assetServer; this._assetServer = opts.assetServer;
if (opts.getTransformOptionsModulePath) { if (opts.getTransformOptionsModulePath) {
this._getTransformOptionsModule = require(opts.getTransformOptionsModulePath); this._transformOptionsModule = require(
opts.getTransformOptionsModulePath
);
} }
} }
@ -224,6 +226,7 @@ class Bundler {
response, response,
module, module,
platform, platform,
isDev,
hot, hot,
).then(transformed => { ).then(transformed => {
if (bar) { if (bar) {
@ -289,7 +292,8 @@ class Bundler {
bundle, bundle,
response, response,
module, module,
platform platform,
isDev,
).then(transformed => { ).then(transformed => {
if (bar) { if (bar) {
bar.tick(); bar.tick();
@ -326,15 +330,22 @@ class Bundler {
} }
); );
} else { } else {
return this._transformer.loadFileAndTransform( // TODO(martinb): pass non null main (t9527509)
module.path, return this._getTransformOptions(
// TODO(martinb): pass non null main (t9527509) {main: null, dev: true, platform: 'ios'}, // TODO(martinb): avoid hard-coding platform
this._getTransformOptions({main: null}, {hot: true}), {hot: true},
); ).then(options => {
return this._transformer.loadFileAndTransform(module.path, options);
});
} }
} }
invalidateFile(filePath) { invalidateFile(filePath) {
if (this._transformOptionsModule) {
this._transformOptionsModule.onFileChange &&
this._transformOptionsModule.onFileChange();
}
this._transformer.invalidateFile(filePath); this._transformer.invalidateFile(filePath);
} }
@ -386,7 +397,7 @@ class Bundler {
); );
} }
_transformModule(bundle, response, module, platform = null, hot = false) { _transformModule(bundle, response, module, platform = null, dev = true, hot = false) {
if (module.isAsset_DEPRECATED()) { if (module.isAsset_DEPRECATED()) {
return this._generateAssetModule_DEPRECATED(bundle, module); return this._generateAssetModule_DEPRECATED(bundle, module);
} else if (module.isAsset()) { } else if (module.isAsset()) {
@ -394,13 +405,20 @@ class Bundler {
} else if (module.isJSON()) { } else if (module.isJSON()) {
return generateJSONModule(module); return generateJSONModule(module);
} else { } else {
return this._transformer.loadFileAndTransform( return this._getTransformOptions(
path.resolve(module.path), {
this._getTransformOptions( bundleEntry: bundle.getMainModuleName(),
{bundleEntry: bundle.getMainModuleName(), modulePath: module.path}, platform: platform,
{hot: hot}, dev: dev,
), modulePath: module.path,
); },
{hot: hot},
).then(options => {
return this._transformer.loadFileAndTransform(
path.resolve(module.path),
options,
);
});
} }
} }
@ -484,11 +502,20 @@ class Bundler {
} }
_getTransformOptions(config, options) { _getTransformOptions(config, options) {
const transformerOptions = this._getTransformOptionsModule const transformerOptions = this._transformOptionsModule
? this._getTransformOptionsModule(config) ? this._transformOptionsModule.get(Object.assign(
: null; {
bundler: this,
platform: options.platform,
dev: options.dev,
},
config,
))
: Promise.resolve(null);
return {...options, ...transformerOptions}; return transformerOptions.then(overrides => {
return {...options, ...overrides};
});
} }
} }