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

[babel 8] Add "exports" to every package #14013

Merged
merged 9 commits into from Dec 29, 2021

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Dec 1, 2021

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

In Babel 8 we will want to use "exports" in every package, to prevent people from relying on our internal files. This PR uses a new feature of http://github.com/nicolo-ribaudo/yarn-plugin-conditions/ to specify "exports" when publishing with the BABEL_8_BREAKING flag (and for our internal development), but to remove it when publishing Babel 7 releases.

I also unified the different "exports" we already had for some Babel 7 packages, by making them expose both ".": "./lib/index.js" and "./package.json" (some already did, some didn't) since it's useful when using require.resolve to get the package root, or to get metadata such as the plugin version.

The commits prefixed with RUN are not created manually, but by running yarn constraints --fix with the constraints introduced by the previous commit.

@babel-bot
Copy link
Collaborator

babel-bot commented Dec 1, 2021

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

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review December 11, 2021 17:05
@JLHwung JLHwung mentioned this pull request Dec 16, 2021
34 tasks
},
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Why should we move the exports to conditions if-else? I perceive that it is to use Babel 7 export-less package.json but don't know what is breaking. I expect every package will eventually come with top level exports, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I removed this because the file already contains a complex "exports" that lets it work in Babel 7 while also having an ESM entry point. The exports in BABEL_8_BREAKING are a simpler version of what this package already has (you can see it by expanding the diff).

This exports I deleted here was auto-generated by yarn constraints --fix while we didn't have the other exports yet, then I rebased and had to delete it to remove the "conflict".

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Q: Should we begin to ship exports for those packages with only a single ./lib/index.js?

@nicolo-ribaudo
Copy link
Member Author

Q: Should we begin to ship exports for those packages with only a single ./lib/index.js?

We would have to expose:

  • @babel/...
  • @babel/.../package
  • @babel/.../package.json
  • @babel/.../lib
  • @babel/.../lib/index
  • @babel/.../lib/index.js

I think it's easier to leave it as-is.

@nicolo-ribaudo nicolo-ribaudo merged commit d1cabf6 into babel:main Dec 29, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the babel-8-exports branch December 29, 2021 15:29
@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 31, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2022
@nicolo-ribaudo nicolo-ribaudo added this to the v8.0.0 milestone Aug 8, 2023
@nicolo-ribaudo nicolo-ribaudo added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release and removed babel 8 labels Aug 8, 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.

None yet

3 participants