Skip to content
Permalink
Browse files
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.
  • Loading branch information
NickKaramoff committed Oct 23, 2021
1 parent f861d8d commit 04529e2b9040adc54cc8e5efc66b95bc0023477c
Showing with 229 additions and 170 deletions.
  1. +1 βˆ’1 README.md
  2. +11 βˆ’3 lib/index.js
  3. +197 βˆ’147 package-lock.json
  4. +2 βˆ’1 package.json
  5. +0 βˆ’7 test/__mocks__/cosmiconfig.js
  6. +7 βˆ’0 test/__mocks__/lilconfig.js
  7. +10 βˆ’10 test/index.spec.js
  8. +1 βˆ’1 test/integration.test.js
@@ -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.
@@ -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')

@@ -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',
@@ -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()
@@ -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)' }
Loading

0 comments on commit 04529e2

Please sign in to comment.