From fc7e24f226d02d4d64502f211d5c49127955d267 Mon Sep 17 00:00:00 2001 From: ink-victor <171172553+ink-victor@users.noreply.github.com> Date: Wed, 5 Feb 2025 13:55:02 -0500 Subject: [PATCH] fix build --- .env.example | 2 +- next.config.ts | 56 +++++++++++++++----------------- scripts/generate-dummy-dotenv.sh | 10 +++++- src/env.ts | 2 +- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/.env.example b/.env.example index a039dd7..67732b6 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Environment NEXT_PUBLIC_ENVIRONMENT= -# Sentry +# Sentry (Optional) NEXT_PUBLIC_SENTRY_DSN= SENTRY_AUTH_TOKEN= diff --git a/next.config.ts b/next.config.ts index 3c31a78..610561d 100644 --- a/next.config.ts +++ b/next.config.ts @@ -19,33 +19,29 @@ const nextConfig: NextConfig = { }, }; -console.debug(`NEXT_PUBLIC_ENVIRONMENT: ${clientEnv.NEXT_PUBLIC_ENVIRONMENT}`); - -export default clientEnv.NEXT_PUBLIC_ENVIRONMENT === "ci" - ? nextConfig - : withSentryConfig(withNextIntl(nextConfig), { - // For all available options, see node_modules/@sentry/nextjs/build/types/config/types.d.ts - - org: "payward-inc", - project: "ink-web-app", - authToken: env.SENTRY_AUTH_TOKEN, - silent: true, - - // Sourcemaps config - sourcemaps: { - // Send source maps to Sentry, but do not include them in the client bundle - deleteSourcemapsAfterUpload: true, - }, - - // Upload a larger set of source maps for prettier stack traces (increases build time) - widenClientFileUpload: true, - - // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. - // This can increase your server load as well as your hosting bill. - // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- - // side errors will fail. - tunnelRoute: "/monitoring", - - // Automatically tree-shake Sentry logger statements to reduce bundle size - disableLogger: true, - }); +export default withSentryConfig(withNextIntl(nextConfig), { + // For all available options, see node_modules/@sentry/nextjs/build/types/config/types.d.ts + + org: "payward-inc", + project: "ink-web-app", + authToken: env.SENTRY_AUTH_TOKEN, + silent: true, + + // Sourcemaps config + sourcemaps: { + // Send source maps to Sentry, but do not include them in the client bundle + deleteSourcemapsAfterUpload: true, + }, + + // Upload a larger set of source maps for prettier stack traces (increases build time) + widenClientFileUpload: true, + + // Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. + // This can increase your server load as well as your hosting bill. + // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- + // side errors will fail. + tunnelRoute: "/monitoring", + + // Automatically tree-shake Sentry logger statements to reduce bundle size + disableLogger: true, +}); diff --git a/scripts/generate-dummy-dotenv.sh b/scripts/generate-dummy-dotenv.sh index 8faf6e7..222604c 100755 --- a/scripts/generate-dummy-dotenv.sh +++ b/scripts/generate-dummy-dotenv.sh @@ -9,6 +9,12 @@ while IFS= read -r line || [ -n "$line" ]; do # Get the variable name (everything before =) var_name=$(echo "$line" | cut -d= -f1) + # Skip variables that start with SENTRY_ variables as they mess up the build if defined with dummy data... Learned this the hard way: + # node_modules/@sentry/nextjs/build/types/config/types.d.ts + if [[ "$var_name" =~ ^SENTRY_ ]]; then + continue + fi + # Get existing environment variable value if it exists existing_value="${!var_name}" @@ -17,8 +23,10 @@ while IFS= read -r line || [ -n "$line" ]; do echo "${var_name}=${existing_value}" >> .env.production else # No existing value, use dummy values based on variable name - if [[ "$var_name" == *_URL ]]; then + if [[ "$var_name" =~ _URL$ ]] || [[ "$var_name" =~ _DSN$ ]]; then echo "${var_name}=https://dummy-url.com/" >> .env.production + elif [[ "$var_name" == "NEXT_PUBLIC_ENVIRONMENT" ]]; then + echo "${var_name}=ci" >> .env.production else echo "${var_name}=DUMMY_DO_NOT_REPLACE" >> .env.production fi diff --git a/src/env.ts b/src/env.ts index 795a105..62b4c05 100644 --- a/src/env.ts +++ b/src/env.ts @@ -4,7 +4,7 @@ import { z } from "zod"; export const env = createEnv({ server: { CI: z.string().optional(), - SENTRY_AUTH_TOKEN: z.string().min(1), + SENTRY_AUTH_TOKEN: z.string().optional(), ORIGIN: z.string().min(1).default("inkonchain.com"), BRAZE_INSTANCE_URL: z.string().url(), BRAZE_API_KEY: z.string().min(1),