-
-
Notifications
You must be signed in to change notification settings - Fork 40
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
About true-composite projects support #93
Comments
I have just experienced a bundling failure of a composite project. There are multiple packages in my monorepo:
It all worked magically before without It started failing after adding I have found two workarounds for composite projects problem:
Please let me know if I can help to solve this problem in any way. |
@igorpupkinable sorry I know it has been a while since your message, but did you find a workaround? Do you still have access to the project and can share a simple reproduction? |
The comment's content has been migrated to the topic message for visibility. Initially I posted it as a message so people who is subscribed to notifications will get it instead of "silence" while editing a message. |
At this point and based on my thoughts above it feels like it is not an "issue" but a discussion instead, so I'm converting it. Once again, feel free to share your opinion/thoughts. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Just a note about what this issue means exactly (at least from my current understanding) and some thoughts.
First of all, having this issue opened doesn't mean that the tool doesn't support composite projects. Please keep reading (see "workaround" section below).
Technical details
About the issue
If you have a composite project, it means that most likely you have some sort of a "solution" config that references other projects that might reference other projects and so on. The tool doesn't work with projects but with files instead, so it doesn't care about projects and their relationship. It doesn't even load files based on
files
,include
andexclude
options in tsconfig (as it is mainly a directive for tsc cli). But what it does care about is the compiler options. If your compiler options are consistent across projects within a composite projects, then you should be fine even if you havecomposite: true
in there (yeah you might see a warning but the tool can just work well). The issue started when your "default" tsconfig doesn't have any compiler options but just references to other projects (for example like this). In this case the tool will not load any compiler options your project is using to get compiled and you might experience "strange" behavior like compilation errors while runningtsc -b
"just works fine".Even if your compiler options are a touch different, it still might work well, it really depends on many factors and actual differences. E.g. in you have differences in
target
option it shouldn't affect anything, but differentstripInternal
can and probably will.Compiler API for composite projects
Another note I'd like to cover here is another reason why it still not implemented (and probably cannot be? feel free to share your thoughts). If you want to compile a composite project (in a build mode), the compiler provides different set of API. Instead of using
ts.createProgram
you have to usets.createSolutionBuilder
API. This API looks like a high-level API to perform compilation in a similar waytsc
does, but it doesn't provide you anything about the program it is going to build. It is a high-level API to perform actions like "compile project", "clean project", "build references" and so on. The API doesn't provide a program instance (and a type checker) for each sub-project unless they are "invalidated". In fact, it might not even write any output for a project (if it decides that nothing has changed since "last" build).Another question/issue that needs to be solved here is detecting where the input file belongs to (which sub-project) and compile only projects its project depends on. And probably it will cause other questions and I don't see yet.
P.S.: If there are other cases that aren't aligned with the explanation above - feel free to share them here. I'll be happy to update this post to include additional cases.
Workaround
The best and simplest solution I can suggest is to create a separate tsconfig file with all your compiler options and pass them to the tool via either
--project
CLI option orcompilationOptions.preferredConfigPath
option in the config file (depends on what you use). To avoid duplication, you can then extend other tsconfig files with that newly created "options" tsconfig so you won't repeat the same options again and again across your project (I hope you're doing this already anyway).It is super simple and requires almost no effort (this is one of the main reasons why there is no support for this feature yet..
About creating tsconfig for the tool
Here is the list of tips you can apply that might make your life easier.
If the compiler options across projects aren't the same, the safest options would be to includes the most common options in that new tsconfig and probably use it for the tool only. If these different options are conflicting (e.g. different
lib
options or differentstripInternal
value), the best solution would be to compile different projects via build mode prior bundling typings, and then tell the tool to bundle typings with input files beingd.ts
outputs from previous step. In this case you can keep different compiler options while building a project and bundle typings (and it should work somewhat quicker as the tool doesn't need to compile the full version of the project).These options shouldn't necessary include all of the options, but these that you do care in terms of declaration generation and ones that your project can be compiled with. If you're running the tool against
d.ts
files only, then probably almost any tsconfig would work as no compiler options will affect output, it just should be compile-able. But this is advanced and make sure you understand what you're doing - the safer option is to include compiler options you use to compile the project.Conclusion
I admit that it might be possible to write a ton of code to make it work with true-composite projects, but I just cannot justify it comparing to creating a new tsconfig file for dts bundling.
If you have any ideas/thoughts on this topic, feel free to share it here. If you have issues that you're experiencing with bundling composite projects - feel free to ping me and I will try to assist you.
The text was updated successfully, but these errors were encountered: