[WIP] Migrate everything to modules by weswigham · Pull Request #35561 · microsoft/TypeScript (original) (raw)
The idea is that we can refactor our codebase to modules, generate the existing outputs, and then factor everything into smaller, self-contained dependencies that you can include a-la-cart - so while typescript
on npm may still contain 4 bundled copies of the code for API compatibility's sake, @typescript/tsc
only depends on the modules required to implement tsc
, and @typescript/tsserver
- only those for the server and so on. But before we can ship those smaller, piecewise packages (which definitely have tangible benefits, like shared sources within a runtime), we have to break up our codebase to be piecewise in the firstplace.
Plus, to directly counter each of your points:
requires extra tooling for bundling
Consumers of TS
already use bundlers in scenarios where they make sense to use - our monolithic structure makes our internals impossible to tree shake, resulting in exceedingly large bundles. That our "typescript.js" can load the language server API in a browser with a single script
tag, while great for toys without much other meat, isn't great for real at-scale applications.
requires extra 'ceremony' i.e. typically 5-10 of import statements 'tax for the very same existing logic
Yes and no. That "ceremony" is implicitly being added by the compiler right now - all those cross-file references implicitly compile to ts.
namespace references. Those actually have a real cost, compared to (native) named imports across modules - on the order of multiple percentage points of performance. (See #39247 for similar discussion). Beyond performance, we literally make the tool that makes the editor take care of that "ceremony" automatically for users - and we really should be dogfooding it more.
requires extensive, non-localisable bug-prone refactoring
the "extensive non-local refactoring" is done by a tool at this point, so... 🤷 if the results are typechecked and tested, and the transform done by tools... does it matter?