1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-16 19:45:33 -04:00

consolidate environment variable parsing

This commit is contained in:
2022-09-12 15:42:56 -04:00
parent 0373f806f6
commit c64d6cfb52
7 changed files with 434 additions and 412 deletions

View File

@@ -1,6 +1,7 @@
import { useMemo } from "react"; import { useMemo } from "react";
import { minify } from "uglify-js"; import { minify } from "uglify-js";
import { clientScript } from "./client"; import { clientScript } from "./client";
import { IS_DEV_SERVER } from "../../lib/config/constants";
export type ThemeScriptProps = JSX.IntrinsicElements["script"] & { export type ThemeScriptProps = JSX.IntrinsicElements["script"] & {
themeClassNames: { themeClassNames: {
@@ -21,7 +22,7 @@ const ThemeScript = ({ key, themeClassNames, themeStorageKey, ...rest }: ThemeSc
const unminified = `(${functionString})()`; const unminified = `(${functionString})()`;
// skip minification if running locally to save a few ms // skip minification if running locally to save a few ms
if (process.env.IS_DEV_SERVER === "true") { if (IS_DEV_SERVER) {
return unminified; return unminified;
} }

View File

@@ -5,3 +5,8 @@ export const NOTES_DIR = "notes";
// normalize the timestamp saved when building/deploying (see next.config.js) and fall back to right now: // normalize the timestamp saved when building/deploying (see next.config.js) and fall back to right now:
export const RELEASE_DATE = new Date(process.env.RELEASE_DATE || Date.now()).toISOString(); export const RELEASE_DATE = new Date(process.env.RELEASE_DATE || Date.now()).toISOString();
// detect if running locally via `next dev` (phase is checked in next.config.js)
export const IS_DEV_SERVER = process.env.IS_DEV_SERVER === "true";
export const BUILD_ENV = process.env.VERCEL_ENV || process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.NODE_ENV;

View File

@@ -1,6 +1,7 @@
import { serialize } from "next-mdx-remote/serialize"; import { serialize } from "next-mdx-remote/serialize";
import { minify } from "uglify-js"; import { minify } from "uglify-js";
import { getNoteData } from "./parse-notes"; import { getNoteData } from "./parse-notes";
import { IS_DEV_SERVER } from "../config/constants";
// remark/rehype markdown plugins // remark/rehype markdown plugins
import remarkGfm from "remark-gfm"; import remarkGfm from "remark-gfm";
@@ -34,18 +35,17 @@ export const compileNote = async (slug: string): Promise<NoteWithSource> => {
}, },
}); });
// HACK: next-mdx-remote v4 doesn't (yet?) minify compiled JSX output, see: // TODO: next-mdx-remote v4 doesn't (yet?) minify compiled JSX output, see:
// https://github.com/hashicorp/next-mdx-remote/pull/211#issuecomment-1013658514 // https://github.com/hashicorp/next-mdx-remote/pull/211#issuecomment-1013658514
// ...so for now, let's do it manually (and conservatively) with uglify-js when building for production. // ...so for now, let's do it manually (and conservatively) with uglify-js when building for production.
const compiledSource = const compiledSource = IS_DEV_SERVER
process.env.IS_DEV_SERVER !== "true" ? source.compiledSource
? minify(source.compiledSource, { : minify(source.compiledSource, {
toplevel: true, toplevel: true,
parse: { parse: {
bare_returns: true, bare_returns: true,
}, },
}).code }).code;
: source.compiledSource;
return { return {
frontMatter, frontMatter,

View File

@@ -1,4 +1,5 @@
import { PrismaClient } from "@prisma/client"; import { PrismaClient } from "@prisma/client";
import { IS_DEV_SERVER } from "../config/constants";
// PrismaClient is attached to the `global` object in development to prevent // PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit. // exhausting your database connection limit.
@@ -18,4 +19,4 @@ export const prisma =
log: ["query"], log: ["query"],
}); });
if (process.env.IS_DEV_SERVER === "true") global.prisma = prisma; if (IS_DEV_SERVER) global.prisma = prisma;

View File

@@ -1,11 +1,12 @@
import * as Sentry from "@sentry/node"; import * as Sentry from "@sentry/node";
import "@sentry/tracing"; import "@sentry/tracing";
import { BUILD_ENV } from "../config/constants";
const IsomorphicSentry = () => { const IsomorphicSentry = () => {
// https://docs.sentry.io/platforms/node/configuration/options/ // https://docs.sentry.io/platforms/node/configuration/options/
Sentry.init({ Sentry.init({
dsn: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN || "", dsn: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN || "",
environment: process.env.NODE_ENV || process.env.VERCEL_ENV || process.env.NEXT_PUBLIC_VERCEL_ENV || "", environment: BUILD_ENV,
tracesSampleRate: 1.0, tracesSampleRate: 1.0,
}); });

794
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -24,10 +24,10 @@
"@hcaptcha/react-hcaptcha": "^1.4.4", "@hcaptcha/react-hcaptcha": "^1.4.4",
"@novnc/novnc": "github:novnc/novnc#cdfb33665195eb9a73fb00feb6ebaccd1068cd50", "@novnc/novnc": "github:novnc/novnc#cdfb33665195eb9a73fb00feb6ebaccd1068cd50",
"@octokit/graphql": "^5.0.1", "@octokit/graphql": "^5.0.1",
"@octokit/graphql-schema": "^12.4.0", "@octokit/graphql-schema": "^12.4.1",
"@primer/octicons": "^17.5.0", "@primer/octicons": "^17.5.0",
"@prisma/client": "^4.3.1", "@prisma/client": "^4.3.1",
"@react-spring/web": "^9.5.2", "@react-spring/web": "^9.5.3",
"@sentry/node": "^7.12.1", "@sentry/node": "^7.12.1",
"@sentry/tracing": "^7.12.1", "@sentry/tracing": "^7.12.1",
"@stitches/react": "^1.2.8", "@stitches/react": "^1.2.8",
@@ -42,7 +42,7 @@
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"hex-to-rgba": "^2.0.1", "hex-to-rgba": "^2.0.1",
"marked": "^4.1.0", "marked": "^4.1.0",
"next": "12.3.1-canary.0", "next": "12.3.1-canary.1",
"next-mdx-remote": "^4.1.0", "next-mdx-remote": "^4.1.0",
"next-seo": "^5.5.0", "next-seo": "^5.5.0",
"obj-str": "^1.1.0", "obj-str": "^1.1.0",
@@ -66,7 +66,7 @@
"remark-smartypants": "^2.0.0", "remark-smartypants": "^2.0.0",
"remark-unwrap-images": "^3.0.1", "remark-unwrap-images": "^3.0.1",
"remove-markdown": "^0.5.0", "remove-markdown": "^0.5.0",
"simple-icons": "^7.10.0", "simple-icons": "^7.11.0",
"sitemap": "^7.1.1", "sitemap": "^7.1.1",
"swr": "^1.3.0" "swr": "^1.3.0"
}, },
@@ -78,16 +78,16 @@
"@types/node": "*", "@types/node": "*",
"@types/novnc__novnc": "^1.3.0", "@types/novnc__novnc": "^1.3.0",
"@types/prop-types": "^15.7.5", "@types/prop-types": "^15.7.5",
"@types/react": "^18.0.18", "@types/react": "^18.0.19",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@types/react-is": "^17.0.3", "@types/react-is": "^17.0.3",
"@types/remove-markdown": "^0.3.1", "@types/remove-markdown": "^0.3.1",
"@types/uglify-js": "^3.17.0", "@types/uglify-js": "^3.17.0",
"@typescript-eslint/eslint-plugin": "^5.36.2", "@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.36.2", "@typescript-eslint/parser": "^5.37.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "~8.23.0", "eslint": "~8.23.1",
"eslint-config-next": "12.3.1-canary.0", "eslint-config-next": "12.3.1-canary.1",
"eslint-config-prettier": "~8.5.0", "eslint-config-prettier": "~8.5.0",
"eslint-plugin-mdx": "~2.0.4", "eslint-plugin-mdx": "~2.0.4",
"eslint-plugin-prettier": "~4.2.1", "eslint-plugin-prettier": "~4.2.1",