CodeSampleX

Пример

@rolldown/pluginutils 1.0.0-rc.3

Проверенный пример — npm @rolldown/pluginutils 1.0.0-rc.3. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден.

sha256:295f41ed1011f9fc015dd9c3d7424121d57f34b98ef5a310e61faa7a3c94d05b

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-24
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-07

Кейс

HOW
Цель
verify pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3
Пакеты
Окружение
node 22.23.2
Создан
2026-08-24T06:51:46Z

Контракт

  1. exactRegex creates an anchored RegExp matching only the exact string
  2. prefixRegex creates a RegExp matching strings starting with the given prefix
  3. makeIdFiltersToMatchWithQuery adapts string globs and regular expressions to also match ids with query strings
  4. and, or, not create composable logical filter expressions
  5. query and queries construct query parameter filter expressions
  6. interpreter evaluates include and exclude expressions sequentially against module code, id, moduleType, and importerId
  7. interpreter correctly handles cleanUrl and query parameter checks
  8. filterVitePlugins removes dev server plugins while preserving build plugins and flattening nested arrays

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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/%40rolldown/pluginutils@1.0.0-rc.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3
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:d893d6d9ac7972d302b8cecbe58aeb8cf9c9dc82dc0899d3f63c7713f1d0ba06","constraints":{"executionContext":"node"},"contract":["exactRegex creates an anchored RegExp matching only the exact string","prefixRegex creates a RegExp matching strings starting with the given prefix","makeIdFiltersToMatchWithQuery adapts string globs and regular expressions to also match ids with query strings","and, or, not create composable logical filter expressions","query and queries construct query parameter filter expressions","interpreter evaluates include and exclude expressions sequentially against module code, id, moduleType, and importerId","interpreter correctly handles cleanUrl and query parameter checks","filterVitePlugins removes dev server plugins while preserving build plugins and flattening nested arrays"],"goal":"verify pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3","kind":"HOW","packages":["pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3"],"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/%40rolldown/pluginutils@1.0.0-rc.3"],"schemaVersion":1,"subject":"pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-rolldown-pluginutils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-rolldown-pluginutils",
      "version": "1.0.0",
      "dependencies": {
        "@rolldown/pluginutils": "1.0.0-rc.3"
      }
    },
    "node_modules/@rolldown/pluginutils": {
      "version": "1.0.0-rc.3",
      "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.3.tgz",
      "integrity": "sha512-eybk3TjzzzV97Dlj5c+XrBFW57eTNhzod66y9HrBlzJ6NsCrWCp/2kaPS3K9wJmurBC0Tdw4yPjXKZqlznim3Q==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-rolldown-pluginutils",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "@rolldown/pluginutils": "1.0.0-rc.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40rolldown/pluginutils@1.0.0-rc.3"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  exactRegex,
  prefixRegex,
  makeIdFiltersToMatchWithQuery,
  and,
  or,
  not,
  id,
  importerId,
  moduleType,
  code,
  query,
  queries,
  include,
  exclude,
  interpreter,
  filterVitePlugins,
} from '@rolldown/pluginutils';

// 1. exactRegex creates an anchored RegExp matching only the exact string
{
  const re = exactRegex('src/index.js');
  assert.ok(re instanceof RegExp);
  assert.equal(re.test('src/index.js'), true);
  assert.equal(re.test('a/src/index.js'), false);
  assert.equal(re.test('src/index.js/more'), false);

  const reFlags = exactRegex('foo.js', 'i');
  assert.equal(reFlags.test('FOO.JS'), true);
}

// 2. prefixRegex creates a RegExp matching strings starting with the given prefix
{
  const re = prefixRegex('node_modules/');
  assert.ok(re instanceof RegExp);
  assert.equal(re.test('node_modules/pkg/index.js'), true);
  assert.equal(re.test('src/node_modules/pkg'), false);
}

// 3. makeIdFiltersToMatchWithQuery adapts string globs and regular expressions to also match ids with query strings
{
  const globResult = makeIdFiltersToMatchWithQuery('**/*.js');
  assert.equal(globResult, '**/*.js{?*,}');

  const regexResult = makeIdFiltersToMatchWithQuery(/\.ts$/);
  assert.ok(regexResult instanceof RegExp);
  assert.equal(regexResult.test('file.ts'), true);
  assert.equal(regexResult.test('file.ts?inline'), true);
  assert.equal(regexResult.test('file.ts.bak'), false);

  const arrayResult = makeIdFiltersToMatchWithQuery(['**/*.vue', /\.svelte$/]);
  assert.equal(arrayResult[0], '**/*.vue{?*,}');
  assert.ok(arrayResult[1] instanceof RegExp);
}

// 4. and, or, not create composable logical filter expressions
{
  const andExpr = and(id(/\.ts$/), moduleType('ts'));
  assert.equal(andExpr.kind, 'and');
  assert.equal(andExpr.args.length, 2);

  const orExpr = or(id(/\.jsx?$/), id(/\.tsx?$/));
  assert.equal(orExpr.kind, 'or');
  assert.equal(orExpr.args.length, 2);

  const notExpr = not(importerId(/node_modules/));
  assert.equal(notExpr.kind, 'not');
  assert.equal(notExpr.expr.kind, 'importerId');

  assert.throws(() => and(), /`And` expects at least one operand/);
  assert.throws(() => or(), /`Or` expects at least one operand/);
}

// 5. query and queries construct query parameter filter expressions
{
  const q1 = query('vue', true);
  assert.equal(q1.kind, 'query');
  assert.equal(q1.key, 'vue');
  assert.equal(q1.pattern, true);

  const q2 = query('type', 'template');
  assert.equal(q2.kind, 'query');
  assert.equal(q2.key, 'type');
  assert.equal(q2.pattern, 'template');

  const composed = queries({ raw: true, lang: 'css' });
  assert.equal(composed.kind, 'and');
  assert.equal(composed.args.length, 2);
}

// 6. interpreter evaluates include and exclude expressions sequentially against module code, id, moduleType, and importerId
{
  const filter = [
    exclude(importerId(/node_modules/)),
    include(and(id(/\.ts$/), moduleType('ts'))),
  ];

  assert.equal(
    interpreter(filter, 'export const x = 1;', 'src/app.ts', 'ts', 'src/main.ts'),
    true
  );

  assert.equal(
    interpreter(filter, 'export const x = 1;', 'src/app.ts', 'ts', 'node_modules/dep/index.js'),
    false
  );

  assert.equal(
    interpreter(filter, 'export const x = 1;', 'src/app.ts', 'js', 'src/main.ts'),
    false
  );
}

// 7. interpreter correctly handles cleanUrl and query parameter checks
{
  const filter = [
    include(
      and(
        id('src/component.vue', { cleanUrl: true }),
        code(/<template>/),
        query('type', 'template')
      )
    ),
  ];

  assert.equal(
    interpreter(filter, '<template><div></div></template>', 'src/component.vue?type=template&lang=html'),
    true
  );

  assert.equal(
    interpreter(filter, '<template><div></div></template>', 'src/component.vue?type=style'),
    false
  );

  assert.equal(
    interpreter(filter, '<script>export default {}</script>', 'src/component.vue?type=template'),
    false
  );
}

// 8. filterVitePlugins removes dev server plugins while preserving build plugins and flattening nested arrays
{
  const plugins = [
    { name: 'build-plugin', apply: 'build' },
    { name: 'serve-plugin', apply: 'serve' },
    { name: 'common-plugin' },
    [
      { name: 'nested-serve', apply: 'serve' },
      { name: 'nested-fn', apply: (config, env) => env.command === 'build' },
    ],
    null,
    false,
  ];

  const filtered = filterVitePlugins(plugins);
  assert.deepEqual(
    filtered.map((p) => p.name),
    ['build-plugin', 'common-plugin', 'nested-fn']
  );
}

Исходный сидер

аноним