diff --git a/bin/semantic-release.js b/bin/semantic-release.js index cbd697e9..407475da 100755 --- a/bin/semantic-release.js +++ b/bin/semantic-release.js @@ -3,7 +3,7 @@ // Bad news: We have to write plain ES5 in this file // Good news: It's the only file of the entire project -/* eslint-disable no-var, promise/prefer-await-to-then, prefer-destructuring */ +/* eslint-disable no-var */ var semver = require('semver'); var execa = require('execa'); diff --git a/cli.js b/cli.js index 9d7e03a3..d8780d7f 100755 --- a/cli.js +++ b/cli.js @@ -1,4 +1,4 @@ -const {argv, env, stderr} = require('process'); +const {argv, env, stderr} = require('process'); // eslint-disable-line node/prefer-global/process const util = require('util'); const hideSensitive = require('./lib/hide-sensitive'); @@ -51,12 +51,14 @@ Usage: // Debug must be enabled before other requires in order to work require('debug').enable('semantic-release:*'); } + await require('.')(opts); return 0; } catch (error) { if (error.name !== 'YError') { stderr.write(hideSensitive(env)(util.inspect(error, {colors: true}))); } + return 1; } }; diff --git a/index.js b/index.js index 8a77527a..2ccd5d78 100644 --- a/index.js +++ b/index.js @@ -52,6 +52,7 @@ async function run(context, plugins) { ); return false; } + logger[options.dryRun ? 'warn' : 'success']( `Run automated release from branch ${ciBranch}${options.dryRun ? ' in dry-run mode' : ''}` ); @@ -70,6 +71,7 @@ async function run(context, plugins) { ); return false; } + throw error; } } catch (error) { @@ -92,6 +94,7 @@ async function run(context, plugins) { logger.log('There are no relevant changes, so no new version is released.'); return false; } + context.nextRelease = nextRelease; nextRelease.version = getNextVersion(context); nextRelease.gitTag = template(options.tagFormat)({version: nextRelease.version}); diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 96945df3..69c2fb22 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -1,10 +1,9 @@ -const url = require('url'); const {inspect} = require('util'); const {toLower, isString} = require('lodash'); const pkg = require('../../package.json'); const {RELEASE_TYPE} = require('./constants'); -const homepage = url.format({...url.parse(pkg.homepage), hash: null}); +const [homepage] = pkg.homepage.split('#'); const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5})); const linkify = file => `${homepage}/blob/master/${file}`; diff --git a/lib/definitions/plugins.js b/lib/definitions/plugins.js index e8e01a31..3d4478a9 100644 --- a/lib/definitions/plugins.js +++ b/lib/definitions/plugins.js @@ -59,6 +59,7 @@ module.exports = { // Regenerate the release notes context.nextRelease.notes = await generateNotes(context); } + // Call the next prepare plugin with the updated `nextRelease` return context; }, diff --git a/lib/get-config.js b/lib/get-config.js index 9cf34e0d..1745eaf1 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -30,6 +30,7 @@ module.exports = async (context, opts) => { if (options.ci === false) { options.noCi = true; } + const pluginsPath = {}; let extendPaths; ({extends: extendPaths, ...options} = options); diff --git a/lib/get-git-auth-url.js b/lib/get-git-auth-url.js index f3210bd5..10bdda1d 100644 --- a/lib/get-git-auth-url.js +++ b/lib/get-git-auth-url.js @@ -1,4 +1,4 @@ -const {parse, format} = require('url'); +const {parse, format} = require('url'); // eslint-disable-line node/no-deprecated-api const {isNil} = require('lodash'); const hostedGitInfo = require('hosted-git-info'); const {verifyAuth} = require('./git'); diff --git a/lib/plugins/index.js b/lib/plugins/index.js index abbc754c..51b080d1 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -57,10 +57,12 @@ module.exports = (context, pluginsPath) => { plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin ); } + if (!validateStep({required}, options[type])) { errors.push(getError('EPLUGINCONF', {type, required, pluginConf: options[type]})); return pluginsConf; } + pluginOpts = options[type]; } diff --git a/lib/plugins/normalize.js b/lib/plugins/normalize.js index 56af5b68..b35f3370 100644 --- a/lib/plugins/normalize.js +++ b/lib/plugins/normalize.js @@ -40,9 +40,11 @@ module.exports = (context, type, pluginOpt, pluginsPath) => { if (outputValidator && !outputValidator(result)) { throw getError(`E${type.toUpperCase()}OUTPUT`, {result, pluginName}); } + logger.success(`Completed step "${type}" of plugin "${pluginName}"`); return result; } + logger.warn(`Skip step "${type}" of plugin "${pluginName}" in dry-run mode`); } catch (error) { logger.error(`Failed step "${type}" of plugin "${pluginName}"`); diff --git a/lib/plugins/pipeline.js b/lib/plugins/pipeline.js index d36c8608..b12f264e 100644 --- a/lib/plugins/pipeline.js +++ b/lib/plugins/pipeline.js @@ -44,6 +44,7 @@ module.exports = (steps, {settleAll = false, getNextInput = identity, transform throw error; } } + // Prepare input for the next step, passing the input of the last iteration (or initial parameter for the first iteration) and the result of the current one return getNextInput(lastInput, result); }, @@ -52,5 +53,6 @@ module.exports = (steps, {settleAll = false, getNextInput = identity, transform if (errors.length > 0) { throw new AggregateError(errors); } + return results; }; diff --git a/lib/plugins/utils.js b/lib/plugins/utils.js index 2a213400..e0cf759f 100644 --- a/lib/plugins/utils.js +++ b/lib/plugins/utils.js @@ -12,6 +12,7 @@ const validateSteps = conf => { ) { return true; } + conf = castArray(conf); if (conf.length !== 1) { @@ -39,6 +40,7 @@ function validateStep({required}, conf) { if (required) { return conf.length >= 1 && validateSteps(conf); } + return conf.length === 0 || validateSteps(conf); } @@ -59,6 +61,7 @@ function parseConfig(plugin) { } else { path = plugin; } + return [path, config || {}]; } diff --git a/package.json b/package.json index 5f34f4ef..82b10ac5 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "sinon": "^7.1.1", "stream-buffers": "^3.0.2", "tempy": "^0.2.1", - "xo": "^0.23.0" + "xo": "^0.24.0" }, "engines": { "node": ">=8.3"