Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 24 additions & 2 deletions scripts/get-release-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,30 @@ 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)
) {
if (semver.gt(latestStable, baseVersion)) {
throw new Error(
`Nightly base ${baseVersion} is lower than published latest ${latestStable}. Refusing divergent preview baseline.`,
);
}
if (semver.eq(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
23 changes: 23 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,29 @@ describe('getVersion', () => {
expect(result.previousReleaseTag).toBe('v0.6.1');
});

it('should bump the preview base when the latest stable matches it', () => {
vi.mocked(execSync).mockImplementation((command) => {
if (command.includes('npm view') && command.includes('--tag=latest'))
return '0.8.0';
return mockExecSync(command);
});

const result = getVersion({ type: 'preview' });
expect(result.releaseVersion).toBe('0.8.1-preview.0');
});

it('should reject the preview when the latest stable is ahead', () => {
vi.mocked(execSync).mockImplementation((command) => {
if (command.includes('npm view') && command.includes('--tag=latest'))
return '0.9.0';
return mockExecSync(command);
});

expect(() => getVersion({ type: 'preview' })).toThrow(
'Nightly base 0.8.0 is lower than published latest 0.9.0. Refusing divergent preview baseline.',
);
});

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