Skip to content

ESM + Typescript - #630

Merged
timgit merged 30 commits into
masterfrom
ts-esm
Nov 9, 2025
Merged

ESM + Typescript#630
timgit merged 30 commits into
masterfrom
ts-esm

Conversation

@timgit

@timgit timgit commented Nov 7, 2025

Copy link
Copy Markdown
Owner

No description provided.

@coveralls

coveralls commented Nov 7, 2025

Copy link
Copy Markdown

Coverage Status

coverage: 99.899% (+0.006%) from 99.893%
when pulling c6f0cf6 on ts-esm
into 5a6313a on master.

@timgit

timgit commented Nov 7, 2025

Copy link
Copy Markdown
Owner Author

@davbrito and @bcomnes, this PR contains the ESM rewrite PR + Typescript tests. Asking for your opinions on the index.cjs pattern I used here (and anything else). This pattern seems to be unpopular, but I was wanting a more clean way to require(esm) than what typescript is currently producing during transpile where export default boss becomes export.default = boss instead of module.exports = boss like it used to be for require(). Obviously this pattern has a shelf life once cjs become extinct, but it at least avoid dual package publishing. I bumped up the minimum node version to 22.12 for require(esm) as well.

@bcomnes

bcomnes commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

I can take a peek tomorrow.

@davbrito

davbrito commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

This pattern seems to be unpopular, but I was wanting a more clean way to require(esm) than what typescript is currently producing during transpile where export default boss becomes export.default = boss instead of module.exports = boss like it used to be for require()

It seems it could be achieved with a single default export: https://tsdown.dev/options/cjs-default

I tried removing these lines:
image

image

And had this cjs output thanks to cjsDefault option:
image


A different approach would be to get rid of the default export and just use named exports. This way it can be published as esm only, cjs users will just need a node version compatible with require(esm).

image

@davbrito

davbrito commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Here is an example how would it be with esm only & named exports only:

davbrito@fef79d4

@timgit

timgit commented Nov 7, 2025

Copy link
Copy Markdown
Owner Author

Thanks for the feedback. I'm leaning towards consolidating to named exports and abandoning default

@bcomnes

bcomnes commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

I’m plus one on not supporting default exports and avoiding a cjs wrapper. In theory it works well in modern node but things get murky in tortured environments like next.js or deno/bun node comparability layers.

Comment thread src/types.ts Outdated
Comment thread test/test-types.d.ts Outdated
Comment thread test/workTest.ts Outdated
Comment thread test/queueTest.ts Outdated
@timgit
timgit merged commit cb6c919 into master Nov 9, 2025
4 checks passed
@timgit
timgit deleted the ts-esm branch November 9, 2025 22:03
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.

4 participants