DEV: Improve plugin/theme deprecation prefixes (#24155)
- Add prefixes to Ember deprecations (previously was just Discourse deprecations) - Allow logic to work in tests (where window.Discourse is not defined) - Detect `{plugin}_tests.js` files - Optimise dev/test regex logic out of the production build using `if(DEBUG)`
This commit is contained in:
parent
bbcf8e421c
commit
32716f3746
|
@ -39,7 +39,7 @@ export default function deprecated(msg, options = {}) {
|
|||
msg = msg.join(" ");
|
||||
|
||||
let consolePrefix = "";
|
||||
if (window.Discourse) {
|
||||
if (require.has("discourse/lib/source-identifier")) {
|
||||
// This module doesn't exist in pretty-text/wizard/etc.
|
||||
consolePrefix =
|
||||
require("discourse/lib/source-identifier").consolePrefix() || "";
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import { registerDeprecationHandler } from "@ember/debug";
|
||||
import { consolePrefix } from "discourse/lib/source-identifier";
|
||||
|
||||
let registered = false;
|
||||
|
||||
export default {
|
||||
initialize() {
|
||||
if (registered) {
|
||||
return;
|
||||
}
|
||||
|
||||
registerDeprecationHandler((message, options, next) => {
|
||||
let prefix = consolePrefix();
|
||||
if (prefix) {
|
||||
next(`${prefix} ${message}`, options);
|
||||
} else {
|
||||
next(message, options);
|
||||
}
|
||||
});
|
||||
|
||||
registered = true;
|
||||
},
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
import DEBUG from "@glimmer/env";
|
||||
import PreloadStore from "discourse/lib/preload-store";
|
||||
import { isDevelopment } from "discourse-common/config/environment";
|
||||
import getURL from "discourse-common/lib/get-url";
|
||||
|
||||
export default function identifySource(error) {
|
||||
|
@ -30,20 +30,20 @@ export default function identifySource(error) {
|
|||
|
||||
let plugin;
|
||||
|
||||
// Source-mapped:
|
||||
plugin = plugin || error.stack.match(/plugins\/([\w-]+)\//)?.[1];
|
||||
if (DEBUG) {
|
||||
// Development (no fingerprinting)
|
||||
plugin ??= error.stack.match(/assets\/plugins\/([\w-]+)\.js/)?.[1];
|
||||
|
||||
if (isDevelopment()) {
|
||||
// Un-source-mapped:
|
||||
plugin = plugin || error.stack.match(/assets\/plugins\/([\w-]+)\.js/)?.[1];
|
||||
// Test files:
|
||||
plugin ??= error.stack.match(
|
||||
/assets\/plugins\/test\/([\w-]+)_tests\.js/
|
||||
)?.[1];
|
||||
}
|
||||
|
||||
// Production mode
|
||||
plugin =
|
||||
plugin ||
|
||||
error.stack.match(
|
||||
/assets\/plugins\/_?([\w-]+)-[0-9a-f]+(?:\.br)?\.js/
|
||||
)?.[1];
|
||||
// Production (with fingerprints)
|
||||
plugin ??= error.stack.match(
|
||||
/assets\/plugins\/_?([\w-]+)-[0-9a-f]+(?:\.br)?\.js/
|
||||
)?.[1];
|
||||
|
||||
if (plugin) {
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue