Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JeroMiya opened this issue Feb 4, 2015 · 6 comments
Closed

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

JeroMiya opened this issue Feb 4, 2015 · 6 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@JeroMiya
Copy link

JeroMiya commented Feb 4, 2015

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.
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Mar 24, 2015
@aciccarello
Copy link

I'm looking for some way to more easily manage this too. I like the idea of having unit tests along side the source file because it makes the /// file references easier (rather than ../../../src/feature/file.ts). I might be interested in just creating different tsconfig files (e.g. tsconfig-app.json, tsconfig-unit.json) which should work with the -p project spec.

@Zorgatone
Copy link

I need a feature like this, to possibly bundle some files and compile the rest alone

@aciccarello
Copy link

@Zorgatone I'm using browserify with the tsify plugin to bundle my files. Then I've started using ES6 imports to pull in all the files that I need for that bundle.

@adidahiya
Copy link
Contributor

+1 it would be great if tsconfig.json supported multiple subprojects, and I like the syntax / semantics that @JeroMiya is proposing

@Zorgatone
Copy link

I totally think that this suggestion needs more attention though.
It's definitely something that will help a lot of people save some precious time. Instead of having to rely on external tools (grunt/gulp/browserify/...)

@mhegazy
Copy link
Contributor

mhegazy commented Sep 28, 2015

Duplicate of #3469?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants