Open carmanchris31 opened 3 years ago
The extends property in commitlint.config.js should resolve configs using es6-style default exports.
extends
commitlint.config.js
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:
commitlint
module.exports
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
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
c.default || c
default
module.exports = config
exports.default = config
commitlint --version
git --version
node --version
Thanks! Would you have the time to give that a try in a PR?
Expected Behavior
The
extends
property incommitlint.config.js
should resolve configs using es6-style default exports.Current Behavior
Currently,
commitlint
appears to only look atmodule.exports
as a whole, so if an exported config uses a es6-style default export like this:then presumably the config is resolved to something like:
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
: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 thedefault
export if it's present. This should allow compatibility for the oldmodule.exports = config
style and the newexports.default = config
style. https://github.com/conventional-changelog/commitlint/blob/12d0ca3dbff4d23c178c5fd99fc101d8aaf27e40/%40commitlint/resolve-extends/src/index.ts#L58Steps to Reproduce (for bugs)
commitlint.config.js
```js ```Context
Your Environment
commitlint --version
git --version
node --version