Skip to content

Switch to ESM#59

Merged
lydell merged 4 commits intolydell:mainfrom
fisker:esm
Dec 8, 2025
Merged

Switch to ESM#59
lydell merged 4 commits intolydell:mainfrom
fisker:esm

Conversation

@fisker
Copy link
Copy Markdown
Contributor

@fisker fisker commented Dec 8, 2025

@babel/code-frame@8 is now in ESM, reasonable to ship this module in ESM?

@fisker fisker marked this pull request as ready for review December 8, 2025 13:31
@lydell
Copy link
Copy Markdown
Owner

lydell commented Dec 8, 2025

Hi! What are you doing that motivates this?

@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Dec 8, 2025

Sorry, forgot to write.. See updated PR description.

@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Dec 8, 2025

The main purpose is for Prettier

image

@lydell
Copy link
Copy Markdown
Owner

lydell commented Dec 8, 2025

And what are you trying to achieve in Prettier? I’m not sure what you want to show with the screenshot.

@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Dec 8, 2025

ESbuild bundles CJS files like this

var require_js_tokens = __commonJS({
  // ...
});
var import_js_tokens = __toESM(require_js_tokens(), 1);
import_js_tokens.default(...);

And ESM files are like

// ...
var js_tokens_default = jsTokens;
js_tokens_default(...);

To me, the code is nicer.

I'm sending this since I thought you are open to ES modules, but it's fine if you don't want to accept.

@lydell
Copy link
Copy Markdown
Owner

lydell commented Dec 8, 2025

I am open to ES modules, but I would rather switch to ESM-only than doubling the package size. So far, I haven’t really seen the benefit of making that breaking change, but since Node.js supports require-ing ESM (some) modules these days I think it might be time to finally make the switch.

@fisker fisker changed the title Ship in dual mode Switch to ESM Dec 8, 2025
@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Dec 8, 2025

Done

Comment thread README.md
import jsTokens from "js-tokens";
// or:
const jsTokens = require("js-tokens");
const jsTokens = require("js-tokens").default; // Requires Node.js 20.19.0 or later.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, didn’t know about that feature. #61

@lydell lydell merged commit 4f0f377 into lydell:main Dec 8, 2025
10 checks passed
@fisker fisker deleted the esm branch December 8, 2025 18:37
@lydell
Copy link
Copy Markdown
Owner

lydell commented Dec 8, 2025

Released in v10.0.0.

Thanks for the nudge and the help!

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.

2 participants