A platform for community discussion. Free, open, simple.
DEV: Allow using .js extension for javascript modules in themes (#9358)
David Taylor3814ca06a82e
diff --git a/app/models/theme_field.rb b/app/models/theme_field.rbindex 085a0e649ef..ed0966fb5c4 100644--- a/app/models/theme_field.rb+++ b/app/models/theme_field.rb@@ -134,7 +134,7 @@ class ThemeField < ActiveRecord::Basefilename, extension = name.split(".", 2)begincase extension- when "js.es6"+ when "js.es6", "js"js_compiler.append_module(content, filename)when "hbs"js_compiler.append_ember_template(filename.sub("discourse/templates/", ""), content)diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rbindex 28d2e3de140..306b3aeec30 100644--- a/spec/models/theme_field_spec.rb+++ b/spec/models/theme_field_spec.rb@@ -173,7 +173,8 @@ HTMLit "correctly handles extra JS fields" dotheme = Fabricate(:theme)- js_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery.js.es6", value: "import 'discourse/lib/ajax'; console.log('hello');")+ js_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery.js.es6", value: "import 'discourse/lib/ajax'; console.log('hello from .js.es6');")+ js_2_field = theme.set_field(target: :extra_js, name: "discourse/controllers/discovery-2.js", value: "import 'discourse/lib/ajax'; console.log('hello from .js');")hbs_field = theme.set_field(target: :extra_js, name: "discourse/templates/discovery.hbs", value: "{{hello-world}}")raw_hbs_field = theme.set_field(target: :extra_js, name: "discourse/templates/discovery.hbr", value: "{{hello-world}}")hbr_field = theme.set_field(target: :extra_js, name: "discourse/templates/other_discovery.hbr", value: "{{hello-world}}")@@ -189,7 +190,7 @@ HTMLvar themePrefix = function themePrefix(key) {return "theme_translations.#{theme.id}." + key;};- console.log('hello');+ console.log('hello from .js.es6');});JSexpect(js_field.reload.value_baked).to eq(expected_js.strip)@@ -204,6 +205,7 @@ HTMLexpect(theme.javascript_cache.content).to include('Ember.TEMPLATES["discovery"]')expect(theme.javascript_cache.content).to include('Discourse.RAW_TEMPLATES["discovery"]')expect(theme.javascript_cache.content).to include('define("discourse/controllers/discovery"')+ expect(theme.javascript_cache.content).to include('define("discourse/controllers/discovery-2"')expect(theme.javascript_cache.content).to include("var settings =")end