Explicitly specifying tsconfig.json file paths to analyze fails

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\**\*.json
  • C:\a\_work\1\s\Source\Websites\**\tsconfig.json
  • C:\a\_work\1\s\Source\Websites\*
  • C:\a\_work\1\s\Source\Websites\*\*.json
  • C:\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.

Hi,

Welcome to the community!

Can you share your pipeline configuration for analysis?

You haven’t mentioned specifying sonar.sources. Some of the scanners configure that automatically from the build environment, but SonarScanner for NPM doesn’t seem to be one of them. When not set, this property defaults to ., which matches with what you’re seeing.

 
Ann

Dear Ann,

Thank you for your reply.

Our setup is pretty straight-forward.

    - task: SonarCloudPrepare@3
      displayName: 'Prepare analysis on SonarCloud'
      inputs:
        SonarCloud: '...'
        organization: '...'
        scannerMode: 'dotnet'
        projectKey: '...'
        projectName: '...'
        extraProperties: |
          sonar.sensor.cache.project.enable=false

... removed for bravity.

    - task: SonarCloudAnalyze@3
      displayName: 'Run code analysis'
      condition: succeededOrFailed()
    - task: SonarCloudPublish@3
      displayName: 'Publish Quality Gate result'
      condition: succeededOrFailed()

I just tried setting the sonar.sources property but that results with the following line in our pipelines:

WARNING: The sonar.sources and sonar.tests properties are not supported by the Scanner for .NET and are ignored. They are automatically computed based on your repository. You can fine-tune the analysis and exclude some files by using the sonar.exclusions, sonar.inclusions, sonar.test.exclusions, and sonar.test.inclusions properties.

I did not try the sonar.exclusions property, as I still would like to get the packages directory scanned, but just the mentioned tsconfig.json files skipped.

I also don’t think this is the NPM scanner, as these are not NPM packages. They are NuGet packages instead.

So my question is, why is my setting for the sonar.typescript.tsconfigPaths keeps being ignored and how to ignore some specific tsconfig.json files, or specify directories where the tsconfig.json files we are interested in analyzing exists.

Hi,

Where is your setting for the sonar.typescript.tsconfigPaths? I don’t see it in your pipeline configuration.

 
Ann

Oh, I mentioned it in my original post.

With the sonar.typescript.tsconfigPaths property specified with a value of C:\a\_work\1\s\Source\Websites\*\tsconfig.json

But below is how we configure it;

sonar.typescript.tsconfigPaths=$(System.DefaultWorkingDirectory)\Source\Websites\*\tsconfig.json


I also listed all variations of wildcard patterns we tried, as well as the response we receive when we specify something there.

The weird thing is, when the property is set, it says:

DEBUG: Using 'C:\a\_work\1\s\Source\Websites\*\tsconfig.json' to resolve TSConfig file(s)
INFO: Found 0 TSConfig file(s): []


But then it finds them when it falls back to the next line in the logs I shared above.

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
]

Four of the eight files listed above are actually in that directory specified, where it says it cannot find any.

Please do not focus on the \*\ part which does not look like the recursive one \**\*, we also tried that one and the result is the same.

Hi,

Could I please have the full pipeline configuration for analysis?

A full analysis log would be good too.

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi Ann,

Our configuration is what I shared above, plus the tsconfig property. That is all really. Everything else is just default values we have not specified.

    - task: SonarCloudPrepare@3
      displayName: 'Prepare analysis on SonarCloud'
      inputs:
        SonarCloud: '...'
        organization: '...'
        scannerMode: 'dotnet'
        projectKey: '...'
        projectName: '...'
        extraProperties: |
          sonar.sensor.cache.project.enable=false
          sonar.typescript.tsconfigPaths=$(System.DefaultWorkingDirectory)\Source\Websites\*\tsconfig.json

... removed for bravity. This is where other things go on, such as building the project.

    - task: SonarCloudAnalyze@3
      displayName: 'Run code analysis'
      condition: succeededOrFailed()
    - task: SonarCloudPublish@3
      displayName: 'Publish Quality Gate result'
      condition: succeededOrFailed()


I am afraid I will not be able to share the logs with you, as they are about 127.000 lines of logs, and redacting everything and anything will not be time efficient.

What is more, everything else works as expected. Whatever does not, does not because it tries to analyze files that we are not interested in being analyzed, as it ignores our sonar.typescript.tsconfigPaths configuration.

I believe I already shared the weird part where it says it cannot find any json files, but then lists files it found. I guess it has a fallback mechanism that takes place (the line where it says Found 8 tsconfig.json files).

The relevant sensor lines from the logs for this particular case is below if it helps anything.

INFO: Sensor JavaScript/TypeScript analysis [javascript]
DEBUG: Files which didn't change will only be analyzed for taint and architecture rules, other rules will not be executed
DEBUG: The bridge server is up, no need to start.
DEBUG: Initializing linter with S4790,S2251,S5122,S4275,S1440,S3981,S2255,S1442,S4158,S3500,S3863,S3984,S2137,S2259,S2138,S138,S930,S2814,S1314,S2819,S4144,S4143,S4784,S3696,S2123,S2245,S3972,S3973,S4787,S3699,S4823,S3579,S3854,S3735,S3616,S1439,S4829,S1321,S4030,S2077,S878,S2990,S2870,S2234,S3686,S1940,S1788,S2999,S2757,S113,S4818,S4817,S1135,S1134,S1131,S4140,S888,S2068,S2189,S3796,S4524,S125,S128,S2589,S3799,S1533,S1534,S3834,S3317,S881,S1656,S122,S1536,S121,S1301,S1143,S1264,S1481,S2692,S3782,S3785,S3786,S1488,S1763,S1764,S1523,S1525,S1526,S1527,S2737,S1528,S1119,S1529,S1117,S1116,S1110,S905,S2681,S1472,S108,S107,S3531,S2201,S2685,S1871,S104,S1751,S3533,S3776,S103,S1994,S2688,S1479,S3812,S1515,S1516,S101,S1128,S1126,S1125,S3001,S2310,S3003,S2432,S1862,S3403,S3800,S3801,S3923,S1219,S1192,S4043,S4165,S3353,S4326,S3358,S4721,S2424,S1854,S3757,S3516,S3758,S2703,S2428,S1226,S1105,S1066,S881,S122,S4818,S125,S4817,S128,S1940,S2757,S1301,S4139,S4138,S1821,S2077,S2870,S2871,S2234,S4136,S1143,S1264,S878,S4829,S138,S3616,S3973,S1439,S4787,S3699,S4823,S3854,S4822,S4784,S3696,S2123,S2245,S3972,S4782,S4144,S4023,S4143,S888,S4140,S3504,S2933,S3626,S3863,S3984,S2137,S4798,S4157,S3981,S4156,S2255,S4158,S4790,S1440,S5122,S4275,S4030,S3516,S1219,S4326,S4721,S4325,S1854,S4327,S3353,S4322,S4324,S4323,S4043,S4619,S1105,S1226,S3801,S3923,S1862,S4335,S1066,S1479,S1116,S1874,S1751,S4623,S3533,S1516,S3776,S4622,S1515,S2688,S4624,S1117,S4621,S3498,S2201,S2685,S3257,S1871,S1110,S2681,S1472,S1529,S101,S104,S103,S1523,S1764,S1125,S1488,S2737,S4634,S3786,S1526,S1525,S1128,S1121,S2692,S113,S117,S3317,S1533,S4524,S2589,S3799,S1656,S4124,S4123,S2068,S108,S107,S905
DEBUG: Loaded rule ucfg from C:\a\_work\1\.sonarqube\out\.sonar\.sonartmp\bridge-bundle\package\custom-rules11306384611743748892\package\dist\rules.js
DEBUG: Loaded rule sonar-architecture-ir from C:\a\_work\1\.sonarqube\out\.sonar\.sonartmp\bridge-bundle\package\custom-rules12570600714515655328\package\dist\rules.js
DEBUG: Initializing org.sonar.plugins.javascript.analysis.AnalysisWithProgram
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]

From this point on, things do work, except that we have failures as some of the tsconfig.json files it analyzes refer to missing files (not a problem with SonarCloud itself) so we want to skip those specific tsconfig.json files.

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 '[]'.


We are not interested in analyzing this file, we just aim to skip it.

Thank you for your assistance by the way, I appreciate your time and efforts.

Hi,

It looks like you’re setting an absolute path here:

It’s not explicit, but based on the docs

If not specified, it traverses the filesystem from the project root

I suppose it’s expecting paths relative from project root. Additionally, I wouldn’t expect a wildcard to be supported here. But if it were, I would expect glob patterns to be what was supported, so not \*\ but \**\.

 
HTH,
Ann