Hamburger Cross Icon
Node.js Project Guardrails - Lunar Policy for Devex Build And Ci

Node.js Project Guardrails

✓ Policy Stable Devex Build And Ci

Enforce Node.js-specific project standards including lockfile presence, TypeScript configuration, engine version pinning, and minimum Node.js version requirements for code and CI environments.

Add nodejs to your lunar-config.yml:
uses: github://earthly/lunar-lib/policies/nodejs@v1.0.5

Included Guardrails

This policy includes 5 guardrails that enforce standards for your devex build and ci.

Guardrail

lockfile-exists

Ensures a package lockfile exists (package-lock.json, yarn.lock, or pnpm-lock.yaml). Lockfiles are essential for reproducible builds and dependency integrity.

lockfile package-lock.json yarn.lock pnpm-lock.yaml reproducibility
View Guardrail
Guardrail

typescript-configured

Ensures TypeScript is configured via tsconfig.json. TypeScript provides type safety and improved developer experience.

typescript tsconfig.json type safety
View Guardrail
Guardrail

engines-pinned

Ensures the engines.node field is set in package.json. Pinning the Node.js engine version prevents compatibility issues across environments.

engines node version package.json compatibility
View Guardrail
Guardrail

min-node-version

Ensures the Node.js version detected in the project meets the minimum for its major release. Compares full versions, not just the major.

node version compatibility security
View Guardrail
Guardrail

min-node-version-cicd

Ensures every Node.js version recorded for node commands in CI meets the minimum for its major release. Compares full versions, not just the major.

node version ci/cd compatibility security
View Guardrail

How Guardrails Fit into Lunar

Lunar guardrails define your engineering standards as code. They evaluate data collected by integrations and produce pass/fail checks with actionable feedback.

Policies support gradual enforcement—from silent scoring to blocking PRs or deployments—letting you roll out standards at your own pace without disrupting existing workflows.

Learn How Lunar Works →
1
↓ Integrations Gather Data
Collectors extract metadata from code, CI pipelines, tool outputs, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
✓ Guardrails Enforce Standards This Policy
Real-time feedback in PRs and AI workflows

Required Integrations

This policy evaluates data gathered by one or more of the following integration(s). Make sure to enable them in your lunar-config.yml.

Configuration

Configure this policy in your lunar-config.yml.

Inputs

Input Required Default Description
min_node_version Optional 18 Minimum Node.js version ("18", "20.15.1") or one per major release ("20.19.5, 22.20.0, 24.10.0")
min_node_version_cicd Optional 18 Minimum Node.js version for node commands in CI, in the same forms as min_node_version

Documentation

View on GitHub

Node.js Project Guardrails

Enforce Node.js-specific project standards including lockfile presence, TypeScript configuration, engine version pinning, and minimum Node.js version requirements.

Overview

This policy validates Node.js projects against best practices for package management and project structure. It ensures projects have lockfiles for reproducible builds, TypeScript for type safety, pinned engine versions, and meet minimum Node.js version requirements in both code and CI environments.

Policies

This plugin provides the following policies (use include to select a subset):

Policy Description
lockfile-exists Validates a lockfile exists (package-lock.json, yarn.lock, or pnpm-lock.yaml)
typescript-configured Validates tsconfig.json exists
engines-pinned Ensures engines.node is set in package.json
min-node-version Ensures minimum Node.js version
min-node-version-cicd Ensures minimum Node.js version in CI/CD

Version comparison

min-node-version and min-node-version-cicd compare full versions. Earlier releases compared only the major, so a patch-level minimum such as 20.15.1 passed 20.0.0; it now fails. A major-only minimum such as 20 gives the same results as before, except that a pre-release sorts before its release: 22.0.0-rc.1 fails a 22 minimum.

min-node-version reads .lang.nodejs.version, which the nodejs collector takes from the Node.js installed where it runs, not from the project. Use min-node-version-cicd to check the Node.js your CI runs.

Minimum per major release

A single minimum is one floor for every major: 20.19.5 passes any 22, including a vulnerable 22.12.0. To hold each major to its own patched release, list one minimum per major, separated by commas, spaces or newlines:

with:
  min_node_version_cicd: "20.19.5, 22.20.0, 24.10.0"
Version Result
20.19.5, 22.21.1 Passes: meets its major's minimum
20.18.0, 22.12.0 Fails: below its major's minimum
18.20.8, 16.20.2 Fails: older than every listed major
21.7.3, 23.11.1 Fails: no minimum is listed for its major, and a newer major is listed
25.1.0, 26.0.0 Passes: newer than every listed major, as with a single minimum

Required Data

This policy reads from the following Component JSON paths:

Path Type Provided By
.lang.nodejs object nodejs collector
.lang.nodejs.package_lock_exists boolean nodejs collector
.lang.nodejs.yarn_lock_exists boolean nodejs collector
.lang.nodejs.pnpm_lock_exists boolean nodejs collector
.lang.nodejs.tsconfig_exists boolean nodejs collector
.lang.nodejs.engines_node string nodejs collector
.lang.nodejs.version string nodejs collector
.lang.nodejs.cicd.cmds array nodejs collector

Note: Ensure the corresponding collector(s) are configured before enabling this policy.

Installation

Add to your lunar-config.yml:

policies:
  - uses: github://earthly/lunar-lib/policies/nodejs@v1.0.0
    on: ["domain:your-domain"]  # replace with your own domain or tags
    enforcement: report-pr
    include:
      - lockfile-exists
      - typescript-configured
      - engines-pinned
      - min-node-version
      - min-node-version-cicd
    with:
      min_node_version: "18"       # Minimum Node.js version, or one per major (default: "18")
      min_node_version_cicd: "18"  # Minimum Node.js version for CI/CD commands (default: "18")

Examples

Passing Example

{
  "lang": {
    "nodejs": {
      "version": "20.11.0",
      "package_lock_exists": true,
      "tsconfig_exists": true,
      "engines_node": ">=18"
    }
  }
}

Failing Example

{
  "lang": {
    "nodejs": {
      "version": "16.20.0",
      "package_lock_exists": false,
      "yarn_lock_exists": false,
      "pnpm_lock_exists": false,
      "tsconfig_exists": false
    }
  }
}

Failure messages:

  • "No lockfile found. Run 'npm install', 'yarn install', or 'pnpm install' to generate a lockfile and commit it to version control."
  • "TypeScript is not configured. Add a tsconfig.json to enable type checking."
  • "engines.node is not set in package.json."
  • "Node.js version 16.20.0 is below minimum 18."

Remediation

When this policy fails, you can resolve it by:

  1. lockfile-exists: Run npm install, yarn install, or pnpm install to generate a lockfile and commit it to version control.
  2. typescript-configured: Run npx tsc --init to generate a tsconfig.json and configure compiler options.
  3. engines-pinned: Add "engines": { "node": ">=18" } to package.json to communicate the required version.
  4. min-node-version: Update your project's Node.js version and .nvmrc, .node-version, or engines.node.
  5. min-node-version-cicd: Update your CI/CD pipeline (GitHub Actions node-version or Docker base image).

Open Source

This policy is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

Ready to Automate Your Standards?

See how Lunar can turn your AGENTS.md, engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 300+ built-in guardrails.

Works with any process
check AI agent rules & prompt files
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Auto-ID My Guardrails
Paste your AGENTS.md or manual process doc and get guardrails in minutes
Book a Demo