Skip to content

support sub-projects within a single tsconfig.json #1928

Closed
@JeroMiya

Description

@JeroMiya

Extension to #1692.

Motivation:
A common file layout for some projects is to organize code by feature, rather by the kind of the file. This means that the implementation of a feature, along with its unit tests and end to end tests are all grouped into a single directory structure. I use this convention in my own projects.

Currently, however, tsconfig.json assumes that sub-projects are split by directories. With the feature grouped files convention, however, we have multiple 'projects' interleaved in the same directories. For example, end to end tests have different project settings than unit tests, which may have different project settings from the application code itself.

Proposal:
Support sub-projects within a single tsconfig.json. This allows for more flexibility in how files are laid out in an application.

Example:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "removeComments": false,
    "sourceMap": true
  },
  "files": [
     "common-files/commonFiles.ts",
  ],
  "projects": {
     "app": {
         "compilerOptions": {
             "module": "amd",
             "removeComments": true,
             "out": "app/app.js"
         },
         "files": [
             "app/feature1/feature1.ts"
         ]
     },
     "unit": {
         "compilerOptions": {
             "out": "tmp/unit/"
         },
         "files": [
           "app/feature1/feature1_test.ts",
         ]
    },
    "e2e": {
        "compilerOptions": {
            "module": "commonjs",
            "out": "tmp/e2e/"
        },
        "files": [
            "app/feature1/feature1PageObject_e2e.ts",
            "app/feature1/feature1_e2e.ts"
         ]
    }       
}

Building with tsc:

tsc -p tsconfig.json
-> builds root and all sub-projects, including those in sub-directories, recursively.

tsc -p tsconfig.json:app
-> builds root and app sub-project.

Notes:

  • Projects are recursive. You can have sub-projects of projects. Building the root builds all sub-projects and their sub-projects.
  • To build a specific sub-project, use ':', for example tsc -p jsconfig.json:app:feature1 if "feature1" were a subproject of "app" (not shown in the example above).
  • Child projects inherit options and files from their parent projects, unless options are overwritten. Files are additive.
  • tsconfig.json files in sub-directories are evaluated independently. That is, they do not inherit anything from tsconfig.json files in a parent directory.
  • IDE and editor extensions may decide to support switching the current "context" of a file, i.e. the project or sub-project, or the tsconfig.json file if more than one reference the same file in one of the parent directories.

The default context is determined as follows:

  • Find the tsconfig.json in the same directory as the file, or recursively search parent directories.
  • If the root project has a reference to the file, use the root settings as the default context.
  • Recursively look in each sub-project, finding the first project with a reference to the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions