CodeSampleX

示例

picomatch 2.3.2

已验证示例 — npm picomatch 2.3.2. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: picomatch creates compiled matcher functions supporting wildcards, brace…

sha256:eb22deb580c1183937b491034ad7e0de6b41a97941dbc88293cebb76f51d7443

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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-27

案例

HOW
目标
verify pkg:npm/picomatch@2.3.2
包
环境
node 22.23.2
创建时间
2026-08-27T15:29:24Z

契约

  1. picomatch creates compiled matcher functions supporting wildcards, brace expansions, and negated patterns
  2. picomatch.isMatch evaluates paths against glob patterns with support for case-insensitivity, dotfiles, and ignore rules
  3. picomatch.scan parses glob patterns into components including static base directory, glob portion, and isGlob metadata
  4. picomatch.makeRe compiles glob patterns into RegExp instances for regular expression matching

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 pkg:npm/picomatch@2.3.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/picomatch@2.3.2
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:4c8d305f92c97cfc254d87f30ab3ec866843a00e18d6b707d97faac9407398f1","constraints":{"executionContext":"node"},"contract":["picomatch creates compiled matcher functions supporting wildcards, brace expansions, and negated patterns","picomatch.isMatch evaluates paths against glob patterns with support for case-insensitivity, dotfiles, and ignore rules","picomatch.scan parses glob patterns into components including static base directory, glob portion, and isGlob metadata","picomatch.makeRe compiles glob patterns into RegExp instances for regular expression matching"],"goal":"verify pkg:npm/picomatch@2.3.2","kind":"HOW","packages":["pkg:npm/picomatch@2.3.2"],"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/picomatch@2.3.2"],"schemaVersion":1,"subject":"pkg:npm/picomatch@2.3.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "picomatch-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "picomatch-sample",
      "version": "1.0.0",
      "dependencies": {
        "picomatch": "2.3.2"
      }
    },
    "node_modules/picomatch": {
      "version": "2.3.2",
      "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz",
      "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==",
      "license": "MIT",
      "engines": {
        "node": ">=8.6"
      },
      "funding": {
        "url": "https://github.com/sponsors/jonschlinkert"
      }
    }
  }
}
package.json
{
  "name": "picomatch-sample",
  "version": "1.0.0",
  "dependencies": {
    "picomatch": "2.3.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/picomatch@2.3.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/picomatch@2.3.2"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const picomatch = require('picomatch');

/**
 * Creates a compiled matcher function for one or more glob patterns.
 *
 * @param {string|string[]} patterns - Glob pattern or array of patterns.
 * @param {object} [options] - Picomatch options.
 * @returns {(input: string) => boolean} Matcher function.
 */
function createMatcher(patterns, options) {
  return picomatch(patterns, options);
}

/**
 * Tests whether a path string matches a glob pattern.
 *
 * @param {string} input - Path string to test.
 * @param {string|string[]} patterns - Glob pattern or patterns.
 * @param {object} [options] - Options such as ignore, nocase, dot.
 * @returns {boolean} True if matched.
 */
function matchPath(input, patterns, options) {
  return picomatch.isMatch(input, patterns, options);
}

/**
 * Scans a glob pattern string to extract static base path, glob component, and metadata.
 *
 * @param {string} pattern - Glob pattern to analyze.
 * @param {object} [options] - Scan options.
 * @returns {object} Scan result object.
 */
function scanPattern(pattern, options) {
  return picomatch.scan(pattern, options);
}

/**
 * Compiles a glob pattern into a regular expression.
 *
 * @param {string} pattern - Glob pattern.
 * @param {object} [options] - Regex options.
 * @returns {RegExp} Compiled RegExp.
 */
function compilePattern(pattern, options) {
  return picomatch.makeRe(pattern, options);
}

module.exports = {
  createMatcher,
  matchPath,
  scanPattern,
  compilePattern,
  picomatch,
};
test/contract.js
const assert = require('node:assert/strict');
const {
  createMatcher,
  matchPath,
  scanPattern,
  compilePattern,
} = require('../src/index.js');

// Contract 1: picomatch creates compiled matcher functions supporting wildcards, brace expansions, and negated patterns
{
  const isImage = createMatcher('*.{png,jpg,webp}');
  assert.strictEqual(isImage('photo.jpg'), true, 'Should match jpg via brace expansion');
  assert.strictEqual(isImage('banner.webp'), true, 'Should match webp via brace expansion');
  assert.strictEqual(isImage('vector.svg'), false, 'Should not match non-listed extension');

  const isSource = createMatcher(['src/**/*.js', 'src/**/*.ts']);
  assert.strictEqual(isSource('src/index.js'), true, 'Should match js file in src');
  assert.strictEqual(isSource('src/components/App.ts'), true, 'Should match ts file in nested src');
  assert.strictEqual(isSource('docs/readme.md'), false, 'Should not match md file outside src');

  const notTest = createMatcher('!**/*.test.js');
  assert.strictEqual(notTest('src/index.js'), true, 'Negated pattern matches non-test file');
  assert.strictEqual(notTest('src/index.test.js'), false, 'Negated pattern rejects test file');
}

// Contract 2: picomatch.isMatch evaluates paths against glob patterns with support for case-insensitivity, dotfiles, and ignore rules
{
  assert.strictEqual(matchPath('lib/utils.js', 'lib/*.js'), true, 'Direct match in lib directory');
  assert.strictEqual(matchPath('lib/sub/utils.js', 'lib/*.js'), false, 'Single star should not cross directory boundaries');

  assert.strictEqual(matchPath('README.MD', '*.md', { nocase: true }), true, 'nocase: true allows case-insensitive match');
  assert.strictEqual(matchPath('README.MD', '*.md', { nocase: false }), false, 'nocase: false enforces case sensitivity');

  assert.strictEqual(matchPath('.env', '*.env', { dot: true }), true, 'dot: true matches dotfiles');
  assert.strictEqual(matchPath('.env', '*.env', { dot: false }), false, 'dot: false ignores dotfiles by default');

  assert.strictEqual(
    matchPath('node_modules/pkg/index.js', '**/*.js', { ignore: '**/node_modules/**' }),
    false,
    'ignore option excludes matching paths'
  );
}

// Contract 3: picomatch.scan parses glob patterns into components including static base directory, glob portion, and isGlob metadata
{
  const scanned = scanPattern('src/assets/**/*.svg');
  assert.strictEqual(scanned.base, 'src/assets', 'Base directory before any glob characters');
  assert.strictEqual(scanned.glob, '**/*.svg', 'Glob portion extracted');
  assert.strictEqual(scanned.isGlob, true, 'isGlob should be true for wildcard pattern');

  const staticScan = scanPattern('src/config/settings.json');
  assert.strictEqual(staticScan.base, 'src/config/settings.json', 'Static path base equals full input');
  assert.strictEqual(staticScan.glob, '', 'Static path has empty glob portion');
  assert.strictEqual(staticScan.isGlob, false, 'isGlob should be false for static path');
}

// Contract 4: picomatch.makeRe compiles glob patterns into RegExp instances for regular expression matching
{
  const re = compilePattern('build/*.min.js');
  assert.ok(re instanceof RegExp, 'Should return a RegExp instance');
  assert.strictEqual(re.test('build/app.min.js'), true, 'Compiled regex matches expected target');
  assert.strictEqual(re.test('build/app.js'), false, 'Compiled regex rejects unmatched target');
  assert.strictEqual(re.test('dist/app.min.js'), false, 'Compiled regex respects directory prefix');
}

console.log('All pkg:npm/picomatch@2.3.2 contracts passed successfully.');

原始种子者

匿名