* @param {*} options * @param {*} optionInfos * @param {{ logger?: false; isCLI?: boolean; passThrough?: string[] | boolean; FlagSchema?: any; descriptor?: any }} param2
(
options,
optionInfos,
{
logger = false,
isCLI = false,
passThrough = false,
FlagSchema,
descriptor,
} = {},
)
| 12 | * @param {{ logger?: false; isCLI?: boolean; passThrough?: string[] | boolean; FlagSchema?: any; descriptor?: any }} param2 |
| 13 | */ |
| 14 | function normalizeOptions( |
| 15 | options, |
| 16 | optionInfos, |
| 17 | { |
| 18 | logger = false, |
| 19 | isCLI = false, |
| 20 | passThrough = false, |
| 21 | FlagSchema, |
| 22 | descriptor, |
| 23 | } = {}, |
| 24 | ) { |
| 25 | // TODO: Move CLI related part into `/src/cli` |
| 26 | if (isCLI) { |
| 27 | /* c8 ignore start */ |
| 28 | if (!FlagSchema) { |
| 29 | throw new Error("'FlagSchema' option is required."); |
| 30 | } |
| 31 | |
| 32 | if (!descriptor) { |
| 33 | throw new Error("'descriptor' option is required."); |
| 34 | } |
| 35 | /* c8 ignore stop */ |
| 36 | } else { |
| 37 | descriptor = vnopts.apiDescriptor; |
| 38 | } |
| 39 | |
| 40 | const unknown = !passThrough |
| 41 | ? (key, value, options) => { |
| 42 | // Don't suggest `_` for unknown flags |
| 43 | const { _, ...schemas } = options.schemas; |
| 44 | return vnopts.levenUnknownHandler(key, value, { |
| 45 | ...options, |
| 46 | schemas, |
| 47 | }); |
| 48 | } |
| 49 | : Array.isArray(passThrough) |
| 50 | ? (key, value) => |
| 51 | !passThrough.includes(key) ? undefined : { [key]: value } |
| 52 | : (key, value) => ({ [key]: value }); |
| 53 | |
| 54 | const schemas = optionInfosToSchemas(optionInfos, { isCLI, FlagSchema }); |
| 55 | const normalizer = new vnopts.Normalizer(schemas, { |
| 56 | logger, |
| 57 | unknown, |
| 58 | descriptor, |
| 59 | }); |
| 60 | |
| 61 | const shouldSuppressDuplicateDeprecationWarnings = logger !== false; |
| 62 | |
| 63 | if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) { |
| 64 | // @ts-expect-error |
| 65 | normalizer._hasDeprecationWarned = hasDeprecationWarned; |
| 66 | } |
| 67 | |
| 68 | const normalized = normalizer.normalize(options); |
| 69 | |
| 70 | if (shouldSuppressDuplicateDeprecationWarnings) { |
| 71 | // @ts-expect-error |
no test coverage detected
searching dependent graphs…