Skip to content

Commit 581c972

Browse files
avivkellerCopilot
andauthored
chore(const): add IS_NOT_VERCEL_RUNTIME_ENV (#7721)
* chore(const): add IS_NOT_VERCEL_RUNTIME_ENV * finally a good copilot suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Aviv Keller <me@aviv.sh> * pull out `!IS_DEV_ENV` Signed-off-by: Aviv Keller <me@aviv.sh> --------- Signed-off-by: Aviv Keller <me@aviv.sh> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b663493 commit 581c972

4 files changed

Lines changed: 15 additions & 21 deletions

File tree

apps/site/next-data/blogData.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import {
22
ENABLE_STATIC_EXPORT,
3-
IS_DEV_ENV,
43
NEXT_DATA_URL,
5-
VERCEL_ENV,
6-
VERCEL_REGION,
4+
IS_NOT_VERCEL_RUNTIME_ENV,
75
} from '@/next.constants.mjs';
86
import type { BlogCategory, BlogPostsRSC } from '@/types';
97

108
const getBlogData = (
119
cat: BlogCategory,
1210
page?: number
1311
): Promise<BlogPostsRSC> => {
14-
const IS_NOT_VERCEL_RUNTIME_ENV =
15-
(!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) ||
16-
(!IS_DEV_ENV && !VERCEL_ENV);
17-
1812
// When we're using Static Exports the Next.js Server is not running (during build-time)
1913
// hence the self-ingestion APIs will not be available. In this case we want to load
2014
// the data directly within the current thread, which will anyways be loaded only once

apps/site/next-data/downloadSnippets.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
ENABLE_STATIC_EXPORT,
3-
IS_DEV_ENV,
43
NEXT_DATA_URL,
5-
VERCEL_ENV,
6-
VERCEL_REGION,
4+
IS_NOT_VERCEL_RUNTIME_ENV,
75
} from '@/next.constants.mjs';
86
import { availableLocaleCodes } from '@/next.locales.mjs';
97
import type { DownloadSnippet } from '@/types';
@@ -17,10 +15,6 @@ export default async function getDownloadSnippets(
1715
return [];
1816
}
1917

20-
const IS_NOT_VERCEL_RUNTIME_ENV =
21-
(!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) ||
22-
(!IS_DEV_ENV && !VERCEL_ENV);
23-
2418
// When we're using Static Exports the Next.js Server is not running (during build-time)
2519
// hence the self-ingestion APIs will not be available. In this case we want to load
2620
// the data directly within the current thread, which will anyways be loaded only once

apps/site/next-data/releaseData.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import {
22
ENABLE_STATIC_EXPORT,
3-
IS_DEV_ENV,
43
NEXT_DATA_URL,
5-
VERCEL_ENV,
6-
VERCEL_REGION,
4+
IS_NOT_VERCEL_RUNTIME_ENV,
75
} from '@/next.constants.mjs';
86
import type { NodeRelease } from '@/types';
97

108
const getReleaseData = (): Promise<Array<NodeRelease>> => {
11-
const IS_NOT_VERCEL_RUNTIME_ENV =
12-
(!IS_DEV_ENV && VERCEL_ENV && !VERCEL_REGION) ||
13-
(!IS_DEV_ENV && !VERCEL_ENV);
14-
159
// When we're using Static Exports the Next.js Server is not running (during build-time)
1610
// hence the self-ingestion APIs will not be available. In this case we want to load
1711
// the data directly within the current thread, which will anyways be loaded only once

apps/site/next.constants.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ export const VERCEL_ENV = process.env.VERCEL_ENV || undefined;
2323
*/
2424
export const VERCEL_REGION = process.env.VERCEL_REGION || undefined;
2525

26+
/**
27+
* This constant determines if the current environment is NOT a Vercel runtime environment.
28+
*
29+
* The logic is as follows:
30+
* - If we are NOT in a development environment (`!IS_DEV_ENV`) AND:
31+
* - Vercel environment variable (`VERCEL_ENV`) is defined but the Vercel region (`VERCEL_REGION`) is NOT defined, OR
32+
* - Vercel environment variable (`VERCEL_ENV`) is NOT defined at all.
33+
* This helps identify cases where the application is running outside of Vercel's runtime environment.
34+
*/
35+
export const IS_NOT_VERCEL_RUNTIME_ENV =
36+
!IS_DEV_ENV && ((VERCEL_ENV && !VERCEL_REGION) || !VERCEL_ENV);
37+
2638
/**
2739
* This is used for telling Next.js to do a Static Export Build of the Website
2840
*

0 commit comments

Comments
 (0)