ajitid / fzf-for-js

Do fuzzy matching using FZF algorithm in JavaScript

Home Page:https://fzf.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to run this library inside deno?

felixsanz opened this issue · comments

Hi ! I've found this package on deno.land/x but there is no instructions on how to run it, mod.ts doesn't exist, etc. Can someone paste a working example like the one on the readme, but for deno? thanks!

commented

Apologies for it being a lazy port. Try using web sources like Deno suggests. Here's a working example:

import { Fzf } from 'https://esm.sh/fzf@0.5.1'
// or
// import { Fzf } from 'https://cdn.skypack.dev/fzf?dts'

const fzf = new Fzf(['deno', 'dinosaurus', 'docusaurus', 'digimon'])

const entries = fzf.find('dno')
console.log('we found:')
entries.forEach(entry => console.log(entry.item))

If you are happy with the solution, I'd put it in the documentation.

that works! i didn't try it before because usually you don't use esm.sh (and friends) IF the package is in deno.land/x.

So that version doesn't work then?

Anyway this one does so.... thanks!

commented

So I did a bit of digging as I don't use Deno myself:

there is no instructions on how to run it, mod.ts doesn't exist, etc.

Apparently putting mod.ts at project root is just a convention, and not all modules published on deno.land follow it. Yargs for example, uses deno.ts and deno-types.ts instead.

Others publish the build output there or suggest to use the package using NPM compatibility — basically asking devs to use the build output via Skypack, esm.sh, etc. Oddly, people are okay with using these party web sources.

So that (deno.land) version doesn't work then?

I assume that many people are publishing to deno.land just to get more visibility to their package (and also its pretty easy to do it).

What's the right way then?

Thanks for asking. Doing something like:

import { Fzf } from 'https://deno.land/x/fzf/src/lib/main.ts'
// or
// import { Fzf } from 'https://raw.githubusercontent.com/ajitid/fzf-for-js/stable-releases/src/lib/main.ts'

didn't work for you because main.ts itself imports files without extension, say import /*...*/ './finders'. So Deno looks for https://deno.land/x/fzf/src/lib/finders and not https://deno.land/x/fzf/src/lib/finders.ts (notice missing extension in the former), resulting in 404.

Relevant discussion here: denoland/deno#9569

I could:

  • stick to suggesting users to make NPM compatible imports, or
  • do it the right way by converting my source files to make explicit imports (like what Zod does)

(Unrelated) article for consumers of deno packages: https://dev.to/wongjiahau/why-deps-ts-and-mod-ts-is-bad-in-deno-bjo

i think using esm.sh and that websites is ok enough. but it's confusing if the package is located at deno.land/x and that version is not working, i think it should be at least noted on the readme, or fixed so it can work. What zod does is the best option in my opinion. my 2 cents!