Adyen / adyen-node-api-library

Adyen API Library for Node.js
MIT License
104 stars 60 forks source link

Convert Library to support ES Modules #1107

Open JohanBjoerklund opened 1 year ago

JohanBjoerklund commented 1 year ago

Is your feature request related to a problem? Please describe. Support for esm modules, since it has been supported in node for a while now.

Describe the solution you'd like Expose esm modulus.

Describe alternatives you've considered Impossible to use alternative if you want access to top level await etc

wboereboom commented 1 year ago

Hi @JohanBjoerklund ,

Thanks for requesting this feature. Could you maybe elaborate why you need this feature, and which problems it would solve for you?

Kind Regards, Wouter Adyen

JohanBjoerklund commented 1 year ago

It would enable the use of advanced features like top level await. That is not possible for anyone using this package at the moment.

wboereboom commented 1 year ago

Understood. I will add this feature to our Backlog. We'll investigate whether we can make this change without breaking current merchant implementations, and we shall address it when we can.

Kind Regards, Wouter Adyen

tpater commented 10 months ago

I'd vote for this as well. When using esbuild as a bundler it is impossible to do a proper tree-shaking with commonjs modules. At least for now. ES modules convertion would be really helpfull. When you use library e.g. as a dependency in AWS lambda - even though ES imports work - the whole library is being bundled into final minified chunk.

alfaproject commented 9 months ago

I'm having the exact same issue as @tpater. Due to the use of classes the library is massive and can't be tree shaken )':

paul-vd commented 5 months ago

We have a project using vite, we had to polyfill the library so that it works, as vite converts esm, but due to they weird bundled code, it not longer allows the named exports.

Here is the solution we implemented, but yea, this means no treashaking, but it's fine as we only use it server side.

// lib/adyen/api-library.ts
import * as AdyenLib from "@adyen/api-library";
export type * from "@adyen/api-library";

const Adyen =
  (AdyenLib as any as { default: typeof AdyenLib })?.default ?? AdyenLib;

export default Adyen;

it would be great if the package could implement hybrid usage for the bundles: https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

ptlls commented 4 months ago

@wboereboom Do you have an update on this?

When using the lib in AWS Lambda and esbuild, we are getting a huge bundle size of 1.9MB where 1.4MB is from this library.

image

Checkout, Terminal and other things are bundled even if we don't use it at all in our implementation.

ptlls commented 3 months ago

@DjoykeAbyah would you be able to help providing an update on this matter? Sorry to bother, I see you have been active in this repo and it would be great to get this improvement.

DjoykeAbyah commented 3 months ago

Hi @ptlls!

No problem at all! It wasn't in our initial roadmap at the time, but we will investigate this further. Currently, I don't have any updates on this matter, but I will get back to you as soon as I know more.

Regards,

Djoyke Adyen