πŸ¦• Molt

CI codecov

[!WARNING]
Molt is still being developed actively. The API is not stable yet and may change frequently.

Molt is a Deno module to bump versions in import specifiers, like udd, but with a few different goals:

Consistent - Molt uses deno_graph for dependency resolution, and utilizes fetch redirects for unversioned dependencies to get latest versions. This should make it support as many module registries as Deno runtime does, with a minimum maintenance cost.

Module-first - The core logic is provided as versatile functions in a Deno module, which enables you to write the best scripts for your use cases.

Git-friendly - The operations can be easily divided into logical groups for subsequent git commits. A submodule and CLI for git operations are also provided.

Usage

Deno Module

API Reference

Examples

Update all dependencies in a module and write the changes to local files
import { collect, writeAll } from "https://deno.land/x/molt@{VERSION}/mod.ts";

const updates = await collect("./mod.ts", { importMap: "./deno.json" });

await writeAll(updates, {
  onWrite: (file) => console.log(`πŸ’Ύ ${file.specifier}`),
});
Update all dependencies in a module and commit the changes to local git repository
import { collect, commitAll } from "https://deno.land/x/molt@{VERSION}/mod.ts";

const updates = await collect("./mod.ts", { findImportMap: true });

await commitAll(updates, {
  groupBy: (dependency) => dependency.name,
  composeCommitMessage: ({ group, version }) =>
    `build(deps): bump <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>g</mi><mi>r</mi><mi>o</mi><mi>u</mi><mi>p</mi></mrow><mi>t</mi><mi>o</mi></mrow><annotation encoding="application/x-tex">{group} to </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8095em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">ro</span><span class="mord mathnormal">u</span><span class="mord mathnormal">p</span></span><span class="mord mathnormal">t</span><span class="mord mathnormal">o</span></span></span></span>{version!.to}`,
  postCommit: (commit) => console.log(commit.message),
});

CLI

Although it is encouraged to write your own scripts, a pre-built CLI tool is also provided as cli.ts for convenience or a reference implementation, which is supposed to cover most of the use cases.

Installation (optional)

The molt CLI can be installed globally with the following command, for example:

deno install --allow-env --allow-read --allow-write --allow-net --allow-run=git,deno\
--name molt https://deno.land/x/molt@{VERSION}/cli.ts

Alternatively, you may prefer to run the remote script directly through deno task for better security or reproducibility:

{
  "tasks": {
    "update": "deno run --allow-env --allow-read --allow-write=. --allow-run=git,deno --allow-net=deno.land https://deno.land/x/molt@{VERSION}/cli.ts ./**/*.ts",
    "update:commit": "deno task -q update --commit --pre-commit=fmt,lint,test"
  }
}

Usage

> molt --help
Usage: molt <modules...>

Description:

  Check updates to dependencies in Deno modules

Options:

  -h, --help               - Show this help.                                            
  -v, --version            - Print version info.                                        
  --import-map   <file>    - Specify import map file                                    
  -w, --write              - Write changes to local files                               
  -c, --commit             - Commit changes to local git repository                     
  --pre-commit   <tasks>   - Run tasks before each commit            (Depends: --commit)
  --post-commit  <tasks>   - Run tasks after each commit             (Depends: --commit)
  --prefix       <prefix>  - Prefix for commit messages              (Depends: --commit)
  --summary      <file>    - Write a summary of changes to file                         
  --report       <file>    - Write a report of changes to file

[!Note]
Molt CLI automatically uses import maps defined in deno.json or deno.jsonc if available.
You can’t, however, use import maps as entrypoints.

Examples

Check for updates
> molt mod.ts 
πŸ’‘ Found updates:

πŸ“¦ deno.land/std 0.200.0 => 123.456.789
  lib.ts 0.200.0
  mod.ts 0.200.0

πŸ“¦ deno.land/x/deno_graph 0.50.0 => 123.456.789
  mod.ts 0.50.0

πŸ“¦ node-emoji 2.0.0 => 123.456.789
  mod.ts 2.0.0
Write changes to files
> molt mod.ts --write
πŸ’‘ Found updates:
    ...

πŸ’Ύ lib.ts
πŸ’Ύ mod.ts
Commit changes to git
> molt mod.ts --commit --pre-commit=test --prefix :package: --summary title.txt --report report.md
πŸ’‘ Found updates:
    ...

πŸ“ :package: bump deno.land/std from 0.200.0 to 123.456.789
πŸ“ :package: bump deno.land/x/deno_graph from 0.50.0 to 123.456.789
πŸ“ :package: bump node-emoji from 2.0.0 to 123.456.789

Limitations

The following limitations are (currently) imposed by the design of Molt:

  • Dependencies are always updated to the latest version. No version constraints are supported.
  • Dependencies in import specifiers are only targeted.

See issues for other known limitations.

References

Molt is inspired by prior works such as

and of full respect to the authors.