CodeSampleX

示例

minimatch 9.0.9

已验证示例 — npm minimatch 9.0.9. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: matchPath tests file paths against glob patterns with wildcards, single…

sha256:bd6d3e054d0c0e5105ccbace0b3714afa38ef995cd3aecfb209526468b51bf15

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

案例

HOW
目标
verify pkg:npm/minimatch@9.0.9
包
环境
node 22.23.2
创建时间
2026-08-21T03:55:20Z

契约

  1. matchPath tests file paths against glob patterns with wildcards, single character matches, and character classes
  2. createFilter generates a predicate function for filtering path arrays with glob patterns
  3. matchFiles filters an array of paths matching a glob pattern directly
  4. globToRegex converts glob patterns into RegExp instances for pattern matching
  5. Minimatch class instantiates glob matchers with match and hasMagic methods
  6. expandBraces expands brace alternative patterns into multiple glob combinations
  7. escapeGlob and unescapeGlob escape and unescape glob magic characters
  8. matchPath supports dot, nocase, and matchBase options for specialized glob matching

文件

  • 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 pkg:npm/minimatch@9.0.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/minimatch@9.0.9
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:61837f036038392e784f8fdd478f2b225c8dfa356554543638bbfef3633f0627","constraints":{"executionContext":"node"},"contract":["matchPath tests file paths against glob patterns with wildcards, single character matches, and character classes","createFilter generates a predicate function for filtering path arrays with glob patterns","matchFiles filters an array of paths matching a glob pattern directly","globToRegex converts glob patterns into RegExp instances for pattern matching","Minimatch class instantiates glob matchers with match and hasMagic methods","expandBraces expands brace alternative patterns into multiple glob combinations","escapeGlob and unescapeGlob escape and unescape glob magic characters","matchPath supports dot, nocase, and matchBase options for specialized glob matching"],"goal":"verify pkg:npm/minimatch@9.0.9","kind":"HOW","packages":["pkg:npm/minimatch@9.0.9"],"schemaVersion":1},"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/minimatch@9.0.9"],"schemaVersion":1,"subject":"pkg:npm/minimatch@9.0.9","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-minimatch",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-minimatch",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "minimatch": "9.0.9"
      }
    },
    "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": "2.1.4",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.4.tgz",
      "integrity": "sha512-hGfVzPxthbf3+2yjg/RBs60cB0FhqBS/zvdV/4wn4/BmN0bNMMHPc4V/BbFieqf1TKAGGAHnY4eSjajCl0f2Xg==",
      "license": "MIT",
      "dependencies": {
        "balanced-match": "^1.0.0"
      }
    },
    "node_modules/minimatch": {
      "version": "9.0.9",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz",
      "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==",
      "license": "ISC",
      "dependencies": {
        "brace-expansion": "^2.0.2"
      },
      "engines": {
        "node": ">=16 || 14 >=14.17"
      },
      "funding": {
        "url": "https://github.com/sponsors/isaacs"
      }
    }
  }
}
package.json
{
  "name": "sample-minimatch",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of minimatch",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "minimatch": "9.0.9"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/minimatch@9.0.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/minimatch@9.0.9"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const minimatchPkg = require('minimatch');
const minimatch = typeof minimatchPkg === 'function' ? minimatchPkg : minimatchPkg.minimatch;
const {
  filter = minimatch.filter,
  match = minimatch.match,
  makeRe = minimatch.makeRe,
  braceExpand = minimatch.braceExpand,
  escape = minimatch.escape,
  unescape = minimatch.unescape,
  Minimatch = minimatch.Minimatch
} = minimatchPkg;

/**
 * Tests whether a path string matches a glob pattern.
 * @param {string} p - File path to test
 * @param {string} pattern - Glob pattern
 * @param {object} [options] - Matching options
 * @returns {boolean}
 */
function matchPath(p, pattern, options) {
  return minimatch(p, pattern, options);
}

/**
 * Returns a filter predicate function for arrays.
 * @param {string} pattern - Glob pattern
 * @param {object} [options] - Matching options
 * @returns {Function}
 */
function createFilter(pattern, options) {
  return filter(pattern, options);
}

/**
 * Filters a list of path strings matching a pattern.
 * @param {string[]} list - Array of path strings
 * @param {string} pattern - Glob pattern
 * @param {object} [options] - Matching options
 * @returns {string[]}
 */
function matchFiles(list, pattern, options) {
  return match(list, pattern, options);
}

/**
 * Converts a glob pattern into a regular expression.
 * @param {string} pattern - Glob pattern
 * @param {object} [options] - Matching options
 * @returns {RegExp|null}
 */
function globToRegex(pattern, options) {
  return makeRe(pattern, options);
}

/**
 * Expands brace patterns into an array of glob strings.
 * @param {string} pattern - Glob pattern containing braces
 * @param {object} [options] - Matching options
 * @returns {string[]}
 */
function expandBraces(pattern, options) {
  return braceExpand(pattern, options);
}

/**
 * Escapes glob magic characters in a string.
 * @param {string} pattern - Glob pattern
 * @returns {string}
 */
function escapeGlob(pattern) {
  return escape(pattern);
}

/**
 * Unescapes glob magic characters in a string.
 * @param {string} pattern - Glob pattern
 * @returns {string}
 */
function unescapeGlob(pattern) {
  return unescape(pattern);
}

/**
 * Creates a Minimatch class instance for compiled glob operations.
 * @param {string} pattern - Glob pattern
 * @param {object} [options] - Matching options
 * @returns {Minimatch}
 */
function createMinimatch(pattern, options) {
  return new Minimatch(pattern, options);
}

module.exports = {
  minimatch,
  Minimatch,
  matchPath,
  createFilter,
  matchFiles,
  globToRegex,
  expandBraces,
  escapeGlob,
  unescapeGlob,
  createMinimatch
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  minimatch,
  Minimatch,
  matchPath,
  createFilter,
  matchFiles,
  globToRegex,
  expandBraces,
  escapeGlob,
  unescapeGlob,
  createMinimatch
} = require('../src/index.js');

// 1. Direct glob matching with wildcards, single character matches, and character classes
assert.strictEqual(matchPath('file.txt', '*.txt'), true, '*.txt matches file.txt');
assert.strictEqual(matchPath('file.js', '*.txt'), false, '*.txt does not match file.js');
assert.strictEqual(matchPath('foo1.js', 'foo?.js'), true, 'foo?.js matches foo1.js');
assert.strictEqual(matchPath('foo12.js', 'foo?.js'), false, 'foo?.js does not match foo12.js');
assert.strictEqual(matchPath('file3.txt', 'file[0-9].txt'), true, 'character class [0-9] matches 3');
assert.strictEqual(matchPath('fileA.txt', 'file[0-9].txt'), false, 'character class [0-9] rejects A');

// 2. filter creates a predicate function for Array.prototype.filter
const fileList = ['src/a.ts', 'src/b.js', 'test/a.test.js', 'package.json'];
const jsFilter = createFilter('**/*.js');
assert.deepStrictEqual(fileList.filter(jsFilter), ['src/b.js', 'test/a.test.js'], 'filter should filter matching paths');

// 3. match filters an array of strings directly
const matchedJson = matchFiles(fileList, '*.json');
assert.deepStrictEqual(matchedJson, ['package.json'], 'matchFiles should filter top-level json file');

// 4. makeRe converts glob pattern into a regular expression
const re = globToRegex('*.spec.js');
assert.ok(re instanceof RegExp, 'makeRe must return a RegExp instance');
assert.strictEqual(re.test('index.spec.js'), true, 'makeRe RegExp matches index.spec.js');
assert.strictEqual(re.test('index.js'), false, 'makeRe RegExp rejects index.js');

// 5. Minimatch class instantiation and match method
const mm = createMinimatch('src/**/*.ts');
assert.strictEqual(mm.match('src/components/Button.ts'), true, 'Minimatch instance matches nested ts file');
assert.strictEqual(mm.match('dist/index.js'), false, 'Minimatch instance rejects dist/index.js');
assert.strictEqual(mm.hasMagic(), true, 'hasMagic returns true for glob pattern');

// 6. braceExpand expands brace patterns into multiple glob strings
const expanded = expandBraces('{src,test}/**/*.{js,ts}');
assert.deepStrictEqual(
  expanded,
  ['src/**/*.js', 'src/**/*.ts', 'test/**/*.js', 'test/**/*.ts'],
  'expandBraces expands brace options'
);

// 7. escape and unescape handle glob special characters
const escaped = escapeGlob('hello*[world]?');
assert.strictEqual(escaped, 'hello\\*\\[world\\]\\?', 'escape backslashes special glob characters');
const unescaped = unescapeGlob('hello\\[world\\]');
assert.strictEqual(unescaped, 'hello[world]', 'unescape unescapes bracket characters');

// 8. Pattern matching options: dot, nocase, and matchBase
assert.strictEqual(matchPath('.env', '*.env'), false, 'dotfiles not matched by default wildcard');
assert.strictEqual(matchPath('.env', '*.env', { dot: true }), true, 'dot:true matches dotfiles');
assert.strictEqual(matchPath('README.MD', '*.md'), false, 'case-sensitive by default');
assert.strictEqual(matchPath('README.MD', '*.md', { nocase: true }), true, 'nocase:true ignores case');
assert.strictEqual(matchPath('nested/dir/app.js', '*.js', { matchBase: true }), true, 'matchBase matches filename in subdirectories');

console.log('Contract tests passed successfully.');

原始种子者

匿名