DEV: Exclude deprecation-collector plugin from source identifier (#24662)

This commit is contained in:
David Taylor 2023-12-01 12:21:19 +00:00 committed by GitHub
parent 4df672a541
commit b72a177fb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -15,8 +15,14 @@ export default function identifySource(error) {
return;
}
const themeMatches =
error.stack.match(/\/theme-javascripts\/[\w-]+\.js/g) || [];
// Ignore the discourse-deprecation-collector plugin because it inserts itself
// into all deprecation stacks.
const stack = error.stack.replaceAll(
/^.*discourse-deprecation-collector.*$/gm,
""
);
const themeMatches = stack.match(/\/theme-javascripts\/[\w-]+\.js/g) || [];
for (const match of themeMatches) {
const scriptElement = document.querySelector(`script[src*="${match}"`);
@ -32,16 +38,14 @@ export default function identifySource(error) {
if (DEBUG) {
// Development (no fingerprinting)
plugin ??= error.stack.match(/assets\/plugins\/([\w-]+)\.js/)?.[1];
plugin ??= stack.match(/assets\/plugins\/([\w-]+)\.js/)?.[1];
// Test files:
plugin ??= error.stack.match(
/assets\/plugins\/test\/([\w-]+)_tests\.js/
)?.[1];
plugin ??= stack.match(/assets\/plugins\/test\/([\w-]+)_tests\.js/)?.[1];
}
// Production (with fingerprints)
plugin ??= error.stack.match(
plugin ??= stack.match(
/assets\/plugins\/_?([\w-]+)-[0-9a-f]+(?:\.br)?\.js/
)?.[1];