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 packagerServer.buildBundleForHMR(modulesToUpdate);
return packagerServer.buildBundleForHMR({
entryFile: client.bundleEntry,
platform: client.platform,
modules: modulesToUpdate,
});
})
.then(bundle => {
if (bundle) {

View File

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

View File

@ -165,7 +165,7 @@ class Resolver {
);
}
wrapModule(resolutionResponse, module, code) {
resolveRequires(resolutionResponse, module, code) {
return Promise.resolve().then(() => {
if (module.isPolyfill()) {
return Promise.resolve({code});
@ -200,12 +200,24 @@ class Resolver {
.replace(replacePatterns.EXPORT_RE, relativizeCode)
.replace(replacePatterns.REQUIRE_RE, relativizeCode);
return module.getName().then(name =>
({name, code: defineModuleCode(name, code)}));
return module.getName().then(name => {
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() {
return this._depGraph.getDebugInfo();
}