CodeSampleX

Пример

postcss 8.5.26: decl

Проверенный пример — npm postcss 8.5.26: decl. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: postcss.decl creates Declaration nodes…

sha256:962adfc7e54a9e9cbff026593cb452921120eae57d9ddb3787f1b93ddb78df5a

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Кейс

HOW
Цель
verify postcss.decl in pkg:npm/postcss@8.5.26
Пакеты
Символы
  • postcss.decl
Создан
2026-08-27T02:09:44Z

Контракт

  1. postcss.decl creates Declaration nodes with specified prop and value
  2. postcss.decl creates Declaration nodes with important flag set to true
  3. postcss.decl creates Declaration nodes with custom raws formatting
  4. postcss.decl nodes support updating prop and value properties dynamically
  5. postcss.decl nodes support cloning with property overrides
  6. postcss.decl nodes can be appended to PostCSS Rule containers and serialized

Файлы

  • 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 postcss.decl in pkg:npm/postcss@8.5.26
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/postcss@8.5.26
Demonstrate these symbols/APIs:
  - postcss.decl

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:107b2f9b4b55ac3ba10b11455daa7f29e50722d24a8f86b7596453f608d2b04c","contract":["postcss.decl creates Declaration nodes with specified prop and value","postcss.decl creates Declaration nodes with important flag set to true","postcss.decl creates Declaration nodes with custom raws formatting","postcss.decl nodes support updating prop and value properties dynamically","postcss.decl nodes support cloning with property overrides","postcss.decl nodes can be appended to PostCSS Rule containers and serialized"],"goal":"verify postcss.decl in pkg:npm/postcss@8.5.26","kind":"HOW","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"symbols":["postcss.decl"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/postcss@8.5.26"],"schemaVersion":1,"subject":"pkg:npm/postcss@8.5.26","symbols":["postcss.decl"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-postcss-decl",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-postcss-decl",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "postcss": "8.5.26"
      }
    },
    "node_modules/nanoid": {
      "version": "3.3.18",
      "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.18.tgz",
      "integrity": "sha512-DTg4MJbGMWkfi6VZFdNt2/caMbQy4Ou+Op/hJQvGEWcnVfoA1QA+xzRKAzw9jD6+GVOOeYr/mIcuDSdug6F6+w==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "bin": {
        "nanoid": "bin/nanoid.cjs"
      },
      "engines": {
        "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
      }
    },
    "node_modules/picocolors": {
      "version": "1.1.1",
      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
      "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
      "license": "ISC"
    },
    "node_modules/postcss": {
      "version": "8.5.26",
      "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
      "integrity": "sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==",
      "funding": [
        {
          "type": "opencollective",
          "url": "https://opencollective.com/postcss/"
        },
        {
          "type": "tidelift",
          "url": "https://tidelift.com/funding/github/npm/postcss"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/ai"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "nanoid": "^3.3.17",
        "picocolors": "^1.1.1",
        "source-map-js": "^1.2.1"
      },
      "engines": {
        "node": "^10 || ^12 || >=14"
      }
    },
    "node_modules/source-map-js": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
      "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
      "license": "BSD-3-Clause",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-postcss-decl",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of postcss.decl in postcss",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "postcss": "8.5.26"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify postcss.decl in pkg:npm/postcss@8.5.26",
  "kind": "HOW",
  "packages": [
    "pkg:npm/postcss@8.5.26"
  ],
  "symbols": [
    "postcss.decl"
  ]
}
src/index.js
const postcss = require('postcss');

function createDecl(defaults) {
  return postcss.decl(defaults);
}

function createImportantDecl(prop, value) {
  return postcss.decl({ prop, value, important: true });
}

function formatDecl(prop, value, options = {}) {
  const defaults = { prop, value, ...options };
  return postcss.decl(defaults);
}

function cloneDecl(decl, overrides) {
  return decl.clone(overrides);
}

function buildRuleWithDecls(selector, declarations) {
  const rule = postcss.rule({ selector });
  for (const item of declarations) {
    const decl = typeof item === 'object' && item.type === 'decl' ? item : postcss.decl(item);
    rule.append(decl);
  }
  return rule;
}

module.exports = {
  postcss,
  createDecl,
  createImportantDecl,
  formatDecl,
  cloneDecl,
  buildRuleWithDecls
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  postcss,
  createDecl,
  createImportantDecl,
  formatDecl,
  cloneDecl,
  buildRuleWithDecls
} = require('../src/index.js');

// 1. postcss.decl creates Declaration nodes with specified prop and value
const decl1 = createDecl({ prop: 'color', value: 'red' });
assert(decl1, 'decl1 should exist');
assert.strictEqual(decl1.type, 'decl', 'declaration type must be "decl"');
assert.strictEqual(decl1.prop, 'color', 'declaration prop must match input');
assert.strictEqual(decl1.value, 'red', 'declaration value must match input');
assert.strictEqual(decl1.toString(), 'color: red', 'stringified declaration must match CSS format');

// 2. postcss.decl creates Declaration nodes with important flag set to true
const decl2 = createImportantDecl('font-size', '16px');
assert.strictEqual(decl2.type, 'decl', 'declaration type must be "decl"');
assert.strictEqual(decl2.prop, 'font-size', 'prop must be "font-size"');
assert.strictEqual(decl2.value, '16px', 'value must be "16px"');
assert.strictEqual(decl2.important, true, 'important flag must be true');
assert.strictEqual(decl2.toString(), 'font-size: 16px !important', 'stringified output must include !important');

// 3. postcss.decl creates Declaration nodes with custom raws formatting
const decl3 = formatDecl('margin', '0 auto', {
  raws: {
    between: ':  '
  }
});
assert.strictEqual(decl3.prop, 'margin', 'prop must match');
assert.strictEqual(decl3.value, '0 auto', 'value must match');
assert.strictEqual(decl3.raws.between, ':  ', 'raws.between must match');
assert.strictEqual(decl3.toString(), 'margin:  0 auto', 'stringified output must reflect raws between separator');

// 4. postcss.decl nodes support updating prop and value properties dynamically
const decl4 = createDecl({ prop: 'background', value: '#fff' });
decl4.prop = 'background-color';
decl4.value = '#000';
assert.strictEqual(decl4.prop, 'background-color', 'updated prop must reflect new value');
assert.strictEqual(decl4.value, '#000', 'updated value must reflect new value');
assert.strictEqual(decl4.toString(), 'background-color: #000', 'stringified output must reflect updated fields');

// 5. postcss.decl nodes support cloning with property overrides
const baseDecl = createDecl({ prop: 'opacity', value: '1' });
const cloned = cloneDecl(baseDecl, { value: '0.5' });
assert.strictEqual(baseDecl.value, '1', 'original declaration must remain unchanged');
assert.strictEqual(cloned.prop, 'opacity', 'cloned declaration must preserve prop');
assert.strictEqual(cloned.value, '0.5', 'cloned declaration must have overridden value');
assert.strictEqual(cloned.type, 'decl', 'cloned declaration type must be "decl"');

// 6. postcss.decl nodes can be appended to PostCSS Rule containers and serialized
const rule = buildRuleWithDecls('.card', [
  { prop: 'display', value: 'flex' },
  { prop: 'padding', value: '16px' }
]);
assert.strictEqual(rule.nodes.length, 2, 'rule must contain 2 declaration child nodes');
assert.strictEqual(rule.nodes[0].type, 'decl', 'first child must be a declaration');
assert.strictEqual(rule.nodes[0].prop, 'display', 'first child prop must match');
assert.strictEqual(rule.nodes[1].type, 'decl', 'second child must be a declaration');
assert.strictEqual(rule.nodes[1].prop, 'padding', 'second child prop must match');
assert.strictEqual(rule.nodes[0].parent, rule, 'declaration parent must reference the rule');
assert.strictEqual(rule.toString(), '.card {\n    display: flex;\n    padding: 16px\n}', 'rule stringification should include all declarations');

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

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

аноним