CodeSampleX

Sample

require-directory 2.1.1

Verified sample for npm require-directory 2.1.1. The contract ran on node 22 · linux alpine/x64 · docker and passed: requireDirectory loads all supported…

sha256:cc9764aadfbf42acfb4d422d91ab2f297f0ff619f62616755634186c288533f8

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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-23

Case

HOW
Goal
verify pkg:npm/require-directory@2.1.1
Packages
Environment
node 22.23.2
Created
2026-08-23T08:24:02Z

Contract

  1. requireDirectory loads all supported modules recursively from a directory into a nested object
  2. supports filtering files using include and exclude regular expressions or functions
  3. allows custom renaming of object keys using the rename option function
  4. allows transforming imported modules using the visit option callback
  5. honors recurse option to toggle recursive subfolder traversal

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.js
  • test/fixtures/config.json
  • test/fixtures/helpers/format.js
  • test/fixtures/helpers/ignore.txt
  • test/fixtures/math/add.js
  • test/fixtures/math/subtract.js

Download the source artifact (tar.gz)

Source

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 pkg:npm/require-directory@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/require-directory@2.1.1

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:f88ff53ee4c4e6c10442b5933a66b82d30572983b6118d49f85cf39ee30c4fcc","contract":["requireDirectory loads all supported modules recursively from a directory into a nested object","supports filtering files using include and exclude regular expressions or functions","allows custom renaming of object keys using the rename option function","allows transforming imported modules using the visit option callback","honors recurse option to toggle recursive subfolder traversal"],"goal":"verify pkg:npm/require-directory@2.1.1","kind":"HOW","packages":["pkg:npm/require-directory@2.1.1"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/require-directory@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/require-directory@2.1.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-require-directory",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-require-directory",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "require-directory": "2.1.1"
      }
    },
    "node_modules/require-directory": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
      "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-require-directory",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for require-directory",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "require-directory": "2.1.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/require-directory@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/require-directory@2.1.1"
  ]
}
src/index.js
const requireDirectory = require('require-directory');

function loadModules(callingModule, targetPath, options) {
  return requireDirectory(callingModule, targetPath, options);
}

module.exports = {
  requireDirectory,
  loadModules
};
test/contract.js
const assert = require('node:assert');
const path = require('node:path');
const requireDirectory = require('require-directory');
const { loadModules } = require('../src/index.js');

const fixturesDir = path.join(__dirname, 'fixtures');

// 1. requireDirectory loads all supported modules recursively from a directory into a nested object
const modules = loadModules(module, './fixtures');
assert.strictEqual(typeof modules, 'object', 'modules must be an object');
assert.ok(modules.math, 'modules should contain math namespace');
assert.ok(modules.helpers, 'modules should contain helpers namespace');
assert.ok(modules.config, 'modules should contain config JSON');
assert.strictEqual(typeof modules.math.add, 'function', 'math.add must be a function');
assert.strictEqual(typeof modules.math.subtract, 'function', 'math.subtract must be a function');
assert.strictEqual(typeof modules.helpers.format, 'function', 'helpers.format must be a function');
assert.strictEqual(modules.math.add(10, 5), 15, 'math.add(10, 5) should equal 15');
assert.strictEqual(modules.math.subtract(10, 5), 5, 'math.subtract(10, 5) should equal 5');
assert.strictEqual(modules.helpers.format('  hello  '), 'hello', 'helpers.format should trim whitespace');
assert.strictEqual(modules.config.name, 'sample-config', 'config.name should match');
assert.strictEqual(modules.config.enabled, true, 'config.enabled should match');
assert.strictEqual(modules.helpers.ignore, undefined, 'unsupported extension files should be ignored');

// 2. supports filtering files using include and exclude regular expressions or functions
const mathOnly = loadModules(module, './fixtures', {
  include: /math/
});
assert.ok(mathOnly.math, 'math directory should be included');
assert.strictEqual(mathOnly.helpers, undefined, 'helpers directory should not be included');

const excludeSubtract = loadModules(module, './fixtures', {
  exclude: /subtract/
});
assert.ok(excludeSubtract.math.add, 'math.add should be included');
assert.strictEqual(excludeSubtract.math.subtract, undefined, 'math.subtract should be excluded');

const functionFiltered = loadModules(module, './fixtures', {
  exclude: (filePath) => filePath.endsWith('add.js')
});
assert.strictEqual(functionFiltered.math.add, undefined, 'math.add should be excluded by predicate function');
assert.ok(functionFiltered.math.subtract, 'math.subtract should remain when not excluded');

// 3. allows custom renaming of object keys using the rename option function
const uppercaseKeys = loadModules(module, './fixtures', {
  rename: (name) => name.toUpperCase()
});
assert.ok(uppercaseKeys.MATH, 'renamed key MATH should exist');
assert.ok(uppercaseKeys.MATH.ADD, 'renamed key MATH.ADD should exist');
assert.strictEqual(uppercaseKeys.MATH.ADD(3, 4), 7, 'renamed function should be callable');

// 4. allows transforming imported modules using the visit option callback
let visitedCount = 0;
const visitedModules = loadModules(module, './fixtures', {
  visit: (obj, fullPath, filename) => {
    visitedCount++;
    if (typeof obj === 'function') {
      return { wrapped: obj, filename };
    }
    return obj;
  }
});
assert.ok(visitedCount > 0, 'visitor should be called for each imported module');
assert.strictEqual(typeof visitedModules.math.add.wrapped, 'function', 'math.add should be wrapped by visitor');
assert.strictEqual(visitedModules.math.add.wrapped(2, 3), 5, 'wrapped math.add should work');
assert.strictEqual(visitedModules.math.add.filename, 'add.js', 'visitor should receive filename');

// 5. honors recurse option to toggle recursive subfolder traversal
const nonRecursive = loadModules(module, './fixtures', {
  recurse: false
});
assert.ok(nonRecursive.config, 'top-level config.json should be loaded');
assert.strictEqual(nonRecursive.math, undefined, 'math subdirectory should not be loaded when recurse is false');
assert.strictEqual(nonRecursive.helpers, undefined, 'helpers subdirectory should not be loaded when recurse is false');

console.log('All require-directory contract tests passed successfully.');
test/fixtures/config.json
{
  "name": "sample-config",
  "enabled": true
}
test/fixtures/helpers/format.js
module.exports = function format(str) {
  return String(str).trim();
};
test/fixtures/helpers/ignore.txt
This is an ignored non-code file.
test/fixtures/math/add.js
module.exports = function add(a, b) {
  return a + b;
};
test/fixtures/math/subtract.js
module.exports = function subtract(a, b) {
  return a - b;
};

Origin Seeder

anonymous