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

Convert to ESM module #48

Merged
merged 26 commits into from
Dec 29, 2023
Merged

Convert to ESM module #48

merged 26 commits into from
Dec 29, 2023

Conversation

banga
Copy link
Owner

@banga banga commented Dec 29, 2023

This converts the package to generate an ESM module as the build output. The instigator was #39 but there were a number of ESM-only packages in the dependencies. The final result is as follows:

  • Switched from term-size to terminal-size and upgraded ansi-regex, chalk and diff.
  • Switched to shikiji and patched the perf optimization for setTheme from shiki.
  • Update min node version to 18.
  • There's a ~35ms improvement in startup time.
  • Switched from yarn to npm. yarn v4 does pretty weird things that were hard to get to work esp on windows.

Upgrading the version for `terminal-size`, which forces us to switch to
ESM and bump the min node version to 18.

I got the build to work with esbuild using --format=esm. Also realized
that we can remove the `bin/git-split-diffs` file and instead directly
specify `index.mjs` in the `bin` field in `package.json` after inserting
a shebang line at the top using esbuild.

The stuff that doesn't work is:
- `yarn benchmark`, likely because the `benchmark` lib generates the
  module in weird way that conversion to ESM doesn't work. I should find
  a more modern benchmarking lib.
- `yarn test` fails because jest and ts-jest's ESM support seems kind of
  finicky.
- For benchmark, just needed to declare `benchmark` as external for
  esbuild
- For tests, node needs to be invoked specially
  (https://jestjs.io/docs/ecmascript-modules) and `ts-jest` needs to be
  configured differently
tsc was initially complaining about missing file extensions because, but
  adding them in breaks jest (somehow end up with .ts.ts files). So
  instead by changing `moduleResolution` to `Bundler`, we get ts to
  leave the paths alone.
Now that we can handle ESM-only modules, switch to the `shikiji`
package, which at least supports lazy loading languages. I measured a
small speedup of 40ms, which is lower than what I was expecting.
`ansi-regex` and `chalk` are ESM only, which we can now handle. Esbuild
can also now bundle them into the output.
Didn't realize I was still on yarn 1. Used `yarn patch` to add the fix
from antfu/shikiji#66.
@banga banga merged commit 3829fbb into main Dec 29, 2023
18 checks passed
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.

None yet

1 participant