I've been searching far and wide online for a solution to my problem, but unfortunately, I haven't come across anything useful yet. Essentially, I am in need of a tool or method that will allow me to kick off TypeScript file Watching/Compiling in multiple directories simultaneously.
Within my monorepo, I have various scoped NPM packages such as @test/one, @test/two, @test/three, and so on. My objective is to be able to watch and compile all these packages at once.
It seems that TypeScript does not directly support this functionality, and there doesn't appear to be any existing tools that can accomplish this task either. The closest solution I found was nodemon, which can watch multiple directories at the same time, but it lacks the ability to execute 'tsc' in every watched directory upon changes.
The most effective workaround I could come up with using nodemon looked like this, although it's not an ideal approach as it compiles all packages even if only one has changed:
npx nodemon --watch test-shared-api --watch test-shared-redux --watch test-shared-types -e js,ts,jsx,tsx --exec "npx tsc --build test-shared-api/tsconfig.json && npx tsc --build test-shared-types/tsconfig.json && npx tsc -build test-shared-redux/tsconfig.json"
Alternatively, utilizing concurrently in the package.json allows me to implement the following setup, which is a step closer to efficiency, but still leaves room for improvement:
"scripts": {
"ts-watch-shared-types": "tsc -p packages/@test-shared/test-shared-types/tsconfig.json -w",
"ts-watch-shared-api": "tsc -p packages/@test-shared/test-shared-api/tsconfig.json -w",
"ts-watch-shared-redux": "tsc -p packages/@test-shared/test-shared-redux/tsconfig.json -w",
"ts-shared-watch": "concurrently -k -n w: npm:ts-watch-shared-*"
},
Any suggestions or better solutions are greatly appreciated!