Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Test build time flag (#139)

Sean Boult067a9a2d91d8
diff --git a/package.json b/package.json
index 7c55f376..6a34f2b4 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,7 @@
"refresh": "pnpm reset && pnpm prisma db seed",
"typecheck": "tsc --noEmit",
"prepare": "husky install",
- "dl-monaco": "node scripts/dl-monaco.mjs"
+ "dl-monaco": "node scripts/dl-monaco.mjs"
},
"type": "module",
"dependencies": {
@@ -44,6 +44,7 @@
"@trpc/server": "^10.26.0",
"@types/lodash": "^4.14.195",
"@uiw/react-md-editor": "^3.23.3",
+ "@vercel/edge-config": "^0.2.1",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"cmdk": "^0.2.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 766798f9..b9676fa2 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1,4 +1,4 @@
-lockfileVersion: '6.1'
+lockfileVersion: '6.0'
settings:
autoInstallPeers: true
@@ -94,6 +94,9 @@ dependencies:
'@uiw/react-md-editor':
specifier: ^3.23.3
+ '@vercel/edge-config':
+ specifier: ^0.2.1
+ version: 0.2.1
class-variance-authority:
specifier: ^0.6.0
version: 0.6.0([email protected])
@@ -2398,6 +2401,17 @@ packages:
- supports-color
dev: false
+ /@vercel/[email protected]:
+ resolution: {integrity: sha512-NRIBwfcS0bUoUbRWlNGetqjvLSwgYH/BqKqDN7vK1g32p7dN96k0712COgaz6VFizAm9b0g6IG6hR6+hc0KCPg==}
+ dev: false
+
+ /@vercel/[email protected]:
+ resolution: {integrity: sha512-847kYqJEbga4PGgNrctQ9XsD+2Kw/S+UjzZnIFpebQ9VbdtB0MX4anq33WetcYZYPfhZd2L0uXVnY/BcjI5dOw==}
+ engines: {node: '>=14.6'}
+ dependencies:
+ '@vercel/edge-config-fs': 0.1.0
+ dev: false
+
resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==}
peerDependencies:
diff --git a/src/components/ui/navigation.tsx b/src/components/ui/navigation.tsx
index e8c5fd99..6f120600 100644
--- a/src/components/ui/navigation.tsx
+++ b/src/components/ui/navigation.tsx
@@ -26,6 +26,7 @@ import {
} from './dropdown-menu';
import { useSession } from 'next-auth/react';
import { RoleTypes } from '@prisma/client';
+import { isProd } from '~/utils/featureFlags';
export function Navigation() {
const [mounted, setMounted] = useState(false);
@@ -62,9 +63,8 @@ export function Navigation() {
return (
<header className="w-full">
<nav
- className={`flex h-14 items-center ${
- pathname.includes('/challenge') || pathname.includes('/create') ? 'px-4' : 'container'
- }`}
+ className={`flex h-14 items-center ${pathname.includes('/challenge') || pathname.includes('/create') ? 'px-4' : 'container'
+ }`}
>
<div className="flex w-full items-center justify-between">
<div className="relative flex">
@@ -112,12 +112,14 @@ export function Navigation() {
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
- <NavigationMenuItem className="hidden sm:block">
- <NavigationMenuTrigger>Something Nice</NavigationMenuTrigger>
- <NavigationMenuContent>
- <NavigationMenuLink>Nice</NavigationMenuLink>
- </NavigationMenuContent>
- </NavigationMenuItem>
+ {!isProd() && (
+ <NavigationMenuItem className="hidden sm:block">
+ <NavigationMenuTrigger>Something Nice</NavigationMenuTrigger>
+ <NavigationMenuContent>
+ <NavigationMenuLink>Nice</NavigationMenuLink>
+ </NavigationMenuContent>
+ </NavigationMenuItem>
+ )}
</NavigationMenuList>
</NavigationMenu>
</div>
diff --git a/src/env.mjs b/src/env.mjs
index f36d8294..f8f4ccd6 100644
--- a/src/env.mjs
+++ b/src/env.mjs
@@ -11,6 +11,7 @@ export const env = createEnv({
NODE_ENV: z.enum(['development', 'test', 'production']),
GITHUB_ID: z.string(),
GITHUB_SECRET: z.string(),
+ // EDGE_CONFIG: z.string(),
},
/**
@@ -31,6 +32,7 @@ export const env = createEnv({
NODE_ENV: process.env.NODE_ENV,
GITHUB_SECRET: process.env.GITHUB_SECRET,
GITHUB_ID: process.env.GITHUB_ID,
+ // EDGE_CONFIG: process.env.EDGE_CONFIG,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
diff --git a/src/utils/featureFlags.ts b/src/utils/featureFlags.ts
new file mode 100644
index 00000000..c9955472
--- /dev/null
+++ b/src/utils/featureFlags.ts
@@ -0,0 +1,21 @@
+import { createClient } from '@vercel/edge-config';
+import { env } from '../env.mjs';
+
+interface FeatureFlags {
+ // The mode the site is running in
+ mode: 'marketing' | 'production';
+}
+
+// We use prefixes to avoid mixing up the flags with other Edge Config values
+const prefixKey = (key: string) => `ff_${key}`;
+// export async function get(key: keyof FeatureFlags) {
+// const prefixedKey = prefixKey(key);
+// const edgeConfig = createClient(env.EDGE_CONFIG);
+// const featureFlag = await edgeConfig.get<FeatureFlags>(prefixedKey);
+// return featureFlag;
+// }
+
+// For now we use this since it is a simp build time thingy
+export function isProd() {
+ return process.env.NODE_ENV === 'production';
+}