Skip to content

Commit 94eab40

Browse files
authored
feat(load): update cosmiconfig to v9 to add support for package.yaml config (#3976)
1 parent 99cd49d commit 94eab40

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

Diff for: @commitlint/load/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@commitlint/resolve-extends": "^19.1.0",
5151
"@commitlint/types": "^19.0.3",
5252
"chalk": "^5.3.0",
53-
"cosmiconfig": "^8.3.6",
53+
"cosmiconfig": "^9.0.0",
5454
"cosmiconfig-typescript-loader": "^5.0.0",
5555
"lodash.isplainobject": "^4.0.6",
5656
"lodash.merge": "^4.6.2",

Diff for: @commitlint/load/src/load.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ describe.each([['basic'], ['extends']])('%s config', (template) => {
238238
'commitlint.config.js',
239239
'commitlint.config.mjs',
240240
'package.json',
241+
'package.yaml',
241242
'.commitlintrc',
242243
'.commitlintrc.cjs',
243244
'.commitlintrc.js',
@@ -274,6 +275,13 @@ describe.each([['basic'], ['extends']])('%s config', (template) => {
274275
readFileSync(configPath, {encoding: 'utf-8'})
275276
);
276277
return JSON.stringify({commitlint});
278+
} else if (filename === 'package.yaml') {
279+
const configPath = path.join(
280+
__dirname,
281+
`../fixtures/${template}-config/.commitlintrc.yaml`
282+
);
283+
const yaml = readFileSync(configPath, {encoding: 'utf-8'});
284+
return `commitlint:\n${yaml.replace(/^/gm, ' ')}`;
277285
} else {
278286
const filePath = ['..', 'fixtures', `${template}-config`, filename];
279287

Diff for: @commitlint/load/src/utils/load-config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface LoadConfigResult {
1616
}
1717

1818
const moduleName = 'commitlint';
19+
const searchStrategy = 'global';
1920

2021
export async function loadConfig(
2122
cwd: string,
@@ -37,10 +38,12 @@ export async function loadConfig(
3738
: defaultLoadersSync;
3839

3940
const explorer = cosmiconfig(moduleName, {
41+
searchStrategy,
4042
searchPlaces: [
4143
// cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files),
4244
// we need to manually merge default searchPlaces from https://github.com/davidtheclark/cosmiconfig#searchplaces
4345
'package.json',
46+
'package.yaml',
4447
`.${moduleName}rc`,
4548
`.${moduleName}rc.json`,
4649
`.${moduleName}rc.yaml`,

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ These can be modified by [your own configuration](#config).
113113
- `commitlint.config.ts`
114114
- `commitlint.config.cts`
115115
- `commitlint` field in `package.json`
116+
- `commitlint` field in [`package.yaml`](https://github.com/pnpm/pnpm/pull/1799)
116117
- Packages: [cli](./@commitlint/cli), [core](./@commitlint/core)
117118
- See [Rules](./docs/reference/rules.md) for a complete list of possible rules
118119
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/src/index.ts)

Diff for: docs/reference/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Configuration files are resolved using [cosmiconfig](https://github.com/cosmicon
2929

3030
## Config via `package.json`
3131

32-
You can add `commitlint` field in `package.json` with an object that follows below structure.
32+
You can add a `commitlint` field in `package.json` (or [`package.yaml`](https://github.com/pnpm/pnpm/pull/1799)) with an object that follows the below structure.
3333

3434
## Config option CLI
3535

Diff for: yarn.lock

+6-6
Original file line numberDiff line numberDiff line change
@@ -3417,15 +3417,15 @@ cosmiconfig@^7.0.0:
34173417
path-type "^4.0.0"
34183418
yaml "^1.10.0"
34193419

3420-
cosmiconfig@^8.3.6:
3421-
version "8.3.6"
3422-
resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz"
3423-
integrity sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==
3420+
cosmiconfig@^9.0.0:
3421+
version "9.0.0"
3422+
resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz#34c3fc58287b915f3ae905ab6dc3de258b55ad9d"
3423+
integrity sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==
34243424
dependencies:
3425+
env-paths "^2.2.1"
34253426
import-fresh "^3.3.0"
34263427
js-yaml "^4.1.0"
34273428
parse-json "^5.2.0"
3428-
path-type "^4.0.0"
34293429

34303430
cross-env@^7.0.3:
34313431
version "7.0.3"
@@ -3716,7 +3716,7 @@ entities@^4.5.0:
37163716
resolved "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48"
37173717
integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==
37183718

3719-
env-paths@^2.2.0:
3719+
env-paths@^2.2.0, env-paths@^2.2.1:
37203720
version "2.2.1"
37213721
resolved "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz"
37223722
integrity sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==

0 commit comments

Comments
 (0)