Skip to content

extends support for es6-style default exports? #2405

Open
@carmanchris31

Description

@carmanchris31

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

  • cli
  • core
  • prompt
  • config-angular

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.

const c = load(resolved);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions