question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Breaking: define an `exports` field for our public API

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:23 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, 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).

2reactions
ljharbcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Respect "exports" field in "package.json" · Issue #9509 - GitHub
What is the expected behavior? It would be nice if webpack respects "exports" filed defined in package.json and follow a new resolution strategy ......
Read more >
Packages | Node.js v18 API
Existing packages introducing the "exports" field will prevent consumers of the package from using any entry points that are not defined, including the...
Read more >
Break up a large export - Product Documentation | ServiceNow
This exports the first 10,000 records in order, sorted by the sys_id number. Find the next record in order, such as 10,001. Right-click...
Read more >
Understanding Modules and Import and Export Statements in ...
In the previous examples, you exported multiple named exports and imported them individually or as one object with each export as a method...
Read more >
Project import/export API - GitLab Docs
GitHub. GitHub import Rake task. Migrate projects using file exports. Troubleshooting. Rate limits for project and group imports and exports.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found