@rushstack/heft-config-file
The @rushstack/heft-config-file library is the standard engine used to load Heft's config files. It provides a number of features such as
- JSON schema validation
"extends"
inheritance with intuitive error messages- Support for rig package resolution
- Four different
"extends"
inheritance types (append, merge, replace, computed) with preconfigured defaults - Property inheritance directives to customize them
属性继承指令
当使用 "extends"
继承时,Heft 配置文件通常会为每个 JSON 字段预配置一个直观的默认策略。(有关实际示例,请查看来自 JestPlugin.ts 的 propertyInheritance
字段。)
如果需要为特定设置使用不同的继承类型,可以在 JSON 文件中添加 **属性继承指令**。例如,假设我们正在扩展一个假设的文件,该文件以前定义了 exampleObject
值(这是一个键值对对象)和 exampleArray
值(这是一个数组对象)
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/example-config-file.schema.json",
"extends": "base-project/config/example-config-file.json",
"$exampleObject.inheritanceType": "merge", // valid choices are: "merge", "replace"
"exampleObject": {
"$exampleObjectMember.inheritanceType": "merge", // valid choices are: "merge", "replace"
"exampleObjectMember": { ... },
"$exampleArrayMember.inheritanceType": "append", // valid choices are: "append", "replace"
"exampleArrayMember": [ ... ]
},
"$exampleArray.inheritanceType": "replace", // valid choices are: "append", "replace"
"exampleArray": [ ... ]
}
一旦将对象设置为 inheritanceType
为 override,所有子属性的 inheritanceType
值将被忽略,因为最顶层对象已覆盖所有子属性。
需要注意的是,键值对对象和数组使用了不同的逻辑。这样做的目的是明确地表明数组将按原样追加,并且在合并期间不会执行其他处理(例如,如果数组应为集合,则不会进行重复数据删除)。如果需要此类行为,可以在实现端完成。在 @rushstack/heft-config-file
包中对数组进行重复数据删除没有意义,因为对非基本对象的数组进行重复数据删除难以定义。