Upgrade NPM Package Dependencies — fast, safe, formatting-preserving.
A Go CLI that bumps dependency versions in an NPM package.json while
byte-preserving all original JSON formatting — whitespace, key order,
and quoting style stay exactly as you wrote them. Only the version
number inside each constraint string changes. Nothing else is touched.
Go rewrite of
rse/upd— the original JavaScript/Node.js CLI by Dr. Ralf S. Engelschall.
More focused demos: pattern filtering, greatest version, latest pinning.
- Formatting-preserving edits — surgically replaces only the version bytes inside each constraint string. Your indentation, key order, and quoting style are never touched.
- TOCTOU-safe atomic writes — stages a temp file, fsyncs it, verifies
the on-disk fingerprint hasn't changed since read, then atomically renames.
If another process (pnpm install, IDE formatter) edited
package.jsonduring the network-fetch window, the write is aborted and your file is left untouched. - Concurrent registry queries — fetches packuments in parallel with a configurable connection pool (default 8).
- Semantic version resolution — resolves to
dist-tags.latestby default, or the highest semver across all published versions with-g. - Pin
latesttags —-P/--pin-latestrewrites bare"latest"tags to their exact resolved semver (e.g."latest"→"7.7.4"). - Glob pattern filtering — update only matching dependencies, with
!-prefixed exclusions (e.g.upd react* !react-dom). - All four dependency sections —
dependencies,devDependencies,peerDependencies,optionalDependencies. - Character-level diff highlighting — shows exactly which characters changed in red/green.
- Embedded defaults — an
"upd"field inpackage.jsonsupplies default CLI arguments so you don't repeat yourself. - Styled CLI help — built with
charm.land/fang/v2+ Cobra: color-coded help, usage examples, man pages (upd man), and shell completions (upd completion <bash|zsh|fish>). - Single static binary — no runtime dependencies, no Node.js required.
# Install (requires Go 1.26.7+ with GOEXPERIMENT=jsonv2; the toolchain
# auto-downloads if needed)
GOEXPERIMENT=jsonv2 go install github.com/LarsArtmann/upd/cmd/upd@latest
# Dry run — show what would change without writing
upd -n
# Apply updates
updWhy
GOEXPERIMENT=jsonv2?upduses Go'sencoding/json/v2for byte-precise JSON editing. This flag will become unnecessary once the Go team stabilizes thejson/v2package in a future release.
Example output (upd -n -C):
┌─────────────────────────────────────┬──────────────┬──────────────┬─────────┐
│MODULE NAME │VERSION OLD │VERSION NEW │STATE │
├─────────────────────────────────────┼──────────────┼──────────────┼─────────┤
│express │^4.18.0 │^5.2.1 │updated │
│jest │^29.5.0 │^30.4.2 │updated │
│lodash │^4.17.20 │^4.18.1 │updated │
│typescript │^5.2.0 │^7.0.2 │updated │
└─────────────────────────────────────┴──────────────┴──────────────┴─────────┘
Download a tar.gz for your platform (Linux/macOS, amd64/arm64) with the
matching SHA256SUMS from the
GitHub Releases page.
GOEXPERIMENT=jsonv2 go install github.com/LarsArtmann/upd/cmd/upd@latestRequires Go 1.26.7+ (the toolchain auto-downloads if needed) with the
json/v2 experiment enabled.
# Run directly without installing
nix run github:LarsArtmann/upd
# Install to your profile
nix profile install github:LarsArtmann/updgit clone https://github.com/LarsArtmann/upd.git
cd upd
nix run .#build # or: GOEXPERIMENT=jsonv2 go build -o upd ./cmd/updRelease notes for every version live in CHANGELOG.md; published releases are on the GitHub Releases page.
upd [-h] [-V] [-q|-s] [-n|--dry-run] [-C] [-f <file>] [-r <registry>] [-g] [-a] [-c <concurrency>] [-P] [-t <timeout>] [--retries <n>] [--format <table|json>] [--verbose] [<pattern> ...]
| Flag | Long form | Description |
|---|---|---|
-h |
--help |
Show usage help. |
-V |
--version |
Show program version. |
-q |
--quiet |
Suppress output (no progress bar, no table, no warnings). |
-s |
--silent |
Alias for --quiet. |
-n |
--nop |
Dry run — do not modify package.json. |
--dry-run |
Alias for --nop. |
|
-C |
--no-color |
Disable ANSI colors in output. --noColor is a deprecated alias (removed in v2). |
-f |
--file |
Path to package config (default: package.json). |
-r |
--registry |
NPM registry base URL (default: registry.npmjs.org). |
-g |
--greatest |
Use greatest published version instead of latest tag. |
-a |
--all |
Show all packages, not just updated ones. |
-c |
--concurrency |
Concurrent NPM registry connections (default: 8). |
-P |
--pin-latest |
Pin bare latest tags to exact semver. |
-t |
--timeout |
Per-request timeout (default: 20s). |
--retries |
Max retries for transient 429/5xx failures (default: 3). | |
--format |
Output format: table (default) or json for CI/scripts. --json is a deprecated alias (removed in v2). |
|
--verbose |
Show full error chains in the error detail block. | |
<pattern> |
Glob pattern for dependency names. ! prefix excludes. |
Color auto-detection: Colors are automatically disabled when the NO_COLOR
environment variable is set (see no-color.org) or when
stdout is not a terminal (piped/redirected). Use -C to force-disable.
Examples:
upd # update all dependencies
upd -n # dry run (preview changes)
upd react* # only update packages matching "react*"
upd react* !react-dom # update react packages except react-dom
upd -g # use greatest version (include pre-releases)
upd -P # pin "latest" tags to exact versions
upd -c 16 lodash* # 16 concurrent connections, only lodash
upd -f alt.json -n # preview changes to alt.jsonupd parses package.json with a streaming JSON decoder that tracks
byte offsets. When a version needs updating, it splices only the version
bytes out of the raw file and inserts the new ones. The rest of the file
— every space, newline, key ordering, and quoting choice — is preserved
exactly. No re-serialization, no formatter arguments, no diffs to resolve.
Each dependency constraint is classified by a regex:
- Upgradable — strings starting with a digit, optionally preceded by
^or~(e.g.1.2.3,^1.2.3,~2.3.4,1.x). The prefix is preserved on update:^1.2.3→^2.0.0. - Skipped — comparator ranges (
>=1.0.0), tags (latest), git/file URLs — anything containing<>|=. Use-Pto opt-in to pinninglatest. - Ignored — names that don't match any supplied glob pattern.
After resolving the target version from the NPM registry, a semver
comparison guards against downgrades: if the resolved version isn't
actually newer, the dependency is marked kept.
The write path uses go-atomic-write
to prevent data loss when another process edits package.json during the
network-fetch window. It stages a temp file, fsyncs it, acquires a
cross-platform file lock, verifies the on-disk fingerprint hasn't changed
since read, then atomically renames. On mismatch it aborts with
ErrConcurrentModification — the file is untouched.
See docs/atomic-writes.md for the full step-by-step breakdown and flow diagram.
Add an "upd" field to your package.json to supply default arguments
that are prepended to CLI flags:
{
"upd": ["react*", "!react-dom", "-c", "16"],
"dependencies": {
"react": "^18.0.0",
"react-dom": "^18.0.0",
"lodash": "^4.17.20"
}
}Now upd is equivalent to upd react* !react-dom -c 16. CLI flags
override or supplement these defaults. The field accepts a string or an
array.
upd reads .npmrc from your home directory and from the directory of the
package file (project-local wins). It consumes:
registry=<url>— default registry when--registry/UPD_REGISTRYis not set.//<registry-host>/:_authToken=<token>— sent as a bearer token for private registries. Token values are never printed or logged.
Malformed or unsupported entries (e.g. legacy _auth, scoped
@scope:registry) produce a warning; they never silently break auth.
Every public flag can also be set via an environment variable with the
UPD_ prefix. CLI flags always override environment variables.
| Env var | Equivalent flag |
|---|---|
UPD_REGISTRY |
--registry |
UPD_FILE |
--file |
UPD_TIMEOUT |
--timeout |
UPD_CONCURRENCY |
--concurrency |
UPD_RETRIES |
--retries |
UPD_QUIET |
--quiet |
UPD_NOP |
--nop |
UPD_DRY_RUN |
--dry-run |
UPD_NO_COLOR |
--no-color |
UPD_GREATEST |
--greatest |
UPD_ALL |
--all |
UPD_PIN_LATEST |
--pin-latest |
UPD_JSON |
--json (deprecated; use UPD_FORMAT) |
UPD_FORMAT |
--format |
UPD_VERBOSE |
--verbose |
For example:
UPD_REGISTRY=https://my-registry.example.com upd -nGenerate shell completions for bash, zsh, or fish:
upd completion bash > /etc/bash_completion.d/upd
upd completion zsh > /usr/share/zsh/site-functions/_upd
upd completion fish > ~/.config/fish/completions/upd.fish| Code | Meaning |
|---|---|
0 |
Success — all dependencies resolved without errors. |
1 |
Failure — package not found, partial resolution errors, IO error, or malformed input. |
75 |
Registry unavailable — transient 5xx/timeout from the NPM registry. Retryable (EX_TEMPFAIL). |
In CI, check for exit 75 to decide whether to retry the job. Exit 1 means something needs human attention (typo in dependency name, malformed JSON, etc.).
ERROR: package not found in NPM registry (exit 1)
The package name in package.json doesn't exist on the registry. Check for
typos, check if the package was unpublished, or verify you're using the correct
registry (-r/--registry).
ERROR: NPM registry is unavailable (exit 75)
The registry returned a server error (5xx) or timed out. This is transient —
re-run upd after a few seconds. If using a private registry, verify it's
running and accessible. Use --retries to increase the number of retry attempts.
ERROR: package configuration file was modified concurrently
Another process (pnpm install, IDE auto-save, formatter) edited package.json
while upd was fetching versions. Your file was not changed. Simply re-run upd.
ERROR: invalid JSON in package configuration file
Your package.json has malformed JSON. Run pnpm dlx jsonlint package.json or
node -e "JSON.parse(require('fs').readFileSync('package.json','utf8'))" to
find the syntax error.
Progress bar is garbled or leaves artifacts
The progress bar is cleared using a fixed-width reset. If your terminal is
narrower than 80 characters, use -q (quiet mode) to suppress it.
Colors appear in piped output
Colors are auto-disabled when stdout is not a terminal or NO_COLOR is set.
If you still see colors, ensure no tool in your pipeline (e.g. script) is
emulating a TTY. You can always force-disable with -C.
This repo uses Nix flakes for all build automation:
nix run .#build # build to bin/upd
nix run .#test # go test ./... -v -count=1
nix run .#lint # go vet + go build + golangci-lint
nix run .#run -- <args> # go run ./cmd/upd <args>
nix flake check # validate the flakePlain Go equivalents (requires GOEXPERIMENT=jsonv2):
export GOEXPERIMENT=jsonv2 # required — uses encoding/json/v2
go build ./cmd/upd
go test -race ./...
go vet ./...Contributing? See CONTRIBUTING.md for the nix-first workflow and conventions.
nix run .#demo # render GIF locally to demo/
nix run .#demo -- --publish # render + upload to vhs.charm.sh cloud- Original:
rse/upd— an npm package written in JavaScript/Node.js by Dr. Ralf S. Engelschall. - This project: a complete Go rewrite by Lars Artmann, keeping the same CLI behavior and philosophy while leveraging Go's performance, compile-time type safety, and single-binary distribution.
MIT — Copyright © 2015-2026 Dr. Ralf S. Engelschall, Copyright © 2026 Lars Artmann.
See LICENSE for the full text.
