babel / notes

♬ Notes from the @Babel Team (discuss in PRs)
https://github.com/babel/notes#meetings
122 stars 16 forks source link

Babel 8 Ecosystem Migration Stuff #116

Open hzoo opened 4 years ago

hzoo commented 4 years ago

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:

Issues

Todo

ljharb commented 4 years ago

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.