Skip to content

Guardrails / nodejs

Package manager is pinned ​

nodejs/package-manager-pinned@v1

The manifest names the package manager and the exact version Corepack should install.

Idnodejs/package-manager-pinned
Versionv1
Categorynodejs
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsnodejs

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

CollectorGathersInputs it is given
nodejsThe Node.js project in the project directory: its manifest, the Node version and package manager it asks for, every workspace it declares, the dependencies each manifest names and which of them are pinned, and the lock files committed beside them.projectDir

The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "nodejs/package-manager-pinned@v1",
              "severity": "warning",
              "with": {
                  "projectDir": "."
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

How to fix ​

Name the package manager and its version in package.json. This is the version Corepack installs:

json
{
  "packageManager": "pnpm@9.1.0"
}

Without this field, or with a name but no version, the install runs under whichever npm, pnpm or yarn the runner happens to have. A lock file written by one package manager is then resolved by another, and the tree a developer reviewed is not the tree CI installs.

More in nodejs ​

  • nodejs/lockfile-committed. The project commits a lock file, so an install of the same commit resolves the same versions.
  • nodejs/single-package-manager. The project commits at most one lock file, so two package managers don't both try to manage the dependency tree.
  • nodejs/version-declared. The project declares the Node.js version it is built and run against, and that version is no older than the configured floor.

All 4 nodejs guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412