vite 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { C as commonjsGlobal, B as getDefaultExportFromCjs } from './dep-94_H5fT6.js';
1
+ import { C as commonjsGlobal, B as getDefaultExportFromCjs } from './dep-Glf1enhJ.js';
2
2
  import require$$0__default from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -13077,6 +13077,21 @@ function sortObjectKeys(obj) {
13077
13077
  }
13078
13078
  return sorted;
13079
13079
  }
13080
+ function displayTime(time) {
13081
+ // display: {X}ms
13082
+ if (time < 1000) {
13083
+ return `${time}ms`;
13084
+ }
13085
+ time = time / 1000;
13086
+ // display: {X}s
13087
+ if (time < 60) {
13088
+ return `${time.toFixed(2)}s`;
13089
+ }
13090
+ const mins = parseInt((time / 60).toString());
13091
+ const seconds = time % 60;
13092
+ // display: {X}m {Y}s
13093
+ return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}`;
13094
+ }
13080
13095
 
13081
13096
  /* eslint no-console: 0 */
13082
13097
  const LogLevels = {
@@ -13226,8 +13241,6 @@ function buildReporterPlugin(config) {
13226
13241
  let transformedCount = 0;
13227
13242
  let chunkCount = 0;
13228
13243
  let compressedCount = 0;
13229
- let startTime = Date.now();
13230
- let buildFailed = false;
13231
13244
  async function getCompressedSize(code) {
13232
13245
  if (config.build.ssr || !config.build.reportCompressedSize) {
13233
13246
  return null;
@@ -13270,14 +13283,10 @@ function buildReporterPlugin(config) {
13270
13283
  }
13271
13284
  return null;
13272
13285
  },
13273
- options() {
13274
- startTime = Date.now();
13275
- },
13276
13286
  buildStart() {
13277
13287
  transformedCount = 0;
13278
13288
  },
13279
- buildEnd(error) {
13280
- buildFailed = !!error;
13289
+ buildEnd() {
13281
13290
  if (shouldLogInfo) {
13282
13291
  if (tty) {
13283
13292
  clearLine$1();
@@ -13424,11 +13433,6 @@ function buildReporterPlugin(config) {
13424
13433
  `- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.`));
13425
13434
  }
13426
13435
  },
13427
- closeBundle() {
13428
- if (shouldLogInfo && !config.build.watch && !buildFailed) {
13429
- config.logger.info(`${colors$1.green(`✓ built in ${displayTime(Date.now() - startTime)}`)}`);
13430
- }
13431
- },
13432
13436
  };
13433
13437
  }
13434
13438
  function writeLine(output) {
@@ -13455,21 +13459,6 @@ function throttle(fn) {
13455
13459
  }, 100);
13456
13460
  };
13457
13461
  }
13458
- function displayTime(time) {
13459
- // display: {X}ms
13460
- if (time < 1000) {
13461
- return `${time}ms`;
13462
- }
13463
- time = time / 1000;
13464
- // display: {X}s
13465
- if (time < 60) {
13466
- return `${time.toFixed(2)}s`;
13467
- }
13468
- const mins = parseInt((time / 60).toString());
13469
- const seconds = time % 60;
13470
- // display: {X}m {Y}s
13471
- return `${mins}m${seconds < 1 ? '' : ` ${seconds.toFixed(0)}s`}`;
13472
- }
13473
13462
 
13474
13463
  const POSIX_SEP_RE = new RegExp('\\' + path$o.posix.sep, 'g');
13475
13464
  const NATIVE_SEP_RE = new RegExp('\\' + path$o.sep, 'g');
@@ -29603,7 +29592,7 @@ function stripLiteralDetailed(code, options) {
29603
29592
  var main$1 = {exports: {}};
29604
29593
 
29605
29594
  var name = "dotenv";
29606
- var version$2 = "16.4.1";
29595
+ var version$2 = "16.4.2";
29607
29596
  var description = "Loads environment variables from .env file";
29608
29597
  var main = "lib/main.js";
29609
29598
  var types$2 = "lib/main.d.ts";
@@ -29634,7 +29623,7 @@ var repository = {
29634
29623
  type: "git",
29635
29624
  url: "git://github.com/motdotla/dotenv.git"
29636
29625
  };
29637
- var funding = "https://github.com/motdotla/dotenv?sponsor=1";
29626
+ var funding = "https://dotenvx.com";
29638
29627
  var keywords$2 = [
29639
29628
  "dotenv",
29640
29629
  "env",
@@ -29743,7 +29732,7 @@ function _parseVault (options) {
29743
29732
  }
29744
29733
 
29745
29734
  // handle scenario for comma separated keys - for use with key rotation
29746
- // example: DOTENV_KEY="dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenv.org/vault/.env.vault?environment=prod"
29735
+ // example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
29747
29736
  const keys = _dotenvKey(options).split(',');
29748
29737
  const length = keys.length;
29749
29738
 
@@ -29807,7 +29796,7 @@ function _instructions (result, dotenvKey) {
29807
29796
  uri = new URL(dotenvKey);
29808
29797
  } catch (error) {
29809
29798
  if (error.code === 'ERR_INVALID_URL') {
29810
- const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development');
29799
+ const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
29811
29800
  err.code = 'INVALID_DOTENV_KEY';
29812
29801
  throw err
29813
29802
  }
@@ -30037,81 +30026,80 @@ main$1.exports.populate = DotenvModule.populate;
30037
30026
 
30038
30027
  main$1.exports = DotenvModule;
30039
30028
 
30040
- // like String.prototype.search but returns the last index
30041
- function _searchLast (str, rgx) {
30042
- const matches = Array.from(str.matchAll(rgx));
30043
- return matches.length > 0 ? matches.slice(-1)[0].index : -1
30044
- }
30029
+ // * /
30030
+ // * (\\)? # is it escaped with a backslash?
30031
+ // * (\$) # literal $
30032
+ // * (?!\() # shouldnt be followed by parenthesis
30033
+ // * (\{?) # first brace wrap opening
30034
+ // * ([\w.]+) # key
30035
+ // * (?::-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))? # optional default nested 3 times
30036
+ // * (\}?) # last brace warp closing
30037
+ // * /xi
30045
30038
 
30046
- function _interpolate (envValue, environment, config) {
30047
- // find the last unescaped dollar sign in the
30048
- // value so that we can evaluate it
30049
- const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
30039
+ const DOTENV_SUBSTITUTION_REGEX = /(\\)?(\$)(?!\()(\{?)([\w.]+)(?::?-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))?(\}?)/gi;
30050
30040
 
30051
- // If we couldn't match any unescaped dollar sign
30052
- // let's return the string as is
30053
- if (lastUnescapedDollarSignIndex === -1) return envValue
30041
+ function _resolveEscapeSequences (value) {
30042
+ return value.replace(/\\\$/g, '$')
30043
+ }
30054
30044
 
30055
- // This is the right-most group of variables in the string
30056
- const rightMostGroup = envValue.slice(lastUnescapedDollarSignIndex);
30045
+ function interpolate (value, processEnv, parsed) {
30046
+ return value.replace(DOTENV_SUBSTITUTION_REGEX, (match, escaped, dollarSign, openBrace, key, defaultValue, closeBrace) => {
30047
+ if (escaped === '\\') {
30048
+ return match.slice(1)
30049
+ } else {
30050
+ if (processEnv[key]) {
30051
+ return processEnv[key]
30052
+ }
30057
30053
 
30058
- /**
30059
- * This finds the inner most variable/group divided
30060
- * by variable name and default value (if present)
30061
- * (
30062
- * (?!(?<=\\))\$ // only match dollar signs that are not escaped
30063
- * {? // optional opening curly brace
30064
- * ([\w]+) // match the variable name
30065
- * (?::-([^}\\]*))? // match an optional default value
30066
- * }? // optional closing curly brace
30067
- * )
30068
- */
30069
- const matchGroup = /((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;
30070
- const match = rightMostGroup.match(matchGroup);
30071
-
30072
- if (match != null) {
30073
- const [, group, variableName, defaultValue] = match;
30074
-
30075
- return _interpolate(
30076
- envValue.replace(
30077
- group,
30078
- environment[variableName] ||
30079
- defaultValue ||
30080
- config.parsed[variableName] ||
30081
- ''
30082
- ),
30083
- environment,
30084
- config
30085
- )
30086
- }
30054
+ if (parsed[key]) {
30055
+ return parsed[key]
30056
+ }
30087
30057
 
30088
- return envValue
30089
- }
30058
+ if (defaultValue) {
30059
+ if (defaultValue.startsWith('$')) {
30060
+ return interpolate(defaultValue, processEnv, parsed)
30061
+ } else {
30062
+ return defaultValue
30063
+ }
30064
+ }
30090
30065
 
30091
- function _resolveEscapeSequences (value) {
30092
- return value.replace(/\\\$/g, '$')
30066
+ return ''
30067
+ }
30068
+ })
30093
30069
  }
30094
30070
 
30095
- function expand (config) {
30096
- // if ignoring process.env, use a blank object
30097
- const environment = config.ignoreProcessEnv ? {} : process.env;
30071
+ function expand (options) {
30072
+ let processEnv = process.env;
30073
+ if (options && options.processEnv != null) {
30074
+ processEnv = options.processEnv;
30075
+ }
30098
30076
 
30099
- for (const configKey in config.parsed) {
30100
- const value = Object.prototype.hasOwnProperty.call(environment, configKey)
30101
- ? environment[configKey]
30102
- : config.parsed[configKey];
30077
+ for (const key in options.parsed) {
30078
+ let value = options.parsed[key];
30103
30079
 
30104
- config.parsed[configKey] = _resolveEscapeSequences(
30105
- _interpolate(value, environment, config)
30106
- );
30080
+ const inProcessEnv = Object.prototype.hasOwnProperty.call(processEnv, key);
30081
+
30082
+ if (inProcessEnv) {
30083
+ if (processEnv[key] === options.parsed[key]) {
30084
+ // assume was set to processEnv from the .env file if the values match and therefore interpolate
30085
+ value = interpolate(value, processEnv, options.parsed);
30086
+ } else {
30087
+ // do not interpolate - assume processEnv had the intended value even if containing a $.
30088
+ value = processEnv[key];
30089
+ }
30090
+ } else {
30091
+ // not inProcessEnv so assume interpolation for this .env key
30092
+ value = interpolate(value, processEnv, options.parsed);
30093
+ }
30094
+
30095
+ options.parsed[key] = _resolveEscapeSequences(value);
30107
30096
  }
30108
30097
 
30109
- // PATCH: don't write to process.env
30110
- // for (const processKey in config.parsed) {
30111
- // environment[processKey] = config.parsed[processKey]
30112
- // }
30098
+ for (const processKey in options.parsed) {
30099
+ processEnv[processKey] = options.parsed[processKey];
30100
+ }
30113
30101
 
30114
- return config
30102
+ return options
30115
30103
  }
30116
30104
 
30117
30105
  var expand_1 = expand;
@@ -30148,9 +30136,10 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
30148
30136
  if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {
30149
30137
  process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
30150
30138
  }
30151
- // let environment variables use each other
30152
- // `expand` patched in patches/dotenv-expand@9.0.0.patch
30153
- expand_1({ parsed });
30139
+ // let environment variables use each other. make a copy of `process.env` so that `dotenv-expand`
30140
+ // doesn't re-assign the expanded values to the global `process.env`.
30141
+ const processEnv = { ...process.env };
30142
+ expand_1({ parsed, processEnv });
30154
30143
  // only keys that start with prefix are exposed to client
30155
30144
  for (const [key, value] of Object.entries(parsed)) {
30156
30145
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
@@ -32082,8 +32071,8 @@ function createCachedImport(imp) {
32082
32071
  return cached;
32083
32072
  };
32084
32073
  }
32085
- const importPostcssImport = createCachedImport(() => import('./dep-xESY8DUV.js').then(function (n) { return n.i; }));
32086
- const importPostcssModules = createCachedImport(() => import('./dep-XbJJvsnO.js').then(function (n) { return n.i; }));
32074
+ const importPostcssImport = createCachedImport(() => import('./dep-vBYKhUMg.js').then(function (n) { return n.i; }));
32075
+ const importPostcssModules = createCachedImport(() => import('./dep-7WSsXf4P.js').then(function (n) { return n.i; }));
32087
32076
  const importPostcss = createCachedImport(() => import('postcss'));
32088
32077
  const preprocessorWorkerControllerCache = new WeakMap();
32089
32078
  let alwaysFakeWorkerWorkerControllerCache;
@@ -49247,10 +49236,11 @@ function webWorkerPlugin(config) {
49247
49236
  // Using blob URL for SharedWorker results in multiple instances of a same worker
49248
49237
  workerConstructor === 'Worker'
49249
49238
  ? `${encodedJs}
49239
+ const decodeBase64 = (base64) => Uint8Array.from(atob(base64), c => c.charCodeAt(0));
49250
49240
  const blob = typeof window !== "undefined" && window.Blob && new Blob([${workerType === 'classic'
49251
49241
  ? ''
49252
49242
  : // `URL` is always available, in `Worker[type="module"]`
49253
- `'URL.revokeObjectURL(import.meta.url);'+`}atob(encodedJs)], { type: "text/javascript;charset=utf-8" });
49243
+ `'URL.revokeObjectURL(import.meta.url);',`}decodeBase64(encodedJs)], { type: "text/javascript;charset=utf-8" });
49254
49244
  export default function WorkerWrapper(options) {
49255
49245
  let objURL;
49256
49246
  try {
@@ -56180,7 +56170,7 @@ async function fetchModule(server, url, importer, options = {}) {
56180
56170
  throw err;
56181
56171
  }
56182
56172
  const file = pathToFileURL(resolved.id).toString();
56183
- const type = isFilePathESM(file, server.config.packageCache)
56173
+ const type = isFilePathESM(resolved.id, server.config.packageCache)
56184
56174
  ? 'module'
56185
56175
  : 'commonjs';
56186
56176
  return { externalize: file, type };
@@ -65558,7 +65548,7 @@ function importAnalysisPlugin(config) {
65558
65548
  }
65559
65549
  // fix#9534, prevent the importerModuleNode being stopped from propagating updates
65560
65550
  importerModule.isSelfAccepting = false;
65561
- return this.error(`Failed to resolve import "${url}" from "${path$o.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
65551
+ return this.error(`Failed to resolve import "${url}" from "${normalizePath$3(path$o.relative(process.cwd(), importerFile))}". Does the file exist?`, pos);
65562
65552
  }
65563
65553
  if (isExternalUrl(resolved.id)) {
65564
65554
  return [resolved.id, resolved.id];
@@ -66793,6 +66783,7 @@ async function build(inlineConfig = {}) {
66793
66783
  config.logger.error(msg, { error: e });
66794
66784
  };
66795
66785
  let bundle;
66786
+ let startTime;
66796
66787
  try {
66797
66788
  const buildOutputOptions = (output = {}) => {
66798
66789
  // @ts-expect-error See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
@@ -66890,6 +66881,7 @@ async function build(inlineConfig = {}) {
66890
66881
  }
66891
66882
  // write or generate files with rollup
66892
66883
  const { rollup } = await import('rollup');
66884
+ startTime = Date.now();
66893
66885
  bundle = await rollup(rollupOptions);
66894
66886
  if (options.write) {
66895
66887
  prepareOutDir(outDirs, options.emptyOutDir, config);
@@ -66898,11 +66890,16 @@ async function build(inlineConfig = {}) {
66898
66890
  for (const output of normalizedOutputs) {
66899
66891
  res.push(await bundle[options.write ? 'write' : 'generate'](output));
66900
66892
  }
66893
+ config.logger.info(`${colors$1.green(`✓ built in ${displayTime(Date.now() - startTime)}`)}`);
66901
66894
  return Array.isArray(outputs) ? res : res[0];
66902
66895
  }
66903
66896
  catch (e) {
66904
66897
  e.message = mergeRollupError(e);
66905
66898
  clearLine();
66899
+ if (startTime) {
66900
+ config.logger.error(`${colors$1.red('x')} Build failed in ${displayTime(Date.now() - startTime)}`);
66901
+ startTime = undefined;
66902
+ }
66906
66903
  throw e;
66907
66904
  }
66908
66905
  finally {
@@ -1,4 +1,4 @@
1
- import { B as getDefaultExportFromCjs } from './dep-94_H5fT6.js';
1
+ import { B as getDefaultExportFromCjs } from './dep-Glf1enhJ.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-8a-6Quh6.js';
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { c as colors, a as createLogger, r as resolveConfig } from './chunks/dep-94_H5fT6.js';
5
+ import { c as colors, a as createLogger, r as resolveConfig } from './chunks/dep-Glf1enhJ.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -757,7 +757,7 @@ cli
757
757
  filterDuplicateOptions(options);
758
758
  // output structure is preserved even after bundling so require()
759
759
  // is ok here
760
- const { createServer } = await import('./chunks/dep-94_H5fT6.js').then(function (n) { return n.E; });
760
+ const { createServer } = await import('./chunks/dep-Glf1enhJ.js').then(function (n) { return n.E; });
761
761
  try {
762
762
  const server = await createServer({
763
763
  root,
@@ -836,7 +836,7 @@ cli
836
836
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
837
837
  .action(async (root, options) => {
838
838
  filterDuplicateOptions(options);
839
- const { build } = await import('./chunks/dep-94_H5fT6.js').then(function (n) { return n.F; });
839
+ const { build } = await import('./chunks/dep-Glf1enhJ.js').then(function (n) { return n.F; });
840
840
  const buildOptions = cleanOptions(options);
841
841
  try {
842
842
  await build({
@@ -863,7 +863,7 @@ cli
863
863
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
864
864
  .action(async (root, options) => {
865
865
  filterDuplicateOptions(options);
866
- const { optimizeDeps } = await import('./chunks/dep-94_H5fT6.js').then(function (n) { return n.D; });
866
+ const { optimizeDeps } = await import('./chunks/dep-Glf1enhJ.js').then(function (n) { return n.D; });
867
867
  try {
868
868
  const config = await resolveConfig({
869
869
  root,
@@ -889,7 +889,7 @@ cli
889
889
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
890
890
  .action(async (root, options) => {
891
891
  filterDuplicateOptions(options);
892
- const { preview } = await import('./chunks/dep-94_H5fT6.js').then(function (n) { return n.G; });
892
+ const { preview } = await import('./chunks/dep-Glf1enhJ.js').then(function (n) { return n.G; });
893
893
  try {
894
894
  const server = await preview({
895
895
  root,
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, b as arraify } from './chunks/dep-94_H5fT6.js';
3
- export { f as build, j as buildErrorMessage, u as createFilter, a as createLogger, e as createServer, d as defineConfig, k as fetchModule, g as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-94_H5fT6.js';
2
+ import { i as isInNodeModules, b as arraify } from './chunks/dep-Glf1enhJ.js';
3
+ export { f as build, j as buildErrorMessage, u as createFilter, a as createLogger, e as createServer, d as defineConfig, k as fetchModule, g as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Glf1enhJ.js';
4
4
  export { VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import { existsSync, readFileSync } from 'node:fs';
@@ -5577,7 +5577,7 @@ function isFileServingAllowed(url, server) {
5577
5577
  var main$1 = {exports: {}};
5578
5578
 
5579
5579
  var name = "dotenv";
5580
- var version$1 = "16.4.1";
5580
+ var version$1 = "16.4.2";
5581
5581
  var description = "Loads environment variables from .env file";
5582
5582
  var main = "lib/main.js";
5583
5583
  var types = "lib/main.d.ts";
@@ -5608,7 +5608,7 @@ var repository = {
5608
5608
  type: "git",
5609
5609
  url: "git://github.com/motdotla/dotenv.git"
5610
5610
  };
5611
- var funding = "https://github.com/motdotla/dotenv?sponsor=1";
5611
+ var funding = "https://dotenvx.com";
5612
5612
  var keywords = [
5613
5613
  "dotenv",
5614
5614
  "env",
@@ -5717,7 +5717,7 @@ function _parseVault (options) {
5717
5717
  }
5718
5718
 
5719
5719
  // handle scenario for comma separated keys - for use with key rotation
5720
- // example: DOTENV_KEY="dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenv.org/vault/.env.vault?environment=prod"
5720
+ // example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
5721
5721
  const keys = _dotenvKey(options).split(',');
5722
5722
  const length = keys.length;
5723
5723
 
@@ -5781,7 +5781,7 @@ function _instructions (result, dotenvKey) {
5781
5781
  uri = new URL(dotenvKey);
5782
5782
  } catch (error) {
5783
5783
  if (error.code === 'ERR_INVALID_URL') {
5784
- const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development');
5784
+ const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
5785
5785
  err.code = 'INVALID_DOTENV_KEY';
5786
5786
  throw err
5787
5787
  }
@@ -6011,81 +6011,80 @@ main$1.exports.populate = DotenvModule.populate;
6011
6011
 
6012
6012
  main$1.exports = DotenvModule;
6013
6013
 
6014
- // like String.prototype.search but returns the last index
6015
- function _searchLast (str, rgx) {
6016
- const matches = Array.from(str.matchAll(rgx));
6017
- return matches.length > 0 ? matches.slice(-1)[0].index : -1
6018
- }
6014
+ // * /
6015
+ // * (\\)? # is it escaped with a backslash?
6016
+ // * (\$) # literal $
6017
+ // * (?!\() # shouldnt be followed by parenthesis
6018
+ // * (\{?) # first brace wrap opening
6019
+ // * ([\w.]+) # key
6020
+ // * (?::-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))? # optional default nested 3 times
6021
+ // * (\}?) # last brace warp closing
6022
+ // * /xi
6019
6023
 
6020
- function _interpolate (envValue, environment, config) {
6021
- // find the last unescaped dollar sign in the
6022
- // value so that we can evaluate it
6023
- const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
6024
+ const DOTENV_SUBSTITUTION_REGEX = /(\\)?(\$)(?!\()(\{?)([\w.]+)(?::?-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))?(\}?)/gi;
6024
6025
 
6025
- // If we couldn't match any unescaped dollar sign
6026
- // let's return the string as is
6027
- if (lastUnescapedDollarSignIndex === -1) return envValue
6026
+ function _resolveEscapeSequences (value) {
6027
+ return value.replace(/\\\$/g, '$')
6028
+ }
6028
6029
 
6029
- // This is the right-most group of variables in the string
6030
- const rightMostGroup = envValue.slice(lastUnescapedDollarSignIndex);
6030
+ function interpolate (value, processEnv, parsed) {
6031
+ return value.replace(DOTENV_SUBSTITUTION_REGEX, (match, escaped, dollarSign, openBrace, key, defaultValue, closeBrace) => {
6032
+ if (escaped === '\\') {
6033
+ return match.slice(1)
6034
+ } else {
6035
+ if (processEnv[key]) {
6036
+ return processEnv[key]
6037
+ }
6031
6038
 
6032
- /**
6033
- * This finds the inner most variable/group divided
6034
- * by variable name and default value (if present)
6035
- * (
6036
- * (?!(?<=\\))\$ // only match dollar signs that are not escaped
6037
- * {? // optional opening curly brace
6038
- * ([\w]+) // match the variable name
6039
- * (?::-([^}\\]*))? // match an optional default value
6040
- * }? // optional closing curly brace
6041
- * )
6042
- */
6043
- const matchGroup = /((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;
6044
- const match = rightMostGroup.match(matchGroup);
6045
-
6046
- if (match != null) {
6047
- const [, group, variableName, defaultValue] = match;
6048
-
6049
- return _interpolate(
6050
- envValue.replace(
6051
- group,
6052
- environment[variableName] ||
6053
- defaultValue ||
6054
- config.parsed[variableName] ||
6055
- ''
6056
- ),
6057
- environment,
6058
- config
6059
- )
6060
- }
6039
+ if (parsed[key]) {
6040
+ return parsed[key]
6041
+ }
6061
6042
 
6062
- return envValue
6063
- }
6043
+ if (defaultValue) {
6044
+ if (defaultValue.startsWith('$')) {
6045
+ return interpolate(defaultValue, processEnv, parsed)
6046
+ } else {
6047
+ return defaultValue
6048
+ }
6049
+ }
6064
6050
 
6065
- function _resolveEscapeSequences (value) {
6066
- return value.replace(/\\\$/g, '$')
6051
+ return ''
6052
+ }
6053
+ })
6067
6054
  }
6068
6055
 
6069
- function expand (config) {
6070
- // if ignoring process.env, use a blank object
6071
- const environment = config.ignoreProcessEnv ? {} : process.env;
6056
+ function expand (options) {
6057
+ let processEnv = process.env;
6058
+ if (options && options.processEnv != null) {
6059
+ processEnv = options.processEnv;
6060
+ }
6061
+
6062
+ for (const key in options.parsed) {
6063
+ let value = options.parsed[key];
6072
6064
 
6073
- for (const configKey in config.parsed) {
6074
- const value = Object.prototype.hasOwnProperty.call(environment, configKey)
6075
- ? environment[configKey]
6076
- : config.parsed[configKey];
6065
+ const inProcessEnv = Object.prototype.hasOwnProperty.call(processEnv, key);
6077
6066
 
6078
- config.parsed[configKey] = _resolveEscapeSequences(
6079
- _interpolate(value, environment, config)
6080
- );
6067
+ if (inProcessEnv) {
6068
+ if (processEnv[key] === options.parsed[key]) {
6069
+ // assume was set to processEnv from the .env file if the values match and therefore interpolate
6070
+ value = interpolate(value, processEnv, options.parsed);
6071
+ } else {
6072
+ // do not interpolate - assume processEnv had the intended value even if containing a $.
6073
+ value = processEnv[key];
6074
+ }
6075
+ } else {
6076
+ // not inProcessEnv so assume interpolation for this .env key
6077
+ value = interpolate(value, processEnv, options.parsed);
6078
+ }
6079
+
6080
+ options.parsed[key] = _resolveEscapeSequences(value);
6081
6081
  }
6082
6082
 
6083
- // PATCH: don't write to process.env
6084
- // for (const processKey in config.parsed) {
6085
- // environment[processKey] = config.parsed[processKey]
6086
- // }
6083
+ for (const processKey in options.parsed) {
6084
+ processEnv[processKey] = options.parsed[processKey];
6085
+ }
6087
6086
 
6088
- return config
6087
+ return options
6089
6088
  }
6090
6089
 
6091
6090
  var expand_1 = expand;
@@ -6122,9 +6121,10 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
6122
6121
  if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {
6123
6122
  process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
6124
6123
  }
6125
- // let environment variables use each other
6126
- // `expand` patched in patches/dotenv-expand@9.0.0.patch
6127
- expand_1({ parsed });
6124
+ // let environment variables use each other. make a copy of `process.env` so that `dotenv-expand`
6125
+ // doesn't re-assign the expanded values to the global `process.env`.
6126
+ const processEnv = { ...process.env };
6127
+ expand_1({ parsed, processEnv });
6128
6128
  // only keys that start with prefix are exposed to client
6129
6129
  for (const [key, value] of Object.entries(parsed)) {
6130
6130
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -103,8 +103,8 @@
103
103
  "cross-spawn": "^7.0.3",
104
104
  "debug": "^4.3.4",
105
105
  "dep-types": "link:./src/types",
106
- "dotenv": "^16.4.1",
107
- "dotenv-expand": "^10.0.0",
106
+ "dotenv": "^16.4.2",
107
+ "dotenv-expand": "^11.0.3",
108
108
  "es-module-lexer": "^1.4.1",
109
109
  "escape-html": "^1.0.3",
110
110
  "estree-walker": "^3.0.3",