Breaking: define an `exports` field for our public API
See original GitHub issueThe version of ESLint you are using.
Latest
The problem you want to solve.
Downstream packages rely on ESLint’s internal modules, and removing/altering these modules can cause breakages in the ecosystem (example here). A lot of thought has gone into what is and isn’t our public API (defined here), but it would be great to be able to enforce that downstream packages don’t rely on these modules, since treating every module in our codebase as public isn’t practical and would make it extremely difficult to refactor or do feature work.
To be clear, I don’t think that our current strategy of defining our public API and then treating all other modules as “private” is an uncommon practice, but I do think this small change could prevent some instances of this from happening in the future.
Your take on the correct solution to problem.
As suggested here, I would like to propose that we define an exports
field to a) clearly document what we consider our public API from an importable module standpoint, and b) prevent those using more recent versions of Node.js from importing internal modules not intended for public consumption. For older versions of Node.js, main
(which we have defined) would be used as a fallback. You can find more details in the Node.js Package Entry Points docs.
Are you willing to submit a pull request to implement this change?
Absolutely!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:23 (21 by maintainers)
Top GitHub Comments
TSC Summary: This proposal seeks to add an
exports
field topackage.json
that specifically identifies which files are part of the public API. Despite our consistently saying people should not be accessing files directly in theeslint
package, people still are, and then complain when we make a change. For new Node.js versions, includingexports
would ensure our internal file structure isn’t exposed publicly.TSC Question: Shall we accept this proposal and add it to the public roadmap (for v8.0.0).
When adding this, you can use
npx ls-exports path .
to verify what exports you’re exposing. This can be used to add the field in a nonbreaking way right now as well.Either way, I’d be happy to review any change around this field for correctness (node 13.0 and 13.1, if supported, require extra consideration in the format, as do a few non-latest minors in 12 and 14); please feel free to ping me.