CodeSampleX

Beispiel

at-least-node 1.0.0: verify node version meets minimum requirement with at-least-node

Verifiziertes Beispiel für npm at-least-node 1.0.0: verify node version meets minimum requirement with at-least-node. Der Vertrag lief auf node 22 · linux…

sha256:50f3874a1f035e31de85007158f8f8c9dadabd25f15f167efa37629a4c1577fd

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
2
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-07

Fall

HOW
Ziel
verify node version meets minimum requirement with at-least-node
Pakete
Umgebung
node 22.23.2
Erstellt
2026-08-26T09:24:51Z

Contract

  1. atLeastNode is a callable function accepting a target version string
  2. returns true when current node version is greater than the required major version
  3. returns true when current node version equals the required version string
  4. returns false when current node version is less than the required major version
  5. handles semantic version strings with major minor and patch numbers correctly
  6. helper function checks minimum version requirement for runtime feature gating

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify node version meets minimum requirement with at-least-node
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/at-least-node@1.0.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:bb376e77ba80b0b8f72ba43302a63ae56eac810670a74663d91f049e7da42440","constraints":{"executionContext":"node"},"contract":["atLeastNode is a callable function accepting a target version string","returns true when current node version is greater than the required major version","returns true when current node version equals the required version string","returns false when current node version is less than the required major version","handles semantic version strings with major minor and patch numbers correctly","helper function checks minimum version requirement for runtime feature gating"],"goal":"verify node version meets minimum requirement with at-least-node","kind":"HOW","packages":["pkg:npm/at-least-node@1.0.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/at-least-node@1.0.0"],"schemaVersion":1,"subject":"pkg:npm/at-least-node@1.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-at-least-node",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-at-least-node",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "at-least-node": "1.0.0"
      }
    },
    "node_modules/at-least-node": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
      "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==",
      "license": "ISC",
      "engines": {
        "node": ">= 4.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-at-least-node",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for at-least-node@1.0.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "at-least-node": "1.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify node version meets minimum requirement with at-least-node",
  "kind": "HOW",
  "packages": [
    "pkg:npm/at-least-node@1.0.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const atLeastNode = require('at-least-node');

/**
 * Checks if the current Node.js runtime version is at least the specified minimum version.
 *
 * @param {string} minVersion - The target minimum version (e.g. '10.0.0', '18.0.0', '22.0.0').
 * @returns {boolean} True if current node version is greater than or equal to minVersion.
 */
function isNodeAtLeast(minVersion) {
  return atLeastNode(minVersion);
}

/**
 * Checks if a specific feature requiring a minimum Node.js version is supported by the current runtime.
 *
 * @param {string} requiredVersion - The minimum version required by the feature.
 * @returns {{ supported: boolean, currentVersion: string, requiredVersion: string }}
 */
function checkFeatureSupport(requiredVersion) {
  return {
    supported: atLeastNode(requiredVersion),
    currentVersion: process.versions.node,
    requiredVersion
  };
}

module.exports = {
  atLeastNode,
  isNodeAtLeast,
  checkFeatureSupport
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  atLeastNode,
  isNodeAtLeast,
  checkFeatureSupport
} = require('../src/index.js');

async function testAll() {
  const currentVersion = process.versions.node;
  const [currentMajor, currentMinor, currentPatch] = currentVersion.split('.').map(Number);

  // 1. atLeastNode is a callable function accepting a target version string
  assert.equal(typeof atLeastNode, 'function', 'atLeastNode should be a function');
  assert.equal(typeof isNodeAtLeast, 'function', 'isNodeAtLeast should be a function');
  assert.equal(typeof checkFeatureSupport, 'function', 'checkFeatureSupport should be a function');

  // 2. returns true when current node version is greater than the required major version
  const olderMajor = `${Math.max(1, currentMajor - 5)}.0.0`;
  assert.equal(atLeastNode(olderMajor), true, `should return true for older major version ${olderMajor}`);
  assert.equal(isNodeAtLeast(olderMajor), true, `helper should return true for older major version ${olderMajor}`);

  // 3. returns true when current node version equals the required version string
  assert.equal(atLeastNode(currentVersion), true, `should return true when matching exact current version ${currentVersion}`);
  assert.equal(isNodeAtLeast(currentVersion), true, `helper should return true when matching exact current version`);

  // 4. returns false when current node version is less than the required major version
  const futureMajor = `${currentMajor + 10}.0.0`;
  assert.equal(atLeastNode(futureMajor), false, `should return false for future major version ${futureMajor}`);
  assert.equal(isNodeAtLeast(futureMajor), false, `helper should return false for future major version ${futureMajor}`);

  // 5. handles semantic version strings with major minor and patch numbers correctly
  const sameMajorOlderMinor = `${currentMajor}.${Math.max(0, currentMinor - 1)}.0`;
  assert.equal(atLeastNode(sameMajorOlderMinor), true, `should return true for older minor version within same major`);

  const sameMajorFutureMinor = `${currentMajor}.${currentMinor + 5}.0`;
  assert.equal(atLeastNode(sameMajorFutureMinor), false, `should return false for future minor version within same major`);

  // 6. helper function checks minimum version requirement for runtime feature gating
  const supportOlder = checkFeatureSupport(olderMajor);
  assert.deepEqual(supportOlder, {
    supported: true,
    currentVersion,
    requiredVersion: olderMajor
  });

  const supportFuture = checkFeatureSupport(futureMajor);
  assert.deepEqual(supportFuture, {
    supported: false,
    currentVersion,
    requiredVersion: futureMajor
  });

  console.log('All at-least-node contract tests passed successfully.');
}

testAll().catch((err) => {
  console.error('Contract test failure:', err);
  process.exit(1);
});

Ursprungs-Seeder

anonym