Skip to content

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

DEV: Prefix deprecation notices with plugin name (#15942)

David Taylorebb5c1ff4ddd
diff --git a/app/assets/javascripts/discourse/app/lib/source-identifier.js b/app/assets/javascripts/discourse/app/lib/source-identifier.js
index 0ba32e30a4b..da342b550af 100644
--- a/app/assets/javascripts/discourse/app/lib/source-identifier.js
+++ b/app/assets/javascripts/discourse/app/lib/source-identifier.js
@@ -1,5 +1,6 @@
import getURL from "discourse-common/lib/get-url";
import PreloadStore from "discourse/lib/preload-store";
+import { isDevelopment } from "discourse-common/config/environment";
export default function identifySource(error) {
if (!error || !error.stack) {
@@ -26,6 +27,28 @@ export default function identifySource(error) {
};
}
}
+
+ let plugin;
+
+ if (isDevelopment()) {
+ // Source-mapped:
+ plugin = plugin || error.stack.match(/plugins\/([\w-]+)\//)?.[1];
+
+ // Un-source-mapped:
+ plugin = plugin || error.stack.match(/assets\/plugins\/([\w-]+)\.js/)?.[1];
+ }
+
+ // Production mode
+ plugin =
+ plugin ||
+ error.stack.match(/assets\/plugins\/_?([\w-]+)-[0-9a-f]+\.js/)?.[1];
+
+ if (plugin) {
+ return {
+ type: "plugin",
+ name: plugin,
+ };
+ }
}
export function getThemeInfo(id) {
@@ -41,6 +64,9 @@ export function consolePrefix(error, source) {
source = source || identifySource(error);
if (source && source.type === "theme") {
return `[THEME ${source.id} '${source.name}']`;
+ } else if (source && source.type === "plugin") {
+ return `[PLUGIN ${source.name}]`;
}
+
return "";
}
diff --git a/config/application.rb b/config/application.rb
index 072b86f6d1f..437bbdf8362 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -241,7 +241,7 @@ module Discourse
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
- config.assets.version = '1.2.4'
+ config.assets.version = '1.2.5'
# see: http://stackoverflow.com/questions/11894180/how-does-one-correctly-add-custom-sql-dml-in-migrations/11894420#11894420
config.active_record.schema_format = :sql
diff --git a/lib/discourse_js_processor.rb b/lib/discourse_js_processor.rb
index 7fd18e136d3..efb0890012b 100644
--- a/lib/discourse_js_processor.rb
+++ b/lib/discourse_js_processor.rb
@@ -19,7 +19,14 @@ class DiscourseJsProcessor
# add sourceURL until we can do proper source maps
unless Rails.env.production?
- data = "eval(#{data.inspect} + \"\\n//# sourceURL=#{logical_path}\");\n"
+ plugin_name = root_path[/\/plugins\/([\w-]+)\/assets/, 1]
+ source_url = if plugin_name
+ "plugins/#{plugin_name}/assets/javascripts/#{logical_path}"
+ else
+ logical_path
+ end
+
+ data = "eval(#{data.inspect} + \"\\n//# sourceURL=#{source_url}\");\n"
end
{ data: data }