From 6afa78a34ae447a9c7af8a98f2714207b4613aff Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Thu, 14 Dec 2023 18:12:37 -0800 Subject: [PATCH] Convert env calls --- .../desktop-client/src/browser-preload.browser.js | 6 +++--- packages/desktop-client/src/components/App.tsx | 2 +- .../src/components/DevelopmentTopBar.tsx | 4 ++-- packages/desktop-client/vite.config.mts | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/desktop-client/src/browser-preload.browser.js b/packages/desktop-client/src/browser-preload.browser.js index 803ed2ac5b9..5b86f930f4b 100644 --- a/packages/desktop-client/src/browser-preload.browser.js +++ b/packages/desktop-client/src/browser-preload.browser.js @@ -11,7 +11,7 @@ const backendWorkerUrl = new URL('./browser-server.js', import.meta.url); // browser environment this is where we initialize the backend and // everything else. -const IS_DEV = process.env.NODE_ENV === 'development'; +const IS_DEV = import.meta.env.MODE === 'development'; const ACTUAL_VERSION = Platform.isPlaywright ? '99.9.9' : packageJson.version; // *** Start the backend *** @@ -29,8 +29,8 @@ function createBackendWorker() { type: 'init', version: ACTUAL_VERSION, isDev: IS_DEV, - publicUrl: process.env.PUBLIC_URL, - hash: process.env.REACT_APP_BACKEND_WORKER_HASH, + publicUrl: import.meta.env.BASE_URL.slice(0, -1), + hash: import.meta.env.REACT_APP_BACKEND_WORKER_HASH, isSharedArrayBufferOverrideEnabled: localStorage.getItem( 'SharedArrayBufferOverride', ), diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsx index bf5334c42d7..16ed0ce8374 100644 --- a/packages/desktop-client/src/components/App.tsx +++ b/packages/desktop-client/src/components/App.tsx @@ -175,7 +175,7 @@ function AppWrapper() { }} > - {process.env.REACT_APP_REVIEW_ID && !Platform.isPlaywright && ( + {import.meta.env.REACT_APP_REVIEW_ID && !Platform.isPlaywright && ( )} - Open the PR: #{process.env.REACT_APP_REVIEW_ID} + Open the PR: #{import.meta.env.REACT_APP_REVIEW_ID} diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mts index 9fb45f69cf3..70bbf2f8f54 100644 --- a/packages/desktop-client/vite.config.mts +++ b/packages/desktop-client/vite.config.mts @@ -24,13 +24,15 @@ const addWatchers = (): Plugin => ({ }); // https://vitejs.dev/config/ -export default defineConfig(({ mode }) => { +export default defineConfig(async ({ mode }) => { const env = loadEnv(mode, process.cwd(), ''); const devHeaders = { 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp', }; + const buildShims = await path.resolve('./src/build-shims.js'); + // Forward Netlify env variables if (process.env.REVIEW_ID) { process.env.REACT_APP_REVIEW_ID = process.env.REVIEW_ID; @@ -117,17 +119,15 @@ export default defineConfig(({ mode }) => { disableGlobbing: false, }, }, - optimizeDeps: { - include: ['process'], - }, resolve: { extensions: resolveExtensions, }, plugins: [ { ...inject({ - global: [path.resolve('src/build-shims.js'), 'global'], - process: [path.resolve('src/build-shims.js'), 'process'], + exclude: ['src/setupTests.jsx'], + global: [buildShims, 'global'], + process: [buildShims, 'process'], }), enforce: 'post', },