microsoft / microsoft/TypeScript

[Bug] Projects have different output directory structure with same configuration.

Đang mở
#40,400 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Needs Investigation
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

TypeScript Version: 4.0 (npm)

Search Terms:
declarationDir, rootDir, baseURL.

Problem
My app has a circular reference between the client and the server for typing reasons, essentially during prototyping there is a proxy that allows the server and the client to call functions on the remote as though they were local asynchronous functions. This has traditionally worked fine (well, with effort) but lately my server tsconfig seems to want to output files in a different directory structure than it was previously, without warning (I didn't change the tsconfig file). Here's what's happening:

Expected behavior:
The folder structure should look like this:

Project:
    Client/
        tsconfig.json <--"Client tsconfig"
        code.ts
        code.js
    ClientDeclarations/
        code.d.ts
    Common/
        code.ts
        code.d.ts
        code.js
    Server/
        tsconfig.json <-- "Server tsconfig"
        code.ts
        code.js
    ServerDeclarations/
        code.d.ts <-- ! Note server files are meant to be at the root of the output dir
    tsconfig.json <-- "Parent tsconfig"

Actual behavior:
Instead it looks like this:

Project:
    Client/
        tsconfig.json <--"Client tsconfig"
        code.ts
        code.js
    ClientDeclarations/
        code.d.ts
    Common/
        code.ts
        code.d.ts
        code.js
    Server/
        tsconfig.json <-- "Server tsconfig"
        code.ts
        code.js
    ServerDeclarations/
        Client/
             code.d.ts <-- ! This is the client's .d.ts files which shouldn't be output by the server tsproj!
        Server/
             code.d.ts
    tsconfig.json <-- "Parent tsconfig"

Code
This is the "Parent tsconfig" (note I am using ttypescript):

{
  "compileOnSave": false,
  "compilerOptions": {
    "target": "es6",
    "sourceMap": true,
    "strict": true,
    "plugins": [
      { "transform": "../Typescript/SuperTransform.js" },
      { "transform": "../Typescript/Macros.js" }
    ]
  },
  "exclude": [
    "node_modules"
  ]
}

This is the client config (I don't think the references section is used on the client, it's just there to keep the client and server configs similar):

{
  "compileOnSave": false,
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "module": "amd",
    "target": "es6",
    "lib": [ "es6", "dom" ],
    "sourceMap": true,
    "strict": true,
    "build": true,
    "declaration": true,
    "declarationDir": "../ClientDeclarations",
    "baseUrl": "./",
    "paths": {
      "@Common/*": [ "../Common/*" ],
      "@Server/*": [ "../ServerDeclarations/*" ],
      "@Client/*": [ "./*" ]
    }
  },
  "include": [
    "./*",
    "./External/koco.ts",
    "./External/kocss.ts",
    "./External/kopath.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "references": [
    { "path": "../Common" }
  ]
}

This is the server config (on the server I'm using module-alias):

{
  "compileOnSave": false,
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "lib": [ "es6", "dom" ],
    "sourceMap": true,
    "strict": true,
    "build": true,
    "declaration": true,
    "declarationDir": "../ServerDeclarations",
    "baseUrl": "./",
    "paths": {
      "@Common/*": [ "../Common/*" ],
      "@Client/*": [ "../ClientDeclarations/*" ],
      "@Server/*": [ "./*" ]
    }
  },
  "include": [
    "./*"
  ],
  "exclude": [
    "node_modules",
  ],
  "references": [
    { "path": "../Common" }
  ]
}

Note that the only difference between the client and the server is that they have a different module output type and the client includes a few more files.

I've tried adding "../Client" and "../Client/**" to the list of excludes on the server tsconfig but that didn't do anything. I also tried adding rootDir to be the same as baseUrl but that also didn't do anything. Interestingly removing baseUrl and adding rootDir had the desired effect (although is not usable because I need to use paths).

Playground link
This issue cannot be reproduced on the playground.

Related Issues:
I could not find any related issues.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các ví dụ tsconfig.json của parent, client và server trong issue, tập trung vào declarationDir, baseUrl, rootDir, paths và project references. Tái hiện bố cục thư mục đầu ra của TypeScript 4.0 và so sánh với cấu trúc dự kiến. Được xem là hoàn tất khi giải thích hoặc sửa được lý do server phát ra các khai báo của Client và lồng các tệp, đồng thời bao quát cấu hình đã báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.