Skip to content

A platform for community discussion. Free, open, simple.

DEV: Stop storing theme-transpiler on filesystem in development (#28198)

David Taylor11369018b684
diff --git a/app/assets/javascripts/theme-transpiler/build.js b/app/assets/javascripts/theme-transpiler/build.js
index 26fdb119cba..612412713ed 100644
--- a/app/assets/javascripts/theme-transpiler/build.js
+++ b/app/assets/javascripts/theme-transpiler/build.js
@@ -3,7 +3,6 @@
const esbuild = require("esbuild");
const path = require("node:path");
const fs = require("node:fs");
-const { argv } = require("node:process");
let wasmPlugin = {
name: "wasm",
@@ -57,7 +56,6 @@ esbuild
},
external: ["fs", "path"],
entryPoints: ["./app/assets/javascripts/theme-transpiler/transpiler.js"],
- outfile: argv[2],
plugins: [wasmPlugin],
})
.then(() => {});
diff --git a/lib/discourse_js_processor.rb b/lib/discourse_js_processor.rb
index de807a69642..5d5cad9f260 100644
--- a/lib/discourse_js_processor.rb
+++ b/lib/discourse_js_processor.rb
@@ -63,14 +63,7 @@ class DiscourseJsProcessor
end
class Transpiler
- TRANSPILER_PATH =
- (
- if Rails.env.production?
- "tmp/theme-transpiler.js"
- else
- "tmp/theme-transpiler/#{Process.pid}.js"
- end
- )
+ TRANSPILER_PATH = "tmp/theme-transpiler.js"
@mutex = Mutex.new
@ctx_init = Mutex.new
@@ -81,11 +74,12 @@ class DiscourseJsProcessor
end
def self.build_theme_transpiler
- Discourse::Utils.execute_command(
- "node",
- "app/assets/javascripts/theme-transpiler/build.js",
- TRANSPILER_PATH,
- )
+ FileUtils.rm_rf("tmp/theme-transpiler") # cleanup old files - remove after Jan 2025
+ Discourse::Utils.execute_command("node", "app/assets/javascripts/theme-transpiler/build.js")
+ end
+
+ def self.build_production_theme_transpiler
+ File.write(TRANSPILER_PATH, build_theme_transpiler)
TRANSPILER_PATH
end
@@ -98,10 +92,14 @@ class DiscourseJsProcessor
ctx.attach("rails.logger.warn", proc { |err| Rails.logger.warn(err.to_s) })
ctx.attach("rails.logger.error", proc { |err| Rails.logger.error(err.to_s) })
- # Theme template AST transformation plugins
- @processor_mutex.synchronize { build_theme_transpiler } if !Rails.env.production?
+ source =
+ if Rails.env.production?
+ File.read(TRANSPILER_PATH)
+ else
+ @processor_mutex.synchronize { build_theme_transpiler }
+ end
- ctx.eval(File.read(TRANSPILER_PATH), filename: "theme-transpiler.js")
+ ctx.eval(source, filename: "theme-transpiler.js")
ctx
end
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index 7f7b8fc2d98..f75bfcceace 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -321,7 +321,7 @@ task "assets:precompile:compress_js": "environment" do
end
task "assets:precompile:theme_transpiler": "environment" do
- DiscourseJsProcessor::Transpiler.build_theme_transpiler
+ DiscourseJsProcessor::Transpiler.build_production_theme_transpiler
end
# Run these tasks **before** Rails' "assets:precompile" task
diff --git a/spec/tasks/assets_precompile_spec.rb b/spec/tasks/assets_precompile_spec.rb
index d12d3ee0808..723223dd60c 100644
--- a/spec/tasks/assets_precompile_spec.rb
+++ b/spec/tasks/assets_precompile_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe "assets:precompile" do
it "compiles the js processor" do
path = Rake::Task["assets:precompile:theme_transpiler"].actions.first.call
- expect(path).to match(%r{tmp/theme-transpiler})
+ expect(path).to end_with("tmp/theme-transpiler.js")
expect(File.exist?(path)).to eq(true)
end
end