vite 6.0.0-beta.1 → 6.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,15 @@
1
1
  import * as fs$j from 'node:fs';
2
- import fs__default, { promises as promises$1 } from 'node:fs';
2
+ import fs__default, { promises as promises$1, existsSync as existsSync$1, readFileSync as readFileSync$1 } from 'node:fs';
3
3
  import fsp, { lstat as lstat$3, readdir as readdir$5, readlink, realpath as realpath$2 } from 'node:fs/promises';
4
4
  import path$n, { win32 as win32$1, posix as posix$1, isAbsolute as isAbsolute$1, join as join$2, dirname as dirname$2, relative as relative$2, basename as basename$2, extname as extname$1 } from 'node:path';
5
- import { fileURLToPath, URL as URL$3, parse as parse$h, pathToFileURL } from 'node:url';
5
+ import { fileURLToPath, URL as URL$3, pathToFileURL } from 'node:url';
6
6
  import { promisify as promisify$4, format as format$2, inspect } from 'node:util';
7
7
  import { performance as performance$1 } from 'node:perf_hooks';
8
8
  import { createRequire as createRequire$1, builtinModules } from 'node:module';
9
9
  import require$$0$3 from 'tty';
10
10
  import esbuild, { transform as transform$1, formatMessages, build as build$3 } from 'esbuild';
11
- import require$$0$4, { win32, posix, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, sep as sep$1, normalize as normalize$1 } from 'path';
12
- import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, ENV_ENTRY, SPECIAL_QUERY_RE, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, KNOWN_ASSET_TYPES, JS_TYPES_RE, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, VITE_PACKAGE_DIR, CLIENT_DIR, DEFAULT_DEV_PORT, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
11
+ import require$$0$4, { posix, win32, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, sep as sep$1, normalize as normalize$1 } from 'path';
12
+ import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, ENV_ENTRY, SPECIAL_QUERY_RE, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, KNOWN_ASSET_TYPES, JS_TYPES_RE, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ERR_OUTDATED_OPTIMIZED_DEP, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, VITE_PACKAGE_DIR, CLIENT_DIR, DEFAULT_DEV_PORT, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
13
13
  import * as require$$0$2 from 'fs';
14
14
  import require$$0__default, { lstatSync, readdir as readdir$4, readdirSync, readlinkSync, realpathSync as realpathSync$1, existsSync, readFileSync, statSync as statSync$1 } from 'fs';
15
15
  import { EventEmitter as EventEmitter$4 } from 'node:events';
@@ -31,13 +31,13 @@ import { createHash as createHash$2 } from 'node:crypto';
31
31
  import { promises } from 'node:dns';
32
32
  import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
33
33
  import { parseAstAsync, parseAst } from 'rollup/parseAst';
34
+ import readline from 'node:readline';
35
+ import require$$3$1 from 'crypto';
34
36
  import require$$0$8, { createRequire as createRequire$2 } from 'module';
35
37
  import assert$1 from 'node:assert';
36
38
  import v8 from 'node:v8';
37
39
  import { Worker as Worker$1 } from 'node:worker_threads';
38
- import require$$3$1 from 'crypto';
39
40
  import { Buffer as Buffer$1 } from 'node:buffer';
40
- import readline from 'node:readline';
41
41
  import zlib$1 from 'zlib';
42
42
  import require$$0$a from 'buffer';
43
43
  import require$$1$1 from 'https';
@@ -2265,19 +2265,16 @@ const postfixRE = /[?#].*$/;
2265
2265
  function cleanUrl(url) {
2266
2266
  return url.replace(postfixRE, "");
2267
2267
  }
2268
+ function splitFileAndPostfix(path) {
2269
+ const file = cleanUrl(path);
2270
+ return { file, postfix: path.slice(file.length) };
2271
+ }
2268
2272
  function withTrailingSlash(path) {
2269
2273
  if (path[path.length - 1] !== "/") {
2270
2274
  return `${path}/`;
2271
2275
  }
2272
2276
  return path;
2273
2277
  }
2274
- const AsyncFunction = async function() {
2275
- }.constructor;
2276
- const asyncFunctionDeclarationPaddingLineCount = /* @__PURE__ */ (() => {
2277
- const body = "/*code*/";
2278
- const source = new AsyncFunction("a", "b", body).toString();
2279
- return source.slice(0, source.indexOf(body)).split("\n").length - 1;
2280
- })();
2281
2278
 
2282
2279
  // @ts-check
2283
2280
  /** @typedef { import('estree').BaseNode} BaseNode */
@@ -2554,7 +2551,7 @@ const attachScopes = function attachScopes(ast, propertyName = 'scope') {
2554
2551
  const node = n;
2555
2552
  // function foo () {...}
2556
2553
  // class Foo {...}
2557
- if (/(Function|Class)Declaration/.test(node.type)) {
2554
+ if (/(?:Function|Class)Declaration/.test(node.type)) {
2558
2555
  scope.addDeclaration(node, false, false);
2559
2556
  }
2560
2557
  // var foo = 1
@@ -2581,7 +2578,7 @@ const attachScopes = function attachScopes(ast, propertyName = 'scope') {
2581
2578
  }
2582
2579
  }
2583
2580
  // create new for scope
2584
- if (/For(In|Of)?Statement/.test(node.type)) {
2581
+ if (/For(?:In|Of)?Statement/.test(node.type)) {
2585
2582
  newScope = new Scope({
2586
2583
  parent: scope,
2587
2584
  block: true
@@ -2631,8 +2628,9 @@ function ensureArray(thing) {
2631
2628
  return [thing];
2632
2629
  }
2633
2630
 
2631
+ const normalizePathRegExp = new RegExp(`\\${win32.sep}`, 'g');
2634
2632
  const normalizePath$5 = function normalizePath(filename) {
2635
- return filename.split(win32.sep).join(posix.sep);
2633
+ return filename.replace(normalizePathRegExp, posix.sep);
2636
2634
  };
2637
2635
 
2638
2636
  function getMatcherString(id, resolutionBase) {
@@ -2664,10 +2662,12 @@ const createFilter$1 = function createFilter(include, exclude, options) {
2664
2662
  };
2665
2663
  const includeMatchers = ensureArray(include).map(getMatcher);
2666
2664
  const excludeMatchers = ensureArray(exclude).map(getMatcher);
2665
+ if (!includeMatchers.length && !excludeMatchers.length)
2666
+ return (id) => typeof id === 'string' && !id.includes('\0');
2667
2667
  return function result(id) {
2668
2668
  if (typeof id !== 'string')
2669
2669
  return false;
2670
- if (/\0/.test(id))
2670
+ if (id.includes('\0'))
2671
2671
  return false;
2672
2672
  const pathId = normalizePath$5(id);
2673
2673
  for (let i = 0; i < excludeMatchers.length; ++i) {
@@ -2778,7 +2778,7 @@ const dataToEsm = function dataToEsm(data, options = {}) {
2778
2778
  }
2779
2779
  let maxUnderbarPrefixLength = 0;
2780
2780
  for (const key of Object.keys(data)) {
2781
- const underbarPrefixLength = (_b = (_a = key.match(/^(_+)/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
2781
+ const underbarPrefixLength = (_b = (_a = /^(_+)/.exec(key)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
2782
2782
  if (underbarPrefixLength > maxUnderbarPrefixLength) {
2783
2783
  maxUnderbarPrefixLength = underbarPrefixLength;
2784
2784
  }
@@ -12185,7 +12185,7 @@ function isReference(node, parent) {
12185
12185
  return false;
12186
12186
  }
12187
12187
 
12188
- var version$2 = "26.0.1";
12188
+ var version$2 = "26.0.3";
12189
12189
  var peerDependencies = {
12190
12190
  rollup: "^2.68.0||^3.0.0||^4.0.0"
12191
12191
  };
@@ -16706,11 +16706,8 @@ function isOptimizable(id, optimizeDeps) {
16706
16706
  const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/;
16707
16707
  const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
16708
16708
  const _require$1 = createRequire$1(import.meta.url);
16709
- function resolveDependencyVersion(dep, pkgRelativePath = "../../package.json") {
16710
- const pkgPath = path$n.resolve(_require$1.resolve(dep), pkgRelativePath);
16711
- return JSON.parse(fs__default.readFileSync(pkgPath, "utf-8")).version;
16712
- }
16713
- const rollupVersion = resolveDependencyVersion("rollup");
16709
+ const _dirname = path$n.dirname(fileURLToPath(import.meta.url));
16710
+ const rollupVersion = resolvePackageData("rollup", _dirname, true)?.data.version ?? "";
16714
16711
  const filter = process.env.VITE_DEBUG_FILTER;
16715
16712
  const DEBUG = process.env.DEBUG;
16716
16713
  function createDebugger(namespace, options = {}) {
@@ -17329,7 +17326,6 @@ function getHash(text, length = 8) {
17329
17326
  if (length <= 64) return h;
17330
17327
  return h.padEnd(length, "_");
17331
17328
  }
17332
- const _dirname = path$n.dirname(fileURLToPath(import.meta.url));
17333
17329
  const requireResolveFromRootWithFallback = (root, id) => {
17334
17330
  const found = resolvePackageData(id, root) || resolvePackageData(id, _dirname);
17335
17331
  if (!found) {
@@ -17797,7 +17793,7 @@ function buildReporterPlugin(config) {
17797
17793
  let chunkCount = 0;
17798
17794
  let compressedCount = 0;
17799
17795
  async function getCompressedSize(code) {
17800
- if (environment.config.build.ssr || !environment.config.build.reportCompressedSize) {
17796
+ if (environment.config.consumer !== "client" || !environment.config.build.reportCompressedSize) {
17801
17797
  return null;
17802
17798
  }
17803
17799
  if (shouldLogInfo && !hasCompressChunk) {
@@ -17928,7 +17924,7 @@ function buildReporterPlugin(config) {
17928
17924
  return chunk.type === "chunk" && chunk.code.length / 1e3 > chunkLimit;
17929
17925
  });
17930
17926
  }
17931
- if (hasLargeChunks && environment.config.build.minify && !config.build.lib && !environment.config.build.ssr) {
17927
+ if (hasLargeChunks && environment.config.build.minify && !config.build.lib && environment.config.consumer === "client") {
17932
17928
  environment.logger.warn(
17933
17929
  colors$1.yellow(
17934
17930
  `
@@ -20383,7 +20379,7 @@ async function fileToBuiltUrl(pluginContext, id, skipPublicCheck = false, forceI
20383
20379
  if (cached) {
20384
20380
  return cached;
20385
20381
  }
20386
- const file = cleanUrl(id);
20382
+ const { file, postfix } = splitFileAndPostfix(id);
20387
20383
  const content = await fsp.readFile(file);
20388
20384
  let url;
20389
20385
  if (shouldInline(pluginContext, file, id, content, forceInline)) {
@@ -20399,8 +20395,6 @@ async function fileToBuiltUrl(pluginContext, id, skipPublicCheck = false, forceI
20399
20395
  url = `data:${mimeType};base64,${content.toString("base64")}`;
20400
20396
  }
20401
20397
  } else {
20402
- const { search, hash } = parse$h(id);
20403
- const postfix = (search || "") + (hash || "");
20404
20398
  const originalFileName = normalizePath$3(
20405
20399
  path$n.relative(environment.config.root, file)
20406
20400
  );
@@ -20613,7 +20607,7 @@ function dataURIPlugin() {
20613
20607
  resolved = /* @__PURE__ */ new Map();
20614
20608
  },
20615
20609
  resolveId(id) {
20616
- if (!dataUriRE.test(id)) {
20610
+ if (!id.trimStart().startsWith("data:")) {
20617
20611
  return;
20618
20612
  }
20619
20613
  const uri = new URL$3(id);
@@ -32478,6 +32472,9 @@ function getFirstKeyStartProps(prev) {
32478
32472
  break loop;
32479
32473
  }
32480
32474
  }
32475
+ while (prev[++i]?.type === 'space') {
32476
+ /* loop */
32477
+ }
32481
32478
  return prev.splice(i, prev.length);
32482
32479
  }
32483
32480
  function fixFlowSeqItems(fc) {
@@ -35153,10 +35150,6 @@ function ensureVersionQuery(resolved, id, options, ssr, depsOptimizer) {
35153
35150
  }
35154
35151
  return resolved;
35155
35152
  }
35156
- function splitFileAndPostfix(path2) {
35157
- const file = cleanUrl(path2);
35158
- return { file, postfix: path2.slice(file.length) };
35159
- }
35160
35153
  function tryFsResolve(fsPath, options, tryIndex = true, skipPackageJson = false) {
35161
35154
  const hashIndex = fsPath.indexOf("#");
35162
35155
  if (hashIndex >= 0 && isInNodeModules$1(fsPath)) {
@@ -35897,6 +35890,16 @@ const environmentColors = [
35897
35890
  colors$1.green,
35898
35891
  colors$1.gray
35899
35892
  ];
35893
+ function getDefaultResolvedEnvironmentOptions(config) {
35894
+ return {
35895
+ define: config.define,
35896
+ resolve: config.resolve,
35897
+ consumer: "server",
35898
+ webCompatible: false,
35899
+ dev: config.dev,
35900
+ build: config.build
35901
+ };
35902
+ }
35900
35903
  class PartialEnvironment {
35901
35904
  name;
35902
35905
  getTopLevelConfig() {
@@ -38188,7 +38191,8 @@ function getConfigHash(environment) {
38188
38191
  ...optimizeDeps2?.esbuildOptions,
38189
38192
  plugins: optimizeDeps2?.esbuildOptions?.plugins?.map((p) => p.name)
38190
38193
  }
38191
- }
38194
+ },
38195
+ webCompatible: config.webCompatible
38192
38196
  },
38193
38197
  (_, value) => {
38194
38198
  if (typeof value === "function" || value instanceof RegExp) {
@@ -38371,9 +38375,6 @@ function extractJsonErrorPosition(errorMessage, inputLength) {
38371
38375
  return errorMessageList ? Math.max(parseInt(errorMessageList[1], 10) - 1, 0) : void 0;
38372
38376
  }
38373
38377
 
38374
- const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR";
38375
- const ERR_OUTDATED_OPTIMIZED_DEP = "ERR_OUTDATED_OPTIMIZED_DEP";
38376
- const ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR = "ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR";
38377
38378
  const debug$b = createDebugger("vite:optimize-deps");
38378
38379
  function optimizedDepsPlugin() {
38379
38380
  return {
@@ -45814,17 +45815,17 @@ function ssrFixStacktrace(e, moduleGraph) {
45814
45815
  }
45815
45816
 
45816
45817
  async function ssrLoadModule(url, server, fixStacktrace) {
45817
- server._ssrCompatModuleRunner ||= new SSRCompatModuleRunner(server);
45818
+ const environment = server.environments.ssr;
45819
+ server._ssrCompatModuleRunner ||= new SSRCompatModuleRunner(environment);
45818
45820
  url = unwrapId$1(url);
45819
45821
  return instantiateModule(
45820
45822
  url,
45821
45823
  server._ssrCompatModuleRunner,
45822
- server,
45824
+ environment,
45823
45825
  fixStacktrace
45824
45826
  );
45825
45827
  }
45826
- async function instantiateModule(url, runner, server, fixStacktrace) {
45827
- const environment = server.environments.ssr;
45828
+ async function instantiateModule(url, runner, environment, fixStacktrace) {
45828
45829
  const mod = await environment.moduleGraph.ensureEntryFromUrl(url);
45829
45830
  if (mod.ssrError) {
45830
45831
  throw mod.ssrError;
@@ -45841,7 +45842,7 @@ async function instantiateModule(url, runner, server, fixStacktrace) {
45841
45842
  `),
45842
45843
  {
45843
45844
  timestamp: true,
45844
- clear: server.config.clearScreen,
45845
+ clear: environment.config.clearScreen,
45845
45846
  error: e
45846
45847
  }
45847
45848
  );
@@ -45849,31 +45850,31 @@ async function instantiateModule(url, runner, server, fixStacktrace) {
45849
45850
  }
45850
45851
  }
45851
45852
  class SSRCompatModuleRunner extends ModuleRunner {
45852
- constructor(server) {
45853
+ constructor(environment) {
45853
45854
  super(
45854
45855
  {
45855
- root: server.environments.ssr.config.root,
45856
+ root: environment.config.root,
45856
45857
  transport: {
45857
- fetchModule: (id, importer, options) => server.environments.ssr.fetchModule(id, importer, options)
45858
+ fetchModule: (id, importer, options) => environment.fetchModule(id, importer, options)
45858
45859
  },
45859
45860
  sourcemapInterceptor: false,
45860
45861
  hmr: false
45861
45862
  },
45862
45863
  new ESModulesEvaluator()
45863
45864
  );
45864
- this.server = server;
45865
+ this.environment = environment;
45865
45866
  }
45866
- async directRequest(id, mod, _callstack) {
45867
- const serverId = mod.meta && "serverId" in mod.meta && mod.meta.serverId;
45868
- if (!serverId) {
45869
- return super.directRequest(id, mod, _callstack);
45867
+ async directRequest(url, mod, callstack) {
45868
+ const id = mod.meta && "id" in mod.meta && mod.meta.id;
45869
+ if (!id) {
45870
+ return super.directRequest(url, mod, callstack);
45870
45871
  }
45871
- const viteMod = this.server.environments.ssr.moduleGraph.getModuleById(serverId);
45872
+ const viteMod = this.environment.moduleGraph.getModuleById(id);
45872
45873
  if (!viteMod) {
45873
- return super.directRequest(id, mod, _callstack);
45874
+ return super.directRequest(id, mod, callstack);
45874
45875
  }
45875
45876
  try {
45876
- const exports = await super.directRequest(id, mod, _callstack);
45877
+ const exports = await super.directRequest(id, mod, callstack);
45877
45878
  viteMod.ssrModule = exports;
45878
45879
  return exports;
45879
45880
  } catch (err) {
@@ -46233,7 +46234,7 @@ Contents of line ${line}: ${code.split("\n")[line - 1]}`
46233
46234
  s.appendLeft(
46234
46235
  position,
46235
46236
  `
46236
- Object.defineProperty(${ssrModuleExportsKey}, "${name}", { enumerable: true, configurable: true, get(){ return ${local} }});`
46237
+ Object.defineProperty(${ssrModuleExportsKey}, ${JSON.stringify(name)}, { enumerable: true, configurable: true, get(){ return ${local} }});`
46237
46238
  );
46238
46239
  }
46239
46240
  const imports = [];
@@ -46249,10 +46250,7 @@ Object.defineProperty(${ssrModuleExportsKey}, "${name}", { enumerable: true, con
46249
46250
  const importId = defineImport(hoistIndex, node.source.value, {
46250
46251
  importedNames: node.specifiers.map((s2) => {
46251
46252
  if (s2.type === "ImportSpecifier")
46252
- return s2.imported.type === "Identifier" ? s2.imported.name : (
46253
- // @ts-expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
46254
- s2.imported.value
46255
- );
46253
+ return getIdentifierNameOrLiteralValue(s2.imported);
46256
46254
  else if (s2.type === "ImportDefaultSpecifier") return "default";
46257
46255
  }).filter(isDefined)
46258
46256
  });
@@ -46267,8 +46265,7 @@ Object.defineProperty(${ssrModuleExportsKey}, "${name}", { enumerable: true, con
46267
46265
  } else {
46268
46266
  idToImportMap.set(
46269
46267
  spec.local.name,
46270
- `${importId}[${// @ts-expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
46271
- JSON.stringify(spec.imported.value)}]`
46268
+ `${importId}[${JSON.stringify(spec.imported.value)}]`
46272
46269
  );
46273
46270
  }
46274
46271
  } else if (spec.type === "ImportDefaultSpecifier") {
@@ -46299,27 +46296,35 @@ Object.defineProperty(${ssrModuleExportsKey}, "${name}", { enumerable: true, con
46299
46296
  node.start,
46300
46297
  node.source.value,
46301
46298
  {
46302
- importedNames: node.specifiers.map((s2) => s2.local.name)
46299
+ importedNames: node.specifiers.map(
46300
+ (s2) => getIdentifierNameOrLiteralValue(s2.local)
46301
+ )
46303
46302
  }
46304
46303
  );
46305
46304
  for (const spec of node.specifiers) {
46306
- const exportedAs = spec.exported.type === "Identifier" ? spec.exported.name : (
46307
- // @ts-expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
46308
- spec.exported.value
46309
- );
46310
- defineExport(
46311
- node.start,
46312
- exportedAs,
46313
- `${importId}.${spec.local.name}`
46305
+ const exportedAs = getIdentifierNameOrLiteralValue(
46306
+ spec.exported
46314
46307
  );
46308
+ if (spec.local.type === "Identifier") {
46309
+ defineExport(
46310
+ node.start,
46311
+ exportedAs,
46312
+ `${importId}.${spec.local.name}`
46313
+ );
46314
+ } else {
46315
+ defineExport(
46316
+ node.start,
46317
+ exportedAs,
46318
+ `${importId}[${JSON.stringify(spec.local.value)}]`
46319
+ );
46320
+ }
46315
46321
  }
46316
46322
  } else {
46317
46323
  for (const spec of node.specifiers) {
46318
46324
  const local = spec.local.name;
46319
46325
  const binding = idToImportMap.get(local);
46320
- const exportedAs = spec.exported.type === "Identifier" ? spec.exported.name : (
46321
- // @ts-expect-error TODO: Estree types don't consider arbitrary module namespace specifiers yet
46322
- spec.exported.value
46326
+ const exportedAs = getIdentifierNameOrLiteralValue(
46327
+ spec.exported
46323
46328
  );
46324
46329
  defineExport(node.end, exportedAs, binding || local);
46325
46330
  }
@@ -46351,7 +46356,10 @@ Object.defineProperty(${ssrModuleExportsKey}, "default", { enumerable: true, con
46351
46356
  s.remove(node.start, node.end);
46352
46357
  const importId = defineImport(node.start, node.source.value);
46353
46358
  if (node.exported) {
46354
- defineExport(node.start, node.exported.name, `${importId}`);
46359
+ const exportedAs = getIdentifierNameOrLiteralValue(
46360
+ node.exported
46361
+ );
46362
+ defineExport(node.start, exportedAs, `${importId}`);
46355
46363
  } else {
46356
46364
  s.appendLeft(node.start, `${ssrExportAllKey}(${importId});
46357
46365
  `);
@@ -46394,18 +46402,13 @@ Object.defineProperty(${ssrModuleExportsKey}, "default", { enumerable: true, con
46394
46402
  }
46395
46403
  });
46396
46404
  let map = s.generateMap({ hires: "boundary" });
46405
+ map.sources = [path$n.basename(url)];
46406
+ map.sourcesContent = [originalCode];
46397
46407
  if (inMap && inMap.mappings && "sources" in inMap && inMap.sources.length > 0) {
46398
46408
  map = combineSourcemaps(url, [
46399
- {
46400
- ...map,
46401
- sources: inMap.sources,
46402
- sourcesContent: inMap.sourcesContent
46403
- },
46409
+ map,
46404
46410
  inMap
46405
46411
  ]);
46406
- } else {
46407
- map.sources = [path$n.basename(url)];
46408
- map.sourcesContent = [originalCode];
46409
46412
  }
46410
46413
  return {
46411
46414
  code: s.toString(),
@@ -46415,6 +46418,9 @@ Object.defineProperty(${ssrModuleExportsKey}, "default", { enumerable: true, con
46415
46418
  dynamicDeps: [...dynamicDeps]
46416
46419
  };
46417
46420
  }
46421
+ function getIdentifierNameOrLiteralValue(node) {
46422
+ return node.type === "Identifier" ? node.name : node.value;
46423
+ }
46418
46424
  const isNodeInPatternWeakSet = /* @__PURE__ */ new WeakSet();
46419
46425
  const setIsNodeInPattern = (node) => isNodeInPatternWeakSet.add(node);
46420
46426
  const isNodeInPattern = (node) => isNodeInPatternWeakSet.has(node);
@@ -52594,6 +52600,7 @@ const WebSocketServerRaw = process.versions.bun ? (
52594
52600
  import.meta.require("ws").WebSocketServer
52595
52601
  ) : WebSocketServerRaw_;
52596
52602
  const HMR_HEADER = "vite-hmr";
52603
+ const isWebSocketServer = Symbol("isWebSocketServer");
52597
52604
  const wsServerEvents = [
52598
52605
  "connection",
52599
52606
  "error",
@@ -52606,6 +52613,7 @@ function noop$3() {
52606
52613
  function createWebSocketServer(server, config, httpsOptions) {
52607
52614
  if (config.server.ws === false) {
52608
52615
  return {
52616
+ [isWebSocketServer]: true,
52609
52617
  get clients() {
52610
52618
  return /* @__PURE__ */ new Set();
52611
52619
  },
@@ -52727,6 +52735,7 @@ ${e.stack || e.message}`),
52727
52735
  }
52728
52736
  let bufferedError = null;
52729
52737
  return {
52738
+ [isWebSocketServer]: true,
52730
52739
  listen: () => {
52731
52740
  wsHttpServer?.listen(port, host);
52732
52741
  },
@@ -56026,7 +56035,6 @@ async function handleModuleSoftInvalidation(environment, mod, timestamp) {
56026
56035
  const modulePreloadPolyfillId = "vite/modulepreload-polyfill";
56027
56036
  const resolvedModulePreloadPolyfillId = "\0" + modulePreloadPolyfillId + ".js";
56028
56037
  function modulePreloadPolyfillPlugin(config) {
56029
- const skip = config.command !== "build" || config.build.ssr;
56030
56038
  let polyfillString;
56031
56039
  return {
56032
56040
  name: "vite:modulepreload-polyfill",
@@ -56037,7 +56045,7 @@ function modulePreloadPolyfillPlugin(config) {
56037
56045
  },
56038
56046
  load(id) {
56039
56047
  if (id === resolvedModulePreloadPolyfillId) {
56040
- if (skip) {
56048
+ if (config.command !== "build" || this.environment.config.consumer !== "client") {
56041
56049
  return "";
56042
56050
  }
56043
56051
  if (!polyfillString) {
@@ -56265,7 +56273,7 @@ function buildHtmlPlugin(config) {
56265
56273
  preHooks.push(htmlEnvHook(config));
56266
56274
  postHooks.push(injectNonceAttributeTagHook(config));
56267
56275
  postHooks.push(postImportMapHook());
56268
- const processedHtml = /* @__PURE__ */ new Map();
56276
+ const processedHtml = usePerEnvironmentState(() => /* @__PURE__ */ new Map());
56269
56277
  const isExcludedUrl = (url) => url[0] === "#" || isExternalUrl(url) || isDataUrl(url);
56270
56278
  isAsyncScriptMap.set(config, /* @__PURE__ */ new Map());
56271
56279
  return {
@@ -56533,7 +56541,7 @@ import ${JSON.stringify(url)}`;
56533
56541
  s.remove(start, end);
56534
56542
  }
56535
56543
  }
56536
- processedHtml.set(id, s.toString());
56544
+ processedHtml(this).set(id, s.toString());
56537
56545
  const { modulePreload } = this.environment.config.build;
56538
56546
  if (modulePreload !== false && modulePreload.polyfill && (someScriptsAreAsync || someScriptsAreDefer)) {
56539
56547
  js = `import "${modulePreloadPolyfillId}";
@@ -56606,7 +56614,7 @@ ${js}`;
56606
56614
  });
56607
56615
  return tags;
56608
56616
  };
56609
- for (const [normalizedId, html] of processedHtml) {
56617
+ for (const [normalizedId, html] of processedHtml(this)) {
56610
56618
  const relativeUrlPath = normalizePath$3(
56611
56619
  path$n.relative(config.root, normalizedId)
56612
56620
  );
@@ -57878,7 +57886,7 @@ class ModuleGraph {
57878
57886
  }
57879
57887
  if (ssrModules) {
57880
57888
  for (const mod of ssrModules) {
57881
- if (!this._client.getModuleById(mod.id)) {
57889
+ if (mod.id == null || !this._client.getModuleById(mod.id)) {
57882
57890
  result.add(this.getBackwardCompatibleBrowserModuleNode(mod));
57883
57891
  }
57884
57892
  }
@@ -59990,7 +59998,7 @@ function preAliasPlugin(config) {
59990
59998
  name: "vite:pre-alias",
59991
59999
  async resolveId(id, importer, options) {
59992
60000
  const { environment } = this;
59993
- const ssr = options?.ssr === true;
60001
+ const ssr = environment.config.consumer === "server";
59994
60002
  const depsOptimizer = environment.mode === "dev" ? environment.depsOptimizer : void 0;
59995
60003
  if (importer && depsOptimizer && bareImportRE.test(id) && !options?.scan && id !== "@vite/client" && id !== "@vite/env") {
59996
60004
  if (findPatterns.find((pattern) => matches(pattern, id))) {
@@ -61014,6 +61022,9 @@ function assetImportMetaUrlPlugin(config) {
61014
61022
  }
61015
61023
  }
61016
61024
  const url = rawUrl.slice(1, -1);
61025
+ if (isDataUrl(url)) {
61026
+ continue;
61027
+ }
61017
61028
  let file;
61018
61029
  if (url[0] === ".") {
61019
61030
  file = slash$1(path$n.resolve(path$n.dirname(id), url));
@@ -61239,7 +61250,7 @@ function dynamicImportToGlob(node, sourceString) {
61239
61250
  }
61240
61251
 
61241
61252
  // Disallow ./*.ext
61242
- const ownDirectoryStarExtension = /^\.\/\*\.[\w]+$/;
61253
+ const ownDirectoryStarExtension = /^\.\/\*\.\w+$/;
61243
61254
  if (ownDirectoryStarExtension.test(glob)) {
61244
61255
  throw new VariableDynamicImportError(
61245
61256
  `${
@@ -61596,7 +61607,8 @@ class EnvironmentPluginContainer {
61596
61607
  info: noop,
61597
61608
  warn: noop,
61598
61609
  // @ts-expect-error noop
61599
- error: noop
61610
+ error: noop,
61611
+ environment
61600
61612
  };
61601
61613
  const utils = createPluginHookUtils(plugins);
61602
61614
  this.getSortedPlugins = utils.getSortedPlugins;
@@ -62468,7 +62480,7 @@ function cssPostPlugin(config) {
62468
62480
  chunkCSSMap = /* @__PURE__ */ new Map();
62469
62481
  codeSplitEmitQueue = createSerialPromiseQueue();
62470
62482
  },
62471
- async transform(css, id, options) {
62483
+ async transform(css, id) {
62472
62484
  if (!isCSSRequest(id) || commonjsProxyRE.test(id) || SPECIAL_QUERY_RE.test(id)) {
62473
62485
  return;
62474
62486
  }
@@ -62506,7 +62518,7 @@ function cssPostPlugin(config) {
62506
62518
  if (isDirectCSSRequest(id)) {
62507
62519
  return null;
62508
62520
  }
62509
- if (options?.ssr) {
62521
+ if (this.environment.config.consumer !== "client") {
62510
62522
  return modulesCode || `export default ${JSON.stringify(css)}`;
62511
62523
  }
62512
62524
  if (inlined) {
@@ -62713,7 +62725,7 @@ function cssPostPlugin(config) {
62713
62725
  });
62714
62726
  generatedAssets.set(referenceId, { originalFileName, isEntry });
62715
62727
  chunk.viteMetadata.importedCss.add(this.getFileName(referenceId));
62716
- } else if (!config.build.ssr) {
62728
+ } else if (this.environment.config.consumer === "client") {
62717
62729
  chunkCSS = await finalizeCss(chunkCSS, true, config);
62718
62730
  let cssString = JSON.stringify(chunkCSS);
62719
62731
  cssString = renderAssetUrlInJS(this, chunk, opts, cssString)?.toString() || cssString;
@@ -63232,8 +63244,8 @@ function createCachedImport(imp) {
63232
63244
  return cached;
63233
63245
  };
63234
63246
  }
63235
- const importPostcssImport = createCachedImport(() => import('./dep-DiM5uMHt.js').then(function (n) { return n.i; }));
63236
- const importPostcssModules = createCachedImport(() => import('./dep-BZeeNeMJ.js').then(function (n) { return n.i; }));
63247
+ const importPostcssImport = createCachedImport(() => import('./dep-BabmomGK.js').then(function (n) { return n.i; }));
63248
+ const importPostcssModules = createCachedImport(() => import('./dep-DTHr9Se7.js').then(function (n) { return n.i; }));
63237
63249
  const importPostcss = createCachedImport(() => import('postcss'));
63238
63250
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
63239
63251
  let alwaysFakeWorkerWorkerControllerCache;
@@ -63711,7 +63723,7 @@ const makeModernScssWorker = (environment, resolvers, alias, maxWorkers) => {
63711
63723
  fileURLToPath2(canonicalUrl),
63712
63724
  options.filename
63713
63725
  );
63714
- return { contents, syntax };
63726
+ return { contents, syntax, sourceMapUrl: canonicalUrl };
63715
63727
  }
63716
63728
  };
63717
63729
  sassOptions.importers = [
@@ -63741,11 +63753,12 @@ const makeModernScssWorker = (environment, resolvers, alias, maxWorkers) => {
63741
63753
  return worker;
63742
63754
  };
63743
63755
  const makeModernCompilerScssWorker = (environment, resolvers, alias, _maxWorkers) => {
63744
- let compiler;
63756
+ let compilerPromise;
63745
63757
  const worker = {
63746
63758
  async run(sassPath, data, options) {
63747
63759
  const sass = (await import(pathToFileURL(sassPath).href)).default;
63748
- compiler ??= await sass.initAsyncCompiler();
63760
+ compilerPromise ??= sass.initAsyncCompiler();
63761
+ const compiler = await compilerPromise;
63749
63762
  const sassOptions = { ...options };
63750
63763
  sassOptions.url = pathToFileURL(options.filename);
63751
63764
  sassOptions.sourceMap = options.enableSourcemap;
@@ -63776,7 +63789,7 @@ const makeModernCompilerScssWorker = (environment, resolvers, alias, _maxWorkers
63776
63789
  resolvers.sass
63777
63790
  );
63778
63791
  const contents = result2.contents ?? await fsp.readFile(result2.file, "utf-8");
63779
- return { contents, syntax };
63792
+ return { contents, syntax, sourceMapUrl: canonicalUrl };
63780
63793
  }
63781
63794
  };
63782
63795
  sassOptions.importers = [
@@ -63793,8 +63806,8 @@ const makeModernCompilerScssWorker = (environment, resolvers, alias, _maxWorkers
63793
63806
  };
63794
63807
  },
63795
63808
  async stop() {
63796
- compiler?.dispose();
63797
- compiler = void 0;
63809
+ (await compilerPromise)?.dispose();
63810
+ compilerPromise = void 0;
63798
63811
  }
63799
63812
  };
63800
63813
  return worker;
@@ -64280,7 +64293,10 @@ async function compileLightningCSS(id, src, environment, urlReplacer) {
64280
64293
  }
64281
64294
  deps.add(dep.url);
64282
64295
  if (urlReplacer) {
64283
- const replaceUrl = await urlReplacer(dep.url, dep.loc.filePath);
64296
+ const replaceUrl = await urlReplacer(
64297
+ dep.url,
64298
+ toAbsolute(dep.loc.filePath)
64299
+ );
64284
64300
  css = css.replace(dep.placeholder, () => replaceUrl);
64285
64301
  } else {
64286
64302
  css = css.replace(dep.placeholder, () => dep.url);
@@ -64468,9 +64484,7 @@ function preload(baseModule, deps, importerUrl) {
64468
64484
  });
64469
64485
  }
64470
64486
  function buildImportAnalysisPlugin(config) {
64471
- const ssr = !!config.build.ssr;
64472
- const isWorker = config.isWorker;
64473
- const insertPreload = !(ssr || !!config.build.lib || isWorker);
64487
+ const getInsertPreload = (environment) => environment.config.consumer === "client" && !config.isWorker && !config.build.lib;
64474
64488
  const renderBuiltUrl = config.experimental.renderBuiltUrl;
64475
64489
  const isRelativeBase = config.base === "./" || config.base === "";
64476
64490
  return {
@@ -64517,6 +64531,7 @@ function buildImportAnalysisPlugin(config) {
64517
64531
  if (!imports.length) {
64518
64532
  return null;
64519
64533
  }
64534
+ const insertPreload = getInsertPreload(this.environment);
64520
64535
  const dynamicImports = {};
64521
64536
  if (insertPreload) {
64522
64537
  let match;
@@ -64609,7 +64624,7 @@ function buildImportAnalysisPlugin(config) {
64609
64624
  if (format !== "es") {
64610
64625
  return;
64611
64626
  }
64612
- if (!insertPreload) {
64627
+ if (!getInsertPreload(this.environment)) {
64613
64628
  const removedPureCssFiles = removedPureCssFilesCache.get(config);
64614
64629
  if (removedPureCssFiles && removedPureCssFiles.size > 0) {
64615
64630
  for (const file in bundle) {
@@ -65958,14 +65973,15 @@ async function fetchModule(environment, url, importer, options = {}) {
65958
65973
  );
65959
65974
  }
65960
65975
  if (options.inlineSourceMap !== false) {
65961
- result = inlineSourceMap(mod, result, options.processSourceMap);
65976
+ result = inlineSourceMap(mod, result, options.startOffset);
65962
65977
  }
65963
65978
  if (result.code[0] === "#")
65964
65979
  result.code = result.code.replace(/^#!.*/, (s) => " ".repeat(s.length));
65965
65980
  return {
65966
65981
  code: result.code,
65967
65982
  file: mod.file,
65968
- serverId: mod.id,
65983
+ id: mod.id,
65984
+ url: mod.url,
65969
65985
  invalidate: !cached
65970
65986
  };
65971
65987
  }
@@ -65973,7 +65989,7 @@ const OTHER_SOURCE_MAP_REGEXP = new RegExp(
65973
65989
  `//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`,
65974
65990
  "gm"
65975
65991
  );
65976
- function inlineSourceMap(mod, result, processSourceMap) {
65992
+ function inlineSourceMap(mod, result, startOffset) {
65977
65993
  const map = result.map;
65978
65994
  let code = result.code;
65979
65995
  if (!map || !("version" in map) || code.includes(MODULE_RUNNER_SOURCEMAPPING_SOURCE))
@@ -65981,7 +65997,9 @@ function inlineSourceMap(mod, result, processSourceMap) {
65981
65997
  OTHER_SOURCE_MAP_REGEXP.lastIndex = 0;
65982
65998
  if (OTHER_SOURCE_MAP_REGEXP.test(code))
65983
65999
  code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
65984
- const sourceMap = processSourceMap?.(map) || map;
66000
+ const sourceMap = startOffset ? Object.assign({}, map, {
66001
+ mappings: ";".repeat(startOffset) + map.mappings
66002
+ }) : map;
65985
66003
  result.code = `${code.trimEnd()}
65986
66004
  //# sourceURL=${mod.id}
65987
66005
  ${MODULE_RUNNER_SOURCEMAPPING_SOURCE}
@@ -66077,7 +66095,7 @@ function createDepsOptimizer(environment) {
66077
66095
  firstRunCalled = !!cachedMetadata;
66078
66096
  metadata = depsOptimizer.metadata = cachedMetadata || initDepsOptimizerMetadata(environment, sessionTimestamp);
66079
66097
  if (!cachedMetadata) {
66080
- environment._onCrawlEnd(onCrawlEnd);
66098
+ environment.waitForRequestsIdle().then(onCrawlEnd);
66081
66099
  waitingForCrawlEnd = true;
66082
66100
  currentlyProcessing = true;
66083
66101
  const manuallyIncludedDeps = {};
@@ -66854,7 +66872,7 @@ class DevEnvironment extends BaseEnvironment {
66854
66872
  /**
66855
66873
  * @internal
66856
66874
  */
66857
- _ssrRunnerOptions;
66875
+ _remoteRunnerOptions;
66858
66876
  get pluginContainer() {
66859
66877
  if (!this._pluginContainer)
66860
66878
  throw new Error(
@@ -66874,10 +66892,6 @@ class DevEnvironment extends BaseEnvironment {
66874
66892
  * @internal
66875
66893
  */
66876
66894
  _pendingRequests;
66877
- /**
66878
- * @internal
66879
- */
66880
- _onCrawlEndCallbacks;
66881
66895
  /**
66882
66896
  * @internal
66883
66897
  */
@@ -66905,12 +66919,9 @@ class DevEnvironment extends BaseEnvironment {
66905
66919
  (url) => this.pluginContainer.resolveId(url, void 0)
66906
66920
  );
66907
66921
  this.hot = context.hot || createNoopHotChannel();
66908
- this._onCrawlEndCallbacks = [];
66909
- this._crawlEndFinder = setupOnCrawlEnd(() => {
66910
- this._onCrawlEndCallbacks.forEach((cb) => cb());
66911
- });
66912
- this._ssrRunnerOptions = context.runner ?? {};
66913
- context.runner?.transport?.register(this);
66922
+ this._crawlEndFinder = setupOnCrawlEnd();
66923
+ this._remoteRunnerOptions = context.remoteRunner ?? {};
66924
+ context.remoteRunner?.transport?.register(this);
66914
66925
  this.hot.on("vite:invalidate", async ({ path, message }) => {
66915
66926
  invalidateModule(this, {
66916
66927
  path,
@@ -66940,7 +66951,7 @@ class DevEnvironment extends BaseEnvironment {
66940
66951
  }
66941
66952
  fetchModule(id, importer, options) {
66942
66953
  return fetchModule(this, id, importer, {
66943
- ...this._ssrRunnerOptions,
66954
+ ...this._remoteRunnerOptions,
66944
66955
  ...options
66945
66956
  });
66946
66957
  }
@@ -66971,6 +66982,8 @@ class DevEnvironment extends BaseEnvironment {
66971
66982
  await Promise.allSettled([
66972
66983
  this.pluginContainer.close(),
66973
66984
  this.depsOptimizer?.close(),
66985
+ // WebSocketServer is independent of HotChannel and should not be closed on environment close
66986
+ isWebSocketServer in this.hot ? Promise.resolve() : this.hot.close(),
66974
66987
  (async () => {
66975
66988
  while (this._pendingRequests.size > 0) {
66976
66989
  await Promise.allSettled(
@@ -66999,13 +67012,6 @@ class DevEnvironment extends BaseEnvironment {
66999
67012
  _registerRequestProcessing(id, done) {
67000
67013
  this._crawlEndFinder.registerRequestProcessing(id, done);
67001
67014
  }
67002
- /**
67003
- * @internal
67004
- * TODO: use waitForRequestsIdle in the optimizer instead of this function
67005
- */
67006
- _onCrawlEnd(cb) {
67007
- this._onCrawlEndCallbacks.push(cb);
67008
- }
67009
67015
  }
67010
67016
  function invalidateModule(environment, m) {
67011
67017
  const mod = environment.moduleGraph.urlToModuleMap.get(m.path);
@@ -67026,7 +67032,7 @@ function invalidateModule(environment, m) {
67026
67032
  }
67027
67033
  }
67028
67034
  const callCrawlEndIfIdleAfterMs = 50;
67029
- function setupOnCrawlEnd(onCrawlEnd) {
67035
+ function setupOnCrawlEnd() {
67030
67036
  const registeredIds = /* @__PURE__ */ new Set();
67031
67037
  const seenIds = /* @__PURE__ */ new Set();
67032
67038
  const onCrawlEndPromiseWithResolvers = promiseWithResolvers();
@@ -67035,14 +67041,6 @@ function setupOnCrawlEnd(onCrawlEnd) {
67035
67041
  function cancel() {
67036
67042
  cancelled = true;
67037
67043
  }
67038
- let crawlEndCalled = false;
67039
- function callOnCrawlEnd() {
67040
- if (!cancelled && !crawlEndCalled) {
67041
- crawlEndCalled = true;
67042
- onCrawlEnd();
67043
- }
67044
- onCrawlEndPromiseWithResolvers.resolve();
67045
- }
67046
67044
  function registerRequestProcessing(id, done) {
67047
67045
  if (!seenIds.has(id)) {
67048
67046
  seenIds.add(id);
@@ -67074,7 +67072,7 @@ function setupOnCrawlEnd(onCrawlEnd) {
67074
67072
  }
67075
67073
  async function callOnCrawlEndWhenIdle() {
67076
67074
  if (cancelled || registeredIds.size > 0) return;
67077
- callOnCrawlEnd();
67075
+ onCrawlEndPromiseWithResolvers.resolve();
67078
67076
  }
67079
67077
  return {
67080
67078
  registerRequestProcessing,
@@ -67083,23 +67081,141 @@ function setupOnCrawlEnd(onCrawlEnd) {
67083
67081
  };
67084
67082
  }
67085
67083
 
67086
- function createNodeDevEnvironment(name, config, context) {
67087
- if (context.hot == null) {
67088
- throw new Error(
67089
- "`hot` is a required option. Either explicitly opt out of HMR by setting `hot: false` or provide a hot channel."
67084
+ class ServerHMRBroadcasterClient {
67085
+ constructor(hotChannel) {
67086
+ this.hotChannel = hotChannel;
67087
+ }
67088
+ send(...args) {
67089
+ let payload;
67090
+ if (typeof args[0] === "string") {
67091
+ payload = {
67092
+ type: "custom",
67093
+ event: args[0],
67094
+ data: args[1]
67095
+ };
67096
+ } else {
67097
+ payload = args[0];
67098
+ }
67099
+ if (payload.type !== "custom") {
67100
+ throw new Error(
67101
+ "Cannot send non-custom events from the client to the server."
67102
+ );
67103
+ }
67104
+ this.hotChannel.send(payload);
67105
+ }
67106
+ }
67107
+ class ServerHMRConnector {
67108
+ constructor(hotChannel) {
67109
+ this.hotChannel = hotChannel;
67110
+ this.hmrClient = new ServerHMRBroadcasterClient(hotChannel);
67111
+ hotChannel.api.outsideEmitter.on("send", (payload) => {
67112
+ this.handlers.forEach((listener) => listener(payload));
67113
+ });
67114
+ this.hotChannel = hotChannel;
67115
+ }
67116
+ handlers = [];
67117
+ hmrClient;
67118
+ connected = false;
67119
+ isReady() {
67120
+ return this.connected;
67121
+ }
67122
+ send(payload_) {
67123
+ const payload = payload_;
67124
+ this.hotChannel.api.innerEmitter.emit(
67125
+ payload.event,
67126
+ payload.data,
67127
+ this.hmrClient
67090
67128
  );
67091
67129
  }
67092
- return new DevEnvironment(name, config, {
67093
- ...context,
67094
- runner: {
67095
- processSourceMap(map) {
67096
- return Object.assign({}, map, {
67097
- mappings: ";".repeat(asyncFunctionDeclarationPaddingLineCount) + map.mappings
67098
- });
67130
+ onUpdate(handler) {
67131
+ this.handlers.push(handler);
67132
+ handler({ type: "connected" });
67133
+ this.connected = true;
67134
+ }
67135
+ }
67136
+
67137
+ function createHMROptions(environment, options) {
67138
+ if (environment.config.server.hmr === false || options.hmr === false) {
67139
+ return false;
67140
+ }
67141
+ if (options.hmr?.connection) {
67142
+ return {
67143
+ connection: options.hmr.connection,
67144
+ logger: options.hmr.logger
67145
+ };
67146
+ }
67147
+ if (!("api" in environment.hot)) return false;
67148
+ const connection = new ServerHMRConnector(environment.hot);
67149
+ return {
67150
+ connection,
67151
+ logger: options.hmr?.logger
67152
+ };
67153
+ }
67154
+ const prepareStackTrace = {
67155
+ retrieveFile(id) {
67156
+ if (existsSync$1(id)) {
67157
+ return readFileSync$1(id, "utf-8");
67158
+ }
67159
+ }
67160
+ };
67161
+ function resolveSourceMapOptions(options) {
67162
+ if (options.sourcemapInterceptor != null) {
67163
+ if (options.sourcemapInterceptor === "prepareStackTrace") {
67164
+ return prepareStackTrace;
67165
+ }
67166
+ if (typeof options.sourcemapInterceptor === "object") {
67167
+ return { ...prepareStackTrace, ...options.sourcemapInterceptor };
67168
+ }
67169
+ return options.sourcemapInterceptor;
67170
+ }
67171
+ if (typeof process !== "undefined" && "setSourceMapsEnabled" in process) {
67172
+ return "node";
67173
+ }
67174
+ return prepareStackTrace;
67175
+ }
67176
+ function createServerModuleRunner(environment, options = {}) {
67177
+ const hmr = createHMROptions(environment, options);
67178
+ return new ModuleRunner(
67179
+ {
67180
+ ...options,
67181
+ root: environment.config.root,
67182
+ transport: {
67183
+ fetchModule: (id, importer, options2) => environment.fetchModule(id, importer, options2)
67099
67184
  },
67100
- ...context.runner
67185
+ hmr,
67186
+ sourcemapInterceptor: resolveSourceMapOptions(options)
67187
+ },
67188
+ options.evaluator || new ESModulesEvaluator()
67189
+ );
67190
+ }
67191
+
67192
+ function createRunnableDevEnvironment(name, config, context = {}) {
67193
+ if (context.hot == null) {
67194
+ context.hot = createServerHotChannel();
67195
+ }
67196
+ return new RunnableDevEnvironment(name, config, context);
67197
+ }
67198
+ function isRunnableDevEnvironment(environment) {
67199
+ return environment instanceof RunnableDevEnvironment;
67200
+ }
67201
+ class RunnableDevEnvironment extends DevEnvironment {
67202
+ _runner;
67203
+ _runnerFactory;
67204
+ constructor(name, config, context) {
67205
+ super(name, config, context);
67206
+ this._runnerFactory = context.runner;
67207
+ }
67208
+ get runner() {
67209
+ if (this._runner) {
67210
+ return this._runner;
67101
67211
  }
67102
- });
67212
+ if (this._runnerFactory) {
67213
+ this._runner = this._runnerFactory(this);
67214
+ return this._runner;
67215
+ }
67216
+ this._runner = createServerModuleRunner(this);
67217
+ return this._runner;
67218
+ }
67103
67219
  }
67104
67220
 
67105
67221
  // NOTE: supports Node 6.x
@@ -67386,9 +67502,7 @@ function defaultCreateClientDevEnvironment(name, config, context) {
67386
67502
  });
67387
67503
  }
67388
67504
  function defaultCreateSsrDevEnvironment(name, config) {
67389
- return createNodeDevEnvironment(name, config, {
67390
- hot: createServerHotChannel()
67391
- });
67505
+ return createRunnableDevEnvironment(name, config);
67392
67506
  }
67393
67507
  function defaultCreateDevEnvironment(name, config) {
67394
67508
  return new DevEnvironment(name, config, {
@@ -67447,16 +67561,6 @@ function getDefaultEnvironmentOptions(config) {
67447
67561
  build: config.build
67448
67562
  };
67449
67563
  }
67450
- function getDefaultResolvedEnvironmentOptions(config) {
67451
- return {
67452
- define: config.define,
67453
- resolve: config.resolve,
67454
- consumer: "server",
67455
- webCompatible: false,
67456
- dev: config.dev,
67457
- build: config.build
67458
- };
67459
- }
67460
67564
  function checkBadCharactersInPath(path2, logger) {
67461
67565
  const badChars = [];
67462
67566
  if (path2.includes("#")) {
@@ -68004,7 +68108,7 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
68004
68108
  debug?.("no config file found.");
68005
68109
  return null;
68006
68110
  }
68007
- const isESM = isFilePathESM(resolvedPath);
68111
+ const isESM = typeof process.versions.deno === "string" || isFilePathESM(resolvedPath);
68008
68112
  try {
68009
68113
  const bundled = await bundleConfigFile(resolvedPath, isESM);
68010
68114
  const userConfig = await loadConfigFromBundledFile(
@@ -68246,4 +68350,4 @@ function optimizeDepsDisabledBackwardCompatibility(resolved, optimizeDeps, optim
68246
68350
  }
68247
68351
  }
68248
68352
 
68249
- export { createLogger as A, BuildEnvironment as B, searchForWorkspaceRoot as C, DevEnvironment as D, isFileServingAllowed as E, isFileLoadingAllowed as F, loadEnv as G, resolveEnvPrefix as H, colors$1 as I, getDefaultExportFromCjs as J, commonjsGlobal as K, index$1 as L, index as M, build$1 as N, preview$1 as O, arraify as a, build as b, createServer as c, defineConfig as d, createBuilder as e, createIdResolver as f, formatPostcssSourceMap as g, preprocessCSS as h, isInNodeModules$1 as i, buildErrorMessage as j, createNodeDevEnvironment as k, loadConfigFromFile as l, fetchModule as m, createServerHotChannel as n, optimizeDeps as o, preview as p, ssrTransform as q, resolveConfig as r, sortUserPlugins as s, transformWithEsbuild as t, normalizePath$3 as u, mergeConfig as v, mergeAlias as w, createFilter as x, rollupVersion as y, send$1 as z };
68353
+ export { rollupVersion as A, BuildEnvironment as B, send$1 as C, DevEnvironment as D, createLogger as E, searchForWorkspaceRoot as F, isFileServingAllowed as G, isFileLoadingAllowed as H, loadEnv as I, resolveEnvPrefix as J, colors$1 as K, getDefaultExportFromCjs as L, commonjsGlobal as M, index$1 as N, index as O, build$1 as P, preview$1 as Q, ServerHMRConnector as S, arraify as a, build as b, createServer as c, defineConfig as d, createBuilder as e, createIdResolver as f, formatPostcssSourceMap as g, preprocessCSS as h, isInNodeModules$1 as i, buildErrorMessage as j, createRunnableDevEnvironment as k, loadConfigFromFile as l, isRunnableDevEnvironment as m, fetchModule as n, optimizeDeps as o, preview as p, createServerModuleRunner as q, resolveConfig as r, sortUserPlugins as s, transformWithEsbuild as t, createServerHotChannel as u, ssrTransform as v, normalizePath$3 as w, mergeConfig as x, mergeAlias as y, createFilter as z };