Skip to content

Commit

Permalink
fix(icons): remove duplicate asset and add check to helpers (#5844)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack committed Apr 16, 2020
1 parent c2d6751 commit 8968bf5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/icon-build-helpers/src/metadata/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ async function create(directory) {
}

const entry = registry.get(asset.id);

// We have an invariant that all icons in a source SVG folder must have a
// unique name even if they are under different namespaces.
if (hash(entry.id, entry.namespace) !== hash(asset.id, asset.namespace)) {
const expected = entry.namespace.join(', ');
const actual = asset.namespace.join(', ');
throw new Error(
`Found namespace mismatch with asset ${asset.id}. Expected ` +
`[${expected}] but received [${actual}]. This likely means that ` +
`there is a duplicate asset in the source SVG folder`
);
}

entry.assets.push({
filepath: asset.filepath,
size: asset.size,
Expand All @@ -99,6 +112,17 @@ async function create(directory) {
return registry;
}

/**
* Generate a hash with the basename and namespace of an asset to compare if two
* assets in the registry are equivalent
* @param {string} basename
* @param {Array<string>} [namespace]
* @returns {string}
*/
function hash(basename, namespace = []) {
return [...namespace, basename].join('/');
}

const denylist = new Set(['.DS_Store']);

/**
Expand Down
1 change: 0 additions & 1 deletion packages/icons/svg/32/composer-edit.svg

This file was deleted.

0 comments on commit 8968bf5

Please sign in to comment.