zettcaZ
Denoβ€’2y agoβ€’
2 replies
zettca

Deno JSR API package + CLI entrypoint "best-practices"

Hey πŸ‘‹

I have a package that is both a CLI and provides a JS API.
Previously with deno.land/x, the JS API entrypoint would be in mod.ts and the CLI entrypoint in
main.ts
; something like:

import myThing from "https://deno.land/x/myThing/mod.ts"

deno run https://deno.land/x/myThing/main.ts arg1 arg2


But I'm not sure of the best way to do it with JSR. Should there be multiple entrypoints? It's a small library
It feels like the usage be something like this (single mod.ts entrypoint):
import myApi from "jsr:@scope/myThing"

deno run jsr:@scope/myThing arg1 arg2


I see a few options:
1. Have the mod.ts entrypoint exports both the JS API and the CLI (under import.meta.main)
2. Have multiple entrypoints, but the imports won't be "pretty" (eg. jsr:@scope/myThing/cli.ts)
3. Separate the CLI into a separate package

3. seems a bit overkill, but 1. doesn't feel too right either

What do you think?
Thanks!
Was this page helpful?