Skip to content

Commit 8968bf5

Browse files
committed
fix(icons): remove duplicate asset and add check to helpers (#5844)
1 parent c2d6751 commit 8968bf5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/icon-build-helpers/src/metadata/registry.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ async function create(directory) {
9090
}
9191

9292
const entry = registry.get(asset.id);
93+
94+
// We have an invariant that all icons in a source SVG folder must have a
95+
// unique name even if they are under different namespaces.
96+
if (hash(entry.id, entry.namespace) !== hash(asset.id, asset.namespace)) {
97+
const expected = entry.namespace.join(', ');
98+
const actual = asset.namespace.join(', ');
99+
throw new Error(
100+
`Found namespace mismatch with asset ${asset.id}. Expected ` +
101+
`[${expected}] but received [${actual}]. This likely means that ` +
102+
`there is a duplicate asset in the source SVG folder`
103+
);
104+
}
105+
93106
entry.assets.push({
94107
filepath: asset.filepath,
95108
size: asset.size,
@@ -99,6 +112,17 @@ async function create(directory) {
99112
return registry;
100113
}
101114

115+
/**
116+
* Generate a hash with the basename and namespace of an asset to compare if two
117+
* assets in the registry are equivalent
118+
* @param {string} basename
119+
* @param {Array<string>} [namespace]
120+
* @returns {string}
121+
*/
122+
function hash(basename, namespace = []) {
123+
return [...namespace, basename].join('/');
124+
}
125+
102126
const denylist = new Set(['.DS_Store']);
103127

104128
/**

packages/icons/svg/32/composer-edit.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)