microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.02k stars 12.49k forks source link

Microsoft.TypeScript.MSBuild, need to find a way to delay execution of tsc #57695

Closed ViRuSTriNiTy closed 8 months ago

ViRuSTriNiTy commented 8 months ago

Acknowledgement

Comment

Hi there,

I am using Microsoft.TypeScript.MSBuild to compile .ts files to .js files in my project. But additionally, I use NTypewriter.SourceGenerator to generate .ts files from C# code. These .ts files should be compiled to .js in one run, meaning I don't want to have to build twice to get a fresh .js.

When using diagnostic verbosity on building the project, I can see that NTypewriter.SourceGenerator is executed when the CoreCompile target executes, the same seems to apply to Microsoft.TypeScript.MSBuild. So, both source generator and tsc are executed at the same time and since tsc is somewhat slower, it cannot catch the output of the source generator in time.

To somehow get it working, I thought about changing the execution order of the tasks by adding

<Target Name="EnforceTypeScriptCompileAfterSourceGenerators" BeforeTargets="PreComputeCompileTypeScriptWithTSConfig" DependsOnTargets="CoreCompile" />

to the project. This seems to work fine.

Is this the right approach or can I solve the issue in another / better way?

So lonG

RyanCavanaugh commented 8 months ago

This is really more of an MSBuild question and we're not experts on that. If it works, seems good, though?

typescript-bot commented 8 months ago

This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

ViRuSTriNiTy commented 1 month ago

Side note:

Unfortunately, using the target configuration as described in the initial post breaks resx functionality. For now, the only solution is to either build twice to get fresh js files or move the resources to a separate project. In case NuGet packages are used, the separate project can then be automatically included, see https://josef.codes/dotnet-pack-include-referenced-projects.