From fabb49509730609276ff9ef6357536c95a1f6bb1 Mon Sep 17 00:00:00 2001 From: Himanshu Mehta Date: Wed, 27 Oct 2021 15:24:36 +0530 Subject: [PATCH] feat(load): add support for `.commitlintrc.cjs` and `commitlint.config.cjs` files (#2797) * feat(load): add support for `*.cjs` files * chore(load): improve comment in searchPlaces * docs: update supported configs list in README.md Co-authored-by: Himanshu Mehta --- @commitlint/load/src/utils/load-config.ts | 10 ++++++++-- README.md | 13 ++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/@commitlint/load/src/utils/load-config.ts b/@commitlint/load/src/utils/load-config.ts index ee5759aaa3..5fb34d6f66 100644 --- a/@commitlint/load/src/utils/load-config.ts +++ b/@commitlint/load/src/utils/load-config.ts @@ -15,15 +15,21 @@ export async function loadConfig( const moduleName = 'commitlint'; const explorer = cosmiconfig(moduleName, { 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', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, - `.${moduleName}rc.ts`, `.${moduleName}rc.js`, - `${moduleName}.config.ts`, + `.${moduleName}rc.cjs`, `${moduleName}.config.js`, + `${moduleName}.config.cjs`, + + // files supported by TypescriptLoader + `.${moduleName}rc.ts`, + `${moduleName}.config.ts`, ], loaders: { '.ts': TypeScriptLoader, diff --git a/README.md b/README.md index dd07923535..c7b2525266 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,18 @@ Check the [husky documentation](https://typicode.github.io/husky/#/?id=manual) o ## Config -- Configuration is picked up from `commitlint.config.js`, `.commitlintrc.js`, `.commitlintrc`, `.commitlintrc.json`, `.commitlintrc.yml` file or a `commitlint` field in `package.json` +- Configuration is picked up from: + - `.commitlintrc` + - `.commitlintrc.json` + - `.commitlintrc.yaml` + - `.commitlintrc.yml` + - `.commitlintrc.js` + - `.commitlintrc.cjs` + - `.commitlintrc.ts` + - `commitlint.config.js` + - `commitlint.config.cjs` + - `commitlint.config.ts` + - `commitlint` field in `package.json` - 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/index.js)