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

exporting the packageResolve function #18

Closed
sheerlox opened this issue Nov 5, 2023 · 2 comments
Closed

exporting the packageResolve function #18

sheerlox opened this issue Nov 5, 2023 · 2 comments

Comments

@sheerlox
Copy link

sheerlox commented Nov 5, 2023

Hey there 👋 Thanks for developing this great package!

I am working on an ESM version of import-from (ingeniously named import-from-esm), for which I needed to emulate require's behavior using ESM dynamic import.

I found a function (packageResolve) in your library that saved me 99% of the work, and by using it I don't have to implement node_modules tree traversal, export maps resolution, etc...

Because that function isn't exported by your package, I have copied the sources (and license) from import-meta-resolve/lib/, exported the packageResolve function, removed the resolve & moduleResolve functions, and pruned unused code.

As discussed on semantic-release/release-notes-generator#544 (comment), it would be best to directly use your library for updates and security concerns, if you'd agree to export the packageResolve function (without necessarily documenting it).

Please let me know if you'd be okay with that, or if there are any concerns on your mind!

@wooorm
Copy link
Owner

wooorm commented Nov 6, 2023

Yo Pierre!

Now that import.meta.resolve in Node is a release candidate, I expect it to be unflagged soonish. If that happens, that would likely/hopefully be backported to v18. Which is EOL at 2025-04-30, at which point this package is no longer needed, at which point you’d need a maintained version.

So perhaps pushing for nodejs/node#49445 I think might be better?

Anyway, feel free to PR this for now.
Actually, given 49445, perhaps return the folder URL (as a string) instead of the package.json URL? That would make it useful more broadly. And then we kinda polyfill that import.meta idea!

@sheerlox
Copy link
Author

sheerlox commented Nov 6, 2023

Thank you for your swift response, and for pointing me to nodejs/node#49445!

After reading the whole thread this morning, I added missing tests on my library and started a little refactoring: it turns out moduleResolve does the job for my use case, with the added benefit of now supporting import maps.

Thank you for your guidance 😄

@sheerlox sheerlox closed this as completed Nov 6, 2023
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

No branches or pull requests

2 participants