CodeSampleX

Exemple

fs-extra 11.4.0

Échantillon vérifié pour npm fs-extra 11.4.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : ensureDir creates nested…

sha256:43dec1b1f7c63de082baeaec7aa8bb815f0979be617fc3da06d36e0222551a35

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/fs-extra@11.4.0
Paquets
Environnement
node 22.23.2
Créé
2026-08-20T20:16:46Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

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

Use EXACTLY these public packages and versions:
  - pkg:npm/fs-extra@11.4.0
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:72f0a5b5c840eef3beeb68016d10037afc33b5cc30c2db780aa1f0f6bc22c3bf","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.4.0","kind":"HOW","packages":["pkg:npm/fs-extra@11.4.0"],"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.4.0"],"schemaVersion":1,"subject":"pkg:npm/fs-extra@11.4.0","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.4.0"
      }
    },
    "node_modules/fs-extra": {
      "version": "11.4.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.4.0.tgz",
      "integrity": "sha512-EQsFzMUJkCKGr1ePqlYADkIUmHW1s3ZXr5Yqy6wbGrfUCphpl2maM/kyOIRA2HpP3AaFQTZXD4ldjek+nccddA==",
      "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.4.0",
  "main": "index.js",
  "dependencies": {
    "fs-extra": "11.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/fs-extra@11.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/fs-extra@11.4.0"
  ],
  "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);
});

Seeder d'origine

anonyme