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

Extract resolution algorithm for imports #14

Closed
SimenB opened this issue Feb 7, 2022 · 15 comments · Fixed by #24
Closed

Extract resolution algorithm for imports #14

SimenB opened this issue Feb 7, 2022 · 15 comments · Fixed by #24

Comments

@SimenB
Copy link
Contributor

SimenB commented Feb 7, 2022

From what I understand, the imports field has the same rules when it comes to conditions and wildcard substitutions that exports has. Do you have any plans to extract the algorithm used in this module so it can be reused for imports? Or create an resolve.imports module? 😀

@lukeed
Copy link
Owner

lukeed commented Feb 9, 2022

There are a couple additions to the imports side of things & I was planning on offering an extra module for it. I haven't actually done it yet, but it might make sense for there to be some facade module (eg resolve.exports/internal) to do the matching that both modules can reuse, depending on how much duplication there actually is.

There's also #6 to consider, which would mean that there'd have to be different error codes thrown. Still planned for a 2.0 release

@SimenB
Copy link
Contributor Author

SimenB commented Feb 9, 2022

Awesome, looking forward to it! Very close to shipping exports in jest using this module and would love to use something similar for imports 👍

@chenyulun
Copy link

Create a package resolve.pkg

import { resolve, legacy } from 'resolve.pkg'
import { resolve, legacy, resolveExports, resolveImports } from 'resolve.pkg'
// type default 'exports'
resolve(pkgJSON, './foo', {type: 'exports'}) // === resolve(pkgJSON, './foo') === resolveExports(pkgJSON)
resolve(pkgJSON, '#dep', {type: 'imports'}) // === resolveImports(pkgJSON,  '#dep')

Add some necessary validation

That's my advice

@chenyulun
Copy link

chenyulun commented Feb 17, 2022

Should not need the type argument, can be checked by # start,
With pkg-up, we can quickly find nearby package.json files

@okikio
Copy link

okikio commented Feb 23, 2022

If y'all need a quick resolve.imports fork I created a gist with a tweaked version of resolve.exports but with support of the imports field, https://gist.github.com/okikio/3f07571c7707dc6e6eb4906b951c6bc3

@SimenB
Copy link
Contributor Author

SimenB commented Apr 25, 2022

Jest 28 is out with exports support. Very happy with the integration! 😀 Is imports still on the roadmap @lukeed?

@thepassle
Copy link

If y'all need a quick resolve.imports fork I created a gist with a tweaked version of resolve.exports but with support of the imports field, https://gist.github.com/okikio/3f07571c7707dc6e6eb4906b951c6bc3

Is this published on npm anywhere by any chance? 🙂 Found myself needing to resolve imports, and was hoping this package already supported it

@lukeed would you be open for a contribution to support this usecase?

@okikio
Copy link

okikio commented Dec 30, 2022

I could quickly publish it as a package if you'd like.

@thepassle
Copy link

That'd be awesome, thanks 🙂

@okikio
Copy link

okikio commented Jan 1, 2023

@thepassle It's published as @okikio/resolve.imports

You can also use, it seems to be an alternative

@thepassle
Copy link

@thepassle It's published as @okikio/resolve.imports

You can also use, it seems to be an alternative

Thanks dude, appreciate it!

@SimenB
Copy link
Contributor Author

SimenB commented Jan 1, 2023

Yeah, thanks! I just opened a PR in Jest using it 🙂

@SimenB
Copy link
Contributor Author

SimenB commented Jan 1, 2023

As an aside, I opened up nodejs/node#44535 in node core asking then to expose the algorithm for others to use. Not much movement yet, but who knows 🙂

@unional
Copy link

unional commented Jan 1, 2023

FYI resolve.imports 1.2.4 is released.

@lukeed
Copy link
Owner

lukeed commented Jan 15, 2023

resolve.exports@next is released for early preview, which includes imports support. Total package is less than 1kB while still including the (treeshakable) legacy method 😅. I'll publish it as stable 2.0 Monday or Tuesday if all seems to work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants