lukeed / tsm

TypeScript Module Loader
MIT License
1.18k stars 19 forks source link

feat: self-compile, add CLI #30

Closed ctjlewis closed 2 years ago

ctjlewis commented 2 years ago

Huge rewrite. Config file currently not working, not really a goal of mine here. The loader is now used to resolve imports in tsm-cli build output.

If you're not amenable to merging, I will ship/maintain this fork independently. Just wanted to send the PR in.

lukeed commented 2 years ago

No, but thanks. It’s a whole repo PR and not even sure what’s actually different in the source. Looks like just refactoring the build step for fun. If there are individual fixes or features you’d like to add, please open an issue to begin the process. I believe we briefly talked about this build-refactor & I didn’t see a point to the added complexity of self-compiling except for cool/style points

ctjlewis commented 2 years ago

Well, it uses the loader to rewrite import specifiers in emitted esbuild output for one, so we can get node dist/*.js to work for any arbitrary tsm-cli build output in 6ms. This is one of two compilers I know that can do this and I wrote both of them (the other one sprung out of Jared Palmer's tsdx, which was another good piece of software). There's also tons of debug logging added and room for more, plus reorganization. I also kneecapped a ton of stuff to prioritize ESM output, CJS support was removed entirely.

It's cool. I've worked toward this specific thing for a few years now and your work on the loader blew the whole thing open. The other working proof-of-concept I had took two orders of magnitude longer to compile and single-digit multiple in terms of SLOC. Your work here was really important.

I wish you'd stop saying it's for cool/style points, though. The point of having the compiler build itself is the natural test coverage, and it scales automatically with the logical complexity and dependency graph of the compiler. I'm shocked that isn't very obvious. It's pretty normal to have compilers self-host and most of Rollup's holes came from the fact that it didn't do that, same with tsdx.

ctjlewis commented 2 years ago

This wasn't ready to merge btw, it's full of comments etc., but if you want to review the changes at some point feel free. I'm going to be using this on a daily basis either way. (Edit: There's also massive bugs I hadn't caught yet and weren't caught by the tests! So it's 100% not ready to merge and would've been disastrous, meant to send as draft.)

In meantime though, shipped at @tsmodule/tsm, would welcome contributions.