@@ -20,6 +20,13 @@ function isTemplate(moduleName) {
20
20
return moduleName . includes ( "/templates/" ) ;
21
21
}
22
22
23
+ function appendToCache ( cache , key , value ) {
24
+ let cachedValue = cache . get ( key ) ;
25
+ cachedValue ??= [ ] ;
26
+ cachedValue . push ( value ) ;
27
+ cache . set ( key , cachedValue ) ;
28
+ }
29
+
23
30
function buildPrioritizedMaps ( moduleNames ) {
24
31
const coreTemplates = new Map ( ) ;
25
32
const pluginTemplates = new Map ( ) ;
@@ -29,11 +36,12 @@ function buildPrioritizedMaps(moduleNames) {
29
36
if ( isInRecognisedNamespace ( moduleName ) && isTemplate ( moduleName ) ) {
30
37
let pluginMatch , themeMatch ;
31
38
if ( ( pluginMatch = moduleName . match ( pluginRegex ) ) ) {
32
- pluginTemplates . set ( pluginMatch [ 2 ] , moduleName ) ;
39
+ appendToCache ( pluginTemplates , pluginMatch [ 2 ] , moduleName ) ;
33
40
} else if ( ( themeMatch = moduleName . match ( themeRegex ) ) ) {
34
- themeTemplates . set ( themeMatch [ 2 ] , moduleName ) ;
41
+ appendToCache ( themeTemplates , themeMatch [ 2 ] , moduleName ) ;
35
42
} else {
36
- coreTemplates . set (
43
+ appendToCache (
44
+ coreTemplates ,
37
45
moduleName . replace ( / ^ d i s c o u r s e \/ t e m p l a t e s \/ / , "" ) ,
38
46
moduleName
39
47
) ;
@@ -60,8 +68,10 @@ class DiscourseTemplateMap {
60
68
this . templates . clear ( ) ;
61
69
62
70
for ( const templateMap of buildPrioritizedMaps ( moduleNames ) ) {
63
- for ( const [ path , moduleName ] of templateMap ) {
64
- this . #add( path , moduleName ) ;
71
+ for ( const [ path , modulesForPath ] of templateMap ) {
72
+ for ( const moduleForPath of modulesForPath ) {
73
+ this . #add( path , moduleForPath ) ;
74
+ }
65
75
}
66
76
}
67
77
}
0 commit comments