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

refactor: migrate to using esms #83

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bryan-hoang
Copy link

To address #69, I read through an article about how to convert packages
to pure ESM 1. cjstoesm was quite helpful here 2.

But it didn't talk about how to still support being imported by CJS
modules without the use of dynamic imports. It's annoying being forced
to change the color of a function 3.

I came across another article discussing a more streamlined way to build
a package for consumers of either module format 4, and I wanted to
try out unbuild 5.

The current version of ava used doesn't support ESMs. Given that
updating to a major version that does support it would lead to more code
changes from breaking changes, I decided to switch to using Vitest.

There were also issues with importing older versions of chalk into
ESMs, so I opted to update chalk to v5 (ESM).

titleize was removed as an unused dependency.

Resolves #69.

Footnotes

  1. https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

  2. https://github.com/wessberg/cjstoesm

  3. https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/

  4. https://antfu.me/posts/publish-esm-and-cjs

  5. https://github.com/unjs/unbuild

It's easier to read and make changes to a consistently formatted
`package.json` file.

Refs: https://www.npmjs.com/package/sort-package-json
What motivated the change is that it wasn't clear from the `readme.md`
nor the CI job that `pnpm` is the main package manager for the project.

In addition to updating the CI job & docs, the `packageManager` field of
the `package.json` was updated to help signify the intended package
manager used to develop the project.

BREAKING CHANGE: Dropped support for Node.js versions lower than 18.
Node.js 16's security updates ended on 2023-09-11.

Refs: https://github.com/nodejs/Release#end-of-life-releases
To address vercel#69, I read through an article about how to convert packages
to pure ESM [^1]. `cjstoesm` was quite helpful here [^2].

But it didn't talk about how to still support being imported by CJS
modules without the use of dynamic imports. It's annoying being forced
to change the color of a function [^3].

I came across another article discussing a more streamlined way to build
a package for consumers of either module format [^4], and I wanted to
try out `unbuild` [^5].

The current version of `ava` used doesn't support ESMs. Given that
updating to a major version that does support it would lead to more code
changes from breaking changes, I decided to switch to using Vitest.

There were also issues with importing older versions of `chalk` into
ESMs, so I opted to update `chalk` to v5 (ESM).

`titleize` was removed as an unused dependency.

Resolves vercel#69.

[^1]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[^2]: https://github.com/wessberg/cjstoesm
[^3]: https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/
[^4]: https://antfu.me/posts/publish-esm-and-cjs
[^5]: https://github.com/unjs/unbuild
Given it's a project from vercel, we may as well start following the
company's style for the project to help with enforcing consistency.

Also had to do some configuration around import assertions/attributes
for ESLint.
To run fix formatting & lint issues before commits are made.
Adds clipboard support for WSL & fixes vulnerabilities for using `exec`
v0.8.0.
Copy link

@orca-security-us orca-security-us bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca

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

Successfully merging this pull request may close these issues.

Update all dependencies to latest and support ESM
1 participant