vite 5.0.0-beta.4 → 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
  };
@@ -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;
@@ -15579,16 +15631,35 @@ class Mappings {
15579
15631
 
15580
15632
  addEdit(sourceIndex, content, loc, nameIndex) {
15581
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
+
15582
15651
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
15583
15652
  if (nameIndex >= 0) {
15584
15653
  segment.push(nameIndex);
15585
15654
  }
15586
15655
  this.rawSegments.push(segment);
15656
+
15657
+ this.advance(content.slice(previousContentLineEnd + 1));
15587
15658
  } else if (this.pending) {
15588
15659
  this.rawSegments.push(this.pending);
15660
+ this.advance(content);
15589
15661
  }
15590
15662
 
15591
- this.advance(content);
15592
15663
  this.pending = null;
15593
15664
  }
15594
15665
 
@@ -27857,7 +27928,7 @@ function stringifyQuery(query) {
27857
27928
  }
27858
27929
 
27859
27930
  new Set(builtinModules);
27860
- function matchAll(regex, string, addition) {
27931
+ function matchAll$1(regex, string, addition) {
27861
27932
  const matches = [];
27862
27933
  for (const match of string.matchAll(regex)) {
27863
27934
  matches.push({
@@ -28396,7 +28467,7 @@ pathToFileURL(process.cwd());
28396
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;
28397
28468
  const TYPE_RE = /^\s*?type\s/;
28398
28469
  function findStaticImports(code) {
28399
- return matchAll(ESM_STATIC_IMPORT_RE, code, { type: "static" });
28470
+ return matchAll$1(ESM_STATIC_IMPORT_RE, code, { type: "static" });
28400
28471
  }
28401
28472
  function parseStaticImport(matched) {
28402
28473
  const cleanedImports = clearImports(matched.imports);
@@ -28461,10 +28532,15 @@ function resolvePlugin(resolveOptions) {
28461
28532
  const targetWeb = !ssr || ssrTarget === 'webworker';
28462
28533
  // this is passed by @rollup/plugin-commonjs
28463
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;
28464
28539
  const options = {
28465
28540
  isRequire,
28466
28541
  ...resolveOptions,
28467
28542
  scan: resolveOpts?.scan ?? resolveOptions.scan,
28543
+ conditions: ssr ? ssrConditions : resolveOptions.conditions,
28468
28544
  };
28469
28545
  const resolvedImports = resolveSubpathImports(id, importer, options, targetWeb);
28470
28546
  if (resolvedImports) {
@@ -28852,7 +28928,7 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr = f
28852
28928
  ...options,
28853
28929
  isRequire: false,
28854
28930
  mainFields: DEFAULT_MAIN_FIELDS,
28855
- extensions: DEFAULT_EXTENSIONS$1,
28931
+ extensions: DEFAULT_EXTENSIONS,
28856
28932
  });
28857
28933
  }
28858
28934
  if (!resolved) {
@@ -37957,6 +38033,31 @@ function buildHtmlPlugin(config) {
37957
38033
  const publicBase = getBaseInHTML(relativeUrlPath, config);
37958
38034
  const publicToRelative = (filename, importer) => publicBase + filename;
37959
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
+ };
37960
38061
  // pre-transform
37961
38062
  html = await applyHtmlTransforms(html, preHooks, {
37962
38063
  path: publicPath,
@@ -38052,7 +38153,7 @@ function buildHtmlPlugin(config) {
38052
38153
  const importExpression = `\nimport ${JSON.stringify(url)}`;
38053
38154
  styleUrls.push({
38054
38155
  url,
38055
- start: node.sourceCodeLocation.startOffset,
38156
+ start: nodeStartWithLeadingWhitespace(node),
38056
38157
  end: node.sourceCodeLocation.endOffset,
38057
38158
  });
38058
38159
  js += importExpression;
@@ -38107,7 +38208,7 @@ function buildHtmlPlugin(config) {
38107
38208
  if (shouldRemove) {
38108
38209
  // remove the script tag from the html. we are going to inject new
38109
38210
  // ones in the end.
38110
- s.remove(node.sourceCodeLocation.startOffset, node.sourceCodeLocation.endOffset);
38211
+ s.remove(nodeStartWithLeadingWhitespace(node), node.sourceCodeLocation.endOffset);
38111
38212
  }
38112
38213
  });
38113
38214
  isAsyncScriptMap.get(config).set(id, everyScriptIsAsync);
@@ -39407,8 +39508,8 @@ function createCachedImport(imp) {
39407
39508
  return cached;
39408
39509
  };
39409
39510
  }
39410
- const importPostcssImport = createCachedImport(() => import('./dep-a86a117b.js').then(function (n) { return n.i; }));
39411
- const importPostcssModules = createCachedImport(() => import('./dep-ae1dfb84.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; }));
39412
39513
  const importPostcss = createCachedImport(() => import('postcss'));
39413
39514
  /**
39414
39515
  * @experimental
@@ -40745,11 +40846,13 @@ function createIsConfiguredAsSsrExternal(config) {
40745
40846
  const noExternalFilter = noExternal !== 'undefined' &&
40746
40847
  typeof noExternal !== 'boolean' &&
40747
40848
  createFilter(undefined, noExternal, { resolve: false });
40849
+ const targetConditions = config.ssr.resolve?.externalConditions || [];
40748
40850
  const resolveOptions = {
40749
40851
  ...config.resolve,
40750
40852
  root,
40751
40853
  isProduction: false,
40752
40854
  isBuild: true,
40855
+ conditions: targetConditions,
40753
40856
  };
40754
40857
  const isExternalizable = (id, importer, configuredAsExternal) => {
40755
40858
  if (!bareImportRE.test(id) || id.includes('\0')) {
@@ -42299,6 +42402,9 @@ function importAnalysisPlugin(config) {
42299
42402
  importerModule.isSelfAccepting = false;
42300
42403
  return this.error(`Failed to resolve import "${url}" from "${path$o.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
42301
42404
  }
42405
+ if (isExternalUrl(resolved.id)) {
42406
+ return [resolved.id, resolved.id];
42407
+ }
42302
42408
  const isRelative = url[0] === '.';
42303
42409
  const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
42304
42410
  // normalize all imports into resolved URLs
@@ -42316,9 +42422,6 @@ function importAnalysisPlugin(config) {
42316
42422
  else {
42317
42423
  url = resolved.id;
42318
42424
  }
42319
- if (isExternalUrl(url)) {
42320
- return [url, url];
42321
- }
42322
42425
  // if the resolved id is not a valid browser import specifier,
42323
42426
  // prefix it to make it valid. We will strip this before feeding it
42324
42427
  // back into the transform pipeline
@@ -42516,7 +42619,10 @@ function importAnalysisPlugin(config) {
42516
42619
  return;
42517
42620
  }
42518
42621
  // Unexpected error, log the issue but avoid an unhandled exception
42519
- config.logger.error(e.message, { error: e });
42622
+ config.logger.error(`Pre-transform error: ${e.message}`, {
42623
+ error: e,
42624
+ timestamp: true,
42625
+ });
42520
42626
  });
42521
42627
  }
42522
42628
  }
@@ -45018,7 +45124,8 @@ async function computeEntries(config) {
45018
45124
  }
45019
45125
  // Non-supported entry file types and virtual files should not be scanned for
45020
45126
  // dependencies.
45021
- 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));
45022
45129
  return entries;
45023
45130
  }
45024
45131
  async function prepareEsbuildScanner(config, entries, deps, missing, scanContext) {
@@ -45148,12 +45255,11 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45148
45255
  namespace: 'html',
45149
45256
  };
45150
45257
  });
45151
- // extract scripts inside HTML-like files and treat it as a js module
45152
- build.onLoad({ filter: htmlTypesRE, namespace: 'html' }, async ({ path }) => {
45153
- let raw = await fsp.readFile(path, 'utf-8');
45258
+ const htmlTypeOnLoadCallback = async ({ path: p }) => {
45259
+ let raw = await fsp.readFile(p, 'utf-8');
45154
45260
  // Avoid matching the content of the comment
45155
45261
  raw = raw.replace(commentRE, '<!---->');
45156
- const isHtml = path.endsWith('.html');
45262
+ const isHtml = p.endsWith('.html');
45157
45263
  scriptRE.lastIndex = 0;
45158
45264
  let js = '';
45159
45265
  let scriptId = 0;
@@ -45179,7 +45285,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45179
45285
  if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
45180
45286
  loader = lang;
45181
45287
  }
45182
- else if (path.endsWith('.astro')) {
45288
+ else if (p.endsWith('.astro')) {
45183
45289
  loader = 'ts';
45184
45290
  }
45185
45291
  const srcMatch = openTag.match(srcRE);
@@ -45197,11 +45303,12 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45197
45303
  // since they may be used in the template
45198
45304
  const contents = content +
45199
45305
  (loader.startsWith('ts') ? extractImportPaths(content) : '');
45200
- const key = `${path}?id=${scriptId++}`;
45306
+ const key = `${p}?id=${scriptId++}`;
45201
45307
  if (contents.includes('import.meta.glob')) {
45202
45308
  scripts[key] = {
45203
45309
  loader: 'js',
45204
- contents: await doTransformGlobImport(contents, path, loader),
45310
+ contents: await doTransformGlobImport(contents, p, loader),
45311
+ resolveDir: normalizePath$3(path$o.dirname(p)),
45205
45312
  pluginData: {
45206
45313
  htmlType: { loader },
45207
45314
  },
@@ -45211,6 +45318,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45211
45318
  scripts[key] = {
45212
45319
  loader,
45213
45320
  contents,
45321
+ resolveDir: normalizePath$3(path$o.dirname(p)),
45214
45322
  pluginData: {
45215
45323
  htmlType: { loader },
45216
45324
  },
@@ -45223,7 +45331,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45223
45331
  // Especially for Svelte files, exports in <script context="module"> means module exports,
45224
45332
  // exports in <script> means component props. To avoid having two same export name from the
45225
45333
  // star exports, we need to ignore exports in <script>
45226
- if (path.endsWith('.svelte') && context !== 'module') {
45334
+ if (p.endsWith('.svelte') && context !== 'module') {
45227
45335
  js += `import ${virtualModulePath}\n`;
45228
45336
  }
45229
45337
  else {
@@ -45235,14 +45343,20 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45235
45343
  // anywhere in a string. Svelte and Astro files can't have
45236
45344
  // `export default` as code so we know if it's encountered it's a
45237
45345
  // false positive (e.g. contained in a string)
45238
- if (!path.endsWith('.vue') || !js.includes('export default')) {
45346
+ if (!p.endsWith('.vue') || !js.includes('export default')) {
45239
45347
  js += '\nexport default {}';
45240
45348
  }
45241
45349
  return {
45242
45350
  loader: 'js',
45243
45351
  contents: js,
45244
45352
  };
45245
- });
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);
45246
45360
  // bare imports: record and externalize ----------------------------------
45247
45361
  build.onResolve({
45248
45362
  // avoid matching windows volume
@@ -45270,7 +45384,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45270
45384
  }
45271
45385
  return externalUnlessEntry({ path: id });
45272
45386
  }
45273
- else if (isScannable(resolved)) {
45387
+ else if (isScannable(resolved, config.optimizeDeps.extensions)) {
45274
45388
  const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined;
45275
45389
  // linked package, keep crawling
45276
45390
  return {
@@ -45315,7 +45429,8 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
45315
45429
  },
45316
45430
  });
45317
45431
  if (resolved) {
45318
- if (shouldExternalizeDep(resolved, id) || !isScannable(resolved)) {
45432
+ if (shouldExternalizeDep(resolved, id) ||
45433
+ !isScannable(resolved, config.optimizeDeps.extensions)) {
45319
45434
  return externalUnlessEntry({ path: id });
45320
45435
  }
45321
45436
  const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined;
@@ -45387,8 +45502,11 @@ function shouldExternalizeDep(resolvedId, rawId) {
45387
45502
  }
45388
45503
  return false;
45389
45504
  }
45390
- function isScannable(id) {
45391
- 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);
45392
45510
  }
45393
45511
  // esbuild v0.18 only transforms decorators when `experimentalDecorators` is set to `true`.
45394
45512
  // To preserve compat with the esbuild breaking change, we set `experimentalDecorators` to
@@ -54689,206 +54807,249 @@ chokidar.watch = watch;
54689
54807
 
54690
54808
  var shellQuote$1 = {};
54691
54809
 
54692
- shellQuote$1.quote = function (xs) {
54693
- return xs.map(function (s) {
54694
- if (s && typeof s === 'object') {
54695
- return s.op.replace(/(.)/g, '\\$1');
54696
- }
54697
- else if (/["\s]/.test(s) && !/'/.test(s)) {
54698
- return "'" + s.replace(/(['\\])/g, '\\$1') + "'";
54699
- }
54700
- else if (/["'\s]/.test(s)) {
54701
- return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';
54702
- }
54703
- else {
54704
- return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@\[\\\]^`{|}])/g, '$1\\$2');
54705
- }
54706
- }).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(' ');
54707
54823
  };
54708
54824
 
54709
54825
  // '<(' is process substitution operator and
54710
54826
  // can be parsed the same as control operator
54711
54827
  var CONTROL = '(?:' + [
54712
- '\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '>>', '>\\&', '[&;()|<>]'
54828
+ '\\|\\|',
54829
+ '\\&\\&',
54830
+ ';;',
54831
+ '\\|\\&',
54832
+ '\\<\\(',
54833
+ '\\<\\<\\<',
54834
+ '>>',
54835
+ '>\\&',
54836
+ '<\\&',
54837
+ '[&;()|<>]'
54713
54838
  ].join('|') + ')';
54839
+ var controlRE = new RegExp('^' + CONTROL + '$');
54714
54840
  var META = '|&;()<> \\t';
54715
- var BAREWORD = '(\\\\[\'"' + META + ']|[^\\s\'"' + META + '])+';
54716
54841
  var SINGLE_QUOTE = '"((\\\\"|[^"])*?)"';
54717
54842
  var DOUBLE_QUOTE = '\'((\\\\\'|[^\'])*?)\'';
54843
+ var hash = /^#$/;
54844
+
54845
+ var SQ = "'";
54846
+ var DQ = '"';
54847
+ var DS = '$';
54718
54848
 
54719
54849
  var TOKEN = '';
54850
+ var mult = 0x100000000; // Math.pow(16, 8);
54720
54851
  for (var i = 0; i < 4; i++) {
54721
- TOKEN += (Math.pow(16,8)*Math.random()).toString(16);
54852
+ TOKEN += (mult * Math.random()).toString(16);
54722
54853
  }
54854
+ var startsWithToken = new RegExp('^' + TOKEN);
54723
54855
 
54724
- shellQuote$1.parse = function (s, env, opts) {
54725
- var mapped = parse$5(s, env, opts);
54726
- if (typeof env !== 'function') return mapped;
54727
- return mapped.reduce(function (acc, s) {
54728
- if (typeof s === 'object') return acc.concat(s);
54729
- var xs = s.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
54730
- if (xs.length === 1) return acc.concat(xs[0]);
54731
- return acc.concat(xs.filter(Boolean).map(function (x) {
54732
- if (RegExp('^' + TOKEN).test(x)) {
54733
- return JSON.parse(x.split(TOKEN)[1]);
54734
- }
54735
- else return x;
54736
- }));
54737
- }, []);
54738
- };
54856
+ function matchAll(s, r) {
54857
+ var origIndex = r.lastIndex;
54739
54858
 
54740
- function parse$5 (s, env, opts) {
54741
- var chunker = new RegExp([
54742
- '(' + CONTROL + ')', // control chars
54743
- '(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')*'
54744
- ].join('|'), 'g');
54745
- var match = s.match(chunker).filter(Boolean);
54746
- var commented = false;
54859
+ var matches = [];
54860
+ var matchObj;
54747
54861
 
54748
- if (!match) return [];
54749
- if (!env) env = {};
54750
- if (!opts) opts = {};
54751
- return match.map(function (s, j) {
54752
- if (commented) {
54753
- return;
54754
- }
54755
- if (RegExp('^' + CONTROL + '$').test(s)) {
54756
- return { op: s };
54757
- }
54862
+ while ((matchObj = r.exec(s))) {
54863
+ matches.push(matchObj);
54864
+ if (r.lastIndex === matchObj.index) {
54865
+ r.lastIndex += 1;
54866
+ }
54867
+ }
54758
54868
 
54759
- // Hand-written scanner/parser for Bash quoting rules:
54760
- //
54761
- // 1. inside single quotes, all characters are printed literally.
54762
- // 2. inside double quotes, all characters are printed literally
54763
- // except variables prefixed by '$' and backslashes followed by
54764
- // either a double quote or another backslash.
54765
- // 3. outside of any quotes, backslashes are treated as escape
54766
- // characters and not printed (unless they are themselves escaped)
54767
- // 4. quote context can switch mid-token if there is no whitespace
54768
- // between the two quote contexts (e.g. all'one'"token" parses as
54769
- // "allonetoken")
54770
- var SQ = "'";
54771
- var DQ = '"';
54772
- var DS = '$';
54773
- var BS = opts.escape || '\\';
54774
- var quote = false;
54775
- var esc = false;
54776
- var out = '';
54777
- var isGlob = false;
54778
-
54779
- for (var i = 0, len = s.length; i < len; i++) {
54780
- var c = s.charAt(i);
54781
- isGlob = isGlob || (!quote && (c === '*' || c === '?'));
54782
- if (esc) {
54783
- out += c;
54784
- esc = false;
54785
- }
54786
- else if (quote) {
54787
- if (c === quote) {
54788
- quote = false;
54789
- }
54790
- else if (quote == SQ) {
54791
- out += c;
54792
- }
54793
- else { // Double quote
54794
- if (c === BS) {
54795
- i += 1;
54796
- c = s.charAt(i);
54797
- if (c === DQ || c === BS || c === DS) {
54798
- out += c;
54799
- } else {
54800
- out += BS + c;
54801
- }
54802
- }
54803
- else if (c === DS) {
54804
- out += parseEnvVar();
54805
- }
54806
- else {
54807
- out += c;
54808
- }
54809
- }
54810
- }
54811
- else if (c === DQ || c === SQ) {
54812
- quote = c;
54813
- }
54814
- else if (RegExp('^' + CONTROL + '$').test(c)) {
54815
- return { op: s };
54816
- }
54817
- else if (RegExp('^#$').test(c)) {
54818
- commented = true;
54819
- if (out.length){
54820
- return [out, { comment: s.slice(i+1) + match.slice(j+1).join(' ') }];
54821
- }
54822
- return [{ comment: s.slice(i+1) + match.slice(j+1).join(' ') }];
54823
- }
54824
- else if (c === BS) {
54825
- esc = true;
54826
- }
54827
- else if (c === DS) {
54828
- out += parseEnvVar();
54829
- }
54830
- else out += c;
54831
- }
54869
+ r.lastIndex = origIndex;
54832
54870
 
54833
- if (isGlob) return {op: 'glob', pattern: out};
54871
+ return matches;
54872
+ }
54834
54873
 
54835
- 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
+ }
54836
54881
 
54837
- function parseEnvVar() {
54838
- i += 1;
54839
- var varend, varname;
54840
- //debugger
54841
- if (s.charAt(i) === '{') {
54842
- i += 1;
54843
- if (s.charAt(i) === '}') {
54844
- throw new Error("Bad substitution: " + s.substr(i - 2, 3));
54845
- }
54846
- varend = s.indexOf('}', i);
54847
- if (varend < 0) {
54848
- throw new Error("Bad substitution: " + s.substr(i));
54849
- }
54850
- varname = s.substr(i, varend - i);
54851
- i = varend;
54852
- }
54853
- else if (/[*@#?$!_\-]/.test(s.charAt(i))) {
54854
- varname = s.charAt(i);
54855
- i += 1;
54856
- }
54857
- else {
54858
- varend = s.substr(i).match(/[^\w\d_]/);
54859
- if (!varend) {
54860
- varname = s.substr(i);
54861
- i = s.length;
54862
- } else {
54863
- varname = s.substr(i, varend.index);
54864
- i += varend.index - 1;
54865
- }
54866
- }
54867
- return getVar(null, '', varname);
54868
- }
54869
- })
54870
- // finalize parsed aruments
54871
- .reduce(function(prev, arg){
54872
- if (arg === undefined){
54873
- return prev;
54874
- }
54875
- return prev.concat(arg);
54876
- },[]);
54882
+ if (typeof r === 'object') {
54883
+ return pre + TOKEN + JSON.stringify(r) + TOKEN;
54884
+ }
54885
+ return pre + r;
54886
+ }
54877
54887
 
54878
- function getVar (_, pre, key) {
54879
- var r = typeof env === 'function' ? env(key) : env[key];
54880
- if (r === undefined && key != '')
54881
- r = '';
54882
- else if (r === undefined)
54883
- 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 + '])+';
54884
54894
 
54885
- if (typeof r === 'object') {
54886
- return pre + TOKEN + JSON.stringify(r) + TOKEN;
54887
- }
54888
- else return pre + r;
54889
- }
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
+ }, []);
54890
55026
  }
54891
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
+
54892
55053
  var osx = {
54893
55054
  '/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
54894
55055
  '/Applications/Atom Beta.app/Contents/MacOS/Atom Beta':
@@ -54932,10 +55093,10 @@ var osx = {
54932
55093
  var linux = {
54933
55094
  atom: 'atom',
54934
55095
  Brackets: 'brackets',
54935
- code: 'code',
54936
55096
  'code-insiders': 'code-insiders',
54937
- codium: 'codium',
55097
+ code: 'code',
54938
55098
  vscodium: 'vscodium',
55099
+ codium: 'codium',
54939
55100
  emacs: 'emacs',
54940
55101
  gvim: 'gvim',
54941
55102
  'idea.sh': 'idea',
@@ -56529,18 +56690,20 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
56529
56690
  };
56530
56691
  urlStack = urlStack.concat(url);
56531
56692
  const isCircular = (url) => urlStack.includes(url);
56532
- const { isProduction, resolve: { dedupe, preserveSymlinks }, root, } = server.config;
56693
+ const { isProduction, resolve: { dedupe, preserveSymlinks }, root, ssr, } = server.config;
56694
+ const overrideConditions = ssr.resolve?.externalConditions || [];
56533
56695
  const resolveOptions = {
56534
56696
  mainFields: ['main'],
56535
56697
  browserField: true,
56536
56698
  conditions: [],
56537
- overrideConditions: ['production', 'development'],
56699
+ overrideConditions: [...overrideConditions, 'production', 'development'],
56538
56700
  extensions: ['.js', '.cjs', '.json'],
56539
56701
  dedupe,
56540
56702
  preserveSymlinks,
56541
56703
  isBuild: false,
56542
56704
  isProduction,
56543
56705
  root,
56706
+ ssrConfig: ssr,
56544
56707
  };
56545
56708
  // Since dynamic imports can happen in parallel, we need to
56546
56709
  // account for multiple pending deps and duplicate imports.
@@ -56638,22 +56801,13 @@ async function nodeImport(id, importer, resolveOptions) {
56638
56801
  url = id;
56639
56802
  }
56640
56803
  else {
56641
- const resolved = tryNodeResolve(id, importer,
56642
- // Non-external modules can import ESM-only modules, but only outside
56643
- // of test runs, because we use Node `require` in Jest to avoid segfault.
56644
- // @ts-expect-error jest only exists when running Jest
56645
- typeof jest === 'undefined'
56646
- ? { ...resolveOptions, tryEsmOnly: true }
56647
- : resolveOptions, false);
56804
+ const resolved = tryNodeResolve(id, importer, { ...resolveOptions, tryEsmOnly: true }, false, undefined, true);
56648
56805
  if (!resolved) {
56649
56806
  const err = new Error(`Cannot find module '${id}' imported from '${importer}'`);
56650
56807
  err.code = 'ERR_MODULE_NOT_FOUND';
56651
56808
  throw err;
56652
56809
  }
56653
- url = resolved.id;
56654
- if (usingDynamicImport) {
56655
- url = pathToFileURL(url).toString();
56656
- }
56810
+ url = pathToFileURL(resolved.id).toString();
56657
56811
  }
56658
56812
  const mod = await dynamicImport(url);
56659
56813
  return proxyESM(mod);
@@ -65015,7 +65169,7 @@ function transformMiddleware(server) {
65015
65169
  }
65016
65170
  else {
65017
65171
  warning =
65018
- `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` +
65019
65173
  `Instead of ${colors$1.cyan(url)}, use ${colors$1.cyan(url.replace(publicPath, '/'))}.`;
65020
65174
  }
65021
65175
  logger.warn(colors$1.yellow(warning));
@@ -65340,7 +65494,10 @@ function preTransformRequest(server, url, base) {
65340
65494
  return;
65341
65495
  }
65342
65496
  // Unexpected error, log the issue but avoid an unhandled exception
65343
- server.config.logger.error(e.message);
65497
+ server.config.logger.error(`Pre-transform error: ${e.message}`, {
65498
+ error: e,
65499
+ timestamp: true,
65500
+ });
65344
65501
  });
65345
65502
  }
65346
65503
 
@@ -66453,7 +66610,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
66453
66610
  mainFields: config.resolve?.mainFields ?? DEFAULT_MAIN_FIELDS,
66454
66611
  browserField: config.resolve?.browserField ?? true,
66455
66612
  conditions: config.resolve?.conditions ?? [],
66456
- extensions: config.resolve?.extensions ?? DEFAULT_EXTENSIONS$1,
66613
+ extensions: config.resolve?.extensions ?? DEFAULT_EXTENSIONS,
66457
66614
  dedupe: config.resolve?.dedupe ?? [],
66458
66615
  preserveSymlinks: config.resolve?.preserveSymlinks ?? false,
66459
66616
  alias: resolvedAlias,
@@ -66661,12 +66818,6 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
66661
66818
  else if (middlewareMode === 'html') {
66662
66819
  logger.warn(colors$1.yellow(`Setting server.middlewareMode to 'html' is deprecated, set server.middlewareMode to \`true\` instead`));
66663
66820
  }
66664
- if (config.server?.force &&
66665
- !isBuild &&
66666
- config.optimizeDeps?.force === undefined) {
66667
- resolved.optimizeDeps.force = true;
66668
- logger.warn(colors$1.yellow(`server.force is deprecated, use optimizeDeps.force instead`));
66669
- }
66670
66821
  debug?.(`using resolved config: %O`, {
66671
66822
  ...resolved,
66672
66823
  plugins: resolved.plugins.map((p) => p.name),
@@ -66848,7 +66999,7 @@ async function bundleConfigFile(fileName, isESM) {
66848
66999
  conditions: [],
66849
67000
  overrideConditions: ['node'],
66850
67001
  dedupe: [],
66851
- extensions: DEFAULT_EXTENSIONS$1,
67002
+ extensions: DEFAULT_EXTENSIONS,
66852
67003
  preserveSymlinks: false,
66853
67004
  packageCache,
66854
67005
  isRequire,