SIGN IN SIGN UP

Compile to both ESM and CJS (#114)

* Compile to both ESM and CJS

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 its 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 new
`tsconfig.cjs.json` file. Finally, it runs a new `tools/fixup` bash
script to insert some build specific `package.json` files that add the
correct "type" attribute to the folder. The final dist tree structure
looks like:

```
dist
├── cjs
│   ├── index.js
│   ├── index.js.map
│   ├── index.test.js
│   ├── index.test.js.map
│   └── package.json
├── esm
│   ├── index.js
│   ├── index.js.map
│   ├── index.test.js
│   ├── index.test.js.map
│   └── package.json
├── index.d.ts
└── index.test.d.ts
```

The rest of the change is updating the `package.json` file to point to
these new files.

* "main" - Old entry point. Points to CJS index.js
* "module" - Deprecated entry point (but many clients still use it).
  Points to ESM index.js
* "types" - Entry point for typescript types. Points to top level
  index.d.ts
* "exports" - New entry point router for Node14+. Points require
  statements to the CJS index.js and import statements to the ESM
  index.js

* Fix test command

Co-authored-by: Mike Marcacci <mike.marcacci@gmail.com>
E
Eric Koslow committed
a48e563a6e32280ef1fed3272237ba39cc8c987c
Parent: b75a5f4
Committed by GitHub <noreply@github.com> on 11/26/2021, 5:40:12 PM