Skip to content

refactor: migrate to using esms - #83

Closed
bryan-hoang wants to merge 7 commits into
vercel:mainfrom
bryan-hoang:feature/support-esm
Closed

bryan-hoang wants to merge 7 commits into
vercel:mainfrom
bryan-hoang:feature/support-esm

Conversation

@bryan-hoang

Copy link
Copy Markdown
Contributor

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

[^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.

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

Copy link
Copy Markdown

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

@leerob

leerob commented Nov 19, 2024

Copy link
Copy Markdown
Contributor

Largely replaced by #86.

Although, I would be open to a separate PR building off of that PR to move to Vitest!

@bryan-hoang

Copy link
Copy Markdown
Contributor Author

Largely replaced by #86.

Although, I would be open to a separate PR building off of that PR to move to Vitest!

Roger that. I've opened #88!

leerob pushed a commit that referenced this pull request Nov 26, 2024
Based on a suggestion from @leerob [^1], I re-implemented the change I
made in #83.

I also attempted to improve the descriptions of each of the test cases.

[^1]: #83 (comment)
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

2 participants