CodeSampleX

サンプル

fs-extra 11.3.1

検証済みサンプル — npm fs-extra 11.3.1. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: ensureDir creates nested directory structures if they do not exist

sha256:aa7391eac1a723861f5805a30a82ac2822dd03a8ce37cf9e0be5537fc06ad5b6

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

ケース

HOW
ゴール
verify pkg:npm/fs-extra@11.3.1
パッケージ
環境
node 22.23.2
作成日
2026-08-20T20:14:57Z

コントラクト

  1. ensureDir creates nested directory structures if they do not exist
  2. outputJson and readJson write and read JSON documents while automatically creating parent directories
  3. outputFile writes string data creating parent directories automatically and readFile retrieves the written content
  4. copy recursively copies directory hierarchies and supports custom filter functions
  5. emptyDir deletes all contents within a directory while leaving the directory itself intact
  6. pathExists accurately checks the existence of files and directories
  7. remove recursively removes directories and files without throwing if the target does not exist
  8. move moves files and directories across paths with optional overwrite
  9. ensureFile creates parent directories and an empty file if the file does not exist

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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/fs-extra@11.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/fs-extra@11.3.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - 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:a008f65cca884fbd05cb32b7c3ab73000db062e2a96192d0531b87efbbce7541","constraints":{"executionContext":"node"},"contract":["ensureDir creates nested directory structures if they do not exist","outputJson and readJson write and read JSON documents while automatically creating parent directories","outputFile writes string data creating parent directories automatically and readFile retrieves the written content","copy recursively copies directory hierarchies and supports custom filter functions","emptyDir deletes all contents within a directory while leaving the directory itself intact","pathExists accurately checks the existence of files and directories","remove recursively removes directories and files without throwing if the target does not exist","move moves files and directories across paths with optional overwrite","ensureFile creates parent directories and an empty file if the file does not exist"],"goal":"verify pkg:npm/fs-extra@11.3.1","kind":"HOW","packages":["pkg:npm/fs-extra@11.3.1"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/fs-extra@11.3.1"],"schemaVersion":1,"subject":"pkg:npm/fs-extra@11.3.1","verifierAdapter":"node-typescript@1"}
index.js
const fs = require('fs-extra');

module.exports = {
  fs
};
package-lock.json
{
  "name": "sample-fs-extra",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-fs-extra",
      "version": "1.0.0",
      "dependencies": {
        "fs-extra": "11.3.1"
      }
    },
    "node_modules/fs-extra": {
      "version": "11.3.1",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.1.tgz",
      "integrity": "sha512-eXvGGwZ5CL17ZSwHWd3bbgk7UUpF6IFHtP57NYYakPvHOs8GDgDe5KJI36jIJzDkJ6eJjuzRA8eBQb6SkKue0g==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=14.14"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/jsonfile": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-fs-extra",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for fs-extra@11.3.1",
  "main": "index.js",
  "dependencies": {
    "fs-extra": "11.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/fs-extra@11.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fs-extra@11.3.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert/strict');
const path = require('node:path');
const os = require('node:os');
const fs = require('fs-extra');

async function run() {
  const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'fs-extra-test-'));

  try {
    // 1. ensureDir creates nested directory structures if they do not exist
    const nestedDir = path.join(tmpDir, 'nested', 'a', 'b', 'c');
    await fs.ensureDir(nestedDir);
    const dirStat = await fs.stat(nestedDir);
    assert.equal(dirStat.isDirectory(), true);

    // 2. outputJson and readJson write and read JSON documents while automatically creating parent directories
    const jsonPath = path.join(tmpDir, 'json', 'data.json');
    const testData = { name: 'codesamplex', version: '1.0.0', active: true };
    await fs.outputJson(jsonPath, testData);
    const readData = await fs.readJson(jsonPath);
    assert.deepEqual(readData, testData);

    // 3. outputFile writes string data creating parent directories automatically and readFile retrieves the written content
    const filePath = path.join(tmpDir, 'files', 'hello.txt');
    await fs.outputFile(filePath, 'Hello, fs-extra!');
    const content = await fs.readFile(filePath, 'utf8');
    assert.equal(content, 'Hello, fs-extra!');

    // 4. copy recursively copies directory hierarchies and supports custom filter functions
    const srcDir = path.join(tmpDir, 'src_copy');
    const destDir = path.join(tmpDir, 'dest_copy');
    await fs.outputFile(path.join(srcDir, 'file1.txt'), 'content1');
    await fs.outputFile(path.join(srcDir, 'ignore.tmp'), 'ignore');
    await fs.copy(srcDir, destDir, {
      filter: (src) => !src.endsWith('.tmp')
    });
    assert.equal(await fs.pathExists(path.join(destDir, 'file1.txt')), true);
    assert.equal(await fs.pathExists(path.join(destDir, 'ignore.tmp')), false);

    // 5. emptyDir deletes all contents within a directory while leaving the directory itself intact
    const emptyTargetDir = path.join(tmpDir, 'to_empty');
    await fs.outputFile(path.join(emptyTargetDir, 'temp.txt'), 'data');
    await fs.emptyDir(emptyTargetDir);
    assert.equal(await fs.pathExists(emptyTargetDir), true);
    const items = await fs.readdir(emptyTargetDir);
    assert.equal(items.length, 0);

    // 6. pathExists accurately checks the existence of files and directories
    assert.equal(await fs.pathExists(emptyTargetDir), true);
    assert.equal(await fs.pathExists(path.join(tmpDir, 'non_existent')), false);

    // 7. remove recursively removes directories and files without throwing if the target does not exist
    const removeTarget = path.join(tmpDir, 'to_remove');
    await fs.outputFile(path.join(removeTarget, 'child.txt'), 'data');
    await fs.remove(removeTarget);
    assert.equal(await fs.pathExists(removeTarget), false);
    // removing non-existent target should not throw
    await fs.remove(path.join(tmpDir, 'does-not-exist'));

    // 8. move moves files and directories across paths with optional overwrite
    const moveSrc = path.join(tmpDir, 'move_src.txt');
    const moveDest = path.join(tmpDir, 'moved', 'move_dest.txt');
    await fs.outputFile(moveSrc, 'move content');
    await fs.move(moveSrc, moveDest);
    assert.equal(await fs.pathExists(moveSrc), false);
    assert.equal(await fs.readFile(moveDest, 'utf8'), 'move content');

    // 9. ensureFile creates parent directories and an empty file if the file does not exist
    const ensureFilePath = path.join(tmpDir, 'nested', 'deep', 'empty.txt');
    await fs.ensureFile(ensureFilePath);
    assert.equal(await fs.pathExists(ensureFilePath), true);
    const emptyStat = await fs.stat(ensureFilePath);
    assert.equal(emptyStat.isFile(), true);
    assert.equal(emptyStat.size, 0);

    console.log('All fs-extra assertions passed.');
  } finally {
    await fs.remove(tmpDir);
  }
}

run().catch((err) => {
  console.error(err);
  process.exit(1);
});

オリジンシーダー

匿名