dnt icon indicating copy to clipboard operation
dnt copied to clipboard

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

Open Gumball12 opened this issue 1 year ago • 3 comments

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 avatar Apr 27 '24 07:04 Gumball12

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 😢

Gumball12 avatar Apr 27 '24 07:04 Gumball12

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:

  • https://deno.land/x/[email protected]
  • https://www.npmjs.com/package/@denodnt/logger
  • https://jsr.io/@deno-lib/logger

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:

  • https://deno.land/x/[email protected]
  • https://www.npmjs.com/package/midjourney-discord-api
  • https://jsr.io/@u4/midjourney

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/[email protected]",
    "https://deno.land/x/[email protected]/logger.ts",
  );

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

then I rollback the dep.ts

so I can keep the original mapping:

"https://deno.land/x/[email protected]/logger.ts": {
        name: "@denodnt/logger",
        version: "1.1.5",
        peerDependency: false,
      },

so @dsherret can you give us an hint ?

UrielCh avatar May 22 '24 07:05 UrielCh

Looks like version 0.41.2 started preserving values starting with jsr:

https://github.com/denoland/dnt/blob/0.41.2/lib/utils.ts#L98

The mapping still isn't working for me though so I opened a issue about that specifically (https://github.com/denoland/dnt/issues/437).

AlexanderOMara avatar Nov 17 '24 04:11 AlexanderOMara