CodeSampleX

サンプル

graceful-fs 4.2.11: rmSync

検証済みサンプル — npm graceful-fs 4.2.11: rmSync. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: gracefulFs.rmSync removes an existing file…

sha256:13609655ea17f6516d8fe125df81363513ce2420467823c6cd572b97f0370494

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

実行証拠

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

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

検証実行環境

環境 コントラクト ステージ 実行日
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-05

ケース

HOW
ゴール
verify graceful-fs.rmSync in pkg:npm/graceful-fs@4.2.11
パッケージ
シンボル
  • graceful-fs.rmSync
環境
node 22.23.2
作成日
2026-09-05T22:43:16Z

コントラクト

  1. gracefulFs.rmSync removes an existing file synchronously
  2. gracefulFs.rmSync removes a directory and its contents synchronously when recursive option is true
  3. gracefulFs.rmSync ignores non-existent paths without throwing when force option is true
  4. gracefulFs.rmSync throws ENOENT when path does not exist and force option is false
  5. gracefulFs.rmSync throws ERR_FS_EISDIR when attempting to remove a directory without recursive option
  6. gracefulFs.rmSync accepts retry options maxRetries and retryDelay during recursive removal
  7. gracefulFs.rmSync throws TypeError when path argument is not a valid string, Buffer, or URL

ファイル

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

ソースアーティファクトをダウンロード (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 graceful-fs.rmSync in pkg:npm/graceful-fs@4.2.11
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/graceful-fs@4.2.11
Demonstrate these symbols/APIs:
  - graceful-fs.rmSync

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:cf5f80182b3c0e6e4e1c50d07a18378b0ee6c1edaf71aa99caefcc877aeeaada","contract":["gracefulFs.rmSync removes an existing file synchronously","gracefulFs.rmSync removes a directory and its contents synchronously when recursive option is true","gracefulFs.rmSync ignores non-existent paths without throwing when force option is true","gracefulFs.rmSync throws ENOENT when path does not exist and force option is false","gracefulFs.rmSync throws ERR_FS_EISDIR when attempting to remove a directory without recursive option","gracefulFs.rmSync accepts retry options maxRetries and retryDelay during recursive removal","gracefulFs.rmSync throws TypeError when path argument is not a valid string, Buffer, or URL"],"goal":"verify graceful-fs.rmSync in pkg:npm/graceful-fs@4.2.11","kind":"HOW","packages":["pkg:npm/graceful-fs@4.2.11"],"schemaVersion":1,"symbols":["graceful-fs.rmSync"]},"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/graceful-fs@4.2.11"],"schemaVersion":1,"subject":"pkg:npm/graceful-fs@4.2.11","symbols":["graceful-fs.rmSync"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-graceful-fs-rmsync",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-graceful-fs-rmsync",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "graceful-fs": "4.2.11"
      }
    },
    "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"
    }
  }
}
package.json
{
  "name": "sample-graceful-fs-rmsync",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for graceful-fs.rmSync in graceful-fs@4.2.11",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "graceful-fs": "4.2.11"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify graceful-fs.rmSync in pkg:npm/graceful-fs@4.2.11",
  "kind": "HOW",
  "packages": [
    "pkg:npm/graceful-fs@4.2.11"
  ],
  "symbols": [
    "graceful-fs.rmSync"
  ]
}
src/index.js
'use strict';

const fs = require('graceful-fs');

/**
 * Removes files and directories synchronously using graceful-fs.rmSync.
 *
 * @param {string|Buffer|URL} path - Path to file or directory.
 * @param {object} [options] - Removal options (e.g. force, recursive, maxRetries, retryDelay).
 */
function removeSync(path, options) {
  return fs.rmSync(path, options);
}

module.exports = {
  gracefulFs: fs,
  removeSync
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import os from 'node:os';
import path from 'node:path';

const require = createRequire(import.meta.url);
const { gracefulFs, removeSync } = require('../src/index.js');

function testAll() {
  // Verify export functions
  assert.equal(typeof gracefulFs.rmSync, 'function', 'gracefulFs.rmSync must be a function');
  assert.equal(typeof removeSync, 'function', 'removeSync helper must be a function');

  const baseDir = gracefulFs.mkdtempSync(path.join(os.tmpdir(), 'gfs-rmsync-'));

  try {
    // 1. gracefulFs.rmSync removes an existing file synchronously
    const testFile = path.join(baseDir, 'file-to-remove.txt');
    gracefulFs.writeFileSync(testFile, 'hello world', 'utf8');
    assert.ok(gracefulFs.existsSync(testFile), 'file must exist before removal');
    removeSync(testFile);
    assert.ok(!gracefulFs.existsSync(testFile), 'file must not exist after removal');

    // 2. gracefulFs.rmSync removes a directory and its contents synchronously when recursive option is true
    const recursiveDir = path.join(baseDir, 'recursive-dir');
    const nestedSubDir = path.join(recursiveDir, 'sub');
    const nestedFile = path.join(nestedSubDir, 'nested.txt');
    gracefulFs.mkdirSync(recursiveDir);
    gracefulFs.mkdirSync(nestedSubDir);
    gracefulFs.writeFileSync(nestedFile, 'nested data', 'utf8');
    assert.ok(gracefulFs.existsSync(nestedFile), 'nested file must exist before recursive removal');
    removeSync(recursiveDir, { recursive: true });
    assert.ok(!gracefulFs.existsSync(recursiveDir), 'recursive directory must not exist after removal');

    // 3. gracefulFs.rmSync ignores non-existent paths without throwing when force option is true
    const nonExistentPath = path.join(baseDir, 'does-not-exist.txt');
    assert.doesNotThrow(() => {
      removeSync(nonExistentPath, { force: true });
    }, 'rmSync with force: true must not throw for non-existent file');

    // 4. gracefulFs.rmSync throws ENOENT when path does not exist and force option is false
    assert.throws(
      () => removeSync(nonExistentPath),
      (err) => err && (err.code === 'ENOENT' || (err.message && err.message.includes('ENOENT'))),
      'rmSync must throw ENOENT for non-existent path when force is false'
    );

    // 5. gracefulFs.rmSync throws ERR_FS_EISDIR when attempting to remove a directory without recursive option
    const dirWithoutRecursive = path.join(baseDir, 'dir-without-recursive');
    gracefulFs.mkdirSync(dirWithoutRecursive);
    assert.throws(
      () => removeSync(dirWithoutRecursive),
      (err) => err && (err.code === 'ERR_FS_EISDIR' || err.code === 'EISDIR' || (err.message && (err.message.includes('EISDIR') || err.message.includes('is a directory')))),
      'rmSync must throw error when removing directory without recursive option'
    );
    gracefulFs.rmSync(dirWithoutRecursive, { recursive: true, force: true });

    // 6. gracefulFs.rmSync accepts retry options maxRetries and retryDelay during recursive removal
    const retryDir = path.join(baseDir, 'retry-dir');
    gracefulFs.mkdirSync(retryDir);
    assert.doesNotThrow(() => {
      removeSync(retryDir, { recursive: true, maxRetries: 2, retryDelay: 10 });
    }, 'rmSync must accept maxRetries and retryDelay options');
    assert.ok(!gracefulFs.existsSync(retryDir), 'retry directory must not exist after removal');

    // 7. gracefulFs.rmSync throws TypeError when path argument is not a valid string, Buffer, or URL
    assert.throws(
      () => removeSync(12345),
      { name: 'TypeError' },
      'rmSync must throw TypeError when path argument is not string, Buffer, or URL'
    );
  } finally {
    if (gracefulFs.existsSync(baseDir)) {
      gracefulFs.rmSync(baseDir, { recursive: true, force: true });
    }
  }

  console.log('All graceful-fs.rmSync contract assertions passed successfully.');
}

testAll();

オリジンシーダー

匿名