CodeSampleX

示例

rimraf 3.0.2: sync

已验证示例 — npm rimraf 3.0.2: sync. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: rimraf.sync synchronously removes a single file without error

sha256:41430b1a9af935af2a8adaa5160c6c4434072e6865c31fb551a5508a4b34cc0d

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-04

案例

HOW
目标
verify rimraf.sync in pkg:npm/rimraf@3.0.2
包
符号
  • rimraf.sync
环境
node 22.23.2
创建时间
2026-09-04T12:41:17Z

契约

  1. rimraf.sync synchronously removes a single file without error
  2. rimraf.sync synchronously removes nested directory structures and all contained files
  3. rimraf.sync synchronously completes without throwing when target path does not exist
  4. rimraf.sync synchronously removes paths matching a glob pattern

文件

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

下载源代码构件 (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 rimraf.sync in pkg:npm/rimraf@3.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/rimraf@3.0.2
Demonstrate these symbols/APIs:
  - rimraf.sync

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:cd21e5a19cc8095fc15be1f7f280b80a89033aac02f0860fe79723adef649bd1","contract":["rimraf.sync synchronously removes a single file without error","rimraf.sync synchronously removes nested directory structures and all contained files","rimraf.sync synchronously completes without throwing when target path does not exist","rimraf.sync synchronously removes paths matching a glob pattern"],"goal":"verify rimraf.sync in pkg:npm/rimraf@3.0.2","kind":"HOW","packages":["pkg:npm/rimraf@3.0.2"],"schemaVersion":1,"symbols":["rimraf.sync"]},"contractCommand":["node","test/contract.js"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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/rimraf@3.0.2"],"schemaVersion":1,"subject":"pkg:npm/rimraf@3.0.2","symbols":["rimraf.sync"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const rimraf = require('rimraf');

/**
 * Synchronously removes a file or directory path using rimraf.sync.
 * @param {string} targetPath - Path or glob pattern to remove.
 * @param {object} [options] - Options passed to rimraf.sync.
 */
function removeSync(targetPath, options) {
  rimraf.sync(targetPath, options);
}

module.exports = {
  rimraf,
  removeSync
};
package-lock.json
{
  "name": "sample-rimraf-sync",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-rimraf-sync",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "rimraf": "3.0.2"
      }
    },
    "node_modules/balanced-match": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
      "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
      "license": "MIT"
    },
    "node_modules/brace-expansion": {
      "version": "1.1.18",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.18.tgz",
      "integrity": "sha512-Edep/X9fGqVNmzKBVsDYIOtD+z1tuezV70LBjdCst9Tqu76lsnvRiZ6oTic1n+/BIwX6QDGAO94PN4N2SADvtw==",
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "node_modules/concat-map": {
      "version": "0.0.1",
      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
      "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
      "license": "MIT"
    },
    "node_modules/fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
      "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
      "license": "ISC"
    },
    "node_modules/glob": {
      "version": "7.2.3",
      "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
      "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
      "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me",
      "license": "ISC",
      "dependencies": {
        "fs.realpath": "^1.0.0",
        "inflight": "^1.0.4",
        "inherits": "2",
        "minimatch": "^3.1.1",
        "once": "^1.3.0",
        "path-is-absolute": "^1.0.0"
      },
      "engines": {
        "node": "*"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    },
    "node_modules/inflight": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
      "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
      "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.",
      "license": "ISC",
      "dependencies": {
        "once": "^1.3.0",
        "wrappy": "1"
      }
    },
    "node_modules/inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
      "license": "ISC"
    },
    "node_modules/minimatch": {
      "version": "3.1.5",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz",
      "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==",
      "license": "ISC",
      "dependencies": {
        "brace-expansion": "^1.1.7"
      },
      "engines": {
        "node": "*"
      }
    },
    "node_modules/once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
      "license": "ISC",
      "dependencies": {
        "wrappy": "1"
      }
    },
    "node_modules/path-is-absolute": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
      "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    },
    "node_modules/rimraf": {
      "version": "3.0.2",
      "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
      "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
      "deprecated": "Rimraf versions prior to v4 are no longer supported",
      "license": "ISC",
      "dependencies": {
        "glob": "^7.1.3"
      },
      "bin": {
        "rimraf": "bin.js"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    },
    "node_modules/wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
      "license": "ISC"
    }
  }
}
package.json
{
  "name": "sample-rimraf-sync",
  "version": "1.0.0",
  "private": true,
  "description": "verify rimraf.sync in pkg:npm/rimraf@3.0.2",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "rimraf": "3.0.2"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify rimraf.sync in pkg:npm/rimraf@3.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/rimraf@3.0.2"
  ],
  "symbols": [
    "rimraf.sync"
  ]
}
test/contract.js
'use strict';

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const os = require('os');
const rimraf = require('rimraf');
const { removeSync } = require('../index.js');

function testSyncRemoveSingleFile(tmpDir) {
  const testFile = path.join(tmpDir, 'file-to-remove.txt');
  fs.writeFileSync(testFile, 'test payload', 'utf8');
  assert.strictEqual(fs.existsSync(testFile), true, 'File should exist before removal');

  rimraf.sync(testFile);
  assert.strictEqual(fs.existsSync(testFile), false, 'rimraf.sync should delete single file synchronously');
}

function testSyncRemoveNestedDirectories(tmpDir) {
  const rootDir = path.join(tmpDir, 'nested-tree');
  const deepDir = path.join(rootDir, 'level1', 'level2');
  fs.mkdirSync(deepDir, { recursive: true });
  fs.writeFileSync(path.join(rootDir, 'root.txt'), 'root data', 'utf8');
  fs.writeFileSync(path.join(deepDir, 'leaf.txt'), 'leaf data', 'utf8');
  assert.strictEqual(fs.existsSync(rootDir), true, 'Directory tree should exist before removal');

  removeSync(rootDir);
  assert.strictEqual(fs.existsSync(rootDir), false, 'rimraf.sync helper should delete directory tree synchronously');
}

function testSyncRemoveNonExistentPath(tmpDir) {
  const nonExistent = path.join(tmpDir, 'does-not-exist');
  assert.doesNotThrow(() => {
    rimraf.sync(nonExistent);
  }, 'rimraf.sync should complete without throwing when target path does not exist');
}

function testSyncRemoveGlobPattern(tmpDir) {
  const globDir = path.join(tmpDir, 'glob-test');
  fs.mkdirSync(globDir, { recursive: true });
  fs.writeFileSync(path.join(globDir, 'file1.tmp'), 'data1', 'utf8');
  fs.writeFileSync(path.join(globDir, 'file2.tmp'), 'data2', 'utf8');
  fs.writeFileSync(path.join(globDir, 'file3.keep'), 'keep data', 'utf8');

  rimraf.sync(path.join(globDir, '*.tmp'));
  assert.strictEqual(fs.existsSync(path.join(globDir, 'file1.tmp')), false, 'Glob-matched file1 should be deleted');
  assert.strictEqual(fs.existsSync(path.join(globDir, 'file2.tmp')), false, 'Glob-matched file2 should be deleted');
  assert.strictEqual(fs.existsSync(path.join(globDir, 'file3.keep')), true, 'Non-matching file should be preserved');
}

function main() {
  const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-contract-rimraf-sync-'));
  try {
    testSyncRemoveSingleFile(tmpBase);
    testSyncRemoveNestedDirectories(tmpBase);
    testSyncRemoveNonExistentPath(tmpBase);
    testSyncRemoveGlobPattern(tmpBase);
    console.log('Contract tests passed successfully.');
  } finally {
    try {
      if (fs.existsSync(tmpBase)) {
        rimraf.sync(tmpBase);
      }
    } catch (e) {
      // ignore cleanup errors
    }
  }
}

main();

原始种子者

匿名