-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenvPrimitives.mjs
More file actions
64 lines (53 loc) · 1.56 KB
/
Copy pathenvPrimitives.mjs
File metadata and controls
64 lines (53 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* global process */
// Basic environment classification helpers for config and runtime.
// Shared between next.config.js and src/lib/runtimeEnv.ts. This module must be
// safe for both Node and browser bundles, so it only relies on the global
// process.env and avoids node-specific imports.
export function getNodeEnv() {
if (typeof process === 'undefined' || !process.env) {
return 'development';
}
const publicVercelEnv = process.env.NEXT_PUBLIC_VERCEL_ENV;
if (publicVercelEnv) {
if (publicVercelEnv === 'production') {
return 'release';
} else if (publicVercelEnv === 'preview') {
return 'staging';
} else if (publicVercelEnv === 'development') {
return 'development';
}
}
if (process.env.VERCEL && process.env.VERCEL.toString() === '1') {
const vercelEnv = process.env.VERCEL_ENV ?? 'development';
if (vercelEnv === 'production') {
return 'release';
} else if (vercelEnv === 'preview') {
return 'staging';
}
}
return 'development';
}
export function isStaging() {
return getNodeEnv() === 'staging';
}
export function notStaging() {
return !isStaging();
}
export function isRelease() {
return getNodeEnv() === 'release';
}
export function notRelease() {
return !isRelease();
}
export function isDev() {
return notStaging() && notRelease();
}
export function notDev() {
return !isDev();
}
export function getPublicMeasurementDebug() {
if (typeof process === 'undefined' || !process.env) {
return undefined;
}
return process.env.NEXT_PUBLIC_MEASUREMENT_DEBUG ?? undefined;
}