Skip to content

Commit

Permalink
feat(load): update cosmiconfig to v9 to add support for `package.yaml…
Browse files Browse the repository at this point in the history
…` config
  • Loading branch information
danielbayley committed Mar 14, 2024
1 parent 207d2c0 commit acc8e8d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion @commitlint/load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions @commitlint/load/src/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -274,6 +275,15 @@ 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];

Expand Down
3 changes: 3 additions & 0 deletions @commitlint/load/src/utils/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface LoadConfigResult {
}

const moduleName = 'commitlint';
const searchStrategy = 'global';

export async function loadConfig(
cwd: string,
Expand All @@ -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`,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 7 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit acc8e8d

Please sign in to comment.