hasundue / molt

Update dependencies the Deno way
https://jsr.io/@molt
MIT License
56 stars 4 forks source link

Duplicate version number in deno.jsonc #192

Open kawarimidoll opened 1 week ago

kawarimidoll commented 1 week ago

Problem

molt --write duplicates version number in deno.jsonc in specific cases.

    "@std/assert": "jsr:@std/assert@0.226.0@0.226.0"

Conditions:

Steps to reproduce

  1. Create these 2 files

deno.jsonc 👇

{
  "imports": {
    "@std/assert": "jsr:@std/assert"
  },
  "tasks": {
    "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=deno --allow-net=jsr.io jsr:@molt/cli main_test.ts deno.jsonc --write"
  }
}

main_test.ts 👇

import { assertEquals } from "@std/assert";

function add(a: number, b: number): number {
  return a + b;
}

Deno.test(function addTest() {
  assertEquals(add(2, 3), 5);
});
  1. Run deno task update
❯ deno task update
Task update deno run --allow-env --allow-read --allow-write=. --allow-run=deno --allow-net=jsr.io jsr:@molt/cli main_test.ts deno.jsonc --write
📦 @std/assert  => 0.226.0
  deno.jsonc

💾 deno.jsonc
  1. Then version specifier in deno.jsonc is duplicated
❯ cat deno.jsonc
{
  "imports": {
    "@std/assert": "jsr:@std/assert@0.226.0@0.226.0"
  },
  "tasks": {
    "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=deno --allow-net=jsr.io jsr:@molt/cli main_test.ts deno.jsonc --write"
  }
}

Expected behavior

Add just one version specifier.

Deno version

❯ deno --version
deno 1.44.4 (release, aarch64-apple-darwin)
v8 12.6.228.9
typescript 5.4.5

OS version

macOS Sonoma 14.5

hasundue commented 1 week ago

Thanks for reporting :pray: It is a bug, probably in @molt/core.

But I would not create a patch release for this, since it only happens in a limited and avoidable case. The next minor release is including rewrite of the code base of @molt/core, which should fix this problem as well.

To avoid this problem, you may

{
  "imports": {
    "@std/assert": "jsr:@std/assert@^0.226.0"
  },

This is done automatically by deno add jsr:@std/assert, which is the officially-recommended way to add a dependency to your project.

If your deno.json (or deno.jsonc) contains all your imports, you don't have to pass .ts files that refer to them. It just slows down the process.

kawarimidoll commented 1 week ago

@hasundue You're right, this is a sort of an edge case. I will use the way you recommended. Thank you for replying! I leave this issue open since this seems to be a part of Milestone. Please close this whenever you want.