Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When trying to use the new Redlock library I noticed it was able to run
in NodeJS, but failed in Jest. Looks like that was because Jest (like
many tools right now) doesn't yet support native ESM modules yet.
I think its awesome Redlock is outputting native ESM, but while the
world is still converting to ESM I think it's nice to duel output to CJS
as well.
This updates the building of the library to support both ESM and CJS
clients. During the build process it now builds the library twice, once
with the main
tsconfig.json
file and again with a newtsconfig.cjs.json
file. Finally, it runs a newtools/fixup
bashscript to insert some build specific
package.json
files that add thecorrect "type" attribute to the folder. The final dist tree structure
looks like:
The rest of the change is updating the
package.json
file to point tothese new files.
Points to ESM index.js
index.d.ts
statements to the CJS index.js and import statements to the ESM
index.js
I mostly followed this blog post for the technique. I also tested locally to make sure require, import, and typescript types still all resolved correctly.
I know this is a bigger change, so very happy to respond to feedback / drop this PR if you don't feel like this is the correct direction for the project.