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

Extract targets parser and compat data from preset-env #10899

Merged
merged 4 commits into from Jan 10, 2020

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This is PR only moves code around, to expose as public packages internal API which are already used by some Babel integrations:

I created two new packages: @babel/compat-data and @babel/helper-compilation-targets.
I wasn't sure about where to put the info about overlapping plugins which will be useful for preset-modules (I put it in @babel/compat-data) and about the mappings from transform plugins to syntax plugins (I left it in @babel/preset-env).

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Dec 20, 2019
@nicolo-ribaudo nicolo-ribaudo added this to the v7.8.0 milestone Dec 20, 2019
@loganfsmyth
Copy link
Member

I swear at this point we should just append a random UUID to every filename except index.js on publish :P

@nicolo-ribaudo
Copy link
Member Author

Did you see #10850? 😛

@loganfsmyth
Copy link
Member

Hah, nope! Had no idea that was a thing Node allowed!

@nicolo-ribaudo nicolo-ribaudo force-pushed the env-targets-parser branch 3 times, most recently from b842a7c to fad046a Compare December 26, 2019 00:15
@nicolo-ribaudo nicolo-ribaudo added the PR: Needs Review A pull request awaiting more approvals label Jan 1, 2020
@@ -7,7 +7,7 @@ const flattenDeep = require("lodash/flattenDeep");
const isEqual = require("lodash/isEqual");
const mapValues = require("lodash/mapValues");
const pickBy = require("lodash/pickBy");
const unreleasedLabels = require("../data/unreleased-labels");
const { unreleasedLabels } = require("../../babel-helper-compilation-targets");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just require @babel/helper-compilation-targets?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch; I'll update it. Note that this file isn't published to npm so it isn't a problem, but using @babel/helper-compilation-targets is more clear.

"version": "0.0.0",
"author": "The Babel Team (https://babeljs.io/team)",
"license": "MIT",
"description": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "Engine compat data used in @babel/preset-env"?

@existentialism
Copy link
Member

Any reason to not also move isPluginRequired as another primitive to the helper?

In fact, erring on the side of less packages to maintain, can we just have one package that exports getTargets, our plugin/target data and something like:

isRequired(
  name: string,
  targetEnvironments: Targets,
  options: {
    compatData?: { [key in string]: Targets }
    // ...
  }
) { ... }

This seems like a key use-case (as both vue/ember use it), and would allow anyone to pass their own mappings in, if they wanted.

@nicolo-ribaudo
Copy link
Member Author

Any reason to not also move isPluginRequired as another primitive to the helper?

Maybe I forgot it, I'll check.

In fact, erring on the side of less packages to maintain

I don't think that this should be a goal? The maintenance cost of 2 packages in a monorepo is exactly the same as 1 package.

I created two separate packages because, if we are going to disable sub-package imports in Babel 8.0.0, @babel/compat-data will already be an exception when you can import internal files. If we merge it with the helper package, then some internal files will be importable while others won't, and I think that it would be more confusing.

import type { Targets } from "./types";
import { isUnreleasedVersion, semverify } from "./utils";

export function isItemRequired(supportedEnvironments: Targets, item: Targets) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I already extracted it. I called it isItemRequired because it's not just used for plugins, but also for polyfills. Maybe I should choose another name?

Copy link
Member

Choose a reason for hiding this comment

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

Ah missed that. I think the name is fine.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Jan 8, 2020

Whops I accidentally deleted my comment.

I wrote that I agree that the proposed isRequired function would be used both by ember and vue. However, I still think that the data should stay separated in a "data-only" package for direct usage.

Also, do you think that isRequired should default to using the plugins and core-js 2 data, or just the plugins data? And then there is also core-js 3, which keeps its data in a separate package.
(I think that it should only use plugins data)

@existentialism
Copy link
Member

The maintenance cost of 2 packages in a monorepo is exactly the same as 1 package.

I'm not sure I agree with that... perhaps mechanically, but I think we should always consider the balance between a package's public API vs. adding more packages.

Also, do you think that isRequired should default to using the plugins and core-js 2 data, or just the plugins data? And then there is also core-js 3, which keeps its data in a separate package.

I think we can go with just plugins data for now.

@nicolo-ribaudo
Copy link
Member Author

@existentialism I ended up not exporting isItemRequired (which I also renamed) to avoid confusion with isRequired.

@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 Apr 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2020
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: Internal 🏠 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