From 4fdeb6281e8ae9e1b049ef8547f34d86e92c2777 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 24 Aug 2023 13:19:57 +0200 Subject: [PATCH] FIX: `assets:precompile:js_processor` task issue (#23219) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix the reference * Use mutex in non-prod only (…and don't try to build the processor in runtime in prod) --- lib/discourse_js_processor.rb | 32 +++++++++++++++----------------- lib/tasks/assets.rake | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/discourse_js_processor.rb b/lib/discourse_js_processor.rb index b665de0ced0..cb1eee6c9d1 100644 --- a/lib/discourse_js_processor.rb +++ b/lib/discourse_js_processor.rb @@ -110,22 +110,17 @@ class DiscourseJsProcessor end def self.generate_js_processor - @processor_mutex.synchronize do - if Rails.env.development? || Rails.env.test? || - !File.exist?("#{Rails.root}/#{JS_PROCESSOR_PATH}") - Discourse::Utils.execute_command( - "yarn", - "--silent", - "esbuild", - "--log-level=warning", - "--bundle", - "--external:fs", - "--define:process='{\"env\":{}}'", - "app/assets/javascripts/js-processor.js", - "--outfile=#{JS_PROCESSOR_PATH}", - ) - end - end + Discourse::Utils.execute_command( + "yarn", + "--silent", + "esbuild", + "--log-level=warning", + "--bundle", + "--external:fs", + "--define:process='{\"env\":{}}'", + "app/assets/javascripts/js-processor.js", + "--outfile=#{JS_PROCESSOR_PATH}", + ) end def self.create_new_context @@ -138,7 +133,10 @@ class DiscourseJsProcessor ctx.attach("rails.logger.error", proc { |err| Rails.logger.error(err.to_s) }) # Theme template AST transformation plugins - generate_js_processor + if Rails.env.development? || Rails.env.test? + @processor_mutex.synchronize { generate_js_processor } + end + ctx.eval(File.read(JS_PROCESSOR_PATH), filename: "js-processor.js") ctx diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index a3aeac5d055..f98cfbddffc 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -301,7 +301,7 @@ task "assets:precompile:compress_js" do end task "assets:precompile:js_processor": "environment" do - DiscourseJsProcessor.generate_js_processor + DiscourseJsProcessor::Transpiler.generate_js_processor end task "assets:precompile": %w[