jsr icon indicating copy to clipboard operation
jsr copied to clipboard

Add npx-like behavior

Open renejfc opened this issue 1 year ago • 3 comments

I'm submitting this feature request encouraged by @marvinhagemeister on the Discord server.

Context

I was wondering if we could run packages "on the fly" similar to how npx, yarn dlx, pnpm dlx and bunx does.

Behavior

Basically, the expected behavior would be the same or similar as explained in the docs of the previously mentioned commands (npx for reference).

In other words, running the command will first search for the package locally. If it's found, it will run it directly. Otherwise, the command will temporarily fetch the package, run it, and then delete it after use.

Examples

I guess this will be discussed either here, in the pr or by the team but here are a few examples from the top of my head.

  • bunx jsrx @<namespace>/<package>
  • npx jsr:@<namespace>/<package>
  • And honestly that would be it. Feel free to comment more examples.

NOTE: I hope the idea is well conveyed and there wasn't a misunderstanding with the feature, feel free to comment what you think about it or ping me if want to add something to the post.

renejfc avatar Mar 03 '24 23:03 renejfc

I was also thinking the same, that a bin property similar to package.json would be great to have 💪🏻

halvardssm avatar Mar 04 '24 10:03 halvardssm

Hi everybody, looks the pr related to this ticket is in stale, any update on the topic? Thanks a lot

andeeplus avatar Jul 23 '24 21:07 andeeplus

I think this is a dupe of https://github.com/jsr-io/jsr-npm/issues/76

I created an xjsr package as a workaround you can run like this:

➜ npx xjsr @alexgleason/hello
hello

I needed this for my own projects. Feel free to use it. But I'm guessing this issue hasn't been resolved in JSR itself because of incompatibilities between Deno and Node.

For example, this package does not work correctly: npx xjsr @luca/flag because Node.js does not support import.meta.main.

(The Deno.* namespace also doesn't work in Node, so we'd need to add shims or transpile to make some packages work.)

So far I am only using xjsr for packages that are already Node-compatible. But it might be possible to stick Babel in there to transpile the package and solve some of this.

alexgleason avatar Apr 23 '25 15:04 alexgleason

Node.js will support import.meta.main shortly - see recently landed nodejs/node#57804

Lordfirespeed avatar May 27 '25 13:05 Lordfirespeed