mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 17:01:09 +08:00
DEV: Stop storing theme-transpiler on filesystem in development (#28198)
We were writing theme-transpiler JS files to the filesystem on a per-process basis, and then immediately reading them back in. Plus, there was no cleanup mechanism, so the tmp directory would grow indefinitely. This commit refactors things so that the `build.js` script outputs the theme-transpiler source to stdout. That way, we can read it directly into the process, and then into mini-racer, without needing to go via the filesystem. No cleanup required! In production, the theme-transpiler is still cached in a file during `assets:precompile`
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user