Skip to content

Commit

Permalink
ignore trailing comma in cli options
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Dec 9, 2024
1 parent 60a6743 commit 3284ae7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ function getProperty(obj: Record<string, any>, path: string) {
return path.split(".").reduce((obj: Record<string, any>, 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 {}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ?? []);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3284ae7

Please sign in to comment.