DenoDDeno
Powered by
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
deno.land/x
, the JS API entrypoint would be in
mod.ts
mod.ts
and the CLI entrypoint in
main.ts
main.ts
; something like:

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

deno run https://deno.land/x/myThing/main.ts arg1 arg2
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
mod.ts
entrypoint):
import myApi from "jsr:@scope/myThing"
import myApi from "jsr:@scope/myThing"

deno run jsr:@scope/myThing arg1 arg2
deno run jsr:@scope/myThing arg1 arg2


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

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

What do you think?
Thanks!
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

deno.lock multiple entry point best practices
andykaisAandykais / help
4y ago
Jsr modules with package.json
nandi.weird.oneNnandi.weird.one / help
12mo ago
Binary files in jsr package
MqxMMqx / help
2y ago
JSR package not found: @std/jwt
crowlKatsCcrowlKats / help
11mo ago