krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.14k stars 767 forks source link

add ESM exports in package.json #692

Closed akphi closed 1 year ago

akphi commented 1 year ago

@krisk We're using Typescript module: Node16 in our project and since Fuse.js ESM does not specify type: module and exports field in package.json, it does not get picked up properly by Typescript. So I would like to add these to the package.json file.

The error I got is something like this, for the following import:

import Fuse from 'fuse.js';

const searchEngine = new Fuse(...

^
This expression is not constructable.
  Type 'typeof import("/Users/user/my-project/node_modules/fuse.js/dist/fuse")' has no construct signatures.ts(2351)

I believe this would help with https://github.com/krisk/Fuse/issues/541 as I have noted there

For Typescript esm mode, such as Node16, NodeNext, esModuleInterop is not supported in this mode, it's worth if we do something like https://github.com/lukeed/clsx/pull/44 - I have given it an attempt but not quite sure how I can modify the d.ts file accordingly.

rchandu commented 1 year ago

This would be something that would help us. Is there something I can do to help here on this effort ?

akphi commented 1 year ago

@rchandu seems like there hasn't been active development in this repo for a couple of months now 🤔

akphi commented 1 year ago

@krisk Could you kindly please take a look at this? Thanks!

favna commented 1 year ago

@akphi expect a PR to your fork with a completely refreshed but also thoroughly tested setup very soon, when you merge that it'll pop up here for Krisk to then review fully.

I noticed my comment above introduced some other issues as well but now I am testing the scenarios:

Edit: Only having some trouble with the last one still so I need to figure that out.

favna commented 1 year ago

@akphi I created https://github.com/akphi/Fuse/pull/1 just now but before it can be merged you need to rebase your own exports branch on top of Krisk/master. Alternatively I could create my own PR targeting Krisk/master from my own fork and we close this PR but that means your contribution credit is lost, your call.

akphi commented 1 year ago

hey @favna, thanks for being super transparent; I really don't mind you carrying that out; all I need is just to have ESM ready :) Thanks so much for the help! - let me know, I'll close it out in favor of your PR

favna commented 1 year ago

I have created https://github.com/krisk/Fuse/pull/727 so this PR can be closed @akphi