ALM/CI system: Azure DevOps.
Scanner command used: The commands are executed by the Azure DevOps plug-in.
Languages of the repository: The concern for this issue is TS (TypeScript).
Error observed: Cannot specify the directory to filter/search for tsconfig.json files.
Our project structure currently is as below.
C:/a/_work/1/s/Source - where everything resides.
C:/a/_work/1/s/Source/packages - where the NuGet packages are restored as part of our build pipelines.
C:/a/_work/1/s/Source/Websites - where we have the tsconfig.json files we would like to get analyzed.
Where the working directory is C:/a/_work/1/s/.
It turns out the the Javascript Analyzer scans the C:/a/_work/1/s/ directory for all tsconfig.json files, later on which it analyzes one by one.
This is a problem, as one of the packages we depend on, comes along with a few tsconfig.json files which are all unpacked to the C:/a/_work/1/s/Source/packages/package-name/ directory. We cannot influence the contents of this package, and these tsconfig.json files incorrectly refer other non-existing tsconfig.json files, which in turn bloats our pipelines with error messages. This is irrelevant from configuration in our csproj files where we define which content/contentFiles to exclude when referencing a package from our .NET projects, as they affect only the output assets, not the unpacked files of NuGet packages. So, even if we exclude the files from our projects, they are still part of the C:/a/_work/1/s/Source/packages/package-name directory.
Error mentioned above is ##[error]ERROR: Error: Cannot read file 'C:/a/_work/1/s/Source/packages/microsoft.aspnetcore.components.customelements/Shared.JS/tsconfig.json'.; No inputs were found in config file 'C:\a\_work\1\s\Source\packages\microsoft.aspnetcore.components.customelements\9.0.4\content\js\tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.
I realize the SonarCloudPrepare@3 has an extra property that we can configure via the extraProperties input, with key sonar.typescript.tsconfigPaths.
We tried setting this property to explicitly include the tsconfig.json files we would like to get analyzed, as it looks like there is no way to explicitly exclude a file or two.
The issue is that, no matter what “wildcard pattern” we tried, and I will list the patterns we tried below in the end of this post, we always get the same response, and the SonarCloud plug-ins still fallback to the default search pattern, ignoring our configuration with the extraProperties input.
We would like to ideally utilize a wildcard pattern, as we have more than one tsconfig.json file we would like to analyze.
We also have more than one directory where we would like to specify in the sonar.typescript.tsconfigPaths property, separated by , (comma) as specified in the documentation, however, that is so far irrelevant, as things don’t work even with a single path.
Without the sonar.typescript.tsconfigPaths property specified, we get the following resolution when the tsconfig.json files are matched:
INFO: Sensor JavaScript/TypeScript analysis [javascript]
INFO: Found 8 tsconfig.json file(s): [C:\a\_work\1\s\Source\other\tsconfig.json, C:\a\_work\1\s\Source\others\Scripts\release\tsconfig.json, C:\a\_work\1\s\Source\Websites\x\src\x\tsconfig.json, C:\a\_work\1\s\Source\Websites\y\src\y\tsconfig.json, C:\a\_work\1\s\Source\packages\microsoft.aspnetcore.components.customelements\9.0.4\content\js\tsconfig.json, C:\a\_work\1\s\Source\packages\microsoft.aspnetcore.components.customelements\9.0.4\contentFiles\any\net9.0\js\tsconfig.json, C:\a\_work\1\s\Source\Websites\x\src\x\wwwroot\Scripts\release\tsconfig.json, C:\a\_work\1\s\Source\Websites\y\src\y\wwwroot\js\release\tsconfig.json]
With the sonar.typescript.tsconfigPaths property specified with a value of C:\a\_work\1\s\Source\Websites\*\tsconfig.json, we get the following resolution when the tsconfig.json files are matched:
INFO: Sensor JavaScript/TypeScript analysis [javascript]
INFO: Resolving TSConfig files using 'C:\a\_work\1\s\Source\Websites\*\tsconfig.json' from property sonar.typescript.tsconfigPaths
DEBUG: Using 'C:\a\_work\1\s\Source\Websites\*\tsconfig.json' to resolve TSConfig file(s)
INFO: Found 0 TSConfig file(s): []
INFO: Found 8 tsconfig.json file(s): [C:\a\_work\1\s\Source\other\tsconfig.json, C:\a\_work\1\s\Source\other\Scripts\release\tsconfig.json, C:\a\_work\1\s\Source\Websites\x\src\x\tsconfig.json, C:\a\_work\1\s\Source\Websites\y\src\y\tsconfig.json, C:\a\_work\1\s\Source\packages\microsoft.aspnetcore.components.customelements\9.0.4\content\js\tsconfig.json, C:\a\_work\1\s\Source\packages\microsoft.aspnetcore.components.customelements\9.0.4\contentFiles\any\net9.0\js\tsconfig.json, C:\a\_work\1\s\Source\Websites\x\src\x\wwwroot\Scripts\release\tsconfig.json, C:\a\_work\1\s\Source\Websites\y\src\y\wwwroot\js\release\tsconfig.json]
As you can see, it reports that it will match files by the path we provided successfully, then is not able to find any matching files, then falls-back to a default matching I believe, but then finds tsconfig.json files inside the Websites directory, which on the line above reported as non was found.
The wildcard patterns we tried so far:
C:\a\_work\1\s\Source\Websites\**\*C:\a\_work\1\s\Source\Websites\**\*.jsonC:\a\_work\1\s\Source\Websites\**\tsconfig.jsonC:\a\_work\1\s\Source\Websites\*C:\a\_work\1\s\Source\Websites\*\*.jsonC:\a\_work\1\s\Source\Websites\*\tsconfig.json
Does anybody have any idea how we can fix this issue moving forward?
Thank you for your replies in advance.