vite 5.0.0-beta.3 → 5.0.0-beta.5

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.
@@ -23,7 +23,7 @@ import os$4 from 'node:os';
23
23
  import { exec } from 'node:child_process';
24
24
  import { createHash as createHash$2 } from 'node:crypto';
25
25
  import { promises } from 'node:dns';
26
- import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, VALID_ID_PREFIX, NULL_BYTE_PLACEHOLDER, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, ENV_ENTRY, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS as DEFAULT_EXTENSIONS$1, SPECIAL_QUERY_RE, CSS_LANGS_RE, ESBUILD_MODULES_TARGET, KNOWN_ASSET_TYPES, CLIENT_DIR, JS_TYPES_RE, VERSION as VERSION$1, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
26
+ import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, VALID_ID_PREFIX, NULL_BYTE_PLACEHOLDER, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, ENV_ENTRY, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, SPECIAL_QUERY_RE, CSS_LANGS_RE, ESBUILD_MODULES_TARGET, KNOWN_ASSET_TYPES, CLIENT_DIR, JS_TYPES_RE, VERSION as VERSION$1, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
27
27
  import require$$3$1 from 'crypto';
28
28
  import { Buffer as Buffer$1 } from 'node:buffer';
29
29
  import require$$0$8, { createRequire as createRequire$2 } from 'module';
@@ -7460,9 +7460,9 @@ function isReference(node, parent) {
7460
7460
  return false;
7461
7461
  }
7462
7462
 
7463
- var version$3 = "25.0.4";
7463
+ var version$3 = "25.0.5";
7464
7464
  var peerDependencies = {
7465
- rollup: "^2.68.0||^3.0.0"
7465
+ rollup: "^2.68.0||^3.0.0||^4.0.0"
7466
7466
  };
7467
7467
 
7468
7468
  function tryParse(parse, code, id) {
@@ -7485,6 +7485,7 @@ function hasCjsKeywords(code, ignoreGlobal) {
7485
7485
 
7486
7486
  /* eslint-disable no-underscore-dangle */
7487
7487
 
7488
+
7488
7489
  function analyzeTopLevelStatements(parse, code, id) {
7489
7490
  const ast = tryParse(parse, code, id);
7490
7491
 
@@ -7531,6 +7532,7 @@ function analyzeTopLevelStatements(parse, code, id) {
7531
7532
 
7532
7533
  /* eslint-disable import/prefer-default-export */
7533
7534
 
7535
+
7534
7536
  function deconflict(scopes, globals, identifier) {
7535
7537
  let i = 1;
7536
7538
  let deconflicted = makeLegalIdentifier(identifier);
@@ -7919,6 +7921,7 @@ function getEsImportProxy(id, defaultIsModuleExports) {
7919
7921
 
7920
7922
  /* eslint-disable no-param-reassign, no-undefined */
7921
7923
 
7924
+
7922
7925
  function getCandidatesForExtension(resolved, extension) {
7923
7926
  return [resolved + extension, `${resolved}${sep}index${extension}`];
7924
7927
  }
@@ -8229,6 +8232,7 @@ function getRequireResolver(extensions, detectCyclesAndConditional, currentlyRes
8229
8232
  currentlyResolvingForParent.add(source);
8230
8233
  const resolved =
8231
8234
  (await rollupContext.resolve(source, parentId, {
8235
+ skipSelf: false,
8232
8236
  custom: { 'node-resolve': { isRequire: true } }
8233
8237
  })) || resolveExtensions(source, parentId, extensions);
8234
8238
  currentlyResolvingForParent.delete(source);
@@ -8897,6 +8901,7 @@ function getGenerateRequireName() {
8897
8901
 
8898
8902
  /* eslint-disable no-param-reassign, no-shadow, no-underscore-dangle, no-continue */
8899
8903
 
8904
+
8900
8905
  const exportsPattern = /^(?:module\.)?exports(?:\.([a-zA-Z_$][a-zA-Z_$0-9]*))?$/;
8901
8906
 
8902
8907
  const functionType = /^(?:FunctionDeclaration|FunctionExpression|ArrowFunctionExpression)$/;
@@ -9167,6 +9172,9 @@ async function transformCommonjs(
9167
9172
  }
9168
9173
  if (!ignoreDynamicRequires) {
9169
9174
  if (isShorthandProperty(parent)) {
9175
+ // as key and value are the same object, isReference regards
9176
+ // both as references, so we need to skip now
9177
+ skippedNodes.add(parent.value);
9170
9178
  magicString.prependRight(node.start, 'require: ');
9171
9179
  }
9172
9180
  replacedDynamicRequires.push(node);
@@ -9709,7 +9717,7 @@ function commonjs(options = {}) {
9709
9717
  try {
9710
9718
  return transformAndCheckExports.call(this, code, id);
9711
9719
  } catch (err) {
9712
- return this.error(err, err.loc);
9720
+ return this.error(err, err.pos);
9713
9721
  }
9714
9722
  }
9715
9723
  };
@@ -12291,9 +12299,9 @@ function windowsSafeRealPathSync(path) {
12291
12299
  return fs$l.realpathSync(path);
12292
12300
  }
12293
12301
  function optimizeSafeRealPathSync() {
12294
- // Skip if using Node <16.18 due to MAX_PATH issue: https://github.com/vitejs/vite/issues/12931
12302
+ // Skip if using Node <18.10 due to MAX_PATH issue: https://github.com/vitejs/vite/issues/12931
12295
12303
  const nodeVersion = process.versions.node.split('.').map(Number);
12296
- if (nodeVersion[0] < 16 || (nodeVersion[0] === 16 && nodeVersion[1] < 18)) {
12304
+ if (nodeVersion[0] < 18 || (nodeVersion[0] === 18 && nodeVersion[1] < 10)) {
12297
12305
  safeRealpathSync = fs$l.realpathSync;
12298
12306
  return;
12299
12307
  }
@@ -12565,20 +12573,12 @@ function arraify(target) {
12565
12573
  const multilineCommentsRE$1 = /\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g;
12566
12574
  const singlelineCommentsRE$1 = /\/\/.*/g;
12567
12575
  const requestQuerySplitRE = /\?(?!.*[/|}])/;
12568
- // @ts-expect-error jest only exists when running Jest
12569
- const usingDynamicImport = typeof jest === 'undefined';
12570
12576
  /**
12571
12577
  * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
12572
12578
  *
12573
- * As a temporary workaround for Jest's lack of stable ESM support, we fallback to require
12574
- * if we're in a Jest environment.
12575
- * See https://github.com/vitejs/vite/pull/5197#issuecomment-938054077
12576
- *
12577
12579
  * @param file File path to import.
12578
12580
  */
12579
- const dynamicImport = usingDynamicImport
12580
- ? new Function('file', 'return import(file)')
12581
- : _require$2;
12581
+ const dynamicImport = new Function('file', 'return import(file)');
12582
12582
  function parseRequest(id) {
12583
12583
  const [_, search] = id.split(requestQuerySplitRE, 2);
12584
12584
  if (!search) {
@@ -13215,11 +13215,13 @@ const NATIVE_SEP_RE = new RegExp('\\' + path$o.sep, 'g');
13215
13215
  /** @type {Map<string,RegExp>}*/
13216
13216
  const PATTERN_REGEX_CACHE = new Map();
13217
13217
  const GLOB_ALL_PATTERN = `**/*`;
13218
- const DEFAULT_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts'];
13219
- const DEFAULT_EXTENSIONS_RE_GROUP = `\\.(?:${DEFAULT_EXTENSIONS.map((ext) => ext.substring(1)).join(
13218
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts'];
13219
+ const JS_EXTENSIONS = ['.js', '.jsx', '.mjs', '.cjs'];
13220
+ const TSJS_EXTENSIONS = TS_EXTENSIONS.concat(JS_EXTENSIONS);
13221
+ const TS_EXTENSIONS_RE_GROUP = `\\.(?:${TS_EXTENSIONS.map((ext) => ext.substring(1)).join('|')})`;
13222
+ const TSJS_EXTENSIONS_RE_GROUP = `\\.(?:${TSJS_EXTENSIONS.map((ext) => ext.substring(1)).join(
13220
13223
  '|'
13221
13224
  )})`;
13222
-
13223
13225
  const IS_POSIX = path$o.posix.sep === path$o.sep;
13224
13226
 
13225
13227
  /**
@@ -13245,10 +13247,8 @@ async function resolveTSConfigJson(filename, cache) {
13245
13247
  return; // ignore files that are not json
13246
13248
  }
13247
13249
  const tsconfig = path$o.resolve(filename);
13248
- if (cache) {
13249
- if (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename)) {
13250
- return tsconfig;
13251
- }
13250
+ if (cache && (cache.hasParseResult(tsconfig) || cache.hasParseResult(filename))) {
13251
+ return tsconfig;
13252
13252
  }
13253
13253
  return promises$1.stat(tsconfig).then((stat) => {
13254
13254
  if (stat.isFile() || stat.isFIFO()) {
@@ -13317,12 +13317,15 @@ const resolve2posix = IS_POSIX
13317
13317
  /**
13318
13318
  *
13319
13319
  * @param {import('./public.d.ts').TSConfckParseResult} result
13320
+ * @param {import('./public.d.ts').TSConfckParseOptions} [options]
13320
13321
  * @returns {string[]}
13321
13322
  */
13322
- function resolveReferencedTSConfigFiles(result) {
13323
+ function resolveReferencedTSConfigFiles(result, options) {
13323
13324
  const dir = path$o.dirname(result.tsconfigFile);
13324
13325
  return result.tsconfig.references.map((ref) => {
13325
- const refPath = ref.path.endsWith('.json') ? ref.path : path$o.join(ref.path, 'tsconfig.json');
13326
+ const refPath = ref.path.endsWith('.json')
13327
+ ? ref.path
13328
+ : path$o.join(ref.path, options?.configName ?? 'tsconfig.json');
13326
13329
  return resolve2posix(dir, refPath);
13327
13330
  });
13328
13331
  }
@@ -13333,9 +13336,11 @@ function resolveReferencedTSConfigFiles(result) {
13333
13336
  * @returns {import('./public.d.ts').TSConfckParseResult}
13334
13337
  */
13335
13338
  function resolveSolutionTSConfig(filename, result) {
13339
+ const allowJs = result.tsconfig.compilerOptions?.allowJs;
13340
+ const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
13336
13341
  if (
13337
13342
  result.referenced &&
13338
- DEFAULT_EXTENSIONS.some((ext) => filename.endsWith(ext)) &&
13343
+ extensions.some((ext) => filename.endsWith(ext)) &&
13339
13344
  !isIncluded(filename, result)
13340
13345
  ) {
13341
13346
  const solutionTSConfig = result.referenced.find((referenced) =>
@@ -13361,13 +13366,15 @@ function isIncluded(filename, result) {
13361
13366
  if (files.includes(filename)) {
13362
13367
  return true;
13363
13368
  }
13369
+ const allowJs = result.tsconfig.compilerOptions?.allowJs;
13364
13370
  const isIncluded = isGlobMatch(
13365
13371
  absoluteFilename,
13366
13372
  dir,
13367
- result.tsconfig.include || (result.tsconfig.files ? [] : [GLOB_ALL_PATTERN])
13373
+ result.tsconfig.include || (result.tsconfig.files ? [] : [GLOB_ALL_PATTERN]),
13374
+ allowJs
13368
13375
  );
13369
13376
  if (isIncluded) {
13370
- const isExcluded = isGlobMatch(absoluteFilename, dir, result.tsconfig.exclude || []);
13377
+ const isExcluded = isGlobMatch(absoluteFilename, dir, result.tsconfig.exclude || [], allowJs);
13371
13378
  return !isExcluded;
13372
13379
  }
13373
13380
  return false;
@@ -13379,9 +13386,11 @@ function isIncluded(filename, result) {
13379
13386
  * @param filename {string} posix style abolute path to filename to test
13380
13387
  * @param dir {string} posix style absolute path to directory of tsconfig containing patterns
13381
13388
  * @param patterns {string[]} glob patterns to match against
13389
+ * @param allowJs {boolean} allowJs setting in tsconfig to include js extensions in checks
13382
13390
  * @returns {boolean} true when at least one pattern matches filename
13383
13391
  */
13384
- function isGlobMatch(filename, dir, patterns) {
13392
+ function isGlobMatch(filename, dir, patterns, allowJs) {
13393
+ const extensions = allowJs ? TSJS_EXTENSIONS : TS_EXTENSIONS;
13385
13394
  return patterns.some((pattern) => {
13386
13395
  // filename must end with part of pattern that comes after last wildcard
13387
13396
  let lastWildcardIndex = pattern.length;
@@ -13403,7 +13412,7 @@ function isGlobMatch(filename, dir, patterns) {
13403
13412
  }
13404
13413
 
13405
13414
  // if pattern ends with *, filename must end with a default extension
13406
- if (pattern.endsWith('*') && !DEFAULT_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
13415
+ if (pattern.endsWith('*') && !extensions.some((ext) => filename.endsWith(ext))) {
13407
13416
  return false;
13408
13417
  }
13409
13418
 
@@ -13439,7 +13448,7 @@ function isGlobMatch(filename, dir, patterns) {
13439
13448
  if (PATTERN_REGEX_CACHE.has(resolvedPattern)) {
13440
13449
  return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
13441
13450
  }
13442
- const regex = pattern2regex(resolvedPattern);
13451
+ const regex = pattern2regex(resolvedPattern, allowJs);
13443
13452
  PATTERN_REGEX_CACHE.set(resolvedPattern, regex);
13444
13453
  return regex.test(filename);
13445
13454
  });
@@ -13447,9 +13456,10 @@ function isGlobMatch(filename, dir, patterns) {
13447
13456
 
13448
13457
  /**
13449
13458
  * @param {string} resolvedPattern
13459
+ * @param {boolean} allowJs
13450
13460
  * @returns {RegExp}
13451
13461
  */
13452
- function pattern2regex(resolvedPattern) {
13462
+ function pattern2regex(resolvedPattern, allowJs) {
13453
13463
  let regexStr = '^';
13454
13464
  for (let i = 0; i < resolvedPattern.length; i++) {
13455
13465
  const char = resolvedPattern[i];
@@ -13474,7 +13484,7 @@ function pattern2regex(resolvedPattern) {
13474
13484
 
13475
13485
  // add known file endings if pattern ends on *
13476
13486
  if (resolvedPattern.endsWith('*')) {
13477
- regexStr += DEFAULT_EXTENSIONS_RE_GROUP;
13487
+ regexStr += allowJs ? TSJS_EXTENSIONS_RE_GROUP : TS_EXTENSIONS_RE_GROUP;
13478
13488
  }
13479
13489
  regexStr += '$';
13480
13490
 
@@ -13494,12 +13504,15 @@ async function find(filename, options) {
13494
13504
  return null;
13495
13505
  }
13496
13506
  const cache = options?.cache;
13497
- if (cache?.hasTSConfigPath(dir)) {
13498
- return cache.getTSConfigPath(dir);
13507
+ const configName = options?.configName ?? 'tsconfig.json';
13508
+ if (cache?.hasConfigPath(dir, configName)) {
13509
+ return cache.getConfigPath(dir, configName);
13499
13510
  }
13500
13511
  const { /** @type {Promise<string|null>} */ promise, resolve, reject } = makePromise();
13501
- const root = options?.root ? path$o.resolve(options.root) : null;
13502
- findUp(dir, { promise, resolve, reject }, options?.cache, root);
13512
+ if (options?.root && !path$o.isAbsolute(options.root)) {
13513
+ options.root = path$o.resolve(options.root);
13514
+ }
13515
+ findUp(dir, { promise, resolve, reject }, options);
13503
13516
  return promise;
13504
13517
  }
13505
13518
 
@@ -13507,16 +13520,15 @@ async function find(filename, options) {
13507
13520
  *
13508
13521
  * @param {string} dir
13509
13522
  * @param {{promise:Promise<string|null>,resolve:(result:string|null)=>void,reject:(err:any)=>void}} madePromise
13510
- * @param {import('./cache.js').TSConfckCache} [cache]
13511
- * @param {string} [root]
13523
+ * @param {import('./public.d.ts').TSConfckFindOptions} [options] - options
13512
13524
  */
13513
- function findUp(dir, { resolve, reject, promise }, cache, root) {
13514
- const tsconfig = path$o.join(dir, 'tsconfig.json');
13525
+ function findUp(dir, { resolve, reject, promise }, options) {
13526
+ const { cache, root, configName } = options ?? {};
13515
13527
  if (cache) {
13516
- if (cache.hasTSConfigPath(dir)) {
13528
+ if (cache.hasConfigPath(dir, configName)) {
13517
13529
  let cached;
13518
13530
  try {
13519
- cached = cache.getTSConfigPath(dir);
13531
+ cached = cache.getConfigPath(dir, configName);
13520
13532
  } catch (e) {
13521
13533
  reject(e);
13522
13534
  return;
@@ -13527,9 +13539,10 @@ function findUp(dir, { resolve, reject, promise }, cache, root) {
13527
13539
  resolve(cached);
13528
13540
  }
13529
13541
  } else {
13530
- cache.setTSConfigPath(dir, promise);
13542
+ cache.setConfigPath(dir, promise, configName);
13531
13543
  }
13532
13544
  }
13545
+ const tsconfig = path$o.join(dir, options?.configName ?? 'tsconfig.json');
13533
13546
  fs$l.stat(tsconfig, (err, stats) => {
13534
13547
  if (stats && (stats.isFile() || stats.isFIFO())) {
13535
13548
  resolve(tsconfig);
@@ -13540,7 +13553,7 @@ function findUp(dir, { resolve, reject, promise }, cache, root) {
13540
13553
  if (root === dir || (parent = path$o.dirname(dir)) === dir) {
13541
13554
  resolve(null);
13542
13555
  } else {
13543
- findUp(parent, { promise, resolve, reject }, cache, root);
13556
+ findUp(parent, { promise, resolve, reject }, options);
13544
13557
  }
13545
13558
  }
13546
13559
  });
@@ -13752,7 +13765,7 @@ async function parse$f(filename, options) {
13752
13765
  result = await cache.getParseResult(tsconfigFile);
13753
13766
  } else {
13754
13767
  result = await parseFile$1(tsconfigFile, cache, filename === tsconfigFile);
13755
- await Promise.all([parseExtends(result, cache), parseReferences(result, cache)]);
13768
+ await Promise.all([parseExtends(result, cache), parseReferences(result, options)]);
13756
13769
  }
13757
13770
  resolve(resolveSolutionTSConfig(filename, result));
13758
13771
  return promise;
@@ -13777,9 +13790,11 @@ async function parseFile$1(tsconfigFile, cache, skipCache) {
13777
13790
  .readFile(tsconfigFile, 'utf-8')
13778
13791
  .then(toJson)
13779
13792
  .then((json) => {
13793
+ const parsed = JSON.parse(json);
13794
+ applyDefaults(parsed, tsconfigFile);
13780
13795
  return {
13781
13796
  tsconfigFile,
13782
- tsconfig: normalizeTSConfig(JSON.parse(json), path$o.dirname(tsconfigFile))
13797
+ tsconfig: normalizeTSConfig(parsed, path$o.dirname(tsconfigFile))
13783
13798
  };
13784
13799
  })
13785
13800
  .catch((e) => {
@@ -13813,16 +13828,18 @@ function normalizeTSConfig(tsconfig, dir) {
13813
13828
  /**
13814
13829
  *
13815
13830
  * @param {import('./public.d.ts').TSConfckParseResult} result
13816
- * @param {import('./cache.js').TSConfckCache} [cache]
13831
+ * @param {import('./public.d.ts').TSConfckParseOptions} [options]
13817
13832
  * @returns {Promise<void>}
13818
13833
  */
13819
- async function parseReferences(result, cache) {
13834
+ async function parseReferences(result, options) {
13820
13835
  if (!result.tsconfig.references) {
13821
13836
  return;
13822
13837
  }
13823
- const referencedFiles = resolveReferencedTSConfigFiles(result);
13824
- const referenced = await Promise.all(referencedFiles.map((file) => parseFile$1(file, cache)));
13825
- await Promise.all(referenced.map((ref) => parseExtends(ref, cache)));
13838
+ const referencedFiles = resolveReferencedTSConfigFiles(result, options);
13839
+ const referenced = await Promise.all(
13840
+ referencedFiles.map((file) => parseFile$1(file, options?.cache))
13841
+ );
13842
+ await Promise.all(referenced.map((ref) => parseExtends(ref, options?.cache)));
13826
13843
  referenced.forEach((ref) => {
13827
13844
  ref.solution = result;
13828
13845
  });
@@ -14074,34 +14091,66 @@ class TSConfckParseError extends Error {
14074
14091
  }
14075
14092
  }
14076
14093
 
14094
+ /**
14095
+ *
14096
+ * @param {any} tsconfig
14097
+ * @param {string} tsconfigFile
14098
+ */
14099
+ function applyDefaults(tsconfig, tsconfigFile) {
14100
+ if (isJSConfig(tsconfigFile)) {
14101
+ tsconfig.compilerOptions = {
14102
+ ...DEFAULT_JSCONFIG_COMPILER_OPTIONS,
14103
+ ...tsconfig.compilerOptions
14104
+ };
14105
+ }
14106
+ }
14107
+
14108
+ const DEFAULT_JSCONFIG_COMPILER_OPTIONS = {
14109
+ allowJs: true,
14110
+ maxNodeModuleJsDepth: 2,
14111
+ allowSyntheticDefaultImports: true,
14112
+ skipLibCheck: true,
14113
+ noEmit: true
14114
+ };
14115
+
14116
+ /**
14117
+ * @param {string} configFileName
14118
+ */
14119
+ function isJSConfig(configFileName) {
14120
+ return path$o.basename(configFileName) === 'jsconfig.json';
14121
+ }
14122
+
14077
14123
  /** @template T */
14078
14124
  class TSConfckCache {
14079
14125
  /**
14080
14126
  * clear cache, use this if you have a long running process and tsconfig files have been added,changed or deleted
14081
14127
  */
14082
14128
  clear() {
14083
- this.#tsconfigPaths.clear();
14129
+ this.#configPaths.clear();
14084
14130
  this.#parsed.clear();
14085
14131
  }
14086
14132
 
14087
14133
  /**
14088
- * has cached closest tsconfig for files in dir
14134
+ * has cached closest config for files in dir
14089
14135
  * @param {string} dir
14136
+ * @param {string} [configName=tsconfig.json]
14090
14137
  * @returns {boolean}
14091
14138
  */
14092
- hasTSConfigPath(dir) {
14093
- return this.#tsconfigPaths.has(dir);
14139
+ hasConfigPath(dir, configName = 'tsconfig.json') {
14140
+ return this.#configPaths.has(`${dir}/${configName}`);
14094
14141
  }
14095
14142
 
14096
14143
  /**
14097
14144
  * get cached closest tsconfig for files in dir
14098
14145
  * @param {string} dir
14146
+ * @param {string} [configName=tsconfig.json]
14099
14147
  * @returns {Promise<string|null>|string|null}
14100
14148
  * @throws {unknown} if cached value is an error
14101
14149
  */
14102
- getTSConfigPath(dir) {
14103
- const value = this.#tsconfigPaths.get(dir);
14104
- if (value === null || value.length || value.then) {
14150
+ getConfigPath(dir, configName = 'tsconfig.json') {
14151
+ const key = `${dir}/${configName}`;
14152
+ const value = this.#configPaths.get(key);
14153
+ if (value == null || value.length || value.then) {
14105
14154
  return value;
14106
14155
  } else {
14107
14156
  throw value;
@@ -14157,19 +14206,21 @@ class TSConfckCache {
14157
14206
  * @internal
14158
14207
  * @private
14159
14208
  * @param {string} dir
14160
- * @param {Promise<string|null>} tsconfigPath
14209
+ * @param {Promise<string|null>} configPath
14210
+ * @param {string} [configName=tsconfig.json]
14161
14211
  */
14162
- setTSConfigPath(dir, tsconfigPath) {
14163
- this.#tsconfigPaths.set(dir, tsconfigPath);
14164
- tsconfigPath
14212
+ setConfigPath(dir, configPath, configName = 'tsconfig.json') {
14213
+ const key = `${dir}/${configName}`;
14214
+ this.#configPaths.set(key, configPath);
14215
+ configPath
14165
14216
  .then((path) => {
14166
- if (this.#tsconfigPaths.get(dir) === tsconfigPath) {
14167
- this.#tsconfigPaths.set(dir, path);
14217
+ if (this.#configPaths.get(key) === configPath) {
14218
+ this.#configPaths.set(key, path);
14168
14219
  }
14169
14220
  })
14170
14221
  .catch((e) => {
14171
- if (this.#tsconfigPaths.get(dir) === tsconfigPath) {
14172
- this.#tsconfigPaths.set(dir, e);
14222
+ if (this.#configPaths.get(key) === configPath) {
14223
+ this.#configPaths.set(key, e);
14173
14224
  }
14174
14225
  });
14175
14226
  }
@@ -14180,7 +14231,7 @@ class TSConfckCache {
14180
14231
  * @private
14181
14232
  * @type{Map<string,(Promise<string|null>|string|null)>}
14182
14233
  */
14183
- #tsconfigPaths = new Map();
14234
+ #configPaths = new Map();
14184
14235
 
14185
14236
  /**
14186
14237
  * map files to their parsed tsconfig result
@@ -14192,8 +14243,9 @@ class TSConfckCache {
14192
14243
  }
14193
14244
 
14194
14245
  const debug$g = createDebugger('vite:esbuild');
14195
- // IIFE content looks like `var MyLib = function() {`. Spaces are removed when minified
14196
- const IIFE_BEGIN_RE = /(const|var)\s+\S+\s*=\s*function\(\)\s*\{.*"use strict";/s;
14246
+ // IIFE content looks like `var MyLib = function() {`.
14247
+ // Spaces are removed and parameters are mangled when minified
14248
+ const IIFE_BEGIN_RE = /(const|var)\s+\S+\s*=\s*function\([^()]*\)\s*\{\s*"use strict";/;
14197
14249
  const validExtensionRE = /\.\w+$/;
14198
14250
  const jsxExtensionsRE = /\.(?:j|t)sx\b/;
14199
14251
  let server;
@@ -14721,11 +14773,14 @@ const loadTerserPath = (root) => {
14721
14773
  return terserPath;
14722
14774
  };
14723
14775
  function terserPlugin(config) {
14776
+ const { maxWorkers, ...terserOptions } = config.build.terserOptions;
14724
14777
  const makeWorker = () => new Worker_1(async (terserPath, code, options) => {
14725
14778
  // test fails when using `import`. maybe related: https://github.com/nodejs/node/issues/43205
14726
14779
  // eslint-disable-next-line no-restricted-globals -- this function runs inside cjs
14727
14780
  const terser = require(terserPath);
14728
14781
  return terser.minify(code, options);
14782
+ }, {
14783
+ max: maxWorkers,
14729
14784
  });
14730
14785
  let worker;
14731
14786
  return {
@@ -14749,7 +14804,7 @@ function terserPlugin(config) {
14749
14804
  const terserPath = loadTerserPath(config.root);
14750
14805
  const res = await worker.run(terserPath, code, {
14751
14806
  safari10: true,
14752
- ...config.build.terserOptions,
14807
+ ...terserOptions,
14753
14808
  sourceMap: !!outputOptions.sourcemap,
14754
14809
  module: outputOptions.format.startsWith('es'),
14755
14810
  toplevel: outputOptions.format === 'cjs',
@@ -15576,16 +15631,35 @@ class Mappings {
15576
15631
 
15577
15632
  addEdit(sourceIndex, content, loc, nameIndex) {
15578
15633
  if (content.length) {
15634
+ let contentLineEnd = content.indexOf('\n', 0);
15635
+ let previousContentLineEnd = -1;
15636
+ while (contentLineEnd >= 0) {
15637
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
15638
+ if (nameIndex >= 0) {
15639
+ segment.push(nameIndex);
15640
+ }
15641
+ this.rawSegments.push(segment);
15642
+
15643
+ this.generatedCodeLine += 1;
15644
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
15645
+ this.generatedCodeColumn = 0;
15646
+
15647
+ previousContentLineEnd = contentLineEnd;
15648
+ contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
15649
+ }
15650
+
15579
15651
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
15580
15652
  if (nameIndex >= 0) {
15581
15653
  segment.push(nameIndex);
15582
15654
  }
15583
15655
  this.rawSegments.push(segment);
15656
+
15657
+ this.advance(content.slice(previousContentLineEnd + 1));
15584
15658
  } else if (this.pending) {
15585
15659
  this.rawSegments.push(this.pending);
15660
+ this.advance(content);
15586
15661
  }
15587
15662
 
15588
- this.advance(content);
15589
15663
  this.pending = null;
15590
15664
  }
15591
15665
 
@@ -27854,7 +27928,7 @@ function stringifyQuery(query) {
27854
27928
  }
27855
27929
 
27856
27930
  new Set(builtinModules);
27857
- function matchAll(regex, string, addition) {
27931
+ function matchAll$1(regex, string, addition) {
27858
27932
  const matches = [];
27859
27933
  for (const match of string.matchAll(regex)) {
27860
27934
  matches.push({
@@ -28393,7 +28467,7 @@ pathToFileURL(process.cwd());
28393
28467
  const ESM_STATIC_IMPORT_RE = /(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
28394
28468
  const TYPE_RE = /^\s*?type\s/;
28395
28469
  function findStaticImports(code) {
28396
- return matchAll(ESM_STATIC_IMPORT_RE, code, { type: "static" });
28470
+ return matchAll$1(ESM_STATIC_IMPORT_RE, code, { type: "static" });
28397
28471
  }
28398
28472
  function parseStaticImport(matched) {
28399
28473
  const cleanedImports = clearImports(matched.imports);
@@ -28458,10 +28532,15 @@ function resolvePlugin(resolveOptions) {
28458
28532
  const targetWeb = !ssr || ssrTarget === 'webworker';
28459
28533
  // this is passed by @rollup/plugin-commonjs
28460
28534
  const isRequire = resolveOpts?.custom?.['node-resolve']?.isRequire ?? false;
28535
+ // end user can configure different conditions for ssr and client.
28536
+ // falls back to client conditions if no ssr conditions supplied
28537
+ const ssrConditions = resolveOptions.ssrConfig?.resolve?.conditions ||
28538
+ resolveOptions.conditions;
28461
28539
  const options = {
28462
28540
  isRequire,
28463
28541
  ...resolveOptions,
28464
28542
  scan: resolveOpts?.scan ?? resolveOptions.scan,
28543
+ conditions: ssr ? ssrConditions : resolveOptions.conditions,
28465
28544
  };
28466
28545
  const resolvedImports = resolveSubpathImports(id, importer, options, targetWeb);
28467
28546
  if (resolvedImports) {
@@ -28821,8 +28900,10 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr = f
28821
28900
  bareImportRE.test(id)) {
28822
28901
  const mainPkg = findNearestMainPackageData(basedir, packageCache)?.data;
28823
28902
  if (mainPkg) {
28824
- if (mainPkg.peerDependencies?.[id] &&
28825
- mainPkg.peerDependenciesMeta?.[id]?.optional) {
28903
+ const pkgName = getNpmPackageName(id);
28904
+ if (pkgName != null &&
28905
+ mainPkg.peerDependencies?.[pkgName] &&
28906
+ mainPkg.peerDependenciesMeta?.[pkgName]?.optional) {
28826
28907
  return {
28827
28908
  id: `${optionalPeerDepId}:${id}:${mainPkg.name}`,
28828
28909
  };
@@ -28847,7 +28928,7 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr = f
28847
28928
  ...options,
28848
28929
  isRequire: false,
28849
28930
  mainFields: DEFAULT_MAIN_FIELDS,
28850
- extensions: DEFAULT_EXTENSIONS$1,
28931
+ extensions: DEFAULT_EXTENSIONS,
28851
28932
  });
28852
28933
  }
28853
28934
  if (!resolved) {
@@ -37111,7 +37192,7 @@ function _stripLiteralAcorn(code, options) {
37111
37192
 
37112
37193
  const multilineCommentsRE = /\/\*([^*\/])*?\*\//gms;
37113
37194
  const singlelineCommentsRE = /(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gm;
37114
- const templateLiteralRE = /\$\{(\s*(?:|{.*}|(?!\$\{).|\n|\r)*?\s*)\}/g;
37195
+ const templateLiteralRE$1 = /\$\{(\s*(?:|{.*}|(?!\$\{).|\n|\r)*?\s*)\}/g;
37115
37196
  const quotesRE = [
37116
37197
  /(["'`])((?:\\\1|(?!\1)|.|\r)*?)\1/gm,
37117
37198
  /([`])((?:\\\1|(?!\1)|.|\n|\r)*?)\1/gm
@@ -37125,7 +37206,7 @@ function stripLiteralRegex(code, options) {
37125
37206
  let expanded = code;
37126
37207
  for (let i = 0; i < 16; i++) {
37127
37208
  const before = expanded;
37128
- expanded = expanded.replace(templateLiteralRE, "` $1`");
37209
+ expanded = expanded.replace(templateLiteralRE$1, "` $1`");
37129
37210
  if (expanded === before)
37130
37211
  break;
37131
37212
  }
@@ -37635,6 +37716,14 @@ function expand (config) {
37635
37716
 
37636
37717
  var expand_1 = expand;
37637
37718
 
37719
+ function getEnvFilesForMode(mode) {
37720
+ return [
37721
+ /** default file */ `.env`,
37722
+ /** local file */ `.env.local`,
37723
+ /** mode file */ `.env.${mode}`,
37724
+ /** mode local file */ `.env.${mode}.local`,
37725
+ ];
37726
+ }
37638
37727
  function loadEnv(mode, envDir, prefixes = 'VITE_') {
37639
37728
  if (mode === 'local') {
37640
37729
  throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
@@ -37642,12 +37731,7 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
37642
37731
  }
37643
37732
  prefixes = arraify(prefixes);
37644
37733
  const env = {};
37645
- const envFiles = [
37646
- /** default file */ `.env`,
37647
- /** local file */ `.env.local`,
37648
- /** mode file */ `.env.${mode}`,
37649
- /** mode local file */ `.env.${mode}.local`,
37650
- ];
37734
+ const envFiles = getEnvFilesForMode(mode);
37651
37735
  const parsed = Object.fromEntries(envFiles.flatMap((file) => {
37652
37736
  const filePath = path$o.join(envDir, file);
37653
37737
  if (!tryStatSync(filePath)?.isFile())
@@ -37949,6 +38033,31 @@ function buildHtmlPlugin(config) {
37949
38033
  const publicBase = getBaseInHTML(relativeUrlPath, config);
37950
38034
  const publicToRelative = (filename, importer) => publicBase + filename;
37951
38035
  const toOutputPublicFilePath = (url) => toOutputFilePathInHtml(url.slice(1), 'public', relativeUrlPath, 'html', config, publicToRelative);
38036
+ // Determines true start position for the node, either the < character
38037
+ // position, or the newline at the end of the previous line's node.
38038
+ const nodeStartWithLeadingWhitespace = (node) => {
38039
+ if (node.sourceCodeLocation.startOffset === 0)
38040
+ return node.sourceCodeLocation.startOffset;
38041
+ // Gets the offset for the start of the line including the
38042
+ // newline trailing the previous node
38043
+ const lineStartOffset = node.sourceCodeLocation.startOffset -
38044
+ node.sourceCodeLocation.startCol;
38045
+ const line = s.slice(lineStartOffset, node.sourceCodeLocation.startOffset);
38046
+ // <previous-line-node></previous-line-node>
38047
+ // <target-node></target-node>
38048
+ //
38049
+ // Here we want to target the newline at the end of the previous line
38050
+ // as the start position for our target.
38051
+ //
38052
+ // <previous-node></previous-node>
38053
+ // <doubled-up-node></doubled-up-node><target-node></target-node>
38054
+ //
38055
+ // However, if there is content between our target node start and the
38056
+ // previous newline, we cannot strip it out without risking content deletion.
38057
+ return line.trim()
38058
+ ? node.sourceCodeLocation.startOffset
38059
+ : lineStartOffset;
38060
+ };
37952
38061
  // pre-transform
37953
38062
  html = await applyHtmlTransforms(html, preHooks, {
37954
38063
  path: publicPath,
@@ -38044,7 +38153,7 @@ function buildHtmlPlugin(config) {
38044
38153
  const importExpression = `\nimport ${JSON.stringify(url)}`;
38045
38154
  styleUrls.push({
38046
38155
  url,
38047
- start: node.sourceCodeLocation.startOffset,
38156
+ start: nodeStartWithLeadingWhitespace(node),
38048
38157
  end: node.sourceCodeLocation.endOffset,
38049
38158
  });
38050
38159
  js += importExpression;
@@ -38099,7 +38208,7 @@ function buildHtmlPlugin(config) {
38099
38208
  if (shouldRemove) {
38100
38209
  // remove the script tag from the html. we are going to inject new
38101
38210
  // ones in the end.
38102
- s.remove(node.sourceCodeLocation.startOffset, node.sourceCodeLocation.endOffset);
38211
+ s.remove(nodeStartWithLeadingWhitespace(node), node.sourceCodeLocation.endOffset);
38103
38212
  }
38104
38213
  });
38105
38214
  isAsyncScriptMap.get(config).set(id, everyScriptIsAsync);
@@ -39399,8 +39508,8 @@ function createCachedImport(imp) {
39399
39508
  return cached;
39400
39509
  };
39401
39510
  }
39402
- const importPostcssImport = createCachedImport(() => import('./dep-68c42983.js').then(function (n) { return n.i; }));
39403
- const importPostcssModules = createCachedImport(() => import('./dep-9586b1f1.js').then(function (n) { return n.i; }));
39511
+ const importPostcssImport = createCachedImport(() => import('./dep-958c4c65.js').then(function (n) { return n.i; }));
39512
+ const importPostcssModules = createCachedImport(() => import('./dep-86245b77.js').then(function (n) { return n.i; }));
39404
39513
  const importPostcss = createCachedImport(() => import('postcss'));
39405
39514
  /**
39406
39515
  * @experimental
@@ -40737,11 +40846,13 @@ function createIsConfiguredAsSsrExternal(config) {
40737
40846
  const noExternalFilter = noExternal !== 'undefined' &&
40738
40847
  typeof noExternal !== 'boolean' &&
40739
40848
  createFilter(undefined, noExternal, { resolve: false });
40849
+ const targetConditions = config.ssr.resolve?.externalConditions || [];
40740
40850
  const resolveOptions = {
40741
40851
  ...config.resolve,
40742
40852
  root,
40743
40853
  isProduction: false,
40744
40854
  isBuild: true,
40855
+ conditions: targetConditions,
40745
40856
  };
40746
40857
  const isExternalizable = (id, importer, configuredAsExternal) => {
40747
40858
  if (!bareImportRE.test(id) || id.includes('\0')) {
@@ -41716,7 +41827,7 @@ async function handleHMRUpdate(file, server, configOnly) {
41716
41827
  const isConfig = file === config.configFile;
41717
41828
  const isConfigDependency = config.configFileDependencies.some((name) => file === name);
41718
41829
  const isEnv = config.inlineConfig.envFile !== false &&
41719
- (fileName === '.env' || fileName.startsWith('.env.'));
41830
+ getEnvFilesForMode(config.mode).includes(fileName);
41720
41831
  if (isConfig || isConfigDependency || isEnv) {
41721
41832
  // auto restart server
41722
41833
  debugHmr?.(`[config change] ${colors$1.dim(shortFile)}`);
@@ -42098,6 +42209,7 @@ const hasImportInQueryParamsRE = /[?&]import=?\b/;
42098
42209
  const hasViteIgnoreRE = /\/\*\s*@vite-ignore\s*\*\//;
42099
42210
  const cleanUpRawUrlRE = /\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm;
42100
42211
  const urlIsStringRE = /^(?:'.*'|".*"|`.*`)$/;
42212
+ const templateLiteralRE = /^\s*`(.*)`\s*$/;
42101
42213
  function isExplicitImportRequired(url) {
42102
42214
  return !isJSRequest(cleanUrl(url)) && !isCSSRequest(url);
42103
42215
  }
@@ -42255,7 +42367,6 @@ function importAnalysisPlugin(config) {
42255
42367
  let needQueryInjectHelper = false;
42256
42368
  let s;
42257
42369
  const str = () => s || (s = new MagicString(source));
42258
- const importedUrls = new Set();
42259
42370
  let isPartiallySelfAccepting = false;
42260
42371
  const importedBindings = enablePartialAccept
42261
42372
  ? new Map()
@@ -42291,6 +42402,9 @@ function importAnalysisPlugin(config) {
42291
42402
  importerModule.isSelfAccepting = false;
42292
42403
  return this.error(`Failed to resolve import "${url}" from "${path$o.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
42293
42404
  }
42405
+ if (isExternalUrl(resolved.id)) {
42406
+ return [resolved.id, resolved.id];
42407
+ }
42294
42408
  const isRelative = url[0] === '.';
42295
42409
  const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
42296
42410
  // normalize all imports into resolved URLs
@@ -42308,9 +42422,6 @@ function importAnalysisPlugin(config) {
42308
42422
  else {
42309
42423
  url = resolved.id;
42310
42424
  }
42311
- if (isExternalUrl(url)) {
42312
- return [url, url];
42313
- }
42314
42425
  // if the resolved id is not a valid browser import specifier,
42315
42426
  // prefix it to make it valid. We will strip this before feeding it
42316
42427
  // back into the transform pipeline
@@ -42356,13 +42467,14 @@ function importAnalysisPlugin(config) {
42356
42467
  }
42357
42468
  return [url, resolved.id];
42358
42469
  };
42470
+ const orderedImportedUrls = new Array(imports.length);
42359
42471
  const orderedAcceptedUrls = new Array(imports.length);
42360
42472
  const orderedAcceptedExports = new Array(imports.length);
42361
42473
  await Promise.all(imports.map(async (importSpecifier, index) => {
42362
- const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex,
42474
+ const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex, a: assertIndex, } = importSpecifier;
42363
42475
  // #2083 User may use escape path,
42364
42476
  // so use imports[index].n to get the unescaped string
42365
- n: specifier, a: assertIndex, } = importSpecifier;
42477
+ let specifier = importSpecifier.n;
42366
42478
  const rawUrl = source.slice(start, end);
42367
42479
  // check import.meta usage
42368
42480
  if (rawUrl === 'import.meta') {
@@ -42392,6 +42504,15 @@ function importAnalysisPlugin(config) {
42392
42504
  }
42393
42505
  return;
42394
42506
  }
42507
+ else if (templateLiteralRE.test(rawUrl)) {
42508
+ // If the import has backticks but isn't transformed as a glob import
42509
+ // (as there's nothing to glob), check if it's simply a plain string.
42510
+ // If so, we can replace the specifier as a plain string to prevent
42511
+ // an incorrect "cannot be analyzed" warning.
42512
+ if (!(rawUrl.includes('${') && rawUrl.includes('}'))) {
42513
+ specifier = rawUrl.replace(templateLiteralRE, '$1');
42514
+ }
42515
+ }
42395
42516
  const isDynamicImport = dynamicIndex > -1;
42396
42517
  // strip import assertions as we can process them ourselves
42397
42518
  if (!isDynamicImport && assertIndex > -1) {
@@ -42479,7 +42600,7 @@ function importAnalysisPlugin(config) {
42479
42600
  const hmrUrl = unwrapId(stripBase(url, base));
42480
42601
  const isLocalImport = !isExternalUrl(hmrUrl) && !isDataUrl(hmrUrl);
42481
42602
  if (isLocalImport) {
42482
- importedUrls.add(hmrUrl);
42603
+ orderedImportedUrls[index] = hmrUrl;
42483
42604
  }
42484
42605
  if (enablePartialAccept && importedBindings) {
42485
42606
  extractImportedBindings(resolvedId, source, importSpecifier, importedBindings);
@@ -42498,7 +42619,10 @@ function importAnalysisPlugin(config) {
42498
42619
  return;
42499
42620
  }
42500
42621
  // Unexpected error, log the issue but avoid an unhandled exception
42501
- config.logger.error(e.message, { error: e });
42622
+ config.logger.error(`Pre-transform error: ${e.message}`, {
42623
+ error: e,
42624
+ timestamp: true,
42625
+ });
42502
42626
  });
42503
42627
  }
42504
42628
  }
@@ -42530,6 +42654,7 @@ function importAnalysisPlugin(config) {
42530
42654
  }
42531
42655
  }
42532
42656
  }));
42657
+ const importedUrls = new Set(orderedImportedUrls.filter(Boolean));
42533
42658
  const acceptedUrls = mergeAcceptedUrls(orderedAcceptedUrls);
42534
42659
  const acceptedExports = mergeAcceptedUrls(orderedAcceptedExports);
42535
42660
  if (hasEnv) {
@@ -44999,7 +45124,8 @@ async function computeEntries(config) {
44999
45124
  }
45000
45125
  // Non-supported entry file types and virtual files should not be scanned for
45001
45126
  // dependencies.
45002
- entries = entries.filter((entry) => isScannable(entry) && fs$l.existsSync(entry));
45127
+ entries = entries.filter((entry) => isScannable(entry, config.optimizeDeps.extensions) &&
45128
+ fs$l.existsSync(entry));
45003
45129
  return entries;
45004
45130
  }
45005
45131
  async function prepareEsbuildScanner(config, entries, deps, missing, scanContext) {
@@ -45129,12 +45255,11 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45129
45255
  namespace: 'html',
45130
45256
  };
45131
45257
  });
45132
- // extract scripts inside HTML-like files and treat it as a js module
45133
- build.onLoad({ filter: htmlTypesRE, namespace: 'html' }, async ({ path }) => {
45134
- let raw = await fsp.readFile(path, 'utf-8');
45258
+ const htmlTypeOnLoadCallback = async ({ path: p }) => {
45259
+ let raw = await fsp.readFile(p, 'utf-8');
45135
45260
  // Avoid matching the content of the comment
45136
45261
  raw = raw.replace(commentRE, '<!---->');
45137
- const isHtml = path.endsWith('.html');
45262
+ const isHtml = p.endsWith('.html');
45138
45263
  scriptRE.lastIndex = 0;
45139
45264
  let js = '';
45140
45265
  let scriptId = 0;
@@ -45160,7 +45285,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45160
45285
  if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
45161
45286
  loader = lang;
45162
45287
  }
45163
- else if (path.endsWith('.astro')) {
45288
+ else if (p.endsWith('.astro')) {
45164
45289
  loader = 'ts';
45165
45290
  }
45166
45291
  const srcMatch = openTag.match(srcRE);
@@ -45178,11 +45303,12 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45178
45303
  // since they may be used in the template
45179
45304
  const contents = content +
45180
45305
  (loader.startsWith('ts') ? extractImportPaths(content) : '');
45181
- const key = `${path}?id=${scriptId++}`;
45306
+ const key = `${p}?id=${scriptId++}`;
45182
45307
  if (contents.includes('import.meta.glob')) {
45183
45308
  scripts[key] = {
45184
45309
  loader: 'js',
45185
- contents: await doTransformGlobImport(contents, path, loader),
45310
+ contents: await doTransformGlobImport(contents, p, loader),
45311
+ resolveDir: normalizePath$3(path$o.dirname(p)),
45186
45312
  pluginData: {
45187
45313
  htmlType: { loader },
45188
45314
  },
@@ -45192,6 +45318,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45192
45318
  scripts[key] = {
45193
45319
  loader,
45194
45320
  contents,
45321
+ resolveDir: normalizePath$3(path$o.dirname(p)),
45195
45322
  pluginData: {
45196
45323
  htmlType: { loader },
45197
45324
  },
@@ -45204,7 +45331,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45204
45331
  // Especially for Svelte files, exports in <script context="module"> means module exports,
45205
45332
  // exports in <script> means component props. To avoid having two same export name from the
45206
45333
  // star exports, we need to ignore exports in <script>
45207
- if (path.endsWith('.svelte') && context !== 'module') {
45334
+ if (p.endsWith('.svelte') && context !== 'module') {
45208
45335
  js += `import ${virtualModulePath}\n`;
45209
45336
  }
45210
45337
  else {
@@ -45216,14 +45343,20 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45216
45343
  // anywhere in a string. Svelte and Astro files can't have
45217
45344
  // `export default` as code so we know if it's encountered it's a
45218
45345
  // false positive (e.g. contained in a string)
45219
- if (!path.endsWith('.vue') || !js.includes('export default')) {
45346
+ if (!p.endsWith('.vue') || !js.includes('export default')) {
45220
45347
  js += '\nexport default {}';
45221
45348
  }
45222
45349
  return {
45223
45350
  loader: 'js',
45224
45351
  contents: js,
45225
45352
  };
45226
- });
45353
+ };
45354
+ // extract scripts inside HTML-like files and treat it as a js module
45355
+ build.onLoad({ filter: htmlTypesRE, namespace: 'html' }, htmlTypeOnLoadCallback);
45356
+ // the onResolve above will use namespace=html but esbuild doesn't
45357
+ // call onResolve for glob imports and those will use namespace=file
45358
+ // https://github.com/evanw/esbuild/issues/3317
45359
+ build.onLoad({ filter: htmlTypesRE, namespace: 'file' }, htmlTypeOnLoadCallback);
45227
45360
  // bare imports: record and externalize ----------------------------------
45228
45361
  build.onResolve({
45229
45362
  // avoid matching windows volume
@@ -45251,7 +45384,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45251
45384
  }
45252
45385
  return externalUnlessEntry({ path: id });
45253
45386
  }
45254
- else if (isScannable(resolved)) {
45387
+ else if (isScannable(resolved, config.optimizeDeps.extensions)) {
45255
45388
  const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined;
45256
45389
  // linked package, keep crawling
45257
45390
  return {
@@ -45296,7 +45429,8 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45296
45429
  },
45297
45430
  });
45298
45431
  if (resolved) {
45299
- if (shouldExternalizeDep(resolved, id) || !isScannable(resolved)) {
45432
+ if (shouldExternalizeDep(resolved, id) ||
45433
+ !isScannable(resolved, config.optimizeDeps.extensions)) {
45300
45434
  return externalUnlessEntry({ path: id });
45301
45435
  }
45302
45436
  const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined;
@@ -45368,8 +45502,11 @@ function shouldExternalizeDep(resolvedId, rawId) {
45368
45502
  }
45369
45503
  return false;
45370
45504
  }
45371
- function isScannable(id) {
45372
- return JS_TYPES_RE.test(id) || htmlTypesRE.test(id);
45505
+ function isScannable(id, extensions) {
45506
+ return (JS_TYPES_RE.test(id) ||
45507
+ htmlTypesRE.test(id) ||
45508
+ extensions?.includes(path$o.extname(id)) ||
45509
+ false);
45373
45510
  }
45374
45511
  // esbuild v0.18 only transforms decorators when `experimentalDecorators` is set to `true`.
45375
45512
  // To preserve compat with the esbuild breaking change, we set `experimentalDecorators` to
@@ -54670,206 +54807,249 @@ chokidar.watch = watch;
54670
54807
 
54671
54808
  var shellQuote$1 = {};
54672
54809
 
54673
- shellQuote$1.quote = function (xs) {
54674
- return xs.map(function (s) {
54675
- if (s && typeof s === 'object') {
54676
- return s.op.replace(/(.)/g, '\\$1');
54677
- }
54678
- else if (/["\s]/.test(s) && !/'/.test(s)) {
54679
- return "'" + s.replace(/(['\\])/g, '\\$1') + "'";
54680
- }
54681
- else if (/["'\s]/.test(s)) {
54682
- return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';
54683
- }
54684
- else {
54685
- return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@\[\\\]^`{|}])/g, '$1\\$2');
54686
- }
54687
- }).join(' ');
54810
+ var quote = function quote(xs) {
54811
+ return xs.map(function (s) {
54812
+ if (s && typeof s === 'object') {
54813
+ return s.op.replace(/(.)/g, '\\$1');
54814
+ }
54815
+ if ((/["\s]/).test(s) && !(/'/).test(s)) {
54816
+ return "'" + s.replace(/(['\\])/g, '\\$1') + "'";
54817
+ }
54818
+ if ((/["'\s]/).test(s)) {
54819
+ return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';
54820
+ }
54821
+ return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, '$1\\$2');
54822
+ }).join(' ');
54688
54823
  };
54689
54824
 
54690
54825
  // '<(' is process substitution operator and
54691
54826
  // can be parsed the same as control operator
54692
54827
  var CONTROL = '(?:' + [
54693
- '\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '>>', '>\\&', '[&;()|<>]'
54828
+ '\\|\\|',
54829
+ '\\&\\&',
54830
+ ';;',
54831
+ '\\|\\&',
54832
+ '\\<\\(',
54833
+ '\\<\\<\\<',
54834
+ '>>',
54835
+ '>\\&',
54836
+ '<\\&',
54837
+ '[&;()|<>]'
54694
54838
  ].join('|') + ')';
54839
+ var controlRE = new RegExp('^' + CONTROL + '$');
54695
54840
  var META = '|&;()<> \\t';
54696
- var BAREWORD = '(\\\\[\'"' + META + ']|[^\\s\'"' + META + '])+';
54697
54841
  var SINGLE_QUOTE = '"((\\\\"|[^"])*?)"';
54698
54842
  var DOUBLE_QUOTE = '\'((\\\\\'|[^\'])*?)\'';
54843
+ var hash = /^#$/;
54844
+
54845
+ var SQ = "'";
54846
+ var DQ = '"';
54847
+ var DS = '$';
54699
54848
 
54700
54849
  var TOKEN = '';
54850
+ var mult = 0x100000000; // Math.pow(16, 8);
54701
54851
  for (var i = 0; i < 4; i++) {
54702
- TOKEN += (Math.pow(16,8)*Math.random()).toString(16);
54852
+ TOKEN += (mult * Math.random()).toString(16);
54703
54853
  }
54854
+ var startsWithToken = new RegExp('^' + TOKEN);
54704
54855
 
54705
- shellQuote$1.parse = function (s, env, opts) {
54706
- var mapped = parse$5(s, env, opts);
54707
- if (typeof env !== 'function') return mapped;
54708
- return mapped.reduce(function (acc, s) {
54709
- if (typeof s === 'object') return acc.concat(s);
54710
- var xs = s.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
54711
- if (xs.length === 1) return acc.concat(xs[0]);
54712
- return acc.concat(xs.filter(Boolean).map(function (x) {
54713
- if (RegExp('^' + TOKEN).test(x)) {
54714
- return JSON.parse(x.split(TOKEN)[1]);
54715
- }
54716
- else return x;
54717
- }));
54718
- }, []);
54719
- };
54856
+ function matchAll(s, r) {
54857
+ var origIndex = r.lastIndex;
54720
54858
 
54721
- function parse$5 (s, env, opts) {
54722
- var chunker = new RegExp([
54723
- '(' + CONTROL + ')', // control chars
54724
- '(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')*'
54725
- ].join('|'), 'g');
54726
- var match = s.match(chunker).filter(Boolean);
54727
- var commented = false;
54859
+ var matches = [];
54860
+ var matchObj;
54728
54861
 
54729
- if (!match) return [];
54730
- if (!env) env = {};
54731
- if (!opts) opts = {};
54732
- return match.map(function (s, j) {
54733
- if (commented) {
54734
- return;
54735
- }
54736
- if (RegExp('^' + CONTROL + '$').test(s)) {
54737
- return { op: s };
54738
- }
54862
+ while ((matchObj = r.exec(s))) {
54863
+ matches.push(matchObj);
54864
+ if (r.lastIndex === matchObj.index) {
54865
+ r.lastIndex += 1;
54866
+ }
54867
+ }
54739
54868
 
54740
- // Hand-written scanner/parser for Bash quoting rules:
54741
- //
54742
- // 1. inside single quotes, all characters are printed literally.
54743
- // 2. inside double quotes, all characters are printed literally
54744
- // except variables prefixed by '$' and backslashes followed by
54745
- // either a double quote or another backslash.
54746
- // 3. outside of any quotes, backslashes are treated as escape
54747
- // characters and not printed (unless they are themselves escaped)
54748
- // 4. quote context can switch mid-token if there is no whitespace
54749
- // between the two quote contexts (e.g. all'one'"token" parses as
54750
- // "allonetoken")
54751
- var SQ = "'";
54752
- var DQ = '"';
54753
- var DS = '$';
54754
- var BS = opts.escape || '\\';
54755
- var quote = false;
54756
- var esc = false;
54757
- var out = '';
54758
- var isGlob = false;
54759
-
54760
- for (var i = 0, len = s.length; i < len; i++) {
54761
- var c = s.charAt(i);
54762
- isGlob = isGlob || (!quote && (c === '*' || c === '?'));
54763
- if (esc) {
54764
- out += c;
54765
- esc = false;
54766
- }
54767
- else if (quote) {
54768
- if (c === quote) {
54769
- quote = false;
54770
- }
54771
- else if (quote == SQ) {
54772
- out += c;
54773
- }
54774
- else { // Double quote
54775
- if (c === BS) {
54776
- i += 1;
54777
- c = s.charAt(i);
54778
- if (c === DQ || c === BS || c === DS) {
54779
- out += c;
54780
- } else {
54781
- out += BS + c;
54782
- }
54783
- }
54784
- else if (c === DS) {
54785
- out += parseEnvVar();
54786
- }
54787
- else {
54788
- out += c;
54789
- }
54790
- }
54791
- }
54792
- else if (c === DQ || c === SQ) {
54793
- quote = c;
54794
- }
54795
- else if (RegExp('^' + CONTROL + '$').test(c)) {
54796
- return { op: s };
54797
- }
54798
- else if (RegExp('^#$').test(c)) {
54799
- commented = true;
54800
- if (out.length){
54801
- return [out, { comment: s.slice(i+1) + match.slice(j+1).join(' ') }];
54802
- }
54803
- return [{ comment: s.slice(i+1) + match.slice(j+1).join(' ') }];
54804
- }
54805
- else if (c === BS) {
54806
- esc = true;
54807
- }
54808
- else if (c === DS) {
54809
- out += parseEnvVar();
54810
- }
54811
- else out += c;
54812
- }
54869
+ r.lastIndex = origIndex;
54813
54870
 
54814
- if (isGlob) return {op: 'glob', pattern: out};
54871
+ return matches;
54872
+ }
54815
54873
 
54816
- return out;
54874
+ function getVar(env, pre, key) {
54875
+ var r = typeof env === 'function' ? env(key) : env[key];
54876
+ if (typeof r === 'undefined' && key != '') {
54877
+ r = '';
54878
+ } else if (typeof r === 'undefined') {
54879
+ r = '$';
54880
+ }
54817
54881
 
54818
- function parseEnvVar() {
54819
- i += 1;
54820
- var varend, varname;
54821
- //debugger
54822
- if (s.charAt(i) === '{') {
54823
- i += 1;
54824
- if (s.charAt(i) === '}') {
54825
- throw new Error("Bad substitution: " + s.substr(i - 2, 3));
54826
- }
54827
- varend = s.indexOf('}', i);
54828
- if (varend < 0) {
54829
- throw new Error("Bad substitution: " + s.substr(i));
54830
- }
54831
- varname = s.substr(i, varend - i);
54832
- i = varend;
54833
- }
54834
- else if (/[*@#?$!_\-]/.test(s.charAt(i))) {
54835
- varname = s.charAt(i);
54836
- i += 1;
54837
- }
54838
- else {
54839
- varend = s.substr(i).match(/[^\w\d_]/);
54840
- if (!varend) {
54841
- varname = s.substr(i);
54842
- i = s.length;
54843
- } else {
54844
- varname = s.substr(i, varend.index);
54845
- i += varend.index - 1;
54846
- }
54847
- }
54848
- return getVar(null, '', varname);
54849
- }
54850
- })
54851
- // finalize parsed aruments
54852
- .reduce(function(prev, arg){
54853
- if (arg === undefined){
54854
- return prev;
54855
- }
54856
- return prev.concat(arg);
54857
- },[]);
54882
+ if (typeof r === 'object') {
54883
+ return pre + TOKEN + JSON.stringify(r) + TOKEN;
54884
+ }
54885
+ return pre + r;
54886
+ }
54858
54887
 
54859
- function getVar (_, pre, key) {
54860
- var r = typeof env === 'function' ? env(key) : env[key];
54861
- if (r === undefined && key != '')
54862
- r = '';
54863
- else if (r === undefined)
54864
- r = '$';
54888
+ function parseInternal(string, env, opts) {
54889
+ if (!opts) {
54890
+ opts = {};
54891
+ }
54892
+ var BS = opts.escape || '\\';
54893
+ var BAREWORD = '(\\' + BS + '[\'"' + META + ']|[^\\s\'"' + META + '])+';
54865
54894
 
54866
- if (typeof r === 'object') {
54867
- return pre + TOKEN + JSON.stringify(r) + TOKEN;
54868
- }
54869
- else return pre + r;
54870
- }
54895
+ var chunker = new RegExp([
54896
+ '(' + CONTROL + ')', // control chars
54897
+ '(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')+'
54898
+ ].join('|'), 'g');
54899
+
54900
+ var matches = matchAll(string, chunker);
54901
+
54902
+ if (matches.length === 0) {
54903
+ return [];
54904
+ }
54905
+ if (!env) {
54906
+ env = {};
54907
+ }
54908
+
54909
+ var commented = false;
54910
+
54911
+ return matches.map(function (match) {
54912
+ var s = match[0];
54913
+ if (!s || commented) {
54914
+ return void undefined;
54915
+ }
54916
+ if (controlRE.test(s)) {
54917
+ return { op: s };
54918
+ }
54919
+
54920
+ // Hand-written scanner/parser for Bash quoting rules:
54921
+ //
54922
+ // 1. inside single quotes, all characters are printed literally.
54923
+ // 2. inside double quotes, all characters are printed literally
54924
+ // except variables prefixed by '$' and backslashes followed by
54925
+ // either a double quote or another backslash.
54926
+ // 3. outside of any quotes, backslashes are treated as escape
54927
+ // characters and not printed (unless they are themselves escaped)
54928
+ // 4. quote context can switch mid-token if there is no whitespace
54929
+ // between the two quote contexts (e.g. all'one'"token" parses as
54930
+ // "allonetoken")
54931
+ var quote = false;
54932
+ var esc = false;
54933
+ var out = '';
54934
+ var isGlob = false;
54935
+ var i;
54936
+
54937
+ function parseEnvVar() {
54938
+ i += 1;
54939
+ var varend;
54940
+ var varname;
54941
+ var char = s.charAt(i);
54942
+
54943
+ if (char === '{') {
54944
+ i += 1;
54945
+ if (s.charAt(i) === '}') {
54946
+ throw new Error('Bad substitution: ' + s.slice(i - 2, i + 1));
54947
+ }
54948
+ varend = s.indexOf('}', i);
54949
+ if (varend < 0) {
54950
+ throw new Error('Bad substitution: ' + s.slice(i));
54951
+ }
54952
+ varname = s.slice(i, varend);
54953
+ i = varend;
54954
+ } else if ((/[*@#?$!_-]/).test(char)) {
54955
+ varname = char;
54956
+ i += 1;
54957
+ } else {
54958
+ var slicedFromI = s.slice(i);
54959
+ varend = slicedFromI.match(/[^\w\d_]/);
54960
+ if (!varend) {
54961
+ varname = slicedFromI;
54962
+ i = s.length;
54963
+ } else {
54964
+ varname = slicedFromI.slice(0, varend.index);
54965
+ i += varend.index - 1;
54966
+ }
54967
+ }
54968
+ return getVar(env, '', varname);
54969
+ }
54970
+
54971
+ for (i = 0; i < s.length; i++) {
54972
+ var c = s.charAt(i);
54973
+ isGlob = isGlob || (!quote && (c === '*' || c === '?'));
54974
+ if (esc) {
54975
+ out += c;
54976
+ esc = false;
54977
+ } else if (quote) {
54978
+ if (c === quote) {
54979
+ quote = false;
54980
+ } else if (quote == SQ) {
54981
+ out += c;
54982
+ } else { // Double quote
54983
+ if (c === BS) {
54984
+ i += 1;
54985
+ c = s.charAt(i);
54986
+ if (c === DQ || c === BS || c === DS) {
54987
+ out += c;
54988
+ } else {
54989
+ out += BS + c;
54990
+ }
54991
+ } else if (c === DS) {
54992
+ out += parseEnvVar();
54993
+ } else {
54994
+ out += c;
54995
+ }
54996
+ }
54997
+ } else if (c === DQ || c === SQ) {
54998
+ quote = c;
54999
+ } else if (controlRE.test(c)) {
55000
+ return { op: s };
55001
+ } else if (hash.test(c)) {
55002
+ commented = true;
55003
+ var commentObj = { comment: string.slice(match.index + i + 1) };
55004
+ if (out.length) {
55005
+ return [out, commentObj];
55006
+ }
55007
+ return [commentObj];
55008
+ } else if (c === BS) {
55009
+ esc = true;
55010
+ } else if (c === DS) {
55011
+ out += parseEnvVar();
55012
+ } else {
55013
+ out += c;
55014
+ }
55015
+ }
55016
+
55017
+ if (isGlob) {
55018
+ return { op: 'glob', pattern: out };
55019
+ }
55020
+
55021
+ return out;
55022
+ }).reduce(function (prev, arg) { // finalize parsed arguments
55023
+ // TODO: replace this whole reduce with a concat
55024
+ return typeof arg === 'undefined' ? prev : prev.concat(arg);
55025
+ }, []);
54871
55026
  }
54872
55027
 
55028
+ var parse$5 = function parse(s, env, opts) {
55029
+ var mapped = parseInternal(s, env, opts);
55030
+ if (typeof env !== 'function') {
55031
+ return mapped;
55032
+ }
55033
+ return mapped.reduce(function (acc, s) {
55034
+ if (typeof s === 'object') {
55035
+ return acc.concat(s);
55036
+ }
55037
+ var xs = s.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
55038
+ if (xs.length === 1) {
55039
+ return acc.concat(xs[0]);
55040
+ }
55041
+ return acc.concat(xs.filter(Boolean).map(function (x) {
55042
+ if (startsWithToken.test(x)) {
55043
+ return JSON.parse(x.split(TOKEN)[1]);
55044
+ }
55045
+ return x;
55046
+ }));
55047
+ }, []);
55048
+ };
55049
+
55050
+ shellQuote$1.quote = quote;
55051
+ shellQuote$1.parse = parse$5;
55052
+
54873
55053
  var osx = {
54874
55054
  '/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
54875
55055
  '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta':
@@ -54913,10 +55093,10 @@ var osx = {
54913
55093
  var linux = {
54914
55094
  atom: 'atom',
54915
55095
  Brackets: 'brackets',
54916
- code: 'code',
54917
55096
  'code-insiders': 'code-insiders',
54918
- codium: 'codium',
55097
+ code: 'code',
54919
55098
  vscodium: 'vscodium',
55099
+ codium: 'codium',
54920
55100
  emacs: 'emacs',
54921
55101
  gvim: 'gvim',
54922
55102
  'idea.sh': 'idea',
@@ -56510,18 +56690,20 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
56510
56690
  };
56511
56691
  urlStack = urlStack.concat(url);
56512
56692
  const isCircular = (url) => urlStack.includes(url);
56513
- const { isProduction, resolve: { dedupe, preserveSymlinks }, root, } = server.config;
56693
+ const { isProduction, resolve: { dedupe, preserveSymlinks }, root, ssr, } = server.config;
56694
+ const overrideConditions = ssr.resolve?.externalConditions || [];
56514
56695
  const resolveOptions = {
56515
56696
  mainFields: ['main'],
56516
56697
  browserField: true,
56517
56698
  conditions: [],
56518
- overrideConditions: ['production', 'development'],
56699
+ overrideConditions: [...overrideConditions, 'production', 'development'],
56519
56700
  extensions: ['.js', '.cjs', '.json'],
56520
56701
  dedupe,
56521
56702
  preserveSymlinks,
56522
56703
  isBuild: false,
56523
56704
  isProduction,
56524
56705
  root,
56706
+ ssrConfig: ssr,
56525
56707
  };
56526
56708
  // Since dynamic imports can happen in parallel, we need to
56527
56709
  // account for multiple pending deps and duplicate imports.
@@ -56619,22 +56801,13 @@ async function nodeImport(id, importer, resolveOptions) {
56619
56801
  url = id;
56620
56802
  }
56621
56803
  else {
56622
- const resolved = tryNodeResolve(id, importer,
56623
- // Non-external modules can import ESM-only modules, but only outside
56624
- // of test runs, because we use Node `require` in Jest to avoid segfault.
56625
- // @ts-expect-error jest only exists when running Jest
56626
- typeof jest === 'undefined'
56627
- ? { ...resolveOptions, tryEsmOnly: true }
56628
- : resolveOptions, false);
56804
+ const resolved = tryNodeResolve(id, importer, { ...resolveOptions, tryEsmOnly: true }, false, undefined, true);
56629
56805
  if (!resolved) {
56630
56806
  const err = new Error(`Cannot find module '${id}' imported from '${importer}'`);
56631
56807
  err.code = 'ERR_MODULE_NOT_FOUND';
56632
56808
  throw err;
56633
56809
  }
56634
- url = resolved.id;
56635
- if (usingDynamicImport) {
56636
- url = pathToFileURL(url).toString();
56637
- }
56810
+ url = pathToFileURL(resolved.id).toString();
56638
56811
  }
56639
56812
  const mod = await dynamicImport(url);
56640
56813
  return proxyESM(mod);
@@ -64885,11 +65058,16 @@ function htmlFallbackMiddleware(root, spaFallback) {
64885
65058
  return spaFallback ? `/index.html` : request.url;
64886
65059
  },
64887
65060
  },
64888
- // don't rewrite paths ending with .html
64889
65061
  {
64890
65062
  from: /\.html$/,
64891
- to({ request }) {
64892
- return request.url;
65063
+ to({ parsedUrl, request }) {
65064
+ // .html files are not handled by serveStaticMiddleware
65065
+ // so we need to check if the file exists
65066
+ const pathname = decodeURIComponent(parsedUrl.pathname);
65067
+ if (fs$l.existsSync(path$o.join(root, pathname))) {
65068
+ return request.url;
65069
+ }
65070
+ return spaFallback ? `/index.html` : request.url;
64893
65071
  },
64894
65072
  },
64895
65073
  ],
@@ -64991,7 +65169,7 @@ function transformMiddleware(server) {
64991
65169
  }
64992
65170
  else {
64993
65171
  warning =
64994
- `files in the public directory are served at the root path.\n` +
65172
+ `Files in the public directory are served at the root path.\n` +
64995
65173
  `Instead of ${colors$1.cyan(url)}, use ${colors$1.cyan(url.replace(publicPath, '/'))}.`;
64996
65174
  }
64997
65175
  logger.warn(colors$1.yellow(warning));
@@ -65316,7 +65494,10 @@ function preTransformRequest(server, url, base) {
65316
65494
  return;
65317
65495
  }
65318
65496
  // Unexpected error, log the issue but avoid an unhandled exception
65319
- server.config.logger.error(e.message);
65497
+ server.config.logger.error(`Pre-transform error: ${e.message}`, {
65498
+ error: e,
65499
+ timestamp: true,
65500
+ });
65320
65501
  });
65321
65502
  }
65322
65503
 
@@ -66273,6 +66454,7 @@ async function preview(inlineConfig = {}) {
66273
66454
  etag: true,
66274
66455
  dev: true,
66275
66456
  single: config.appType === 'spa',
66457
+ ignores: false,
66276
66458
  setHeaders(res) {
66277
66459
  if (headers) {
66278
66460
  for (const name in headers) {
@@ -66403,6 +66585,10 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
66403
66585
  allowClearScreen: config.clearScreen,
66404
66586
  customLogger: config.customLogger,
66405
66587
  });
66588
+ let foundDiscouragedVariableName;
66589
+ if ((foundDiscouragedVariableName = Object.keys(config.define ?? {}).find((k) => ['process', 'global'].includes(k)))) {
66590
+ logger.warn(colors$1.yellow(`Replacing ${colors$1.bold(foundDiscouragedVariableName)} using the define option is discouraged. See https://vitejs.dev/config/shared-options.html#define for more details.`));
66591
+ }
66406
66592
  // resolve root
66407
66593
  const resolvedRoot = normalizePath$3(config.root ? path$o.resolve(config.root) : process.cwd());
66408
66594
  if (resolvedRoot.includes('#')) {
@@ -66424,7 +66610,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
66424
66610
  mainFields: config.resolve?.mainFields ?? DEFAULT_MAIN_FIELDS,
66425
66611
  browserField: config.resolve?.browserField ?? true,
66426
66612
  conditions: config.resolve?.conditions ?? [],
66427
- extensions: config.resolve?.extensions ?? DEFAULT_EXTENSIONS$1,
66613
+ extensions: config.resolve?.extensions ?? DEFAULT_EXTENSIONS,
66428
66614
  dedupe: config.resolve?.dedupe ?? [],
66429
66615
  preserveSymlinks: config.resolve?.preserveSymlinks ?? false,
66430
66616
  alias: resolvedAlias,
@@ -66632,12 +66818,6 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
66632
66818
  else if (middlewareMode === 'html') {
66633
66819
  logger.warn(colors$1.yellow(`Setting server.middlewareMode to 'html' is deprecated, set server.middlewareMode to \`true\` instead`));
66634
66820
  }
66635
- if (config.server?.force &&
66636
- !isBuild &&
66637
- config.optimizeDeps?.force === undefined) {
66638
- resolved.optimizeDeps.force = true;
66639
- logger.warn(colors$1.yellow(`server.force is deprecated, use optimizeDeps.force instead`));
66640
- }
66641
66821
  debug?.(`using resolved config: %O`, {
66642
66822
  ...resolved,
66643
66823
  plugins: resolved.plugins.map((p) => p.name),
@@ -66819,7 +66999,7 @@ async function bundleConfigFile(fileName, isESM) {
66819
66999
  conditions: [],
66820
67000
  overrideConditions: ['node'],
66821
67001
  dedupe: [],
66822
- extensions: DEFAULT_EXTENSIONS$1,
67002
+ extensions: DEFAULT_EXTENSIONS,
66823
67003
  preserveSymlinks: false,
66824
67004
  packageCache,
66825
67005
  isRequire,