jsr icon indicating copy to clipboard operation
jsr copied to clipboard

Allow users to use package.json without needing separate deno/jsr.json

Open jhechtf opened this issue 1 year ago • 3 comments

Looking into using the JSR registry, I tried to manually push a test package that I plan on building primarily for node. As such, I used the package.json file to declare things like name, version, and exports. Trying to push this failed, obviously.

This means I need to add either a jsr.json or deno.json, which duplicates the name, version, and exports. I feel this is cumbersome, especially because I often use some variety of tooling to automate version bumping my package.json file. I don't personally know of any tools (beyond ones I've written and since deprecated) that worked with deno.json or jsr.json. This puts me in a weird spot where I'd like to use the jsr registry, but I find the idea of needing to sync between package.json and jsr.json tedious. Maybe not tedious enough to not use it, but tedious enough I felt it necessary to create an issue on your github.

jhechtf avatar May 23 '24 06:05 jhechtf

Maybe jsr CLI could bump the version in jsr.json, using the same version in package.json, or if the project already has a package.json, JSR could use name, version and exports from there =)

fdaciuk avatar Jun 04 '24 13:06 fdaciuk

I could see if the npx jsr client preferred the package.json over the jsr.json and copied it; deno publish would obviously prefer the deno.json and then jsr.json. However, people would have to make sure to publish the copy over from the package.json to the jsr.json after running the npx jsr step in the event that it copied over the package.json version, which I'm not huge on.

Perhaps there could be a jsr sync command, which looks for package.json or deno.json and copies over the name/version. This way in say a package.json script we could have something like the following, which would auto-sync the versions.

{
  "name": "@scoped/package-name",
  "version": "1.0.0-rc",
  "scripts": {
    "prepublish": "npx jsr sync",
    "publish": "npx jsr publish"
  }
}

I'd prefer it that npx jsr just used the package.json, but I'd be willing to work with this.

jhechtf avatar Jun 04 '24 18:06 jhechtf

Possibly autogenerated (https://github.com/jsr-io/jsr/issues/544#issuecomment-2130255153) jsr.json should always have priority over deno.json:

jq '{ name, version, exports }' package.json >jsr.json

wojpawlik avatar Jun 05 '24 10:06 wojpawlik

Here is my command to move "version" and "name" fields from package.json to jsr.json. It doesn't overwrite other preexisting fields in jsr.json such as "$schema" (btw, I highly recommend adding "$schema": "https://jsr.io/schema/config-file.v1.json", to your jsr.json) or "publish" which could be quite different from the usual "publish" in package.json.

jq -s '.[1] + {name: .[0].name, version: .[0].version}' package.json jsr.json > temp.json && mv temp.json jsr.json

Or also you can prefix the name:

jq -s '.[1] + {name: ("@nikelborm/" + .[0].name), version: .[0].version}' package.json jsr.json > temp.json && mv temp.json jsr.json

nikelborm avatar Dec 29 '24 06:12 nikelborm