From 0bdabe465d63d2e229ceab361cf054ee08a554e8 Mon Sep 17 00:00:00 2001 From: Evan Carroll Date: Tue, 28 Sep 2021 13:52:21 -0500 Subject: [PATCH] feat: more conservative configuration detection * 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. --- lib/definitions/errors.js | 8 ++++++++ lib/get-config.js | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index c109f2afab..4c3d8a4225 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -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. diff --git a/lib/get-config.js b/lib/get-config.js index 6902752d0f..5a576fb3ee 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -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'; @@ -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};