microsoft / TypeScript

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

TS 5.6 `files` missing from `--showConfig` (with absolute / ``${configDir}`` `include` paths) #60199

Open stabpd opened 1 week ago

stabpd commented 1 week ago

πŸ”Ž Search Terms

"--showConfig", "include", "configDir", "files", "extends", "absolute"

πŸ•— Version & Regression Information

⏯ Playground Link

No response

πŸ’» Code

// tsconfig-rel.json
{
    //...
    "include": ["src/**/*"]
}
// tsconfig-abs.json
{
    //...
    "include": ["/path/to/src/**/*"]
}
// tsconfig-cnf.json
{
    //...
    "include": ["${configDir}/src/**/*"]
}
// src/index.ts
console.log("dummy");

πŸ™ Actual behavior

❌ Printing config yields different results.

npx tsc --project tsconfig-rel.json --showConfig
npx tsc --project tsconfig-abs.json --showConfig
npx tsc --project tsconfig-cnf.json --showConfig
  {
      "compilerOptions": {...},
-     "files": [
-         "./src/index.ts"
-     ],
      "include": [
-         "src/**/*"
+         "/path/to/src/**/*"
      ],
      "exclude": [...]
  }

βœ… Listing files yields the same output.

npx tsc --project tsconfig-rel.json --listFiles --noEmit
npx tsc --project tsconfig-abs.json --listFiles --noEmit
npx tsc --project tsconfig-cnf.json --listFiles --noEmit

List of files printed to stdout, containing

βœ… Building yields the same index.js file content for all configs.

npx tsc --project tsconfig-rel.json
npx tsc --project tsconfig-abs.json
npx tsc --project tsconfig-cnf.json

πŸ™‚ Expected behavior

--showConfig should show the same files for configs that build the same files and show the same listing for --listFiles.

Additional information about the issue

includeRe in matchesSpecs seems to be calculated differently for absolute / relative paths, resulting in all files being filtered out in convertToTSConfig.

I can't tell though which behaviour is actually expected. (keep files or filter files out?)

RyanCavanaugh commented 1 week ago

I don't know if anyone is really putting absolute paths in their config files; this seems like a nonstandard usage. showConfig is intended for human consumption so it's not really wrong for it to do different things given different inputs. Not sure what the "best" behavior is but if someone really needs to change it to some provably better outcome, they can.

stabpd commented 6 days ago

I agree that this is not an urgent matter. Let me add a little clarification for future discussion though:

For me, it's not about manually configured absolute paths, but about ${configDir} which has the same issue, because the template variable gets substituted with absolute paths internally.

When switching from a monolithic config to a base tsconfig.json that I could extend, I wanted to verify changes via showConfig. Seeing no files there, no matter what I did, almost made me discard using that nice new ${configDir} feature.

I can live with the current behaviour, now that I know. But maybe this will confuse other users as well, leading them down the wrong path too.