From 3284ae74e686a3b154eb306d8e06eb1abbd065e2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 9 Dec 2024 10:07:41 +0100 Subject: [PATCH] ignore trailing comma in cli options --- index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 848d41d..9ba4d19 100755 --- a/index.ts +++ b/index.ts @@ -189,6 +189,10 @@ function getProperty(obj: Record, path: string) { return path.split(".").reduce((obj: Record, prop: string) => obj?.[prop] ?? null, obj); } +function commaSeparatedToArray(str: string) { + return str.split(",").filter(Boolean); +} + function findUpSync(filename: string, dir: string): string | null { const path = join(dir, filename); try { accessSync(path); return path; } catch {} @@ -776,7 +780,7 @@ function parseMixedArg(arg: any) { } else if (arg === "") { return true; } else if (typeof arg === "string") { - return arg.includes(",") ? new Set(arg.split(",")) : new Set([arg]); + return arg.includes(",") ? new Set(commaSeparatedToArray(arg)) : new Set([arg]); } else if (Array.isArray(arg)) { return new Set(arg); } else { @@ -971,10 +975,12 @@ async function main() { let includeCli: string[] = []; let excludeCli: string[] = []; if (args.include && args.include !== true) { // cli - includeCli = (Array.isArray(args.include) ? args.include : [args.include]).flatMap(item => item.split(",")); + includeCli = (Array.isArray(args.include) ? args.include : [args.include]) + .flatMap(item => commaSeparatedToArray(item)); } if (args.exclude && args.exclude !== true) { - excludeCli = (Array.isArray(args.exclude) ? args.exclude : [args.exclude]).flatMap(item => item.split(",")); + excludeCli = (Array.isArray(args.exclude) ? args.exclude : [args.exclude]) + .flatMap(item => commaSeparatedToArray(item)); } const include = matchersToRegexSet(includeCli, config?.include ?? []); const exclude = matchersToRegexSet(excludeCli, config?.exclude ?? []); @@ -1004,7 +1010,7 @@ async function main() { let dependencyTypes: string[] = []; if (types) { - dependencyTypes = Array.isArray(types) ? types : types.split(","); + dependencyTypes = Array.isArray(types) ? types : commaSeparatedToArray(types); } else if ("types" in config && Array.isArray(config.types)) { dependencyTypes = config.types; } else {