A platform for community discussion. Free, open, simple.
DEV: Support colocation under `/admin` namespace in themes/plugins (#19353)
David Taylor566793208ec9
diff --git a/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js b/app/assets/javascripts/discourse-plugins/colocated-template-compiler.jsindex 9cc4d462b21..04611e3697d 100644--- a/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js+++ b/app/assets/javascripts/discourse-plugins/colocated-template-compiler.js@@ -3,12 +3,12 @@ const ColocatedTemplateProcessor = require("ember-cli-htmlbars/lib/colocated-bromodule.exports = class DiscoursePluginColocatedTemplateProcessor extends (ColocatedTemplateProcessor) {- constructor(tree, discoursePluginName) {+ constructor(tree, rootName) {super(tree);- this.discoursePluginName = discoursePluginName;+ this.rootName = rootName;}detectRootName() {- return `discourse/plugins/${this.discoursePluginName}/discourse`;+ return this.rootName;}};diff --git a/app/assets/javascripts/discourse-plugins/index.js b/app/assets/javascripts/discourse-plugins/index.jsindex 730f926472b..b4b25cfcc34 100644--- a/app/assets/javascripts/discourse-plugins/index.js+++ b/app/assets/javascripts/discourse-plugins/index.js@@ -176,7 +176,15 @@ module.exports = {tree = RawHandlebarsCompiler(tree);- tree = new DiscoursePluginColocatedTemplateProcessor(tree, pluginName);+ const colocateBase = `discourse/plugins/${pluginName}`;+ tree = new DiscoursePluginColocatedTemplateProcessor(+ tree,+ `${colocateBase}/discourse`+ );+ tree = new DiscoursePluginColocatedTemplateProcessor(+ tree,+ `${colocateBase}/admin`+ );tree = this.compileTemplates(tree);tree = this.processedAddonJsFiles(tree);diff --git a/lib/theme_javascript_compiler.rb b/lib/theme_javascript_compiler.rbindex f4f7047fe2a..b8c9458a5ad 100644--- a/lib/theme_javascript_compiler.rb+++ b/lib/theme_javascript_compiler.rb@@ -89,8 +89,6 @@ class ThemeJavascriptCompilerenddef append_tree(tree, for_tests: false)- root_name = "discourse"-# Replace legacy extensionstree.transform_keys! do |filename|if filename.ends_with? ".js.es6"@@ -121,7 +119,7 @@ class ThemeJavascriptCompiler# Handle colocated componentstree.dup.each_pair do |filename, content|- is_component_template = filename.end_with?(".hbs") && filename.start_with?("#{root_name}/components/")+ is_component_template = filename.end_with?(".hbs") && filename.start_with?("discourse/components/", "admin/components/")next if !is_component_templatetemplate_contents = contentdiff --git a/spec/lib/theme_javascript_compiler_spec.rb b/spec/lib/theme_javascript_compiler_spec.rbindex 8d94ed72d5b..6392b429981 100644--- a/spec/lib/theme_javascript_compiler_spec.rb+++ b/spec/lib/theme_javascript_compiler_spec.rb@@ -110,6 +110,20 @@ RSpec.describe ThemeJavascriptCompiler doexpect(compiler.raw_content).to include("setComponentTemplate")end+ it "handles colocated admin components" do+ compiler.append_tree(+ {+ "admin/components/mycomponent.js" => <<~JS,+ import Component from "@glimmer/component";+ export default class MyComponent extends Component {}+ JS+ "admin/components/mycomponent.hbs" => "{{my-component-template}}"+ }+ )+ expect(compiler.raw_content).to include("__COLOCATED_TEMPLATE__ =")+ expect(compiler.raw_content).to include("setComponentTemplate")+ end+it "applies theme AST transforms to colocated components" docompiler = ThemeJavascriptCompiler.new(12345678910, 'my theme name')compiler.append_tree(