Skip to content

Commit

Permalink
fix(cli): use defaults when source is empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Sep 17, 2020
1 parent bfd12b4 commit c2f6199
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/commands/lib/get-wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const getPatternsFromJson = (
return packages ? [process.cwd()].concat(packages).map((dirPath) => join(dirPath, 'package.json')) : null;
};

const getCliPatterns = (program: Options): Options['source'] | null =>
isArrayOfStrings(program.source) ? program.source : null;

const getYarnPatterns = (): string[] | null =>
getPatternsFromJson('package.json', (config) => [config.workspaces, config.workspaces?.packages]);

Expand All @@ -58,18 +61,13 @@ const getPnpmPatterns = (): string[] | null => {
}
};

const hasCliPatterns = (program: Options): boolean => program.source && program.source.length > 0;
const getCliPatterns = (program: Options): Options['source'] => program.source;
const getDefaultPatterns = (): string[] => ALL_PATTERNS;
const resolvePattern = (pattern: string): string[] => sync(pattern, { absolute: true });
const reduceFlatArray = (all: string[], next: string[]): string[] => all.concat(next);
const createWrapper = (filePath: string): SourceWrapper => ({ contents: readJsonSync(filePath), filePath });

export const getWrappers = (program: Options): SourceWrapper[] =>
(hasCliPatterns(program)
? getCliPatterns(program)
: getYarnPatterns() || getPnpmPatterns() || getLernaPatterns() || getDefaultPatterns()
)
(getCliPatterns(program) || getYarnPatterns() || getPnpmPatterns() || getLernaPatterns() || getDefaultPatterns())
.map(resolvePattern)
.reduce(reduceFlatArray, [])
.map(createWrapper);
2 changes: 1 addition & 1 deletion src/lib/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const getConfig = (program: Partial<SyncpackConfig>): SyncpackConfig => {
semverRange: getOption<ValidRange>('semverRange', isValidSemverRange),
sortAz: getOption<string[]>('sortAz', isArrayOfStrings),
sortFirst: getOption<string[]>('sortFirst', isArrayOfStrings),
source: getOption<string[]>('source', isArray),
source: getOption<string[]>('source', isArrayOfStrings),
versionGroups: getOption<VersionGroup[]>('versionGroups', isArrayOfVersionGroups),
};
};

0 comments on commit c2f6199

Please sign in to comment.