-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ drop
yaml
config support to improve performance
BREAKING CHANGE: 💥 `yaml` configuration files are no longer supported
- Loading branch information
1 parent
a21ff75
commit 8248c06
Showing
5 changed files
with
17 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,15 @@ | ||
import type { Loader } from 'lilconfig' | ||
import { lilconfig } from 'lilconfig' | ||
import yaml from 'yaml' | ||
|
||
const loadYaml: Loader = (_filepath, content) => { | ||
return yaml.parse(content) | ||
} | ||
|
||
interface LoadConfigResult<T> { | ||
config: T | ||
filepath: string | ||
isEmpty?: boolean | ||
} | ||
|
||
const defaultSearchPlaces = (name: string): string[] => [ | ||
`.${name}rc`, | ||
`.${name}rc.json`, | ||
`.${name}rc.yaml`, | ||
`.${name}rc.yml`, | ||
`.${name}rc.js`, | ||
`.${name}rc.cjs`, | ||
`${name}.config.js`, | ||
`${name}.config.cjs`, | ||
] | ||
|
||
export const getSearchPlaces = (configName: string): string[] => [ | ||
'package.json', | ||
...defaultSearchPlaces(configName), | ||
...defaultSearchPlaces(configName).map( | ||
(searchPlace) => `.config/${searchPlace}` | ||
), | ||
] | ||
|
||
export const loadConfig = async <T>( | ||
configName: string | ||
): Promise<LoadConfigResult<T> | null> => { | ||
const explorer = lilconfig(configName, { | ||
searchPlaces: getSearchPlaces(configName), | ||
loaders: { | ||
'.yaml': loadYaml, | ||
'.yml': loadYaml, | ||
'noExt': loadYaml, | ||
}, | ||
}) | ||
const explorer = lilconfig(configName) | ||
|
||
return explorer.search(process.cwd()) | ||
} |