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:
parent
a5c1f0303c
commit
d875aac3c8
|
@ -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) {
|
||||||
|
|
|
@ -284,29 +284,37 @@ class Bundler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bundleForHMR(modules) {
|
bundleForHMR({entryFile, platform, modules}) {
|
||||||
return Promise.all(
|
return this.getDependencies(entryFile, /*isDev*/true, platform)
|
||||||
modules.map(module => {
|
.then(response => {
|
||||||
return Promise.all([
|
return Promise.all(
|
||||||
module.getName(),
|
modules.map(module => {
|
||||||
this._transformer.loadFileAndTransform(
|
return Promise.all([
|
||||||
module.path,
|
module.getName(),
|
||||||
// TODO(martinb): pass non null main (t9527509)
|
this._transformer.loadFileAndTransform(
|
||||||
this._getTransformOptions({main: null}, {hot: true}),
|
module.path,
|
||||||
),
|
// TODO(martinb): pass non null main (t9527509)
|
||||||
]).then(([moduleName, transformedSource]) => {
|
this._getTransformOptions({main: null}, {hot: true}),
|
||||||
return (`
|
),
|
||||||
__accept(
|
]).then(([moduleName, transformed]) => {
|
||||||
'${moduleName}',
|
return this._resolver.resolveRequires(response,
|
||||||
function(global, require, module, exports) {
|
module,
|
||||||
${transformedSource.code}
|
transformed.code,
|
||||||
}
|
).then(({name, code}) => {
|
||||||
);
|
return (`
|
||||||
`);
|
__accept(
|
||||||
});
|
'${moduleName}',
|
||||||
|
function(global, require, module, exports) {
|
||||||
|
${code}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
})
|
})
|
||||||
)
|
.then(modules => modules.join('\n'));
|
||||||
.then(code => code.join('\n'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidateFile(filePath) {
|
invalidateFile(filePath) {
|
||||||
|
|
|
@ -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,12 +200,24 @@ 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() {
|
||||||
return this._depGraph.getDebugInfo();
|
return this._depGraph.getDebugInfo();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue