-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: present
meta.defaultOptions
in the config inspector (#110)
Co-authored-by: Anthony Fu <[email protected]>
- Loading branch information
1 parent
ab526d0
commit 9820d63
Showing
12 changed files
with
505 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Indicates if any user-supplied option values match the default value for that option | ||
*/ | ||
let hasRedundantOptions: boolean | ||
|
||
/** | ||
* Wraps an option value in a 3-part array, while still preserving the original data type and value. | ||
* | ||
* The '--' markers provide something that a regex replace can easily later match on. | ||
* (See transformDiff() in ./strings.ts) | ||
*/ | ||
function redundantOption(option: any) { | ||
hasRedundantOptions = true | ||
return ['--', option, '--'] | ||
} | ||
|
||
function deepCompareOption(option: any, defaultOption: any) { | ||
if (defaultOption === void 0) | ||
return option | ||
if (typeof option !== typeof defaultOption) | ||
return option | ||
|
||
if (option === defaultOption) | ||
return redundantOption(option) | ||
|
||
if (typeof option === 'object' && option !== null && defaultOption !== null) { | ||
if (Array.isArray(option) && Array.isArray(defaultOption) && option.length === defaultOption.length) { | ||
if (option.length === 0) | ||
return redundantOption(option) | ||
return option.map((value: any, index: number): any[] => deepCompareOption(value, defaultOption[index])) | ||
} | ||
else if (!Array.isArray(option) && !Array.isArray(defaultOption)) { | ||
const optionKeys = Object.keys(option) | ||
|
||
return optionKeys.reduce((comparedKeys: Record<string, any>, key) => { | ||
comparedKeys[key] = deepCompareOption(option[key], defaultOption[key]) | ||
return comparedKeys | ||
}, {}) | ||
} | ||
} | ||
|
||
return option | ||
} | ||
|
||
export function deepCompareOptions(options: any[], defaultOptions: any[]) { | ||
hasRedundantOptions = false | ||
const comparedOptions = options.map((value, index) => deepCompareOption(value, index < defaultOptions.length ? defaultOptions[index] : void 0)) | ||
|
||
return { | ||
options: comparedOptions, | ||
hasRedundantOptions, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.