Skip to content

Commit d079b25

Browse files
committed
fix(prepare): use correct version for prereleases
this fix requires that all `-` be replaced by `.` in the gem version to avoid version inconsistencies
1 parent db9aa06 commit d079b25

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/__tests__/prepare.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('when the version.rb contains a prerelease version', () => {
5555
expect(versionContents).toEqual(`# frozen_string_literal: true
5656
5757
module TestGem
58-
VERSION = '1.0.0-alpha.1'
58+
VERSION = '1.0.0.alpha.1'
5959
end
6060
`);
6161
});

src/__tests__/verifyConditions.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('when the gemspec has no name defined', () => {
4848
});
4949
});
5050

51-
it('finds the version file', async () => {
51+
it('verifies the version file', async () => {
5252
const { versionFile } = await verifyConditions(
5353
{},
5454
{ cwd: validCwd, env: defaultEnv },

src/prepare.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ const { VERSION_REGEX } = require('./common');
66
const writeVersion = async ({ versionFile, nextVersion, logger, cwd }) => {
77
const fullVersionPath = path.resolve(cwd, versionFile);
88
const versionContents = await readFile(fullVersionPath, 'utf8');
9-
const newContents = versionContents.replace(VERSION_REGEX, `$1${nextVersion}$2`);
9+
const newContents = versionContents.replace(
10+
VERSION_REGEX,
11+
// Rubygems replaces all `-` with `.pre.`, which causes odd version differences between tags/releases
12+
// and the published gem version. Replacing `-` with `.` is a smaller difference.
13+
`$1${nextVersion.replace('-', '.')}$2`,
14+
);
1015
logger.log('Writing version %s to `%s`', nextVersion, versionFile);
1116
await writeFile(fullVersionPath, newContents, 'utf8');
1217
};

0 commit comments

Comments
 (0)