Skip to content

In composite projects with ttypescript, ts-node should call transformers with parameters defined on the tsconfig.json of the executed file instead of the original one #1945

@aquilae

Description

@aquilae

Search Terms

composite, transform, ttypescript

Expected Behavior

When building a composite project, typescript/ttypescript picks up the transformers defined on each nested project.
For example, with this structure:

root/
 - tsconfig.json with transform A
 - root.ts
 - app/
  - tsconfig.json with transform B
  - app.ts

transform A will be applied to root.ts and transform B will be applied to app.ts.

In repro branch:

> npx ttsc -b
another transform subapp.ts with ../visitor
transform root.ts with ./visitor

Actual Behavior

ts-node currently reads transformers once from the tsconfig.json corresponding to the file you pass as an argument, and then applies the same transformer to all the files it encounters even when importing files under a different composite project.

root/
 - tsconfig.json with transform A
 - root.ts
 - app/
  - tsconfig.json with transform B
  - app.ts

Running ts-node root.ts, transform A will be applied both to root.ts and app.ts

In repro branch:

> npx ts-node -C ttypescript root.ts
transform root.ts with ./visitor
transform subapp.ts with ./visitor

In practice, that completely breaks not only the ability to use different transformers for different projects, but also the support for relative path parameters to transformers.

Steps to reproduce the problem

Set up a composite TS project with different transformers for root and nested projects, notice the difference in transformer calls between ttsc -b and ts-node -C ttypescript ..

Minimal reproduction

Repro repo PR: TypeStrong/ts-node-repros#32

> npx ttsc -b
another transform subapp.ts with ../visitor
transform root.ts with ./visitor

> npx ts-node -C ttypescript root.ts
transform root.ts with ./visitor
transform subapp.ts with ./visitor

Specifications

  • ts-node version: v10.9.1
  • node version: v16.17.1
  • TypeScript version: v4.9.4
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "outDir": ".typescript",
    "plugins": [
      {
        "type": "program",
        "transform": "./transform.js",
        "visitor": "./visitor"
      }
    ]
  },
  "references": [
    { "path": "./subapp" }
  ],
  "files": ["root.ts"]
}

  • package.json:
{
  "version": "0.0.1",
  "devDependencies": {
    "ts-node": "^10.9.1",
    "ttypescript": "^1.5.15",
    "typescript": "^4.9.4"
  }
}

  • Operating system and version: Win 10
  • If Windows, are you using WSL or WSL2?: No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions