Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions scripts/get-release-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,24 @@ function getPreviewVersion(args) {
);
releaseVersion = overrideVersion;
} else if (tagResult) {
releaseVersion =
tagResult.latestVersion.replace(/-nightly.*/, '') + '-preview.0';
let baseVersion = tagResult.latestVersion.replace(/-nightly.*/, '');
// When the nightly base is already published as stable, the preview must
// target the next patch — otherwise the scheduled Tuesday release derives
// a version whose channel packages already exist on npm (E403).
const latestStable = getVersionFromNPM('latest');
if (
latestStable &&
semver.valid(latestStable) &&
semver.valid(baseVersion) &&
semver.gte(latestStable, baseVersion)
) {
const bumped = semver.inc(latestStable, 'patch');
console.error(
`Nightly base ${baseVersion} already released as stable (${latestStable}); bumping preview base to ${bumped}.`,
);
baseVersion = bumped;
}
releaseVersion = baseVersion + '-preview.0';
validateVersion(
releaseVersion,
'X.Y.Z-preview.N',
Expand Down
17 changes: 17 additions & 0 deletions scripts/tests/get-release-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ describe('getVersion', () => {
expect(result.previousReleaseTag).toBe('v0.6.1');
});

it.each([
['matches', '0.8.0', '0.8.1-preview.0'],
['is ahead of', '0.9.0', '0.9.1-preview.0'],
])(
'should bump the preview base when the latest stable %s it',
(_, latestStable, expected) => {
vi.mocked(execSync).mockImplementation((command) => {
if (command.includes('npm view') && command.includes('--tag=latest'))
return latestStable;
return mockExecSync(command);
});

const result = getVersion({ type: 'preview' });
expect(result.releaseVersion).toBe(expected);
},
);

it('should calculate the next nightly version from package.json', () => {
vi.mocked(execSync).mockImplementation(mockExecSync);
const result = getVersion({ type: 'nightly' });
Expand Down
Loading