Skip to content

Commit

Permalink
fix(prepare): use correct version for prereleases
Browse files Browse the repository at this point in the history
this fix requires that all `-` be replaced by `.` in the gem version to avoid version inconsistencies
  • Loading branch information
rylanc committed Jul 22, 2020
1 parent db9aa06 commit d079b25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('when the version.rb contains a prerelease version', () => {
expect(versionContents).toEqual(`# frozen_string_literal: true
module TestGem
VERSION = '1.0.0-alpha.1'
VERSION = '1.0.0.alpha.1'
end
`);
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/verifyConditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('when the gemspec has no name defined', () => {
});
});

it('finds the version file', async () => {
it('verifies the version file', async () => {
const { versionFile } = await verifyConditions(
{},
{ cwd: validCwd, env: defaultEnv },
Expand Down
7 changes: 6 additions & 1 deletion src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const { VERSION_REGEX } = require('./common');
const writeVersion = async ({ versionFile, nextVersion, logger, cwd }) => {
const fullVersionPath = path.resolve(cwd, versionFile);
const versionContents = await readFile(fullVersionPath, 'utf8');
const newContents = versionContents.replace(VERSION_REGEX, `$1${nextVersion}$2`);
const newContents = versionContents.replace(
VERSION_REGEX,
// Rubygems replaces all `-` with `.pre.`, which causes odd version differences between tags/releases
// and the published gem version. Replacing `-` with `.` is a smaller difference.
`$1${nextVersion.replace('-', '.')}$2`,
);
logger.log('Writing version %s to `%s`', nextVersion, versionFile);
await writeFile(fullVersionPath, newContents, 'utf8');
};
Expand Down

0 comments on commit d079b25

Please sign in to comment.