ensure an env variable that handles deprecation messages

This commit is contained in:
Leonardo Venturini
2024-12-20 15:44:05 +01:00
committed by Nacho Codoñer
parent a993b78f86
commit ac9257c0bd

View File

@@ -1,3 +1,13 @@
if (Meteor.isServer && Meteor.isDevelopment) {
if (typeof __meteor_runtime_config__ === 'object') {
var noDeprecations = process.env.METEOR_NO_DEPRECATIONS;
if (noDeprecations === 'true' || noDeprecations === 'false') {
noDeprecations = noDeprecations === 'true';
}
__meteor_runtime_config__.noDeprecations = noDeprecations;
}
}
function cleanStackTrace(stackTrace) {
if (!stackTrace || typeof stackTrace !== 'string') return [];
var lines = stackTrace.split('\n');
@@ -28,6 +38,14 @@ Meteor.deprecate = function () {
var stackStrace = cleanStackTrace(new Error().stack || '');
var messages = Array.prototype.slice.call(arguments); // Convert arguments to array
if (typeof __meteor_runtime_config__.noDeprecations === 'string') {
const noDeprecationPattern = new RegExp(__meteor_runtime_config__.noDeprecations);
if (noDeprecationPattern.test(stackStrace)) {
return;
}
} else if (typeof __meteor_runtime_config__.noDeprecations === 'boolean' && __meteor_runtime_config__.noDeprecations) {
return;
}
if (stackStrace.length > 0) {
messages.push('\n\n', 'Trace:', '\n', stackStrace);
}