Skip to content
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

Compile to both ESM and CJS #114

Merged
merged 3 commits into from
Nov 26, 2021
Merged

Commits on Nov 3, 2021

  1. 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
    ekosz committed Nov 3, 2021
    Configuration menu
    Copy the full SHA
    dcc7875 View commit details
    Browse the repository at this point in the history
  2. Fix test command

    ekosz committed Nov 3, 2021
    Configuration menu
    Copy the full SHA
    f85bda8 View commit details
    Browse the repository at this point in the history

Commits on Nov 26, 2021

  1. Configuration menu
    Copy the full SHA
    127584d View commit details
    Browse the repository at this point in the history