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

Provide an ESM build #75

Merged
merged 16 commits into from Mar 23, 2021
Merged

Provide an ESM build #75

merged 16 commits into from Mar 23, 2021

Conversation

nicolo-ribaudo
Copy link
Member

I'm slowly converting the babel/babel repository to ESM, and it's a bit annoying that these packages require the @babel/core peerDependency because they fail when testing an ESM build of @babel/core.

Providing an ESM build fixes the problem, and it also gives us the possibility of testing real-world ESM Babel plugins.

CI will fail until we release babel/babel#13000.

Comment on lines +4 to +5
import * as babel from "@babel/core";
const { types: t } = babel.default || babel;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is because Rollup's interop is incompatible with Node.js's behavior (rollup/plugins#635)

Copy link
Member Author

Choose a reason for hiding this comment

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

rollup/plugins#838 will make it possible to avoid doing this, if it will get merged.

import esShims from "babel-plugin-polyfill-es-shims";
import regenerator from "babel-plugin-polyfill-regenerator";

assert.equal(typeof corejs2, "function");
Copy link
Member Author

Choose a reason for hiding this comment

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

This would be an object with { default: function, __esModule: true } if we imported the CJS file.

@nicolo-ribaudo
Copy link
Member Author

I tried using this in an ESM build of the babel/babel repository, but it throws because of a Rollup bug: rollup/rollup#3996

Gulpfile.js Outdated
}),
rollupNodeResolve({
extensions: [".ts", ".js", ".mjs", ".cjs", ".json"],
browser: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Why do we need to resolve against browser fields?

Copy link
Member Author

Choose a reason for hiding this comment

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

We now provide two bundles for @babel/helper-define-polyfill-provider: one for Node.js (which accesses the filesystem) and one for the browser (which doesn't).

babel.config.js Show resolved Hide resolved
@nicolo-ribaudo
Copy link
Member Author

Ohh it's finally green!

@nicolo-ribaudo nicolo-ribaudo merged commit 4ac92be into babel:main Mar 23, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the native-esm branch March 23, 2021 15:43
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

Successfully merging this pull request may close these issues.

None yet

3 participants