Skip to content

Commit

Permalink
Emit fewer deprecation warnings.
Browse files Browse the repository at this point in the history
In theory, you want to see any unique issue, but in practice… that’s
super annoying. Just changing this to key off the _message_ instead of
the _stack_. This means we will get at most one warning per deprecated
interface usage.
  • Loading branch information
theengineear committed Dec 5, 2024
1 parent fab50a7 commit 87d1f36
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions x-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,13 @@ class TemplateEngine {
}
}

static #interfaceDeprecatedStacks = new Set();
static #interfaceDeprecatedMessages = new Set();
static #interfaceDeprecated(name, callback) {
return (...args) => {
const error = new Error(`Deprecated "${name}" from default templating engine interface.`);
const stack = error.stack;
if (!this.#interfaceDeprecatedStacks.has(stack)) {
this.#interfaceDeprecatedStacks.add(stack);
console.warn(error); // eslint-disable-line no-console
const message = `Deprecated "${name}" from default templating engine interface.`;
if (!this.#interfaceDeprecatedMessages.has(message)) {
this.#interfaceDeprecatedMessages.add(message);
console.warn(new Error(message)); // eslint-disable-line no-console
}
return callback(...args);
};
Expand Down

0 comments on commit 87d1f36

Please sign in to comment.