Skip to content
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

Feature request: Support multiple tsconfig.json files #16

Closed
jonaskello opened this issue Jan 27, 2018 · 6 comments
Closed

Feature request: Support multiple tsconfig.json files #16

jonaskello opened this issue Jan 27, 2018 · 6 comments

Comments

@jonaskello
Copy link

jonaskello commented Jan 27, 2018

My application is a monorepo with multiple packages where each package have it's own tsconfig.json. I would like to restart my server on a change to any of the packages. So for example I want to to this:

tsc-watch -p ./packages/foo-server -p ./packages/foo-utils --onSuccess 'node ./packages/foo-server/lib/server.js' -

So the request is to support multiple instances of the -p. The regular tsc --watch only supports one instance.

@jonaskello
Copy link
Author

jonaskello commented Jan 27, 2018

If -p would also support globbing it would even simpler to watch all packages in a monorepo:

tsc-watch -p ./packages/*/tsconfig.json

There is a related issue in the typescript repo here.

@gilamran
Copy link
Owner

@jonaskello tsc-watch is using the installed typescript on your project, it is only forcing watch mode.
Once typescript will be able to use more than one tsconfig.json tsc-watch will support it too.

If you are using multiple tsconfig.json files, you are probably separating client from server.
I have another repo. that demonstrate just that: fullstack-typescript

image

You can see how I managed 2 tsconfig.json files, including shared code.
If you change a client code, only the client code will be recompiled, and refreshed.
If you change the server code, only the server will be recompiled and restarted.
If you change the shared code, both will.

Hope this help.

@jonaskello
Copy link
Author

jonaskello commented Jan 27, 2018

@gilamran Yes, I understand how it works, I have read the source :-).

I previously also used an approach similar to your fullstack example. However lately I realised the advantages of yarn workspace so in my latest project I'm using a proper monorepo with multiple packages instead. See here for an example how that is setup. There are many advantages to have real packages for shared code instead of just separate folders under ./src. In this case each package is compiled into it's own lib folder and with yarn workspace (or lerna) they can easily reference each other using regular node_modules resolution. You can also publish some of the packages to be used in other projects.

I think tsc-watch could actually support muliple -p quite easily, it is just a matter of spawning multiple tsc processes and then listening on output from all of them and restarting the server if any of them re-compiles. So the only code that would need to change is the one that spawns the tsc process. All listener code would be the same. I could make PR for this if you want to see how it would work.

@gilamran
Copy link
Owner

@jonaskello Thanks for the explanation.
As typescript itself is going forward with this feature, I don't want to do a double work on that.
Once they implement it, tsc-watch will have that automatically.
I would have considered this if they didn't plan on doing it...

@jonaskello
Copy link
Author

If the typescript team will add this that would be really nice. But I'm not sure they will? Do you have a reference to an official statement on that?

I've been following this issue which is referenced by the issue I mentioned previously. However they have been discussing since 2015 and I have not seen any concrete statements that they will do anything as of yet.

@jonaskello
Copy link
Author

I went with a mix of webpack and nodemon for my monorepo. I guess multiple -p is not a perfect solution either because for the initial compilation a dependency order would have to be established and that is not so simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants