Skip to content

Commit

Permalink
feat: more conservative configuration detection
Browse files Browse the repository at this point in the history
* Make a loud debug message if there is no configuration file found
* Throw an error if there is a configuration file but it is empty. This
  can happen if you misspell modules.exports as module.export and you
  use a .js file.
  • Loading branch information
EvanCarroll committed Sep 28, 2021
1 parent c35ecd8 commit 0bdabe4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/definitions/errors.js
Expand Up @@ -11,6 +11,14 @@ const wordsList = (words) =>
`${words.slice(0, -1).join(', ')}${words.length > 1 ? ` or ${words[words.length - 1]}` : trim(words[0])}`;

module.exports = {
ECONFIGNOTFOUND: () => ({
message: 'Your release configuration file was NOT found',
details: `We could not found a config file, proceeding with only the defaults`,
}),
EEMPTYCONFIG: ({filepath}) => ({
message: 'Your release configuration was found but has no contents',
details: `Please verify your config file ${filepath} is present with content`,
}),
ENOGITREPO: ({cwd}) => ({
message: 'Not running from a git repository.',
details: `The \`semantic-release\` command must be executed from a Git repository.
Expand Down
9 changes: 9 additions & 0 deletions lib/get-config.js
Expand Up @@ -7,6 +7,7 @@ const {repoUrl} = require('./git');
const PLUGINS_DEFINITIONS = require('./definitions/plugins');
const plugins = require('./plugins');
const {validatePlugin, parseConfig} = require('./plugins/utils');
const getError = require('./get-error');

const CONFIG_NAME = 'release';

Expand Down Expand Up @@ -36,6 +37,14 @@ const DEFAULTS = {
module.exports = async (context, cliOptions) => {
const {cwd, env} = context;
const {config, filepath} = (await cosmiconfig(CONFIG_NAME).search(cwd)) || {};

if ( filepath === undefined ) {
debug( getError('ECONFIGNOTFOUND') );
}
// Will trigger if the file is .js but doesn't set modules.exports
else if ( Object.prototype.constructor.keys(config||{}).length == 0 ) {
throw getError('EEMPTYCONFIG', {filepath});
}

// Merge config file options and CLI/API options
let options = {...config, ...cliOptions};
Expand Down

0 comments on commit 0bdabe4

Please sign in to comment.