Skip to content

Commit

Permalink
check for duplicate asset ids
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper committed Jul 26, 2018
1 parent 2e1ffc6 commit 804a8a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class Asset {
if (!this.id) {
this.id =
this.options.production || this.options.scopeHoist
? md5(this.relativeName, 'base64').slice(0, 4)
? md5(this.relativeName, 'base64').slice(0, 10)
: this.relativeName;
}

Expand Down
25 changes: 25 additions & 0 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Bundler extends EventEmitter {
this.loadedAssets = new Map();
this.watchedAssets = new Map();

this.assets = new Map();

this.farm = null;
this.watcher = null;
this.hmr = null;
Expand Down Expand Up @@ -517,6 +519,23 @@ class Bundler extends EventEmitter {
await this.loadAsset(asset);
}

sliceAssetId(asset, length = 3, offset = 0) {
if (offset + length >= asset.id.length) {
throw new Error(`Could not find an asset id for ${asset.relativeName}`);
}

let assetId = asset.id;
assetId = assetId.slice(offset, offset + length);
if (this.assets.has(assetId)) {
if (length < 4) {
length++;
}
return this.sliceAssetId(asset, length, offset + 1);
}

return assetId;
}

async loadAsset(asset) {
if (asset.processed) {
return;
Expand Down Expand Up @@ -545,6 +564,12 @@ class Bundler extends EventEmitter {
asset.hash = processed.hash;
asset.cacheData = processed.cacheData;

if (this.options.production && !this.options.scopeHoist) {
asset.id = this.sliceAssetId(asset);
}

this.assets.set(asset.id, asset);

// Call the delegate to get implicit dependencies
let dependencies = processed.dependencies;
if (this.delegate.getImplicitDependencies) {
Expand Down

0 comments on commit 804a8a8

Please sign in to comment.