unstorage icon indicating copy to clipboard operation
unstorage copied to clipboard

refactor(redis): use named import for `Redis`

Open tobiasdiez opened this issue 2 years ago โ€ข 4 comments

๐Ÿ”— Linked issue

โ“ Type of change

  • [ ] ๐Ÿ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] ๐Ÿž Bug fix (a non-breaking change that fixes an issue)
  • [ ] ๐Ÿ‘Œ Enhancement (improving an existing functionality like performance)
  • [ ] โœจ New feature (a non-breaking change that adds functionality)
  • [x] ๐Ÿงน Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to change)

๐Ÿ“š Description

Since a few versions, ioredis supports named imports. This should improve esm compatibility, and maybe at some point enable treeshaking.

๐Ÿ“ Checklist

  • [ ] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

tobiasdiez avatar Sep 21 '23 16:09 tobiasdiez

Thanks for this PR, but do you think it is an essential change? If ioredis keep supporting default export, it can be safer for projects might have an older version of it.

pi0 avatar Sep 28 '23 21:09 pi0

It's not very essential. I have some troubles with the ioredis import (https://github.com/redis/ioredis/issues/1822, mostly when using vitest) and was hoping this is fixed with this change here. But if you think backwards compatibility is an issue, we can still wait with merging this.

tobiasdiez avatar Sep 29 '23 00:09 tobiasdiez

Can you help on preparing a reproduction for vitest issue?

What else we can do, is to use import * from or use dynamic import() to dedefault in runtime to have both backward and forward (vitest, ESM) compatibility.

pi0 avatar Sep 29 '23 09:09 pi0

It's sadly hard to reproduce, only occurring in certain situations (which seem to involve importing ioredis another time in code that is tested after using unstorage). Will append a reproduction to the issue as soon as I have one.

You are the expert of cjs/esm imports, so I'll let you decide what's the best import here. I got confused by how ioredis is doing its exports https://unpkg.com/browse/[email protected]/built/index.js

tobiasdiez avatar Sep 29 '23 09:09 tobiasdiez