justkey007 / tsc-alias

Replace alias paths with relative paths after typescript compilation
MIT License
902 stars 62 forks source link

Does not work with Project References that have a rootDir in their tsconfig #145

Open miguel-leon opened 1 year ago

miguel-leon commented 1 year ago

In my main project tsconfig.json there is:

  "compilerOptions": {
    ...
    "outDir": "../dist/api",
    "baseUrl": ".",
    "paths": {
      "models": ["../models/src/index.ts"]
    }
  },
  "include": ["./src"],
  "references": [
    {
      "path": "../models"
    }
  ]

being models a Project Reference, there's a tsconfig.json file in its directory:

{
  "compilerOptions": {
    "composite": true,
    "outDir": "../dist/models",
    "rootDir": "./src"
  },
  "include": ["./src"]
}

This means the output of tsc will be put directly in ../dist/models skipping the src subdirectory.

When tsc-aliases runs, it is trying to locate the file dist/models/src/index.js, deems it invalid and doesn't replace the import. But it should have been looking in dist/models/index.js instead.

raouldeheer commented 1 year ago

@miguel-leon can you provide us the console output when running with --debug?

miguel-leon commented 1 year ago

It contained a lot of unnecessary information, because it wasn't a new empty project. I took the path it is trying to locate ...dist/models/src/index.js from that output, that's how I know. Also there wasn't any signs of the models/tsconfig.json being loaded to check up on the rootDir.

I already moved on, so I don't have it anymore. I was letting you guys know in case you were interested.

raouldeheer commented 1 year ago

This issue could probably be solved by changing "models": ["../models/src/index.ts"] to "models": ["../models/src/index.ts", "../models/index.js"]

sadofriod commented 1 year ago

I think an update to rootDir's parsing is needed to fully resolve this issue here. Make it possible to parse the directory after the build.

forgetso commented 1 year ago

This issue could probably be solved by changing "models": ["../models/src/index.ts"] to "models": ["../models/src/index.ts", "../models/index.js"]

This doesn't work.