alias-hq icon indicating copy to clipboard operation
alias-hq copied to clipboard

Support Fallbacks

Open p-98 opened this issue 1 year ago • 3 comments

As per the typescript docs, one can specify multiple mappings which are tried in turn such as

"paths": {
    "Types/*": ["../shared/src/types/*", "./src/types/*"],
}

Unfortunately, alias-hq outputs

// alias-hq.get("webpack")
{
    Types: '/absolute-path-to-repo/shared/src/types'
}
// alias-hq.get("jest")
{
    '^Types/(.*)$': '<rootDir>/../shared/src/types/$1'
}

Which leads to the failing to resolve imports if the file is in the second directory, namely ./src/types/.
The docs of both tools say you can also pass arrays.

Can we get support for this?

p-98 avatar Oct 29 '24 10:10 p-98

Hey, thanks for this.

I think the reason I did that was because libs like Jest only support a single alias (at the time of writing).

If you're saying it is supported now, then absolutely, it would be best to support that!

davestewart avatar Oct 29 '24 11:10 davestewart

FWIW I have not had the time this year to do much OSS at all, but actually it looks like I will have some time over the next few months, so I'll do my best to get to this.

davestewart avatar Oct 29 '24 11:10 davestewart

Actually, I just checked all the tools you have plugins for. babel accepts an array, rollup unfortunately does not and neither does the rollup plugin linked in the issue. Regarding module-alias I haven't found any information, but when looking at the source it doesn't look like it.

And I just realized there is the format: 'array' option for jest. From the description it was not clear to me what this option was doing, but turns out it enables support for multiple target paths.

I already tested it locally and can create a pr for webpack. You might still consider rewording the description.

p-98 avatar Oct 29 '24 12:10 p-98