alexeyraspopov / picocolors

The tiniest and the fastest library for terminal output formatting with ANSI colors

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add CJS version

ai opened this issue · comments

For PostCSS and Autoprefixer it is impossible to go to ESM-only mode in next 2 years.

Can you add CJS version? I prefer copy pasting with export replacement to have smallest npm package.

Here is a way to switch between CJS and ESM in package.json: https://github.com/ai/nanocolors/blob/main/package.json#L24-L25 https://github.com/ai/nanocolors/blob/main/package.json#L26-L33

Per @denysovkos's PR #5 and this issue, I started thinking about the approach to support CJS. Here are some takeaways:

  • CJS module is required for Node versions before 12
  • Adding CJS support via build step drastically increases package size
  • Node 10 most likely to die out very soon

The approach I'm currently considering implementing:

  • Create branch commonjs, where everything is converted to CJS module and published as v1.0.0
  • Keep main branch as ESM only package and publish v2.0.0
  • Update README with proper notice of versions support
  • Whenever needed, backport changes from main to commonjs and bump both minor/patch versions (I don't anticipate any major API breaking changes any time soon)
  • Eventually, stop support of v1.x once most of the community has moved to newer Node versions

Regardless, the decision won't affect #1.

Thoughts @ai @denysovkos?

Node 10 most likely to die out very soon

Just to clarify, Node 10 dead doesn’t mean that you can return to ESM.

CJS apps/libs can use ESM dependencies.

ESM is like a virus :D. The single ESM dependency inside the dependency tree will force everyone up by the stack to move to ESM.

This is why ESM transition will take a while. At least, year or two.

1.x and 2.x branches is not very useful. If we will need CJS version for years, we need a way to make major changes.

(Just to explain the problems of ESM transition. Right now Jest has no ESM support with mocks. It means that some big apps just can’t move to ESM right now.)

@alexeyraspopov I am totally fine with another branch for commonjs. From my experience, I am still on daily basis have some fun even with projects built on Node 6 or 8, so I am not sure it will die. Looks like it is the curse of Java 6 :)

Maybe better to ship binary and avoid of all of this cjs vs esm vs whatever_else?

Right now Jest has no ESM support with mocks.

Valid point, I'm experiencing quite a lot of trouble because of this.

Node 10 most likely to die out very soon

Just to clarify, Node 10 dead doesn’t mean that you can return to ESM.

CJS apps/libs can use ESM dependencies.

ESM is like a virus :D. The single ESM dependency inside the dependency tree will force everyone up by the stack to move to ESM.

This is why ESM transition will take a while. At least, year or two.

as said it might be a drastic change, my discord bot is fully CJS and cause picocolors needed import, I had to go to nanocolors
since this commit is pushed to github can you push it to https://npmjs.com/package/picocolors as well?
also thanks for the CJS 👍 :)

@Nigelrex, I'll be publishing a fresh version soon. Just finished adding proper level of testing for both module types in #8

picocolors@0.1.0 is now published and supports CommonJS modules
https://github.com/alexeyraspopov/picocolors/releases/tag/v0.1.0