Skip to content

Commit

Permalink
fix(semantic-release): Move provider logic from setup to run
Browse files Browse the repository at this point in the history
This avoids doing git commands on every invocation of any spire command
  • Loading branch information
danez committed May 12, 2020
1 parent a08d97f commit dba578a
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions packages/spire-plugin-semantic-release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const execa = require('execa');
const SpireError = require('spire/error');

function semanticRelease(
{ setState, getState, hasFile, hasPackageProp, getProvider },
{ hasFile, hasPackageProp, getProvider },
{
command = 'release',
provider = 'auto',
Expand All @@ -22,7 +22,15 @@ function semanticRelease(
name: 'spire-plugin-semantic-release',
command,
description: 'run semantic-release',
async setup({ resolve }) {
async setup() {
// Inform user about disallowed overrides
if ((await hasCustomConfig()) && !allowCustomConfig) {
throw new SpireError(
`Custom semantic-release config is not allowed, using ${defaultSemanticReleaseConfig} instead`
);
}
},
async run({ options, cwd, logger, resolve }) {
let semanticReleaseArgs = [];
let semanticReleaseConfigFile = defaultSemanticReleaseConfig;
const customConfig = await hasCustomConfig();
Expand All @@ -41,19 +49,6 @@ function semanticRelease(
semanticReleaseArgs = ['--extends', resolve(semanticReleaseConfigFile)];
}

setState({
semanticReleaseArgs,
});

// Inform user about disallowed overrides
if (customConfig && !allowCustomConfig) {
throw new SpireError(
`Custom semantic-release config is not allowed, using ${defaultSemanticReleaseConfig} instead`
);
}
},
async run({ options, cwd, logger }) {
const { semanticReleaseArgs } = getState();
const [, ...userProvidedArgs] = options._;
const finalSemanticReleaseArgs = [
...semanticReleaseArgs,
Expand Down

0 comments on commit dba578a

Please sign in to comment.