( options: EnvironmentOptions, alias: Alias[], preserveSymlinks: boolean, forceOptimizeDeps: boolean | undefined, logger: Logger, environmentName: string, isBuild: boolean, isBundledDev: boolean, // Backward compatibility isSsrTargetWebworkerSet?: boolean, preTransformRequests?: boolean, )
| 931 | } |
| 932 | |
| 933 | function resolveEnvironmentOptions( |
| 934 | options: EnvironmentOptions, |
| 935 | alias: Alias[], |
| 936 | preserveSymlinks: boolean, |
| 937 | forceOptimizeDeps: boolean | undefined, |
| 938 | logger: Logger, |
| 939 | environmentName: string, |
| 940 | isBuild: boolean, |
| 941 | isBundledDev: boolean, |
| 942 | // Backward compatibility |
| 943 | isSsrTargetWebworkerSet?: boolean, |
| 944 | preTransformRequests?: boolean, |
| 945 | ): ResolvedEnvironmentOptions { |
| 946 | const isClientEnvironment = environmentName === 'client' |
| 947 | const consumer = |
| 948 | options.consumer ?? (isClientEnvironment ? 'client' : 'server') |
| 949 | const isSsrTargetWebworkerEnvironment = |
| 950 | isSsrTargetWebworkerSet && environmentName === 'ssr' |
| 951 | |
| 952 | const isBundled = |
| 953 | options.isBundled ?? (isBuild || (isClientEnvironment && isBundledDev)) |
| 954 | |
| 955 | if (options.define?.['process.env']) { |
| 956 | const processEnvDefine = options.define['process.env'] |
| 957 | if (typeof processEnvDefine === 'object') { |
| 958 | const pathKey = Object.entries(processEnvDefine).find( |
| 959 | // check with toLowerCase() to match with `Path` / `PATH` (Windows uses `Path`) |
| 960 | ([key, value]) => key.toLowerCase() === 'path' && !!value, |
| 961 | )?.[0] |
| 962 | if (pathKey) { |
| 963 | logger.warnOnce( |
| 964 | colors.yellow( |
| 965 | `The \`define\` option contains an object with ${JSON.stringify(pathKey)} for "process.env" key. ` + |
| 966 | 'It looks like you may have passed the entire `process.env` object to `define`, ' + |
| 967 | 'which can unintentionally expose all environment variables. ' + |
| 968 | 'This poses a security risk and is discouraged.', |
| 969 | ), |
| 970 | ) |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | const resolve = resolveEnvironmentResolveOptions( |
| 976 | options.resolve, |
| 977 | alias, |
| 978 | preserveSymlinks, |
| 979 | logger, |
| 980 | consumer, |
| 981 | isSsrTargetWebworkerEnvironment, |
| 982 | ) |
| 983 | return { |
| 984 | define: options.define, |
| 985 | resolve, |
| 986 | keepProcessEnv: |
| 987 | options.keepProcessEnv ?? |
| 988 | (isSsrTargetWebworkerEnvironment ? false : consumer === 'server'), |
| 989 | consumer, |
| 990 | optimizeDeps: resolveDepOptimizationOptions( |
no test coverage detected