Make TypeScript itself ESM-only, made possible by require(ESM)
https://github.com/nodejs/node/pull/51977 (behind --experimental-require-module in Node 22) enables Node to require ESM so long as that ESM does not make use of top-level await. TypeScript would only need top-level await to construct ts.sys at startup, which must be defined when the environment is detected to be Node. Via https://github.com/nodejs/node/issues/52599 and https://github.com/nodejs/node/pull/51977, we can synchronously access Node's built-ins, and therefore can offer up a TLA-free public API, enabling TypeScript to ship as ESM-only without breaking CJS users, once require(ESM) is unflagged.
TODO:
- [ ] Fix public API dts
- [ ] Figure out
__esModule- The real question is the context of
require(ESM)having__esModule. But I suspect that exportingdefaultfixes this.
- The real question is the context of
- [x] Consider looking for
requireifprocess.getBuiltinModuleis not found - [ ] Export maps? Actually make the package importable? (does this work?)
- [x] ~Maybe still ship CJS behind a condition to get this out sooner?~
- ~Dual package hazard is very scary here. Maybe acceptable with
modulecondition/top-level prop?~
- ~Dual package hazard is very scary here. Maybe acceptable with
- [x] ~Stop bundling? Share code between tsc.js/typescript.js?~
- [ ] Is this even a good idea before we figure out a better public API than our current huge omnibus?
- [x]
@types/diffis typed wrong
Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary.
This has been rebased now that we're using extensions on main, condensing this down to a pretty small change (though there's still stuff not working).
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.
Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.
There are still a bunch of TODOs, but this is actually green! Wow!
https://github.com/nodejs/node/pull/52762 was merged a bit ago; I should be able to retarget this PR at nightly.