mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Merge pull request #13542 from meteor/env-deprecate-warnings
Deprecation messages can be managed through environment variables.
This commit is contained in:
@@ -1,3 +1,26 @@
|
||||
if (Meteor.isServer && Meteor.isDevelopment) {
|
||||
if (typeof __meteor_runtime_config__ === 'object') {
|
||||
var noDeprecation = process.env.METEOR_NO_DEPRECATION || process.noDeprecation;
|
||||
if (noDeprecation === 'true' || noDeprecation === 'false') {
|
||||
noDeprecation = noDeprecation === 'true';
|
||||
}
|
||||
__meteor_runtime_config__.noDeprecation = noDeprecation;
|
||||
}
|
||||
}
|
||||
|
||||
function oncePerArgument(func) {
|
||||
var cache = new Map();
|
||||
|
||||
return function _oncePerArgument() {
|
||||
var key = JSON.stringify(arguments);
|
||||
if (!cache.has(key)) {
|
||||
var result = func.apply(this, arguments);
|
||||
cache.set(key, result);
|
||||
}
|
||||
return cache.get(key);
|
||||
};
|
||||
}
|
||||
|
||||
function cleanStackTrace(stackTrace) {
|
||||
if (!stackTrace || typeof stackTrace !== 'string') return [];
|
||||
var lines = stackTrace.split('\n');
|
||||
@@ -20,6 +43,14 @@ function cleanStackTrace(stackTrace) {
|
||||
return trace.join('\n');
|
||||
}
|
||||
|
||||
var onceWarning = oncePerArgument(function _onceWarning(message) {
|
||||
console.warn.apply(console, message);
|
||||
});
|
||||
|
||||
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) {
|
||||
return;
|
||||
@@ -28,10 +59,21 @@ 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__.noDeprecation === 'string') {
|
||||
var 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) {
|
||||
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));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user