Skip to content

Commit

Permalink
Copy on write to fix writing hashed bundle names to the cache
Browse files Browse the repository at this point in the history
Fixes #1586.
  • Loading branch information
devongovett committed Jun 25, 2018
1 parent b62132c commit 1bd5fcc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Asset.js
Expand Up @@ -231,15 +231,23 @@ class Asset {
}

replaceBundleNames(bundleNameMap) {
let copied = false;
for (let key in this.generated) {
let value = this.generated[key];
if (typeof value === 'string') {
// Replace temporary bundle names in the output with the final content-hashed names.
let newValue = value;
for (let [name, map] of bundleNameMap) {
value = value.split(name).join(map);
newValue = newValue.split(name).join(map);
}

this.generated[key] = value;
// Copy `this.generated` on write so we don't end up writing the final names to the cache.
if (newValue !== value && !copied) {
this.generated = Object.assign({}, this.generated);
copied = true;
}

this.generated[key] = newValue;
}
}
}
Expand Down

0 comments on commit 1bd5fcc

Please sign in to comment.