File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
icon-build-helpers/src/metadata Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,19 @@ async function create(directory) {
90
90
}
91
91
92
92
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
+
93
106
entry . assets . push ( {
94
107
filepath : asset . filepath ,
95
108
size : asset . size ,
@@ -99,6 +112,17 @@ async function create(directory) {
99
112
return registry ;
100
113
}
101
114
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
+
102
126
const denylist = new Set ( [ '.DS_Store' ] ) ;
103
127
104
128
/**
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments