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

Bundle most packages in Babel 8 #14179

Merged
merged 20 commits into from Sep 16, 2022

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 19, 2022

Q                       A
Fixed Issues? Bundle most packages in Babel 8, fixes #9575
Patch: Bug Fix?
Major: Breaking Change? Yes, behind BABEL_8_BREAKING flag
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link babel/website#2765
Any Dependency Changes?
License MIT

In this PR we bundle most packages when built with BABEL_8_BREAKING with exceptions listed below:

Notable internal changes:

@babel/traverse:

  • The virtual-types typings generator has been removed because it needs internal access to transpiled source files, which is not available when we bundle @babel/traverse. Instead the typings are now explicitly listed on packages/babel-traverse/src/path/lib/virtual-types.ts and packages/babel-traverse/src/path/lib/virtual-types-validator.ts.
  • The virtual types validator are refactored to straightforward notations. Instead of dynamically generating validator interface t["is" + virtualType] = validators[virtualType].checkPath, they are now explicitly declared in packages/babel-traverse/src/path/lib/virtual-types-validator.ts. Now TS manages to detect some bugs in the validators and I have fixed reported issues. And it improves method navigability.

Known issues: I will fix them in a subsequent PR so the Babel-traverse / optional chaining fixes in this PR can be landed to Babel 7 soon.

  • react-jsx-development depends on exports in react-jsx
  • corejs-compat/data.json is bundled in preset-env

Because the bundling happens during prepublish phrase, it can only be tested by Babel 8 breaking tests hosted in Circle CI.

@babel-bot
Copy link
Collaborator

babel-bot commented Jan 19, 2022

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

@JLHwung JLHwung force-pushed the bundle-most-packages-in-babel-8 branch 3 times, most recently from 5ab46bb to e3aa0e5 Compare January 24, 2022 20:37
@@ -393,8 +405,33 @@ function buildRollup(packages, targetBrowsers) {
name,
sourcemap: sourcemap,
exports: "named",
interop(id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interop config fixes a regression issue: Using @babel/plugin-proposal-optional-chaining with an old @babel/parser version will throw optional chaining syntax is required.

In https://unpkg.com/@babel/plugin-proposal-optional-chaining@7.16.7/lib/index.js,

inherits: syntaxOptionalChaining__default['default'].default,

the inherited syntax plugin is always undefined because we and rollup both apply interop transform on the default exports.

Now it generates

inherits: syntaxOptionalChaining.default,

as expected.

@JLHwung JLHwung marked this pull request as ready for review January 24, 2022 22:30
@JLHwung JLHwung added the PR: Internal 🏠 A type of pull request used for our changelog categories label Jan 24, 2022
@JLHwung JLHwung force-pushed the bundle-most-packages-in-babel-8 branch from 1e618f9 to e9f9361 Compare January 24, 2022 22:32
}
if (pkgJSON === undefined) continue;
const src = packageDir + "/" + dir;
if (pkgJSON.main) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may extend support to pkgJSON.exports in the future. However, bundling a package with multiple exports could be tricky: Do we want to bundle multiple entry thus minimizing internal module imports? Or do we want to bundle modules in topological order thus minimizing the artifact size?

Since few packages supports multiple exports, I think supporting main is good enough.

@JLHwung JLHwung force-pushed the bundle-most-packages-in-babel-8 branch from e9f9361 to df66712 Compare January 27, 2022 20:49
@JLHwung JLHwung marked this pull request as draft January 27, 2022 21:28
@JLHwung JLHwung force-pushed the bundle-most-packages-in-babel-8 branch from 11e6b20 to 61d987f Compare January 31, 2022 19:34
@JLHwung JLHwung marked this pull request as ready for review January 31, 2022 20:01
@JLHwung
Copy link
Contributor Author

JLHwung commented Jan 31, 2022

The CI error is unrelated, it will be fixed in #14087.

@JLHwung JLHwung force-pushed the bundle-most-packages-in-babel-8 branch from 61d987f to f1ac928 Compare February 3, 2022 20:07
@JLHwung JLHwung force-pushed the bundle-most-packages-in-babel-8 branch 2 times, most recently from 0822478 to 5c6bae9 Compare July 27, 2022 17:16
Gulpfile.mjs Outdated Show resolved Hide resolved
Gulpfile.mjs Outdated Show resolved Hide resolved
Gulpfile.mjs Outdated Show resolved Hide resolved
Gulpfile.mjs Outdated Show resolved Hide resolved
Gulpfile.mjs Outdated Show resolved Hide resolved
@liuxingbaoyu
Copy link
Member

To be honest, I'm a little concerned that this will affect debugging while in use, hope it's ok.

@JLHwung
Copy link
Contributor Author

JLHwung commented Jul 27, 2022

Note that make watch calls yarn gulp build-no-bundle, which will skip rollup and run Babel on source files, so this PR does not complicate current contributing workflow. On CI we build with rollup and test against that. Users generally benefit from bundling: less modules yields shorter start-up time.

@liuxingbaoyu
Copy link
Member

Yeah, I mean when babel is a dependency.
I'm worried this will be a little more difficult. (especially traverse)

PS: I haven't even used make watch because of make, lol😂

@liuxingbaoyu
Copy link
Member

Also it looks like this PR is done #9575.

@@ -294,23 +299,49 @@ if (process.env.CIRCLE_PR_NUMBER) {

const babelVersion =
require("./packages/babel-core/package.json").version + versionSuffix;
function buildRollup(packages, targetBrowsers) {
function buildRollup(packages, buildStandalone) {
const sourcemap = process.env.NODE_ENV === "production";
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR:
Do we need to include source maps in the release?
Currently NODE_ENV is only used in prepublish-build(doesn't even include prepublish-build-standalone), I don't know if this is expected.

(found this when I tried to debug in the repl)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I think the source maps should be included, especially for a browser package like babel-standalone.

@nicolo-ribaudo nicolo-ribaudo merged commit aad7eb7 into babel:main Sep 16, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the bundle-most-packages-in-babel-8 branch September 16, 2022 07:49
@nicolo-ribaudo nicolo-ribaudo removed the PR: Internal 🏠 A type of pull request used for our changelog categories label Sep 16, 2022
@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 Jan 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2023
@JLHwung JLHwung added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release and removed babel 8 labels Aug 9, 2023
@JLHwung JLHwung added this to the v8.0.0 milestone Aug 9, 2023
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 PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider @babel/core being bundled to improve CLI startup times.
4 participants