Skip to content

Commit

Permalink
feat(load): add support for .commitlintrc.cjs and `commitlint.confi…
Browse files Browse the repository at this point in the history
…g.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 <himanshu.mehta@go-jek.com>
  • Loading branch information
himanshumehta1114 and Himanshu Mehta committed Oct 27, 2021
1 parent 7841a5d commit fabb495
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 8 additions & 2 deletions @commitlint/load/src/utils/load-config.ts
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -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`

This comment has been minimized.

Copy link
@Mouvedia

Mouvedia Aug 18, 2022

Contributor

.cjs but not the pendant .mjs, interesting

This comment has been minimized.

Copy link
@escapedcat

escapedcat Aug 18, 2022

Member

I believe all this comes via https://github.com/davidtheclark/cosmiconfig
If you're missign .mjs have a look if this is already supported or what needs to be done to support it.

This comment has been minimized.

Copy link
@Mouvedia

Mouvedia Aug 18, 2022

Contributor

It requires a "custom loader".

This comment has been minimized.

Copy link
@escapedcat

escapedcat Aug 18, 2022

Member

I guess commitlint would need one. Like we do with TS I believe.

- `.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)
Expand Down

0 comments on commit fabb495

Please sign in to comment.