OK, I'll answer my own question with a summary of the other answers and some extra options.
After some thought I came to a realization. The question is - who and when runs tsc
to compile the LibraryA's Typescript to Javascript? Essentially there are just a few choices:
- The developer of LibraryA runs it and publishes the compiled result (somewhere);
- LibraryA is published in source form and compilation happens when installing the package to WebserverB;
- LibraryA is published in source form and building WebserverB also compiles the library.
Let's look at each in detail.
1. Publish compiled result
The question then is - where is the published result stored? It has to be somewhere where NPM can access it. As such, there are only a few choices again:
- npm registry (private, if you can afford it, public if you're OK with it). Drawback: well, you have to pay for it.
- A tarball on some server where you can get a URL to it. Drawback: You have to get a server to host these. And take care of said server.
- A new GIT repository. Not tarballed, because npm cannot untar from a git repository. Drawback: you now have two repositories for one project.
- The same git repository where LibraryA lives. In essence, you not only commit your TypeScript source files, but also the compiled result. Drawback: committing compilation artifacts is just wrong. And you're publishing your sources together with the compiled results. You don't need those in WebserverB.
- The same git repository where LibraryA lives, but in a separate, disconnected branch. Drawback: This gets confusing. How many repositories have you seen with two disconnected main branches?
Still, despite the drawbacks, they're all serviceable options.
2. Compile upon install
The main drawback here is that this immediately puts a dependency on typescript on WebserverB. And not just a development-dependency but a full runtime dependency. This may be OK, but it's getting really weird. How do you plan on deploying WebserverB? Will that too run the compilation? I don't think this is the way to go. But it's possible. See H.B.
's answer for details.
3. Compile together with WebserverB
Well, if you plan only on using it in typescript projects, this might be OK. I'm not sure about installing it though. You'll need to modify your tsconfig.json
file to include node_modules/LibraryA
in the compilation. That's weird. And will your IDE be happy about this? All in all, this doesn't feel like a good idea either. It feels like fighting/abusing the system and that rarely ends well.
In the end, I think I'll go with the "commit compiled JS" approach. Because "just wrong" isn't a good argument. And since it's a private project, the extra published sources aren't much of an issue either. In fact, maybe they'll even help to debug.