fix: warn instead of throw for removed bugfixes option in preset-env#18143
Open
mvanhorn wants to merge 1 commit into
Open
fix: warn instead of throw for removed bugfixes option in preset-env#18143mvanhorn wants to merge 1 commit into
bugfixes option in preset-env#18143mvanhorn wants to merge 1 commit into
Conversation
`@babel/preset-env` threw a hard error when the removed `bugfixes` option was passed, which breaks configs carried over from Babel 7 even though the option is now a harmless no-op (bugfix plugins are always enabled). Downgrade it to a `console.warn`, matching the existing `corejs` warning style in the same file. Because `bugfixes` is not a valid top-level option, `validateTopLevelOptions` would still throw on the next line, so the option is stripped from a shallow copy of the input (leaving the caller's object untouched) before validation runs. Configs that do not pass `bugfixes` are unaffected. Closes babel#18096
❌ Automation signalsActivity patterns show signs of automation. This is an automated analysis by AgentScan |
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61942 |
|
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@babel/preset-envcurrently throws a hard error when the removedbugfixesoption is passed. This turns a harmless leftover config key into a build-breaking crash. This PR downgrades it to aconsole.warn, as suggested in the issue thread.Background
bugfixeswas removed in Babel 8 because bugfix plugins are now always enabled, so the option is a no-op. But configs carried over from Babel 7 (or shared presets that still set it) commonly includebugfixes: true. On Babel 8 those configs fail outright atnormalizeOptions:Since the option no longer does anything, a hard error is stricter than necessary. In the issue, a core maintainer noted that downgrading it to a
console.warnis reasonable, matching how thecorejs-without-useBuiltInscase is already handled in this same file.Fix
When
bugfixesis present, emit aconsole.warn(same message, same newline-wrappedWARNING (@babel/preset-env):style as the existingcorejswarning) instead of throwing.There is one subtlety:
bugfixesis not inTopLevelOptions, and the very next line callsv.validateTopLevelOptions, which throws on any unknown top-level key. So simply swapping theinvariantfor a warning would still crash. To avoid that, the option is stripped from a shallow copy of the input before validation runs. The caller's original options object is left untouched (only the local reference is reassigned), and configs that never passbugfixesare completely unaffected.Testing
Added a focused case to
packages/babel-preset-env/test/normalize-options.skip-bundled.jsthat spies onconsole.warnand asserts: passingbugfixes: true/falseno longer throws, a warning mentioningbugfixesis emitted, the caller's options object is not mutated, and no warning fires when the option is absent. Thebabel-preset-envnormalize-options suite passes (30 tests) andmake tscheckis clean across the monorepo.Closes #18096
AI was used for assistance.