11import fs from 'fs'
22import { createHash } from 'node:crypto'
33import path from 'path'
4+ import { parse as parseDotEnv } from 'dotenv'
45import { loadEnv , transformWithEsbuild } from 'vite'
56import commonjs from 'vite-plugin-commonjs'
67import { nodePolyfills } from 'vite-plugin-node-polyfills'
@@ -13,6 +14,19 @@ import { getTsconfigAliases } from './config/getTsconfigAliases'
1314// Tamagui static extractor can resolve it.
1415process . env . APP_ID = 'extension'
1516
17+ const USE_NEW_CONFIGS = process . env . USE_NEW_CONFIGS === 'true'
18+ const NEW_ENV_PATH = path . resolve ( import . meta. dirname , '.env.new' )
19+
20+ // Fail fast so a missing .env.new aborts the build instead of silently producing
21+ // a bundle with empty env values.
22+ if ( USE_NEW_CONFIGS && ! fs . existsSync ( NEW_ENV_PATH ) ) {
23+ throw new Error ( `USE_NEW_CONFIGS=true but ${ NEW_ENV_PATH } does not exist` )
24+ }
25+
26+ function parseEnvFile ( filePath : string ) : Record < string , string > {
27+ return parseDotEnv ( fs . readFileSync ( filePath ) )
28+ }
29+
1630const icons = {
1731 16 : 'assets/icon16.png' ,
1832 32 : 'assets/icon32.png' ,
@@ -37,7 +51,7 @@ const publicAssetsVariant = getPublicAssetsVariant()
3751
3852const BASE_NAME = 'Uniswap Extension'
3953const BASE_DESCRIPTION = "The Uniswap Extension is a self-custody crypto wallet that's built for swapping."
40- const BASE_VERSION = '1.74 .0'
54+ const BASE_VERSION = '1.75 .0'
4155
4256const BUILD_NUM = parseInt ( process . env . BUILD_NUM || '0' )
4357const EXTENSION_VERSION = `${ BASE_VERSION } .${ BUILD_NUM } `
@@ -261,32 +275,25 @@ export default defineConfig({
261275
262276 // Vite configuration copied from web project
263277 vite : ( env ) => {
264- // Load ALL env variables (including those without VITE_ prefix). Matches webpack's
265- // DotenvPlugin behavior: read the monorepo-root `.env` (user-provided) AND the
266- // monorepo-root `.env.defaults` (checked-in defaults), with `.env` taking precedence.
267- // Vite only reads from one directory per call and doesn't know about `.env.defaults`,
268- // so we do both loads and merge.
269- const monorepoRoot = path . resolve ( import . meta. dirname , '../..' )
270- const envDefaults = loadEnv ( env . mode , monorepoRoot , '' )
271- // Re-read with a custom-named prefix file: loadEnv only looks at `.env`, `.env.local`,
272- // `.env.<mode>`, `.env.<mode>.local`. Manually parse `.env.defaults` since Vite won't.
273- const defaultsPath = path . join ( monorepoRoot , '.env.defaults' )
274- const parsedDefaults : Record < string , string > = { }
275- if ( fs . existsSync ( defaultsPath ) ) {
276- for ( const rawLine of fs . readFileSync ( defaultsPath , 'utf-8' ) . split ( '\n' ) ) {
277- const line = rawLine . trim ( )
278- if ( ! line || line . startsWith ( '#' ) ) continue
279- const eq = line . indexOf ( '=' )
280- if ( eq === - 1 ) continue
281- const key = line . slice ( 0 , eq ) . trim ( )
282- const value = line
283- . slice ( eq + 1 )
284- . trim ( )
285- . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' )
286- parsedDefaults [ key ] = value
287- }
278+ let envVars : Record < string , string >
279+ if ( USE_NEW_CONFIGS ) {
280+ // New unified config: read only apps/extension/.env.new. Other env sources
281+ // (monorepo-root .env / .env.defaults / etc.) are ignored.
282+ envVars = parseEnvFile ( NEW_ENV_PATH )
283+ } else {
284+ // Load ALL env variables (including those without VITE_ prefix). Matches webpack's
285+ // DotenvPlugin behavior: read the monorepo-root `.env` (user-provided) AND the
286+ // monorepo-root `.env.defaults` (checked-in defaults), with `.env` taking precedence.
287+ // Vite only reads from one directory per call and doesn't know about `.env.defaults`,
288+ // so we do both loads and merge.
289+ const monorepoRoot = path . resolve ( import . meta. dirname , '../..' )
290+ const envDefaults = loadEnv ( env . mode , monorepoRoot , '' )
291+ // Re-read with a custom-named prefix file: loadEnv only looks at `.env`, `.env.local`,
292+ // `.env.<mode>`, `.env.<mode>.local`. Manually parse `.env.defaults` since Vite won't.
293+ const defaultsPath = path . join ( monorepoRoot , '.env.defaults' )
294+ const parsedDefaults = fs . existsSync ( defaultsPath ) ? parseEnvFile ( defaultsPath ) : { }
295+ envVars = { ...parsedDefaults , ...envDefaults }
288296 }
289- const envVars = { ...parsedDefaults , ...envDefaults }
290297
291298 const __dirname = path . dirname ( new URL ( import . meta. url ) . pathname )
292299 const isProduction = process . env . NODE_ENV === 'production'
0 commit comments