From c4e34047a1d274849b5239f91aa3ed9db21fc31c Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 11 Feb 2022 09:17:24 +0000 Subject: [PATCH] DEV: Prefix deprecation notices and api warnings with theme name/id --- .../discourse-common/addon/lib/deprecated.js | 10 +++++++++- .../javascripts/discourse/app/lib/plugin-api.js | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse-common/addon/lib/deprecated.js b/app/assets/javascripts/discourse-common/addon/lib/deprecated.js index e1d82d3bb20..1c36871d6af 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/deprecated.js +++ b/app/assets/javascripts/discourse-common/addon/lib/deprecated.js @@ -11,5 +11,13 @@ export default function deprecated(msg, opts = {}) { if (opts.raiseError) { throw msg; } - console.warn(msg); // eslint-disable-line no-console + + let consolePrefix = ""; + if (window.Discourse) { + // This module doesn't exist in pretty-text/wizard/etc. + consolePrefix = + require("discourse/lib/source-identifier").consolePrefix() || ""; + } + + console.warn(consolePrefix, msg); //eslint-disable-line no-console } diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js index bad054424fe..ed0ed57cc2e 100644 --- a/app/assets/javascripts/discourse/app/lib/plugin-api.js +++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js @@ -92,6 +92,7 @@ import { } from "discourse/widgets/search-menu-results"; import { CUSTOM_USER_SEARCH_OPTIONS } from "select-kit/components/user-chooser"; import { downloadCalendar } from "discourse/lib/download-calendar"; +import { consolePrefix } from "discourse/lib/source-identifier"; // If you add any methods to the API ensure you bump up the version number // based on Semantic Versioning 2.0.0. Please update the changelog at @@ -104,6 +105,7 @@ function canModify(klass, type, resolverName, changes) { if (!changes.pluginId) { // eslint-disable-next-line no-console console.warn( + consolePrefix(), "To prevent errors in tests, add a `pluginId` key to your `modifyClass` call. This will ensure the modification is only applied once." ); return true; @@ -166,6 +168,7 @@ class PluginApi { if (this.container.cache[resolverName]) { // eslint-disable-next-line no-console console.warn( + consolePrefix(), `"${resolverName}" was already cached in the container. Changes won't be applied.` ); } @@ -174,7 +177,10 @@ class PluginApi { if (!klass) { if (!opts.ignoreMissing) { // eslint-disable-next-line no-console - console.warn(`"${resolverName}" was not found by modifyClass`); + console.warn( + consolePrefix(), + `"${resolverName}" was not found by modifyClass` + ); } return; } @@ -981,6 +987,7 @@ class PluginApi { if (!item["name"]) { // eslint-disable-next-line no-console console.warn( + consolePrefix(), "A 'name' is required when adding a Navigation Bar Item.", item ); @@ -1643,7 +1650,7 @@ function getPluginApi(version) { return pluginApi; } else { // eslint-disable-next-line no-console - console.warn(`Plugin API v${version} is not supported`); + console.warn(consolePrefix(), `Plugin API v${version} is not supported`); } } @@ -1670,6 +1677,7 @@ function decorate(klass, evt, cb, id) { if (!id) { // eslint-disable-next-line no-console console.warn( + consolePrefix(), "`decorateCooked` should be supplied with an `id` option to avoid memory leaks in test mode. The id will be used to ensure the decorator is only applied once." ); } else {