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

Account for ConfigItem being generated by another copy of Babel #11734

Merged
merged 8 commits into from Nov 10, 2020

Conversation

developit
Copy link
Member

@developit developit commented Jun 19, 2020

Q                       A
Fixed Issues? developit/microbundle#657
Patch: Bug Fix? yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass?
Documentation PR Link N/A
Any Dependency Changes? no
License MIT

This fixes ConfigItem unboxing when core.createConfigItem() is used to generate a ConfigItem that is then passed to a different copy of Babel. This is common in cases where npm fails to dedupe modules, or when differing versions of Babel are in-use.

// good - uses the version of babel that is doing the transforming:
module.exports = function preset(api) {
  api.createConfigItem(...)
}
// bad - uses whatever version this module installed:
import api from '@babel/core';
module.exports = babelLoader.custom({
  options() {
    api.createConfigItem(..)
  }
});

@babel-bot
Copy link
Collaborator

babel-bot commented Jun 19, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/32245/

Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

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

not sure how else we want to handle this issue, also wonder other cases we are using instanceof and might have this problem?

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 19, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a00bf9e:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@developit
Copy link
Member Author

Another suggestion, rather than changing all the instanceof checks, might be to throw or warn when this behavior is detected:

import core from '@babel/core';  // could be a separate copy of Babel (determined by npm)

export function custom() {
  return {
    config() {
      core.createConfigItem(...)
      // "Error: detected ConfigItem instances from a different version of Babel"
    }
  }
}

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Nov 9, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit ddd868f into babel:main Nov 10, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: core PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants