Skip to content

Commit

Permalink
Cache resolved paths of dependencies (#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed May 6, 2018
1 parent 2f7be14 commit adeee42
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Bundler.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit adeee42

Please sign in to comment.