From ac9257c0bd9ae2ea84eb792f5cc91a3dd7eb3300 Mon Sep 17 00:00:00 2001 From: Leonardo Venturini Date: Fri, 20 Dec 2024 15:44:05 +0100 Subject: [PATCH 1/5] ensure an env variable that handles deprecation messages --- packages/meteor/deprecate.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/meteor/deprecate.js b/packages/meteor/deprecate.js index 1e213ceeab..d00ab68bf0 100644 --- a/packages/meteor/deprecate.js +++ b/packages/meteor/deprecate.js @@ -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); } From 16e123d1eb6454de373b3aa535e5a9d1936fec75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 13 Jan 2025 15:07:41 +0100 Subject: [PATCH 2/5] ensure deprecations will only be shown once --- packages/meteor/deprecate.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/meteor/deprecate.js b/packages/meteor/deprecate.js index d00ab68bf0..8f97e07c4d 100644 --- a/packages/meteor/deprecate.js +++ b/packages/meteor/deprecate.js @@ -1,13 +1,26 @@ 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'; + var noDeprecation = process.env.METEOR_NO_DEPRECATION; + if (noDeprecation === 'true' || noDeprecation === 'false') { + noDeprecation = noDeprecation === 'true'; } - __meteor_runtime_config__.noDeprecations = noDeprecations; + __meteor_runtime_config__.noDeprecation = noDeprecation; } } +function oncePerArgument(func) { + const cache = new Map(); + + return function (...args) { + const key = JSON.stringify(args); + if (!cache.has(key)) { + const result = func.apply(this, args); + cache.set(key, result); + } + return cache.get(key); + }; +} + function cleanStackTrace(stackTrace) { if (!stackTrace || typeof stackTrace !== 'string') return []; var lines = stackTrace.split('\n'); @@ -30,6 +43,10 @@ function cleanStackTrace(stackTrace) { return trace.join('\n'); } +const onceWarning = oncePerArgument((message) => { + console.warn.apply(console, message); +}); + Meteor.deprecate = function () { if (!Meteor.isDevelopment) { return; @@ -38,18 +55,19 @@ 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 (typeof __meteor_runtime_config__.noDeprecation === 'string') { + const noDeprecationPattern = new RegExp(__meteor_runtime_config__.noDeprecation); if (noDeprecationPattern.test(stackStrace)) { return; } - } else if (typeof __meteor_runtime_config__.noDeprecations === 'boolean' && __meteor_runtime_config__.noDeprecations) { + } else if (typeof __meteor_runtime_config__.noDeprecation === 'boolean' && __meteor_runtime_config__.noDeprecation) { return; } if (stackStrace.length > 0) { messages.push('\n\n', 'Trace:', '\n', stackStrace); } + messages.push('\n\n', 'To disable warnings, set the `METEOR_NO_DEPRECATION` to `true` or a regex pattern.', '\n'); - console.warn.apply(console, ['[DEPRECATION]'].concat(messages)); + onceWarning(['[DEPRECATION]'].concat(messages)); } }; From 0b5045ff0873c3b88dc35f0eb29cf1d2f2a688d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 13 Jan 2025 15:13:38 +0100 Subject: [PATCH 3/5] affect node's no-deprecation on meteor deprecation warnings --- packages/meteor/deprecate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/meteor/deprecate.js b/packages/meteor/deprecate.js index 8f97e07c4d..81fa898565 100644 --- a/packages/meteor/deprecate.js +++ b/packages/meteor/deprecate.js @@ -1,6 +1,6 @@ if (Meteor.isServer && Meteor.isDevelopment) { if (typeof __meteor_runtime_config__ === 'object') { - var noDeprecation = process.env.METEOR_NO_DEPRECATION; + var noDeprecation = process.env.METEOR_NO_DEPRECATION || process.noDeprecation; if (noDeprecation === 'true' || noDeprecation === 'false') { noDeprecation = noDeprecation === 'true'; } From b8f5862304d34b64f6e20d7cfc88415e6c2fe221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 13 Jan 2025 15:41:12 +0100 Subject: [PATCH 4/5] add a log to warn about existing deprecation warnings --- packages/meteor/deprecate.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/meteor/deprecate.js b/packages/meteor/deprecate.js index 81fa898565..80d588f2a2 100644 --- a/packages/meteor/deprecate.js +++ b/packages/meteor/deprecate.js @@ -47,6 +47,10 @@ const onceWarning = oncePerArgument((message) => { console.warn.apply(console, message); }); +const onceFixDeprecation = () => { + onceWarning(['Deprecation warnings are hidden but crucial to address for future Meteor updates.', '\n', 'Remove the `METEOR_NO_DEPRECATION` env var to reveal them, then report or fix the issues.']); +}; + Meteor.deprecate = function () { if (!Meteor.isDevelopment) { return; @@ -58,9 +62,11 @@ Meteor.deprecate = function () { if (typeof __meteor_runtime_config__.noDeprecation === 'string') { const noDeprecationPattern = new RegExp(__meteor_runtime_config__.noDeprecation); if (noDeprecationPattern.test(stackStrace)) { + onceFixDeprecation(); return; } } else if (typeof __meteor_runtime_config__.noDeprecation === 'boolean' && __meteor_runtime_config__.noDeprecation) { + onceFixDeprecation(); return; } if (stackStrace.length > 0) { From 9c1236873ba2d1360f8e40f72a16eaa4d4127154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Codo=C3=B1er?= Date: Mon, 13 Jan 2025 15:50:33 +0100 Subject: [PATCH 5/5] fix code style issues --- packages/meteor/deprecate.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/meteor/deprecate.js b/packages/meteor/deprecate.js index 80d588f2a2..a21e641b94 100644 --- a/packages/meteor/deprecate.js +++ b/packages/meteor/deprecate.js @@ -9,12 +9,12 @@ if (Meteor.isServer && Meteor.isDevelopment) { } function oncePerArgument(func) { - const cache = new Map(); + var cache = new Map(); - return function (...args) { - const key = JSON.stringify(args); + return function _oncePerArgument() { + var key = JSON.stringify(arguments); if (!cache.has(key)) { - const result = func.apply(this, args); + var result = func.apply(this, arguments); cache.set(key, result); } return cache.get(key); @@ -43,13 +43,13 @@ function cleanStackTrace(stackTrace) { return trace.join('\n'); } -const onceWarning = oncePerArgument((message) => { +var onceWarning = oncePerArgument(function _onceWarning(message) { console.warn.apply(console, message); }); -const onceFixDeprecation = () => { +function onceFixDeprecation() { onceWarning(['Deprecation warnings are hidden but crucial to address for future Meteor updates.', '\n', 'Remove the `METEOR_NO_DEPRECATION` env var to reveal them, then report or fix the issues.']); -}; +} Meteor.deprecate = function () { if (!Meteor.isDevelopment) { @@ -60,7 +60,7 @@ Meteor.deprecate = function () { var messages = Array.prototype.slice.call(arguments); // Convert arguments to array if (typeof __meteor_runtime_config__.noDeprecation === 'string') { - const noDeprecationPattern = new RegExp(__meteor_runtime_config__.noDeprecation); + var noDeprecationPattern = new RegExp(__meteor_runtime_config__.noDeprecation); if (noDeprecationPattern.test(stackStrace)) { onceFixDeprecation(); return;