Resolve requires on HMR

Summary:
public

Requires are transformed when building the bundle but we forgot doing so when building the HMR one.

Reviewed By: vjeux

Differential Revision: D2801319

fb-gh-sync-id: ae70612945ab81a05154b14d6b756ef390770542
This commit is contained in:
Martín Bigio 2016-01-06 09:46:56 -08:00 committed by facebook-github-bot-5
parent a5c1f0303c
commit d875aac3c8
3 changed files with 50 additions and 26 deletions

View File

@ -151,7 +151,11 @@ function attachHMRServer({httpServer, path, packagerServer}) {
return; return;
} }
return packagerServer.buildBundleForHMR(modulesToUpdate); return packagerServer.buildBundleForHMR({
entryFile: client.bundleEntry,
platform: client.platform,
modules: modulesToUpdate,
});
}) })
.then(bundle => { .then(bundle => {
if (bundle) { if (bundle) {

View File

@ -284,7 +284,9 @@ class Bundler {
}); });
} }
bundleForHMR(modules) { bundleForHMR({entryFile, platform, modules}) {
return this.getDependencies(entryFile, /*isDev*/true, platform)
.then(response => {
return Promise.all( return Promise.all(
modules.map(module => { modules.map(module => {
return Promise.all([ return Promise.all([
@ -294,19 +296,25 @@ class Bundler {
// TODO(martinb): pass non null main (t9527509) // TODO(martinb): pass non null main (t9527509)
this._getTransformOptions({main: null}, {hot: true}), this._getTransformOptions({main: null}, {hot: true}),
), ),
]).then(([moduleName, transformedSource]) => { ]).then(([moduleName, transformed]) => {
return this._resolver.resolveRequires(response,
module,
transformed.code,
).then(({name, code}) => {
return (` return (`
__accept( __accept(
'${moduleName}', '${moduleName}',
function(global, require, module, exports) { function(global, require, module, exports) {
${transformedSource.code} ${code}
} }
); );
`); `);
}); });
});
}) })
) );
.then(code => code.join('\n')); })
.then(modules => modules.join('\n'));
} }
invalidateFile(filePath) { invalidateFile(filePath) {

View File

@ -165,7 +165,7 @@ class Resolver {
); );
} }
wrapModule(resolutionResponse, module, code) { resolveRequires(resolutionResponse, module, code) {
return Promise.resolve().then(() => { return Promise.resolve().then(() => {
if (module.isPolyfill()) { if (module.isPolyfill()) {
return Promise.resolve({code}); return Promise.resolve({code});
@ -200,10 +200,22 @@ class Resolver {
.replace(replacePatterns.EXPORT_RE, relativizeCode) .replace(replacePatterns.EXPORT_RE, relativizeCode)
.replace(replacePatterns.REQUIRE_RE, relativizeCode); .replace(replacePatterns.REQUIRE_RE, relativizeCode);
return module.getName().then(name => return module.getName().then(name => {
({name, code: defineModuleCode(name, code)})); return {name, code};
}); });
}); });
});
}
wrapModule(resolutionResponse, module, code) {
if (module.isPolyfill()) {
return Promise.resolve({code});
}
return this.resolveRequires(resolutionResponse, module, code).then(
({name, code}) => {
return {name, code: defineModuleCode(name, code)};
});
} }
getDebugInfo() { getDebugInfo() {