Skip to content

The output structures of rootDir and rootDirs are inconsistent #61883

Open
@TomFryersMidsummer

Description

@TomFryersMidsummer

🔎 Search Terms

rootDirs rootDir inconsistent structure

Maybe related to #44321 and #22039.

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about rootDirs (of which there are none). I tried next, 5.8.3 and 2.0.8. All exhibit this behaviour.

⏯ Playground Link

Here's a tiny repo or see below.

💻 Code

tsconfig1.json:

{"compilerOptions": {"outDir": "build", "rootDir": "src"}

tsconfig2.json:

{"compilerOptions": {"outDir": "build", "rootDirs": ["src"]}

src/foo/bar.ts is an empty file.

🙁 Actual behavior

Building with "rootDir": "src" and rootDirs: ["src"] produces different output:

$ tsc -p tsconfig1.json
$ find build/ -type f
build/foo/bar.js
$ rm -r build/
$ tsc -p tsconfig2.json
$ find build/ -type f
build/bar.js

🙂 Expected behavior

Both should do the same thing. Indeed, according to the documentation, using rootDirs ‘does not affect how TypeScript emits JavaScript’.

Additional information about the issue

For single-element arrays, of course, it doesn't really matter. But as it stands, I can't see a way to get both the non-nested structure rootDir provides and multiple root directories. #22039 perhaps suggests that setting both rootDir and rootDirs would work, but doing that makes tsc complain about whichever of rootDirs isn't in rootDir.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions