From 4bf9b94cd40ff3d349c35b11fd517fd5134dcb60 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Mon, 19 Jan 2026 19:22:46 -0800 Subject: [PATCH] feat: add isNightly build flag for nightly-only features (#8149) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Adds a compile-time `__IS_NIGHTLY__` constant that detects whether the build is from the main branch (nightly) or a core/* branch (RC/stable). The detection logic in vite.config.mts auto-detects based on `GITHUB_REF_NAME === 'main'` in CI, with explicit override support via `IS_NIGHTLY` environment variable. Exports `isNightly` from `src/platform/distribution/types.ts` for use throughout the codebase. Includes unit tests for the detection logic. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8149-feat-add-isNightly-build-flag-for-nightly-only-features-2ec6d73d365081c09930edec1c6644f5) by [Unito](https://www.unito.io) --- scripts/vite-define-shim.ts | 3 +++ src/platform/distribution/types.ts | 8 ++++++++ vite.config.mts | 11 ++++++++++- vitest.setup.ts | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/vite-define-shim.ts b/scripts/vite-define-shim.ts index e12b126f3..970d09aef 100644 --- a/scripts/vite-define-shim.ts +++ b/scripts/vite-define-shim.ts @@ -12,6 +12,7 @@ declare global { const __ALGOLIA_API_KEY__: string const __USE_PROD_CONFIG__: boolean const __DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud' + const __IS_NIGHTLY__: boolean } type GlobalWithDefines = typeof globalThis & { @@ -22,6 +23,7 @@ type GlobalWithDefines = typeof globalThis & { __ALGOLIA_API_KEY__: string __USE_PROD_CONFIG__: boolean __DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud' + __IS_NIGHTLY__: boolean window?: Record } @@ -36,6 +38,7 @@ globalWithDefines.__ALGOLIA_APP_ID__ = '' globalWithDefines.__ALGOLIA_API_KEY__ = '' globalWithDefines.__USE_PROD_CONFIG__ = false globalWithDefines.__DISTRIBUTION__ = 'localhost' +globalWithDefines.__IS_NIGHTLY__ = false // Provide a minimal window shim for Node environment // This is needed for code that checks window existence during imports diff --git a/src/platform/distribution/types.ts b/src/platform/distribution/types.ts index d03e6d53b..53ba95bea 100644 --- a/src/platform/distribution/types.ts +++ b/src/platform/distribution/types.ts @@ -9,6 +9,7 @@ type Distribution = 'desktop' | 'localhost' | 'cloud' declare global { const __DISTRIBUTION__: Distribution + const __IS_NIGHTLY__: boolean } /** Current distribution - replaced at compile time */ @@ -18,3 +19,10 @@ const DISTRIBUTION: Distribution = __DISTRIBUTION__ export const isDesktop = DISTRIBUTION === 'desktop' || isElectron() // TODO: replace with build var export const isCloud = DISTRIBUTION === 'cloud' // export const isLocalhost = DISTRIBUTION === 'localhost' || (!isDesktop && !isCloud) + +/** + * Whether this is a nightly build (from main branch). + * Nightly builds may show experimental features and surveys. + * @public + */ +export const isNightly = __IS_NIGHTLY__ diff --git a/vite.config.mts b/vite.config.mts index e3246e608..d01be687e 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -51,6 +51,14 @@ const DISTRIBUTION: 'desktop' | 'localhost' | 'cloud' = ? 'cloud' : 'localhost' +// Nightly builds are from main branch; RC/stable builds are from core/* branches +// Can be overridden via IS_NIGHTLY env var for testing +const IS_NIGHTLY = + process.env.IS_NIGHTLY === 'true' || + (process.env.IS_NIGHTLY !== 'false' && + process.env.CI === 'true' && + process.env.GITHUB_REF_NAME === 'main') + // Disable Vue DevTools for production cloud distribution const DISABLE_VUE_PLUGINS = process.env.DISABLE_VUE_PLUGINS === 'true' || @@ -502,7 +510,8 @@ export default defineConfig({ __ALGOLIA_APP_ID__: JSON.stringify(process.env.ALGOLIA_APP_ID || ''), __ALGOLIA_API_KEY__: JSON.stringify(process.env.ALGOLIA_API_KEY || ''), __USE_PROD_CONFIG__: process.env.USE_PROD_CONFIG === 'true', - __DISTRIBUTION__: JSON.stringify(DISTRIBUTION) + __DISTRIBUTION__: JSON.stringify(DISTRIBUTION), + __IS_NIGHTLY__: JSON.stringify(IS_NIGHTLY) }, resolve: { diff --git a/vitest.setup.ts b/vitest.setup.ts index fca677557..81c39723a 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -46,6 +46,7 @@ globalThis.__ALGOLIA_APP_ID__ = '' globalThis.__ALGOLIA_API_KEY__ = '' globalThis.__USE_PROD_CONFIG__ = false globalThis.__DISTRIBUTION__ = 'localhost' +globalThis.__IS_NIGHTLY__ = false // Define runtime config for tests window.__CONFIG__ = {