-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: support EsModules #143
Conversation
9c83302
to
fc75695
Compare
if (length === false) { | ||
options.normalizer = (await import("./normalizers/primitive.mjs")).default; | ||
} else if (length > 1) { | ||
options.normalizer = ( | ||
await import("./normalizers/get-primitive-fixed.mjs") | ||
).default(length); | ||
} | ||
} else if (length === false) | ||
options.normalizer = (await import("./normalizers/get.mjs")).default(); | ||
else if (length === 1) | ||
options.normalizer = (await import("./normalizers/get-1.mjs")).default(); | ||
else options.normalizer = (await import("./normalizers/get-fixed.mjs")).default(length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These modules are tiny, and there's not much benefit in importing them lazily. I can import them at the top-level instead of using dynamic imports. This would make the memoize function sync again similar to the cjs implementation.
@aminya great thanks for the effort, but at this point I do not plan to refactor this package into ES modules. I believe this package is also perfectly accessible from ES modules context. Ideally such changes, before taking implementation effort should be first consulted on issue level |
No problem. I assumed that this repo will not be open to modernization given the number of polyfills that are imported directly. I'll create a hard fork then. |
Here's the fork link for those interested. I'll probably rename and publish the modernized package on npm soon. It will be API-compatible with memoizee, and will support all the old platforms via Babel. |
This adds support for EsModules to Memoizee. This is a step towards the modernization of this library. The old Node 0.12 support is maintained via Babel, and thus these changes are fully backwards compatible.
When ' ESM ' is used, the main
memoizee
function loads the extensions asynchronously via dynamic imports. This helps prevent the bundling of unused code in the browsers.31st Aug 2024 benchmarks: