-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
No way to use composite project where outDir is determined by build tool #37378
Comments
when doing |
Yes, I can see that. The only way I think I should take @DanielRosenwasser up on a suggestion that we have a brief design discussion. After studying this problem for a week, it seems that Bazel's output directory is simply incompatible with typescript project references and one of them needs to change. Do you have a design meeting this week? Thanks! |
I hoped that
is there any other way to avoid this checking? |
@RyanCavanaugh thanks for the discussion today. I noted that you said TS repo itself is affected by this issue, requiring that you have multiple tsconfig files to express the difference between two different build options. I have another proposal based on some more experimentation. Take this scenario. We've already compiled lib and now want to compile app.
As we know with TS today, this fails because the reference goes to the Let's say the semantics for references were expanded (maybe under some new flag) so that This can work, but only if we also add a build step to copy the tsconfig file to the output directory - and we know that's complex because the paths need to be made relative to the new location. So instead, since there is no I could imagine that a reference to a tsbuildinfo file could be made to work in place of a reference to a tsconfig file? If so this seems simple and in my basic testing it works. |
#37509 shows the change to resolving reference paths that I'm currently using for prototyping. Along with a hack in Bazel to copy tsconfig into the outDir, this seems to work. |
@sheetalkamat FYI we shipped the new TS support for Bazel with a bunch of ugly caveats about this and related bugs What do you or Ryan think of the proposal to resolve reference paths into the outDir? |
c:: @RyanCavanaugh @DanielRosenwasser |
As that last reference points out, this problem has gotten worse. Bazel has more potential values for |
Daniel and I chatted about this for a while and I think this is sensible and very implementable. Basically just add a new flag (name TBD) where we compute the outDir of a referenced project as follows:
This means that if you had
Then if Just to confirm: Would that solve your problem? |
I think the key is that this flag only really makes sense when the entire source-tree is mirrored by a corresponding output tree. The above output format would work, and maybe would more specifically look like this for Bazel and similar systems:
But it would not work for the following layout:
So that's why we're curious whether it fits the bill for you. |
Thanks for looking! That's very close. Composite projects is the TS-idiomatic way to express one compilation unit which depends on the typings from another, and I have some examples which do that. However under Bazel it's not required to do it this way. Many users have a single tsconfig.json file at the root, and then configure bazel with a
so I think it would be better to design this such that having a (If it's useful to you, a bunch of samples running @DanielRosenwasser you're correct, the first layout is what bazel uses (entire source tree structure is mirrored in each output folder). GN does the same, as one example. The second structure you describe isn't interesting from a bazel perspective. |
Okay, so I think the key to thinking about this is this: TypeScript project references roughly gives you two things
You want to be able to do (2) without setting up project references as well. |
Yes that's a good summary, Bazel can use a different mechanism than project references to accomplish 1, but our workarounds for 2 are not scaling to the number of potential outdirs. I should note, another potential fix for our issue would be to allow the |
@RyanCavanaugh could it be as simple as:
|
@RyanCavanaugh @DanielRosenwasser ping on this, should I be doing more to push design along? do you want a clumsy PR for it? |
@alexeagle we'll talk about it again this week, I think your suggestion is pretty sound. A PR would be nice as an anchoring point if you're willing |
Note, the proposal would also solve #22208 since I'll try to work up a PR, any help would be appreciated to get something closer to landable :) |
Proof of concept for resolving microsoft#37378 Under the new proposed `compilerOptions.resolveFromOutDir` boolean, module resolution is attempted relative to the output folder. This is analogous to loading from the rootDirs, however it allows compilation where the output directory is configured on the command line rather than in the tsconfig.json. See the attached issue for context. TODO: - figure out what tests to add - reason about whether this interacts correctly with other related module resolution conditional logic - verify this works in some Bazel projects where the problem is observed
Proof of concept for resolving microsoft#37378 Under the new proposed `compilerOptions.resolveFromOutDir` boolean, module resolution is attempted relative to the output folder. This is analogous to loading from the rootDirs, however it allows compilation where the output directory is configured on the command line rather than in the tsconfig.json. See the attached issue for context. TODO: - figure out what tests to add - reason about whether this interacts correctly with other related module resolution conditional logic - verify this works in some Bazel projects where the problem is observed
@RyanCavanaugh the PR is up. I think if you accept this issue that will clue the bot into putting nicer labels on it :) |
@alexeagle I think @RyanCavanaugh suggested changing outDir computation for the referenced project instead of module resolution. #48190 does changes to module resolution which is not what the suggestion was. |
Project References is just one use case that the PR fixes. As I explained above most Bazel users are simply compiling a project with #37378 (comment) is where I think @RyanCavanaugh agreed to the change in the module resolver. |
Yeah I think the idea of resolving modules relative to their outputs was what we agreed to in #48042. |
But then that doesnt solve project reference issue... how do you know if the d.ts file you got is from project reference? there is definitely some confusion here since i was under impression that we want outDir for the project reference instead as i discussed this with @RyanCavanaugh this morning. |
Could you be more specific what problem this introduces for |
Ping! Some large Bazel users are now on a fork of TypeScript to get this. |
Appologies that this slipped through other notifications.. In editors, when say app project referecnes output d.ts of shared project through module resolution or any other way, we use its source file instead so we can walk through edits without having to save it.. This functionality might be affected with this change since we dont know resolved module is from project reference. |
Where is the fork code? |
Update: we now have better Bazel rules which don't require this at all. They copy all the sources and the node_modules tree to the bazel-out folder, then run |
@alexeagle when attempting to use a "references" key in a tsconfig.json using Aspect's rules_ts, I'm observing the error:
I'm noting a lack of tsconfig.json's with a references key in the examples with this rules_ts codesearch. Is it possible to use project references with rules_ts? Is there a workaround that hasn't made it into the examples yet? |
@rc-glean it's probably better to file that on the rules_ts repo than on TypeScript, I don't think there's a bug in this repo edit: I see aspect-build/rules_ts#163 now - when you cross-post an issue to more than one repo, it's good practice to link to the other one :) |
In #37257 I discussed one way to host TS project references under Bazel, where each build step gets only
.d.ts
andtsconfig.json
files from the referenced projects. This is broken because TS module resolution fails to locate the.d.ts
files in theiroutDir
.In this issue, let's try a different approach for Bazel, to satisfy current TS module resolution, each build step should get the
.ts
sources of its referenced projects, and the.tsbuildinfo
output as well.Bazel is picky about the setting of
--outDir
, because it supports cross-compiled builds in distinct output locations. For example if you're on a Mac and building for local platform, the outDir is<workspace root>/bazel-out/darwin-fastbuild/bin
. But if you're on a Mac and building for a docker image, you need native binaries to be for the target platform so outDir is<workspace root>/bazel-out/k8-fastbuild/bin
and if you want binaries with debug information it's<workspace root>/bazel-out/k8-dbg/bin
.Since the outDir is platform-specific, we don't want to check in a config file that hard-codes it. So we prefer to always have Bazel pass the
--outDir
option on the command-line totsc
, rather than include it in the tsconfig files.Now we come to the problem. TypeScript "composite" setting enables up-to-dateness checking in
tsc
. With this input structure, and trying totsc -p b
we get
b/b.ts(1,17): error TS6305: Output file '/private/var/tmp/_bazel_alx/df60115ea7f2a64e10fb4aa64b7d827f/sandbox/darwin-sandbox/54/execroot/ts_composite/a/a.d.ts' has not been built from source file '/private/var/tmp/_bazel_alx/df60115ea7f2a64e10fb4aa64b7d827f/sandbox/darwin-sandbox/54/execroot/ts_composite/a/a.ts'.
This indicates that TS is looking for
a.d.ts
next toa.ts
. If we hard-code the platform-dependent outDir into a/tsconfig.json like I've done herehttps://github.com/alexeagle/ts_composite/pull/5 it solves this problem, but not in a way we can ship.
Note that the compilation of a/tsconfig.json produces a .tsbuildinfo file with a correct "outDir" (based on the --outDir flag that was passed to compilation of
a
So it seems like the behavior for compiling
b
is to read theoutDir
setting from a/tsconfig.json rather than trust theoptions.outDir
reflected in the .tsbuildinfo output.The text was updated successfully, but these errors were encountered: