From adeee429b60da2c7073d0e3b280b588cf22ce03e Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sun, 6 May 2018 12:18:52 -0700 Subject: [PATCH] Cache resolved paths of dependencies (#1309) --- src/Bundler.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index ecdc302c46b..18cfc3f50c0 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -402,6 +402,10 @@ class Bundler extends EventEmitter { async resolveDep(asset, dep, install = true) { try { + if (dep.resolved) { + return this.getLoadedAsset(dep.resolved); + } + return await this.resolveAsset(dep.name, asset.name); } catch (err) { // If the dep is optional, return before we throw @@ -493,11 +497,10 @@ class Bundler extends EventEmitter { // First try the cache, otherwise load and compile in the background let startTime = Date.now(); let processed = this.cache && (await this.cache.read(asset.name)); + let cacheMiss = false; if (!processed || asset.shouldInvalidate(processed.cacheData)) { processed = await this.farm.run(asset.name); - if (this.cache) { - this.cache.write(asset.name, processed); - } + cacheMiss = true; } asset.buildTime = Date.now() - startTime; @@ -538,8 +541,13 @@ class Bundler extends EventEmitter { let assetDep = assetDeps[i]; if (assetDep) { asset.depAssets.set(dep, assetDep); + dep.resolved = assetDep.name; } }); + + if (this.cache && cacheMiss) { + this.cache.write(asset.name, processed); + } } createBundleTree(asset, bundle, dep, parentBundles = new Set()) {