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 (#3976)
  • Loading branch information
danielbayley authored Mar 15, 2024
1 parent 99cd49d commit 94eab40
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 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
8 changes: 8 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,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];

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
12 changes: 6 additions & 6 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

0 comments on commit 94eab40

Please sign in to comment.