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.

`pathFilter` (or some new API) should support implementations of `exports`

See original GitHub issue

In lieu of this module supporting exports out of the box, it would be awesome if consumers could use its existing capabilities (packageFilter, pathFilter etc.) to implement support for exports on the consumer side.

I have experimented a bit with this, and from what I can tell there are 2 issues:

  1. resolve adds index if a directory is specified (https://github.com/browserify/resolve/blob/f1b51848ecb7f56f77bfb823511d032489a13eab/lib/sync.js#L192). This can potentially cause issues in the case index is not specified by the user as changing it to . (which is what a directory means in exports) is not necessarily a safe operation. Not sure how to mitigate this in a way that’s backwards compatible.
  2. I tried to use pathFilter which works great for require('some-module/thing'), but it doesn’t work for require('./some-thing') from within a module. Relative imports within a module isn’t restricted by exports, but pathFilter cannot know if the resolution request is for a relative file or not. A solution here is maybe to include a flag saying if it’s relative within the package or not?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, Oct 14, 2021

Right, it breaks a test, but I think that test is faulty (it imports a “local” module with a package.json with exports via a relative path, but that is not in node_modules). I think that’s just wrong behavior, so it failing now is actually a bug fix and my old test was just bad 😅

Might just roll this out behind a config flag and hope people test it and report instances where it behaves wrong (after adding more tests)

1reaction
SimenBcommented, Feb 17, 2022

Ok, closing again 🙈 My solution is to pop of anything trailing after pkg/ or @scope/pkg/, add ./package.json and resolve that using resolve, and if package.json has exports resolve those with anything trailing (or . if nothing), and return the full path. No packageFilter or pathFilter at all. In theory a tiny bit faster as well as we head straight for the package.json file and potentially shortcut instead of traversing and checking for file existence.

(code is in above PR if this explanation made no sense, which it probably doesn’t)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature]: Support package imports in jest-resolve #12270
Once a module implementing the algorithm exists (e.g. lukeed/resolve.exports#14) we should be good to go for adding support here.
Read more >
Using the Incremental Exports API | Zendesk Developer Docs
You can use the Incremental Exports API to get items that changed or were created in Zendesk ... The other endpoints only support...
Read more >
Configuring Jest
All modules used in your tests will have a replacement implementation, keeping the API surface. Example: utils.js. export default {
Read more >
How can I export to a json file with more then 10000 records?
Solved: I try to use a powershell script to get data from a couple ... You can look at the following link which...
Read more >
Export a REST API from API Gateway - AWS Documentation
Export an existing REST API from API Gateway to OpenAPI and other API definition ... Export API, which is part of the Amazon...
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