Skip to content

Add support for .cjs config file #700

Description

@steviss

Hey,

I was configuring a new project today and I decided to consolidate all the configuration files, using a .cjs extension. While using your package I noticed I could not get the config file running as a .cjs file.

But this was easily fixed by adding one line in the src/config.ts file.

Today I used patch-package to patch jira-prepare-commit-msg@1.7.2 so it's doable on my personal project.

Here is the difference that solved my problem:

diff --git a/node_modules/jira-prepare-commit-msg/bin/config.js b/node_modules/jira-prepare-commit-msg/bin/config.js
index b51d947..b268a2a 100644
--- a/node_modules/jira-prepare-commit-msg/bin/config.js
+++ b/node_modules/jira-prepare-commit-msg/bin/config.js
@@ -33,6 +33,7 @@ async function loadConfig(configPath) {
                 '.jirapreparecommitmsgrc.yaml',
                 '.jirapreparecommitmsgrc.yml',
                 'jira-prepare-commit-msg.config.js',
+                'jira-prepare-commit-msg.config.cjs',
             ],
         });
         const config = configPath ? await explorer.load(resolveConfig(configPath)) : await explorer.search();

For context, if somebody else wants to use this as well:

This is my working jira-prepare-commit-msg.config.cjs file:

const config = {
  messagePattern: '[$J] $M',
  jiraTicketPattern: '([A-Z]+-\\d+)',
  isConventionalCommit: true,
  conventionalCommitPattern: '^([a-z]+)(\\([a-z0-9.,-_ ]+\\))?!?: ([\\w \\S]+)$',
  allowEmptyCommitMessage: false,
  allowReplaceAllOccurrences: true,
  ignoredBranchesPattern: '^(master|main|dev|develop|development|release)$',
  ignoreBranchesMissingTickets: false,
}

module.exports = config

I went into the node_modules folder and edited the node_modules\jira-prepare-commit-msg\bin\config.js file with the code listed above. After that, I ran yarn patch-package jira-prepare-commit-msg. (Please note, you will have to install patch-package and postinstall -> yarn add -D patch-package postinstall)

I also added "postinstall": "patch-package" to scripts in my package.json file so the patch is applied every time somebody installs the project on their own environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions