CodeSampleX

示例

@tailwindcss/node 4.3.3: compile

已验证示例 — npm @tailwindcss/node 4.3.3: compile. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: compile is a function exported by @tailwindcss/node and…

sha256:694a334e0787e1b16ede6e1d84fdb16ec0ffd13e4bb639c02808339ed914d111

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

案例

HOW
目标
verify @tailwindcss/node.compile in pkg:npm/%40tailwindcss/node@4.3.3
包
符号
  • @tailwindcss/node.compile
环境
node 22.23.2
创建时间
2026-08-20T15:22:05Z

契约

  1. compile is a function exported by @tailwindcss/node and wrapper module
  2. createCompiler returns a compiler object with build and buildSourceMap methods
  3. compiler.build(candidates) generates CSS rules for standard utility classes
  4. compiler.build(candidates) generates CSS rules for arbitrary value utilities
  5. compiler.build(candidates) generates CSS rules for variants such as hover and focus
  6. compiler.build(candidates) generates responsive variant media queries
  7. compiler.build(candidates) generates CSS rules for custom utilities defined in input stylesheet
  8. compiler.build(candidates) ignores unrecognized or invalid utility classes
  9. compiler.buildSourceMap() returns a decoded source map with mappings
  10. compileAndBuild helper compiles and builds CSS candidates directly
  11. compile tracks imported stylesheets and dependencies via onDependency callback

文件

  • 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 @tailwindcss/node.compile in pkg:npm/%40tailwindcss/node@4.3.3
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40tailwindcss/node@4.3.3
Demonstrate these symbols/APIs:
  - @tailwindcss/node.compile
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:36c164be08bab84e75743a4c354cba09c0ed45f26c9b04c786db0743d60ba4b2","constraints":{"executionContext":"node"},"contract":["compile is a function exported by @tailwindcss/node and wrapper module","createCompiler returns a compiler object with build and buildSourceMap methods","compiler.build(candidates) generates CSS rules for standard utility classes","compiler.build(candidates) generates CSS rules for arbitrary value utilities","compiler.build(candidates) generates CSS rules for variants such as hover and focus","compiler.build(candidates) generates responsive variant media queries","compiler.build(candidates) generates CSS rules for custom utilities defined in input stylesheet","compiler.build(candidates) ignores unrecognized or invalid utility classes","compiler.buildSourceMap() returns a decoded source map with mappings","compileAndBuild helper compiles and builds CSS candidates directly","compile tracks imported stylesheets and dependencies via onDependency callback"],"goal":"verify @tailwindcss/node.compile in pkg:npm/%40tailwindcss/node@4.3.3","kind":"HOW","packages":["pkg:npm/%40tailwindcss/node@4.3.3"],"schemaVersion":1,"symbols":["@tailwindcss/node.compile"]},"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/%40tailwindcss/node@4.3.3"],"schemaVersion":1,"subject":"pkg:npm/%40tailwindcss/node@4.3.3","symbols":["@tailwindcss/node.compile"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-tailwindcss-node-compile",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-tailwindcss-node-compile",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@tailwindcss/node": "4.3.3"
      }
    },
    "node_modules/@jridgewell/gen-mapping": {
      "version": "0.3.13",
      "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
      "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.0",
        "@jridgewell/trace-mapping": "^0.3.24"
      }
    },
    "node_modules/@jridgewell/remapping": {
      "version": "2.3.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz",
      "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/gen-mapping": "^0.3.5",
        "@jridgewell/trace-mapping": "^0.3.24"
      }
    },
    "node_modules/@jridgewell/resolve-uri": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
      "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "node_modules/@jridgewell/trace-mapping": {
      "version": "0.3.31",
      "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
      "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/resolve-uri": "^3.1.0",
        "@jridgewell/sourcemap-codec": "^1.4.14"
      }
    },
    "node_modules/@tailwindcss/node": {
      "version": "4.3.3",
      "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.3.3.tgz",
      "integrity": "sha512-/T8IKEsf9VTU6tLjgC7+sv2mOPtQxzE2jMw7u4Tt40Tx+QSZxpzh95/H6cMKoja9XuW7iMdLJYBB0o9G1CaAgg==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/remapping": "^2.3.5",
        "enhanced-resolve": "^5.24.1",
        "jiti": "^2.7.0",
        "lightningcss": "1.32.0",
        "magic-string": "^0.30.21",
        "source-map-js": "^1.2.1",
        "tailwindcss": "4.3.3"
      }
    },
    "node_modules/detect-libc": {
      "version": "2.1.2",
      "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
      "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
      "license": "Apache-2.0",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/enhanced-resolve": {
      "version": "5.24.5",
      "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.24.5.tgz",
      "integrity": "sha512-L1l8TNvomm6UVW5B253AGxQagSQr+vGwhMlrrfRS2qmhx46AMpMVJKQYLvWYbysTMY8VoicOvzHzoHMbyzB+4A==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.4",
        "tapable": "^2.3.3"
      },
      "engines": {
        "node": ">=10.13.0"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/jiti": {
      "version": "2.7.0",
      "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz",
      "integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==",
      "license": "MIT",
      "bin": {
        "jiti": "lib/jiti-cli.mjs"
      }
    },
    "node_modules/lightningcss": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz",
      "integrity": "sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==",
      "license": "MPL-2.0",
      "dependencies": {
        "detect-libc": "^2.0.3"
      },
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      },
      "optionalDependencies": {
        "lightningcss-android-arm64": "1.32.0",
        "lightningcss-darwin-arm64": "1.32.0",
        "lightningcss-darwin-x64": "1.32.0",
        "lightningcss-freebsd-x64": "1.32.0",
        "lightningcss-linux-arm-gnueabihf": "1.32.0",
        "lightningcss-linux-arm64-gnu": "1.32.0",
        "lightningcss-linux-arm64-musl": "1.32.0",
        "lightningcss-linux-x64-gnu": "1.32.0",
        "lightningcss-linux-x64-musl": "1.32.0",
        "lightningcss-win32-arm64-msvc": "1.32.0",
        "lightningcss-win32-x64-msvc": "1.32.0"
      }
    },
    "node_modules/lightningcss-android-arm64": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.32.0.tgz",
      "integrity": "sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==",
      "cpu": [
        "arm64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "android"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-darwin-arm64": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.32.0.tgz",
      "integrity": "sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==",
      "cpu": [
        "arm64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "darwin"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-darwin-x64": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.32.0.tgz",
      "integrity": "sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==",
      "cpu": [
        "x64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "darwin"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-freebsd-x64": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.32.0.tgz",
      "integrity": "sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==",
      "cpu": [
        "x64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "freebsd"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-linux-arm-gnueabihf": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.32.0.tgz",
      "integrity": "sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==",
      "cpu": [
        "arm"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-linux-arm64-gnu": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.32.0.tgz",
      "integrity": "sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==",
      "cpu": [
        "arm64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-linux-arm64-musl": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.32.0.tgz",
      "integrity": "sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==",
      "cpu": [
        "arm64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-linux-x64-gnu": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.32.0.tgz",
      "integrity": "sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==",
      "cpu": [
        "x64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-linux-x64-musl": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.32.0.tgz",
      "integrity": "sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==",
      "cpu": [
        "x64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "linux"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-win32-arm64-msvc": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.32.0.tgz",
      "integrity": "sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==",
      "cpu": [
        "arm64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "win32"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/lightningcss-win32-x64-msvc": {
      "version": "1.32.0",
      "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.32.0.tgz",
      "integrity": "sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==",
      "cpu": [
        "x64"
      ],
      "license": "MPL-2.0",
      "optional": true,
      "os": [
        "win32"
      ],
      "engines": {
        "node": ">= 12.0.0"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/parcel"
      }
    },
    "node_modules/magic-string": {
      "version": "0.30.21",
      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
      "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.5"
      }
    },
    "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"
      }
    },
    "node_modules/tailwindcss": {
      "version": "4.3.3",
      "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.3.3.tgz",
      "integrity": "sha512-gOhV3P7ufE62QDGg1zVaTgCR+EtPv92k2nIhVcVKcLmxT1sUBsQGhnZj175j+MqRt4zLF7ic+sCYjfhxMxj7YQ==",
      "license": "MIT"
    },
    "node_modules/tapable": {
      "version": "2.3.3",
      "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.3.tgz",
      "integrity": "sha512-uxc/zpqFg6x7C8vOE7lh6Lbda8eEL9zmVm/PLeTPBRhh1xCgdWaQ+J1CUieGpIfm2HdtsUpRv+HshiasBMcc6A==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      },
      "funding": {
        "type": "opencollective",
        "url": "https://opencollective.com/webpack"
      }
    }
  }
}
package.json
{
  "name": "sample-tailwindcss-node-compile",
  "version": "1.0.0",
  "license": "MIT-0",
  "main": "src/index.js",
  "dependencies": {
    "@tailwindcss/node": "4.3.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @tailwindcss/node.compile in pkg:npm/%40tailwindcss/node@4.3.3",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40tailwindcss/node@4.3.3"
  ],
  "symbols": [
    "@tailwindcss/node.compile"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const { compile } = require('@tailwindcss/node');

/**
 * Compiles a Tailwind CSS stylesheet and returns the compiler instance.
 * @param {string} css - Input CSS stylesheet containing Tailwind directives or custom utilities.
 * @param {object} [options={}] - Compilation options including base directory and dependency tracker.
 * @returns {Promise<object>} Compiler instance providing build and buildSourceMap methods.
 */
async function createCompiler(css, options = {}) {
  const opts = {
    base: options.base || process.cwd(),
    onDependency: options.onDependency || (() => {}),
    ...options
  };
  return compile(css, opts);
}

/**
 * Compiles CSS and immediately generates CSS rules for the provided utility candidates.
 * @param {string} css - Input CSS stylesheet.
 * @param {string[]} candidates - List of Tailwind utility candidate class names.
 * @param {object} [options={}] - Compilation options.
 * @returns {Promise<string>} Generated CSS string.
 */
async function compileAndBuild(css, candidates, options = {}) {
  const compiler = await createCompiler(css, options);
  return compiler.build(candidates);
}

module.exports = {
  compile,
  createCompiler,
  compileAndBuild
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const { compile, createCompiler, compileAndBuild } = require('../src/index.js');
const tailwindNode = require('@tailwindcss/node');

// 1. compile is a function exported by @tailwindcss/node and wrapper module
assert.equal(typeof compile, 'function', 'compile must be a function');
assert.strictEqual(compile, tailwindNode.compile, 'compile must match @tailwindcss/node.compile');

// 2. createCompiler returns a compiler object with build and buildSourceMap methods
const dependencies = [];
const customCss = `
@import "tailwindcss";
@utility custom-pill {
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}
`;

const compiler = await createCompiler(customCss, {
  base: import.meta.dirname,
  onDependency: (dep) => {
    dependencies.push(dep);
  }
});

assert.equal(typeof compiler.build, 'function', 'compiler.build must be a function');
assert.equal(typeof compiler.buildSourceMap, 'function', 'compiler.buildSourceMap must be a function');
assert.ok(Array.isArray(compiler.sources), 'compiler.sources must be an array');

// 3. compiler.build(candidates) generates CSS rules for standard utility classes
const standardCss = compiler.build(['flex', 'items-center', 'justify-between', 'text-center']);
assert.ok(standardCss.includes('.flex'), 'must include .flex class rule');
assert.ok(standardCss.includes('display: flex'), 'must contain display: flex declaration');
assert.ok(standardCss.includes('.items-center'), 'must include .items-center class rule');
assert.ok(standardCss.includes('align-items: center'), 'must contain align-items: center declaration');
assert.ok(standardCss.includes('.justify-between'), 'must include .justify-between class rule');
assert.ok(standardCss.includes('.text-center'), 'must include .text-center class rule');

// 4. compiler.build(candidates) generates CSS rules for arbitrary value utilities
const arbitraryCss = compiler.build(['m-[13px]', 'top-[42px]', 'text-[#123456]']);
assert.ok(arbitraryCss.includes('13px'), 'must include 13px arbitrary margin');
assert.ok(arbitraryCss.includes('42px'), 'must include 42px arbitrary top position');
assert.ok(arbitraryCss.includes('#123456'), 'must include #123456 arbitrary color');

// 5. compiler.build(candidates) generates CSS rules for variants such as hover and focus
const variantCss = compiler.build(['hover:underline', 'focus:ring-2']);
assert.ok(variantCss.includes(':hover'), 'must generate :hover pseudo-class variant');
assert.ok(variantCss.includes(':focus'), 'must generate :focus pseudo-class variant');
assert.ok(variantCss.includes('text-decoration-line: underline'), 'must generate underline on hover');

// 6. compiler.build(candidates) generates responsive variant media queries
const responsiveCss = compiler.build(['md:flex', 'lg:hidden']);
assert.ok(responsiveCss.includes('@media (width >= 48rem)'), 'must generate @media rule for md variant');
assert.ok(responsiveCss.includes('@media (width >= 64rem)'), 'must generate @media rule for lg variant');

// 7. compiler.build(candidates) generates CSS rules for custom utilities defined in input stylesheet
const customUtilityCss = compiler.build(['custom-pill']);
assert.ok(customUtilityCss.includes('.custom-pill'), 'must generate rule for custom-pill');
assert.ok(customUtilityCss.includes('padding: 0.25rem 0.75rem'), 'must contain custom padding');
assert.ok(customUtilityCss.includes('border-radius: 9999px'), 'must contain custom border radius');

// 8. compiler.build(candidates) ignores unrecognized or invalid utility classes
const invalidCss = compiler.build(['non-existent-class-12345', 'invalid!!!class']);
assert.ok(!invalidCss.includes('non-existent-class-12345'), 'must not include invalid classes');
assert.ok(!invalidCss.includes('invalid!!!class'), 'must not include invalid classes');

// 9. compiler.buildSourceMap() returns a decoded source map with mappings
const sourceMap = compiler.buildSourceMap();
assert.ok(sourceMap !== null && typeof sourceMap === 'object', 'source map must be an object');
assert.ok(Array.isArray(sourceMap.mappings), 'source map must contain mappings array');

// 10. compileAndBuild helper compiles and builds CSS candidates directly
const directCss = await compileAndBuild('@import "tailwindcss";', ['grid', 'grid-cols-2'], {
  base: import.meta.dirname
});
assert.ok(directCss.includes('.grid'), 'must include .grid class rule');
assert.ok(directCss.includes('grid-template-columns: repeat(2, minmax(0, 1fr))'), 'must include grid-template-columns declaration');

// 11. compile tracks imported stylesheets and dependencies via onDependency callback
assert.ok(dependencies.length > 0, 'onDependency must have been called with dependency paths');

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

原始种子者

匿名