vite 2.6.10 → 2.7.0-beta.0

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -1,29 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var fs$r = require('fs');
4
3
  var path$t = require('path');
5
- var require$$0$b = require('events');
4
+ var fs$r = require('fs');
5
+ var qs = require('querystring');
6
+ var require$$0$4 = require('tty');
6
7
  var require$$0$6 = require('util');
7
- var require$$0$a = require('stream');
8
+ var require$$3 = require('net');
9
+ var require$$0$b = require('events');
10
+ var require$$0$8 = require('url');
11
+ var require$$1$2 = require('http');
12
+ var require$$0$c = require('buffer');
13
+ var require$$0$9 = require('zlib');
8
14
  var require$$0$5 = require('os');
15
+ var resolve$4 = require('resolve');
16
+ var require$$0$7 = require('module');
9
17
  var perf_hooks = require('perf_hooks');
10
- var require$$0$8 = require('url');
18
+ var readline = require('readline');
11
19
  var require$$1 = require('crypto');
12
- var require$$0$7 = require('module');
20
+ var require$$0$a = require('stream');
13
21
  var esbuild = require('esbuild');
14
22
  var require$$1$1 = require('worker_threads');
15
23
  var require$$5 = require('assert');
16
- var require$$1$4 = require('child_process');
17
- var readline = require('readline');
18
- var require$$0$9 = require('zlib');
19
- var resolve$4 = require('resolve');
20
- var qs = require('querystring');
21
- var require$$0$4 = require('tty');
22
- var require$$3 = require('net');
23
- var require$$1$2 = require('http');
24
- var require$$0$c = require('buffer');
25
24
  var require$$1$3 = require('https');
26
25
  var require$$4 = require('tls');
26
+ var require$$1$4 = require('child_process');
27
27
 
28
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
29
29
 
@@ -39,29 +39,29 @@ function _interopNamespace(e) {
39
39
  return n;
40
40
  }
41
41
 
42
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path$t);
42
43
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$r);
43
44
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs$r);
44
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path$t);
45
- var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
46
- var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
47
- var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
48
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
49
- var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
50
- var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1);
51
- var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
52
- var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
53
- var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
54
- var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
55
- var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
56
- var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
57
- var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve$4);
58
45
  var qs__namespace = /*#__PURE__*/_interopNamespace(qs);
59
46
  var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0$4);
47
+ var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
60
48
  var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
49
+ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$b);
50
+ var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
61
51
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
62
52
  var require$$0__default$8 = /*#__PURE__*/_interopDefaultLegacy(require$$0$c);
53
+ var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
54
+ var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$5);
55
+ var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve$4);
56
+ var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
57
+ var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
58
+ var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1);
59
+ var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
60
+ var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
61
+ var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
63
62
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
64
63
  var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
64
+ var require$$1__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$1$4);
65
65
 
66
66
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
67
67
 
@@ -3883,8 +3883,13 @@ function unwrapId$1(id) {
3883
3883
  const flattenId = (id) => id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.]/g, '_');
3884
3884
  const normalizeId$1 = (id) => id.replace(/(\s*>\s*)/g, ' > ');
3885
3885
  function isBuiltin(id) {
3886
+ const deepMatch = id.match(deepImportRE);
3887
+ id = deepMatch ? deepMatch[1] || deepMatch[2] : id;
3886
3888
  return builtinModules_1.includes(id);
3887
3889
  }
3890
+ function moduleListContains(moduleList, id) {
3891
+ return moduleList === null || moduleList === void 0 ? void 0 : moduleList.some((m) => m === id || id.startsWith(m + '/'));
3892
+ }
3888
3893
  const bareImportRE = /^[\w@](?!.*:\/\/)/;
3889
3894
  const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
3890
3895
  let isRunningWithYarnPnp;
@@ -4141,6 +4146,21 @@ function writeFile(filename, content) {
4141
4146
  }
4142
4147
  fs__default.writeFileSync(filename, content);
4143
4148
  }
4149
+ /**
4150
+ * Use instead of fs.existsSync(filename)
4151
+ * #2051 if we don't have read permission on a directory, existsSync() still
4152
+ * works and will result in massively slow subsequent checks (which are
4153
+ * unnecessary in the first place)
4154
+ */
4155
+ function isFileReadable(filename) {
4156
+ try {
4157
+ fs__default.accessSync(filename, fs__default.constants.R_OK);
4158
+ return true;
4159
+ }
4160
+ catch {
4161
+ return false;
4162
+ }
4163
+ }
4144
4164
  /**
4145
4165
  * Delete every file and subdirectory. **The given directory must exist.**
4146
4166
  * Pass an optional `skip` array to preserve files in the root directory.
@@ -4286,12 +4306,17 @@ function toUpperCaseDriveLetter(pathName) {
4286
4306
  }
4287
4307
  const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
4288
4308
  const singlelineCommentsRE = /\/\/.*/g;
4309
+ const usingDynamicImport = typeof jest === 'undefined';
4289
4310
  /**
4290
4311
  * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
4291
4312
  *
4313
+ * As a temporary workaround for Jest's lack of stable ESM support, we fallback to require
4314
+ * if we're in a Jest environment.
4315
+ * See https://github.com/vitejs/vite/pull/5197#issuecomment-938054077
4316
+ *
4292
4317
  * @param file File path to import.
4293
4318
  */
4294
- const dynamicImport = new Function('file', 'return import(file)');
4319
+ const dynamicImport = usingDynamicImport ? new Function('file', 'return import(file)') : require;
4295
4320
 
4296
4321
  /* eslint no-console: 0 */
4297
4322
  const LogLevels = {
@@ -19873,7 +19898,7 @@ function cssPlugin(config) {
19873
19898
  const thisModule = moduleGraph.getModuleById(id);
19874
19899
  if (thisModule) {
19875
19900
  // CSS modules cannot self-accept since it exports values
19876
- const isSelfAccepting = !modules;
19901
+ const isSelfAccepting = !modules && !inlineRE.test(id);
19877
19902
  if (deps) {
19878
19903
  // record deps in the module graph so edits to @import css can trigger
19879
19904
  // main import to hot update
@@ -19923,7 +19948,7 @@ function cssPostPlugin(config) {
19923
19948
  outputToExtractedCSSMap = new Map();
19924
19949
  hasEmitted = false;
19925
19950
  },
19926
- async transform(css, id, ssr) {
19951
+ async transform(css, id, options) {
19927
19952
  if (!isCSSRequest(id) || commonjsProxyRE.test(id)) {
19928
19953
  return;
19929
19954
  }
@@ -19936,7 +19961,7 @@ function cssPostPlugin(config) {
19936
19961
  }
19937
19962
  else {
19938
19963
  // server only
19939
- if (ssr) {
19964
+ if (options === null || options === void 0 ? void 0 : options.ssr) {
19940
19965
  return modulesCode || `export default ${JSON.stringify(css)}`;
19941
19966
  }
19942
19967
  if (inlined) {
@@ -19958,13 +19983,10 @@ function cssPostPlugin(config) {
19958
19983
  if (!inlined) {
19959
19984
  styles.set(id, css);
19960
19985
  }
19961
- else {
19962
- css = await minifyCSS(css, config);
19963
- }
19964
19986
  return {
19965
19987
  code: modulesCode ||
19966
19988
  (usedRE.test(id)
19967
- ? `export default ${JSON.stringify(css)}`
19989
+ ? `export default ${JSON.stringify(inlined ? await minifyCSS(css, config) : css)}`
19968
19990
  : `export default ''`),
19969
19991
  map: { mappings: '' },
19970
19992
  // avoid the css module from being tree-shaken so that we can retrieve
@@ -20243,7 +20265,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20243
20265
  replacer: urlReplacer
20244
20266
  }));
20245
20267
  if (isModule) {
20246
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-8e7741a0.js'); }).then(function (n) { return n.index; })).default({
20268
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-e5df0dd2.js'); }).then(function (n) { return n.index; })).default({
20247
20269
  ...modulesOptions,
20248
20270
  getJSON(cssFileName, _modules, outputFileName) {
20249
20271
  modules = _modules;
@@ -21208,7 +21230,7 @@ const assetAttrsConfig = {
21208
21230
  const isAsyncScriptMap = new WeakMap();
21209
21231
  async function traverseHtml(html, filePath, visitor) {
21210
21232
  // lazy load compiler
21211
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-9b6b378f.js'); }).then(function (n) { return n.compilerDom_cjs; });
21233
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-e51889c1.js'); }).then(function (n) { return n.compilerDom_cjs; });
21212
21234
  // @vue/compiler-core doesn't like lowercase doctypes
21213
21235
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21214
21236
  try {
@@ -21590,18 +21612,19 @@ function isEntirelyImport(code) {
21590
21612
  function toPublicPath(filename, config) {
21591
21613
  return isExternalUrl(filename) ? filename : config.base + filename;
21592
21614
  }
21593
- const headInjectRE = /([ \t]*)<\/head>/;
21594
- const headPrependInjectRE = /([ \t]*)<head[^>]*>/;
21615
+ const headInjectRE = /([ \t]*)<\/head>/i;
21616
+ const headPrependInjectRE = /([ \t]*)<head[^>]*>/i;
21617
+ const htmlInjectRE = /<\/html>/i;
21618
+ const htmlPrependInjectRE = /([ \t]*)<html[^>]*>/i;
21619
+ const bodyInjectRE = /([ \t]*)<\/body>/i;
21620
+ const bodyPrependInjectRE = /([ \t]*)<body[^>]*>/i;
21595
21621
  const doctypePrependInjectRE = /<!doctype html>/i;
21596
21622
  function injectToHead(html, tags, prepend = false) {
21597
21623
  if (prepend) {
21598
- // inject after head or doctype
21624
+ // inject as the first element of head
21599
21625
  if (headPrependInjectRE.test(html)) {
21600
21626
  return html.replace(headPrependInjectRE, (match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`);
21601
21627
  }
21602
- else if (doctypePrependInjectRE.test(html)) {
21603
- return html.replace(doctypePrependInjectRE, `$&\n${serializeTags(tags)}`);
21604
- }
21605
21628
  }
21606
21629
  else {
21607
21630
  // inject before head close
@@ -21609,30 +21632,48 @@ function injectToHead(html, tags, prepend = false) {
21609
21632
  // respect indentation of head tag
21610
21633
  return html.replace(headInjectRE, (match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`);
21611
21634
  }
21635
+ // try to inject before the body tag
21636
+ if (bodyPrependInjectRE.test(html)) {
21637
+ return html.replace(bodyPrependInjectRE, (match, p1) => `${serializeTags(tags, p1)}\n${match}`);
21638
+ }
21612
21639
  }
21613
- // if no <head> tag is present, just prepend
21614
- return serializeTags(tags) + html;
21640
+ // if no head tag is present, we prepend the tag for both prepend and append
21641
+ return prependInjectFallback(html, tags);
21615
21642
  }
21616
- const bodyInjectRE = /([ \t]*)<\/body>/;
21617
- const bodyPrependInjectRE = /([ \t]*)<body[^>]*>/;
21618
21643
  function injectToBody(html, tags, prepend = false) {
21619
21644
  if (prepend) {
21620
21645
  // inject after body open
21621
21646
  if (bodyPrependInjectRE.test(html)) {
21622
21647
  return html.replace(bodyPrependInjectRE, (match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`);
21623
21648
  }
21624
- // if no body, prepend
21625
- return serializeTags(tags) + html;
21649
+ // if no there is no body tag, inject after head or fallback to prepend in html
21650
+ if (headInjectRE.test(html)) {
21651
+ return html.replace(headInjectRE, (match, p1) => `${match}\n${serializeTags(tags, p1)}`);
21652
+ }
21653
+ return prependInjectFallback(html, tags);
21626
21654
  }
21627
21655
  else {
21628
21656
  // inject before body close
21629
21657
  if (bodyInjectRE.test(html)) {
21630
21658
  return html.replace(bodyInjectRE, (match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`);
21631
21659
  }
21632
- // if no body, append
21660
+ // if no body tag is present, append to the html tag, or at the end of the file
21661
+ if (htmlInjectRE.test(html)) {
21662
+ return html.replace(htmlInjectRE, `${serializeTags(tags)}\n$&`);
21663
+ }
21633
21664
  return html + `\n` + serializeTags(tags);
21634
21665
  }
21635
21666
  }
21667
+ function prependInjectFallback(html, tags) {
21668
+ // prepend to the html tag, append after doctype, or the document start
21669
+ if (htmlPrependInjectRE.test(html)) {
21670
+ return html.replace(htmlPrependInjectRE, `$&\n${serializeTags(tags)}`);
21671
+ }
21672
+ if (doctypePrependInjectRE.test(html)) {
21673
+ return html.replace(doctypePrependInjectRE, `$&\n${serializeTags(tags)}`);
21674
+ }
21675
+ return serializeTags(tags) + html;
21676
+ }
21636
21677
  const unaryTags = new Set(['link', 'meta', 'base']);
21637
21678
  function serializeTag({ tag, attrs, children }, indent = '') {
21638
21679
  if (unaryTags.has(tag)) {
@@ -29795,7 +29836,8 @@ function resolvePlugin(baseOptions) {
29795
29836
  configureServer(_server) {
29796
29837
  server = _server;
29797
29838
  },
29798
- resolveId(id, importer, resolveOpts, ssr) {
29839
+ resolveId(id, importer, resolveOpts) {
29840
+ const ssr = (resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.ssr) === true;
29799
29841
  if (id.startsWith(browserExternalId)) {
29800
29842
  return id;
29801
29843
  }
@@ -29951,29 +29993,36 @@ function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, target
29951
29993
  postfix = fsPath.slice(postfixIndex);
29952
29994
  }
29953
29995
  let res;
29996
+ // if we fould postfix exist, we should first try resolving file with postfix. details see #4703.
29997
+ if (postfix &&
29998
+ (res = tryResolveFile(fsPath, '', options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29999
+ return res;
30000
+ }
29954
30001
  if ((res = tryResolveFile(file, postfix, options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29955
30002
  return res;
29956
30003
  }
29957
30004
  for (const ext of options.extensions || DEFAULT_EXTENSIONS) {
30005
+ if (postfix &&
30006
+ (res = tryResolveFile(fsPath + ext, '', options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30007
+ return res;
30008
+ }
29958
30009
  if ((res = tryResolveFile(file + ext, postfix, options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29959
30010
  return res;
29960
30011
  }
29961
30012
  }
30013
+ if (postfix &&
30014
+ (res = tryResolveFile(fsPath, '', options, tryIndex, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30015
+ return res;
30016
+ }
29962
30017
  if ((res = tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29963
30018
  return res;
29964
30019
  }
29965
30020
  }
29966
30021
  function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, tryPrefix, skipPackageJson) {
29967
- let isReadable = false;
29968
- try {
29969
- // #2051 if we don't have read permission on a directory, existsSync() still
29970
- // works and will result in massively slow subsequent checks (which are
29971
- // unnecessary in the first place)
29972
- fs__default.accessSync(file, fs__default.constants.R_OK);
29973
- isReadable = true;
29974
- }
29975
- catch (e) { }
29976
- if (isReadable) {
30022
+ // #2051 if we don't have read permission on a directory, existsSync() still
30023
+ // works and will result in massively slow subsequent checks (which are
30024
+ // unnecessary in the first place)
30025
+ if (isFileReadable(file)) {
29977
30026
  if (!fs__default.statSync(file).isDirectory()) {
29978
30027
  return getRealPath(file, preserveSymlinks) + postfix;
29979
30028
  }
@@ -30378,9 +30427,6 @@ const debug$c = createDebugger('vite:ssr-external');
30378
30427
  /**
30379
30428
  * Heuristics for determining whether a dependency should be externalized for
30380
30429
  * server-side rendering.
30381
- *
30382
- * TODO right now externals are imported using require(), we probably need to
30383
- * rework this when more libraries ship native ESM distributions for Node.
30384
30430
  */
30385
30431
  function resolveSSRExternal(config, knownImports, ssrExternals = new Set(), seen = new Set()) {
30386
30432
  var _a, _b, _c, _d;
@@ -30444,6 +30490,10 @@ function resolveSSRExternal(config, knownImports, ssrExternals = new Set(), seen
30444
30490
  // entry is not js, cannot externalize
30445
30491
  continue;
30446
30492
  }
30493
+ if (pkg.type === "module" || entry.endsWith('.mjs')) {
30494
+ ssrExternals.add(id);
30495
+ continue;
30496
+ }
30447
30497
  // check if the entry is cjs
30448
30498
  const content = fs__default.readFileSync(entry, 'utf-8');
30449
30499
  if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
@@ -42060,36 +42110,11 @@ function errorMiddleware(server, allowNext = false) {
42060
42110
  next();
42061
42111
  }
42062
42112
  else {
42063
- if (err instanceof AccessRestrictedError) {
42064
- res.statusCode = 403;
42065
- res.write(renderErrorHTML(err.message));
42066
- res.end();
42067
- }
42068
42113
  res.statusCode = 500;
42069
42114
  res.end();
42070
42115
  }
42071
42116
  };
42072
42117
  }
42073
- class AccessRestrictedError extends Error {
42074
- constructor(msg) {
42075
- super(msg);
42076
- }
42077
- }
42078
- function renderErrorHTML(msg) {
42079
- // to have syntax highlighting and autocompletion in IDE
42080
- const html = String.raw;
42081
- return html `
42082
- <body>
42083
- <h1>403 Restricted</h1>
42084
- <p>${msg.replace(/\n/g, '<br/>')}</p>
42085
- <style>
42086
- body {
42087
- padding: 1em 2em;
42088
- }
42089
- </style>
42090
- </body>
42091
- `;
42092
- }
42093
42118
 
42094
42119
  /**
42095
42120
  * This file is refactored into TypeScript based on
@@ -42143,12 +42168,12 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42143
42168
  });
42144
42169
  }
42145
42170
  async resolve(id, importer, options) {
42146
- let skips;
42171
+ let skip;
42147
42172
  if ((options === null || options === void 0 ? void 0 : options.skipSelf) && this._activePlugin) {
42148
- skips = new Set(this._resolveSkips);
42149
- skips.add(this._activePlugin);
42173
+ skip = new Set(this._resolveSkips);
42174
+ skip.add(this._activePlugin);
42150
42175
  }
42151
- let out = await container.resolveId(id, importer, skips, this.ssr);
42176
+ let out = await container.resolveId(id, importer, { skip, ssr: this.ssr });
42152
42177
  if (typeof out === 'string')
42153
42178
  out = { id: out };
42154
42179
  return out;
@@ -42339,21 +42364,23 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42339
42364
  }
42340
42365
  }));
42341
42366
  },
42342
- async resolveId(rawId, importer = path$t.join(root, 'index.html'), skips, ssr) {
42367
+ async resolveId(rawId, importer = path$t.join(root, 'index.html'), options) {
42368
+ const skip = options === null || options === void 0 ? void 0 : options.skip;
42369
+ const ssr = options === null || options === void 0 ? void 0 : options.ssr;
42343
42370
  const ctx = new Context();
42344
42371
  ctx.ssr = !!ssr;
42345
- ctx._resolveSkips = skips;
42372
+ ctx._resolveSkips = skip;
42346
42373
  const resolveStart = isDebug ? perf_hooks.performance.now() : 0;
42347
42374
  let id = null;
42348
42375
  const partial = {};
42349
42376
  for (const plugin of plugins) {
42350
42377
  if (!plugin.resolveId)
42351
42378
  continue;
42352
- if (skips === null || skips === void 0 ? void 0 : skips.has(plugin))
42379
+ if (skip === null || skip === void 0 ? void 0 : skip.has(plugin))
42353
42380
  continue;
42354
42381
  ctx._activePlugin = plugin;
42355
42382
  const pluginResolveStart = isDebug ? perf_hooks.performance.now() : 0;
42356
- const result = await plugin.resolveId.call(ctx, rawId, importer, {}, ssr);
42383
+ const result = await plugin.resolveId.call(ctx, rawId, importer, { ssr });
42357
42384
  if (!result)
42358
42385
  continue;
42359
42386
  if (typeof result === 'string') {
@@ -42384,21 +42411,24 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42384
42411
  return null;
42385
42412
  }
42386
42413
  },
42387
- async load(id, ssr) {
42414
+ async load(id, options) {
42415
+ const ssr = options === null || options === void 0 ? void 0 : options.ssr;
42388
42416
  const ctx = new Context();
42389
42417
  ctx.ssr = !!ssr;
42390
42418
  for (const plugin of plugins) {
42391
42419
  if (!plugin.load)
42392
42420
  continue;
42393
42421
  ctx._activePlugin = plugin;
42394
- const result = await plugin.load.call(ctx, id, ssr);
42422
+ const result = await plugin.load.call(ctx, id, { ssr });
42395
42423
  if (result != null) {
42396
42424
  return result;
42397
42425
  }
42398
42426
  }
42399
42427
  return null;
42400
42428
  },
42401
- async transform(code, id, inMap, ssr) {
42429
+ async transform(code, id, options) {
42430
+ const inMap = options === null || options === void 0 ? void 0 : options.inMap;
42431
+ const ssr = options === null || options === void 0 ? void 0 : options.ssr;
42402
42432
  const ctx = new TransformContext(id, code, inMap);
42403
42433
  ctx.ssr = !!ssr;
42404
42434
  for (const plugin of plugins) {
@@ -42410,7 +42440,7 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42410
42440
  const start = isDebug ? perf_hooks.performance.now() : 0;
42411
42441
  let result;
42412
42442
  try {
42413
- result = await plugin.transform.call(ctx, code, id, ssr);
42443
+ result = await plugin.transform.call(ctx, code, id, { ssr });
42414
42444
  }
42415
42445
  catch (e) {
42416
42446
  ctx.error(e);
@@ -42660,7 +42690,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42660
42690
  // avoid matching windows volume
42661
42691
  filter: /^[\w@][^:]/
42662
42692
  }, async ({ path: id, importer }) => {
42663
- if (exclude === null || exclude === void 0 ? void 0 : exclude.some((e) => e === id || id.startsWith(e + '/'))) {
42693
+ if (moduleListContains(exclude, id)) {
42664
42694
  return externalUnlessEntry({ path: id });
42665
42695
  }
42666
42696
  if (depImports[id]) {
@@ -42805,7 +42835,7 @@ function shouldExternalizeDep(resolvedId, rawId) {
42805
42835
  function assetImportMetaUrlPlugin(config) {
42806
42836
  return {
42807
42837
  name: 'vite:asset-import-meta-url',
42808
- async transform(code, id, ssr) {
42838
+ async transform(code, id, options) {
42809
42839
  if (code.includes('new URL') && code.includes(`import.meta.url`)) {
42810
42840
  const importMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\)/g;
42811
42841
  const noCommentsCode = code
@@ -42815,7 +42845,7 @@ function assetImportMetaUrlPlugin(config) {
42815
42845
  let match;
42816
42846
  while ((match = importMetaUrlRE.exec(noCommentsCode))) {
42817
42847
  const { 0: exp, 1: rawUrl, index } = match;
42818
- if (ssr) {
42848
+ if (options === null || options === void 0 ? void 0 : options.ssr) {
42819
42849
  this.error(`\`new URL(url, import.meta.url)\` is not supported in SSR.`, index);
42820
42850
  }
42821
42851
  if (!s)
@@ -42877,7 +42907,8 @@ function loadFallbackPlugin() {
42877
42907
  name: 'vite:load-fallback',
42878
42908
  async load(id) {
42879
42909
  try {
42880
- return fs$r.promises.readFile(cleanUrl(id), 'utf-8');
42910
+ // if we don't add `await` here, we couldn't catch the error in readFile
42911
+ return await fs$r.promises.readFile(cleanUrl(id), 'utf-8');
42881
42912
  }
42882
42913
  catch (e) {
42883
42914
  return fs$r.promises.readFile(id, 'utf-8');
@@ -43041,6 +43072,7 @@ async function doBuild(inlineConfig = {}) {
43041
43072
  const rollup = require('rollup');
43042
43073
  const rollupOptions = {
43043
43074
  input,
43075
+ context: 'globalThis',
43044
43076
  preserveEntrySignatures: ssr
43045
43077
  ? 'allow-extension'
43046
43078
  : libOptions
@@ -43319,18 +43351,37 @@ function injectSsrFlagToHooks(p) {
43319
43351
  const { resolveId, load, transform } = p;
43320
43352
  return {
43321
43353
  ...p,
43322
- resolveId: wrapSsrHook(resolveId),
43323
- load: wrapSsrHook(load),
43324
- transform: wrapSsrHook(transform)
43354
+ resolveId: wrapSsrResolveId(resolveId),
43355
+ load: wrapSsrLoad(load),
43356
+ transform: wrapSsrTransform(transform)
43325
43357
  };
43326
43358
  }
43327
- function wrapSsrHook(fn) {
43359
+ function wrapSsrResolveId(fn) {
43328
43360
  if (!fn)
43329
43361
  return;
43330
- return function (...args) {
43331
- return fn.call(this, ...args, true);
43362
+ return function (id, importer, options) {
43363
+ return fn.call(this, id, importer, injectSsrFlag(options));
43332
43364
  };
43333
43365
  }
43366
+ function wrapSsrLoad(fn) {
43367
+ if (!fn)
43368
+ return;
43369
+ // Receiving options param to be future-proof if Rollup adds it
43370
+ return function (id, ...args) {
43371
+ return fn.call(this, id, injectSsrFlag(args[0]));
43372
+ };
43373
+ }
43374
+ function wrapSsrTransform(fn) {
43375
+ if (!fn)
43376
+ return;
43377
+ // Receiving options param to be future-proof if Rollup adds it
43378
+ return function (code, importer, ...args) {
43379
+ return fn.call(this, code, importer, injectSsrFlag(args[0]));
43380
+ };
43381
+ }
43382
+ function injectSsrFlag(options = {}) {
43383
+ return { ...options, ssr: true };
43384
+ }
43334
43385
 
43335
43386
  var build$1 = {
43336
43387
  __proto__: null,
@@ -49054,7 +49105,7 @@ function readFileIfExists(value) {
49054
49105
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49055
49106
  */
49056
49107
  async function createCertificate() {
49057
- const { generate } = await Promise.resolve().then(function () { return require('./dep-b502d052.js'); }).then(function (n) { return n.index; });
49108
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-0619a44b.js'); }).then(function (n) { return n.index; });
49058
49109
  const pems = generate(null, {
49059
49110
  algorithm: 'sha256',
49060
49111
  days: 30,
@@ -56147,6 +56198,14 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
56147
56198
  }
56148
56199
  }
56149
56200
  else if (isFunction(node)) {
56201
+ // If it is a function declaration, it could be shadowing an import
56202
+ // Add its name to the scope so it won't get replaced
56203
+ if (node.type === 'FunctionDeclaration') {
56204
+ const parentFunction = findParentFunction(parentStack);
56205
+ if (parentFunction) {
56206
+ setScope(parentFunction, node.id.name);
56207
+ }
56208
+ }
56150
56209
  // walk function expressions and add its arguments to known identifiers
56151
56210
  // so that we don't prefix them
56152
56211
  node.params.forEach((p) => walk$1(p.type === 'AssignmentPattern' ? p.left : p, {
@@ -56568,22 +56627,24 @@ function servePublicMiddleware(dir) {
56568
56627
  serve(req, res, next);
56569
56628
  };
56570
56629
  }
56571
- function serveStaticMiddleware(dir, config) {
56630
+ function serveStaticMiddleware(dir, server) {
56572
56631
  const serve = sirv(dir, sirvOptions);
56573
56632
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
56574
56633
  return function viteServeStaticMiddleware(req, res, next) {
56575
- // only serve the file if it's not an html request
56634
+ // only serve the file if it's not an html request or ends with `/`
56576
56635
  // so that html requests can fallthrough to our html middleware for
56577
56636
  // special processing
56578
56637
  // also skip internal requests `/@fs/ /@vite-client` etc...
56579
- if (path__default.extname(cleanUrl(req.url)) === '.html' ||
56638
+ const cleanedUrl = cleanUrl(req.url);
56639
+ if (cleanedUrl.endsWith('/') ||
56640
+ path__default.extname(cleanedUrl) === '.html' ||
56580
56641
  isInternalRequest(req.url)) {
56581
56642
  return next();
56582
56643
  }
56583
56644
  const url = decodeURI(req.url);
56584
56645
  // apply aliases to static requests as well
56585
56646
  let redirected;
56586
- for (const { find, replacement } of config.resolve.alias) {
56647
+ for (const { find, replacement } of server.config.resolve.alias) {
56587
56648
  const matches = typeof find === 'string' ? url.startsWith(find) : find.test(url);
56588
56649
  if (matches) {
56589
56650
  redirected = url.replace(find, replacement);
@@ -56595,6 +56656,16 @@ function serveStaticMiddleware(dir, config) {
56595
56656
  if (redirected.startsWith(dir)) {
56596
56657
  redirected = redirected.slice(dir.length);
56597
56658
  }
56659
+ }
56660
+ const resolvedUrl = redirected || url;
56661
+ let fileUrl = path__default.resolve(dir, resolvedUrl.replace(/^\//, ''));
56662
+ if (resolvedUrl.endsWith('/') && !fileUrl.endsWith('/')) {
56663
+ fileUrl = fileUrl + '/';
56664
+ }
56665
+ if (!ensureServingAccess(fileUrl, server, res, next)) {
56666
+ return;
56667
+ }
56668
+ if (redirected) {
56598
56669
  req.url = redirected;
56599
56670
  }
56600
56671
  serve(req, res, next);
@@ -56611,7 +56682,9 @@ function serveRawFsMiddleware(server) {
56611
56682
  // searching based from fs root.
56612
56683
  if (url.startsWith(FS_PREFIX)) {
56613
56684
  // restrict files outside of `fs.allow`
56614
- ensureServingAccess(slash$3(path__default.resolve(fsPathFromId(url))), server);
56685
+ if (!ensureServingAccess(slash$3(path__default.resolve(fsPathFromId(url))), server, res, next)) {
56686
+ return;
56687
+ }
56615
56688
  url = url.slice(FS_PREFIX.length);
56616
56689
  if (isWindows$4)
56617
56690
  url = url.replace(/^[A-Z]:/i, '');
@@ -56623,33 +56696,57 @@ function serveRawFsMiddleware(server) {
56623
56696
  }
56624
56697
  };
56625
56698
  }
56699
+ const _matchOptions = { matchBase: true };
56626
56700
  function isFileServingAllowed(url, server) {
56627
- // explicitly disabled
56628
- if (server.config.server.fs.strict === false)
56701
+ if (!server.config.server.fs.strict)
56629
56702
  return true;
56630
- const file = ensureLeadingSlash(normalizePath$4(cleanUrl(url)));
56703
+ const cleanedUrl = cleanUrl(url);
56704
+ const file = ensureLeadingSlash(normalizePath$4(cleanedUrl));
56705
+ if (server.config.server.fs.deny.some((i) => minimatch_1(file, i, _matchOptions)))
56706
+ return false;
56631
56707
  if (server.moduleGraph.safeModulesPath.has(file))
56632
56708
  return true;
56633
56709
  if (server.config.server.fs.allow.some((i) => file.startsWith(i + '/')))
56634
56710
  return true;
56635
- if (!server.config.server.fs.strict) {
56636
- server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`);
56637
- server.config.logger.warnOnce(`For security concerns, accessing files outside of serving allow list will ` +
56638
- `be restricted by default in the future version of Vite. ` +
56639
- `Refer to https://vitejs.dev/config/#server-fs-allow for more details.`);
56640
- return true;
56641
- }
56642
56711
  return false;
56643
56712
  }
56644
- function ensureServingAccess(url, server) {
56645
- if (!isFileServingAllowed(url, server)) {
56646
- const allow = server.config.server.fs.allow;
56647
- throw new AccessRestrictedError(`The request url "${url}" is outside of Vite serving allow list:
56648
-
56649
- ${allow.map((i) => `- ${i}`).join('\n')}
56713
+ function ensureServingAccess(url, server, res, next) {
56714
+ if (isFileServingAllowed(url, server)) {
56715
+ return true;
56716
+ }
56717
+ if (isFileReadable(cleanUrl(url))) {
56718
+ const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
56719
+ const hintMessage = `
56720
+ ${server.config.server.fs.allow.map((i) => `- ${i}`).join('\n')}
56650
56721
 
56651
- Refer to docs https://vitejs.dev/config/#server-fs-allow for configurations and more details.`);
56722
+ Refer to docs https://vitejs.dev/config/#server-fs-allow for configurations and more details.`;
56723
+ server.config.logger.error(urlMessage);
56724
+ server.config.logger.warnOnce(hintMessage + '\n');
56725
+ res.statusCode = 403;
56726
+ res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
56727
+ res.end();
56728
+ }
56729
+ else {
56730
+ // if the file doesn't exist, we shouldn't restrict this path as it can
56731
+ // be an API call. Middlewares would issue a 404 if the file isn't handled
56732
+ next();
56652
56733
  }
56734
+ return false;
56735
+ }
56736
+ function renderRestrictedErrorHTML(msg) {
56737
+ // to have syntax highlighting and autocompletion in IDE
56738
+ const html = String.raw;
56739
+ return html `
56740
+ <body>
56741
+ <h1>403 Restricted</h1>
56742
+ <p>${msg.replace(/\n/g, '<br/>')}</p>
56743
+ <style>
56744
+ body {
56745
+ padding: 1em 2em;
56746
+ }
56747
+ </style>
56748
+ </body>
56749
+ `;
56653
56750
  }
56654
56751
 
56655
56752
  const debugLoad = createDebugger('vite:load');
@@ -56696,7 +56793,7 @@ async function doTransform(url, server, options) {
56696
56793
  let map = null;
56697
56794
  // load
56698
56795
  const loadStart = isDebug$2 ? perf_hooks.performance.now() : 0;
56699
- const loadResult = await pluginContainer.load(id, ssr);
56796
+ const loadResult = await pluginContainer.load(id, { ssr });
56700
56797
  if (loadResult == null) {
56701
56798
  // if this is an html request and there is no load result, skip ahead to
56702
56799
  // SPA fallback.
@@ -56757,7 +56854,7 @@ async function doTransform(url, server, options) {
56757
56854
  ensureWatchedFile(watcher, mod.file, root);
56758
56855
  // transform
56759
56856
  const transformStart = isDebug$2 ? perf_hooks.performance.now() : 0;
56760
- const transformResult = await pluginContainer.transform(code, id, map, ssr);
56857
+ const transformResult = await pluginContainer.transform(code, id, { inMap: map, ssr });
56761
56858
  if (transformResult == null ||
56762
56859
  (isObject$3(transformResult) && transformResult.code == null)) {
56763
56860
  // no transform applied, keep code as-is
@@ -62845,6 +62942,13 @@ function esbuildDepPlugin(qualified, exportsData, config, ssr) {
62845
62942
  }
62846
62943
  }
62847
62944
  build.onResolve({ filter: /^[\w@][^:]/ }, async ({ path: id, importer, kind }) => {
62945
+ var _a;
62946
+ if (moduleListContains((_a = config.optimizeDeps) === null || _a === void 0 ? void 0 : _a.exclude, id)) {
62947
+ return {
62948
+ path: id,
62949
+ external: true
62950
+ };
62951
+ }
62848
62952
  // ensure esbuild uses our resolved entries
62849
62953
  let entry;
62850
62954
  // if this is an entry, return entry namespace resolve result
@@ -66458,7 +66562,7 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
66458
66562
  const ssrImport = async (dep) => {
66459
66563
  var _a, _b;
66460
66564
  if (dep[0] !== '.' && dep[0] !== '/') {
66461
- return nodeRequire(dep, mod.file, server.config.root, !!server.config.resolve.preserveSymlinks);
66565
+ return nodeImport(dep, mod.file, server.config);
66462
66566
  }
66463
66567
  dep = unwrapId$1(dep);
66464
66568
  if (!isCircular(dep) && !((_a = pendingImports.get(dep)) === null || _a === void 0 ? void 0 : _a.some(isCircular))) {
@@ -66515,10 +66619,25 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
66515
66619
  }
66516
66620
  return Object.freeze(ssrModule);
66517
66621
  }
66518
- function nodeRequire(id, importer, root, preserveSymlinks) {
66519
- const mod = require(resolve(id, importer, root, preserveSymlinks));
66520
- const defaultExport = mod.__esModule ? mod.default : mod;
66521
- // rollup-style default import interop for cjs
66622
+ // In node@12+ we can use dynamic import to load CJS and ESM
66623
+ async function nodeImport(id, importer, config) {
66624
+ let url;
66625
+ // `resolve` doesn't handle `node:` builtins, so handle them directly
66626
+ if (id.startsWith('node:') || isBuiltin(id)) {
66627
+ url = id;
66628
+ }
66629
+ else {
66630
+ url = resolve(id, importer, config.root, !!config.resolve.preserveSymlinks);
66631
+ if (usingDynamicImport) {
66632
+ url = require$$0$8.pathToFileURL(url).toString();
66633
+ }
66634
+ }
66635
+ const mod = await dynamicImport(url);
66636
+ return proxyESM(id, mod);
66637
+ }
66638
+ // rollup-style default import interop for cjs
66639
+ function proxyESM(id, mod) {
66640
+ const defaultExport = mod.__esModule ? mod.default : mod.default ? mod.default : mod;
66522
66641
  return new Proxy(mod, {
66523
66642
  get(mod, prop) {
66524
66643
  if (prop === 'default')
@@ -66578,8 +66697,11 @@ function createMissingImporterRegisterFn(server) {
66578
66697
  }
66579
66698
  finally {
66580
66699
  server._isRunningOptimizer = false;
66581
- pendingResolve && pendingResolve();
66582
- server._pendingReload = pendingResolve = null;
66700
+ if (!handle) {
66701
+ // No other rerun() pending so resolve and let pending requests proceed
66702
+ pendingResolve && pendingResolve();
66703
+ server._pendingReload = pendingResolve = null;
66704
+ }
66583
66705
  }
66584
66706
  // Cached transform results have stale imports (resolved to
66585
66707
  // old locations) so they need to be invalidated before the page is
@@ -66595,10 +66717,15 @@ function createMissingImporterRegisterFn(server) {
66595
66717
  currentMissing[id] = resolved;
66596
66718
  if (handle)
66597
66719
  clearTimeout(handle);
66598
- handle = setTimeout(() => rerun(ssr), debounceMs);
66599
- server._pendingReload = new Promise((r) => {
66600
- pendingResolve = r;
66601
- });
66720
+ handle = setTimeout(() => {
66721
+ handle = undefined;
66722
+ rerun(ssr);
66723
+ }, debounceMs);
66724
+ if (!server._pendingReload) {
66725
+ server._pendingReload = new Promise((r) => {
66726
+ pendingResolve = r;
66727
+ });
66728
+ }
66602
66729
  }
66603
66730
  };
66604
66731
  }
@@ -66618,10 +66745,7 @@ const ROOT_FILES = [
66618
66745
  // yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
66619
66746
  function hasWorkspacePackageJSON(root) {
66620
66747
  const path = path$t.join(root, 'package.json');
66621
- try {
66622
- fs__default.accessSync(path, fs__default.constants.R_OK);
66623
- }
66624
- catch {
66748
+ if (!isFileReadable(path)) {
66625
66749
  return false;
66626
66750
  }
66627
66751
  const content = JSON.parse(fs__default.readFileSync(path, 'utf-8')) || {};
@@ -66839,7 +66963,7 @@ async function createServer(inlineConfig = {}) {
66839
66963
  middlewares.use(transformMiddleware(server));
66840
66964
  // serve static files
66841
66965
  middlewares.use(serveRawFsMiddleware(server));
66842
- middlewares.use(serveStaticMiddleware(root, config));
66966
+ middlewares.use(serveStaticMiddleware(root, server));
66843
66967
  // spa fallback
66844
66968
  if (!middlewareMode || middlewareMode === 'html') {
66845
66969
  middlewares.use(spaFallbackMiddleware(root));
@@ -66973,9 +67097,10 @@ function resolvedAllowDir(root, dir) {
66973
67097
  return ensureLeadingSlash(normalizePath$4(path__default.resolve(root, dir)));
66974
67098
  }
66975
67099
  function resolveServerOptions(root, raw) {
66976
- var _a, _b;
67100
+ var _a, _b, _c, _d;
66977
67101
  const server = raw || {};
66978
67102
  let allowDirs = (_a = server.fs) === null || _a === void 0 ? void 0 : _a.allow;
67103
+ const deny = ((_b = server.fs) === null || _b === void 0 ? void 0 : _b.deny) || ['.env', '.env.*', '*.{crt,pem}'];
66979
67104
  if (!allowDirs) {
66980
67105
  allowDirs = [searchForWorkspaceRoot(root)];
66981
67106
  }
@@ -66986,9 +67111,9 @@ function resolveServerOptions(root, raw) {
66986
67111
  allowDirs.push(resolvedClientDir);
66987
67112
  }
66988
67113
  server.fs = {
66989
- // TODO: make strict by default
66990
- strict: (_b = server.fs) === null || _b === void 0 ? void 0 : _b.strict,
66991
- allow: allowDirs
67114
+ strict: (_d = (_c = server.fs) === null || _c === void 0 ? void 0 : _c.strict) !== null && _d !== void 0 ? _d : true,
67115
+ allow: allowDirs,
67116
+ deny
66992
67117
  };
66993
67118
  return server;
66994
67119
  }
@@ -67190,7 +67315,8 @@ function importAnalysisPlugin(config) {
67190
67315
  configureServer(_server) {
67191
67316
  server = _server;
67192
67317
  },
67193
- async transform(source$1, importer, ssr) {
67318
+ async transform(source$1, importer, options) {
67319
+ const ssr = (options === null || options === void 0 ? void 0 : options.ssr) === true;
67194
67320
  const prettyImporter = prettifyUrl(importer, root);
67195
67321
  if (canSkip(importer)) {
67196
67322
  isDebug && debug$2(source.dim(`[skipped] ${prettyImporter}`));
@@ -67239,12 +67365,26 @@ function importAnalysisPlugin(config) {
67239
67365
  const acceptedUrls = new Set();
67240
67366
  const toAbsoluteUrl = (url) => path__default.posix.resolve(path__default.posix.dirname(importerModule.url), url);
67241
67367
  const normalizeUrl = async (url, pos) => {
67368
+ var _a;
67242
67369
  if (base !== '/' && url.startsWith(base)) {
67243
67370
  url = url.replace(base, '/');
67244
67371
  }
67245
- const resolved = await this.resolve(url, importer);
67372
+ let importerFile = importer;
67373
+ if (moduleListContains((_a = config.optimizeDeps) === null || _a === void 0 ? void 0 : _a.exclude, url) &&
67374
+ server._optimizeDepsMetadata) {
67375
+ // if the dependency encountered in the optimized file was excluded from the optimization
67376
+ // the dependency needs to be resolved starting from the original source location of the optimized file
67377
+ // because starting from node_modules/.vite will not find the dependency if it was not hoisted
67378
+ // (that is, if it is under node_modules directory in the package source of the optimized file)
67379
+ for (const optimizedModule of Object.values(server._optimizeDepsMetadata.optimized)) {
67380
+ if (optimizedModule.file === importerModule.file) {
67381
+ importerFile = optimizedModule.src;
67382
+ }
67383
+ }
67384
+ }
67385
+ const resolved = await this.resolve(url, importerFile);
67246
67386
  if (!resolved) {
67247
- this.error(`Failed to resolve import "${url}" from "${path__default.relative(process.cwd(), importer)}". Does the file exist?`, pos);
67387
+ this.error(`Failed to resolve import "${url}" from "${path__default.relative(process.cwd(), importerFile)}". Does the file exist?`, pos);
67248
67388
  }
67249
67389
  const isRelative = url.startsWith('.');
67250
67390
  const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
@@ -67819,8 +67959,8 @@ function preAliasPlugin() {
67819
67959
  configureServer(_server) {
67820
67960
  server = _server;
67821
67961
  },
67822
- resolveId(id, importer, _, ssr) {
67823
- if (!ssr && bareImportRE.test(id)) {
67962
+ resolveId(id, importer, options) {
67963
+ if (!(options === null || options === void 0 ? void 0 : options.ssr) && bareImportRE.test(id)) {
67824
67964
  return tryOptimizedResolve(id, server, importer);
67825
67965
  }
67826
67966
  }
@@ -67871,7 +68011,8 @@ function definePlugin(config) {
67871
68011
  ')\\b', 'g');
67872
68012
  return {
67873
68013
  name: 'vite:define',
67874
- transform(code, id, ssr) {
68014
+ transform(code, id, options) {
68015
+ const ssr = (options === null || options === void 0 ? void 0 : options.ssr) === true;
67875
68016
  if (!ssr && !isBuild) {
67876
68017
  // for dev we inject actual global defines in the vite client to
67877
68018
  // avoid the transform cost.
@@ -68267,7 +68408,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
68267
68408
  ]
68268
68409
  }));
68269
68410
  }
68270
- return (_a = (await container.resolveId(id, importer, undefined, ssr))) === null || _a === void 0 ? void 0 : _a.id;
68411
+ return (_a = (await container.resolveId(id, importer, { ssr }))) === null || _a === void 0 ? void 0 : _a.id;
68271
68412
  };
68272
68413
  };
68273
68414
  const { publicDir } = config;
@@ -91985,8 +92126,9 @@ var compression$1 = compression$2.exports;
91985
92126
  * @param serverOptions - what host and port to use
91986
92127
  * @experimental
91987
92128
  */
91988
- async function preview(config, serverOptions) {
91989
- var _a, _b;
92129
+ async function preview(inlineConfig) {
92130
+ var _a;
92131
+ const config = await resolveConfig(inlineConfig, 'serve', 'production');
91990
92132
  const app = connect();
91991
92133
  const httpServer = await resolveHttpServer(config.server, app, await resolveHttpsConfig(config));
91992
92134
  // cors
@@ -92006,8 +92148,8 @@ async function preview(config, serverOptions) {
92006
92148
  single: true
92007
92149
  }));
92008
92150
  const options = config.server;
92009
- const hostname = resolveHostname((_a = serverOptions.host) !== null && _a !== void 0 ? _a : options.host);
92010
- const port = (_b = serverOptions.port) !== null && _b !== void 0 ? _b : 5000;
92151
+ const hostname = resolveHostname(options.host);
92152
+ const port = (_a = options.port) !== null && _a !== void 0 ? _a : 5000;
92011
92153
  const protocol = options.https ? 'https' : 'http';
92012
92154
  const logger = config.logger;
92013
92155
  const base = config.base;
@@ -92023,7 +92165,13 @@ async function preview(config, serverOptions) {
92023
92165
  ? path
92024
92166
  : `${protocol}://${hostname.name}:${serverPort}${path}`, true, logger);
92025
92167
  }
92026
- return httpServer;
92168
+ return {
92169
+ config,
92170
+ httpServer,
92171
+ printUrls() {
92172
+ printHttpServerUrls(httpServer, config);
92173
+ }
92174
+ };
92027
92175
  }
92028
92176
 
92029
92177
  exports.build = build;
@@ -92052,4 +92200,4 @@ exports.send = send$1;
92052
92200
  exports.sortUserPlugins = sortUserPlugins;
92053
92201
  exports.source = source;
92054
92202
  exports.transformWithEsbuild = transformWithEsbuild;
92055
- //# sourceMappingURL=dep-be032392.js.map
92203
+ //# sourceMappingURL=dep-f2dce443.js.map