ConfigResolver
Provides the default common config resolution process resolving any extensions and setting default values.
Both file and NPM modules are supported for config extension via the extends as a string or array of strings.
Validation is also available when setting pre and post validation data via setResolverData.
ConfigResolver is modeled after the extensions functionality of ESLint. Please see the respective licenses of the code modified at the end of this file.
Test:
Constructor Summary
| Public Constructor | ||
| public |
constructor(resolverData: ConfigResolverData) Instantiate ConfigResolver potentially destructuring an object passed in with the following keys. |
|
Member Summary
| Private Members | ||
| private |
Accessor entry to default value. |
|
| private |
_eventbus: EventProxy |
|
| private |
Accessor entry to typhonjs-object-util validation entry. |
|
| private |
Accessor entry to typhonjs-object-util validation entry. |
|
| private |
A list of strings indicating keys which will be updated to an array and merged. |
|
Method Summary
| Public Methods | ||
| public |
Returns the resolver data as a ConfigResolverData object. |
|
| public |
onPluginLoad(ev: PluginEvent) Stores any associated plugin eventbus and attempts loading of . |
|
| public |
postValidate(config: object, configName: string) Validates a config object for any missing or incorrect parameters after resolving. |
|
| public |
preValidate(config: object, configName: string) Validates a config object for any missing or incorrect parameters before and during resolving extended config data. |
|
| public |
Resolves any config extension and sets missing default config values. |
|
| public |
setDefaultValues(config: object) Sets default config values. |
|
| public |
setResolverData(objectPattern: {"defaultValues": *, "preValidate": *, "postValidate": *, "upgradeMergeList": *}) Sets the config resolver data. |
|
| Private Methods | ||
| private |
_applyExtends(config: Object, filePath: string, relativeTo: string, validate: function, loadedConfigs: string[]): Object Applies values from the "extends" field in a configuration file. |
|
| private |
Merges two config objects. |
|
| private |
_isFilePath(filePath: string): boolean Determines if a given string represents a filepath or not using the same conventions as require(), meaning that the first character must be non-alphanumeric and not the @ sign which is used for scoped packages to be considered a file path. |
|
| private |
Loads a configuration file from the given file path. |
|
| private |
_resolveExtends(config: object): * Provides config extension implementation. |
|
Public Constructors
public constructor(resolverData: ConfigResolverData) source
Instantiate ConfigResolver potentially destructuring an object passed in with the following keys.
Params:
| Name | Type | Attribute | Description |
| resolverData | ConfigResolverData |
|
Any default values to apply after resolution. |
Private Members
private _eventbus: EventProxy source
Public Methods
public getResolverData(): ConfigResolverData source
Returns the resolver data as a ConfigResolverData object.
Note: that this is the active data and a copy is not made.
public onPluginLoad(ev: PluginEvent) source
Stores any associated plugin eventbus and attempts loading of . The following event bindings are available:
config:resolver:resolve: Invokes resolve.
config:resolver:validate:pre: Invokes preValidate.
config:resolver:validate:post: Invokes postValidate.
Params:
| Name | Type | Attribute | Description |
| ev | PluginEvent | The plugin event. |
public postValidate(config: object, configName: string) source
Validates a config object for any missing or incorrect parameters after resolving.
public preValidate(config: object, configName: string) source
Validates a config object for any missing or incorrect parameters before and during resolving extended config data.
public resolve(config: object): * source
Resolves any config extension and sets missing default config values.
Params:
| Name | Type | Attribute | Description |
| config | object | A config object to resolve. |
Return:
| * |
public setDefaultValues(config: object) source
Sets default config values.
Params:
| Name | Type | Attribute | Description |
| config | object | A config object to set default values that do not already exist. |
public setResolverData(objectPattern: {"defaultValues": *, "preValidate": *, "postValidate": *, "upgradeMergeList": *}) source
Sets the config resolver data.
Note: For values of ConfigResolverData not set empty defaults are provided.
Params:
| Name | Type | Attribute | Description |
| objectPattern | {"defaultValues": *, "preValidate": *, "postValidate": *, "upgradeMergeList": *} |
|
Private Methods
private _applyExtends(config: Object, filePath: string, relativeTo: string, validate: function, loadedConfigs: string[]): Object source
Applies values from the "extends" field in a configuration file.
Params:
| Name | Type | Attribute | Description |
| config | Object | The configuration information. |
|
| filePath | string | The file path from which the configuration information was loaded. |
|
| relativeTo | string |
|
The path to resolve relative to. |
| validate | function |
|
A function performing validation. |
| loadedConfigs | string[] |
|
The config files already loaded. |
private _deepMerge(target: Object, src: Object, combine: boolean, parentKey: string): Object source
Merges two config objects. This will not only add missing keys, but will also modify values to match.
If an object key is included in this._upgradeMergeList it will be upgraded and merged into an array without duplicating elements.
private _isFilePath(filePath: string): boolean source
Determines if a given string represents a filepath or not using the same conventions as require(), meaning that the first character must be non-alphanumeric and not the @ sign which is used for scoped packages to be considered a file path.
Params:
| Name | Type | Attribute | Description |
| filePath | string | The string to check. |
private _load(filePath: string, relativeTo: string, validate: function, loadedConfigs: string[]): Object source
Loads a configuration file from the given file path.
Params:
| Name | Type | Attribute | Description |
| filePath | string | The filename or package name to load the configuration information from. |
|
| relativeTo | string |
|
The path to resolve relative to. |
| validate | function |
|
A function performing validation. |
| loadedConfigs | string[] |
|
The config files already loaded. |