Fix ESM support
Changes made
- add type: module, to package.json
- Use tsup for bundle
- Use pattern for fetch subpath exports
- Use named import for Jsona, broken when trying to use DS otherwise
- Rename jest.config to .cjs
- Workaround for jest tests - use node-fetch v2 for test to workaround ESM compat
- Move some non-deps to devDeps
- Lockfile was updated to v3 automatically
- Remove postpublish script, js files now emit to ./dist
Explanation
I removed rollup but it is quite possible I misunderstood it's purpose, so I apologize if that is the case and can re-add it or refactor the rollup build to work for out needs. I feel more comfortable with tsup right now and it uses rollup under the hood so I figured it shouldn't be too different.
These changes have been tested with npx publint
and npx @arethetypeswrong/cli
, which still reports an issue about the CJS version of the bundle "Masquerading as ESM" (see https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md for the full explanation). Even when emitting both d.mts and d.ts files, I could not fix all of the lint warnings, but at least this version of the bundle works using Next 13's app router. I also tested the bundle in a vanilla TypeScript create-vite-app
.
This should also close https://www.drupal.org/project/drupal_state/issues/3231626 as the compiled js now emits to ./dist