LeDDGroup / typescript-transform-paths

Transforms module resolution paths using TypeScript path mapping and/or custom paths
MIT License
478 stars 25 forks source link

[Bug] Paths seems to be required but not sure why #146

Open dborstelmann opened 2 years ago

dborstelmann commented 2 years ago

I don't use paths in my project, just baseUrl like so:

{
  "extends": "../../tsconfig.packages.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "baseUrl": "./src"
  }
}

I have to add a blank paths to make this work. Is this avoidable?

Doesn't work:

"plugins": [
  { "transform": "typescript-transform-paths", "useRootDirs": true },
  { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
]

Works great:

"paths": {
  "*": ["*"]
},
"plugins": [
  { "transform": "typescript-transform-paths", "useRootDirs": true },
  { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
]
nonara commented 2 years ago

Thanks for the report. That shouldn't happen, no. I recently discovered the same. It applies specifically to useRootDirs if paths isn't set.

I have it covered in the upcoming major release, but I will try to get a patch out in the next few days for you!

dborstelmann commented 2 years ago

Thanks for the quick response! This lib solved me running js in production tonight so it's much appreciated.

nonara commented 2 years ago

Quick update (It's been a busy couple of weeks!)

As memory serves, I ran into some challenges surrounding this same area of code while working on what was supposed to be another small change. All of it is sorted out in the new upcoming major version, which has some significant internal changes.

That in mind, in the mean time, I'd suggest continuing to use the workaround. I'll leave this issue open and update you as soon as the next major comes out! At that point you won't need any workarounds

fsmaia commented 2 years ago

https://github.com/LeDDGroup/typescript-transform-paths/blob/master/src/utils/resolve-path-update-node.ts#L39

It seems that this if statement is suppressing baseUrl resolution, which happens at resolveModuleName, right below.

I'll open a pull request trying to handle this, and then I would like to have some help identifying some other possible corner cases.

holynewbie commented 1 year ago

any progress ? 😂 @nonara