@@ -27,6 +27,7 @@ import {
27
27
concat ,
28
28
defer ,
29
29
from ,
30
+ identity ,
30
31
map ,
31
32
merge ,
32
33
mergeMap ,
@@ -132,15 +133,52 @@ let assurePosixSep = function (p: string): string {
132
133
* @param p - string path
133
134
* @returns String path
134
135
*/
135
- const winSepRegex = new RegExp ( `\\${ path . win32 . sep } ` , "g" ) ;
136
136
function assurePosixSepWin ( p : string ) : string {
137
137
return p . replace ( winSepRegex , path . posix . sep )
138
138
} ;
139
139
140
+ const winSepRegex = new RegExp ( `\\${ path . win32 . sep } ` , "g" ) ;
141
+
140
142
if ( path . sep === path . win32 . sep ) {
141
143
assurePosixSep = assurePosixSepWin ;
142
144
}
143
145
146
+ /**
147
+ * Compare two path strings to decide on the order
148
+ *
149
+ * On Windows the default order of paths containing `_` from the resolve function
150
+ * is different than on macOS. This function restores the order to the usual.
151
+ * Implementation adapted based on https://t.ly/VJp78
152
+ *
153
+ * @param reference Left string to compare
154
+ * @param compare Right string to compare against
155
+ * @returns Number for the sort function to define the order
156
+ */
157
+ function windowsPathSorter ( reference : string , compare : string ) : number {
158
+ reference = reference . toLowerCase ( ) ;
159
+ compare = compare . toLowerCase ( ) ;
160
+
161
+ const length = Math . min ( reference . length , compare . length ) ;
162
+
163
+ for ( let i = 0 ; i < length ; i ++ ) {
164
+ const leftChar = reference [ i ] ;
165
+ const rightChar = compare [ i ] ;
166
+
167
+ if ( leftChar !== rightChar )
168
+ return customAlphabet . indexOf ( leftChar ) - customAlphabet . indexOf ( rightChar ) ;
169
+ }
170
+
171
+ if ( reference . length !== compare . length ) {
172
+ if ( compare . startsWith ( reference ) && compare [ reference . length ] === "-" )
173
+ return 1 ;
174
+ return reference . length - compare . length ;
175
+ }
176
+
177
+ return 0 ;
178
+ }
179
+
180
+ const customAlphabet : string = "_,-.0123456789abcdefghijklmnopqrstuvwxyz" ;
181
+
144
182
/* ----------------------------------------------------------------------------
145
183
* Tasks
146
184
* ------------------------------------------------------------------------- */
@@ -322,7 +360,13 @@ const icons$ = defer(() => resolve("**/*.svg", {
322
360
reduce ( ( index , file ) => index . set (
323
361
file . replace ( / \. s v g $ / , "" ) . replace ( new RegExp ( `\\${ path . sep } ` , "g" ) , "-" ) ,
324
362
assurePosixSep ( file )
325
- ) , new Map < string , string > ( ) )
363
+ ) , new Map < string , string > ( ) ) ,
364
+ // The icons are stored in the index file, and the output needs to be OS
365
+ // agnostic. Some icons contain the `_` character, which has different order
366
+ // in the glob output in Windows.
367
+ ( path . sep === path . win32 . sep ) ? map ( icons => new Map (
368
+ [ ...icons ] . sort ( ( a , b ) => windowsPathSorter ( a [ 0 ] , b [ 0 ] ) )
369
+ ) ) : identity
326
370
)
327
371
328
372
/* Compute emoji mappings (based on Twemoji) */
0 commit comments