From 3814ca06a82e064222e8a46933acad734d5b97c4 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 6 Apr 2020 17:24:59 +0100 Subject: [PATCH] DEV: Allow using .js extension for javascript modules in themes (#9358) --- app/models/theme_field.rb | 2 +- spec/models/theme_field_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb index 085a0e649ef..ed0966fb5c4 100644 --- a/app/models/theme_field.rb +++ b/app/models/theme_field.rb @@ -134,7 +134,7 @@ class ThemeField < ActiveRecord::Base filename, extension = name.split(".", 2) begin case 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.rb index 28d2e3de140..306b3aeec30 100644 --- a/spec/models/theme_field_spec.rb +++ b/spec/models/theme_field_spec.rb @@ -173,7 +173,8 @@ HTML it "correctly handles extra JS fields" do theme = 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 @@ HTML var themePrefix = function themePrefix(key) { return "theme_translations.#{theme.id}." + key; }; - console.log('hello'); + console.log('hello from .js.es6'); }); JS expect(js_field.reload.value_baked).to eq(expected_js.strip) @@ -204,6 +205,7 @@ HTML expect(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