isaacs/tshy

Support for project references

Closed this issue · 10 comments

fubhy commented

Is it currently possible to set up tshy in a monorepo and leverage projects references (with composite and incremental builds)? If not, is that sth. you have planned?

isaacs commented

I use tshy in a monorepo, but not at the root level. I just have each of the packages in the monorepo do their own tshy builds (so I guess it's not "using tshy in a monorepo" but more like "have a monorepo containing a bunch of packages that use tshy").

I'm not sure if it's possible to make it compatible with composite/incremental builds. I haven't looked too much into that, since it seemed to impose a lot of complexity on the project structure. Since tshy works by doing two complete builds into a fresh temp outDir each time, I imagine that it'd be tricky to get it to work with incremental builds? I suppose we could use a separate outDir for each dialect, and keep them around between builds or something?

How would you like it to work?

isaacs commented

Ok, so, leaving aside project references, and just looking at incremental/composite.

"composite": true seems to pretty much Just Work (assuming that you comply with the caveats/restrictions that it imposes (all files being listed, declaration being true, etc), but tshy defaults that all to be the case anyway.

"incremental": true works, but... uselessly. Because tshy builds in a temp dir and then deletes it, it's always throwing away the *.tsbuildinfo file, which means it's starting from zero every time.

I think what it ought to do is detect incremental: true in the config, and if so, do not delete the .tshy-build-tmp folder. It can still delete it if it's not in incremental mode, since in that case, there's no benefit to keeping multiple copies of the built artifacts.

fubhy commented

Hey. Sorry I'm neck deep in some major refactorings atm. and got zero head space right now to ponder this :-). I'll report back here in a few days when I'm done with this game of whack-a-mole! Sorry for not being responsive.

isaacs commented

Hm, the caveat here would be that if you set "incremental": true, then tshy won't delete an output file if it is removed from src. (I suppose it could just removed files explicitly, but that's kind of a pain.)

isaacs commented

@fubhy No worries! I just like to dump thoughts on issues stream of consciousness style while working on it, or else I lose my place and forget what I was doing when I come back to it. Feel free to ignore or weigh in asynchronously whenever you like, or never, as you see fit :)

isaacs commented

Incremental composite builds seem worthwhile even if you aren't using project references, and can speed up build times, so why not. Just need to keep the .tshy-build-tmp folder around. (Might want to rename it to .tshy-build, since it's not tmp if you use incremental building?)

I think maybe that'll make it just work with project references? But I'm not sure.

@fubhy I'll land #29 and leave this open, you can weigh in whenever you get dug out of your refactor hole, or someone else can come along and verify that it works for them, or maybe someday I'll actually use project references and verify it for myself :)

isaacs commented

Closing to get this off my todo list, but happy to reopen of course if there's more to be done here :)

cefn commented

In our repo, project references seem to be straight-up broken with tshy. Builds fail in exactly the same way as if you just deleted the references member altogether from your tsconfig.

When I run pnpm exec tsc --build in one of our monorepo's modules it generates a dist output as expected with no errors. This relies on a fragment in the module's tsconfig which resolves the tsconfig of a sibling module like...

  "references": [
    {
      "path": "../common"
    }
  ]

If I delete this references member from the importing module's tsconfig,json, it can't make sense of the multiple tsconfig scopes and I get an error from pnpm exec tsc --build when my package tries to import its sibling package like...

src/index.ts:7:8 - error TS6059: File '<REDACTED>/web-starter/packages/common/src/index.ts' is not under 'rootDir'

If I leave the correct references config in place (which normally makes tsc work fine), then execute pnpm exec tshy with a config as below, it reports exactly the same error as when I'd deleted the references field and ran tsc without it...

  "tshy": {
    "project": "./tsconfig.json",
    "exports": {
      "./package.json": "./package.json",
      ".": "./src/index.ts"
    },
    "exclude": [
      "test/**",
      "src/**/*.test.ts"
    ]
  }

You shouldn't need the "project": "tsconfig.json", since that's the default value anyway.

What happens if you do this? pnpm tsc -p .tshy/esm.json

What else is in tsconfig.json?

Actually, this should be a new issue. Please feel free to reference this, and answer those questions in a new issue. If we re-open, then closing it again from another commit makes the history really confusing and weird.