Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for .cjs config file #700

Open
steviss opened this issue Sep 26, 2023 · 0 comments
Open

Add support for .cjs config file #700

steviss opened this issue Sep 26, 2023 · 0 comments

Comments

@steviss
Copy link

steviss commented Sep 26, 2023

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 [email protected] 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant