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

Support .mjs plugins/presets and async factories #12266

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Oct 27, 2020

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This is the first step needed to migrate to native ECMAScript modules: we must support loading .mjs plugins and presets 😛

  • The first commit is mostly needed for third-party presets: many of them directly use require() inside the preset factory, and this makes it possible to use await import() instead.
  • The second commit enables loading .mjs plugins/presets. It's mostly functions being converted to generators to work with gensync.

While preparing this PR, I noticed that we currently support this kind of presets:

exports.__esModule = true;
exports.plugins = [foo];

which is the result of transpiling

export const plugins = [foo];

However, we throw an error for

exports.__esModule = true
exports.default = { plugins: [foo] }

because presets must export a function, and not a plain object:

exports.__esModule = true
exports.default = function () {
  return { plugins: [foo] };
};

Since presets must export a function (so that they can properly configure caching), I didn't implement support for the named exports in .mjs files.

@nicolo-ribaudo nicolo-ribaudo added PR: New Feature 🚀 A type of pull request used for our changelog categories pkg: core labels Oct 27, 2020
@babel-bot
Copy link
Collaborator

babel-bot commented Oct 27, 2020

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 27, 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 52e0f20:

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

@nicolo-ribaudo nicolo-ribaudo force-pushed the async-plugin-preset branch 3 times, most recently from 444b0c9 to 885e08d Compare October 28, 2020 19:06
// please publish Babel on a modernized node :)
const { stdout, stderr } = await util.promisify(cp.execFile)(
require.resolve(`./fixtures/babel-compile-${async ? "async" : "sync"}.mjs`),
{ env: process.env },
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

make prepublish is passing as of dfa75fa on macOS.

@nicolo-ribaudo nicolo-ribaudo added this to the v7.13.0 milestone Oct 31, 2020
@nicolo-ribaudo nicolo-ribaudo added the PR: Needs Review A pull request awaiting more approvals label Nov 10, 2020
@nicolo-ribaudo nicolo-ribaudo added PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release and removed PR: Needs Review A pull request awaiting more approvals labels Dec 9, 2020
@nicolo-ribaudo nicolo-ribaudo changed the base branch from main to feat-7.13.0/babel-core-features December 9, 2020 23:06
@nicolo-ribaudo
Copy link
Member Author

I'm merging this PR to the feat-7.13.0/babel-core-features branch, because there are three different PRs that modify @babel/core that conflict with each other (this one, assumptions and targets)

@nicolo-ribaudo nicolo-ribaudo merged commit b02fdc0 into babel:feat-7.13.0/babel-core-features Dec 9, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the async-plugin-preset branch December 9, 2020 23:07
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Jan 12, 2021
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Feb 4, 2021
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Feb 10, 2021
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Feb 11, 2021
@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 Mar 11, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 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: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants