Skip to content

Commit

Permalink
perf: replace cosmiconfig with lilconfig (#981)
Browse files Browse the repository at this point in the history
Replace 'cosmiconfig' with 'lilconfig' due to the smaller size and
dependency tree of the latter package. This also installs 'js-yaml',
since 'lilconfig' doesn't provide YAML parsing.
  • Loading branch information
kytta authored Oct 23, 2021
1 parent f861d8d commit 04529e2
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 170 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Starting with v3.1 you can now use different ways of configuring lint-staged:
- `lint-staged.config.js`, `.lintstagedrc.js`, or `.lintstagedrc.cjs` file in JS format
- Pass a configuration file using the `--config` or `-c` flag
See [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for more details on what formats are supported.
See [lilconfig](https://github.com/antonk52/lilconfig) for more details on what formats are supported.
Configuration should be an object where each value is a command to run and its key is a glob pattern to use for this command. This package uses [micromatch](https://github.com/micromatch/micromatch) for glob patterns.
Expand Down
14 changes: 11 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const { cosmiconfig } = require('cosmiconfig')
const { lilconfig } = require('lilconfig')
const { yaml } = require('js-yaml')
const debugLog = require('debug')('lint-staged')
const stringifyObject = require('stringify-object')

Expand All @@ -24,8 +25,10 @@ const resolveConfig = (configPath) => {
}
}

const jsYamlLoad = (filepath, content) => yaml.load(content)

const loadConfig = (configPath) => {
const explorer = cosmiconfig('lint-staged', {
const explorer = lilconfig('lint-staged', {
searchPlaces: [
'package.json',
'.lintstagedrc',
Expand All @@ -37,6 +40,11 @@ const loadConfig = (configPath) => {
'lint-staged.config.js',
'lint-staged.config.cjs',
],
loaders: {
'.yml': jsYamlLoad,
'.yaml': jsYamlLoad,
noExt: jsYamlLoad,
},
})

return configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()
Expand Down Expand Up @@ -84,7 +92,7 @@ const lintStaged = async (
) => {
await validateOptions({ shell }, logger)

debugLog('Loading config using `cosmiconfig`')
debugLog('Loading config using `lilconfig`')

const resolved = configObject
? { config: configObject, filepath: '(input)' }
Expand Down
Loading

0 comments on commit 04529e2

Please sign in to comment.