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

Fix issue with nested imports #376

Merged
merged 6 commits into from
Sep 1, 2024
Merged

Fix issue with nested imports #376

merged 6 commits into from
Sep 1, 2024

Conversation

lachieh
Copy link
Contributor

@lachieh lachieh commented Aug 28, 2024

Context

With a path alias like @/* pointing to src/*, an import like this:

an import statement like import { foo } from '@/foo'
transforms to import { foo } from './src/foo'

Problem

There is an issue, however, with nested imports being ignored:

an import like import { foo } from '@/nested/foo'
should transformed to import { foo } from './src/nested/foo'
but actually just stays as import { foo } from '@/nested/foo'

Solution

The fix was to update the regex pattern to look for anything in place of the asterisk ((.+)) rather than just 'any non forward slash' (([^\\/]+)).

const find = new RegExp(
`^${pathWithAsterisk.replace(regexpSymbolRE, '\\$1').replace(asteriskRE, '(.+)')}$`
)

Details

The commit log tells the story best and that's probably the easiest way to review the PR as well:

@lachieh
Copy link
Contributor Author

lachieh commented Aug 28, 2024

Fixes #330

@qmhc
Copy link
Owner

qmhc commented Aug 28, 2024

Thanks for your PR, but there are some errors occured from CI. Could you slove them?

@lachieh
Copy link
Contributor Author

lachieh commented Aug 30, 2024

Updated with new solution. Thanks!

@qmhc qmhc merged commit 10118ae into qmhc:main Sep 1, 2024
4 checks passed
@lachieh
Copy link
Contributor Author

lachieh commented Sep 1, 2024

Hey 👋 v4.1.0 is released which should fix this. I tried to add some test cases to cover the cases mentioned here.

If any of you could update and test if you're still having the issue? If not, can you post your full tsconfig.json and vite.config.json? Even better would be a codesandbox reproduction.

@williamp-osttra
Copy link

Hey 👋 v4.1.0 is released which should fix this. I tried to add some test cases to cover the cases mentioned here.

If any of you could update and test if you're still having the issue? If not, can you post your full tsconfig.json and vite.config.json? Even better would be a codesandbox reproduction.

Thank you for this fix! It seems to work using v4.1.0 but I had to switch moduleResolution from node to nodenext and module to nodenext from esnext in my tsconfig.json in order for the fix to work.

lachieh added a commit to wasmCloud/wasmCloud that referenced this pull request Sep 11, 2024
lachieh added a commit to wasmCloud/wasmCloud that referenced this pull request Sep 11, 2024
lachieh added a commit to wasmCloud/wasmCloud that referenced this pull request Sep 17, 2024
…ugin-dts#376

Signed-off-by: Lachlan Heywood <lachieh@users.noreply.github.com>
lachieh added a commit to wasmCloud/wasmCloud that referenced this pull request Sep 17, 2024
…ugin-dts#376

Signed-off-by: Lachlan Heywood <lachieh@users.noreply.github.com>
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 this pull request may close these issues.

Invalid imports in generated d.ts for project with tsconfig path alias defined for any module
3 participants