mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
implement machinery to Meteor.deprecate
This commit is contained in:
35
packages/meteor/deprecate.js
Normal file
35
packages/meteor/deprecate.js
Normal file
@@ -0,0 +1,35 @@
|
||||
function cleanStackTrace(stackTrace) {
|
||||
if (!stackTrace) return [];
|
||||
const lines = stackTrace.split('\n');
|
||||
const trace = [];
|
||||
for (const line of lines) {
|
||||
const _line = line.trim();
|
||||
if (_line.includes('Meteor.deprecate')) continue;
|
||||
if (_line.includes('packages/')) {
|
||||
trace.push(_line);
|
||||
} else if (_line && _line.includes('/')) {
|
||||
// Stop processing if a valid path that does not start with 'packages/**' is found
|
||||
break;
|
||||
}
|
||||
}
|
||||
return trace.join('\n');
|
||||
}
|
||||
|
||||
Meteor.deprecate = function (...messages) {
|
||||
if (!Meteor.isDevelopment) {
|
||||
return;
|
||||
}
|
||||
if (typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
|
||||
const stackStrace = cleanStackTrace(new Error().stack || '');
|
||||
console.warn(
|
||||
'[DEPRECATION]',
|
||||
...messages,
|
||||
...stackStrace?.length > 0 && [
|
||||
'\n\n',
|
||||
'Trace:',
|
||||
'\n',
|
||||
stackStrace
|
||||
] || []
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -41,6 +41,7 @@ Package.onUse(function (api) {
|
||||
api.addFiles('startup_client.js', ['client']);
|
||||
api.addFiles('startup_server.js', ['server']);
|
||||
api.addFiles('debug.js', ['client', 'server']);
|
||||
api.addFiles('deprecate.js', ['client', 'server']);
|
||||
api.addFiles('string_utils.js', ['client', 'server']);
|
||||
api.addFiles('test_environment.js', ['client', 'server']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user