Skip to content

Commit

Permalink
feat: ✨ drop yaml config support to improve performance
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 💥 `yaml` configuration files are no longer supported
  • Loading branch information
jimmy-guzman committed Feb 16, 2024
1 parent a21ff75 commit 8248c06
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 82 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ $ gitzy -lD --no-emoji

# Configuration

By default `gitzy` comes ready to run out of the box but provides various configuration methods and options

You can use a `gitzy` object in your `package.json`, or the following files: `.gitzyrc`, `.gitzyrc.json`, `.gitzyrc.yaml`, `.gitzyrc.yml`, `.gitzyrc.js`, `.gitzyrc.cjs`, `gitzy.config.js`, or `gitzy.config.cjs`,

- _all the files can also live under a `.config/` directory_
By default `gitzy` comes ready to run out of the box but provides various configuration methods and options:

- `package.json`
- `.gitzyrc.json`
- `.gitzyrc.js`
- `.gitzyrc.cjs`
- `.config/gitzyrc`
- `.config/gitzyrc.json`
- `.config/gitzyrc.js`
- `.config/gitzyrc.cjs`
- `gitzy.config.js`
- `gitzy.config.cjs`

## Options

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
]
},
"dependencies": {
"lilconfig": "^2.0.4"
"lilconfig": "^2.1.0"
},
"devDependencies": {
"@comparto/prettier-config": "1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 2 additions & 42 deletions src/config/helpers/loadConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
import { access, unlinkSync, writeFile } from 'node:fs'

import { getSearchPlaces, loadConfig } from './loadConfig'

const expectedSearchPlaces = [
'package.json',
'.gitzyrc',
'.gitzyrc.json',
'.gitzyrc.yaml',
'.gitzyrc.yml',
'.gitzyrc.js',
'.gitzyrc.cjs',
'gitzy.config.js',
'gitzy.config.cjs',
'.config/.gitzyrc',
'.config/.gitzyrc.json',
'.config/.gitzyrc.yaml',
'.config/.gitzyrc.yml',
'.config/.gitzyrc.js',
'.config/.gitzyrc.cjs',
'.config/gitzy.config.js',
'.config/gitzy.config.cjs',
]
import { loadConfig } from './loadConfig'

describe('searchPlaces', () => {
afterEach(() => {
Expand All @@ -29,15 +9,8 @@ describe('searchPlaces', () => {
unlinkSync('.arc.json')
}
})
access('./.arc.yml', (error) => {
if (!error) {
unlinkSync('.arc.yml')
}
})
})
it('should return all search places', () => {
expect(getSearchPlaces('gitzy')).toStrictEqual(expectedSearchPlaces)
})

it('should return null if no config is found', async () => {
const config = await loadConfig('a')

Expand All @@ -57,17 +30,4 @@ describe('searchPlaces', () => {
filepath: `${process.cwd()}/.arc.json`,
})
})
it('should return config for yaml files', async () => {
writeFile('.arc.yml', 'disableEmoji: true', (error) => {
// eslint-disable-next-line jest/no-conditional-in-test
if (error) throw error
})

const config = await loadConfig('a')

expect(config).toStrictEqual({
config: { disableEmoji: true },
filepath: `${process.cwd()}/.arc.yml`,
})
})
})
34 changes: 1 addition & 33 deletions src/config/helpers/loadConfig.ts
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())
}

0 comments on commit 8248c06

Please sign in to comment.