Skip to content

About

Helper tool for automating Node.js package releases across VersaTiles repositories.

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

NPM version NPM downloads Code coverage CI status License

VersaTiles Release Tools

Tools used for:

Installation

npm i -D @versatiles/release-tool

configure scripts

You need to configure the scripts in the package.json:

{
  "scripts": {
    "check": "npm run lint && npm run build && npm run test",
    "prepack": "npm run build && npm run doc",
    "release": "vrt release-npm",
    ...
  },
  ...
}
  • scripts.check is required by the release command. Here you can lint, build and test your code.
  • scripts.prepack is recommended to ensure that all files are up-to-date before releasing. Here you can build code and documentation.
  • scripts.release is recommended to make it easy to release a new version.

Holding back dependencies

By default deps-upgrade upgrades every dependency to its latest version. Dependencies that must not follow can be declared in the vrt.depsUpgrade.ignore field of your package.json:

{
  "vrt": {
    "depsUpgrade": {
      "ignore": ["path-to-regexp@<7.0.0", "typescript"]
    }
  }
}
  • An entry without a range ("typescript") blocks every upgrade of that package.
  • An entry with a semver range ("path-to-regexp@<7.0.0") only blocks versions outside that range, so patches and minor releases keep coming in. Such a package is upgraded within the range that is already declared in your package.json, e.g. "^6.3.0" is upgraded to the latest 6.x.

The same rules can be given as an object, and on the command line:

"ignore": { "path-to-regexp": "<7.0.0", "typescript": true }
vrt deps-upgrade --ignore 'path-to-regexp@<7.0.0' --ignore typescript

Command line entries are merged into the configured ones and win in case of a conflict.

Trimming a noisy dependency graph

For repos with high fan-out, deps-graph accepts repeatable globs to collapse or drop nodes:

# Merge all region scrapers into a single labelled node ("regions/*.ts (24 files)").
vrt deps-graph --collapse-dir 'src/regions/*.ts'

# Drop trivial barrels and stubs from the graph entirely.
vrt deps-graph --exclude '**/_planned.ts' --exclude '**/index.ts'

# Lay out the files of selected directories left-to-right (TB, BT, LR or RL).
vrt deps-graph --subgraph-direction 'src/lib=LR' --subgraph-direction 'src/commands=RL'

# Replace edges from several files in src/commands/ to the same target with one edge from the directory.
vrt deps-graph --merge-outgoing 'src/commands'

# Replace edges into src/core/ with one edge per importing directory, e.g. for a logger that every file imports.
vrt deps-graph --merge-incoming 'src/core'

# Draw imports of barrel files (src/lib/*/index.ts) as edges to their directory.
vrt deps-graph --barrel 'src/lib/*'

--merge-incoming suits modules that almost every file imports, such as logging and errors, once they have a directory of their own next to the others. Each directory around it then has one edge into it, instead of one edge per file. Files directly in a common parent directory, such as src/index.ts, keep their own edge, and so do files in a directory that contains the merged one.

Tests and mocks (*.test.*, *.spec.*, *.mock.*, __tests__/, __mocks__/), type declarations (*.d.ts) and node_modules are always left out.

Instead of passing long lists of flags, you can put the options into a vrt.config.json in your project directory. The keys are the flag names; CLI flags are added to these values:

{
  "deps-graph": {
    "barrel": ["src/lib/*"],
    "collapse-dir": ["src/themes/*", "src/omt/layers/*"],
    "exclude": ["**/_planned.ts"],
    "merge-incoming": ["src/core"],
    "merge-outgoing": ["src/*"],
    "subgraph-direction": ["src/lib=LR"]
  }
}

The svg option (see below) can be set there too, as a string: "svg": "docs/dependency-graph.svg".

Path aliases

Imports using path aliases are resolved without configuration:

  • aliases in the paths of the project's tsconfig.json, e.g. @/utils/x.js, and
  • in SvelteKit projects, $lib and the aliases from svelte.config.js, read from the generated .svelte-kit/tsconfig.json (run svelte-kit sync first). Without that file, $lib points to src/lib.

The project's tsconfig.json is also used when parsing TypeScript. With isolatedModules or verbatimModuleSyntax, imports that are only used as types appear in the graph too, unless they are written as import type.

Svelte components

.svelte files are compiled with the compilerOptions from the project's svelte.config.js, e.g. experimental.async. If a file still can not be analyzed, deps-graph warns and shows it without its imports, instead of aborting.

Dependency graph of a workspace

By default, deps-graph analyzes the files in src. With --include (repeatable), you choose other directories or files instead. At the root of an npm workspace, this draws one graph over all packages, with a subgraph per package:

{
  "deps-graph": {
    "include": ["packages/*/src"],
    "merge-outgoing": ["packages/*/src"]
  }
}

Imports between the packages (e.g. @scope/core/map_renderer) are resolved through the exports field of their package.json. If they point to the build output of a package, they are mapped to its source files:

  • dist/utils/x.js (or .d.ts, .mjs, …) is mapped to src/utils/x.ts (or .tsx, .js, .svelte, …). For packages built with svelte-package, src/lib is tried too. outDir and rootDir in the package's tsconfig.build.json or tsconfig.json override dist and src.
  • If the package is bundled into a single file, an import of the package itself is mapped to src/index.ts.
  • If a package is not built yet, its imports are mapped the same way.

All other options match against the full paths, e.g. packages/core/src/lib.

Imports missing in the graph

deps-graph warns about imports that can not become edges, so an incomplete graph doesn't go unnoticed:

  • local imports that could not be resolved, e.g. a broken relative path or an unknown alias, and
  • imports that resolve to source files outside of include, e.g. to dist/ of another workspace package, or to a directory you forgot to include.

The ten most frequent targets are listed; with -v, all of them are listed with the importing files. npm packages, assets outside of include and modules provided by SvelteKit and Vite ($app/*, $env/*, ./$types, virtual:*) are ignored.

Dependency graph as SVG

GitHub renders Mermaid without the ELK layout, and npmjs.com doesn't render Mermaid at all. With --svg, deps-graph lays out the graph with ELK, writes it as an SVG file and prints a Markdown image link instead of Mermaid markup:

vrt deps-graph --svg docs/dependency-graph.svg | vrt doc-insert README.md '## Dependency Graph'

The output is an image that links to the raw SVG file: [![Dependency graph](docs/dependency-graph.svg)](docs/dependency-graph.svg?raw=true). The paths are relative, so GitHub always shows the graph of the current commit. The SVG adapts to light and dark mode.

In the README the graph is a static image. Clicking it opens the SVG itself, which is interactive: hovering a file highlights its outgoing dependencies in orange and its incoming ones in blue, including the connected files, and dims all other connections. Hovering a directory box or its label does the same for all connections that cross the directory's border, including those of files in subdirectories and those merged by --merge-outgoing; connections inside the directory stay visible. This is plain CSS, without scripts, so it also works on raw.githubusercontent.com.

On npmjs.com, a README must show the graph of its own version, even after the file changes in later commits. vrt release-npm takes care of that:

  1. It runs npm publish with the environment variable VRT_RELEASE_VERSION set to the new version. When prepack regenerates the docs, deps-graph prints a link to the file at the release tag instead, e.g. https://raw.githubusercontent.com/<owner>/<repo>/v1.2.3/docs/dependency-graph.svg. The published package contains this link.
  2. After publishing, it turns these links in all changed Markdown files back into relative links, then commits and creates the tag. Existing tags are never overwritten, so a linked file can't change later.

With vrt release-npm --no-publish the package is not published locally: the command only raises the version, updates the changelog, tags, pushes and creates the GitHub release, and needs no npm login. A CI workflow started by the tag then runs npm publish. For pinned links it has to set VRT_RELEASE_VERSION itself, e.g. VRT_RELEASE_VERSION="${GITHUB_REF_NAME#v}" npm publish.

This requires a public GitHub repository in the repository field of package.json, and a prepack script that regenerates the README (e.g. npm run build, which runs npm run doc). --subgraph-direction is not supported for SVG output.

Treemap as SVG

vrt treemap renders a treemap from JSON on stdin, e.g. the composition of a bundle. Like deps-graph --svg, it writes an SVG file and prints a linked image, followed by an optional caption. The image links and release pinning work the same way:

node scripts/bundle-sizes.js | vrt treemap --svg assets/bundle-treemap.svg | vrt doc-insert README.md '## Bundle Composition'

The input contains the boxes as a tree. A node has a size or children; with "unit": "bytes" sizes are shown as B, KB or MB:

{
  "title": "Bundle composition",
  "caption": "**105 KB** raw, **30.7 KB** gzipped",
  "unit": "bytes",
  "children": [
    { "name": "color", "children": [{ "name": "color.ts", "size": 4198 }, { "name": "parser.ts", "size": 3789 }] },
    { "name": "index.ts", "size": 912 }
  ]
}

Every top-level node gets its own color, and groups show their name and total size. Labels that don't fit are shortened or omitted, but every box has a tooltip with its path, size and share, which is shown when the SVG is opened directly.

Bundle composition

vrt bundle-treemap is treemap with the measuring included: it attributes every byte of a bundle to the source file it came from, groups the files by directory and renders the result. It needs nothing but the source map the build already emits — no bundler plugin, no extra dependency:

vrt bundle-treemap dist/bundle.js --svg assets/bundle-treemap.svg | vrt doc-insert README.md '## Bundle Composition'

The bundle or its source map can be given; the other one is found next to it, or through the sourceMappingURL comment at the end of the bundle — including a map inlined there as data: URI. --map points at it explicitly.

The caption below the image states the raw and the gzipped size of the whole bundle and the number of modules in it. Bytes that no mapping covers — line breaks, and whatever the bundler added on its own — are shown as (unmapped), so the boxes add up to the size of the file.

Two options control how much detail a box holds. --depth sets how many directory levels become groups (default: 1, so src/color/parser.ts lands in a color box); --min-size folds everything below a number of bytes into one "other (N files)" entry per group, which by default is 0.5 % of the bundle. A README wants the shape of the bundle — which directory costs what, and which few files dominate it — not 85 unreadable rectangles.

Without --svg, the treemap is printed as JSON instead of being rendered, which is the input format of vrt treemap. That is the way to adjust it before rendering:

vrt bundle-treemap dist/bundle.js | jq '.title = "What ships to the browser"' | vrt treemap --svg assets/bundle.svg

Release workflow

vrt release splits a release into a local half and a remote half. Locally, it checks the repository, raises the version in every package.json (all workspaces share one version), adds the section generated from the commits to CHANGELOG.md, commits release: vX.Y.Z, and pushes the commit and its tag atomically. It never publishes. The tag starts the project's release workflow, which tests the tagged commit, waits for an approval, publishes the tested tarballs to npm with trusted publishing and provenance, and creates the GitHub release. vrt release watches it and confirms at the end that the packages are on npm.

So no npm login is needed on the maintainer's machine, npm gets what CI tested, and nothing is published before git has the release commit.

Setup, once per project

  1. On npmjs.com, add a trusted publisher to every package: GitHub Actions, this repository, the workflow file release.yml and the environment npm.

  2. In the repository settings, create the environment npm and allow only tags v* to deploy to it. Add required reviewers only if every publish should wait for an approval. To control who can start a release, add a tag ruleset for v* that restricts creation, deletion and non-fast-forward updates to the maintainers.

  3. Add .github/workflows/release.yml. The workflow has to be named Release, which vrt release looks for:

    name: Release
    
    on:
       push:
          tags:
             - 'v*'
    
    permissions: {}
    
    concurrency:
       group: release-${{ github.ref }}
       cancel-in-progress: false
    
    jobs:
       build:
          uses: versatiles-org/node-release-tool/.github/workflows/release.yml@vX.Y.Z
          permissions:
             contents: read
    
       # npm only accepts trusted publishing from the workflow file configured on npmjs.com,
       # so this job lives here and not in the reusable workflow.
       publish:
          name: Publish
          needs: build
          runs-on: ubuntu-latest
          environment: npm
          permissions:
             contents: write # GitHub release
             id-token: write # npm trusted publishing
          steps:
             - uses: actions/setup-node@v7
               with:
                  node-version: 24
                  registry-url: https://registry.npmjs.org
             - uses: actions/download-artifact@v8
               with:
                  name: release
                  path: release
             - run: npx --yes "@versatiles/release-tool@${{ needs.build.outputs.tool-version }}" release-publish release --tag "$GITHUB_REF_NAME"
               env:
                  GH_TOKEN: ${{ github.token }}
                  GH_REPO: ${{ github.repository }}

    Replace vX.Y.Z with the release of this tool that the project uses. The reusable workflow runs npm run check and the vrt of the project's devDependencies; the inputs check-script and vrt change that. A project without public packages can drop environment: npm and id-token: write: it only gets the GitHub release.

  4. Set scripts.release in package.json to vrt release.

When a release fails

  • Before the tag is pushed: the release commit and the tag are undone. Start again.
  • In the workflow, for a reason outside the code, such as an npm outage or a declined approval: the next vrt release notices the unfinished release and offers to run the failed jobs again. Re-running is safe, because versions that are already on npm are skipped.
  • In the workflow, because the code had to be fixed: commit the fix, then vrt release moves the tag to HEAD and releases that, with the same version and changelog section. This is only possible while nothing of the version is on npm. After that, the fix is the next version.

Command vrt

$ vrt
Usage: vrt [options] [command]

CLI tool for releasing packages and generating documentation for
Node.js/TypeScript projects.

Options:
  -h, --help                                display help for command
  -v, --verbose                             Enable verbose output

Commands:
  bundle-treemap [options] <bundle>         Measure a bundle's composition with its source map and render it as treemap.
  check                                     Check repo for required scripts and other stuff.
  deps-graph [options]                      Analyze project files and output a dependency graph as Mermaid markup.
  deps-upgrade [options]                    Upgrade all dependencies in the current project to their latest versions.
  doc-command <command>                     Generate Markdown documentation for a specified command and output the result.
  doc-insert <readme> [heading] [foldable]  Insert Markdown from stdin into a specified section of a Markdown file.
  doc-toc <readme> [heading]                Generate a Table of Contents (TOC) in a Markdown file.
  doc-typescript [options]                  Generate documentation for a TypeScript project.
  help [command]                            display help for command
  release [options] [version]               Prepare a release: check, raise the version, update CHANGELOG.md, commit, tag and push. The pushed tag starts the release workflow, which publishes; this command watches it.
  release-check [options] <tag>             Check that a tag can be released: it must match the version of every package.json, and CHANGELOG.md must have notes for it. Used by the release workflow.
  release-npm [options] [path]              Publish an npm package from the specified path to the npm registry, then wait until npm serves the new version.
  release-pack <directory>                  Pack every public package of the repository, including workspaces, into a directory, in the order to publish them. Used by the release workflow.
  release-publish [options] <directory>     Publish the packed packages to npm with trusted publishing, skipping versions npm has, and create the GitHub release. Used by the release workflow.
  treemap [options]                         Render a treemap from JSON on stdin as SVG file and output a Markdown image link to it.

Subcommand: vrt bundle-treemap

$ vrt bundle-treemap
Usage: vrt bundle-treemap [options] <bundle>

Measure a bundle's composition with its source map and render it as treemap.

Arguments:
  bundle              Path of the bundle, or of its source map.

Options:
  --depth <levels>    How many directory levels become groups. (default: 1)
  -h, --help          display help for command
  --height <pixels>   Height of the treemap. (default: 480)
  --map <file>        Path of the source map. Default: the one the bundle points
                      to, or <bundle>.map.
  --min-size <bytes>  Fold files smaller than this into an "other" entry.
                      Default: 0.5 % of the bundle.
  --svg <file>        Path of the SVG file to write. Without it, the treemap is
                      printed as JSON.
  --title <text>      Title of the image. (default: "Bundle composition")
  --width <pixels>    Width of the treemap. (default: 880)

Every byte of the bundle is attributed to the source file it came from, so
the build only needs to emit a source map, e.g.:
  vrt bundle-treemap dist/bundle.js --svg assets/bundle.svg | vrt doc-insert README.md '## Bundle'

Subcommand: vrt check

$ vrt check
Usage: vrt check [options]

Check repo for required scripts and other stuff.

Options:
  -h, --help  display help for command

Subcommand: vrt deps-graph

$ vrt deps-graph
Usage: vrt deps-graph [options]

Analyze project files and output a dependency graph as Mermaid markup.

Options:
  --barrel <glob>                  Point imports of the index file (e.g.
                                   index.ts) in directories matching the glob to
                                   the directory itself (repeatable). (default:
                                   [])
  --collapse-dir <glob>            Collapse all files matching the glob into a
                                   single node (repeatable). (default: [])
  --exclude <glob>                 Drop files matching the glob from the graph
                                   entirely (repeatable). (default: [])
  -h, --help                       display help for command
  --include <glob>                 Analyze files in directories matching the
                                   glob instead of "src", e.g. "packages/*/src"
                                   in a workspace (repeatable). (default: [])
  --merge-incoming <glob>          Merge edges from files outside of directories
                                   matching the glob that point into them into
                                   one edge per source directory (repeatable).
                                   (default: [])
  --merge-outgoing <glob>          Merge edges from files in directories
                                   matching the glob that point to the same
                                   target into one edge from the directory
                                   (repeatable). (default: [])
  --subgraph-direction <glob=dir>  Set the flow direction (TB, BT, LR, RL) of
                                   directory subgraphs matching the glob, e.g.
                                   "src/lib=LR" (repeatable). (default: [])
  --svg <file>                     Write the graph as SVG to the file and output
                                   a Markdown image link to it instead of
                                   Mermaid markup.

All options can also be set in vrt.config.json, e.g.:
  { "deps-graph": { "merge-outgoing": ["src/*"] } }
CLI options are added to the values from vrt.config.json.

Subcommand: vrt deps-upgrade

$ vrt deps-upgrade
Usage: vrt deps-upgrade [options]

Upgrade all dependencies in the current project to their latest versions.

Options:
  -h, --help                  display help for command
  --ignore <package[@range]>  Do not upgrade this dependency, optionally only up
                              to a semver range, e.g. "path-to-regexp@<7.0.0"
                              (repeatable). (default: [])
  --no-audit                  Do not fix known vulnerabilities with "npm audit
                              fix".
  --no-peer                   Upgrade to the latest version even when a peer
                              dependency of another package does not allow it.

Subcommand: vrt doc-command

$ vrt doc-command
Usage: vrt doc-command [options] <command>

Generate Markdown documentation for a specified command and output the result.

Arguments:
  command     Command to document (e.g., "npm run build").

Options:
  -h, --help  display help for command

Subcommand: vrt doc-insert

$ vrt doc-insert
Usage: vrt doc-insert [options] <readme> [heading] [foldable]

Insert Markdown from stdin into a specified section of a Markdown file.

Arguments:
  readme      Path to the target Markdown file (e.g., README.md).
  heading     Heading in the Markdown file where content should be placed.
              Default is "# API". (default: "# API")
  foldable    Whether to wrap the inserted content in a foldable section.
              (default: false)

Options:
  -h, --help  display help for command

Subcommand: vrt doc-toc

$ vrt doc-toc
Usage: vrt doc-toc [options] <readme> [heading]

Generate a Table of Contents (TOC) in a Markdown file.

Arguments:
  readme      Path to the Markdown file (e.g., README.md).
  heading     Heading in the Markdown file where TOC should be inserted. Default
              is "# Table of Content". (default: "# Table of Content")

Options:
  -h, --help  display help for command

Subcommand: vrt doc-typescript

$ vrt doc-typescript
Usage: vrt doc-typescript [options]

Generate documentation for a TypeScript project.

Options:
  -f, --format <format>      Allowed are "markdown", "wiki" and "html". Default
                             is "markdown".
  -h, --help                 display help for command
  -i, --input <entryPoint>   Entry point of the TypeScript project. Default is
                             "./src/index.ts".
  -o, --output <outputPath>  Output path for the generated documentation.
                             Default is "./docs".

Subcommand: vrt release

$ vrt release
Usage: vrt release [options] [version]

Prepare a release: check, raise the version, update CHANGELOG.md, commit, tag
and push. The pushed tag starts the release workflow, which publishes; this
command watches it.

Arguments:
  version          Version to release: "patch", "minor", "major" or an explicit
                   version. Default: recommended from the commits, and asked
                   for.

Options:
  -h, --help       display help for command
  -n, --dry-run    Run the checks and show what would happen, but change
                   nothing.
  --resume         Finish the unfinished release of the current version without
                   asking.
  --skip-ci-check  Do not require passing CI runs on the released commit
                   (emergencies only).
  -y, --yes        Ask nothing: take the recommended version and confirm
                   everything.

The repository needs a workflow named "Release" that the tag starts, see
https://github.com/versatiles-org/node-release-tool#release-workflow

Subcommand: vrt release-check

$ vrt release-check
Usage: vrt release-check [options] <tag>

Check that a tag can be released: it must match the version of every
package.json, and CHANGELOG.md must have notes for it. Used by the release
workflow.

Arguments:
  tag             The tag to release, e.g. "v1.2.3".

Options:
  -h, --help      display help for command
  --notes <file>  Write the release notes to this file.

Subcommand: vrt release-npm

$ vrt release-npm
Usage: vrt release-npm [options] [path]

Publish an npm package from the specified path to the npm registry, then wait
until npm serves the new version.

Arguments:
  path                  Root path of the Node.js project. Defaults to the
                        current directory.

Options:
  -b, --bump <version>  Version to release: "major", "minor", "patch" or an
                        explicit "x.y.z". Skips the prompt, e.g. for CI.
  -h, --help            display help for command
  -n, --dry-run         Show what would be done without making any changes
  --no-publish          Do not publish to npm: only raise the version, update
                        the changelog, tag, push and create the GitHub release,
                        e.g. when a CI workflow publishes the pushed tag.

Subcommand: vrt release-pack

$ vrt release-pack
Usage: vrt release-pack [options] <directory>

Pack every public package of the repository, including workspaces, into a
directory, in the order to publish them. Used by the release workflow.

Arguments:
  directory   Directory to write the tarballs to, e.g. "release".

Options:
  -h, --help  display help for command

Subcommand: vrt release-publish

$ vrt release-publish
Usage: vrt release-publish [options] <directory>

Publish the packed packages to npm with trusted publishing, skipping versions
npm has, and create the GitHub release. Used by the release workflow.

Arguments:
  directory    Directory with the tarballs and notes.md, e.g. "release".

Options:
  -h, --help   display help for command
  --tag <tag>  The tag to release, e.g. "v1.2.3".

Subcommand: vrt treemap

$ vrt treemap
Usage: vrt treemap [options]

Render a treemap from JSON on stdin as SVG file and output a Markdown image link
to it.

Options:
  -h, --help         display help for command
  --height <pixels>  Height of the treemap. (default: 480)
  --svg <file>       Path of the SVG file to write.
  --width <pixels>   Width of the treemap. (default: 880)

Input: { "title"?, "caption"?, "unit"?: "bytes", "children": [node, …] }
where a node is { "name", "size" } or { "name", "children": [node, …] }.

Development

Dependency Graph

Dependency graph

About

Helper tool for automating Node.js package releases across VersaTiles repositories.

Resources

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages