From 556d66a97c166b0dacd1566e2779c533941cb68f Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 10 Jan 2020 15:06:15 -0500 Subject: [PATCH] FIX: Use CDN for the `discourse-internet-explorer` Previously the CDN was skipped because the assets were not in the proper place to be uploaded. --- lib/discourse.rb | 1 + plugins/discourse-internet-explorer/plugin.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/discourse.rb b/lib/discourse.rb index f4819a210e6..62ba6133164 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -194,6 +194,7 @@ module Discourse STDERR.puts "Could not activate #{p.metadata.name}, discourse does not meet required version (#{v})" end end + DiscourseEvent.trigger(:after_plugin_activation) end def self.disabled_plugin_names diff --git a/plugins/discourse-internet-explorer/plugin.rb b/plugins/discourse-internet-explorer/plugin.rb index 0e97cf4cbd6..5eff00501c4 100644 --- a/plugins/discourse-internet-explorer/plugin.rb +++ b/plugins/discourse-internet-explorer/plugin.rb @@ -11,6 +11,14 @@ hide_plugin if self.respond_to?(:hide_plugin) register_asset 'stylesheets/ie.scss' +# We can't use register asset for an optional resource. Instead copy it after plugins have +# been activated so it can be uploaded to CDNs. +DiscourseEvent.on(:after_plugin_activation) do || + polyfill_path = "#{Plugin::Instance.js_path}/#{self.directory_name}-optional.js" + puts polyfill_path + FileUtils.cp("#{Rails.root}/public/plugins/discourse-internet-explorer/js/ie.js", polyfill_path) +end + after_initialize do # Conditionally load the stylesheet. There is unfortunately no easy way to do this via @@ -47,7 +55,7 @@ after_initialize do # to be loaded before other files register_html_builder('server:before-script-load') do |controller| if BrowserDetection.browser(controller.request.env['HTTP_USER_AGENT']) == :ie - path = "#{Discourse.base_uri}/plugins/discourse-internet-explorer/js/ie.js" + path = controller.helpers.script_asset_path('plugins/discourse-internet-explorer-optional') <<~JAVASCRIPT