示例
require-directory 2.1.1
已验证示例 — npm require-directory 2.1.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: requireDirectory loads all supported modules recursively from a…
sha256:cc9764aadfbf42acfb4d422d91ab2f297f0ff619f62616755634186c288533f8
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify pkg:npm/require-directory@2.1.1
- 环境
- node 22.23.2
- 创建时间
- 2026-08-23T08:24:02Z
契约
- 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
文件
- 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
源代码
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.
{"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"}
{
"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"
}
}
}
}
{
"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"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/require-directory@2.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/require-directory@2.1.1"
]
}
const requireDirectory = require('require-directory');
function loadModules(callingModule, targetPath, options) {
return requireDirectory(callingModule, targetPath, options);
}
module.exports = {
requireDirectory,
loadModules
};
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.');
{
"name": "sample-config",
"enabled": true
}
module.exports = function format(str) {
return String(str).trim();
};
This is an ignored non-code file.
module.exports = function add(a, b) {
return a + b;
};
module.exports = function subtract(a, b) {
return a - b;
};
原始种子者
匿名