diff --git a/app/models/theme.rb b/app/models/theme.rb index 347f54f3a90..8a6e3199984 100644 --- a/app/models/theme.rb +++ b/app/models/theme.rb @@ -6,7 +6,7 @@ require "json_schemer" class Theme < ActiveRecord::Base include GlobalPath - BASE_COMPILER_VERSION = 86 + BASE_COMPILER_VERSION = 87 class SettingsMigrationError < StandardError end diff --git a/lib/theme_javascript_compiler.rb b/lib/theme_javascript_compiler.rb index c599576f56f..bc6dbec9131 100644 --- a/lib/theme_javascript_compiler.rb +++ b/lib/theme_javascript_compiler.rb @@ -209,8 +209,7 @@ class ThemeJavascriptCompiler end def raw_template_name(name) - name = name.sub(/\.(raw|hbr)\z/, "") - name.inspect + name.sub(/\.(raw|hbr)\z/, "") end def append_raw_template(name, hbs_template) @@ -218,16 +217,27 @@ class ThemeJavascriptCompiler DiscourseJsProcessor::Transpiler.new.compile_raw_template(hbs_template, theme_id: @theme_id) source_for_comment = hbs_template.gsub("*/", '*\/').indent(4, " ") modern_replacement_marker = hbs_template.include?("{{!-- has-modern-replacement --}}") - @output_tree << ["#{name}.js", <<~JS] - (function() { - /* + + source = <<~JS + /* #{source_for_comment} - */ - const addRawTemplate = requirejs('discourse-common/lib/raw-templates').addRawTemplate; - const template = requirejs('discourse-common/lib/raw-handlebars').template(#{compiled}); - addRawTemplate(#{raw_template_name(name)}, template, { themeId: #{@theme_id}, themeName: #{@theme_name.to_json}, hasModernReplacement: #{modern_replacement_marker} }); - })(); + */ + + import { template as compiler } from "discourse-common/lib/raw-handlebars"; + import { addRawTemplate } from "discourse-common/lib/raw-templates"; + + let template = compiler(#{compiled}); + + addRawTemplate(#{raw_template_name(name).to_json}, template, { + themeId: #{@theme_id}, + themeName: #{@theme_name.to_json}, + hasModernReplacement: #{modern_replacement_marker} + }); + + export default template; JS + + append_module source, "raw-templates/#{raw_template_name(name)}", "js", include_variables: false rescue MiniRacer::RuntimeError, DiscourseJsProcessor::TranspileError => ex raise CompileError.new ex.message end diff --git a/spec/lib/theme_javascript_compiler_spec.rb b/spec/lib/theme_javascript_compiler_spec.rb index dab065bf9db..50706ab879f 100644 --- a/spec/lib/theme_javascript_compiler_spec.rb +++ b/spec/lib/theme_javascript_compiler_spec.rb @@ -8,15 +8,15 @@ RSpec.describe ThemeJavascriptCompiler do template = "