-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
tsc --build / Project References Feedback & Discussion #25600
Comments
A couple of things:
|
@timfish thanks! Re 1 - PR up at #25610. For the other issue, can you sketch out the files you have? The order is supposed to be a simple topological sort that should always yield a correct ordering. I'll try to repro locally in the meantime based on what you've described Edit: Not sure how to repro - I changed the TypeScript repo's |
@RyanCavanaugh Were you all able to land the cross-project rename for the RC? |
@EisenbergEffect we have "upstream" renames (renaming a usage in |
Gotcha. Any ideas is you'll be able to get the downstream rename in for the final release? or have you already determined that it needs to push out to 3.1 or beyond? |
It looks like we can probably get downstream renames for loaded projects in by 3.0 final. Detecting which other projects on your computer need to be loaded to do an "exhaustive downstream rename" is looking dicey - we haven't found any mechanisms that would let us short-circuit that work when the symbol being renamed is exported from the current file. |
I am using the API to build Typescript projects, including createWatchProgram and createWatchCompilerHost.
|
If you're hosting the compiler API, you don't need to do anything new for project references; everything should work as-is. If you want to take advantage of the new To migrate to using project references in your code itself, updating your |
Thanks @RyanCavanaugh Are there any examples for "createSolutionBuilder" and "timestamp API"? |
@RyanCavanaugh ref: Build order. I'll try to get a repo reproducing this although it won't be until next week. If I'm just adding all references to a root tsconfig, it should work out the dependency tree from that? |
Trying this out with the 3.0 RC.
I tried using this but for some reason "Go to Definition" didn't seem to work. I'm probably doing something wrong, but filed an issue with a minimal reproduction case here: #25662 Will this also handle "Find All References"? If not, is there any way that could be supported? |
Based on @RyanCavanaugh and @rosskevin's work to demonstrate Project References within a Lerna-based monorepo123, I've made another not-for-merging Pull Request which uses both Yarn workspaces and Babel 7: RyanCavanaugh/learn-a#4 Hopefully this example helps others learn! I've been working on a Lerna-based monorepo similar to this, and now (I think) I have a better idea of how to configure Project References with it. — |
I was hoping to get some advice on how to handle path resolutions. My directory currently looks something like this:
Im struggling to reference the For example, the following doesn't work: // server/src/index.ts
import { mySharedFunc } from "../../shared/src"
// This doesn't work either. "shared" is still shared after compilation
import { mySharedFunc } from "shared" Because the project compiles down to:
As you can see, it is invalid to reference the src dir as it doesn't exist after compilation. Should I restructure my repo somehow? Is it possible to get my path aliasing to work? My struggles appear to be related to #25682 |
I've updated my folder structure to have |
@RyanCavanaugh any luck with my code? #3469 (comment) |
I assumed that with I found this out while doing a normal build ( Is this expected behaviour? It seems counter-intuitive to me. |
I found myself using the same technique as the references system in our temporary custom incremental build system (comparing d.ts files) to decide what to rebuild in a non incremental scenario. However, after finding strange results, I've discovered that the typescript compiler (3.0-RC) do NOT generate deterministically d.ts files. ex: I think you may have found yourselves those issues and wonder if that's a know/accepted limitation between runs or if I should open an issue (have not found an existing one yet). |
Trying it out on the codebase I'm working on, I ran into a lot of The consequence is that an Edit: In retrospect this is clearly enough a bug to warrant its own issue, so I made #25864. |
I just tested TS 3 RC project references in a typical npm package setup with included tests. The tests were set up as a TS project referencing the implementation TS project. I surprisingly found that project references do not adhere to the outDir compilerOption of referenced or referencing projects, and that the relative paths for module imports in the compiled referencing project's JS files therefore are wrong; paths point to the TS folder, not the compiled output folder. A somewhat simplified view of my PoC:
Expected behavior:
I put up a small repository to demonstrate the problem: UPDATE: Separate issue created: #26036 |
Is |
@RyanCavanaugh This project thing looks really cool so I decided to give it a try. It hasn't been going so well for me so I thought I'd share my experiences and the code-base in case it's helpful for you guys. Basically, I have the following folders in my project.
My previous set-up (TypeScript v2.x) was to have a tsconfig.json in the root with the most "forgiving" settings and that would give my IDE all the intellisense etc and cross project renames. I then had a compile.json in back-end (which was a tsconfig file in disguise), and another compile.json in the front-end (same concept). The reason for these files is that I wanted to only compile front-end code (for webpack) or back-end code (for ts-node) separately from the rest. Needless to say, they wouldn't have any issues picking up the code that I referenced in the shared folder as the paths were all relative etc. This all worked perfectly fine for my work flow and I've been super happy with it (except about a year and a half ago the Angular CLI didn't like it at all, but I'm doing webpack manually and haven't retried since...) So, I upgraded TypeScript to the The ts-node for my back-end only works if I compile the shared folder and emit to disk, something that I'd rather not have to do because my back-end compiles down to ES6 and my front-end down to ES5. Although I guess it wouldn't be so bad if it emitted declarations only? Anyway, I've checked it all in, would you mind taking a look and seeing what you think? I wouldn't mind if you wanted to use the repo (or part of it) as some kind of example project. Thanks! Here's the link: https://github.com/SMH110/Pizza-website/tree/TS_Projects The previous working setup not using the new projects functionality is at this commit: SMH110/Pizza-website@9548bdd |
Also something that we discovered is that we can't exclude test files from referenced projects but they contribute a large amount of time to compilation time. |
That you can do, by referencing the tsconfig directly: // project-a/tsconfig.build.json
{
"references": [{
"path": "../project-b/tsconfig.build.json"
}]
} Also I think |
Update: We just needed to provide the custom matchers in |
Here are our thoughts when we used the project references at Shopify: We think a different approach might work better for the type checking in vscode. You folks know the TS compiler inside out, and you have enough context to tell if this idea is doable. What if we keep the |
This is working as intended and is documented quite prominently: https://www.typescriptlang.org/tsconfig#exclude
Differently said: |
Thanks for the feedback!
It sounds like you're talking about in the editor? You can turn on the
This is more or less what composite projects / project references do already, especially under |
Thanks for your quick feedback.
True, but this behaviour easily leads to misconfiguration, incorrect, and unintended results. It would make our jobs much easier to detect the root cause by the compiler.
That's possible, we recently started looking into our configs. Is there a way for us to warm up the TS Server (maybe generate the |
|
Thanks for the reply, Is the expectation to run the TSC in a watch mode to compile the referenced projects separately? I don't know how efficient that would be. It seems none of the available options works well for our project. |
I'm using a npm workspace setup, where my local workspaces are symlinked to the root node_modules. An interesting behavior I notice when using project reference in this setup is tsc doesn't seem to find the {
"references": [
{'path': '../path/to/packageA/tsconfig.json'}
]
} // importing a JS file
import {A} from '@my-scope/packageA/src/SomeJSModule'
// complains: can't not find the declaration file for ..., you can install '@types/my_scope_packageA' However, the error goes away if I import this js file using a relative path. The workaround I come up with is just using path to map the absolute imports to relative:
|
@chbdetta that would seem to indicate something isn't set up right with the symlinks. In general for a monorepo workspace, |
Also you can use |
@RyanCavanaugh @sheetalkamat Here's a reproducing repo: https://github.com/chbdetta/ts-project-reference-playground |
@chbdetta I don't get any errors running that |
@RyanCavanaugh I left a @ts-expect-error on the error line |
@chbdetta issue there is that js files discovered with node_modules differ from how ts are treated. The js file take into account |
@sheetalkamat does increasing |
Hey all! I tried searching through GitHub issues to see if there's a reason this wouldn't work or hasn't been done, but I've got a project with 8 libs and 3 apps using project references. It follows this basic structure:
There's a little more complexity, but that's the basic idea. However, I have a ton of repetition between all my {
"extends": ["../../../tsconfig.base.json"],
"references": [
{
"path": "../../libs/lib-1"
},
{
"path": "../../libs/lib-2"
},
// ...
]
} It would be super nice if we could use a wildcard/glob in situations like this, where I could simply have all of my
It also makes it way easier to add new libs/apps in the future to the monorepo. Also, I did try this and it does indeed not work:
I'm happy to try and write a PR if people think this is possible and useful! Also happy to make a separate issue for this specifically, but this seemed like a fairly active ticket and the right place to start the discussion. Thanks! |
@eabrouwer3 yes, a separate issue on that would be great. Thanks! |
#56279 in case anyone's interested. |
|
Run |
I agree with @raihle - I'm not sure how it is useful. On the other hand, cleaning up stale files inside a CI pipeline with cached build artifacts could speed up the pipeline without worrying about leftovers. Perhaps something like EDIT:
|
We're really not interested in breaking into jail with a feature that can delete files that aren't ones we would have normally overwritten anyway. The last thing I want to deal with is "tsc deleted all my source code because I misconfigured it, why would you even ship this??" reports. |
Thanks for taking the time to share your thoughts, @RyanCavanaugh! It's truly appreciated! Personally, I can follow the ' (I don't expect a response - I am OK with it.) |
I'm working on improving TS config for Vite templates, and I've come to the conclusion that using project references with
|
Continuation of #3469 "Medium-sized Projects" which has grown too large for GitHub to display comfortably
Please use this thread for feedback, general discussion, questions, or requests for help / "is this a bug" discussions.
Active bugs / PRs in this area:
Possible next steps:
tsc --build
#25562 Terse mode output fortsc -b
tsc -b
Other interesting links:
--outFile
learn-a
repo usingyarn
workspaces!The text was updated successfully, but these errors were encountered: