-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve how Typescript compiles across the monorepo #1085
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
54b8f74
to
e1d06f3
Compare
workspaces:watch: | ||
desc: Watch source files and build as they change | ||
deps: [workspaces:watch:typescript] | ||
cmds: | ||
- echo "Watching ended" | ||
|
||
workspaces:watch:typescript: | ||
desc: Watch all the source of Typescripts workspaces and automatically recompile (with a single watcher) | ||
cmds: | ||
- yarn tsc -b --watch | ||
|
||
workspaces:watch:wasm: | ||
desc: Watch the source of WASM targets and automatically recompile | ||
cmds: | ||
- yarn wsrun --parallel --exclude-missing ws:watch-wasm | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@notnmeyer this is the best way I could imagine doing watchers with Taskfile. Do you see any problems with this / know of a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, been out. this looks fine to me though. i dont think its a better solution in this case, but taskfile also supports fingerprinting source files and watching a task too,
https://github.com/go-task/task/blob/master/docs/usage.md#watch-tasks
https://github.com/go-task/task/blob/master/docs/usage.md#by-fingerprinting-locally-generated-files-and-their-sources
I've added watching of all the assets, except for Cargo doesn't have any watching abilities, and while the However, that would touch the production code path for spawning |
// We provide a mock for the webpack compiler, so we don't have to reimplement all the watching and can | ||
// leverage the existing plugin. | ||
|
||
let beforeCompileHook; | ||
let thisCompilationHook; | ||
|
||
const compiler = { | ||
options: { | ||
mode: 'development', | ||
}, | ||
|
||
watchMode: true, | ||
|
||
hooks: { | ||
beforeCompile: { | ||
tapPromise(pluginName, hook) { | ||
beforeCompileHook = hook; | ||
}, | ||
}, | ||
thisCompilation: { | ||
tap(pluginName, hook) { | ||
thisCompilationHook = hook; | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
let wasmPack = createWasmPackPlugin(); | ||
|
||
wasmPack.apply(compiler); | ||
|
||
beforeCompileHook().catch((err) => { | ||
throw err; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How hacky is this? Pretty hacky! But given how incredibly small the integration between the wasm-pack watcher and webpack is, there being no alternatives and the complexity of forking / writing it ourselves being more complicated than this, I say it's worth it (for now, at least).
…to local workspace packages
…pescript packages efficiently
e1d06f3
to
53c4d4f
Compare
Seems reasonable - watching on optic-engine-native would be nice, but this solves a large painpoint with the current TS compilations |
Developed against this for two days, all seems to working smoothly, passing CI as well. Lets get this out to develop! |
@LouManglass these changes are definitely an added risk for the next release train. Perhaps we should get a side channel build out there to verify it's all functional? |
Yeah, I'll check that today. Better to find out sooner. |
Why
Optic is structured as a monorepo, with multiple interdependent packages individually published and built in one repo. However, making changes across Typescript packages has been very painful so far, basically sourcing from every package being compiled in isolation by a separate Typescript instance.
Generically, when working on package A, that depends on B, which depends on C, making a change in one of the dependencies doesn't automatically propagate up to package A: you have to manually make sure everything is compiled in the right order.
Often, to make sure things are done correctly, you end up rebuilding everything, which is super slow. And even then you have to reload the VSC window, or restart the Typescript language server.
What
In essence, we're connecting the isolated packages and making the Typescript compiler aware of dependencies living locally and are compilable as well.
It should enable :
It manages to do this through:
@useoptic/*
, while allowing the compiler to still find the local versions it could compile.It adds a task:
workspaces:watch
, to watch the source of all Typescript and WASM targets and recompile them automatically.Additional todos:
workspaces:build
(possibly more efficient): not necessary. As all Typescript packages are now connected, even building them one by one causes incremental builds, only recompiling what's necessary.Validation