conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.8k stars 905 forks source link

`extends` support for es6-style default exports? #2405

Open carmanchris31 opened 3 years ago

carmanchris31 commented 3 years ago

Expected Behavior

The extends property in commitlint.config.js should resolve configs using es6-style default exports.

Current Behavior

Currently, commitlint appears to only look at module.exports as a whole, so if an exported config uses a es6-style default export like this:

Object.defineProperty(exports, "__esModule", { value: true });

var config = {/* rules, etc. */};

exports.default = config;

then presumably the config is resolved to something like:

{
  default: {/* rules, etc. */
}

and commitlint throws an error with: "Please add rules to your commitlint.config.js"

As a workaround we must do something like this in commitlint.config.js:

const {default: config} = require('path/to/module');

module.exports = config

Affected packages

Possible Solution

I'm not familiar with the codebase; however, I think at minimum there needs to be a c.default || c to unwrap the default export if it's present. This should allow compatibility for the old module.exports = config style and the new exports.default = config style. https://github.com/conventional-changelog/commitlint/blob/12d0ca3dbff4d23c178c5fd99fc101d8aaf27e40/%40commitlint/resolve-extends/src/index.ts#L58

Steps to Reproduce (for bugs)

  1. First step
  2. Second step
commitlint.config.js ```js ```

Context

Your Environment

Executable Version
commitlint --version 11.0.0
git --version 2.27.0
node --version 14.15.4
escapedcat commented 3 years ago

Thanks! Would you have the time to give that a try in a PR?