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

Breaking: define an exports field for our public API #13654

Closed
kaicataldo opened this issue Sep 4, 2020 · 23 comments
Closed

Breaking: define an exports field for our public API #13654

kaicataldo opened this issue Sep 4, 2020 · 23 comments

Comments

@kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Sep 4, 2020

The 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!

@ljharb
Copy link
Contributor

@ljharb ljharb commented Sep 4, 2020

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.

Loading

@nzakas
Copy link
Member

@nzakas nzakas commented Oct 1, 2020

@kaicataldo Did you mean to link to here?
https://nodejs.org/api/packages.html. The link in the description is to the ESM Docs.

This seems like a simple enough change to prevent any further misunderstandings about what is and isn’t a public API.

Loading

@kaicataldo
Copy link
Member Author

@kaicataldo kaicataldo commented Oct 1, 2020

@kaicataldo Did you mean to link to here?
https://nodejs.org/api/packages.html. The link in the description is to the ESM Docs.

That's right - looks like the docs were moved.

Loading

@ljharb
Copy link
Contributor

@ljharb ljharb commented Oct 1, 2020

Note as well that all my complaints about breaking changes in non-majors from renaming internal files would go away if internal things were excluded from "exports" :-) (or at least, change to feature requests to expose them explicitly)

Loading

@nzakas
Copy link
Member

@nzakas nzakas commented Oct 7, 2020

TSC Summary: This proposal seeks to add an exports field to package.json that specifically identifies which files are part of the public API. Despite our consistently saying people should not be accessing files directly in the eslint package, people still are, and then complain when we make a change. For new Node.js versions, including exports 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).

Loading

@btmills btmills added this to Planned in Public Roadmap via automation Oct 10, 2020
@btmills
Copy link
Member

@btmills btmills commented Oct 10, 2020

In the 2020-10-08 TSC meeting, we accepted this as a semver-major change for the v8.0.0 release. I've added it to our public roadmap. The next step is for someone to write an RFC outlining which endpoints we need to expose and hopefully identifying which packages currently import private API that will be affected by this change. As we start working on v8.0.0, we can mention this change in a blog post to give those packages plenty of notice.

Loading

@ljharb
Copy link
Contributor

@ljharb ljharb commented Oct 10, 2020

@btmills once the choices are made, I’d be happy to volunteer to write the PR to implement it.

Loading

@btmills
Copy link
Member

@btmills btmills commented Apr 12, 2021

We’d like to include this in our upcoming v8.0.0 release if possible. The next step is to write an RFC specifying which portions of our API we want to expose via exports. Is anybody interested in contributing that? The team would be happy to answer questions along the way.

Loading

@ljharb
Copy link
Contributor

@ljharb ljharb commented Apr 12, 2021

Once the list of entrypoints exists, i will still happily make the PR to define them.

Loading

@nzakas nzakas moved this from Planned to Pull Request Opened in v8.0.0 Jun 16, 2021
@nzakas nzakas moved this from RFC Opened to Pull Request Opened in Triage Jun 16, 2021
@nzakas nzakas moved this from RFC Under Review to In Progress in Public Roadmap Jun 16, 2021
@nzakas nzakas linked a pull request that will close this issue Jun 17, 2021
1 task
@nzakas nzakas linked a pull request that will close this issue Jun 17, 2021
1 task
Public Roadmap automation moved this from In Progress to Complete Jun 18, 2021
Triage automation moved this from Pull Request Opened to Complete Jun 18, 2021
btmills added a commit that referenced this issue Jun 18, 2021
* New: Add ESLint#getRulesMetaForResults() (refs #13654)

* Update docs

* Update docs/developer-guide/nodejs-api.md

Co-authored-by: Brandon Mills <btmills@users.noreply.github.com>

Co-authored-by: Brandon Mills <btmills@users.noreply.github.com>
@bradzacher
Copy link
Contributor

@bradzacher bradzacher commented Jun 18, 2021

note - this should not have been closed yet - the PR only adds one piece of it.

Loading

@btmills
Copy link
Member

@btmills btmills commented Jun 18, 2021

Thanks for catching this @bradzacher, looks like automation got excited. Reopening and re-adding to project boards.

Loading

@btmills btmills reopened this Jun 18, 2021
Public Roadmap automation moved this from Complete to Planned Jun 18, 2021
Triage automation moved this from Complete to Evaluating Jun 18, 2021
@btmills btmills moved this from Planned to In Progress in Public Roadmap Jun 18, 2021
@btmills btmills moved this from Evaluating to Pull Request Opened in Triage Jun 18, 2021
@btmills btmills moved this from Pull Request Opened to Ready for Merge in v8.0.0 Jun 18, 2021
@nzakas nzakas closed this in #14706 Aug 5, 2021
Public Roadmap automation moved this from In Progress to Complete Aug 5, 2021
Triage automation moved this from Pull Request Opened to Complete Aug 5, 2021
v8.0.0 automation moved this from Ready for Merge to Done Aug 5, 2021
nzakas added a commit that referenced this issue Aug 5, 2021
* Breaking: Strict package exports (refs #13654)

* Update docs

* Fix linting errors

* Update docs/developer-guide/nodejs-api.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Update docs/developer-guide/nodejs-api.md

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Public Roadmap
  
Complete
Triage
Complete
v8.0.0
  
Done
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants