Skip to content

Make TypeScript itself ESM-only, made possible by require(ESM) - #58419

Closed
Jake Bailey (jakebailey) wants to merge 6 commits into
microsoft:mainfrom
jakebailey:its-esm
Closed

Make TypeScript itself ESM-only, made possible by require(ESM)#58419
Jake Bailey (jakebailey) wants to merge 6 commits into
microsoft:mainfrom
jakebailey:its-esm

Conversation

@jakebailey

@jakebaileyJake Bailey (jakebailey) commented May 2, 2024

Copy link
Copy Markdown
Member

nodejs/node#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 nodejs/node#52599 and nodejs/node#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 exporting default fixes this.
  • Consider looking for require if process.getBuiltinModule is not found
  • Export maps? Actually make the package importable? (does this work?)
  • Maybe still ship CJS behind a condition to get this out sooner?
    • Dual package hazard is very scary here. Maybe acceptable with module condition/top-level prop?
  • 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?
  • @types/diff is typed wrong

@typescript-bot

Copy link
Copy Markdown
Contributor

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 Sheetal Nandi (@sheetalkamat), Matt Bierner (@mjbvz), Kat Marchán (@zkat), and Joaquin Jares (@joj) for you. Feel free to loop in other consumers/maintainers if necessary.

@jakebailey

Copy link
Copy Markdown
MemberAuthor

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).

@jakebailey
Jake Bailey (jakebailey)force-pushed the its-esm branch 2 times, most recently from bed73cc to 739c9bfCompareMay 7, 2024 02:42
@typescript-bot

Copy link
Copy Markdown
Contributor

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 Daniel Rosenwasser (@DanielRosenwasser) and Ryan Cavanaugh (@RyanCavanaugh) are aware of the changes, just as a heads up.

@jakebailey

Copy link
Copy Markdown
MemberAuthor

There are still a bunch of TODOs, but this is actually green! Wow!

@jakebailey

Copy link
Copy Markdown
MemberAuthor

nodejs/node#52762 was merged a bit ago; I should be able to retarget this PR at nightly.

@jakebailey

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) perf test this faster hosts=node@23.0.0

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 17, 2024

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
perf test this faster hosts=node@23.0.0✅ Started👀 Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v23.0.0, x64)
Errors3131~~~p=1.000 n=6
Symbols62,34062,340~~~p=1.000 n=6
Types50,37950,379~~~p=1.000 n=6
Memory used193,727k (± 0.02%)194,442k (± 0.02%)+715k (+ 0.37%)194,412k194,500kp=0.005 n=6
Parse Time1.14s (± 1.99%)1.17s (± 1.21%)+0.03s (+ 3.08%)1.15s1.19sp=0.023 n=6
Bind Time0.56s0.58s (± 0.71%)+0.02s (+ 3.27%)0.57s0.58sp=0.002 n=6
Check Time7.49s (± 0.36%)7.60s (± 0.81%)+0.11s (+ 1.42%)7.53s7.70sp=0.008 n=6
Emit Time2.28s (± 0.33%)2.40s (± 0.53%)🔻+0.12s (+ 5.19%)2.39s2.42sp=0.004 n=6
Total Time11.47s (± 0.34%)11.74s (± 0.41%)+0.27s (+ 2.38%)11.69s11.81sp=0.005 n=6
angular-1 - node (v23.0.0, x64)
Errors3333~~~p=1.000 n=6
Symbols947,886947,886~~~p=1.000 n=6
Types410,840410,840~~~p=1.000 n=6
Memory used1,225,465k (± 0.00%)1,226,690k (± 0.00%)+1,225k (+ 0.10%)1,226,609k1,226,739kp=0.005 n=6
Parse Time5.65s (± 3.19%)5.70s (± 3.64%)~5.39s5.85sp=0.228 n=6
Bind Time1.74s (±11.31%)1.83s (±10.71%)🔻+0.10s (+ 5.56%)1.71s2.14sp=0.046 n=6
Check Time25.87s (± 0.50%)26.35s (± 0.35%)+0.48s (+ 1.85%)26.23s26.49sp=0.005 n=6
Emit Time13.00s (± 0.66%)13.68s (± 0.55%)🔻+0.68s (+ 5.22%)13.63s13.83sp=0.005 n=6
Total Time46.26s (± 0.45%)47.57s (± 0.27%)+1.31s (+ 2.84%)47.42s47.76sp=0.005 n=6
mui-docs - node (v23.0.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,530,4452,530,445~~~p=1.000 n=6
Types916,594916,594~~~p=1.000 n=6
Memory used2,340,106k (± 0.00%)2,341,324k (± 0.00%)+1,218k (+ 0.05%)2,341,198k2,341,420kp=0.005 n=6
Parse Time9.33s (± 0.77%)9.55s (± 0.55%)+0.22s (+ 2.30%)9.47s9.62sp=0.005 n=6
Bind Time2.23s (± 0.54%)2.30s (± 0.59%)+0.07s (+ 3.14%)2.28s2.32sp=0.004 n=6
Check Time74.99s (± 1.12%)75.36s (± 0.73%)~74.86s76.39sp=0.229 n=6
Emit Time0.38s (±48.10%)0.30s (± 1.35%)~0.30s0.31sp=0.248 n=6
Total Time86.93s (± 1.01%)87.51s (± 0.59%)+0.58s (+ 0.67%)87.04s88.46sp=0.045 n=6
self-build-src - node (v23.0.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,258,0321,258,086+54 (+ 0.00%)~~p=0.001 n=6
Types266,259266,404+145 (+ 0.05%)~~p=0.001 n=6
Memory used2,422,147k (± 0.01%)2,433,135k (± 0.01%)+10,988k (+ 0.45%)2,432,859k2,433,402kp=0.005 n=6
Parse Time4.08s (± 0.89%)4.27s (± 0.65%)🔻+0.19s (+ 4.65%)4.23s4.31sp=0.005 n=6
Bind Time1.75s (± 0.60%)1.80s (± 0.29%)+0.05s (+ 2.75%)1.80s1.81sp=0.004 n=6
Check Time26.72s (± 0.23%)26.97s (± 0.49%)+0.25s (+ 0.93%)26.87s27.21sp=0.005 n=6
Emit Time1.97s (± 0.75%)2.02s (± 0.49%)+0.05s (+ 2.71%)2.01s2.04sp=0.005 n=6
Total Time34.56s (± 0.26%)35.07s (± 0.40%)+0.51s (+ 1.48%)34.92s35.32sp=0.005 n=6
self-build-src-public-api - node (v23.0.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,258,0321,258,086+54 (+ 0.00%)~~p=0.001 n=6
Types266,259266,404+145 (+ 0.05%)~~p=0.001 n=6
Memory used2,503,622k (± 0.01%)2,526,649k (± 0.02%)+23,026k (+ 0.92%)2,526,334k2,527,559kp=0.005 n=6
Parse Time4.34s (± 1.03%)4.47s (± 0.72%)+0.13s (+ 3.11%)4.43s4.51sp=0.005 n=6
Bind Time1.51s (± 0.27%)1.56s (± 0.33%)+0.04s (+ 2.98%)1.55s1.56sp=0.003 n=6
Check Time27.55s (± 0.31%)27.89s (± 0.25%)+0.35s (+ 1.25%)27.82s27.98sp=0.005 n=6
Emit Time1.98s (± 0.87%)2.08s (± 0.66%)🔻+0.10s (+ 5.21%)2.06s2.10sp=0.005 n=6
Total Time35.38s (± 0.32%)36.01s (± 0.23%)+0.63s (+ 1.78%)35.94s36.15sp=0.005 n=6
self-compiler - node (v23.0.0, x64)
Errors00~~~p=1.000 n=6
Symbols261,789261,815+26 (+ 0.01%)~~p=0.001 n=6
Types106,511106,599+88 (+ 0.08%)~~p=0.001 n=6
Memory used439,547k (± 0.02%)440,625k (± 0.03%)+1,078k (+ 0.25%)440,483k440,879kp=0.005 n=6
Parse Time3.09s (± 1.50%)3.19s (± 1.11%)+0.10s (+ 3.18%)3.15s3.22sp=0.005 n=6
Bind Time1.13s (± 1.22%)1.16s (± 1.15%)+0.03s (+ 2.96%)1.14s1.17sp=0.007 n=6
Check Time14.80s (± 0.35%)15.09s (± 0.15%)+0.29s (+ 1.94%)15.05s15.11sp=0.005 n=6
Emit Time1.15s (± 0.65%)1.20s (± 1.01%)+0.04s (+ 3.91%)1.18s1.21sp=0.005 n=6
Total Time20.18s (± 0.27%)20.63s (± 0.22%)+0.46s (+ 2.27%)20.58s20.71sp=0.005 n=6
ts-pre-modules - node (v23.0.0, x64)
Errors6868~~~p=1.000 n=6
Symbols225,919225,919~~~p=1.000 n=6
Types94,41594,415~~~p=1.000 n=6
Memory used372,382k (± 0.01%)373,221k (± 0.01%)+839k (+ 0.23%)373,153k373,283kp=0.005 n=6
Parse Time2.50s (± 1.06%)2.58s (± 2.04%)+0.08s (+ 3.13%)2.51s2.65sp=0.015 n=6
Bind Time1.40s (± 1.05%)1.43s (± 0.73%)+0.03s (+ 2.38%)1.42s1.45sp=0.012 n=6
Check Time12.60s (± 0.52%)12.85s (± 0.50%)+0.24s (+ 1.93%)12.80s12.97sp=0.005 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time16.52s (± 0.50%)16.87s (± 0.49%)+0.35s (+ 2.13%)16.76s17.00sp=0.005 n=6
vscode - node (v23.0.0, x64)
Errors33~~~p=1.000 n=6
Symbols3,118,6703,118,670~~~p=1.000 n=6
Types1,074,9551,074,955~~~p=1.000 n=6
Memory used3,211,514k (± 0.02%)3,212,413k (± 0.00%)+899k (+ 0.03%)3,212,340k3,212,534kp=0.005 n=6
Parse Time12.42s (± 1.14%)12.73s (± 0.52%)+0.31s (+ 2.51%)12.64s12.83sp=0.005 n=6
Bind Time4.02s (± 3.00%)4.16s (± 2.99%)~4.03s4.28sp=0.065 n=6
Check Time70.77s (± 0.49%)72.30s (± 0.36%)+1.53s (+ 2.16%)71.94s72.70sp=0.005 n=6
Emit Time22.72s (±10.89%)25.78s (± 0.86%)🔻+3.05s (+13.43%)25.52s26.13sp=0.005 n=6
Total Time109.93s (± 2.00%)114.97s (± 0.35%)🔻+5.04s (+ 4.58%)114.39s115.37sp=0.005 n=6
webpack - node (v23.0.0, x64)
Errors00~~~p=1.000 n=6
Symbols286,241286,241~~~p=1.000 n=6
Types116,005116,005~~~p=1.000 n=6
Memory used437,913k (± 0.02%)438,988k (± 0.03%)+1,075k (+ 0.25%)438,769k439,069kp=0.005 n=6
Parse Time4.18s (± 0.47%)4.24s (± 0.67%)+0.06s (+ 1.52%)4.19s4.27sp=0.009 n=6
Bind Time1.66s (± 1.25%)1.73s (± 1.34%)🔻+0.07s (+ 4.33%)1.70s1.76sp=0.005 n=6
Check Time16.35s (± 0.32%)16.75s (± 0.07%)+0.40s (+ 2.45%)16.74s16.77sp=0.005 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time22.19s (± 0.30%)22.72s (± 0.21%)+0.54s (+ 2.43%)22.67s22.80sp=0.005 n=6
xstate-main - node (v23.0.0, x64)
Errors33~~~p=1.000 n=6
Symbols543,130543,130~~~p=1.000 n=6
Types181,889181,889~~~p=1.000 n=6
Memory used486,951k (± 0.01%)487,800k (± 0.01%)+849k (+ 0.17%)487,769k487,844kp=0.005 n=6
Parse Time3.46s (± 1.35%)3.55s (± 0.96%)+0.09s (+ 2.75%)3.51s3.60sp=0.005 n=6
Bind Time1.11s (± 0.57%)1.16s (± 1.52%)🔻+0.04s (+ 4.05%)1.13s1.18sp=0.004 n=6
Check Time17.81s (± 0.40%)18.09s (± 0.32%)+0.28s (+ 1.54%)18.02s18.17sp=0.005 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time22.38s (± 0.52%)22.79s (± 0.28%)+0.41s (+ 1.85%)22.69s22.89sp=0.005 n=6
System info unknown
Hosts
  • node (v23.0.0, x64)
Scenarios
  • Compiler-Unions - node (v23.0.0, x64)
  • angular-1 - node (v23.0.0, x64)
  • mui-docs - node (v23.0.0, x64)
  • self-build-src - node (v23.0.0, x64)
  • self-build-src-public-api - node (v23.0.0, x64)
  • self-compiler - node (v23.0.0, x64)
  • ts-pre-modules - node (v23.0.0, x64)
  • vscode - node (v23.0.0, x64)
  • webpack - node (v23.0.0, x64)
  • xstate-main - node (v23.0.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@jakebailey

Copy link
Copy Markdown
MemberAuthor

Huh, where is the perf hit coming from here...?

@jakebailey

Copy link
Copy Markdown
MemberAuthor

Given the Go port, I don't think it makes sense for me to attempt this anymore. I think it's only going to cause more churn in the meantime.

@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Mar 23, 2026
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@jakebailey@typescript-bot