@conformetry/core

中文文档
0.0.76发布于 2026/11/10MITTypeScriptES Module构建来源已验证近 30 天下载 1.4万

Core types and structured contracts for the Conformetry code generation and conformance toolchain

原始使用文档
文档目录8 节
  1. What it owns
  2. Writing a language validator
  3. Weight and score
  4. Structured differences
  5. Exports
  6. Test
  7. License
  8. 👔 Conformetry

👔 Conformetry Core

npm

The shared contract every other Conformetry package builds on. It is the contracts leaf of the five-layer spine — core <- configuration <- analysis <- output <- cli — so it declares types and holds nothing executable: no service, no NestJS module, no dependency on anything else in the conformetry graph. Importing a result type from here therefore drags nothing behind it.

npm install --save-dev @conformetry/core

What it owns

FileResponsibility
lib/differences.types.tsThe structured ConformetryDifference shape, and the language and category unions that discriminate it
lib/inventory.types.tsWhat discovery found, as the output layer renders it: templates, instances, and the pairings between them
lib/runner.types.tsThe ConformetryLanguageValidator contract and the document, payload, and result shapes it is spoken in
lib/scoring.types.tsInstanceScore: how well one matched instance honours the template it matched

The behavior these types describe lives above them. The difference and scoring primitives, the file-existence pass, and every per-format validator are in @conformetry/languages; the validator envelope is in @conformetry/validation; rendering is in @conformetry/output.

"Language" here means a validator for one file format — TypeScript, JSON, markdown, Python. The word "plugin" is reserved for the Nx plugin in @conformetry/nx, and is deliberately not used for these.

Writing a language validator

A validator supplies a descriptor and a single-document comparison. Extension filtering, grouping differences under their file, and assembling the result are handled once by RunnerService in @conformetry/validation, so a language package contains only its comparison logic:

@Injectable()
export class ExampleValidatorService implements ConformetryLanguageValidator {
  public readonly descriptor = EXAMPLE_VALIDATOR_DESCRIPTOR;

  public validateDocument(
    document: PreparedValidationDocument,
  ): DocumentValidationResult {
    // compare document.renderedTemplate against document.instance
    return { differences, totalWeight };
  }
}

Weight and score

A validator reports how much the template asked for alongside what it found. totalWeight counts every requirement the comparison weighed — conforming ones included, because leaving them out would score an instance only against the parts of itself that are already wrong.

Each difference may carry a weight, defaulting to 1. It says how many requirements that one finding stands in for: a validator reports a missing class once, however many members it held, so weighing the finding by its subtree is what keeps deleting a class from costing the same as deleting an import. No per-kind weight table is needed — a class is worth more because it contains more.

score = (totalWeight - sum(difference.weight ?? 1)) / totalWeight

ScoringService, in @conformetry/languages, owns that arithmetic, including the two cases worth getting right once: the default weight of a finding that declares none, and an empty template whose denominator is zero and which therefore conforms perfectly.

@conformetry/validation drives the registered validators; they are never responsible for discovering files or loading configuration.

Structured differences

Differences carry the location on both sides — instance and template — along with the expected value and a concrete fix. That last field is the point: reports are meant to be actionable by whoever, or whatever, has to make the file conform. Prefer populating instanceLine/templateLine (or instancePath for document formats) over folding a location into the message.

Exports

Types only: ConformetryDifference, ConformetryDifferenceLanguage, ConformetryDifferenceType, ConformetryLanguageValidator, DirectoryEntry, DocumentValidationResult, FileSystemAdapter, GeneratorDefinition, GeneratorHook, GeneratorHookContext, GeneratorHooks, InstanceScore, InventoriedInstance, InventoriedPairing, InventoriedTemplate, LanguageValidatorDescriptor, LanguageValidatorResult, PreparedValidationDocument, PreparedValidationPayload, and ValidationFileResult.

Test

nx run conformetry-core:vitest

One test, and it asserts the property that makes this package a leaf: the module contributes nothing at runtime, so importing a result type from here cannot drag a service or a NestJS module behind it. Exporting one value fails it.

License

MIT — see LICENSE.

👔 Conformetry

This project was generated from the nestjs-service-project conformetry template.

版本与发布记录

@conformetry/core 共发布 74 个版本,首次发布于 2026/10/05;过去 12 个月发布了 74 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.76latest2026/11/10今天
0.0.752026/11/10今天
0.0.742026/11/091 天前
0.0.732026/11/091 天前
0.0.722026/11/091 天前
0.0.712026/11/082 天前

关于 @conformetry/core 的常见问题

@conformetry/core 是什么?

Core types and structured contracts for the Conformetry code generation and conformance toolchain

如何安装 @conformetry/core?

在项目目录运行 npm install @conformetry/core,或使用 pnpm add / yarn add / bun add。

@conformetry/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@conformetry/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@conformetry/core 可以商用吗?

@conformetry/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@conformetry/core 的下载量有多少?

根据 npm 官方下载统计,@conformetry/core 在 2026/10/11 – 2026/11/09 这 30 天内被下载 13,550 次,日均约 452 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@conformetry/core 还在维护吗?

最新版本 0.0.76 发布于 2026/11/10(今天);至今共发布 74 个版本,其中过去 12 个月发布了 74 个;首次发布于 2026/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。