Skip to content

Commit

Permalink
♻️ Update resolveConfigFileName to utilize find().
Browse files Browse the repository at this point in the history
This makes the `resolveConfigFileName` method utilize `find()` on an array of possible file names, rather than wonky `if` logic.

Co-authored-by: Cody Kaup <[email protected]>
  • Loading branch information
jwir3 and codykaup authored Nov 6, 2024
1 parent c4086bf commit 2ff92c0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions node-src/lib/getConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ const configurationSchema = z
export type Configuration = z.infer<typeof configurationSchema>;

function resolveConfigFileName(configFile?: string): string {
let usedConfigFile = configFile || 'chromatic.config.json';
if (!configFile && !existsSync(usedConfigFile) && existsSync('chromatic.config.jsonc')) {
usedConfigFile = 'chromatic.config.jsonc';
}
const usedConfigFile = [configFile, 'chromatic.config.json', 'chromatic.config.jsonc'].find(
(f?: string) => f && existsSync(f)
);

return usedConfigFile;
return usedConfigFile || 'chromatic.config.json';
}

/**
* Parse configuration details from a local config file (typically chromatic.config.json, but can
* also use the JSON5 .jsonc extension. If both files are present, then the .json will take
Expand Down

0 comments on commit 2ff92c0

Please sign in to comment.