discourse/frontend/deprecation-silencer/index.js
Jarek Radosz b27530cdb1
DEV: Remove (again) the old non-rollup plugin compiler (#39419)
This reverts commit 7633f0d0ac, cleans up
the tests workflow, and works around the Chrome crash issue. (see:
https://issues.chromium.org/issues/504886986)

Closes #39050
Closes #39051
Closes #39070
Closes #39100
Closes #39158
Closes #39195
Closes #39255
Closes #39308
2026-04-21 21:07:46 +02:00

66 lines
1.6 KiB
JavaScript

const SILENCED_WARN_PREFIXES = [
"Setting the `jquery-integration` optional feature flag",
'unexpectedly found "', // https://github.com/emberjs/ember.js/issues/19392
"The setting 'staticAddonTestSupportTrees'",
"The setting 'staticAddonTrees'",
"\n\n--------\n+ Your app is using the legacy ember-template-compiler.js AMD bundle",
];
class DeprecationSilencer {
constructor() {
this.silenced = new WeakMap();
}
silence(object, method) {
if (this.alreadySilenced(object, method)) {
return;
}
let original = object[method];
object[method] = (message, ...args) => {
if (!this.shouldSilence(message)) {
return original.call(object, message, ...args);
}
};
}
alreadySilenced(object, method) {
let set = this.silenced.get(object);
if (!set) {
set = new Set();
this.silenced.set(object, set);
}
if (set.has(method)) {
return true;
} else {
set.add(method);
return false;
}
}
shouldSilence(message) {
return (
typeof message === "string" &&
SILENCED_WARN_PREFIXES.some((prefix) => message.startsWith(prefix))
);
}
}
const DEPRECATION_SILENCER = new DeprecationSilencer();
/**
* Export a dummy babel plugin which applies the console.warn silences in worker
* processes. Does not actually affect babel output.
*/
module.exports = function () {
DEPRECATION_SILENCER.silence(console, "warn");
DEPRECATION_SILENCER.silence(console, "log");
return {};
};
module.exports.silence = function silence(...args) {
DEPRECATION_SILENCER.silence(...args);
};