1

To programmatically compile/build a project references, I use the ts.createSolutionBuilder API.

Problem is that in my use case I don't have the tsconfig.json file written in the filesystem per package. Instead, the tsconfig.json is calculated based on other criteria.

It's possible to pass the compiler options to this method, but it's only the tsconfig.json of the root that includes all the project references data. How do I pass the compiler-options per project/package?

David
  • 2,528
  • 1
  • 23
  • 29

1 Answers1

0

I'm kinda surprised how lacking the docs on this are in typescript (well at 4.3.x at the moment of writing), but it seems it's quite simple - the argument that provides the paths can accept config links.

Here's my code:

// this selects directories to use
const packages = getTSDirectoriesFromGlobs(process.cwd(), opts._, configName);

// so I basically add the tsconfig names to my paths
const rootnames = packages.map(x => join(x, configName || "tsconfig.json"));

// and then pass that as the second argument
const solution = createSolutionBuilder(nodeSystem, rootnames, {});

// and then...
const exitCode = solution.build();

Works like a charm. :)

Actually I'll add a couple links to the code above in my PR to Tranform Hub where I introduced the link:

I was really surprised to see that it did improve the build times that much - the repo there is a big monorepo so it's quite interesting to see how well this works.

Anyway I hope this helps. :)

Michał Karpacki
  • 2,588
  • 21
  • 34
  • Yes, it's really hard to find information about programmatically compiling project-reference. What I was looking for is a way to pass the options programmatically. In the code pasted above, the `configName || "tsconfig.json"` is the filename on the filesystem. In my use-case I don't want this file on the filesystem. – David Apr 14 '22 at 15:01
  • Oh. I see... I think, but please check this in the docs, that the builder actually takes config as the last arguement, where the `{}` is. Take a look at the file in our repo and try to copy it. With ts completion it should show you the options there – Michał Karpacki Apr 14 '22 at 23:33