vite 2.6.13 → 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
 
@@ -3887,6 +3887,9 @@ function isBuiltin(id) {
3887
3887
  id = deepMatch ? deepMatch[1] || deepMatch[2] : id;
3888
3888
  return builtinModules_1.includes(id);
3889
3889
  }
3890
+ function moduleListContains(moduleList, id) {
3891
+ return moduleList === null || moduleList === void 0 ? void 0 : moduleList.some((m) => m === id || id.startsWith(m + '/'));
3892
+ }
3890
3893
  const bareImportRE = /^[\w@](?!.*:\/\/)/;
3891
3894
  const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
3892
3895
  let isRunningWithYarnPnp;
@@ -4303,12 +4306,17 @@ function toUpperCaseDriveLetter(pathName) {
4303
4306
  }
4304
4307
  const multilineCommentsRE = /\/\*(.|[\r\n])*?\*\//gm;
4305
4308
  const singlelineCommentsRE = /\/\/.*/g;
4309
+ const usingDynamicImport = typeof jest === 'undefined';
4306
4310
  /**
4307
4311
  * Dynamically import files. It will make sure it's not being compiled away by TS/Rollup.
4308
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
+ *
4309
4317
  * @param file File path to import.
4310
4318
  */
4311
- const dynamicImport = new Function('file', 'return import(file)');
4319
+ const dynamicImport = usingDynamicImport ? new Function('file', 'return import(file)') : require;
4312
4320
 
4313
4321
  /* eslint no-console: 0 */
4314
4322
  const LogLevels = {
@@ -19940,7 +19948,7 @@ function cssPostPlugin(config) {
19940
19948
  outputToExtractedCSSMap = new Map();
19941
19949
  hasEmitted = false;
19942
19950
  },
19943
- async transform(css, id, ssr) {
19951
+ async transform(css, id, options) {
19944
19952
  if (!isCSSRequest(id) || commonjsProxyRE.test(id)) {
19945
19953
  return;
19946
19954
  }
@@ -19953,7 +19961,7 @@ function cssPostPlugin(config) {
19953
19961
  }
19954
19962
  else {
19955
19963
  // server only
19956
- if (ssr) {
19964
+ if (options === null || options === void 0 ? void 0 : options.ssr) {
19957
19965
  return modulesCode || `export default ${JSON.stringify(css)}`;
19958
19966
  }
19959
19967
  if (inlined) {
@@ -20257,7 +20265,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20257
20265
  replacer: urlReplacer
20258
20266
  }));
20259
20267
  if (isModule) {
20260
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-1a7759b6.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({
20261
20269
  ...modulesOptions,
20262
20270
  getJSON(cssFileName, _modules, outputFileName) {
20263
20271
  modules = _modules;
@@ -21222,7 +21230,7 @@ const assetAttrsConfig = {
21222
21230
  const isAsyncScriptMap = new WeakMap();
21223
21231
  async function traverseHtml(html, filePath, visitor) {
21224
21232
  // lazy load compiler
21225
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-93e144c8.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; });
21226
21234
  // @vue/compiler-core doesn't like lowercase doctypes
21227
21235
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21228
21236
  try {
@@ -21604,18 +21612,19 @@ function isEntirelyImport(code) {
21604
21612
  function toPublicPath(filename, config) {
21605
21613
  return isExternalUrl(filename) ? filename : config.base + filename;
21606
21614
  }
21607
- const headInjectRE = /([ \t]*)<\/head>/;
21608
- 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;
21609
21621
  const doctypePrependInjectRE = /<!doctype html>/i;
21610
21622
  function injectToHead(html, tags, prepend = false) {
21611
21623
  if (prepend) {
21612
- // inject after head or doctype
21624
+ // inject as the first element of head
21613
21625
  if (headPrependInjectRE.test(html)) {
21614
21626
  return html.replace(headPrependInjectRE, (match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`);
21615
21627
  }
21616
- else if (doctypePrependInjectRE.test(html)) {
21617
- return html.replace(doctypePrependInjectRE, `$&\n${serializeTags(tags)}`);
21618
- }
21619
21628
  }
21620
21629
  else {
21621
21630
  // inject before head close
@@ -21623,30 +21632,48 @@ function injectToHead(html, tags, prepend = false) {
21623
21632
  // respect indentation of head tag
21624
21633
  return html.replace(headInjectRE, (match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`);
21625
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
+ }
21626
21639
  }
21627
- // if no <head> tag is present, just prepend
21628
- 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);
21629
21642
  }
21630
- const bodyInjectRE = /([ \t]*)<\/body>/;
21631
- const bodyPrependInjectRE = /([ \t]*)<body[^>]*>/;
21632
21643
  function injectToBody(html, tags, prepend = false) {
21633
21644
  if (prepend) {
21634
21645
  // inject after body open
21635
21646
  if (bodyPrependInjectRE.test(html)) {
21636
21647
  return html.replace(bodyPrependInjectRE, (match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`);
21637
21648
  }
21638
- // if no body, prepend
21639
- 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);
21640
21654
  }
21641
21655
  else {
21642
21656
  // inject before body close
21643
21657
  if (bodyInjectRE.test(html)) {
21644
21658
  return html.replace(bodyInjectRE, (match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`);
21645
21659
  }
21646
- // 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
+ }
21647
21664
  return html + `\n` + serializeTags(tags);
21648
21665
  }
21649
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
+ }
21650
21677
  const unaryTags = new Set(['link', 'meta', 'base']);
21651
21678
  function serializeTag({ tag, attrs, children }, indent = '') {
21652
21679
  if (unaryTags.has(tag)) {
@@ -29809,7 +29836,8 @@ function resolvePlugin(baseOptions) {
29809
29836
  configureServer(_server) {
29810
29837
  server = _server;
29811
29838
  },
29812
- resolveId(id, importer, resolveOpts, ssr) {
29839
+ resolveId(id, importer, resolveOpts) {
29840
+ const ssr = (resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.ssr) === true;
29813
29841
  if (id.startsWith(browserExternalId)) {
29814
29842
  return id;
29815
29843
  }
@@ -29965,14 +29993,27 @@ function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, target
29965
29993
  postfix = fsPath.slice(postfixIndex);
29966
29994
  }
29967
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
+ }
29968
30001
  if ((res = tryResolveFile(file, postfix, options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29969
30002
  return res;
29970
30003
  }
29971
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
+ }
29972
30009
  if ((res = tryResolveFile(file + ext, postfix, options, false, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29973
30010
  return res;
29974
30011
  }
29975
30012
  }
30013
+ if (postfix &&
30014
+ (res = tryResolveFile(fsPath, '', options, tryIndex, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
30015
+ return res;
30016
+ }
29976
30017
  if ((res = tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, options.tryPrefix, options.skipPackageJson))) {
29977
30018
  return res;
29978
30019
  }
@@ -30386,9 +30427,6 @@ const debug$c = createDebugger('vite:ssr-external');
30386
30427
  /**
30387
30428
  * Heuristics for determining whether a dependency should be externalized for
30388
30429
  * server-side rendering.
30389
- *
30390
- * TODO right now externals are imported using require(), we probably need to
30391
- * rework this when more libraries ship native ESM distributions for Node.
30392
30430
  */
30393
30431
  function resolveSSRExternal(config, knownImports, ssrExternals = new Set(), seen = new Set()) {
30394
30432
  var _a, _b, _c, _d;
@@ -30452,6 +30490,10 @@ function resolveSSRExternal(config, knownImports, ssrExternals = new Set(), seen
30452
30490
  // entry is not js, cannot externalize
30453
30491
  continue;
30454
30492
  }
30493
+ if (pkg.type === "module" || entry.endsWith('.mjs')) {
30494
+ ssrExternals.add(id);
30495
+ continue;
30496
+ }
30455
30497
  // check if the entry is cjs
30456
30498
  const content = fs__default.readFileSync(entry, 'utf-8');
30457
30499
  if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
@@ -42126,12 +42168,12 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42126
42168
  });
42127
42169
  }
42128
42170
  async resolve(id, importer, options) {
42129
- let skips;
42171
+ let skip;
42130
42172
  if ((options === null || options === void 0 ? void 0 : options.skipSelf) && this._activePlugin) {
42131
- skips = new Set(this._resolveSkips);
42132
- skips.add(this._activePlugin);
42173
+ skip = new Set(this._resolveSkips);
42174
+ skip.add(this._activePlugin);
42133
42175
  }
42134
- let out = await container.resolveId(id, importer, skips, this.ssr);
42176
+ let out = await container.resolveId(id, importer, { skip, ssr: this.ssr });
42135
42177
  if (typeof out === 'string')
42136
42178
  out = { id: out };
42137
42179
  return out;
@@ -42322,21 +42364,23 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42322
42364
  }
42323
42365
  }));
42324
42366
  },
42325
- 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;
42326
42370
  const ctx = new Context();
42327
42371
  ctx.ssr = !!ssr;
42328
- ctx._resolveSkips = skips;
42372
+ ctx._resolveSkips = skip;
42329
42373
  const resolveStart = isDebug ? perf_hooks.performance.now() : 0;
42330
42374
  let id = null;
42331
42375
  const partial = {};
42332
42376
  for (const plugin of plugins) {
42333
42377
  if (!plugin.resolveId)
42334
42378
  continue;
42335
- if (skips === null || skips === void 0 ? void 0 : skips.has(plugin))
42379
+ if (skip === null || skip === void 0 ? void 0 : skip.has(plugin))
42336
42380
  continue;
42337
42381
  ctx._activePlugin = plugin;
42338
42382
  const pluginResolveStart = isDebug ? perf_hooks.performance.now() : 0;
42339
- const result = await plugin.resolveId.call(ctx, rawId, importer, {}, ssr);
42383
+ const result = await plugin.resolveId.call(ctx, rawId, importer, { ssr });
42340
42384
  if (!result)
42341
42385
  continue;
42342
42386
  if (typeof result === 'string') {
@@ -42367,21 +42411,24 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42367
42411
  return null;
42368
42412
  }
42369
42413
  },
42370
- async load(id, ssr) {
42414
+ async load(id, options) {
42415
+ const ssr = options === null || options === void 0 ? void 0 : options.ssr;
42371
42416
  const ctx = new Context();
42372
42417
  ctx.ssr = !!ssr;
42373
42418
  for (const plugin of plugins) {
42374
42419
  if (!plugin.load)
42375
42420
  continue;
42376
42421
  ctx._activePlugin = plugin;
42377
- const result = await plugin.load.call(ctx, id, ssr);
42422
+ const result = await plugin.load.call(ctx, id, { ssr });
42378
42423
  if (result != null) {
42379
42424
  return result;
42380
42425
  }
42381
42426
  }
42382
42427
  return null;
42383
42428
  },
42384
- 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;
42385
42432
  const ctx = new TransformContext(id, code, inMap);
42386
42433
  ctx.ssr = !!ssr;
42387
42434
  for (const plugin of plugins) {
@@ -42393,7 +42440,7 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42393
42440
  const start = isDebug ? perf_hooks.performance.now() : 0;
42394
42441
  let result;
42395
42442
  try {
42396
- result = await plugin.transform.call(ctx, code, id, ssr);
42443
+ result = await plugin.transform.call(ctx, code, id, { ssr });
42397
42444
  }
42398
42445
  catch (e) {
42399
42446
  ctx.error(e);
@@ -42643,7 +42690,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42643
42690
  // avoid matching windows volume
42644
42691
  filter: /^[\w@][^:]/
42645
42692
  }, async ({ path: id, importer }) => {
42646
- if (exclude === null || exclude === void 0 ? void 0 : exclude.some((e) => e === id || id.startsWith(e + '/'))) {
42693
+ if (moduleListContains(exclude, id)) {
42647
42694
  return externalUnlessEntry({ path: id });
42648
42695
  }
42649
42696
  if (depImports[id]) {
@@ -42788,7 +42835,7 @@ function shouldExternalizeDep(resolvedId, rawId) {
42788
42835
  function assetImportMetaUrlPlugin(config) {
42789
42836
  return {
42790
42837
  name: 'vite:asset-import-meta-url',
42791
- async transform(code, id, ssr) {
42838
+ async transform(code, id, options) {
42792
42839
  if (code.includes('new URL') && code.includes(`import.meta.url`)) {
42793
42840
  const importMetaUrlRE = /\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\)/g;
42794
42841
  const noCommentsCode = code
@@ -42798,7 +42845,7 @@ function assetImportMetaUrlPlugin(config) {
42798
42845
  let match;
42799
42846
  while ((match = importMetaUrlRE.exec(noCommentsCode))) {
42800
42847
  const { 0: exp, 1: rawUrl, index } = match;
42801
- if (ssr) {
42848
+ if (options === null || options === void 0 ? void 0 : options.ssr) {
42802
42849
  this.error(`\`new URL(url, import.meta.url)\` is not supported in SSR.`, index);
42803
42850
  }
42804
42851
  if (!s)
@@ -42860,6 +42907,7 @@ function loadFallbackPlugin() {
42860
42907
  name: 'vite:load-fallback',
42861
42908
  async load(id) {
42862
42909
  try {
42910
+ // if we don't add `await` here, we couldn't catch the error in readFile
42863
42911
  return await fs$r.promises.readFile(cleanUrl(id), 'utf-8');
42864
42912
  }
42865
42913
  catch (e) {
@@ -43303,18 +43351,37 @@ function injectSsrFlagToHooks(p) {
43303
43351
  const { resolveId, load, transform } = p;
43304
43352
  return {
43305
43353
  ...p,
43306
- resolveId: wrapSsrHook(resolveId),
43307
- load: wrapSsrHook(load),
43308
- transform: wrapSsrHook(transform)
43354
+ resolveId: wrapSsrResolveId(resolveId),
43355
+ load: wrapSsrLoad(load),
43356
+ transform: wrapSsrTransform(transform)
43357
+ };
43358
+ }
43359
+ function wrapSsrResolveId(fn) {
43360
+ if (!fn)
43361
+ return;
43362
+ return function (id, importer, options) {
43363
+ return fn.call(this, id, importer, injectSsrFlag(options));
43309
43364
  };
43310
43365
  }
43311
- function wrapSsrHook(fn) {
43366
+ function wrapSsrLoad(fn) {
43312
43367
  if (!fn)
43313
43368
  return;
43314
- return function (...args) {
43315
- return fn.call(this, ...args, true);
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]));
43316
43372
  };
43317
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
+ }
43318
43385
 
43319
43386
  var build$1 = {
43320
43387
  __proto__: null,
@@ -49038,7 +49105,7 @@ function readFileIfExists(value) {
49038
49105
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49039
49106
  */
49040
49107
  async function createCertificate() {
49041
- const { generate } = await Promise.resolve().then(function () { return require('./dep-724b1c48.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; });
49042
49109
  const pems = generate(null, {
49043
49110
  algorithm: 'sha256',
49044
49111
  days: 30,
@@ -56629,25 +56696,18 @@ function serveRawFsMiddleware(server) {
56629
56696
  }
56630
56697
  };
56631
56698
  }
56699
+ const _matchOptions = { matchBase: true };
56632
56700
  function isFileServingAllowed(url, server) {
56633
- // explicitly disabled
56634
- if (server.config.server.fs.strict === false)
56701
+ if (!server.config.server.fs.strict)
56635
56702
  return true;
56636
56703
  const cleanedUrl = cleanUrl(url);
56637
56704
  const file = ensureLeadingSlash(normalizePath$4(cleanedUrl));
56705
+ if (server.config.server.fs.deny.some((i) => minimatch_1(file, i, _matchOptions)))
56706
+ return false;
56638
56707
  if (server.moduleGraph.safeModulesPath.has(file))
56639
56708
  return true;
56640
56709
  if (server.config.server.fs.allow.some((i) => file.startsWith(i + '/')))
56641
56710
  return true;
56642
- if (!server.config.server.fs.strict) {
56643
- if (isFileReadable(cleanedUrl)) {
56644
- server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`);
56645
- server.config.logger.warnOnce(`For security concerns, accessing files outside of serving allow list will ` +
56646
- `be restricted by default in the future version of Vite. ` +
56647
- `Refer to https://vitejs.dev/config/#server-fs-allow for more details.`);
56648
- }
56649
- return true;
56650
- }
56651
56711
  return false;
56652
56712
  }
56653
56713
  function ensureServingAccess(url, server, res, next) {
@@ -56733,7 +56793,7 @@ async function doTransform(url, server, options) {
56733
56793
  let map = null;
56734
56794
  // load
56735
56795
  const loadStart = isDebug$2 ? perf_hooks.performance.now() : 0;
56736
- const loadResult = await pluginContainer.load(id, ssr);
56796
+ const loadResult = await pluginContainer.load(id, { ssr });
56737
56797
  if (loadResult == null) {
56738
56798
  // if this is an html request and there is no load result, skip ahead to
56739
56799
  // SPA fallback.
@@ -56794,7 +56854,7 @@ async function doTransform(url, server, options) {
56794
56854
  ensureWatchedFile(watcher, mod.file, root);
56795
56855
  // transform
56796
56856
  const transformStart = isDebug$2 ? perf_hooks.performance.now() : 0;
56797
- const transformResult = await pluginContainer.transform(code, id, map, ssr);
56857
+ const transformResult = await pluginContainer.transform(code, id, { inMap: map, ssr });
56798
56858
  if (transformResult == null ||
56799
56859
  (isObject$3(transformResult) && transformResult.code == null)) {
56800
56860
  // no transform applied, keep code as-is
@@ -62882,6 +62942,13 @@ function esbuildDepPlugin(qualified, exportsData, config, ssr) {
62882
62942
  }
62883
62943
  }
62884
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
+ }
62885
62952
  // ensure esbuild uses our resolved entries
62886
62953
  let entry;
62887
62954
  // if this is an entry, return entry namespace resolve result
@@ -66495,7 +66562,7 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
66495
66562
  const ssrImport = async (dep) => {
66496
66563
  var _a, _b;
66497
66564
  if (dep[0] !== '.' && dep[0] !== '/') {
66498
- return nodeRequire(dep, mod.file, server.config.root, !!server.config.resolve.preserveSymlinks);
66565
+ return nodeImport(dep, mod.file, server.config);
66499
66566
  }
66500
66567
  dep = unwrapId$1(dep);
66501
66568
  if (!isCircular(dep) && !((_a = pendingImports.get(dep)) === null || _a === void 0 ? void 0 : _a.some(isCircular))) {
@@ -66552,10 +66619,25 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
66552
66619
  }
66553
66620
  return Object.freeze(ssrModule);
66554
66621
  }
66555
- function nodeRequire(id, importer, root, preserveSymlinks) {
66556
- const mod = require(resolve(id, importer, root, preserveSymlinks));
66557
- const defaultExport = mod.__esModule ? mod.default : mod;
66558
- // 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;
66559
66641
  return new Proxy(mod, {
66560
66642
  get(mod, prop) {
66561
66643
  if (prop === 'default')
@@ -66615,8 +66697,11 @@ function createMissingImporterRegisterFn(server) {
66615
66697
  }
66616
66698
  finally {
66617
66699
  server._isRunningOptimizer = false;
66618
- pendingResolve && pendingResolve();
66619
- 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
+ }
66620
66705
  }
66621
66706
  // Cached transform results have stale imports (resolved to
66622
66707
  // old locations) so they need to be invalidated before the page is
@@ -66632,10 +66717,15 @@ function createMissingImporterRegisterFn(server) {
66632
66717
  currentMissing[id] = resolved;
66633
66718
  if (handle)
66634
66719
  clearTimeout(handle);
66635
- handle = setTimeout(() => rerun(ssr), debounceMs);
66636
- server._pendingReload = new Promise((r) => {
66637
- pendingResolve = r;
66638
- });
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
+ }
66639
66729
  }
66640
66730
  };
66641
66731
  }
@@ -67007,9 +67097,10 @@ function resolvedAllowDir(root, dir) {
67007
67097
  return ensureLeadingSlash(normalizePath$4(path__default.resolve(root, dir)));
67008
67098
  }
67009
67099
  function resolveServerOptions(root, raw) {
67010
- var _a, _b;
67100
+ var _a, _b, _c, _d;
67011
67101
  const server = raw || {};
67012
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}'];
67013
67104
  if (!allowDirs) {
67014
67105
  allowDirs = [searchForWorkspaceRoot(root)];
67015
67106
  }
@@ -67020,9 +67111,9 @@ function resolveServerOptions(root, raw) {
67020
67111
  allowDirs.push(resolvedClientDir);
67021
67112
  }
67022
67113
  server.fs = {
67023
- // TODO: make strict by default
67024
- strict: (_b = server.fs) === null || _b === void 0 ? void 0 : _b.strict,
67025
- 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
67026
67117
  };
67027
67118
  return server;
67028
67119
  }
@@ -67224,7 +67315,8 @@ function importAnalysisPlugin(config) {
67224
67315
  configureServer(_server) {
67225
67316
  server = _server;
67226
67317
  },
67227
- 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;
67228
67320
  const prettyImporter = prettifyUrl(importer, root);
67229
67321
  if (canSkip(importer)) {
67230
67322
  isDebug && debug$2(source.dim(`[skipped] ${prettyImporter}`));
@@ -67273,12 +67365,26 @@ function importAnalysisPlugin(config) {
67273
67365
  const acceptedUrls = new Set();
67274
67366
  const toAbsoluteUrl = (url) => path__default.posix.resolve(path__default.posix.dirname(importerModule.url), url);
67275
67367
  const normalizeUrl = async (url, pos) => {
67368
+ var _a;
67276
67369
  if (base !== '/' && url.startsWith(base)) {
67277
67370
  url = url.replace(base, '/');
67278
67371
  }
67279
- 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);
67280
67386
  if (!resolved) {
67281
- 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);
67282
67388
  }
67283
67389
  const isRelative = url.startsWith('.');
67284
67390
  const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
@@ -67853,8 +67959,8 @@ function preAliasPlugin() {
67853
67959
  configureServer(_server) {
67854
67960
  server = _server;
67855
67961
  },
67856
- resolveId(id, importer, _, ssr) {
67857
- if (!ssr && bareImportRE.test(id)) {
67962
+ resolveId(id, importer, options) {
67963
+ if (!(options === null || options === void 0 ? void 0 : options.ssr) && bareImportRE.test(id)) {
67858
67964
  return tryOptimizedResolve(id, server, importer);
67859
67965
  }
67860
67966
  }
@@ -67905,7 +68011,8 @@ function definePlugin(config) {
67905
68011
  ')\\b', 'g');
67906
68012
  return {
67907
68013
  name: 'vite:define',
67908
- transform(code, id, ssr) {
68014
+ transform(code, id, options) {
68015
+ const ssr = (options === null || options === void 0 ? void 0 : options.ssr) === true;
67909
68016
  if (!ssr && !isBuild) {
67910
68017
  // for dev we inject actual global defines in the vite client to
67911
68018
  // avoid the transform cost.
@@ -68301,7 +68408,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
68301
68408
  ]
68302
68409
  }));
68303
68410
  }
68304
- 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;
68305
68412
  };
68306
68413
  };
68307
68414
  const { publicDir } = config;
@@ -92019,8 +92126,9 @@ var compression$1 = compression$2.exports;
92019
92126
  * @param serverOptions - what host and port to use
92020
92127
  * @experimental
92021
92128
  */
92022
- async function preview(config, serverOptions) {
92023
- var _a, _b;
92129
+ async function preview(inlineConfig) {
92130
+ var _a;
92131
+ const config = await resolveConfig(inlineConfig, 'serve', 'production');
92024
92132
  const app = connect();
92025
92133
  const httpServer = await resolveHttpServer(config.server, app, await resolveHttpsConfig(config));
92026
92134
  // cors
@@ -92040,8 +92148,8 @@ async function preview(config, serverOptions) {
92040
92148
  single: true
92041
92149
  }));
92042
92150
  const options = config.server;
92043
- const hostname = resolveHostname((_a = serverOptions.host) !== null && _a !== void 0 ? _a : options.host);
92044
- 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;
92045
92153
  const protocol = options.https ? 'https' : 'http';
92046
92154
  const logger = config.logger;
92047
92155
  const base = config.base;
@@ -92057,7 +92165,13 @@ async function preview(config, serverOptions) {
92057
92165
  ? path
92058
92166
  : `${protocol}://${hostname.name}:${serverPort}${path}`, true, logger);
92059
92167
  }
92060
- return httpServer;
92168
+ return {
92169
+ config,
92170
+ httpServer,
92171
+ printUrls() {
92172
+ printHttpServerUrls(httpServer, config);
92173
+ }
92174
+ };
92061
92175
  }
92062
92176
 
92063
92177
  exports.build = build;
@@ -92086,4 +92200,4 @@ exports.send = send$1;
92086
92200
  exports.sortUserPlugins = sortUserPlugins;
92087
92201
  exports.source = source;
92088
92202
  exports.transformWithEsbuild = transformWithEsbuild;
92089
- //# sourceMappingURL=dep-85dbaaa7.js.map
92203
+ //# sourceMappingURL=dep-f2dce443.js.map