Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a custom handler to flushDeprecations #207

Merged
merged 4 commits into from
Mar 6, 2025

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented Mar 4, 2025

Running flushDeprecations() will always emit a config where all detected deprecations are silenced. But that is not always what you want. E.g. when you want your config to have throwOnUnhandled enabled, you might want to have all known deprecations to be listed (so they don't throw), but with a log handler.

This is now possible by running flushDeprecations({ handler: 'log' }) instead. The default remains silence, so this is a non-breaking change.

--
Edit:
Internally, this is removing support for deprecations that don't have an ID. Having an ID is asserted for since this PR, which landed way before the earliest version of 3.28 which we support here.

This simplifies the internal collector logic, to just add IDs to a Set and always emitting a config with matchId, instead of having to support both matchId and matchMessage (which was only used when no ID was present)

@@ -107,8 +111,7 @@ export function deprecationCollector(message, options, next) {
let key = (options && options.id) || message;
let matchKey = options && key === options.id ? 'matchId' : 'matchMessage';

self.deprecationWorkflow.deprecationLog.messages[key] =
' { handler: "silence", ' + matchKey + ': ' + JSON.stringify(key) + ' }';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been refactored as it was collecting deprecations but also formatting them for final output. With that it was hard-coding handler: 'silence' in a place where we cannot customize it. But IMO it should have only one responsibility: collecting the raw minimal data, which is what it does now. Formatting happens in flushDeprecations.

Simplifies the internal collector logic, to just collect a `Set` of ids.
@simonihmig
Copy link
Contributor Author

@mansona applied your suggestion as discussed yesterday! Ready for another review!

Copy link
Member

@mansona mansona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one 🎉

@mansona mansona merged commit ea37553 into ember-cli:main Mar 6, 2025
12 checks passed
@github-actions github-actions bot mentioned this pull request Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants