jsr-io / jsr-npm

A cli tool to make installing packages form jsr.io in node easy
https://npmjs.com/package/jsr
MIT License
88 stars 12 forks source link

add run subcommand #76

Open ry opened 2 months ago

ry commented 2 months ago
npx jsr run @luca/flag

just like deno run jsr:@luca/flag

@jlarky https://twitter.com/JLarky/status/1783147968251748624

kt3k commented 2 months ago

Currently jsr run subcommand is used for running run-script in package.json. ref https://github.com/jsr-io/jsr-npm/blob/4f1544c12c61f596757120bbe7657d44860de1dd/src/bin.ts#L56

Does it make sense to change the behavior conditionally based on the given argument? (Or should we replace the existing behavior?)

opeolluwa commented 1 month ago

what does the run command do, exactly? Suppose I have a module with a default export someFunction(){}

Will it exec the some function, and pass the argument to it if any?

marvinhagemeister commented 1 month ago

Right now it only runs scripts defined in package.json.

opeolluwa commented 1 month ago

Oh, okay

opeolluwa commented 1 month ago

I'm looking forward to working on this, I'm going to need more explanation of the feature request

JLarky commented 1 month ago

With npm packages I can run commands like prettier without installing the package using commands like npx, bunx or yarn dlx, pnpm dlx. I wish there was a way to run jsr packages in node/bun like we have with "deno run"

jordanbtucker commented 3 weeks ago

I wish there was a way to run jsr packages in node/bun like we have with "deno run"

This will likely require buy in from npm and bun. You can get half way there with npm using a .npmrc with JSR as a scoped registry.

For example:

# This works
deno run jsr:@denorg/scrypt/cli hash mypassword

# This fails
npx @jsr/denorg__scrypt/cli hash mypassword

# This also fails
npx @jsr/denorg__scrypt hash mypassword

This is because npm expects @jsr/denorg__scrypt/cli to be a directory with a package.json file since it needs to check that for a bin field.

If you remove the cli part, then npm is able to find the package.json file that JSR generated, but it does not have a bin field, so npm doesn't know what file to run.

bunx doesn't even get as far as recognizing the scoped registry even though bun add does.

jordanbtucker commented 3 weeks ago

I suppose it might be possible for jsr to do an npm install into a cache location and then run the requested file.

jsr run @denorg/scrypt/cli hash mypassword

# Under the hood, jsr does something like this:
export NPM_PREFIX=~./jsr
npm install @jsr/denorg__scrypt
node $NPM_PREFIX/@jsr/denorg__scrypt/cli hash mypassword

I don't think that's really within the scope of JSR since it's not a runtime itself.

The better solution is for npx and bunx to support JSR packages.