open-draft / dotalias

A single configuration for path aliases to reuse across all your tools (TypeScript, Jest, webpack, Rollup, etc.).
91 stars 2 forks source link

I think Jest converter needs `<rootDir>/` prefix? #5

Open moltar opened 2 years ago

moltar commented 2 years ago

Ok, I do see that there is logic to prepend this, based on the prefix.

If the path is ./ then <rootDir>/ is added.

However, this doesn't seem to work in my case:

Given

kettanaito commented 2 years ago

Hey, @moltar. Thanks for this suggestion.

I've used <rootDir> in the past but eventually migrated from it. I think the idea was for the relative paths to always be relative to the .alias configuration file.

You're right, we are prepending the <rootDir> if the path starts with ./:

https://github.com/open-draft/dotalias/blob/45d6f438cf908d8ab058e1b2fcc969f16db93061/src/converters/toJestConfig.ts#L54-L56

Do you experience an issue because of this logic? Could you please share your entire .alias config file?

moltar commented 2 years ago

I was calling the fn programmatically. So I guess it's an undocumented use case 😀

kettanaito commented 2 years ago

Can you share how you're calling it? Please, the more info and examples you provide, the more fruitful our discussion is going to be. I'm curious to see when the rootDir may fail.

moltar commented 2 years ago
import { toJestConfig } from 'dotalias/lib/converters/toJestConfig'

const paths: Record<string, string> = {
  bar: './../bar/src'
}

toJestConfig(paths).moduleNameMapper
moltar commented 2 years ago

See https://codesandbox.io/s/typescript-playground-export-forked-g2ekj?file=/index.ts