vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
  • audit
  • bugs
  • build
  • cache
  • ci
  • config
  • create
  • deploy
  • diff
  • docs
  • exec-cache
  • exec-local
  • exec
  • help
  • init
  • install
  • list
  • login
  • logout
  • outdated
  • pack
  • ping
  • pkg
  • publish
  • query
  • registry
  • repo
  • run-exec
  • run
  • setup
  • skills
  • stage
  • token
  • trust
  • uninstall
  • update
  • version
  • view
  • whoami
  • Sides
  • Text
  • Interactive viewer
  • JSON
  • Exit status
  • Use with git
  • In CI
  • Options
  1. Client
  2. /
  3. Commands
  4. /
  5. diff

vlt diff

Usage:

Terminal
$ vlt diff lockfile
$ vlt diff lockfile <a>
$ vlt diff lockfile <a> <b>
$ vlt diff lockfile <a>..<b>
$ vlt diff lockfile <a>...<b>

Show what changed between two states of the project's vlt-lock.json as changes to the dependency graph: the packages added, removed and changed, the edits to each workspace's own dependencies, and what the lockfile records differently for a version that stayed. It compares lockfiles, not what is installed in node_modules.

Sides

CommandCompares
vlt diff lockfileHEAD with the working tree
vlt diff lockfile <a><a> with the working tree
vlt diff lockfile <a> <b><a> with <b>
vlt diff lockfile <a>..<b>the same, an empty end is HEAD
vlt diff lockfile <a>...<b>the merge base of <a> and <b> with <b>

A side is one of:

  • A git revision, such as a branch, a tag, a commit or HEAD~1: the lockfile at the project's path in that commit.
  • :0 to :3, a stage of the lockfile in the git index. vlt diff lockfile :2 :3 compares the two sides of a merge conflict.
  • A file, only when it is written as a path: it starts with ./, ../ or / (also .\, ..\, \ or a drive letter) and is relative to the current directory. /dev/null is a missing lockfile. A bare name such as old.json is read as a revision, so write ./old.json.

A side with no vlt-lock.json, such as a commit from before the lockfile was added, is shown as (no lockfile), and everything on the other side counts as added or removed. Any other problem is an error that names the side: a revision that does not exist, a shallow clone without that history, or a lockfile that is not valid JSON (merge conflict markers included) or has another lockfileVersion.

Text

On a terminal, or with --view=human, the command prints text:

Text
$ vlt diff lockfile HEAD~1 HEAD
vlt-lock.json  HEAD~1 (985cf29) → HEAD (02ade79)
changed 2 packages
2 → 2 lockfile entries, 1 workspace

Direct dependencies
    debug 4.3.4 → 4.3.7  patch, prod, spec 4.3.4 → 4.3.7  root

Transitive
    ms 2.1.2 → 2.1.3  patch  via debug  root

Line 1 names the two sides, line 2 counts the packages added, removed and changed (No changes. when the lockfiles are the same), and line 3 counts lockfile entries and workspaces. The sections follow, each only when it has rows:

  • Check first: what to read before approving a change: differences no other section names, changed lockfile options, and a version that stayed while its integrity, registry url, git commit, bins or platform changed.
  • Workspaces: workspaces added, removed or moved, with their dependencies.
  • Direct dependencies: every edit to a workspace's own dependencies, with the spec, the size of the version change, the workspaces, and the packages it brings or drops.
  • Transitive: the other packages replaced, added or removed, with the direct dependency they came with (via) and the workspaces they reach. Updates within the caret range of the old version are counted on one line.
  • Also: changes that leave the packages as they are, counted, such as packages re-keyed to other instance ids.

--all lists what the text folds into a count, the dependency changes of every package that moved, and the artifacts of every new version:

Text
$ vlt diff lockfile HEAD~1 HEAD --all
vlt-lock.json  HEAD~1 (985cf29) → HEAD (02ade79)
changed 2 packages
2 → 2 lockfile entries, 1 workspace

Direct dependencies
    debug 4.3.4 → 4.3.7  patch, prod, spec 4.3.4 → 4.3.7  root
      ms (prod)  spec 2.1.2 → ^2.1.3

Transitive
    ms 2.1.2 → 2.1.3  patch  via debug  root  for debug 4.3.7 (was 4.3.4)

Also
    artifacts of the 2 new versions:
      debug@4.3.7  https://registry.vlt.io/upstream/npm/  .tar.br  sha512-uPp5DdMDW4y+Y/UOKkISSUpDJk+Wswqw8c+lfT/+M7wyW1/kmYy6Hzskf7xpBselkKn7/poC7w+n8zf2pKgEQQ==
      ms@2.1.3  https://registry.vlt.io/upstream/npm/  .tar.br  sha512-HIi0+JymwtYoEoGiei07w61t95JkwRnzJs+Sgdjzz859UnhyrCpqMxNBxX7gqWkRQEVC7ZV3Cmh3hkUvzceh1A==

Interactive viewer

--view=tui opens the comparison in a fullscreen viewer, with three screens:

  • List: the text, a row at a time. Enter on a row that folds a count lists its members in place, one line each, and the cursor moves through them. a switches the list to the text of --all.
  • Search: / and part of a name lists the packages that match, the exact name first, then names that start with it, or the part after its scope. Enter opens one.
  • Package: the package In full: how each workspace reaches each version on each side, the dependency changes of each move and the artifact of each new version.
KeyAction
↑ ↓, j kmove
PgUp PgDnmove a screen
Home End, g Gfirst, last
Enterunfold a row, open a package
Escback
/search
a--all on or off
qquit
Ctrl+Cquit with status 130

The viewer starts only when --view=tui is on the command line, stdin and stdout are terminals of at least 60 columns and 10 rows, TERM is not dumb, no CI is detected and the text has rows. Anywhere else, also with tui set in vlt.json or VLT_VIEW, the command prints the text as --view=human does. The viewer draws on the terminal's alternate screen and leaves the scrollback as it was. q keeps the exit status the command set, also with --exit-code.

JSON

As with every vlt command, the output is JSON when it goes to a pipe or a file, or with --view=json. The object has schemaVersion: 1, the two sides (base and head), differs, the totals of the summary lines, and an entry in packages for every package that changed, with its versions, replacements and release types. The instance ids of each version are the dependency ids (DepIDs) that vlt query and vlt ls print in their JSON, so entries can be joined with them. --view=silent prints nothing. Other views are an error.

Exit status

Without --exit-code, the status is 0, or 1 on an error, as with every vlt command. With --exit-code:

StatusMeaning
0the lockfiles are the same
1the lockfiles differ
2the comparison failed, also for an unknown option or a broken config file

The lockfiles differ when anything in the two files differs, also a change that leaves every package as it is, such as a lockfile option.

--exit-code and --all count only when given on the command line. Set in vlt.json, under command.diff or as VLT_* environment variables, they do nothing: the project's vlt.json is part of the change under review and cannot turn the check off. --view and --color are read from the config as usual, so the lines below always pass --view.

Use with git

To have git diff print this text for the lockfile instead of its raw JSON changes, add to .gitattributes:

Text
vlt-lock.json diff=vlt-lock linguist-generated

linguist-generated also collapses the lockfile in GitHub's pull request diffs. Then set the driver, in the repository or with git config --global:

Terminal
git config diff.vlt-lock.command 'f() { p() { case "$1" in /*) printf "%s" "$1";; *) printf "./%s" "$1";; esac; }; n="${8:-$1}"; printf "%s\n" "$n"; vlt diff lockfile --view=human ${GIT_PAGER_IN_USE:+--color} "$(p "$2")" "$(p "$5")" 2>&1 || printf "%s: not compared\n" "$n"; }; f'

git diff uses it, and so do git show --ext-diff and git log -p --ext-diff. The function prints the lockfile's path, then the comparison of the two files git hands it, or not compared with the reason: a side that cannot be read does not end the whole git diff. For git difftool:

Terminal
git config difftool.vlt-lock.cmd 'f() { p() { case "$1" in /*) printf "%s" "$1";; *) printf "./%s" "$1";; esac; }; vlt diff lockfile --view=human "$(p "$LOCAL")" "$(p "$REMOTE")"; }; f'
git difftool -y -t vlt-lock <rev> <rev> -- vlt-lock.json

Both are POSIX shell functions.

In CI

On a GitHub pull request, HEAD is the merge commit and HEAD^1 the base branch, so two commits of history are enough:

YAML
- uses: actions/checkout@v4
  with:
    fetch-depth: 2
- run: vlt diff lockfile HEAD^1 HEAD --view=human --exit-code

The step prints what the pull request changes in the lockfile, and with --exit-code it fails when there is a change. Never compare origin/main or the base commit on a clone of depth 1: that history was not fetched, and the command fails with status 2 and a hint that the clone is shallow.

Options

FlagDescription
--exit-codeExit with 1 when the lockfiles differ, 0 when they are the same, and 2 on any failure
-a, --allList what the text folds into a count or leaves out
--view=<human|json|silent|tui>Output format; tui opens the interactive viewer

Previous: deployPrevious pageNext: docsNext page

On this page

  • Sides
  • Text
  • Interactive viewer
  • JSON
  • Exit status
  • Use with git
  • In CI
  • Options
Edit this page

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now