Scheduling infrastructure for absolutely everyone.
fix: embed env var EnvrionmentPlugin config (#14225)
Morgan22212e7edbac
diff --git a/packages/embeds/embed-core/vite.config.js b/packages/embeds/embed-core/vite.config.jsindex 4c63cf230a7..8dea84ce5a4 100644--- a/packages/embeds/embed-core/vite.config.js+++ b/packages/embeds/embed-core/vite.config.js@@ -1,6 +1,6 @@import EnvironmentPlugin from "vite-plugin-environment";-import viteBaseConfig from "../vite.config";+import viteBaseConfig, { embedCoreEnvVars } from "../vite.config";const path = require("path");const { defineConfig } = require("vite");@@ -9,6 +9,13 @@ module.exports = defineConfig((configEnv) => {const config = {...viteBaseConfig,base: "/embed/",+ plugins: [+ EnvironmentPlugin({+ EMBED_PUBLIC_EMBED_FINGER_PRINT: embedCoreEnvVars.EMBED_PUBLIC_EMBED_FINGER_PRINT,+ EMBED_PUBLIC_VERCEL_URL: embedCoreEnvVars.EMBED_PUBLIC_VERCEL_URL,+ EMBED_PUBLIC_WEBAPP_URL: embedCoreEnvVars.EMBED_PUBLIC_WEBAPP_URL,+ }),+ ],build: {emptyOutDir: true,rollupOptions: {@@ -17,11 +24,6 @@ module.exports = defineConfig((configEnv) => {embed: path.resolve(__dirname, "src/embed.ts"),},plugins: [- EnvironmentPlugin([- "EMBED_PUBLIC_EMBED_FINGER_PRINT",- "EMBED_PUBLIC_VERCEL_URL",- "EMBED_PUBLIC_WEBAPP_URL",- ]),{generateBundle: (code, bundle) => {// Note: banner/footer doesn't work because it doesn't enclose the entire library code, some variables are still left out.diff --git a/packages/embeds/vite.config.js b/packages/embeds/vite.config.jsindex d9279c4ff81..f88e008ef27 100644--- a/packages/embeds/vite.config.js+++ b/packages/embeds/vite.config.js@@ -2,13 +2,17 @@ const path = require("path");require("dotenv").config({ path: path.join(__dirname, "..", "..", ".env") });process.env.EMBED_PUBLIC_VERCEL_URL = process.env.VERCEL_URL;process.env.EMBED_PUBLIC_WEBAPP_URL = process.env.NEXT_PUBLIC_WEBAPP_URL;+// eslint-disable-next-line turbo/no-undeclared-env-varsprocess.env.EMBED_PUBLIC_EMBED_LIB_URL = process.env.NEXT_PUBLIC_EMBED_LIB_URL;+// eslint-disable-next-line turbo/no-undeclared-env-varsprocess.env.EMBED_PUBLIC_EMBED_FINGER_PRINT = process.env.NEXT_PUBLIC_EMBED_FINGER_PRINT;// Problem: typeof process.env.EMBED_PUBLIC_EMBED_LIB_URL is "undefined"(truthy) if process.env.NEXT_PUBLIC_EMBED_LIB_URL is undefined(falsy)// This is probably because environment variables are always string, so this weird automatic conversion to string happens// HACKY Solution+// eslint-disable-next-line turbo/no-undeclared-env-varsif (process.env.EMBED_PUBLIC_EMBED_LIB_URL === "undefined") {+ // eslint-disable-next-line turbo/no-undeclared-env-varsdelete process.env.EMBED_PUBLIC_EMBED_LIB_URL;}@@ -24,3 +28,12 @@ const viteBaseConfig = {envPrefix: "EMBED_PUBLIC_",};export default viteBaseConfig;+export const embedCoreEnvVars = {+ EMBED_PUBLIC_EMBED_FINGER_PRINT: process.env.EMBED_PUBLIC_EMBED_FINGER_PRINT ?? "",+ EMBED_PUBLIC_VERCEL_URL: process.env.EMBED_PUBLIC_VERCEL_URL ?? "http://localhost:3000",+ EMBED_PUBLIC_WEBAPP_URL:+ process.env.EMBED_PUBLIC_WEBAPP_URL ??+ (process.env.EMBED_PUBLIC_VERCEL_URL+ ? `https://${process.env.EMBED_PUBLIC_VERCEL_URL}`+ : "http://localhost:3000"),+};