@moontern-labs/code-budget

中文文档
0.1.3发布于 2026/11/02MITTypeScriptES Module

为源存储库强制执行显式的维护规模预算

中文使用文档
文档目录6 节
  1. 配置
  2. 工具违约
  3. 将现有配置移动到工具中
  4. 命令
  5. 命名的天花板
  6. 库API

@moontern-labs / code-budget

具有无限工具和验证的显式实现loc上限。

npm install --save-dev @moontern-labs/[email protected]
npx code-budget                 # infer and explain when unconfigured
npx code-budget init --scope simple-tool
npx code-budget                 # enforce the committed configuration

对于补丁版本, npm run bump 增量 x.x.N 来 x.x.(N + 1) 和 更新lockfile和版本化的源代码/文档引用。使用 npm run bump -- --dry-run.

实现度量产品代码。工具测量开发、构建、 分别释放、线头和操作支持,没有上限。测试中, 仅测试的帮助程序和fixture也被测量,但不受限制。文档、锁文件、许可证和包元数据 单独报告。将源文件移动到不匹配的目录或重叠目录中 区域配置检查失败。

配置

import { defineConfig } from "@moontern-labs/code-budget";

export default defineConfig({
  scope: "platform",
  areas: [
    {
      name: "runtime",
      kind: "implementation",
      include: ["src/**", "bin/**"],
      exclude: ["**/*.test.*", "**/__tests__/**"],
    },
    {
      name: "tooling",
      kind: "tooling",
      include: ["scripts/**"],
      exclude: ["scripts/test/**", "**/*.test.*"],
    },
    {
      name: "tests",
      kind: "verification",
      include: ["test/**", "tests/**", "**/*.test.*", "**/__tests__/**"],
      exclude: ["**/fixtures/**"],
    },
    {
      name: "fixtures",
      kind: "verification",
      include: ["**/fixtures/**"],
    },
    {
      name: "generated-engine",
      kind: "excluded",
      include: ["engine/generated/**"],
      reason: "Reproduced from the checksum-pinned upstream source archive.",
    },
  ],
});

工具违约

推理和 init 使用相同的分类:

路径分类
一切都在 .github/**,包括测试和模板tooling
根 scripts/**, tools/**, tooling/**tooling,除了认可的测试和装置
根 .husky/**tooling,除了认可的测试和装置
src/**, lib/**, app/**, packages/**, bin/**implementation,但认可的工具、测试和夹具除外
目录命名 test, tests, spec, specs,或者 __tests__;文件匹配 *.test.* 或者 *.spec.*verification外, .github/**
目录命名 fixture, fixtures,或者 __fixtures__verification外, .github/**

工具配置模式匹配任何深度。支持 NAME.config.EXT 文件使用这些名称: code-budget, vite, vitest, webpack, rollup, esbuild, tsup, babel, eslint, prettier, jest, playwright, cypress, next, nuxt, svelte, astro, postcss, tailwind. 支持扩展 是 js, cjs, mjs, ts, cts, mts, json.

其他工具模式包括 tsconfig*.json; .eslintrc, .prettierrc, .babelrc,可伸缩或可伸缩 js, cjs, mjs, json, yaml,或者 yml; Makefile, GNUmakefile, Justfile, justfile, Rakefile, Dockerfile, 和 Dockerfile.*;的YAML文件 compose, compose.*, docker-compose,或者 docker-compose.*. 认可的测试和装置 优先于外部的这些模式 .github/**.

这些默认值不能确定脚本的目的。添加明确的区域 其他工具配置、部署清单或工具目录。未知的 类源路径仍然无法通过配置检查。特定于应用程序的名称,例如 作为 src/customer.config.ts 坚持执行。

将现有配置移动到工具中

升级不会重写已提交的配置,也不会从文件中推断出一种类型 地区的名称。更改现有的加工区域 kind 从 implementation 来 tooling. 给 .github/** 它自己的工具区域,并排除 .github/** 从 任何其他匹配区域。使用 code-budget init --scope <scope> --dry-run 来 检查完整的默认值,而不替换您的策略。

对于工具目录下的产品逻辑,添加一个实现区域,例如 include: ["scripts/import-customers/**"]. 将相同的模式添加到工具中 地区的 exclude 列表。为任何测试和测试保留单独的验证规则 产品目录中的固定装置。重叠区域仍然无法通过检查。

报告包括: TOOLING (UNLIMITED) 和JSON totals.tooling,包括档案; LOC和语言计数。工具有助于组合语言报告, 但不是实现上限或验证与实现的比率。 JSON信封仍然是版本 1.0 具有增材工装总数和种类。 详尽处理区域种类的消费者必须接受 tooling.

独立配置名称为 code-budget.config.mjs, .js, .cjs. 这个 0.0.1 budgets 模式保持可读并发出迁移诊断; 它的 maxFiles 和 maxBytes 限制是遗留的。

命令

  • code-budget:无需配置的推断非失败分析; check 用它。
  • code-budget report:报告配置的或推断的度量,为退出0 过剩的政策。
  • code-budget check:要求配置;出口1表示违规,出口2表示错误。
  • code-budget init --scope <scope>:创建config并立即检查; 支持 --dry-run 和 --force.
  • code-budget scopes [--details]:显示每个天花板和捆绑基准。
  • code-budget explain <path>:显示匹配模式和执行效果。

所有命令接受 --cwd, --config, --json, --details, --no-color, --version,以及上下文 --help. JSON只将一个版本化的信封写入 标准输出,包括使用和配置错误。

命名的天花板

范围实现代码行
atomic-library1000年
simple-tool10,000
standalone-tool40000年
platform75000年
infrastructure175000年
suite350000年

看到 METHODOLOGY.md,或者逃跑 code-budget scopes --details, 对于绑定的固定参考基准数据集和计数边界。

库API

包导出 analyzeRepository, checkBudgets, defineConfig,配置 加载和分类帮助器、呈现帮助器以及 SCOPES / SCOPE_NAMES 用TypeScript声明元数据。

版本与发布记录

@moontern-labs/code-budget 共发布 2 个版本,首次发布于 2026/11/02;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.3latest2026/11/021 天前
0.0.0-stage2026/11/021 天前

关于 @moontern-labs/code-budget 的常见问题

@moontern-labs/code-budget 是什么?

为源存储库强制执行显式的维护规模预算

如何安装 @moontern-labs/code-budget?

在项目目录运行 npm install @moontern-labs/code-budget,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 code-budget,可以用 npx code-budget 直接运行。

@moontern-labs/code-budget 支持 TypeScript 吗?

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

@moontern-labs/code-budget 支持 ESM 还是 CommonJS?

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

@moontern-labs/code-budget 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@moontern-labs/code-budget 可以商用吗?

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

@moontern-labs/code-budget 还在维护吗?

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