Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Fallbacks #79

Open
p-98 opened this issue Oct 29, 2024 · 3 comments · May be fixed by #80
Open

Support Fallbacks #79

p-98 opened this issue Oct 29, 2024 · 3 comments · May be fixed by #80

Comments

@p-98
Copy link

p-98 commented Oct 29, 2024

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?

@davestewart
Copy link
Owner

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
Copy link
Owner

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.

@p-98
Copy link
Author

p-98 commented Oct 29, 2024

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 p-98 linked a pull request Oct 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants