DEV: Allow using .js extension for javascript modules in themes (#9358)

DEV: Allow using .js extension for javascript modules in themes (#9358)

diff --git a/app/models/theme_field.rb b/app/models/theme_field.rb
index 085a0e6..ed0966f 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 28d2e3d..306b3ae 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
 

GitHub sha: 3814ca06

This commit appears in #9358 which was merged by davidtaylorhq.