From 65b0f7c868eb49d4fcddc2a03d00ab2c0e159fd7 Mon Sep 17 00:00:00 2001 From: Adam Miskiewicz Date: Wed, 6 Apr 2016 11:36:57 -0700 Subject: [PATCH] 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 --- react-packager/src/Bundler/index.js | 29 ++++++++++++++++++++++++++-- react-packager/src/Resolver/index.js | 4 ++-- react-packager/src/Server/index.js | 11 +++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/react-packager/src/Bundler/index.js b/react-packager/src/Bundler/index.js index b25ce4ca..b8bfb6ba 100644 --- a/react-packager/src/Bundler/index.js +++ b/react-packager/src/Bundler/index.js @@ -426,8 +426,33 @@ class Bundler { this._cache.invalidate(filePath); } - getShallowDependencies(entryFile) { - return this._resolver.getShallowDependencies(entryFile); + getShallowDependencies({ + 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) { diff --git a/react-packager/src/Resolver/index.js b/react-packager/src/Resolver/index.js index 8de8d5f8..fd67201f 100644 --- a/react-packager/src/Resolver/index.js +++ b/react-packager/src/Resolver/index.js @@ -120,8 +120,8 @@ class Resolver { }); } - getShallowDependencies(entryFile) { - return this._depGraph.getShallowDependencies(entryFile); + getShallowDependencies(entryFile, transformOptions) { + return this._depGraph.getShallowDependencies(entryFile, transformOptions); } stat(filePath) { diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index aa772685..f7b4b354 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -254,8 +254,15 @@ class Server { return this._bundler.hmrBundle(modules, host, port); } - getShallowDependencies(entryFile) { - return this._bundler.getShallowDependencies(entryFile); + getShallowDependencies(options) { + return Promise.resolve().then(() => { + if (!options.platform) { + options.platform = getPlatformExtension(options.entryFile); + } + + const opts = dependencyOpts(options); + return this._bundler.getShallowDependencies(opts); + }); } getModuleForPath(entryFile) {