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

Add CJS version #2

Closed
ai opened this issue Sep 27, 2021 · 8 comments
Closed

Add CJS version #2

ai opened this issue Sep 27, 2021 · 8 comments

Comments

@ai
Copy link
Contributor

ai commented Sep 27, 2021

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

@alexeyraspopov
Copy link
Owner

alexeyraspopov commented Sep 27, 2021

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?

@ai
Copy link
Contributor Author

ai commented Sep 27, 2021

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.

@ai
Copy link
Contributor Author

ai commented Sep 27, 2021

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.)

@denysovkos
Copy link
Collaborator

@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?

@alexeyraspopov
Copy link
Owner

Right now Jest has no ESM support with mocks.

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

@r-rajaneesh
Copy link

r-rajaneesh commented Sep 27, 2021

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 👍 :)

@alexeyraspopov
Copy link
Owner

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

@alexeyraspopov
Copy link
Owner

[email protected] is now published and supports CommonJS modules
https://github.com/alexeyraspopov/picocolors/releases/tag/v0.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants