Pass transformOptions to getShallowDependencies.

Summary:We weren't passing `transformOptions` to `getShallowDependencies`, and therefore, when this method was called on a module, it would bust the cache and cause a retransform of the file. This was resulting in a complete retransforming of all files when the HMR Client connected to the packager.
Closes https://github.com/facebook/react-native/pull/6843

Differential Revision: D3145306

Pulled By: martinbigio

fb-gh-sync-id: 3619c27801b2fc07b758fafed47fcc892bb8e6db
fbshipit-source-id: 3619c27801b2fc07b758fafed47fcc892bb8e6db
This commit is contained in:
Adam Miskiewicz 2016-04-06 11:36:57 -07:00 committed by Facebook Github Bot 0
parent 6a133d78a8
commit 8200041694
4 changed files with 50 additions and 8 deletions

View File

@ -48,7 +48,12 @@ function attachHMRServer({httpServer, path, packagerServer}) {
if (dep.isAsset() || dep.isAsset_DEPRECATED() || dep.isJSON()) { if (dep.isAsset() || dep.isAsset_DEPRECATED() || dep.isJSON()) {
return Promise.resolve({path: dep.path, deps: []}); return Promise.resolve({path: dep.path, deps: []});
} }
return packagerServer.getShallowDependencies(dep.path) return packagerServer.getShallowDependencies({
platform: platform,
dev: true,
hot: true,
entryFile: dep.path
})
.then(deps => { .then(deps => {
return { return {
path: dep.path, path: dep.path,
@ -147,7 +152,12 @@ function attachHMRServer({httpServer, path, packagerServer}) {
client.ws.send(JSON.stringify({type: 'update-start'})); client.ws.send(JSON.stringify({type: 'update-start'}));
stat.then(() => { stat.then(() => {
return packagerServer.getShallowDependencies(filename) return packagerServer.getShallowDependencies({
entryFile: filename,
platform: client.platform,
dev: true,
hot: true,
})
.then(deps => { .then(deps => {
if (!client) { if (!client) {
return []; return [];

View File

@ -426,8 +426,33 @@ class Bundler {
this._cache.invalidate(filePath); this._cache.invalidate(filePath);
} }
getShallowDependencies(entryFile) { getShallowDependencies({
return this._resolver.getShallowDependencies(entryFile); entryFile,
platform,
dev = true,
minify = !dev,
hot = false,
generateSourceMaps = false,
}) {
return this.getTransformOptions(
entryFile,
{
dev,
platform,
hot,
generateSourceMaps,
projectRoots: this._projectRoots,
},
).then(transformSpecificOptions => {
const transformOptions = {
minify,
dev,
platform,
transform: transformSpecificOptions,
};
return this._resolver.getShallowDependencies(entryFile, transformOptions);
});
} }
stat(filePath) { stat(filePath) {

View File

@ -120,8 +120,8 @@ class Resolver {
}); });
} }
getShallowDependencies(entryFile) { getShallowDependencies(entryFile, transformOptions) {
return this._depGraph.getShallowDependencies(entryFile); return this._depGraph.getShallowDependencies(entryFile, transformOptions);
} }
stat(filePath) { stat(filePath) {

View File

@ -254,8 +254,15 @@ class Server {
return this._bundler.hmrBundle(modules, host, port); return this._bundler.hmrBundle(modules, host, port);
} }
getShallowDependencies(entryFile) { getShallowDependencies(options) {
return this._bundler.getShallowDependencies(entryFile); return Promise.resolve().then(() => {
if (!options.platform) {
options.platform = getPlatformExtension(options.entryFile);
}
const opts = dependencyOpts(options);
return this._bundler.getShallowDependencies(opts);
});
} }
getModuleForPath(entryFile) { getModuleForPath(entryFile) {