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

Babel 8 Ecosystem Migration Stuff #116

Open
1 task
hzoo opened this issue May 13, 2020 · 1 comment
Open
1 task

Babel 8 Ecosystem Migration Stuff #116

hzoo opened this issue May 13, 2020 · 1 comment

Comments

@hzoo
Copy link
Member

hzoo commented May 13, 2020

Didn't want to spam our release issue too much so just writing this here as well.

#10746, Pinned Babel 8 Release Plan Issue

There are a lot of concerns (I have them too) around what a major version bump would look like for the ecosystem. What else can we do in addition to a upgrade guide for the end user (good errors, clear explanation of changes, workaround/migration)?

What about dependencies of dependencies? Especially if you aren't using Babel directly (see issues from v6 to v7). We ended up with slow approach of essentially a year of alphas/betas/rc so that by the time it was out, most things were already updated and you could say it was relatively smooth compared to v5 to v6. But then again it took forever and there was a long process of versioning.

Idea

Use an environment variable (currently BABEL_8_BREAKING), which includes all breaking changes. Essentially a "feature flag" that we introduce (and continue to add onto) in Babel 7 patch versions.

Enables opt-ing into breaking changes without needing to change versions or dependencies.

So as a library author, you could do a dry-run and update accordingly. Or make PRs that run against the flag so that you can update the package ahead of release as we land changes. (hopefully we don't prolong this more than needed).

For the Babel codebase, ideally we do it in a way that makes this easy to automate away with a codemod. Babel 8 diff would be removing the flags (this is good because we aren't trying to introduce new features in the major version, we just do it in the minor)

if (process.env.BABEL_8_BREAKING) {
    runNewFunction();
} else {
    runOldFunction();
}
// new code during Babel 8 release
runNewFunction();

Tests?

We'll need to run tests for both "versions" to not break anything.

One approach: based on file extension: if the flag is enabled and it's a v7 test OR if the flag isn't enable and it's a v8 test, then skip the test?

Test renaming:

  • A test only for v7: rename to output.v7.js, options.v7.json
  • A test only for v8: rename to output.v8.js, options.v8.json
  • For both: keep as is!
  • During v8 release: remove all .v7. files, rename .v8. files to normal

Issues

  • Generally (or the Babel codebase), we shouldn't intend to use this approach in general.. and end up with if statements/flags everywhere. So use a unique name for the flag: BABEL_8_BREAKING babel a.js instead of something like BABEL_BREAKING babel a.js
    • Does it even matter it's a process.env vs. config option? It seems easier since we don't need to pass options between packages (config, plugin, parser option). Also there's no access to options in our interations like CRA.
  • We already have a next-8-dev branch that has merged some PRs into it. Ideally we would be able to just port all breaking change PRs to master under the flag and ignore next-8-dev.
  • It may be a lot of work to add this flag everywhere, and maintain multiple versions of tests
  • It's very likely can't put everything under a flag, but it's a best effort to help with ecosytem migration. We can defer those till the actual release.
  • What about only supporting later versions of Node? We'll have to defer to the final release?

Todo

  • I'll make an example PR that does this, and then we can attempt a migration on another project as another example.
@ljharb
Copy link
Member

ljharb commented May 13, 2020

I really like that idea. It builds on the pattern I strive to follow in every dependency anyways: all breaking changes are just toggling the default of an option, but you can always opt in to the new default early, or opt out of it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants