Skip to content

Commit fabb495

Browse files
himanshumehta1114Himanshu Mehta
and
Himanshu Mehta
authored
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 <[email protected]>
1 parent 7841a5d commit fabb495

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ export async function loadConfig(
1515
const moduleName = 'commitlint';
1616
const explorer = cosmiconfig(moduleName, {
1717
searchPlaces: [
18+
// cosmiconfig overrides default searchPlaces if any new search place is added (For e.g. `*.ts` files),
19+
// we need to manually merge default searchPlaces from https://github.com/davidtheclark/cosmiconfig#searchplaces
1820
'package.json',
1921
`.${moduleName}rc`,
2022
`.${moduleName}rc.json`,
2123
`.${moduleName}rc.yaml`,
2224
`.${moduleName}rc.yml`,
23-
`.${moduleName}rc.ts`,
2425
`.${moduleName}rc.js`,
25-
`${moduleName}.config.ts`,
26+
`.${moduleName}rc.cjs`,
2627
`${moduleName}.config.js`,
28+
`${moduleName}.config.cjs`,
29+
30+
// files supported by TypescriptLoader
31+
`.${moduleName}rc.ts`,
32+
`${moduleName}.config.ts`,
2733
],
2834
loaders: {
2935
'.ts': TypeScriptLoader,

Diff for: README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,18 @@ Check the [husky documentation](https://typicode.github.io/husky/#/?id=manual) o
124124

125125
## Config
126126

127-
- Configuration is picked up from `commitlint.config.js`, `.commitlintrc.js`, `.commitlintrc`, `.commitlintrc.json`, `.commitlintrc.yml` file or a `commitlint` field in `package.json`
127+
- Configuration is picked up from:
128+
- `.commitlintrc`
129+
- `.commitlintrc.json`
130+
- `.commitlintrc.yaml`
131+
- `.commitlintrc.yml`
132+
- `.commitlintrc.js`
133+
- `.commitlintrc.cjs`
134+
- `.commitlintrc.ts`
135+
- `commitlint.config.js`
136+
- `commitlint.config.cjs`
137+
- `commitlint.config.ts`
138+
- `commitlint` field in `package.json`
128139
- Packages: [cli](./@commitlint/cli), [core](./@commitlint/core)
129140
- See [Rules](./docs/reference-rules.md) for a complete list of possible rules
130141
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/index.js)

0 commit comments

Comments
 (0)