Skip to content

Commit a9cf9ae

Browse files
DEV: Correctly warn about inter-theme/plugin template clashes (#33124)
Followup to d5ddaf0
1 parent 8f52b81 commit a9cf9ae

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

app/assets/javascripts/discourse/app/lib/discourse-template-map.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ function isTemplate(moduleName) {
2020
return moduleName.includes("/templates/");
2121
}
2222

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+
2330
function buildPrioritizedMaps(moduleNames) {
2431
const coreTemplates = new Map();
2532
const pluginTemplates = new Map();
@@ -29,11 +36,12 @@ function buildPrioritizedMaps(moduleNames) {
2936
if (isInRecognisedNamespace(moduleName) && isTemplate(moduleName)) {
3037
let pluginMatch, themeMatch;
3138
if ((pluginMatch = moduleName.match(pluginRegex))) {
32-
pluginTemplates.set(pluginMatch[2], moduleName);
39+
appendToCache(pluginTemplates, pluginMatch[2], moduleName);
3340
} else if ((themeMatch = moduleName.match(themeRegex))) {
34-
themeTemplates.set(themeMatch[2], moduleName);
41+
appendToCache(themeTemplates, themeMatch[2], moduleName);
3542
} else {
36-
coreTemplates.set(
43+
appendToCache(
44+
coreTemplates,
3745
moduleName.replace(/^discourse\/templates\//, ""),
3846
moduleName
3947
);
@@ -60,8 +68,10 @@ class DiscourseTemplateMap {
6068
this.templates.clear();
6169

6270
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+
}
6575
}
6676
}
6777
}

0 commit comments

Comments
 (0)