ide / await-lock

Mutex locks for async functions
MIT License
89 stars 12 forks source link

Switch output to ES modules #33

Open kasbah opened 1 year ago

kasbah commented 1 year ago

fixes #32

ide commented 1 year ago

Does this allow the package to be used from a CommonJS project (that is, with require() under the hood)? That is a requirement for now.

kasbah commented 1 year ago

I believe only if you use dynamic import. I read your answer on #5 as you dropping support for Commonjs but I guess it's still supported but only with a .default?

const AwaitLock = require('await-lock').default
ide commented 1 year ago

The main use case I care about for this package right now is that it works in a CommonJS environment running JS that has been compiled from TS (or another compiler like esbuild) with esModuleInterop enabled. So, require() needs to work without dynamic import().

kasbah commented 1 year ago

Fair enough, I just can't figure out how to actually use it from TS. If I set target to ES5 it complains about the #private identifiers (more details). Do you just ignore those compilation errors?

Thanks for this lib and all your responses by the way!

ide commented 1 year ago

I use a preset like @tsconfig/node18/tsconfig.json in the project's tsconfig.json, including the preset's settings for module resolution.

kasbah commented 1 year ago

That also doesn't work for me unfortunately but I won't drag you further into the module resolution tarpit. I'll likely just vendor your lib or create a fork.