jiti icon indicating copy to clipboard operation
jiti copied to clipboard

A file might be imported multiple times on Windows

Open ah-dc opened this issue 2 years ago • 3 comments

Environment

Windows

Reproduction

I created one on stackblitz but it is on Linux, so please download it and run it on Windows. I met this bug when I was using stub mode of unbuild, so this reproduction is based on that.

https://stackblitz.com/edit/stackblitz-starters-m3lfbv1

Describe the bug

Windows support \ and / as path separator, so a file might be imported more than once with different path on Windows, for example C:\foo.ts and C:/foo.ts. It causes problems when this file has side effects.

Additional context

No response

Logs

No response

ah-dc avatar Jul 19 '23 09:07 ah-dc

I have to say sorry that this issue is completely misleading... After some investigation I found the true issue.

First of all, the multiple paths only affects the cache, jiti uses filename to do hash so different paths will lead to different transpiled files, but it won't cause a file to be imported more than once, just a minor performance issue.

The real cause is

https://github.com/unjs/jiti/blob/79eeafb67b1768531010d41b59fcda3d46f8f730/src/jiti.ts#L154-L156

https://github.com/unjs/jiti/blob/79eeafb67b1768531010d41b59fcda3d46f8f730/src/jiti.ts#L173-L176

I think we should pass _additionalExts into mlly resolve options

ah-dc avatar Jul 19 '23 14:07 ah-dc

But I don't know why it works on linux, maybe it got successfully resolved via another branch

ah-dc avatar Jul 19 '23 15:07 ah-dc

Update: It is still possible to cause duplicated imports by using different paths on Windows.

Now I think we should split this issue into 2.

ah-dc avatar Jul 19 '23 15:07 ah-dc

unjs/jiti#152

pi0 avatar Sep 19 '24 11:09 pi0