# @boundaries/config 中文文档

规范地址：https://npmcn.com/package/%40boundaries/config/

版本：1\.0\.1
npm 元数据更新时间：2026-11-05T11:48:47.630Z
中文译文更新时间：2026-11-08T12:34:49.814Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40boundaries/config
原文对照：https://npmcn.com/package/%40boundaries/config/?lang=original
项目主页：https://github.com/javierbrea/eslint-plugin-boundaries/tree/master/packages/config#readme
源码仓库：https://github.com/javierbrea/eslint-plugin-boundaries

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.4 MB，15 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.18
- 运行依赖：2 个
- 首次发布：2026-11-02T08:05:59.070Z
- 最新版本发布：2026-11-05T11:48:47.442Z
- 近 30 天下载量：94639（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 3 个）

## 中文简介

@ 边界工具的设置和规则选项的规范化和验证

## 安装

```sh
npm install @boundaries/config
```

也可以使用：`pnpm add @boundaries/config`、`yarn add @boundaries/config`、`bun add @boundaries/config`

## README

[![License](https://img.shields.io/npm/l/eslint-plugin-boundaries.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/blob/master/LICENSE) [![Build status](https://github.com/javierbrea/eslint-plugin-boundaries/actions/workflows/build.yml/badge.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/actions?query=workflow%3Abuild+branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/javierbrea/eslint-plugin-boundaries/badge.svg)](https://coveralls.io/github/javierbrea/eslint-plugin-boundaries) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=javierbrea_eslint-plugin-boundaries_config&metric=alert_status)](https://sonarcloud.io/dashboard?id=javierbrea_eslint-plugin-boundaries_config) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fjavierbrea%2Feslint-plugin-boundaries%2Fmaster%3Fmodule%3Dconfig)](https://dashboard.stryker-mutator.io/reports/github.com/javierbrea/eslint-plugin-boundaries/master?module=config)

[![NPM downloads](https://img.shields.io/npm/dm/@boundaries/config.svg)](https://www.npmjs.com/package/@boundaries/config) [![Last commit](https://img.shields.io/github/last-commit/javierbrea/eslint-plugin-boundaries.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/commits) [![Last release](https://img.shields.io/github/release-date/javierbrea/eslint-plugin-boundaries.svg)](https://github.com/javierbrea/eslint-plugin-boundaries/releases)

# @ 边界/ 配置

> 设置和规则选项的规范化和验证 `@boundaries/eslint-plugin`没有ESLint.

## 目录

-   [导言](https://npmcn.com/package/%40boundaries/config/#readme-introduction)
-   [特征](https://npmcn.com/package/%40boundaries/config/#readme-features)
-   [安装](https://npmcn.com/package/%40boundaries/config/#readme-installation)
    -   [浏览器支持](https://npmcn.com/package/%40boundaries/config/#readme-browser-support)
-   [快速启动](https://npmcn.com/package/%40boundaries/config/#readme-quick-start)
-   [核心概念](https://npmcn.com/package/%40boundaries/config/#readme-core-concepts)
    -   [诊断](https://npmcn.com/package/%40boundaries/config/#readme-diagnostics)
    -   [诊断路径](https://npmcn.com/package/%40boundaries/config/#readme-diagnostic-paths)
    -   [正常化值](https://npmcn.com/package/%40boundaries/config/#readme-normalized-values)
-   [使用量](https://npmcn.com/package/%40boundaries/config/#readme-usage)
    -   [规范配置](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-a-config)
    -   [规范设置](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-settings)
    -   [验证规则选项](https://npmcn.com/package/%40boundaries/config/#readme-validating-rule-options)
    -   [规范依赖规则选项](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-the-dependencies-rule-options)
    -   [获取规则选项的外观](https://npmcn.com/package/%40boundaries/config/#readme-getting-the-schema-of-the-rule-options)
-   [API 参考](https://npmcn.com/package/%40boundaries/config/#readme-api-reference)
    -   [职能](https://npmcn.com/package/%40boundaries/config/#readme-functions)
    -   [类型警卫](https://npmcn.com/package/%40boundaries/config/#readme-type-guards)
    -   [Docs 链接](https://npmcn.com/package/%40boundaries/config/#readme-docs-links)
    -   [常数](https://npmcn.com/package/%40boundaries/config/#readme-constants)
-   [类型参考](https://npmcn.com/package/%40boundaries/config/#readme-type-reference)
    -   [结果类型](https://npmcn.com/package/%40boundaries/config/#readme-result-types)
    -   [普通类型](https://npmcn.com/package/%40boundaries/config/#readme-normalized-types)
    -   [设置和规则选项类型](https://npmcn.com/package/%40boundaries/config/#readme-settings-and-rule-options-types)
-   [捐款](https://npmcn.com/package/%40boundaries/config/#readme-contributing)
-   [许可证](https://npmcn.com/package/%40boundaries/config/#readme-license)

## 导言

`@boundaries/config` 阅读用户在 `boundaries/*` 设置和规则选项 [`@boundaries/eslint-plugin`](https://www.npmjs.com/package/@boundaries/eslint-plugin): 它应用他们的默认值,转换其遗留表单, 保留无效的条目, 并返回每个问题作为 **诊断**,与导致它的入道.

ESLint插件使用并打印出诊断作为警告. 没有ESLint的工具,如编辑器或游乐场,可以使用它来显示自己界面中相同的问题.

> \[注\] 此软件包不运行ESLint,不读取文件或打印任何东西. 它接收配置对象为值并返回已归正的值及其问题;显示问题取决于主机.

## 特征

-   **设置正常化** ——适用默认,转换遗留设置并保留无效条目
-   **规则选项验证** 由于ESLint验证了规则中的JSON计划
-   **政策检查** ——规则政策中未确认的选取者形状和被贬损的语法
-   **诊断** 有关卡的,ESLint插件打印的文本和每个受影响的条目的路径
-   **纯函数** ——每一次通话都计算结果,输入从未变异
-   **在节点.js和浏览器中运行**,不包含 ESLint

## 安装

通过 npm 安装软件包 :

```bash
npm install @boundaries/config
```

### 浏览器支持

该软件包不依赖于ESLint或Node.js,因此它也在浏览器中运行. 为浏览器所构建的 Bundlers, 如 Webpack, Vite 或 esbuild , 选择它的浏览器通过 `browser` 其状况 `exports` 字段,且该构建不需要多填充节点.js模块或像 Globals 这样的 `process`。 。 。 .

软件包从不读取环境变量或工作目录: 主机解决了工程的根路径, 并按 `rootPath` 选项.

## 快速启动

将 ESLint 配置中的边界部分正常化并获得其问题:

```ts
import { normalizeConfig } from "@boundaries/config";

const { value, diagnostics } = normalizeConfig({
  settings: {
    "boundaries/elements": [
      { type: "helper", pattern: "helpers/*" },
      { pattern: "components/*" },
    ],
  },
  rules: {
    "boundaries/dependencies": [
      2,
      {
        default: "disallow",
        policies: [
          {
            from: { element: { type: "component" } },
            allow: { to: { element: { type: "helper" } } },
          },
        ],
      },
    ],
  },
});

// value.settings.elementDescriptors: the valid element descriptors, without the second one
// value.rules.dependencies.severity: "error"
// value.rules.dependencies.options.policies: the policies with their selectors normalized
// diagnostics:
// [
//   {
//     level: "warning",
//     title: "Some element descriptors are invalid and will be ignored.",
//     detail: 'Invalid descriptors:\n[{"match":"folder","pattern":"components/*"}].\nMore info: https://www.jsboundaries.dev/docs/settings/',
//     paths: [["settings", "boundaries/elements", 1]],
//   },
// ]
```

## 核心概念

### 诊断

函数因其输入中出现问题而永远不会打印或抛出. 他们把每个问题都当作 `Diagnostic`数字 :

```ts
{
  level: "warning",
  title: "Please provide a valid value in 'boundaries/cache' setting.",
  detail: "The value should be a boolean. More info: https://www.jsboundaries.dev/docs/settings/",
  paths: [["boundaries/cache"]],
}
```

-   **`level`**:如何处理输入.
    -   `"error"`:输入被拒绝,因为ESLint拒绝失败规则计划选项.
    -   `"warning"`:输入被忽略或没有效果.
    -   `"deprecation"`:输入使用仍然有效的遗留语法.
-   **`title`** 财务报告和审定财务报表 **`detail`**:ESLint插件所打印的文本. `detail` 是可选的,它通常以链接到文件结尾.
-   **`paths`**页:1 [路径](https://npmcn.com/package/%40boundaries/config/#readme-diagnostic-paths) 每个受影响的条目.

在多个条目中发现的一个问题被一次返回,其中所有条目的路径,诊断结果以ESLint插件打印的顺序来.

### 诊断路径

一个路径是导致受影响的条目的对象密钥和数组索引的列表,从返回它的函数输入的根起. 一条空道, `[]`,表示整个输入.

| 函数 | 路径的根 | 示例 |
| --- | --- | --- |
| `normalizeConfig` | 配置对象 | `["rules", "boundaries/dependencies", 1, "default"]` |
| `normalizeSettings` | 设置对象 | `["boundaries/elements", 1]` |
| `validateRuleOptions` | 规则条目的选项对象 | `["policies", 0]` |

主机可以使用路径在自己的界面中指向条目,比如在编辑器中突出显示.

### 正常化值

`normalizeConfig` 财务报告和审定财务报表 `normalizeSettings` 返回 a [`ConfigResult`](https://npmcn.com/package/%40boundaries/config/#readme-configresult), (中文(简体) ), `{ value, diagnostics }`编辑 `value` 总是设置的,不管输入: 缺失的设置得到它们的默认值,遗留的表单被转换,无效的条目被忽略,所以即使有诊断,一个主机也可以使用.

## 使用量

### 规范配置

`normalizeConfig` 取ESLint配置对象的边界部分, `{ settings, rules }`。它使设置与 [`normalizeSettings`](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-settings),并验证插件的每个规则条目,作为ESLint验证,然后作为插件验证:

| 规则条目 | 诊断 | 单位 `value.rules` |
| --- | --- | --- |
| 没有插件前缀的密钥, 例如 `import/no-cycle` | 无 | 没有 |
| 严重性 `0`, (中文(简体) ), `1`, (中文(简体) ), `2`, (中文(简体) ), `"off"`, (中文(简体) ), `"warn"` 或者说 `"error"` | 错误 | 没有 |
| 插件的未知规则 | 错误,除非规则被取消 | 没有 |
| 规则关闭 | 无,因为ESLint没有验证 | 是的,但当它失败时, 它的选项被视作没有设定 |
| 规则方案失败的选项 | 错误, 唯一一个条目 | 没有 |
| 有效选项 | 警告和贬值 [`validateRuleOptions`](https://npmcn.com/package/%40boundaries/config/#readme-validating-rule-options) | 对 |

严重程度可以单写, `"warn"`,或作为数组的第一个项, `["warn", { ... }]`。规则以短名键入 `value.rules`选项 `dependencies` 规则,以及被掠夺者 `element-types` 规则,与 [`normalizeDependenciesRuleOptions`](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-the-dependencies-rule-options)。 。 。 .

```ts
import { normalizeConfig } from "@boundaries/config";

const { value, diagnostics } = normalizeConfig({
  rules: {
    "boundaries/dependencies": ["error", { default: "maybe" }],
    "boundaries/unknown-rule": "warn",
    "boundaries/no-private": "on",
    "import/no-cycle": 2,
  },
});

// value.rules: {}
// diagnostics:
// [
//   {
//     level: "warning",
//     title: "Please provide element descriptors using the 'boundaries/elements' setting, or file descriptors using the 'boundaries/files' setting.",
//     detail: "More info: https://www.jsboundaries.dev/docs/settings/",
//     paths: [["settings"]],
//   },
//   {
//     level: "error",
//     title: "[boundaries/dependencies] Invalid rule options.",
//     detail: 'Value "maybe" should be equal to one of the allowed values.\nMore info: https://www.jsboundaries.dev/docs/rules/dependencies/',
//     paths: [["rules", "boundaries/dependencies", 1, "default"]],
//   },
//   {
//     level: "error",
//     title: 'Key "rules": Key "boundaries/unknown-rule": Could not find "unknown-rule" in plugin "boundaries".',
//     paths: [["rules", "boundaries/unknown-rule"]],
//   },
//   {
//     level: "error",
//     title: 'Key "rules": Key "boundaries/no-private": Expected severity of "off", 0, "warn", 1, "error", or 2.',
//     paths: [["rules", "boundaries/no-private"]],
//   },
// ]
```

当插件在 ESLint 配置中以另一个名称注册时, 将其传递为 `pluginName`。只读取前缀的规则:

```ts
const { value } = normalizeConfig(
  {
    settings: { "boundaries/elements": [{ type: "app", pattern: "app/*" }] },
    rules: { "arch/no-private": 1 },
  },
  { pluginName: "arch" }
);

// value.rules: { "no-private": { severity: "warn", options: undefined } }
```

> \[注\] 设置保留 `boundaries/` 前缀,无论插件名称是什么,因为ESLint插件读取它们.

### 规范设置

`normalizeSettings` 拿着 `settings` 仅读取其 `boundaries/*` 键。 它应用每个缺失设置的默认值,转换遗留设置,例如 `boundaries/types` 或者说 `boundaries/elements-single-type`,将无效的条目删除。 这个 [设置 :](https://npmcn.com/package/%40boundaries/config/#readme-settingsnormalized) 列出每个属性及其默认值.

```ts
import { normalizeSettings } from "@boundaries/config";

const { value, diagnostics } = normalizeSettings(
  {
    "boundaries/elements": [{ type: "component", pattern: "components/*" }],
    "boundaries/ignore": "**/*.spec.js",
    "boundaries/cache": "yes",
  },
  { rootPath: "/project" }
);

// value.ignorePaths: ["**/*.spec.js"]
// value.cache: true
// value.rootPath: "/project"
// diagnostics:
// [
//   {
//     level: "warning",
//     title: "Please provide a valid value in 'boundaries/cache' setting.",
//     detail: "The value should be a boolean. More info: https://www.jsboundaries.dev/docs/settings/",
//     paths: [["boundaries/cache"]],
//   },
// ]
```

这个 `rootPath` 选项是工程的根路径,由主机解决。 ESLint 插件从 `boundaries/root-path` 设置 `ESLINT_PLUGIN_BOUNDARIES_ROOT_PATH` 环境变量和工作目录。 没有选择,正常化 `rootPath` 这是 `boundaries/root-path` 设置为正文.

> \[注\] 当 `boundaries/legacy-warnings` 设置是 `false`中,不报告遗留语法:在设置中,也不通过 `normalizeConfig`,在规则选项中.

### 验证规则选项

`validateRuleOptions` 验证单个规则条目的选项对象,紧后的项目。 正如ESLint所做的那样,它根据规则的策略来验证它,然后,对于有政策的规则,它检查其选择者的形状,当 `legacyWarnings` 实值 `true`,他们的被贬损的语法.

```ts
import { validateRuleOptions } from "@boundaries/config";

const diagnostics = validateRuleOptions(
  "boundaries/dependencies",
  {
    default: "disallow",
    policies: [{ from: "component", allow: "helper" }],
  },
  { legacyWarnings: true }
);

// [
//   {
//     level: "deprecation",
//     title: "[boundaries/dependencies] Detected legacy string element selectors in 1 policy at indices: 0.",
//     detail: 'Replace "your-type" with an entity selector, e.g. { element: { type: "your-type" } }. More info: https://www.jsboundaries.dev/docs/releases/migration-guides/v5-to-v6/#object-based-elements-selector-syntax',
//     paths: [["policies", 0]],
//   },
//   {
//     level: "deprecation",
//     title: '[boundaries/dependencies] Detected "allow"/"disallow" entries without a "from"/"to" wrapper in 1 policy at indices: 0.',
//     detail: 'Use allow: [{ to: { element: { type: "your-type" } } }] or [{ from: ... }] instead of a bare element selector. More info: https://www.jsboundaries.dev/docs/releases/migration-guides/v5-to-v6/#to-property-in-allowdisallow-rules-is-now-required',
//     paths: [["policies", 0]],
//   },
// ]
```

当选项失败规则计划时,计划错误是唯一的诊断,因为ESLint从未运行一个选项失败的规则. 已经运行了 ESLint 的宿主, 它验证了计划本身, 通过了 `schema: false` 跳过它:

```ts
validateRuleOptions("boundaries/dependencies", { default: "maybe" }, { legacyWarnings: true });
// [{ level: "error", title: "[boundaries/dependencies] Invalid rule options.", ... paths: [["default"]] }]

validateRuleOptions("boundaries/dependencies", { default: "maybe" }, { legacyWarnings: true, schema: false });
// []
```

> \[注\] 规则名称总是有 `boundaries/` 前缀,无论插件在 ESLint 配置中注册的名称.

### 规范依赖规则选项

`normalizeDependenciesRuleOptions` 应用选项的默认值 `dependencies` 统治和规范其政策的选择者,所以一个主机可以和它们匹配 [`@boundaries/elements`](https://www.npmjs.com/package/@boundaries/elements)。它假设通过规则方案,并报告没有问题:首先通过 `validateRuleOptions`。 。 。 .

```ts
import { normalizeDependenciesRuleOptions } from "@boundaries/config";

const options = normalizeDependenciesRuleOptions({
  policies: [
    {
      from: { element: { type: "component" } },
      allow: { to: { element: { type: "helper" } } },
    },
  ],
});

// {
//   default: "disallow",
//   message: undefined,
//   policies: [
//     {
//       from: [{ element: [{ type: "component" }] }],
//       allow: [{ to: [{ element: [{ type: "helper" }] }] }],
//       ...
//     },
//   ],
//   checkAllOrigins: false,
//   checkUnknownLocals: false,
//   checkInternals: false,
// }
```

> \[尖叫声\] 常态化的选取者与纪念 `@boundaries/elements`不要改变它们.

### 获取规则选项的外观

`getRuleOptionsSchema` 返回规则选项的 JSON 方案, 如 ESLint 插件在规则中声明 `meta.schema`: 包含每个选项的图案的数组, 当规则没有选项时为空 .

```ts
import { getRuleOptionsSchema } from "@boundaries/config";

getRuleOptionsSchema("boundaries/no-private");
// [
//   {
//     type: "object",
//     properties: {
//       allowUncles: { type: "boolean" },
//       message: { type: "string" },
//     },
//     additionalProperties: false,
//   },
// ]

getRuleOptionsSchema("boundaries/no-unknown-files");
// []
```

> \[尖叫声\] 返回的策略在呼叫之间共享. 不要改变他们.

## API 参考

### 职能

#### `normalizeConfig`

将ESLint配置的边界部分正常化, `{ settings, rules }`。见 [规范配置](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-a-config)。 。 。 .

-   **参数**数字 :
    -   `config`数字 : `unknown` ——配置对象. 内容 `settings` 财务报告和审定财务报表 `rules` 是可选的; 任何其它密钥都会被忽略.
    -   `options`数字 : `NormalizeConfigOptions` - 可选的.
        -   `pluginName`数字 : `string` - 可选的。 规则名称在 `rules`默认 `"boundaries"`。 。 。 .
        -   `rootPath`数字 : `string` - 可选的。 项目的根道,已经由主机解决了. 没有它,正常化的 `rootPath` 这是 `boundaries/root-path` 设置为正文.
-   **回返**数字 : [`ConfigResult<ConfigNormalized>`](https://npmcn.com/package/%40boundaries/config/#readme-configresult) —— 规范化的配置和所发现的问题, 有来自配置对象根的路径.

```ts
const { value, diagnostics } = normalizeConfig(config, { rootPath: "/project" });
```

#### `normalizeSettings`

规范化 `boundaries/*` 设置。 见 [规范设置](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-settings)。 。 。 .

-   **参数**数字 :
    -   `settings`数字 : `Record<string, unknown> | undefined` - 电话 `settings` 一个 ESLint 配置的对象。 仅限其 `boundaries/*` 键被读取.
    -   `options`数字 : `NormalizeSettingsOptions` - 可选的.
        -   `rootPath`数字 : `string` - 可选的。 项目的根道,已经由主机解决了. 没有它,正常化的 `rootPath` 这是 `boundaries/root-path` 设置为正文.
-   **回返**数字 : [`ConfigResult<SettingsNormalized>`](https://npmcn.com/package/%40boundaries/config/#readme-configresult) —— 常规设置和发现的问题, 以及设置对象根的路径 .

```ts
const { value, diagnostics } = normalizeSettings(config.settings, { rootPath: "/project" });
```

#### `validateRuleOptions`

验证规则条目的选项。 见 [验证规则选项](https://npmcn.com/package/%40boundaries/config/#readme-validating-rule-options)。 。 。 .

-   **参数**数字 :
    -   `ruleName`数字 : `RuleName` - 规则的名称,加上 `boundaries/` 前缀, 如 `"boundaries/dependencies"`。 。 。 .
    -   `options`数字 : `unknown` - 规则条目的选项对象,或 `undefined` 当条目没有选项时.
    -   `validation`数字 : `RuleOptionsValidation` - 什么来验证.
        -   `legacyWarnings`数字 : `boolean` ——是否将政策贬值的语法报告为: `boundaries/legacy-warnings` 设置是.
        -   `schema`数字 : `boolean` - 可选的。 是否按照 ESLint 对规则的规则验证选项 `meta.schema`默认 `true`; 已经运行 ESLint 通道的主机 `false`。 。 。 .
-   **回返**数字 : [`Diagnostic[]`](https://npmcn.com/package/%40boundaries/config/#readme-diagnostic) ——发现的问题,从选项对象的根出出路径. 当计划验证失败时, 只有错误 .

```ts
const diagnostics = validateRuleOptions("boundaries/dependencies", options, {
  legacyWarnings: true,
});
```

#### `normalizeDependenciesRuleOptions`

应用选项的默认值 `dependencies` 统治政策的选择者并使其正常化。 见 [规范依赖规则选项](https://npmcn.com/package/%40boundaries/config/#readme-normalizing-the-dependencies-rule-options)。 。 。 .

-   **参数**数字 :
    -   `options`数字 : `DependenciesRuleOptions | undefined` - 备选案文 `dependencies` 规则,或 `element-types` 规则,已经验证 与规则的策略.
-   **回返**数字 : [`DependenciesRuleOptionsNormalized`](https://npmcn.com/package/%40boundaries/config/#readme-dependenciesruleoptionsnormalized) ——适用其缺省选项. 这些政策来自 `policies`,或从被贬值的 `rules` 何时 `policies` 未设定,每个都保留其索引.

```ts
const options = normalizeDependenciesRuleOptions({ default: "allow", policies: [] });
```

#### `getRuleOptionsSchema`

返回规则选项的 JSON 方案。 见 [获取规则选项的外观](https://npmcn.com/package/%40boundaries/config/#readme-getting-the-schema-of-the-rule-options)。 。 。 .

-   **参数**数字 :
    -   `ruleName`数字 : `RuleName` - 规则的名称,加上 `boundaries/` 前缀.
-   **回返**数字 : `JsonSchema[]` ——规则的每个选项的图案,当规则没有选项时为空.

```ts
const schema = getRuleOptionsSchema("boundaries/dependencies");
```

### 类型警卫

每人收到一张 `value` 类型 `unknown` 返回时 `true` 当值为类型时.

| 函数 | 缩到 | 回返 `true` 页:1 |
| --- | --- | --- |
| `isSettingsKey` | `SettingsKey` | 插件设置的密钥, 如 `"boundaries/elements"`。 。 。 . |
| `isDependencyNodeKey` | `DependencyNodeKey` | 内置依赖节点 : `"import"`, (中文(简体) ), `"export"`, (中文(简体) ), `"require"` 或者说 `"dynamic-import"`。 。 。 . |
| `isRuleName` | `RuleName` | 规则名称 `boundaries/` 前缀, 如 `"boundaries/dependencies"`。 。 。 . |
| `isRuleShortName` | `RuleShortName` | 没有前缀的规则名称, 如 `"dependencies"`。 。 。 . |
| `isRuleEffect` | `RuleEffect` | `"allow"` 或者说 `"disallow"`。 。 。 . |
| `isRulePolicy` | `RuleEffect` | _(已过期)_ 别名 `isRuleEffect`。 。 。 . |

```ts
isRuleName("boundaries/dependencies"); // true
isRuleName("dependencies"); // false
isRuleShortName("dependencies"); // true
```

### Docs 链接

链接的构建者 [jsbounders.dev (英语)](https://www.jsboundaries.dev/) 诊断带。 每个 `anchor` 参数是可选的 `string`,以 `#<anchor>`,每个函数返回 a `string`。 。 。 .

| 函数 | 回返 |
| --- | --- |
| `docsUrl(path, anchor?)` | 文件页的 URL : `https://www.jsboundaries.dev/docs/<path>/`。 。 。 . |
| `getRuleDocsPath(ruleName)` | 规则文件页的路径, `rules/<short name>`. 被贬损的规则获得替换规则的一页. |
| `ruleDocsUrl(ruleName, anchor?)` | 规则文件页的 URL . |
| `moreInfoLink(path, anchor?)` | `More info: <url>`,带有文件页的 URL. |
| `moreInfoSettingsLink(anchor?)` | `moreInfoLink` 设置页面. |
| `moreInfoElementsLink(anchor?)` | `moreInfoLink` 中. |
| `moreInfoLegacySettingsLink(anchor?)` | `moreInfoLink` 后继设置页面. |
| `moreInfoSelectorsLink(anchor?)` | `moreInfoLink` 中选择. |
| `migrationGuideLink(versionFrom, versionTo, anchor?)` | `moreInfoLink` 两种主要版本之间的移徙指南. |
| `migrationToV2GuideLink(anchor?)` | `migrationGuideLink` 从版本 1 到 2 . |
| `migrationToV6GuideLink(anchor?)` | `migrationGuideLink` 从第五版到第六版. |
| `migrationToV7GuideLink(anchor?)` | `migrationGuideLink` 从第6至7版. |

`path`, (中文(简体) ), `versionFrom` 财务报告和审定财务报表 `versionTo` 为: `string`s,和 `ruleName` 是一个 `RuleName`。 。 。 .

```ts
ruleDocsUrl("boundaries/no-unknown"); // "https://www.jsboundaries.dev/docs/rules/no-unknown-dependencies/"
moreInfoSettingsLink(); // "More info: https://www.jsboundaries.dev/docs/settings/"
```

### 常数

| 常数 | 数值 |
| --- | --- |
| `DIAGNOSTIC_LEVELS_MAP` | 诊断水平: `{ ERROR: "error", WARNING: "warning", DEPRECATION: "deprecation" }`。 。 。 . |
| `RULE_SEVERITIES_MAP` | 规则正常化条目的断层: `{ OFF: "off", WARN: "warn", ERROR: "error" }`。 。 。 . |
| `RULE_NAMES_MAP`, (中文(简体) ), `RULE_NAMES` | 规则名称与 `boundaries/` 前缀,作为地图和数组. |
| `RULE_SHORT_NAMES_MAP`, (中文(简体) ), `RULE_SHORT_NAMES` | 没有前缀的规则名称,作为地图和数组. |
| `SETTINGS_KEYS_MAP` | 设置的密钥, 如 `ELEMENTS: "boundaries/elements"`。 。 。 . |
| `SETTINGS` | 设置和规则的密钥, 有效的元素描述符模式和依赖节点类型, 以及内置依赖节点的选择器, `DEFAULT_DEPENDENCY_NODES`。 。 。 . |
| `DEPENDENCY_NODE_KEYS_MAP` | 内置依赖节点 : `{ REQUIRE: "require", IMPORT: "import", DYNAMIC_IMPORT: "dynamic-import", EXPORT: "export" }`。 。 。 . |
| `RULE_EFFECTS_MAP` | 政策的效果: `{ ALLOW: "allow", DISALLOW: "disallow" }`。 。 。 . `RULE_POLICIES_MAP` 是其被贬损的别名. |
| `NO_UNKNOWN_DEPENDENCIES_REQUIRE_MAP` | 联合国 `require` 选项 `no-unknown-dependencies` 规则: `{ ALL: "all", ELEMENT: "element", FILE: "file", ANY: "any" }`。 。 。 . |
| `LEGACY_TEMPLATES_DEFAULT`, (中文(简体) ), `LEGACY_WARNINGS_DEFAULT`, (中文(简体) ), `ELEMENTS_SINGLE_TYPE_DEFAULT`, (中文(简体) ), `CACHE_DEFAULT` | 默认值 `boundaries/legacy-templates`, (中文(简体) ), `boundaries/legacy-warnings`, (中文(简体) ), `boundaries/elements-single-match` 财务报告和审定财务报表 `boundaries/cache` 设置 : `true`。 。 。 . |
| `FILES_SINGLE_MATCH_DEFAULT` | 默认 `boundaries/files-single-match` 设置 : `false`。 。 。 . |
| `PLUGIN_NAME` | `"boundaries"`。 。 。 . |
| `WEBSITE_URL`, (中文(简体) ), `REPO_URL`, (中文(简体) ), `PLUGIN_ISSUES_URL` | 网站的URL,存储器及其问题. |

地图的值也逐一导出, 例如 `DEPENDENCIES`, (中文(简体) ), `DEPENDENCY_NODE_IMPORT`, (中文(简体) ), `RULE_EFFECT_ALLOW` 或者说 `NO_UNKNOWN_DEPENDENCIES_REQUIRE_ANY`。 。 。 .

## 类型参考

### 结果类型

#### `ConfigResult`

归来 `normalizeConfig` 财务报告和审定财务报表 `normalizeSettings`,作为 `ConfigResult<T>`。 。 。 .

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `value` | `T` | 正常值 。 总是设置: 无效的条目被忽略 . |
| `diagnostics` | `Diagnostic[]` | 发现的问题,按照ESLint插件打印的顺序,每出一次. |

#### `Diagnostic`

输入中发现的问题 。 见 [诊断](https://npmcn.com/package/%40boundaries/config/#readme-diagnostics)。 。 。 .

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `level` | `DiagnosticLevel` | `"error"`, (中文(简体) ), `"warning"` 或者说 `"deprecation"`。 。 。 . |
| `title` | `string` | ESLint插件所打印的标题 . |
| `detail` | `string | undefined` | ESLint插件在标题下打印的细节和文件链接. |
| `paths` | `DiagnosticPath[]` | 每个受影响的条目一条路径. `DiagnosticPath` 实值 `(string | number)[]`。 。 。 . |

### 普通类型

#### `ConfigNormalized`

这个 `value` 返回时间 `normalizeConfig`。 。 。 .

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `settings` | `SettingsNormalized` | 常规设置 . |
| `rules` | `{ [Name in RuleShortName]?: RuleEntryNormalized<Name> }` | 插件的规则 `rules`,简称. 因出错而遗漏的条目缺失 . |

#### `RuleEntryNormalized`

规则条目 `ConfigNormalized`,作为 `RuleEntryNormalized<Name>`。 。 。 .

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `severity` | `RuleSeverity` | `"off"`, (中文(简体) ), `"warn"` 或者说 `"error"`,无论是写成数字还是字符串. |
| `options` | `DependenciesRuleOptionsNormalized` 页:1 `dependencies` 财务报告和审定财务报表 `element-types`, (中文(简体) ), `unknown` 对其他人 | 规则的备选方案:规则与 `dependencies` 政策,为其他人写. |

#### `SettingsNormalized`

这个 `value` 返回时间 `normalizeSettings`,则 `settings` 联 合 国 `ConfigNormalized`。 。 。 .

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `elementDescriptors` | `ElementDescriptors` | 有效的描述 `boundaries/elements`,或堕落者 `boundaries/types` 何时 `boundaries/elements` 未设置。 遗留字符串描述符被转换成对象. 默认 `[]`。 。 。 . |
| `elementsSingleMatch` | `boolean` | `boundaries/elements-single-match`,或贬值的 `boundaries/elements-single-type` 当它没有设置的时候。 默认 `true`。 。 。 . |
| `fileDescriptors` | `FileDescriptors` | 有效的描述 `boundaries/files`默认 `[]`。 。 。 . |
| `filesSingleMatch` | `boolean` | `boundaries/files-single-match`默认 `false`。 。 。 . |
| `ignorePaths` | `string[] | undefined` | `boundaries/ignore`,总是作为一个阵列。 默认 `undefined`。 。 。 . |
| `includePaths` | `string[] | undefined` | `boundaries/include`,总是作为一个阵列。 默认 `undefined`。 。 。 . |
| `rootPath` | `string | undefined` | 这个 `rootPath` 选项,或 `boundaries/root-path` 当选项未被通过时写入. |
| `dependencyNodes` | `DependencyNodeSelector[]` | 节点的选择器 `boundaries/dependency-nodes`,然后是有效的 `boundaries/additional-dependency-nodes`。默认情况下,选择 `import`, (中文(简体) ), `export`, (中文(简体) ), `require` 财务报告和审定财务报表 `dynamic-import`。 。 。 . |
| `legacyTemplates` | `boolean` | `boundaries/legacy-templates`默认 `true`。 。 。 . |
| `cache` | `boolean` | `boundaries/cache`默认 `true`。 。 。 . |
| `legacyWarnings` | `boolean` | `boundaries/legacy-warnings`默认 `true`。 。 。 . |
| `flagAsExternal` | `FlagAsExternalOptions` | `boundaries/flag-as-external`,在默认情况下,每个有效选项: `{ unresolvableAlias: true, inNodeModules: true, outsideRootPath: false, customSourcePatterns: [] }`。 。 。 . |
| `debug` | `DebugSettingNormalized` | `boundaries/debug`,带有默认值. |

`ElementDescriptors`, (中文(简体) ), `FileDescriptors` 财务报告和审定财务报表 `FlagAsExternalOptions` 属于类型 [`@boundaries/elements`](https://www.npmjs.com/package/@boundaries/elements)。 。 。 .

#### `DebugSettingNormalized`

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `enabled` | `boolean` | 是否启用调试模式 。 默认 `false`。 。 。 . |
| `messages` | `{ files: boolean; dependencies: boolean; violations: boolean }` | 是否打印文件的调试消息、 依赖性和规则违反 。 每个都是 `true` 默认. |
| `filter.files` | `FileSelectorNormalized | EntitySelectorNormalized | undefined` | 在文件的调试信件有效时, 过滤这些信件的常态选择器 . |
| `filter.dependencies` | `DependencySelectorNormalized | undefined` | 用于过滤依赖关系的调试消息的常态选择器, 当有效时 . |

#### `DependenciesRuleOptionsNormalized`

归来 `normalizeDependenciesRuleOptions`,则 `options` 会 议 日 程 和 议 程 `dependencies` 财务报告和审定财务报表 `element-types` 条目 `ConfigNormalized`。 。 。 .

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `default` | `RuleEffect` | 当没有政策匹配时的效果 : `"allow"`,或 `"disallow"` 对于任何其他价值. |
| `message` | `string | undefined` | 所有规则被违反的自定义消息, 当设定时 . |
| `policies` | `DependenciesPolicyNormalized[]` | `policies`,或贬值的 `rules` 何时 `policies` 未设置, 其选择者已正常化。 每个人的指数都保留在选项中. |
| `checkAllOrigins` | `boolean` | 是否检查每个来源的依赖性,而不仅仅是本地的依赖性. 默认 `false`。 。 。 . |
| `checkUnknownLocals` | `boolean` | 是否检查本地对未知元素的依赖性 。 默认 `false`。 。 。 . |
| `checkInternals` | `boolean` | 是否检查同一元素的文件之间的依赖性 。 默认 `false`。 。 。 . |

#### `DependenciesPolicyNormalized`

| 财产 | 类型 | 说明 |
| --- | --- | --- |
| `from` | `EntitySelectorNormalized | undefined` | 所依赖的实体的选择者. |
| `to` | `EntitySelectorNormalized | undefined` | 依赖对象实体的选择者. |
| `dependency` | `DependencyInfoSelectorNormalized | undefined` | 依赖元数据选择器 . |
| `allow` | `DependencySelectorNormalized | EntitySelectorNormalized | undefined` | 允许的依赖的选取者 . |
| `disallow` | `DependencySelectorNormalized | EntitySelectorNormalized | undefined` | 不允许依赖的选定者. |
| `importKind` | `DependencyKind | undefined` | _(已过期)_ 政策适用于何种进口,如书面. |
| `message` | `string | undefined` | 政策违规的风俗信息,如上所记. |

选择者类型是类型 [`@boundaries/elements`](https://www.npmjs.com/package/@boundaries/elements),在它选取的参考文献中描述它们.

### 设置和规则选项类型

软件包会导出用户写作的种类,所以一个主机可以输入自己的配置对象. 主要有:

| 类型 | 说明 |
| --- | --- |
| `Settings` | 这个 `boundaries/*` 设置,按键排列. |
| `IgnoreSetting`, (中文(简体) ), `IncludeSetting`, (中文(简体) ), `RootPathSetting`, (中文(简体) ), `DebugSetting` | 联合国 `boundaries/ignore`, (中文(简体) ), `boundaries/include`, (中文(简体) ), `boundaries/root-path` 财务报告和审定财务报表 `boundaries/debug` 设置. |
| `DependencyNodeSelector` | 一项 `boundaries/additional-dependency-nodes`数字 : `{ selector: string; kind: DependencyKind; name?: string }`。 。 。 . |
| `RuleBaseOptions` | 这个 `default` 财务报告和审定财务报表 `message` 与政策规则共享的选项. |
| `DependenciesRuleOptions`, (中文(简体) ), `DependenciesPolicy` | 备选案文 `dependencies` 财务报告和审定财务报表 `element-types` 规则和他们的政策. |
| `EntryPointRuleOptions`, (中文(简体) ), `EntryPointPolicy` | 备选案文 `entry-point` 规则及其政策. |
| `ExternalRuleOptions`, (中文(简体) ), `ExternalPolicy`, (中文(简体) ), `ExternalLibrariesSelector` | 备选案文 `external` 规则、政策和图书馆选择器. |
| `NoPrivateOptions` | 备选案文 `no-private` 规则. |
| `NoUnknownDependenciesOptions` | 备选案文 `no-unknown-dependencies` 财务报告和审定财务报表 `no-unknown` 规则. |
| `RuleOptions` | 任何规则的选择. |
| `RuleName`, (中文(简体) ), `RuleShortName`, (中文(简体) ), `SettingsKey`, (中文(简体) ), `RuleEffect`, (中文(简体) ), `DependencyNodeKey` | 匹配值的结合 [常数](https://npmcn.com/package/%40boundaries/config/#readme-constants)。 。 。 . |
| `NormalizeConfigOptions`, (中文(简体) ), `NormalizeSettingsOptions`, (中文(简体) ), `RuleOptionsValidation` | 备选案文 [函数](https://npmcn.com/package/%40boundaries/config/#readme-functions)。 。 。 . |
| `JsonSchema` | 一个JSON schema对象,例如规则选项的 schema. |

这个 `no-ignored-dependencies`, (中文(简体) ), `no-ignored` 财务报告和审定财务报表 `no-unknown-files` 规则没有选择. `DependenciesRule`, (中文(简体) ), `DependenciesRuleNormalized`, (中文(简体) ), `EntryPointRule`, (中文(简体) ), `ExternalRule`, (中文(简体) ), `ExternalLibrarySelectors`, (中文(简体) ), `RulePolicy` 财务报告和审定财务报表 `AliasSetting` 已贬值.

## 捐款

欢迎贡献者. 请读一下 [提供指南](https://npmcn.com/package/.github/CONTRIBUTING.md) 财务报告和审定财务报表 [行为守则](https://npmcn.com/package/.github/CODE_OF_CONDUCT.md)。 。 。 .

## 许可证

麻省理工学院,看 [自由主义](https://npmcn.com/package/%40boundaries/config/LICENSE) 详细情况.

## 常见问题

### @boundaries/config 是什么？

@ 边界工具的设置和规则选项的规范化和验证

### 如何安装 @boundaries/config？

在项目目录运行 npm install @boundaries/config，或使用 pnpm add / yarn add / bun add。

### @boundaries/config 支持 TypeScript 吗？

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

### @boundaries/config 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @boundaries/config 需要什么版本的 Node\.js？

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

### @boundaries/config 可以商用吗？

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

### @boundaries/config 的下载量有多少？

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

### @boundaries/config 还在维护吗？

最新版本 1\.0\.1 发布于 2026/11/05（3 天前）；至今共发布 3 个版本，其中过去 12 个月发布了 3 个；首次发布于 2026/11/02。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

