deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

[typeCompiler] Support extends on tsconfig.json

Open CristianPi opened this issue 3 years ago • 0 comments

Monorepo with Nx

Project tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "files": [],
  "include": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ]
}

tsconfig.base.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "noLib": false,
    "esModuleInterop": true,
    "target": "esnext",
    "module": "commonjs",
    "lib": [
      "es2017",
      "dom"
    ],
    "skipLibCheck": false,
    "skipDefaultLibCheck": false,
    "baseUrl": ".",
    "paths": {
      "@climbo/api-helper": [
        "libs/api-helper/src/index.ts"
      ],
      "@climbo/graphql-utils": [
        "libs/graphql-utils/src/index.ts"
      ],
      "@climbo/logger": [
        "libs/logger/src/index.ts"
      ],
      "@climbo/moongose-extra": [
        "libs/moongose-extra/src/index.ts"
      ],
      "@climbo/nestjs-request-context": [
        "libs/nestjs-request-context/src/index.ts"
      ],
      "@climbo/project": [
        "libs/project/src/index.ts"
      ],
      "@climbo/tst-reflect-utils": [
        "libs/tst-reflect-utils/src/index.ts"
      ],
      "@climbo/utils": [
        "libs/utils/src/index.ts"
      ]
    },
    "plugins": [
    ]
  },
  "reflection": true, // this is never found!
  "exclude": [
    "node_modules",
    "tmp"
  ]
}

Example of monorepo https://github.com/knowankit/fullstack-monorepo-boilerplate

types are not compiled.

Looking inside compiler.ts

                if (tsConfigExists) {
                    try {
                        let content = readFileSync(tsConfigPath, 'utf8');
                        content = stripJsonComments(content);
                        tsConfig = JSON.parse(content);
                        this.resolvedTsConfig[tsConfigPath].data = tsConfig;
                    } catch (error: any) {
                        console.warn(`Could not parse ${tsConfigPath}: ${error}`);
                    }
                }

extends is not manage, i'm not expert, but something like this works

                if (tsConfigExists) {
                    try {
                        let content = readFileSync(tsConfigPath, 'utf8');
                        content = stripJsonComments(content);
                        tsConfig = JSON.parse(content);
                        if (tsConfig.extends){
                          const base = JSON.parse(readFileSync(join(currentDir,tsConfig.extends),'utf8'))
                          tsConfig = {...base,...tsConfig};
                        }
                        this.resolvedTsConfig[tsConfigPath].data = tsConfig;
                    } catch (error: any) {
                        console.warn(`Could not parse ${tsConfigPath}: ${error}`);
                    }
                }

Not sure if there's a better way

CristianPi avatar Jul 28 '22 20:07 CristianPi