DEV Community

カワリミ人形
カワリミ人形

Posted on

Introduction to the use and configuration of deno-udd, a module version control tool for Deno

Deno does away with the package.json of the Node.js era, and introduces version control by putting the version number directly into the URL.
According to the style guide, it is recommended to load modules into a file called deps.ts and import them indirectly from there in the project.

Here is a tool, UDD, to help you manage the module version.

https://github.com/hayd/deno-udd

It seems that UDD stands for Update Deno Dependencies.

By the way, why does the Sauropod of the main image (↓) have a cow-like atmosphere?
logo
Raising and lowering its long neck to eat grass that grows directly on the ground is obviously useless, so I think the survival of the species is in jeopardy...

Installation

It is available at deno.land/x. Let's install it with deno install.

❯ deno install -A -f -n udd https://deno.land/x/udd@0.5.0/main.ts
(logs...)
✅ Successfully installed udd
/Users/kawarimidoll/.deno/bin/udd
Enter fullscreen mode Exit fullscreen mode

The default installation directory is ~/.deno/bin. Make sure that your PATH includes this directory.

If you run it with no arguments, you can see help.

❯ udd
usage: udd [-h] [--dry-run] [--test TEST] file [file ...]

udd: Update Deno Dependencies

Positional arguments:
  file          files to update dependencies

Optional arguments:
 -h, --help     show this help text
 --dry-run      test what dependencies can be updated
 --test TEST    command to run after each dependency update e.g. "deno test"
Enter fullscreen mode Exit fullscreen mode

Usage

udd checks the version of the modules in the file, and updates them all at once.

❯ # basic
❯ udd deps.ts
❯ # just check
❯ udd deps.ts --dry-run
❯ # multiple files
❯ udd main.ts util.ts
❯ # bulk
❯ udd *.ts
Enter fullscreen mode Exit fullscreen mode

Modules that do not contain a version number in the import URL will be skipped.

If you add the --test option, it will update the file after making sure that the test passes.

❯ udd deps.ts --test="deno test"
Enter fullscreen mode Exit fullscreen mode

Basically, you can run it without any configuration, so you can try it right away.
Another advantage is that if you no longer use this tool, there is no debt associated with it.

Where to get support

At the time of writing, the following registries have been updated.
Most of the commonly used ones in Deno are supported.

Configuration

As mentioned above, no configuration is required for the basic operation, but there are a few useful settings that can be found here.

Respecting Semver

Just like package.json in Node.js, you can fix the major version by adding a token.
This is specified in the hash of the module URL. This is a very interesting idea.

  • ^ Fix the major version
    • If the major version is 0, fix the minor version.
  • ~ Fix major and minor versions
    • If the major version is 0, the minor version will be updated.
  • <[version] Fix to a lower version (in semver) than the specified version.
  • = Do not update.

< requires you to specify the upper version limit, others refer to the version specification contained in the URL.

Use it with Velociraptor

This is a personal preference, but I like to use Velociraptor for all the commands used in the Deno project.

https://velociraptor.run

Add a configuration like this to velociraptor.yml.

scripts:
  deps:
    desc: Update dependencies with ensuring pass tests
    cmd: udd deps.ts --test="deno test -Ar"
Enter fullscreen mode Exit fullscreen mode

Now you can use vr deps to update the module while checking that the test passes.

This configuration is included in my template.

https://github.com/kawarimidoll/deno-dev-template

Closure

This will allow us to "test and update" and reduce the psychological and work load of updating modules.
As a result, the life of the project will be extended.

This is a translation of the following article.
Please leave comments if there are any mistakes in the translation.

https://zenn.dev/kawarimidoll/articles/d4e5ac8770e024

Discussion (0)