CodeSampleX

サンプル

minimatch 3.1.5

検証済みサンプル — npm minimatch 3.1.5. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: minimatch tests paths against glob patterns with support for…

sha256:9e960e084fe3b9b9c9ba95ce08255514dd7f3f1d374fc235d8fb072c652031e0

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

実行証拠

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

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

検証実行環境

環境 コントラクト ステージ 実行日
node 22 · linux alpine/x64 · docker ed25519:2a6aa94bf40f1df0 SKIPPED compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL
CONTAINER_RUN · node-typescript@1
2026-08-19
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

ケース

HOW
ゴール
verify pkg:npm/minimatch@3.1.5
パッケージ
環境
node 22.23.2
作成日
2026-08-19T22:01:40Z

コントラクト

  1. minimatch tests paths against glob patterns with support for wildcards, globstars, brace expansions, and options like nocase and dot
  2. minimatch.match filters an array of path strings against a glob pattern returning only matches
  3. minimatch.filter returns a predicate function compatible with Array.prototype.filter for glob matching
  4. minimatch.makeRe compiles a glob pattern into a RegExp instance for regular expression matching
  5. minimatch.Minimatch creates a reusable matcher instance with pre-parsed pattern set and match method

ファイル

  • 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/minimatch@3.1.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/minimatch@3.1.5
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:dd5c34a40cd5e31fcadf86a7b62b5e0eff9141391c4fc5dec2d32ff42b08c991","constraints":{"executionContext":"node"},"contract":["minimatch tests paths against glob patterns with support for wildcards, globstars, brace expansions, and options like nocase and dot","minimatch.match filters an array of path strings against a glob pattern returning only matches","minimatch.filter returns a predicate function compatible with Array.prototype.filter for glob matching","minimatch.makeRe compiles a glob pattern into a RegExp instance for regular expression matching","minimatch.Minimatch creates a reusable matcher instance with pre-parsed pattern set and match method"],"goal":"verify pkg:npm/minimatch@3.1.5","kind":"HOW","packages":["pkg:npm/minimatch@3.1.5"],"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/minimatch@3.1.5"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "minimatch-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "minimatch-sample",
      "version": "1.0.0",
      "dependencies": {
        "minimatch": "3.1.5"
      }
    },
    "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/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": "*"
      }
    }
  }
}
package.json
{
  "name": "minimatch-sample",
  "version": "1.0.0",
  "dependencies": {
    "minimatch": "3.1.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/minimatch@3.1.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/minimatch@3.1.5"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const minimatch = require('minimatch');

/**
 * Tests if a path matches a pattern.
 *
 * @param {string} p - Path to match.
 * @param {string} pattern - Glob pattern.
 * @param {object} [options] - Minimatch options.
 * @returns {boolean} True if matched.
 */
function matchPath(p, pattern, options) {
  return minimatch(p, pattern, options);
}

/**
 * Filters an array of paths against a pattern.
 *
 * @param {string[]} list - List of paths.
 * @param {string} pattern - Glob pattern.
 * @param {object} [options] - Minimatch options.
 * @returns {string[]} Filtered paths.
 */
function matchAll(list, pattern, options) {
  return minimatch.match(list, pattern, options);
}

/**
 * Returns a filter function for Array.prototype.filter.
 *
 * @param {string} pattern - Glob pattern.
 * @param {object} [options] - Minimatch options.
 * @returns {(p: string, index?: number, array?: string[]) => boolean} Filter function.
 */
function createFilter(pattern, options) {
  return minimatch.filter(pattern, options);
}

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

/**
 * Creates a Minimatch instance for repeated pattern evaluation.
 *
 * @param {string} pattern - Glob pattern.
 * @param {object} [options] - Minimatch options.
 * @returns {minimatch.Minimatch} Minimatch instance.
 */
function createMinimatch(pattern, options) {
  return new minimatch.Minimatch(pattern, options);
}

module.exports = {
  matchPath,
  matchAll,
  createFilter,
  compilePattern,
  createMinimatch,
  minimatch,
};
test/contract.js
const assert = require('node:assert/strict');
const {
  matchPath,
  matchAll,
  createFilter,
  compilePattern,
  createMinimatch,
} = require('../src/index.js');

// Contract 1: minimatch tests paths against glob patterns with support for wildcards, globstars, brace expansions, and options like nocase and dot
{
  assert.strictEqual(matchPath('foo.js', '*.js'), true, 'Matches simple glob');
  assert.strictEqual(matchPath('src/utils/math.js', 'src/**/*.js'), true, 'Matches globstar hierarchy');
  assert.strictEqual(matchPath('build/out.ts', 'src/**/*.js'), false, 'Rejects unmatched path and extension');
  assert.strictEqual(matchPath('app.test.js', '*.{test,spec}.js'), true, 'Matches brace expansion alternative 1');
  assert.strictEqual(matchPath('app.spec.js', '*.{test,spec}.js'), true, 'Matches brace expansion alternative 2');
  assert.strictEqual(matchPath('app.dev.js', '*.{test,spec}.js'), false, 'Rejects brace expansion non-match');

  assert.strictEqual(matchPath('INDEX.JS', '*.js', { nocase: true }), true, 'Supports nocase option');
  assert.strictEqual(matchPath('INDEX.JS', '*.js', { nocase: false }), false, 'Rejects case mismatch when nocase is false');

  assert.strictEqual(matchPath('.gitignore', '.*', { dot: true }), true, 'Matches dotfile with dot option');
  assert.strictEqual(matchPath('.gitignore', '*', { dot: false }), false, 'Rejects dotfile by default');
}

// Contract 2: minimatch.match filters an array of path strings against a glob pattern returning only matches
{
  const files = [
    'src/index.js',
    'src/index.test.js',
    'src/components/Header.jsx',
    'docs/readme.md',
    'package.json',
  ];

  const jsFiles = matchAll(files, '**/*.js');
  assert.deepStrictEqual(jsFiles, ['src/index.js', 'src/index.test.js'], 'Filters JS files across directories');

  const docFiles = matchAll(files, '*.md', { matchBase: true });
  assert.deepStrictEqual(docFiles, ['docs/readme.md'], 'Filters files matching basename');

  const emptyMatches = matchAll(files, '*.png');
  assert.deepStrictEqual(emptyMatches, [], 'Returns empty array on no match');
}

// Contract 3: minimatch.filter returns a predicate function compatible with Array.prototype.filter for glob matching
{
  const files = ['a.txt', 'b.md', 'c.txt', 'd.json'];
  const isTxt = createFilter('*.txt');
  const txtFiles = files.filter(isTxt);
  assert.deepStrictEqual(txtFiles, ['a.txt', 'c.txt'], 'Filters array using predicate');

  const isMdOrJson = createFilter('*.{md,json}');
  const mdAndJsonFiles = files.filter(isMdOrJson);
  assert.deepStrictEqual(mdAndJsonFiles, ['b.md', 'd.json'], 'Filters using brace expansion predicate');
}

// Contract 4: minimatch.makeRe compiles a glob pattern into a RegExp instance for regular expression matching
{
  const re = compilePattern('src/**/*.ts');
  assert.ok(re instanceof RegExp, 'Returns RegExp instance');
  assert.strictEqual(re.test('src/models/user.ts'), true, 'Compiled RegExp matches pattern');
  assert.strictEqual(re.test('dist/models/user.js'), false, 'Compiled RegExp rejects non-matching pattern');
}

// Contract 5: minimatch.Minimatch creates a reusable matcher instance with pre-parsed pattern set and match method
{
  const mm = createMinimatch('lib/**/*.js');
  assert.strictEqual(mm.match('lib/core/api.js'), true, 'Minimatch instance matches target file');
  assert.strictEqual(mm.match('lib/core/api.ts'), false, 'Minimatch instance rejects non-matching extension');
  assert.ok(Array.isArray(mm.set), 'Minimatch exposes parsed pattern set');
  assert.strictEqual(mm.pattern, 'lib/**/*.js', 'Minimatch retains original pattern');
}

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

オリジンシーダー

匿名