Skip to content

Commit e035b80

Browse files
authoredOct 26, 2021
fix: revert back to cosmiconfig from lilconfig (#1035)
* Revert "fix: correctly import `js-yaml` to fix yaml config loading (#1033)" This reverts commit 612d806. * Revert "perf: replace `cosmiconfig` with `lilconfig` (#981)" This reverts commit 04529e2.
1 parent 612d806 commit e035b80

8 files changed

+170
-229
lines changed
 

‎README.md

+1-1
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 [lilconfig](https://github.com/antonk52/lilconfig) for more details on what formats are supported.
108+
See [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) 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

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

3-
const { lilconfig } = require('lilconfig')
4-
const yaml = require('js-yaml')
3+
const { cosmiconfig } = require('cosmiconfig')
54
const debugLog = require('debug')('lint-staged')
65
const stringifyObject = require('stringify-object')
76

@@ -25,10 +24,8 @@ const resolveConfig = (configPath) => {
2524
}
2625
}
2726

28-
const jsYamlLoad = (filepath, content) => yaml.load(content)
29-
3027
const loadConfig = (configPath) => {
31-
const explorer = lilconfig('lint-staged', {
28+
const explorer = cosmiconfig('lint-staged', {
3229
searchPlaces: [
3330
'package.json',
3431
'.lintstagedrc',
@@ -40,11 +37,6 @@ const loadConfig = (configPath) => {
4037
'lint-staged.config.js',
4138
'lint-staged.config.cjs',
4239
],
43-
loaders: {
44-
'.yml': jsYamlLoad,
45-
'.yaml': jsYamlLoad,
46-
noExt: jsYamlLoad,
47-
},
4840
})
4941

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

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

9789
const resolved = configObject
9890
? { config: configObject, filepath: '(input)' }

‎package-lock.json

+147-197
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
"cli-truncate": "2.1.0",
3131
"colorette": "^1.4.0",
3232
"commander": "^8.2.0",
33+
"cosmiconfig": "^7.0.1",
3334
"debug": "^4.3.2",
3435
"enquirer": "^2.3.6",
3536
"execa": "^5.1.1",
36-
"js-yaml": "^4.1.0",
37-
"lilconfig": "^2.0.3",
3837
"listr2": "^3.12.2",
3938
"micromatch": "^4.0.4",
4039
"normalize-path": "^3.0.0",

‎test/__mocks__/cosmiconfig.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const actual = jest.requireActual('cosmiconfig')
2+
3+
function cosmiconfig(name, options) {
4+
return actual.cosmiconfig(name, options)
5+
}
6+
7+
module.exports.cosmiconfig = jest.fn(cosmiconfig)

‎test/__mocks__/lilconfig.js

-7
This file was deleted.

‎test/index.spec.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lilconfig } from 'lilconfig'
1+
import { cosmiconfig } from 'cosmiconfig'
22
import makeConsoleMock from 'consolemock'
33
import path from 'path'
44

@@ -14,8 +14,8 @@ import { InvalidOptionsError } from '../lib/symbols'
1414
import validateOptions from '../lib/validateOptions'
1515
import { replaceSerializer } from './utils/replaceSerializer'
1616

17-
const mockLilconfigWith = (result) => {
18-
lilconfig.mockImplementationOnce(() => ({
17+
const mockCosmiconfigWith = (result) => {
18+
cosmiconfig.mockImplementationOnce(() => ({
1919
search: () => Promise.resolve(result),
2020
}))
2121
}
@@ -33,11 +33,11 @@ describe('lintStaged', () => {
3333
logger.clearHistory()
3434
})
3535

36-
it('should use lilconfig if no params are passed', async () => {
36+
it('should use cosmiconfig if no params are passed', async () => {
3737
expect.assertions(1)
3838

3939
const config = { '*': 'mytask' }
40-
mockLilconfigWith({ config })
40+
mockCosmiconfigWith({ config })
4141

4242
await lintStaged(undefined, logger)
4343

@@ -60,7 +60,7 @@ describe('lintStaged', () => {
6060
it('should use use the console if no logger is passed', async () => {
6161
expect.assertions(2)
6262

63-
mockLilconfigWith({ config: {} })
63+
mockCosmiconfigWith({ config: {} })
6464

6565
const previousConsole = console
6666
const mockedConsole = makeConsoleMock()
@@ -79,7 +79,7 @@ describe('lintStaged', () => {
7979
expect.assertions(1)
8080

8181
const config = { '*': 'mytask' }
82-
mockLilconfigWith({ config })
82+
mockCosmiconfigWith({ config })
8383

8484
await lintStaged({ debug: true, quiet: true }, logger)
8585

@@ -96,7 +96,7 @@ describe('lintStaged', () => {
9696
expect.assertions(1)
9797

9898
const config = { '*': 'mytask' }
99-
mockLilconfigWith({ config })
99+
mockCosmiconfigWith({ config })
100100

101101
await lintStaged({ quiet: true }, logger)
102102

@@ -119,7 +119,7 @@ describe('lintStaged', () => {
119119

120120
it('should throw when invalid config is provided', async () => {
121121
const config = {}
122-
mockLilconfigWith({ config })
122+
mockCosmiconfigWith({ config })
123123

124124
await expect(lintStaged({ quiet: true }, logger)).rejects.toMatchInlineSnapshot(
125125
`[Error: Configuration should not be empty!]`
@@ -200,7 +200,7 @@ describe('lintStaged', () => {
200200
it('should print helpful error message when config file is not found', async () => {
201201
expect.assertions(2)
202202

203-
mockLilconfigWith(null)
203+
mockCosmiconfigWith(null)
204204

205205
await expect(lintStaged({ quiet: true }, logger)).rejects.toMatchInlineSnapshot(
206206
`[Error: Config could not be found]`

‎test/integration.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ansiSerializer from 'jest-snapshot-serializer-ansi'
44
import normalize from 'normalize-path'
55
import path from 'path'
66

7-
jest.unmock('lilconfig')
7+
jest.unmock('cosmiconfig')
88
jest.unmock('execa')
99

1010
import execGitBase from '../lib/execGit'

0 commit comments

Comments
 (0)
Please sign in to comment.