denoland / dnt

Deno to npm package build tool.
MIT License
1.22k stars 37 forks source link

Values that startsWith("jsr:") in the valueToUrl() should also be returned as is #404

Open Gumball12 opened 5 months ago

Gumball12 commented 5 months ago

Deno can use modules that exist in the JSR registry as follows:

import { camelCase } from "jsr:@luca/cases";

camelCase("hello word"); // "helloWord"

For this purpose, dnt should return paths starting with jsr: as the are.

// lib/utils.ts

export function valueToUrl(value: string) {
  const lowerCaseValue = value.toLowerCase();
  if (
    lowerCaseValue.startsWith("http:") ||
    lowerCaseValue.startsWith("https:") ||
    lowerCaseValue.startsWith("npm:") ||
    lowerCaseValue.startsWith("node:") ||
-    lowerCaseValue.startsWith("file:")
+    lowerCaseValue.startsWith("file:") ||
+    lowerCaseValue.startsWith("jsr::")
  ) {
    return value;
  } else {
    return path.toFileUrl(path.resolve(value)).toString();
  }
}

This allows mappings to also handle the jsr module.

await build({
  mappings: {
    "jsr:@luca/cases": {
      // If add `@jsr:registry=https://npm.jsr.io` to .npmrc,
      // it can import module `@luca/cases` as shown below
      // https://jsr.io/docs/npm-compatibility#advanced-setup
      name: "@jsr/luca__cases",
    },
  },
});
Gumball12 commented 5 months ago

I just saw a PR from a month ago about this. I'll close this issue, but it seems like this open source is dead because it hasn't been resolved yet 😢

UrielCh commented 4 months ago

Hi,

I have start moving to JSR, and I confime that the current dnt is not JSR frendly.

I migrate a first package named deno-logger to JSR so the package is available using:

for this one have no issue.

But now that I want to migrate my midjourney client that use x/logger, I have to hot replace my dependency to keep my dnt script working so the package is available using:

My deployement script for dnt is now overcomplicated to let me use a JSR package:

  const depsts = Deno.readTextFileSync("deps.ts");
  const depstsPatch = depsts.replaceAll(
    "jsr:@deno-lib/logger@1.1.5",
    "https://deno.land/x/logger@v1.1.5/logger.ts",
  );

  Deno.writeTextFileSync("deps.ts", depstsPatch);

then I rollback the dep.ts

so I can keep the original mapping:

"https://deno.land/x/logger@v1.1.5/logger.ts": {
        name: "@denodnt/logger",
        version: "1.1.5",
        peerDependency: false,
      },

so @dsherret can you give us an hint ?