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

fix: Support cjs file in read-config-file. #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/read-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ const findConfig = require('find-config');
const path = require('path');
const log = require('./logger');

const readConfigFile = (CZ_CONFIG_NAME = '.cz-config.js') => {
function findConfigFile(CZ_CONFIG_NAME) {
const extensions = ['.js', '.cjs'];
let result = null;
extensions.some((ext) => {
const filename = findConfig.require(CZ_CONFIG_NAME + ext, { home: false });
if (filename !== null) {
result = filename;
return true;
}
return false;
});
return result;
}

const readConfigFile = (CZ_CONFIG_NAME = '.cz-config') => {
// First try to find the .cz-config.js config file
// It seems like find-config still locates config files in the home directory despite of the home:false prop.
const czConfig = findConfig.require(CZ_CONFIG_NAME, { home: false });
const czConfig = findConfigFile(CZ_CONFIG_NAME);

if (czConfig) {
return czConfig;
Expand All @@ -33,7 +47,7 @@ const readConfigFile = (CZ_CONFIG_NAME = '.cz-config.js') => {

/* istanbul ignore next */
log.error(
'Unable to find a configuration file. Please refer to documentation to learn how to set up: https://github.com/leonardoanalista/cz-customizable#steps "'
'Unable to find a configuration file. Please refer to documentation to learn how to set up: https://github.com/leonardoanalista/cz-customizable#steps "',
);
return null;
};
Expand Down
Loading