Unverified Commit 7395b29c authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Fix isStableBuild() treating commit preview tarballs as stable (#98811)

## Summary

Commit preview tarballs carry versions like
`16.4.0-preview-84cee7e6-20260917` (no `canary` substring), so
`isStableBuild()` treated them as stable and canary-only defaults
(`turbopackSharedRuntime`, `turbopackMangleExportNames`) were disabled
on what are canary-quality builds. Versions containing `-preview-` now
count as unstable; numbered npm previews like `16.3.0-preview.10` stay
stable.

## Verification

- Added `canary-only-config-error.test.ts` covering the version matrix
(fails on the tarball case without the fix)
- `npx jest packages/next/src/server/config.test.ts` (existing consumer)
passes

<!-- NEXT_JS_LLM -->

<!-- fleet ae573e35-b551-453d-af1c-548ffb598944 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
parent 22fffea9
import { isStableBuild } from './canary-only-config-error'
describe('isStableBuild', () => {
afterEach(() => {
delete process.env.__NEXT_VERSION
delete process.env.__NEXT_TEST_MODE
delete process.env.NEXT_PRIVATE_LOCAL_DEV
})
it.each([
// A plain release version.
{ version: '16.3.0', expected: true },
// A numbered preview release published to npm (`next@preview`).
{ version: '16.3.0-preview.10', expected: true },
// A commit preview tarball (scripts/set-preview-version.js) is built from
// an arbitrary canary commit and must not be treated as stable.
{ version: '16.4.0-preview-84cee7e6-20260917', expected: false },
{ version: '16.4.0-canary.5', expected: false },
])('returns $expected for version $version', ({ version, expected }) => {
process.env.__NEXT_VERSION = version
expect(isStableBuild()).toBe(expected)
})
it('returns true when no version is set', () => {
delete process.env.__NEXT_VERSION
expect(isStableBuild()).toBe(true)
})
it('returns false in test mode even with a stable version', () => {
process.env.__NEXT_VERSION = '16.3.0'
process.env.__NEXT_TEST_MODE = '1'
expect(isStableBuild()).toBe(false)
})
it('returns false for local dev even with a stable version', () => {
process.env.__NEXT_VERSION = '16.3.0'
process.env.NEXT_PRIVATE_LOCAL_DEV = '1'
expect(isStableBuild()).toBe(false)
})
})
export function isStableBuild() {
const nextVersion = process.env.__NEXT_VERSION
return (
!process.env.__NEXT_VERSION?.includes('canary') &&
!nextVersion?.includes('canary') &&
// Commit preview tarballs (e.g. `16.4.0-preview-84cee7e6-20260917`, see
// scripts/set-preview-version.js) are built from arbitrary canary commits,
// so they are not stable. Numbered preview releases published to npm
// (e.g. `16.3.0-preview.10`) are stable.
!nextVersion?.includes('-preview-') &&
!process.env.__NEXT_TEST_MODE &&
!process.env.NEXT_PRIVATE_LOCAL_DEV
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment