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

Simple plugin order #16442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

liuxingbaoyu
Copy link
Member

@liuxingbaoyu liuxingbaoyu commented Apr 24, 2024

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

This PR isn't ready to be merged yet, but I thought it would be okay to have some discussions now.

This PR adds a top-level option sortPlugins, enabled by default in Babel 8, to control whether the order provided by the plugin is followed.

And added a plugin attribute orderData.

   orderData?: {
     id: string;
     version: number;
   } & {
     type: "list";
     data: () => string[];
   };

id and version are so that we can update the plugin order in patch versions, even if users are still using plugins that carry the old order data.

The sorting algorithm is very simple. From back to front, all plugins included in the order list are extracted and sorted, and inserted into the location of the first found plugin.
For example, A and B carry order data [A, B, C, D], but C does not.
[B,X,A] will be sorted as [X,A,B].
Because users almost always use preset-env, and presets run behind plugins, this will cause the plugins contained in preset-env to be collected at the end, trying to maintain compatibility.

This PR also shows an issue #16398 (comment) where our current plugin order breaks some block scoping.

Although this method is not very powerful, it can better maintain compatibility and meet the problems we currently encounter in built-in plug-ins. We can enhance it in Babel 9.

Maybe we should exclude them or use a separate list.

       "transform-modules-commonjs",
       "transform-modules-amd",
       "transform-modules-systemjs",
       "transform-modules-umd",

       "transform-typescript",
       "transform-flow",

@babel-bot
Copy link
Collaborator

babel-bot commented Apr 24, 2024

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

@liuxingbaoyu liuxingbaoyu changed the title WIP: Simple plugin order Simple plugin order May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants