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/`
This commit is contained in:
David Taylor 2022-10-21 20:20:46 +01:00 committed by GitHub
parent db0dbdf89a
commit 0a33c507d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 12 deletions

View File

@ -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\/(?<name>[^/]+)\/discourse\//
);
if (match) {
return `discourse/plugins/${match.groups.name}/discourse`;
}
return `discourse/plugins/${this.discoursePluginName}/discourse`;
}
};

View File

@ -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);