Skip to content

Commit 04529e2

Browse files
authored
perf: replace cosmiconfig with lilconfig (#981)
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.
1 parent f861d8d commit 04529e2

File tree

8 files changed

+229
-170
lines changed

8 files changed

+229
-170
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Starting with v3.1 you can now use different ways of configuring lint-staged:
105105
- `lint-staged.config.js`, `.lintstagedrc.js`, or `.lintstagedrc.cjs` file in JS format
106106
- Pass a configuration file using the `--config` or `-c` flag
107107
108-
See [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for more details on what formats are supported.
108+
See [lilconfig](https://github.com/antonk52/lilconfig) for more details on what formats are supported.
109109
110110
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.
111111

lib/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

3-
const { cosmiconfig } = require('cosmiconfig')
3+
const { lilconfig } = require('lilconfig')
4+
const { yaml } = require('js-yaml')
45
const debugLog = require('debug')('lint-staged')
56
const stringifyObject = require('stringify-object')
67

@@ -24,8 +25,10 @@ const resolveConfig = (configPath) => {
2425
}
2526
}
2627

28+
const jsYamlLoad = (filepath, content) => yaml.load(content)
29+
2730
const loadConfig = (configPath) => {
28-
const explorer = cosmiconfig('lint-staged', {
31+
const explorer = lilconfig('lint-staged', {
2932
searchPlaces: [
3033
'package.json',
3134
'.lintstagedrc',
@@ -37,6 +40,11 @@ const loadConfig = (configPath) => {
3740
'lint-staged.config.js',
3841
'lint-staged.config.cjs',
3942
],
43+
loaders: {
44+
'.yml': jsYamlLoad,
45+
'.yaml': jsYamlLoad,
46+
noExt: jsYamlLoad,
47+
},
4048
})
4149

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

87-
debugLog('Loading config using `cosmiconfig`')
95+
debugLog('Loading config using `lilconfig`')
8896

8997
const resolved = configObject
9098
? { config: configObject, filepath: '(input)' }

0 commit comments

Comments
 (0)