DEV: perform theme extra_js compilation all together

Previously, compiling theme 'extra_js' was done with a number of steps. Each theme_field would be compiled into its own value_baked column, and then the JavascriptCache content would be built by concatenating all of those compiled values.

This commit streamlines things by removing the value_baked step. The raw value of all extra_js theme_fields are passed directly to the ThemeJavascriptCompiler, and then the result is stored in the JavascriptCache.

In itself, this commit should not cause any behavior change. It is designed to open the door to more advanced compilation features which have interdependencies between different source files (e.g. template colocation, sourcemaps).
This commit is contained in:
David Taylor
2022-10-17 15:04:04 +01:00
parent 9879cb0e68
commit 65a5c84a92
6 changed files with 68 additions and 48 deletions

View File

@ -2,7 +2,6 @@
RSpec.describe ThemeJavascriptCompiler do
let(:compiler) { ThemeJavascriptCompiler.new(1, 'marks') }
let(:theme_id) { 22 }
describe "#append_raw_template" do
it 'uses the correct template paths' do
@ -72,4 +71,20 @@ RSpec.describe ThemeJavascriptCompiler do
end.to raise_error(ThemeJavascriptCompiler::CompileError, /Parse error on line 1/)
end
end
describe "#append_tree" do
it "can handle multiple modules" do
compiler.append_tree(
{
"discourse/components/mycomponent.js" => <<~JS,
import Component from "@glimmer/component";
export default class MyComponent extends Component {}
JS
"discourse/templates/components/mycomponent.hbs" => "{{my-component-template}}"
}
)
expect(compiler.content).to include('define("discourse/theme-1/components/mycomponent"')
expect(compiler.content).to include('define("discourse/theme-1/discourse/templates/components/mycomponent"')
end
end
end