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

ESM #27

Open
brettz9 opened this issue Jan 16, 2021 · 7 comments
Open

ESM #27

brettz9 opened this issue Jan 16, 2021 · 7 comments

Comments

@brettz9
Copy link

brettz9 commented Jan 16, 2021

Open to an ESM PR, for native ESM and/or Rollup?

@sindresorhus
Copy link
Owner

Sure, but only native ESM. I don't want any build step. You need to target Node.js 12.

You can see how I recently did it here: sindresorhus/quick-lru@a408ce9

@brettz9
Copy link
Author

brettz9 commented Jan 17, 2021

Thanks. I don't see a clear way for Karma to be used with ESM outside of an old Karma ESM package which is recommending Web Test Runner. Should I switch to that test runner?

@sindresorhus
Copy link
Owner

Sure

@brettz9
Copy link
Author

brettz9 commented Jan 17, 2021

Hmmm...

In order to preserve the detection and dynamic registration of your "shortcut" capabilities, I think the API would need to change to support the asynchronous nature of the dynamic native ESM imports, i.e., one would have to import an export function and await its result in order to use the Observable.

Top-level await might be usable, but would require Node 14+ (and browser support is currently very limited: https://caniuse.com/mdn-javascript_operators_await_top_level ).

Alternatively, the dynamic detection could be dropped in favor of requiring a specific implementation.

@sindresorhus
Copy link
Owner

What problems does making this package ESM solve? Because it sounds like converting it to ESM will cause more problems than it solves. ESM can import CommonJS.

@brettz9
Copy link
Author

brettz9 commented Jan 17, 2021

I like being able to make direct imports without a build step for browser (or polyglot) environments, but maybe it is just best to wait (or I could just make a specific fork). Will close for now then. Thanks!

@brettz9 brettz9 closed this as completed Jan 17, 2021
@sindresorhus
Copy link
Owner

I'd like to keep this open so it's not forgotten. There's some useful info here. I'll circle back to this issue later this year.

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