change-case icon indicating copy to clipboard operation
change-case copied to clipboard

Add CommonJS output

Open suchipi opened this issue 5 months ago • 0 comments

I have several projects which, for various reasons:

  • use change-case,
  • need to use CommonJS,
  • and need change-case synchronously (ie. import() isn't good enough).

So, I've been keeping them back on version 4.1.2, just like 90% of your users:

Screenshot 2024-08-23 at 11 45 23 PM

It's actually very easy to publish a package that supports both ESM and CJS nowadays; a lot has changed since sindresorhus swapped all their packages to ESM (largely thanks to all the difficulties that caused...)

To publish both ESM and CJS, you output with TypeScript twice, then set the package.json's main field to a CommonJS file, and the exports field to ESM file(s). That's it.

This PR adds CommonJS support to all the packages in the change-case monorepo, by:

  • Instructing ts-scripts to use an additional tsconfig for the build step, via its project config key
  • Adding a tiny tsconfig-cjs.json for each package which extends the normal one, changing only the output module format and the output dir
  • Changing the main field in each package.json to point to the CommonJS output. The exports field remains the same.

Would you please consider accepting this PR? The time for "Pure ESM packages" has passed, and 4.6 million of your users are ready to move out of 2020.

suchipi avatar Aug 24 '24 05:08 suchipi