diff --git a/@commitlint/load/package.json b/@commitlint/load/package.json index 99dc37cf05..9723626fc1 100644 --- a/@commitlint/load/package.json +++ b/@commitlint/load/package.json @@ -50,7 +50,7 @@ "@commitlint/resolve-extends": "^19.1.0", "@commitlint/types": "^19.0.3", "chalk": "^5.3.0", - "cosmiconfig": "^8.3.6", + "cosmiconfig": "^9.0.0", "cosmiconfig-typescript-loader": "^5.0.0", "lodash.isplainobject": "^4.0.6", "lodash.merge": "^4.6.2", diff --git a/@commitlint/load/src/load.test.ts b/@commitlint/load/src/load.test.ts index fbf1d84ddd..129c1944ed 100644 --- a/@commitlint/load/src/load.test.ts +++ b/@commitlint/load/src/load.test.ts @@ -238,6 +238,7 @@ describe.each([['basic'], ['extends']])('%s config', (template) => { 'commitlint.config.js', 'commitlint.config.mjs', 'package.json', + 'package.yaml', '.commitlintrc', '.commitlintrc.cjs', '.commitlintrc.js', @@ -274,6 +275,13 @@ describe.each([['basic'], ['extends']])('%s config', (template) => { readFileSync(configPath, {encoding: 'utf-8'}) ); return JSON.stringify({commitlint}); + } else if (filename === 'package.yaml') { + const configPath = path.join( + __dirname, + `../fixtures/${template}-config/.commitlintrc.yaml` + ); + const yaml = readFileSync(configPath, {encoding: 'utf-8'}); + return `commitlint:\n${yaml.replace(/^/gm, ' ')}`; } else { const filePath = ['..', 'fixtures', `${template}-config`, filename]; diff --git a/@commitlint/load/src/utils/load-config.ts b/@commitlint/load/src/utils/load-config.ts index a5624620ff..34a8af8039 100644 --- a/@commitlint/load/src/utils/load-config.ts +++ b/@commitlint/load/src/utils/load-config.ts @@ -16,6 +16,7 @@ export interface LoadConfigResult { } const moduleName = 'commitlint'; +const searchStrategy = 'global'; export async function loadConfig( cwd: string, @@ -37,10 +38,12 @@ export async function loadConfig( : defaultLoadersSync; const explorer = cosmiconfig(moduleName, { + searchStrategy, searchPlaces: [ // cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files), // we need to manually merge default searchPlaces from https://github.com/davidtheclark/cosmiconfig#searchplaces 'package.json', + 'package.yaml', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, diff --git a/README.md b/README.md index 7786086b48..7fc5051651 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ These can be modified by [your own configuration](#config). - `commitlint.config.ts` - `commitlint.config.cts` - `commitlint` field in `package.json` + - `commitlint` field in [`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) - Packages: [cli](./@commitlint/cli), [core](./@commitlint/core) - See [Rules](./docs/reference/rules.md) for a complete list of possible rules - An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/src/index.ts) diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index c77d695cb2..94ec728c7f 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -29,7 +29,7 @@ Configuration files are resolved using [cosmiconfig](https://github.com/cosmicon ## Config via `package.json` -You can add `commitlint` field in `package.json` with an object that follows below structure. +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. ## Config option CLI diff --git a/yarn.lock b/yarn.lock index 11b8266534..db433b93fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3417,15 +3417,15 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" -cosmiconfig@^8.3.6: - version "8.3.6" - resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz" - integrity sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA== +cosmiconfig@^9.0.0: + version "9.0.0" + resolved "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz#34c3fc58287b915f3ae905ab6dc3de258b55ad9d" + integrity sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg== dependencies: + env-paths "^2.2.1" import-fresh "^3.3.0" js-yaml "^4.1.0" parse-json "^5.2.0" - path-type "^4.0.0" cross-env@^7.0.3: version "7.0.3" @@ -3716,7 +3716,7 @@ entities@^4.5.0: resolved "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48" integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw== -env-paths@^2.2.0: +env-paths@^2.2.0, env-paths@^2.2.1: version "2.2.1" resolved "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz" integrity sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A== @@ -7627,14 +7627,7 @@ string_decoder@^1.1.1, string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==