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 83fd314e37
commit 825ba6cf48
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(
module.path,
// TODO(martinb): pass non null main (t9527509) // TODO(martinb): pass non null main (t9527509)
this._getTransformOptions({main: null}, {hot: true}), return this._getTransformOptions(
); {main: null, dev: true, platform: 'ios'}, // TODO(martinb): avoid hard-coding platform
{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._getTransformOptions(
{
bundleEntry: bundle.getMainModuleName(),
platform: platform,
dev: dev,
modulePath: module.path,
},
{hot: hot},
).then(options => {
return this._transformer.loadFileAndTransform( return this._transformer.loadFileAndTransform(
path.resolve(module.path), path.resolve(module.path),
this._getTransformOptions( options,
{bundleEntry: bundle.getMainModuleName(), modulePath: module.path},
{hot: hot},
),
); );
});
} }
} }
@ -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};
});
} }
} }