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

Disable submodule exports #10850

Closed
wants to merge 1 commit into from

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Dec 10, 2019

Q                       A
License MIT

This PR adds exports: "lib/index.js" to every package except @babel/runtime(-corejs[23])?, which shall be addressed in #10853 . By doing so we are stating explicitly that every package does not offer submodule exports, i.e. import "@babel/core/src/config" will bail because this file belongs to internal implementation details.

Even we don't specify exports: false, the following imports will still bail

import "@babel/core/src/config/index.js";

because the subpath ./src/config/index.js is not defined as export path in package.json. So it should not break anyone.

Note that it is a breaking change because exports takes precedence over main so the following will bail on node.js >= 13.1 or when --experimental-modules is activated:

const babelVersion = require("@babel/core/package.json").version

@JLHwung JLHwung added PR: Internal 🏠 A type of pull request used for our changelog categories PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release labels Dec 10, 2019
@nicolo-ribaudo
Copy link
Member

Does this also applies when using require instead of import?
If it does, then it will break some popular projects:

We should probably consider exposing @babel/preset-env/lib/targets-parser as a separate helper package.

@JLHwung
Copy link
Contributor Author

JLHwung commented Dec 11, 2019

Does this also applies when using require instead of import?

Yes, because exports take over main, which means Node.js 13 will have different module resolution behaviour than previous versions if package exports presents. Therefore, it is a breaking change.

People may use import "@babel/core/lib/whatever" in the wild and 8.x is expected in weeks. As you said there are some cases when the submodule exports is inevitable, so I propose to limit the scope of this PR:

  1. add exports: false to every @babel/* packages with only lib/index.js. This means that
    either require("@babel/foo/lib") or require("@babel/foo/lib/index.js" will throw. The impact is minimal since one can and should always use require("@babel/foo")

  2. for other packages, add necessary exports for compatibility with popular downstream tools. We can always create new package in 8.x if it is reasonable. Finally we can expect to remove unintended submodule exports on 9.x

@babel-bot
Copy link
Collaborator

babel-bot commented Jun 24, 2020

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

@JLHwung
Copy link
Contributor Author

JLHwung commented Jun 24, 2020

This PR has been revamped according to the latest best practise: https://nodejs.org/api/esm.html#esm_main_entry_point_export, to specify both exports and main as relative path starting with .

{
  "main": "./lib/index.js",
  "exports": "./lib/index.js"
}

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 24, 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 9d028ee:

Sandbox Source
busy-sky-n86if Configuration
keen-bartik-uwilx Configuration

@JLHwung
Copy link
Contributor Author

JLHwung commented Jun 25, 2020

The e2e test is failing because vue-cli invokes require("@babel/core/package.json") and package.json entry is not defined in @babel/core. The node communities are still discussing whether package.json should be allowed: nodejs/node#33460

Before decisions are made by node TSC, I consider package.json as our package metadata and thus it falls into part of our public interfaces. I will add ./package.json entries to every packages.

@JLHwung JLHwung force-pushed the disable-submodule-exports branch 2 times, most recently from 37ff39b to c4a1cb4 Compare June 25, 2020 18:26
@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
@JLHwung JLHwung removed this from the v8.0.0 milestone Aug 9, 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 PR: Internal 🏠 A type of pull request used for our changelog categories PR: Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants