Skip to content

Commit

Permalink
fix: retain semver symbols on snapshot update (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabrindle authored and GantMan committed Mar 15, 2018
1 parent 915b12e commit fe99160
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions __tests__/command_helpers/checkCLIForUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const rule = {
version: '--version',
}

const ruleTildeSemver = {
rule: 'cli',
binary: 'npm',
semver: '~5.6.0',
version: '--version',
}

const ruleNoSemver = {
rule: 'cli',
binary: 'yarn',
Expand Down Expand Up @@ -50,5 +57,14 @@ describe('checkCLIForUpdates', () => {
expect(result).toEqual(undefined)
expect(ruleNoSemver.semver).toBe(undefined)
})

it('copies semver ~ symbol if present', async () => {
context.solidarity = {
getVersion: jest.fn(() => '5.8'),
}

const result = await checkCLIForUpdates(ruleTildeSemver, context)
expect(result).toEqual("Setting npm to '~5.8'")
})
})
})
6 changes: 3 additions & 3 deletions src/extensions/functions/checkCLIForUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
binarySemantic += '.0'
}

// if it doesn't satisfy, upgrade
// if it doesn't satisfy, upgrade, and retain semver symbol
if (rule.semver && !semver.satisfies(binarySemantic, rule.semver)) {
rule.semver = binaryVersion
rule.semver = `${/\^|\~/.test(rule.semver) ? rule.semver.charAt(0) : ''}${binaryVersion}`
const lineMessage = rule.line ? ` line ${rule.line}` : ''
return print.colors.green(`Setting ${rule.binary}${lineMessage} to '${binaryVersion}'`)
return print.colors.green(`Setting ${rule.binary}${lineMessage} to '${rule.semver}'`)
}
}

0 comments on commit fe99160

Please sign in to comment.