vite 5.1.0 → 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.
package/LICENSE.md CHANGED
@@ -1912,7 +1912,7 @@ Repository: lydell/js-tokens
1912
1912
 
1913
1913
  > The MIT License (MIT)
1914
1914
  >
1915
- > Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
1915
+ > Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Simon Lydell
1916
1916
  >
1917
1917
  > Permission is hereby granted, free of charge, to any person obtaining a copy
1918
1918
  > of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- import { C as commonjsGlobal, B as getDefaultExportFromCjs } from './dep-nGG-_oRu.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');
@@ -15995,6 +15984,7 @@ function svgToDataURL(content) {
15995
15984
  }
15996
15985
  }
15997
15986
 
15987
+ const endsWithJSRE = /\.[cm]?js$/;
15998
15988
  function manifestPlugin(config) {
15999
15989
  const manifest = {};
16000
15990
  let outputCount;
@@ -16085,7 +16075,8 @@ function manifestPlugin(config) {
16085
16075
  const asset = createAsset(chunk, src, assetMeta?.isEntry);
16086
16076
  // If JS chunk and asset chunk are both generated from the same source file,
16087
16077
  // prioritize JS chunk as it contains more information
16088
- if (manifest[src]?.file.endsWith('.js'))
16078
+ const file = manifest[src]?.file;
16079
+ if (file && endsWithJSRE.test(file))
16089
16080
  continue;
16090
16081
  manifest[src] = asset;
16091
16082
  fileNameToAsset.set(chunk.fileName, asset);
@@ -29137,19 +29128,19 @@ var postcssrc = /*@__PURE__*/getDefaultExportFromCjs(src$1);
29137
29128
  // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
29138
29129
  // License: MIT.
29139
29130
  var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
29140
- RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
29131
+ RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:[^\]\\\n\r\u2028\u2029]+|\\.)*\]|[^\/\\\n\r\u2028\u2029]+|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
29141
29132
  Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
29142
- Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
29143
- StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
29133
+ Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]+|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
29134
+ StringLiteral = /(['"])(?:[^'"\\\n\r]+|(?!\1)['"]|\\(?:\r\n|[^]))*(\1)?/y;
29144
29135
  NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
29145
- Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
29136
+ Template = /[`}](?:[^`\\$]+|\\[^]|\$(?!\{))*(`|\$\{)?/y;
29146
29137
  WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
29147
29138
  LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
29148
- MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
29139
+ MultiLineComment = /\/\*(?:[^*]+|\*(?!\/))*(\*\/)?/y;
29149
29140
  SingleLineComment = /\/\/.*/y;
29150
29141
  JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
29151
29142
  JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
29152
- JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
29143
+ JSXString = /(['"])(?:[^'"]+|(?!\1)['"])*(\1)?/y;
29153
29144
  JSXText = /[^<>{}]+/y;
29154
29145
  TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
29155
29146
  TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
@@ -29601,7 +29592,7 @@ function stripLiteralDetailed(code, options) {
29601
29592
  var main$1 = {exports: {}};
29602
29593
 
29603
29594
  var name = "dotenv";
29604
- var version$2 = "16.4.1";
29595
+ var version$2 = "16.4.2";
29605
29596
  var description = "Loads environment variables from .env file";
29606
29597
  var main = "lib/main.js";
29607
29598
  var types$2 = "lib/main.d.ts";
@@ -29632,7 +29623,7 @@ var repository = {
29632
29623
  type: "git",
29633
29624
  url: "git://github.com/motdotla/dotenv.git"
29634
29625
  };
29635
- var funding = "https://github.com/motdotla/dotenv?sponsor=1";
29626
+ var funding = "https://dotenvx.com";
29636
29627
  var keywords$2 = [
29637
29628
  "dotenv",
29638
29629
  "env",
@@ -29741,7 +29732,7 @@ function _parseVault (options) {
29741
29732
  }
29742
29733
 
29743
29734
  // handle scenario for comma separated keys - for use with key rotation
29744
- // 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"
29745
29736
  const keys = _dotenvKey(options).split(',');
29746
29737
  const length = keys.length;
29747
29738
 
@@ -29805,7 +29796,7 @@ function _instructions (result, dotenvKey) {
29805
29796
  uri = new URL(dotenvKey);
29806
29797
  } catch (error) {
29807
29798
  if (error.code === 'ERR_INVALID_URL') {
29808
- 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');
29809
29800
  err.code = 'INVALID_DOTENV_KEY';
29810
29801
  throw err
29811
29802
  }
@@ -30035,81 +30026,80 @@ main$1.exports.populate = DotenvModule.populate;
30035
30026
 
30036
30027
  main$1.exports = DotenvModule;
30037
30028
 
30038
- // like String.prototype.search but returns the last index
30039
- function _searchLast (str, rgx) {
30040
- const matches = Array.from(str.matchAll(rgx));
30041
- return matches.length > 0 ? matches.slice(-1)[0].index : -1
30042
- }
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
30043
30038
 
30044
- function _interpolate (envValue, environment, config) {
30045
- // find the last unescaped dollar sign in the
30046
- // value so that we can evaluate it
30047
- const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
30039
+ const DOTENV_SUBSTITUTION_REGEX = /(\\)?(\$)(?!\()(\{?)([\w.]+)(?::?-((?:\$\{(?:\$\{(?:\$\{[^}]*\}|[^}])*}|[^}])*}|[^}])+))?(\}?)/gi;
30048
30040
 
30049
- // If we couldn't match any unescaped dollar sign
30050
- // let's return the string as is
30051
- if (lastUnescapedDollarSignIndex === -1) return envValue
30041
+ function _resolveEscapeSequences (value) {
30042
+ return value.replace(/\\\$/g, '$')
30043
+ }
30052
30044
 
30053
- // This is the right-most group of variables in the string
30054
- 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
+ }
30055
30053
 
30056
- /**
30057
- * This finds the inner most variable/group divided
30058
- * by variable name and default value (if present)
30059
- * (
30060
- * (?!(?<=\\))\$ // only match dollar signs that are not escaped
30061
- * {? // optional opening curly brace
30062
- * ([\w]+) // match the variable name
30063
- * (?::-([^}\\]*))? // match an optional default value
30064
- * }? // optional closing curly brace
30065
- * )
30066
- */
30067
- const matchGroup = /((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;
30068
- const match = rightMostGroup.match(matchGroup);
30069
-
30070
- if (match != null) {
30071
- const [, group, variableName, defaultValue] = match;
30072
-
30073
- return _interpolate(
30074
- envValue.replace(
30075
- group,
30076
- environment[variableName] ||
30077
- defaultValue ||
30078
- config.parsed[variableName] ||
30079
- ''
30080
- ),
30081
- environment,
30082
- config
30083
- )
30084
- }
30054
+ if (parsed[key]) {
30055
+ return parsed[key]
30056
+ }
30085
30057
 
30086
- return envValue
30087
- }
30058
+ if (defaultValue) {
30059
+ if (defaultValue.startsWith('$')) {
30060
+ return interpolate(defaultValue, processEnv, parsed)
30061
+ } else {
30062
+ return defaultValue
30063
+ }
30064
+ }
30088
30065
 
30089
- function _resolveEscapeSequences (value) {
30090
- return value.replace(/\\\$/g, '$')
30066
+ return ''
30067
+ }
30068
+ })
30091
30069
  }
30092
30070
 
30093
- function expand (config) {
30094
- // if ignoring process.env, use a blank object
30095
- 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
+ }
30096
30076
 
30097
- for (const configKey in config.parsed) {
30098
- const value = Object.prototype.hasOwnProperty.call(environment, configKey)
30099
- ? environment[configKey]
30100
- : config.parsed[configKey];
30077
+ for (const key in options.parsed) {
30078
+ let value = options.parsed[key];
30101
30079
 
30102
- config.parsed[configKey] = _resolveEscapeSequences(
30103
- _interpolate(value, environment, config)
30104
- );
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);
30105
30096
  }
30106
30097
 
30107
- // PATCH: don't write to process.env
30108
- // for (const processKey in config.parsed) {
30109
- // environment[processKey] = config.parsed[processKey]
30110
- // }
30098
+ for (const processKey in options.parsed) {
30099
+ processEnv[processKey] = options.parsed[processKey];
30100
+ }
30111
30101
 
30112
- return config
30102
+ return options
30113
30103
  }
30114
30104
 
30115
30105
  var expand_1 = expand;
@@ -30146,9 +30136,10 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
30146
30136
  if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {
30147
30137
  process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
30148
30138
  }
30149
- // let environment variables use each other
30150
- // `expand` patched in patches/dotenv-expand@9.0.0.patch
30151
- 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 });
30152
30143
  // only keys that start with prefix are exposed to client
30153
30144
  for (const [key, value] of Object.entries(parsed)) {
30154
30145
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
@@ -31551,75 +31542,74 @@ function cssPostPlugin(config) {
31551
31542
  s.update(start, end, replacementString);
31552
31543
  }
31553
31544
  }
31554
- if (!chunkCSS && !s) {
31555
- return null;
31556
- }
31557
- if (config.build.cssCodeSplit) {
31558
- if (opts.format === 'es' || opts.format === 'cjs') {
31559
- if (isPureCssChunk) {
31560
- // this is a shared CSS-only chunk that is empty.
31561
- pureCssChunks.add(chunk);
31562
- }
31563
- const isEntry = chunk.isEntry && isPureCssChunk;
31564
- const cssFullAssetName = ensureFileExt(chunk.name, '.css');
31565
- // if facadeModuleId doesn't exist or doesn't have a CSS extension,
31566
- // that means a JS entry file imports a CSS file.
31567
- // in this case, only use the filename for the CSS chunk name like JS chunks.
31568
- const cssAssetName = chunk.isEntry &&
31569
- (!chunk.facadeModuleId || !isCSSRequest(chunk.facadeModuleId))
31570
- ? path$o.basename(cssFullAssetName)
31571
- : cssFullAssetName;
31572
- const originalFilename = getChunkOriginalFileName(chunk, config.root, opts.format);
31573
- chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssAssetName);
31574
- // wait for previous tasks as well
31575
- chunkCSS = await codeSplitEmitQueue.run(async () => {
31576
- return finalizeCss(chunkCSS, true, config);
31577
- });
31578
- // emit corresponding css file
31579
- const referenceId = this.emitFile({
31580
- name: cssAssetName,
31581
- type: 'asset',
31582
- source: chunkCSS,
31583
- });
31584
- generatedAssets
31585
- .get(config)
31586
- .set(referenceId, { originalName: originalFilename, isEntry });
31587
- chunk.viteMetadata.importedCss.add(this.getFileName(referenceId));
31588
- }
31589
- else if (!config.build.ssr) {
31590
- // legacy build and inline css
31591
- // Entry chunk CSS will be collected into `chunk.viteMetadata.importedCss`
31592
- // and injected later by the `'vite:build-html'` plugin into the `index.html`
31593
- // so it will be duplicated. (https://github.com/vitejs/vite/issues/2062#issuecomment-782388010)
31594
- // But because entry chunk can be imported by dynamic import,
31595
- // we shouldn't remove the inlined CSS. (#10285)
31596
- chunkCSS = await finalizeCss(chunkCSS, true, config);
31597
- let cssString = JSON.stringify(chunkCSS);
31598
- cssString =
31599
- renderAssetUrlInJS(this, config, chunk, opts, cssString)?.toString() || cssString;
31600
- const style = `__vite_style__`;
31601
- const injectCode = `var ${style} = document.createElement('style');` +
31602
- `${style}.textContent = ${cssString};` +
31603
- `document.head.appendChild(${style});`;
31604
- let injectionPoint;
31605
- const wrapIdx = code.indexOf('System.register');
31606
- if (wrapIdx >= 0) {
31607
- const executeFnStart = code.indexOf('execute:', wrapIdx);
31608
- injectionPoint = code.indexOf('{', executeFnStart) + 1;
31545
+ if (chunkCSS) {
31546
+ if (config.build.cssCodeSplit) {
31547
+ if (opts.format === 'es' || opts.format === 'cjs') {
31548
+ if (isPureCssChunk) {
31549
+ // this is a shared CSS-only chunk that is empty.
31550
+ pureCssChunks.add(chunk);
31551
+ }
31552
+ const isEntry = chunk.isEntry && isPureCssChunk;
31553
+ const cssFullAssetName = ensureFileExt(chunk.name, '.css');
31554
+ // if facadeModuleId doesn't exist or doesn't have a CSS extension,
31555
+ // that means a JS entry file imports a CSS file.
31556
+ // in this case, only use the filename for the CSS chunk name like JS chunks.
31557
+ const cssAssetName = chunk.isEntry &&
31558
+ (!chunk.facadeModuleId || !isCSSRequest(chunk.facadeModuleId))
31559
+ ? path$o.basename(cssFullAssetName)
31560
+ : cssFullAssetName;
31561
+ const originalFilename = getChunkOriginalFileName(chunk, config.root, opts.format);
31562
+ chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssAssetName);
31563
+ // wait for previous tasks as well
31564
+ chunkCSS = await codeSplitEmitQueue.run(async () => {
31565
+ return finalizeCss(chunkCSS, true, config);
31566
+ });
31567
+ // emit corresponding css file
31568
+ const referenceId = this.emitFile({
31569
+ name: cssAssetName,
31570
+ type: 'asset',
31571
+ source: chunkCSS,
31572
+ });
31573
+ generatedAssets
31574
+ .get(config)
31575
+ .set(referenceId, { originalName: originalFilename, isEntry });
31576
+ chunk.viteMetadata.importedCss.add(this.getFileName(referenceId));
31609
31577
  }
31610
- else {
31611
- const insertMark = "'use strict';";
31612
- injectionPoint = code.indexOf(insertMark) + insertMark.length;
31578
+ else if (!config.build.ssr) {
31579
+ // legacy build and inline css
31580
+ // Entry chunk CSS will be collected into `chunk.viteMetadata.importedCss`
31581
+ // and injected later by the `'vite:build-html'` plugin into the `index.html`
31582
+ // so it will be duplicated. (https://github.com/vitejs/vite/issues/2062#issuecomment-782388010)
31583
+ // But because entry chunk can be imported by dynamic import,
31584
+ // we shouldn't remove the inlined CSS. (#10285)
31585
+ chunkCSS = await finalizeCss(chunkCSS, true, config);
31586
+ let cssString = JSON.stringify(chunkCSS);
31587
+ cssString =
31588
+ renderAssetUrlInJS(this, config, chunk, opts, cssString)?.toString() || cssString;
31589
+ const style = `__vite_style__`;
31590
+ const injectCode = `var ${style} = document.createElement('style');` +
31591
+ `${style}.textContent = ${cssString};` +
31592
+ `document.head.appendChild(${style});`;
31593
+ let injectionPoint;
31594
+ const wrapIdx = code.indexOf('System.register');
31595
+ if (wrapIdx >= 0) {
31596
+ const executeFnStart = code.indexOf('execute:', wrapIdx);
31597
+ injectionPoint = code.indexOf('{', executeFnStart) + 1;
31598
+ }
31599
+ else {
31600
+ const insertMark = "'use strict';";
31601
+ injectionPoint = code.indexOf(insertMark) + insertMark.length;
31602
+ }
31603
+ s ||= new MagicString(code);
31604
+ s.appendRight(injectionPoint, injectCode);
31613
31605
  }
31614
- s ||= new MagicString(code);
31615
- s.appendRight(injectionPoint, injectCode);
31616
31606
  }
31617
- }
31618
- else {
31619
- // resolve public URL from CSS paths, we need to use absolute paths
31620
- chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssBundleName);
31621
- // finalizeCss is called for the aggregated chunk in generateBundle
31622
- chunkCSSMap.set(chunk.fileName, chunkCSS);
31607
+ else {
31608
+ // resolve public URL from CSS paths, we need to use absolute paths
31609
+ chunkCSS = resolveAssetUrlsInCss(chunkCSS, cssBundleName);
31610
+ // finalizeCss is called for the aggregated chunk in generateBundle
31611
+ chunkCSSMap.set(chunk.fileName, chunkCSS);
31612
+ }
31623
31613
  }
31624
31614
  if (s) {
31625
31615
  if (config.build.sourcemap) {
@@ -32081,8 +32071,8 @@ function createCachedImport(imp) {
32081
32071
  return cached;
32082
32072
  };
32083
32073
  }
32084
- const importPostcssImport = createCachedImport(() => import('./dep-QywIN17l.js').then(function (n) { return n.i; }));
32085
- const importPostcssModules = createCachedImport(() => import('./dep-BWGc69YA.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; }));
32086
32076
  const importPostcss = createCachedImport(() => import('postcss'));
32087
32077
  const preprocessorWorkerControllerCache = new WeakMap();
32088
32078
  let alwaysFakeWorkerWorkerControllerCache;
@@ -49246,10 +49236,11 @@ function webWorkerPlugin(config) {
49246
49236
  // Using blob URL for SharedWorker results in multiple instances of a same worker
49247
49237
  workerConstructor === 'Worker'
49248
49238
  ? `${encodedJs}
49239
+ const decodeBase64 = (base64) => Uint8Array.from(atob(base64), c => c.charCodeAt(0));
49249
49240
  const blob = typeof window !== "undefined" && window.Blob && new Blob([${workerType === 'classic'
49250
49241
  ? ''
49251
49242
  : // `URL` is always available, in `Worker[type="module"]`
49252
- `'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" });
49253
49244
  export default function WorkerWrapper(options) {
49254
49245
  let objURL;
49255
49246
  try {
@@ -56179,7 +56170,7 @@ async function fetchModule(server, url, importer, options = {}) {
56179
56170
  throw err;
56180
56171
  }
56181
56172
  const file = pathToFileURL(resolved.id).toString();
56182
- const type = isFilePathESM(file, server.config.packageCache)
56173
+ const type = isFilePathESM(resolved.id, server.config.packageCache)
56183
56174
  ? 'module'
56184
56175
  : 'commonjs';
56185
56176
  return { externalize: file, type };
@@ -65557,7 +65548,7 @@ function importAnalysisPlugin(config) {
65557
65548
  }
65558
65549
  // fix#9534, prevent the importerModuleNode being stopped from propagating updates
65559
65550
  importerModule.isSelfAccepting = false;
65560
- 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);
65561
65552
  }
65562
65553
  if (isExternalUrl(resolved.id)) {
65563
65554
  return [resolved.id, resolved.id];
@@ -66792,6 +66783,7 @@ async function build(inlineConfig = {}) {
66792
66783
  config.logger.error(msg, { error: e });
66793
66784
  };
66794
66785
  let bundle;
66786
+ let startTime;
66795
66787
  try {
66796
66788
  const buildOutputOptions = (output = {}) => {
66797
66789
  // @ts-expect-error See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
@@ -66889,6 +66881,7 @@ async function build(inlineConfig = {}) {
66889
66881
  }
66890
66882
  // write or generate files with rollup
66891
66883
  const { rollup } = await import('rollup');
66884
+ startTime = Date.now();
66892
66885
  bundle = await rollup(rollupOptions);
66893
66886
  if (options.write) {
66894
66887
  prepareOutDir(outDirs, options.emptyOutDir, config);
@@ -66897,11 +66890,16 @@ async function build(inlineConfig = {}) {
66897
66890
  for (const output of normalizedOutputs) {
66898
66891
  res.push(await bundle[options.write ? 'write' : 'generate'](output));
66899
66892
  }
66893
+ config.logger.info(`${colors$1.green(`✓ built in ${displayTime(Date.now() - startTime)}`)}`);
66900
66894
  return Array.isArray(outputs) ? res : res[0];
66901
66895
  }
66902
66896
  catch (e) {
66903
66897
  e.message = mergeRollupError(e);
66904
66898
  clearLine();
66899
+ if (startTime) {
66900
+ config.logger.error(`${colors$1.red('x')} Build failed in ${displayTime(Date.now() - startTime)}`);
66901
+ startTime = undefined;
66902
+ }
66905
66903
  throw e;
66906
66904
  }
66907
66905
  finally {
@@ -1,4 +1,4 @@
1
- import { B as getDefaultExportFromCjs } from './dep-nGG-_oRu.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-nGG-_oRu.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-nGG-_oRu.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-nGG-_oRu.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-nGG-_oRu.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-nGG-_oRu.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-nGG-_oRu.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-nGG-_oRu.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.0",
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",