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

Support ES Modules #41

Closed
dyoder opened this issue Aug 1, 2021 · 4 comments
Closed

Support ES Modules #41

dyoder opened this issue Aug 1, 2021 · 4 comments

Comments

@dyoder
Copy link

dyoder commented Aug 1, 2021

I'm adding this per @dchest's comment in #28:

One "feature" that I'd like to add in the future is to support the modern module system in addition to CommonJS, so I'll work on it some time in the future. It will probably require reworking of the random generator detection.

FWIW, we need this for our work (we also need this for Tweet-NaCl). If there are no immediate plans to do this, we can submit a PR.

@dyoder
Copy link
Author

dyoder commented Aug 3, 2021

@dchest I have a working model for doing this, but I don't want to apply it across all the packages unless it's acceptable to you.

  • Basically, I add a second tsconfig file, like this.
  • Then I add exports and alter the build command like this.
  • Running npm run build now will build both versions, placing the esm-compatible version into lib-es6.

I've tested this with base64 and utf8 and the tests still pass, although that's unsurprising since we still build into the lib directory as before. I didn't attempt to get Jasmine to run the tests in lib-es6 as well, but I can do that if this approach makes sense to you. However, I have successfully loaded the module into the browser via an import map, so it's able to find the esm version okay.

If you're agreeable to this approach, I can apply across all the packages and submit a PR. If not, I can try to incorporate your feedback. Or if you have other plans for implementing this, that's fine, too, obviously. Just thought I'd share my work. 🙂

@josh-i386g

This comment was marked as resolved.

@PhearZero
Copy link

Hello @dchest and @dyoder. Hope you are well, didn't know about stable lib until today. Just submitted a draft PR to Tweet-NaCl for ESM. Would love to sync up and help in any way.

@dchest
Copy link
Member

dchest commented Jun 29, 2024

Fixed in 2.0.

@dchest dchest closed this as completed Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants