Make Packager send fresh modules through HMR interface
Reviewed By: frantic Differential Revision: D2787951 fb-gh-sync-id: 63c04710b60d99b5161ef9a40b116ba2f72df745
This commit is contained in:
Родитель
90781d3067
Коммит
ac9c3c548d
|
@ -19,7 +19,12 @@ function attachHMRServer({httpServer, path, packagerServer}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(martinb): send HMR update
|
packagerServer.buildBundleForHMR({
|
||||||
|
entryFile: filename,
|
||||||
|
// TODO(martinb): receive platform on query string when client connects
|
||||||
|
platform: 'ios',
|
||||||
|
})
|
||||||
|
.then(bundle => activeWS.send(bundle));
|
||||||
});
|
});
|
||||||
|
|
||||||
const WebSocketServer = require('ws').Server;
|
const WebSocketServer = require('ws').Server;
|
||||||
|
|
|
@ -277,6 +277,29 @@ class Bundler {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bundleForHMR({
|
||||||
|
entryFile,
|
||||||
|
platform,
|
||||||
|
}) {
|
||||||
|
return this.getDependencies(entryFile, /*isDev*/true, platform).then(response => {
|
||||||
|
const module = response.dependencies.filter(module => module.path === entryFile)[0];
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
module.getName(),
|
||||||
|
this._transformer.loadFileAndTransform(path.resolve(entryFile)),
|
||||||
|
]).then(([moduleName, transformedSource]) => {
|
||||||
|
return (`
|
||||||
|
__accept(
|
||||||
|
'${moduleName}',
|
||||||
|
function(global, require, module, exports) {
|
||||||
|
${transformedSource.code}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
invalidateFile(filePath) {
|
invalidateFile(filePath) {
|
||||||
this._transformer.invalidateFile(filePath);
|
this._transformer.invalidateFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,6 +112,17 @@ const bundleOpts = declareOpts({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const hmrBundleOpts = declareOpts({
|
||||||
|
entryFile: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
platform: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const dependencyOpts = declareOpts({
|
const dependencyOpts = declareOpts({
|
||||||
platform: {
|
platform: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -220,6 +231,17 @@ class Server {
|
||||||
return this.buildBundle(options);
|
return this.buildBundle(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildBundleForHMR(options) {
|
||||||
|
return Promise.resolve().then(() => {
|
||||||
|
if (!options.platform) {
|
||||||
|
options.platform = getPlatformExtension(options.entryFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
const opts = hmrBundleOpts(options);
|
||||||
|
return this._bundler.bundleForHMR(opts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getDependencies(options) {
|
getDependencies(options) {
|
||||||
return Promise.resolve().then(() => {
|
return Promise.resolve().then(() => {
|
||||||
if (!options.platform) {
|
if (!options.platform) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче