From 0a33c507d950ec33a40922f8130a57fcd31996f1 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 21 Oct 2022 20:20:46 +0100 Subject: [PATCH] DEV: Improve colocated component rootName logic (#18708) The complex regex-based detection was based on Ember CLI's implementation, which is necessarily generic and needs to auto-detect the name. In our case, we know the name of the plugin so we can just pass it in - no need for dynamic detection. This resolves issues when there are other files in the `discourse/plugins/{name}` directory which are sorted before `discourse/` --- .../colocated-template-compiler.js | 17 ++++++----------- .../javascripts/discourse-plugins/index.js | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js b/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js index 2cc0759cf38..9cc4d462b21 100644 --- a/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js +++ b/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js @@ -3,17 +3,12 @@ const ColocatedTemplateProcessor = require("ember-cli-htmlbars/lib/colocated-bro module.exports = class DiscoursePluginColocatedTemplateProcessor extends ( ColocatedTemplateProcessor ) { + constructor(tree, discoursePluginName) { + super(tree); + this.discoursePluginName = discoursePluginName; + } + detectRootName() { - const entries = this.currentEntries().filter((e) => !e.isDirectory()); - - const path = entries[0]?.relativePath; - - const match = path?.match( - /^discourse\/plugins\/(?[^/]+)\/discourse\// - ); - - if (match) { - return `discourse/plugins/${match.groups.name}/discourse`; - } + return `discourse/plugins/${this.discoursePluginName}/discourse`; } }; diff --git a/app/assets/javascripts/discourse-plugins/index.js b/app/assets/javascripts/discourse-plugins/index.js index 996f6f08d9b..df33693b319 100644 --- a/app/assets/javascripts/discourse-plugins/index.js +++ b/app/assets/javascripts/discourse-plugins/index.js @@ -171,7 +171,7 @@ module.exports = { tree = RawHandlebarsCompiler(tree); - tree = new DiscoursePluginColocatedTemplateProcessor(tree); + tree = new DiscoursePluginColocatedTemplateProcessor(tree, pluginName); tree = this.compileTemplates(tree); tree = this.processedAddonJsFiles(tree);