Skip to content

Commit

Permalink
fix: change files function to explicitly check sets size
Browse files Browse the repository at this point in the history
fix: change files function to explicitly check sets size
  • Loading branch information
eglavin committed Apr 18, 2024
2 parents 20be13b + bbe3b37 commit cce8489
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/config/user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,31 @@ export async function getUserConfig(): Promise<ForkConfig> {
...cliArguments.flags,
} as ForkConfig;

const files = mergeFiles(parsedConfig.data?.files, cliArguments.flags?.files);

return {
...usersConfig,
path: cwd,
files: files.length > 0 ? files : DEFAULT_CONFIG.files,
files: getFiles(parsedConfig.data?.files, cliArguments.flags?.files),
changelogPresetConfig: getChangelogPresetConfig(usersConfig?.changelogPresetConfig),
};
}

function mergeFiles(configFiles: string[] | undefined, cliFiles: string[] | undefined): string[] {
return Array.from(
new Set(
([] as string[]).concat(
Array.isArray(configFiles) ? configFiles : [],
Array.isArray(cliFiles) ? cliFiles : [],
),
),
);
function getFiles(configFiles: string[] | undefined, cliFiles: string[] | undefined): string[] {
const listOfFiles = new Set<string>();

// Add files from the users config file
if (Array.isArray(configFiles)) {
configFiles.forEach((file) => listOfFiles.add(file));
}

// Add files from the cli arguments
if (Array.isArray(cliFiles)) {
cliFiles.forEach((file) => listOfFiles.add(file));
}

// If the user has defined files use them, otherwise use the default list of files.
if (listOfFiles.size) {
return Array.from(listOfFiles);
}

return DEFAULT_CONFIG.files;
}
1 change: 1 addition & 0 deletions tests/create-test-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function createTestDir(testName: string) {
throw new Error(`Test folder already exists: ${testDir}`);
}

execSync("git config --global init.defaultBranch main", execSyncOptions);
execSync("git init", execSyncOptions);
execSync("git config commit.gpgSign false", execSyncOptions);
execSync("git config core.autocrlf false", execSyncOptions);
Expand Down

0 comments on commit cce8489

Please sign in to comment.