Sparticuz / usps-webtools-promise

USPS Web Tools API wrapper
14 stars 4 forks source link

Very difficult to make 5.x work with anything still on commonjs #20

Closed taxilian closed 1 year ago

taxilian commented 1 year ago

Hi,

My project is using Typescript but still on commonJS -- and it was an absolute pain in the neck to make the current (5.0.0) version work in my project because it's now an ESM.

Any chance you could build a CJS version of the package as well? You can make the published version support both:

https://www.typescriptlang.org/docs/handbook/esm-node.html

// package.json
{
    "name": "my-package",
    "type": "module",
    "exports": {
        ".": {
            // Entry-point for TypeScript resolution - must occur first!
            "types": "./types/index.d.ts",
            // Entry-point for `import "my-package"` in ESM
            "import": "./esm/index.js",
            // Entry-point for `require("my-package") in CJS
            "require": "./commonjs/index.cjs",
        },
    },
    // CJS fall-back for older versions of Node.js
    "main": "./commonjs/index.cjs",
    // Fall-back for older versions of TypeScript
    "types": "./types/index.d.ts"
}
Sparticuz commented 1 year ago

I've moved v5 to esm only, if you still need cjs you can continue to use v4. I'll backport any security fixes to it. https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

On a side note, once I figured out how to migrate ava to support esm in my work projects, moving everything else to esm went fairly quickly.