Skip to content

node

The node archetype covers Node and TypeScript repos: libraries such as design-system, and GitHub Actions such as ff-merge and setup-evolve. It works with npm, pnpm or bun, and drives everything through the repo's own package.json scripts.

# mise.toml
[task_config]
includes = [".mise/common/tasks.toml", ".mise/archetypes/node/tasks.toml"]
# Makefile
include .mise/archetypes/node/include.mk

A bun repo pins nothing. bun is the library's always-installed pin, and it is the repo's runtime, package manager, formatter, type checker, bundler and test runner in one. An npm or pnpm repo still pins its own runtime in the root [tools], because the library pins no node:

[tools]
node = "24.20.0"

The prose gate runs on the library's bun either way, so it never touches the repo's runtime.

The package.json-script contract

The archetype never calls a linter, type checker, bundler or test runner itself. It runs the repo's package.json scripts, by ecosystem convention. For a bun repo:

Script Typically Used by Required?
check the linter: biome lint . today, bun lint once a stable bun ships it lint optional
check:fix the linter's auto-fix: biome lint --write ., later bun lint --fix fmt optional
format bun fmt --no-script fmt optional
typecheck bun check --no-script lint required
build bun build build required
test:coverage bun test --coverage → coverage/lcov.info and coverage/junit.xml test optional

biome's npm bin is a #!/usr/bin/env node launcher, so a bun repo with no Node.js runs it with bun: bun ./node_modules/@biomejs/biome/bin/biome lint .. An npm or pnpm repo fills the same slots with its own tools (biome, tsc --noEmit, tsup, vitest and so on).

Optional scripts run only when package.json defines them. A library with no tests still gets a test task that passes trivially. This is the one place the library tolerates a task that may do nothing, because the script set is the repo's declaration of what applies. The repo's linter and formatter own the code, and bun fmt plus markdownlint (from common) own the Markdown.

Always pass --no-script

bun check and bun fmt run a package.json script of the same name (check, fmt) instead of the built-in tool when one exists. The contract's check script is the linter, so a typecheck script of a bare bun check would run the linter, and a check script that called bun check would call itself forever. Spell them bun check --no-script and bun fmt --no-script.

A bun repo that commits a .prettierrc.yaml for its code options replaces the house prose options wholesale, so it carries them over for Markdown in an overrides entry:

semi: false
singleQuote: true
printWidth: 100
overrides:
  - files: "*.md"
    options:
      proseWrap: always
      printWidth: 120

Tasks

Task What it does
fmt check:fix and format scripts (if defined), prose format, license headers.
lint license check, check script (if defined) then typecheck, containers, shell, workflows, prose.
build The build script.
test The test:coverage script, if defined.
ci lint, build, test, docs-build.
pr fmt, lint, build, test, docs-build, commit.

Every node task depends on a hidden node-install task, which installs exactly as locked and runs everything straight from node_modules, never through npx or a global install.

The reusable CI fails an action PR if the committed dist/ differs from a fresh build, so an action's build must be reproducible. Such a repo lists dist/** in .licenseignore so the license pass doesn't stamp the bundle. If its format script runs bun fmt, it also lists dist/ in a repo .prettierignore. That file replaces the house ignore list wholesale, so copy the house entries into it too.

Package managers

Every node task goes through archetypes/node/scripts/pm.sh, which picks the package manager in this order:

  1. NODE_PACKAGE_MANAGER in the environment, else the node_package_manager var (npm, pnpm or bun). Empty, the default, means auto-detect. Any other value fails.
  2. The name in package.json "packageManager": "pnpm@12.10.0" means pnpm.
  3. The lockfile: package-lock.json or npm-shrinkwrap.json means npm, pnpm-lock.yaml means pnpm, and bun.lock or bun.lockb means bun. Lockfiles from more than one manager fail with an error naming them. Set node_package_manager (or "packageManager") to pick one.
  4. npm.

bun comes from the shared pin every repo installs, and pnpm from a shared lazy pin that installs the first time a task needs it. Both are checksum-locked, so CI needs no setup step. A repo may pin its own version in its root [tools] ("aqua:pnpm/pnpm" = "…"), and its pin wins.

pnpm never self-switches

pnpm normally downloads and switches to whatever version "packageManager" names, which would bypass the checksum-locked pin. pm.sh stops that (pnpm_config_pm_on_fail=warn for pnpm 11+, and npm_config_manage_package_manager_versions=false for pnpm 10), so a version mismatch is only reported as a warning.

The locked install

Manager Command
npm npm ci $flags --no-fund
pnpm pnpm install --frozen-lockfile $flags
bun bun install --frozen-lockfile $flags

$flags comes from the node_install_flags var, which defaults to --ignore-scripts: the safe choice for a library. A GitHub Action repo that relies on lifecycle scripts sets node_install_flags = "" in its root [vars]. NODE_INSTALL_FLAGS in the environment overrides it per run. It's checked as set-or-unset, so NODE_INSTALL_FLAGS= forces a bare install.

The install is skipped while node_modules/.toolchain-install, a sentinel pm.sh touches after a successful install, is newer than package.json, pnpm-workspace.yaml and every manager's lockfile.

Deprecated: npm_ci_flags

The older npm-only npm_ci_flags var and NPM_CI_FLAGS env still work for npm repos and win over node_install_flags when set. Both are ignored for pnpm and bun. Prefer the neutral knobs.

A repo needs no .gitignore or .licenseignore change for pnpm or bun: node_modules/ is already ignored, and the license tasks skip pnpm-lock.yaml by default. addlicense doesn't stamp the other lockfiles' formats.

Knobs

Knob Default Env override Meaning
node_package_manager empty (detect) NODE_PACKAGE_MANAGER Force npm, pnpm or bun.
node_install_flags --ignore-scripts NODE_INSTALL_FLAGS Flags for the locked install.
npm_ci_flags unset (deprecated) NPM_CI_FLAGS npm-only install flags; wins when set.

There's no e2e: running an action for real would mutate refs, so actions are covered by unit tests.

Source

archetypes/node/tasks.toml
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# node — archetype for a Node/TypeScript repo: a library (design-system,
# evolve-design-system) or a GitHub Action (ff-merge, setup-evolve).
#
# Include AFTER common/tasks.toml in the consumer's root mise.toml. A bun
# repo (the default for new repos) pins nothing: bun — runtime, package
# manager, formatter, type checker, bundler and test runner in one — comes
# from the library's shared pin. An npm or pnpm repo still pins its runtime in
# its own root [tools]:
#   [tools]
#   node = "24.20.0"            # npm / pnpm repos only
#   [task_config]
#   includes = [".mise/common/tasks.toml", ".mise/archetypes/node/tasks.toml"]
#
# The contract is the repo's package.json scripts, by ecosystem convention.
# For a bun repo:
#   check / check:fix   linter: biome lint [--write] today (its bin is a
#                       node script: run it as `bun ./node_modules/
#                       @biomejs/biome/bin/biome lint .` so no node is
#                       needed), then bun lint [--fix] once a stable
#                       bun ships it                                   optional
#   format              bun fmt --no-script                            optional
#   typecheck           bun check --no-script                          required
#   build               bun build                                      required
#   test:coverage       bun test --coverage → coverage/lcov.info and
#                       coverage/junit.xml                             optional
# (an npm / pnpm repo fills the same slots with its own tools: biome, tsc,
# tsup, vitest, ...). Optional scripts run only when package.json defines
# them, so a library with no tests still has a (trivially passing) `test`
# task — the one place the library tolerates a task that may do nothing,
# since the script set is the repo's declaration of what applies. The
# repo's linter and formatter own the code; bun fmt + markdownlint (common)
# own the markdown.
#
# Mind `--no-script`: `bun check` and `bun fmt` run a package.json script of
# the same name (`check`, `fmt`) instead of the built-in when one exists. The
# contract's `check` script is the linter, so a `typecheck` script of a bare
# `bun check` would run `check` — and a `check` script that called `bun check`
# would run itself forever. Always spell them `bun check --no-script` and
# `bun fmt --no-script`.
#
# npm, pnpm and bun are all supported; every task goes through
# scripts/pm.sh, which picks the package manager in this order:
#   1. NODE_PACKAGE_MANAGER in the environment, else the node_package_manager
#      var (npm|pnpm|bun; empty = auto-detect)
#   2. the name in package.json "packageManager" (e.g. "pnpm@12.10.0")
#   3. the lockfile: package-lock.json / npm-shrinkwrap.json → npm,
#      pnpm-lock.yaml → pnpm, bun.lock / bun.lockb → bun (lockfiles from more
#      than one manager fail — set node_package_manager to pick)
#   4. npm
# bun comes from the shared pin every repo installs, pnpm from a shared lazy
# pin (installed on first use); both are checksum-locked, and a repo may pin
# its own version in its root [tools]. pnpm never self-switches to the version
# "packageManager" names.
#
# The install runs with the node_install_flags var (--ignore-scripts by
# default, the safe choice for a library; npm also gets --no-fund). A GitHub
# Action repo that runs lifecycle scripts on install sets
# node_install_flags = "" in its root [vars]; NODE_INSTALL_FLAGS in the
# environment overrides per invocation (unset-only, so NODE_INSTALL_FLAGS=
# forces a bare install). For npm repos the older npm_ci_flags var and
# NPM_CI_FLAGS env still win over node_install_flags (deprecated; prefer the
# neutral knobs). No `e2e`: running an action for real would mutate refs;
# covered by unit tests.

# Install exactly as locked, and run everything straight from node_modules
# (never npx or a global). The install is skipped while the sentinel pm.sh
# touches after a successful install is newer than the manifests and every
# manager's lockfile (sources missing from disk are ignored).
[node-install]
hide = true
dir = "{{cwd}}"
sources = [
  "package.json",
  "package-lock.json",
  "npm-shrinkwrap.json",
  "pnpm-lock.yaml",
  "pnpm-workspace.yaml",
  "bun.lock",
  "bun.lockb",
]
outputs = ["node_modules/.toolchain-install"]
env = { TOOLCHAIN_NODE_PM = "{{vars.node_package_manager}}", TOOLCHAIN_NODE_INSTALL_FLAGS = "{{vars.node_install_flags}}", TOOLCHAIN_NPM_CI_FLAGS = "{{ vars.npm_ci_flags | default(value='') }}", TOOLCHAIN_NPM_CI_FLAGS_SET = "{% if vars.npm_ci_flags is defined %}1{% endif %}" }
run = "{{config_root}}/.mise/archetypes/node/scripts/pm.sh install"

# Auto-fix pass wired into `fmt`.
[node-fmt]
hide = true
dir = "{{cwd}}"
depends = ["node-install"]
env = { TOOLCHAIN_NODE_PM = "{{vars.node_package_manager}}" }
run = "{{config_root}}/.mise/archetypes/node/scripts/pm.sh run-if-present check:fix format"

# Check-mode static analysis wired into `lint`: biome (when present) then the
# TypeScript type-check.
[node-lint]
hide = true
dir = "{{cwd}}"
depends = ["node-install"]
env = { TOOLCHAIN_NODE_PM = "{{vars.node_package_manager}}" }
run = [
  "{{config_root}}/.mise/archetypes/node/scripts/pm.sh run-if-present check",
  "{{config_root}}/.mise/archetypes/node/scripts/pm.sh run typecheck",
]

# The reusable CI fails an action PR if the committed dist/ then differs from
# source, so the build must be reproducible.
[node-build]
hide = true
dir = "{{cwd}}"
depends = ["node-install"]
env = { TOOLCHAIN_NODE_PM = "{{vars.node_package_manager}}" }
run = "{{config_root}}/.mise/archetypes/node/scripts/pm.sh run build"

# The test:coverage script — bun test emits coverage/lcov.info + coverage/junit.xml,
# which the reusable CI uploads.
[node-test]
hide = true
dir = "{{cwd}}"
depends = ["node-install"]
env = { TOOLCHAIN_NODE_PM = "{{vars.node_package_manager}}" }
run = "{{config_root}}/.mise/archetypes/node/scripts/pm.sh run-if-present test:coverage"

[fmt]
description = "package.json check:fix / format + prose format, inject license headers"
run = [{ task = "node-fmt" }, { task = "fmt-prose" }, { task = "license" }]

[lint]
description = "package.json check + typecheck + prose, license, container, shell and workflow checks"
run = [
  { task = "license-check" },
  { task = "node-lint" },
  { task = "lint-containers" },
  { task = "lint-shell" },
  { task = "lint-workflows" },
  { task = "lint-prose" },
]

[build]
description = "package.json build"
run = [{ task = "node-build" }]

[test]
description = "package.json test:coverage (if the repo defines it)"
run = [{ task = "node-test" }]

[ci]
description = "the gates the reusable CI workflow runs"
run = [{ task = "lint" }, { task = "build" }, { task = "test" }, { task = "docs-build" }]

[pr]
description = "full local gate before a pull request"
run = [
  { task = "fmt" },
  { task = "lint" },
  { task = "build" },
  { task = "test" },
  { task = "docs-build" },
  { task = "commit" },
]
archetypes/node/scripts/pm.sh
#!/bin/sh
# Copyright 2026 BitWise Media Group Ltd
# SPDX-License-Identifier: MIT
#
# Package-manager dispatcher for the node archetype: the tasks never spell out
# npm, pnpm or bun themselves, they call this script.
#
#   pm.sh install                    install exactly as locked, then touch the
#                                    node_modules/.toolchain-install sentinel
#   pm.sh run <script> [args...]     run a required package.json script
#   pm.sh run-if-present <script>... run each script the package.json defines,
#                                    silently skipping the rest
#
# The package manager is, in order: NODE_PACKAGE_MANAGER in the environment,
# else the node_package_manager var (TOOLCHAIN_NODE_PM); else the name in
# package.json "packageManager"; else the lockfile present in the repo
# (conflicting lockfiles fail); else npm.
#
# Install flags are, in order: NODE_INSTALL_FLAGS in the environment
# (unset-only, so NODE_INSTALL_FLAGS= forces none); for npm only, NPM_CI_FLAGS
# in the environment (unset-only) or the deprecated npm_ci_flags var if the
# repo sets it; else the node_install_flags var (TOOLCHAIN_NODE_INSTALL_FLAGS),
# plus --no-fund for npm.
set -eu

die() {
  echo "pm.sh: $*" >&2
  exit 1
}

check_pm() {
  case "$1" in
    npm | pnpm | bun) ;;
    *) die "unsupported package manager '$1' from $2 (expected npm, pnpm or bun)" ;;
  esac
}

# package.json is read with a JS runtime rather than a JSON-parsing
# dependency: always the bun the library installs in every repo, so the
# dispatcher behaves the same whether or not the repo pins node (and a stale
# global node shim with no version set can't break it).
js() {
  bun "$@"
}

# Prints the package.json "packageManager" field's package-manager name (the
# part before '@'), or nothing.
package_manager_field() {
  [ -f package.json ] || return 0
  js -e '
    const pm = JSON.parse(require("fs").readFileSync("package.json", "utf8")).packageManager;
    if (typeof pm === "string") console.log(pm.split("@")[0]);
  '
}

detect_lockfiles() {
  families=""
  found=""
  for f in package-lock.json npm-shrinkwrap.json pnpm-lock.yaml bun.lock bun.lockb; do
    [ -f "$f" ] || continue
    case "$f" in
      package-lock.json | npm-shrinkwrap.json) family=npm ;;
      pnpm-lock.yaml) family=pnpm ;;
      *) family=bun ;;
    esac
    found="${found:+$found, }$f"
    case " $families " in
      *" $family "*) ;;
      *) families="${families:+$families }$family" ;;
    esac
  done
  case "$families" in
    *" "*) die "conflicting lockfiles ($found); set node_package_manager in the root mise.toml [vars] (or \"packageManager\" in package.json) to pick one" ;;
  esac
  echo "$families"
}

resolve_pm() {
  if [ -n "${NODE_PACKAGE_MANAGER-}" ]; then
    check_pm "$NODE_PACKAGE_MANAGER" NODE_PACKAGE_MANAGER
    pm=$NODE_PACKAGE_MANAGER
    return
  fi
  if [ -n "${TOOLCHAIN_NODE_PM-}" ]; then
    check_pm "$TOOLCHAIN_NODE_PM" "the node_package_manager var"
    pm=$TOOLCHAIN_NODE_PM
    return
  fi
  pm=$(package_manager_field)
  if [ -n "$pm" ]; then
    check_pm "$pm" 'package.json "packageManager"'
    return
  fi
  pm=$(detect_lockfiles)
  [ -n "$pm" ] || pm=npm
}

install_flags() {
  if [ "${NODE_INSTALL_FLAGS+set}" = set ]; then
    echo "$NODE_INSTALL_FLAGS"
  elif [ "$pm" = npm ] && [ "${NPM_CI_FLAGS+set}" = set ]; then
    echo "$NPM_CI_FLAGS"
  elif [ "$pm" = npm ] && [ -n "${TOOLCHAIN_NPM_CI_FLAGS_SET-}" ]; then
    echo "${TOOLCHAIN_NPM_CI_FLAGS-}"
  elif [ "$pm" = npm ]; then
    echo "${TOOLCHAIN_NODE_INSTALL_FLAGS-} --no-fund"
  else
    echo "${TOOLCHAIN_NODE_INSTALL_FLAGS-}"
  fi
}

# package.json scripts are an object of name → command; exit 0 when the named
# one exists, 1 when it does not, 2 when package.json cannot be read.
has_script() {
  js -e '
    let scripts;
    try {
      scripts = JSON.parse(require("fs").readFileSync("package.json", "utf8")).scripts;
    } catch (e) {
      console.error("pm.sh: cannot read package.json: " + e.message);
      process.exit(2);
    }
    process.exit(scripts && Object.hasOwn(scripts, process.argv[1]) ? 0 : 1);
  ' "$1"
}

run() {
  echo "$*" >&2
  "$@"
}

[ $# -ge 1 ] || die "usage: pm.sh install | run <script> [args...] | run-if-present <script>..."
cmd=$1
shift
resolve_pm

# Every pnpm command (run included) would otherwise download and switch to the
# version package.json "packageManager" names, bypassing the checksum-locked
# mise pin. pmOnFail=warn (pnpm 11+) keeps the pinned pnpm and reports the
# mismatch; manage-package-manager-versions is the pnpm 10 spelling.
if [ "$pm" = pnpm ]; then
  export pnpm_config_pm_on_fail=warn
  export npm_config_manage_package_manager_versions=false
fi

case "$cmd" in
  install)
    flags=$(install_flags)
    # Word splitting is intended: flags is a space-separated list.
    # shellcheck disable=SC2086
    case "$pm" in
      npm) run npm ci $flags ;;
      pnpm) run pnpm install --frozen-lockfile $flags ;;
      bun) run bun install --frozen-lockfile $flags ;;
    esac
    mkdir -p node_modules
    touch node_modules/.toolchain-install
    ;;
  run)
    [ $# -ge 1 ] || die "usage: pm.sh run <script> [args...]"
    run "$pm" run "$@"
    ;;
  run-if-present)
    for script in "$@"; do
      rc=0
      has_script "$script" || rc=$?
      case "$rc" in
        0) run "$pm" run "$script" ;;
        1) ;;
        *) exit "$rc" ;;
      esac
    done
    ;;
  *)
    die "unknown command '$cmd' (expected install, run or run-if-present)"
    ;;
esac