jsr-io / jsr

The open-source package registry for modern JavaScript and TypeScript
https://jsr.io
MIT License
2.46k stars 111 forks source link

JSR is not transpiling `npm:` specifiers in existing `.d.ts` files for Node compat #367

Closed lucacasonato closed 6 months ago

lucacasonato commented 6 months ago

Failing NPM tarball test spec (PR that adds this spec format still WIP).

# foo.js
import { html } from "npm:lit@^2.2.7";
await import("npm:lit@^2.2.7")

# bar.mjs
import { html } from "npm:lit@^2.2.7";
await import("npm:lit@^2.2.7")

# baz.ts
import { html } from "npm:lit@^2.2.7";
await import("npm:lit@^2.2.7")

# fizz.d.ts
import { html } from "npm:lit@^2.2.7";
await import("npm:lit@^2.2.7")

# jsr.json
{
  "name": "@scope/foo",
  "version": "0.0.1",
  "exports": {
    "./foo": "./foo.js",
    "./bar": "./bar.mjs",
    "./baz": "./baz.ts",
    "./fizz": "./fizz.d.ts"
  }
}

# npm:lit@^2.2.7

# output
== /bar.mjs ==
import { html } from "lit";
await import("lit")

== /baz.js ==
await import("lit");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHA6Ly9qc3IudGVzdC9Ac2NvcGUvZm9vLzAuMC4xL2Jhei50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBodG1sIH0gZnJvbSBcIm5wbTpsaXRAXjIuMi43XCI7XG5hd2FpdCBpbXBvcnQoXCJucG06bGl0QF4yLjIuN1wiKVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE1BQU0sTUFBTSxDQUFDIn0=

== /fizz.d.ts ==
import { html } from "npm:lit@^2.2.7";
await import("npm:lit@^2.2.7")

== /foo.js ==
import { html } from "lit";
await import("lit")

== /jsr.json ==
{
  "name": "@scope/foo",
  "version": "0.0.1",
  "exports": {
    "./foo": "./foo.js",
    "./bar": "./bar.mjs",
    "./baz": "./baz.ts",
    "./fizz": "./fizz.d.ts"
  }
}

== /package.json ==
{
  "name": "@jsr/scope__foo",
  "version": "0.0.1",
  "homepage": "http://jsr.test/@scope/foo",
  "type": "module",
  "dependencies": {},
  "exports": {
    "./foo": "./foo.js",
    "./bar": "./bar.mjs",
    "./baz": "./baz.js",
    "./fizz": "./fizz.d.ts"
  },
  "_jsr_revision": 7
}
dtinth commented 6 months ago

@lucacasonato Thanks so much for fixing this! ❤️

As a package author, do we have to publish a new version for this fix to be reflected in the npm distribution?

lucacasonato commented 6 months ago

No- it will be reflected automatically

dtinth commented 6 months ago

I tried removing my node_modules, ran pnpm store prune, and did a reinstall using pnpm i. Seems like I still get the version of package that has been built before this fix. Maybe there is a cache somewhere keeping the stale version around 🤔, which I guess kinda makes sense because in npm’s world there is an assumption that a package version’s tarball content would never ever change.

So I had to release a new version to JSR and install the new version. This works fine now. 👍

Thanks again for the fix!