vite 2.7.0-beta.3 → 2.7.0-beta.4

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.

@@ -10,7 +10,7 @@ var require$$0$a = require('events');
10
10
  var require$$0$7 = require('url');
11
11
  var require$$1$2 = require('http');
12
12
  var require$$0$9 = require('stream');
13
- var resolve$4 = require('resolve');
13
+ var resolve$3 = require('resolve');
14
14
  var require$$0$6 = require('module');
15
15
  var perf_hooks = require('perf_hooks');
16
16
  var require$$1$3 = require('https');
@@ -50,7 +50,7 @@ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
50
50
  var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
51
51
  var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
52
52
  var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
53
- var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve$4);
53
+ var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve$3);
54
54
  var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
55
55
  var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
56
56
  var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
@@ -3387,7 +3387,7 @@ function normalizePath$5(input) {
3387
3387
  /**
3388
3388
  * Attempts to resolve `input` URL relative to `base`.
3389
3389
  */
3390
- function resolve$3(input, base) {
3390
+ function resolve$2(input, base) {
3391
3391
  if (!base)
3392
3392
  base = '';
3393
3393
  // Absolute URLs are very easy to resolve right.
@@ -3455,7 +3455,7 @@ function resolve$1$1(input, base) {
3455
3455
  // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
3456
3456
  if (base && !base.endsWith('/'))
3457
3457
  base += '/';
3458
- return resolve$3(input, base);
3458
+ return resolve$2(input, base);
3459
3459
  }
3460
3460
 
3461
3461
  /**
@@ -3958,6 +3958,7 @@ const externalRE = /^(https?:)?\/\//;
3958
3958
  const isExternalUrl = (url) => externalRE.test(url);
3959
3959
  const dataUrlRE = /^\s*data:/i;
3960
3960
  const isDataUrl = (url) => dataUrlRE.test(url);
3961
+ const virtualModuleRE = /virtual-module:.*/;
3961
3962
  const knownJsSrcRE = /\.((j|t)sx?|mjs|vue|marko|svelte|astro)($|\?)/;
3962
3963
  const isJSRequest = (url) => {
3963
3964
  url = cleanUrl(url);
@@ -4058,6 +4059,9 @@ function prettifyUrl(url, root) {
4058
4059
  function isObject$3(value) {
4059
4060
  return Object.prototype.toString.call(value) === '[object Object]';
4060
4061
  }
4062
+ function isDefined(value) {
4063
+ return value != null;
4064
+ }
4061
4065
  function lookupFile(dir, formats, pathOnly = false) {
4062
4066
  for (const format of formats) {
4063
4067
  const fullPath = path__default.join(dir, format);
@@ -4343,9 +4347,8 @@ function createLogger(level = 'info', options = {}) {
4343
4347
  const loggedErrors = new WeakSet();
4344
4348
  const { prefix = '[vite]', allowClearScreen = true } = options;
4345
4349
  const thresh = LogLevels[level];
4346
- const clear = allowClearScreen && process.stdout.isTTY && !process.env.CI
4347
- ? clearScreen
4348
- : () => { };
4350
+ const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
4351
+ const clear = canClearScreen ? clearScreen : () => { };
4349
4352
  function output(type, msg, options = {}) {
4350
4353
  if (thresh >= LogLevels[type]) {
4351
4354
  const method = type === 'info' ? 'log' : type;
@@ -4365,18 +4368,23 @@ function createLogger(level = 'info', options = {}) {
4365
4368
  if (options.error) {
4366
4369
  loggedErrors.add(options.error);
4367
4370
  }
4368
- if (type === lastType && msg === lastMsg) {
4369
- sameCount++;
4370
- clear();
4371
- console[method](format(), source.yellow(`(x${sameCount + 1})`));
4372
- }
4373
- else {
4374
- sameCount = 0;
4375
- lastMsg = msg;
4376
- lastType = type;
4377
- if (options.clear) {
4371
+ if (canClearScreen) {
4372
+ if (type === lastType && msg === lastMsg) {
4373
+ sameCount++;
4378
4374
  clear();
4375
+ console[method](format(), source.yellow(`(x${sameCount + 1})`));
4376
+ }
4377
+ else {
4378
+ sameCount = 0;
4379
+ lastMsg = msg;
4380
+ lastType = type;
4381
+ if (options.clear) {
4382
+ clear();
4383
+ }
4384
+ console[method](format());
4379
4385
  }
4386
+ }
4387
+ else {
4380
4388
  console[method](format());
4381
4389
  }
4382
4390
  }
@@ -19599,7 +19607,7 @@ const plugins = (config, file) => {
19599
19607
 
19600
19608
  var plugins_1 = plugins;
19601
19609
 
19602
- const resolve$2 = path__default.resolve;
19610
+ const resolve$1 = path__default.resolve;
19603
19611
 
19604
19612
  const config$1 = dist$2;
19605
19613
  const yaml = yaml$1;
@@ -19738,7 +19746,7 @@ const rc = withTypeScriptLoader((ctx, path, options) => {
19738
19746
  /**
19739
19747
  * @type {String} `process.cwd()`
19740
19748
  */
19741
- path = path ? resolve$2(path) : process.cwd();
19749
+ path = path ? resolve$1(path) : process.cwd();
19742
19750
 
19743
19751
  return config$1.lilconfig('postcss', options)
19744
19752
  .search(path)
@@ -19760,7 +19768,7 @@ rc.sync = withTypeScriptLoader((ctx, path, options) => {
19760
19768
  /**
19761
19769
  * @type {String} `process.cwd()`
19762
19770
  */
19763
- path = path ? resolve$2(path) : process.cwd();
19771
+ path = path ? resolve$1(path) : process.cwd();
19764
19772
 
19765
19773
  const result = config$1.lilconfigSync('postcss', options).search(path);
19766
19774
 
@@ -20377,7 +20385,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20377
20385
  replacer: urlReplacer
20378
20386
  }));
20379
20387
  if (isModule) {
20380
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-c1084913.js'); }).then(function (n) { return n.index; })).default({
20388
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-9583e954.js'); }).then(function (n) { return n.index; })).default({
20381
20389
  ...modulesOptions,
20382
20390
  getJSON(cssFileName, _modules, outputFileName) {
20383
20391
  modules = _modules;
@@ -21342,7 +21350,7 @@ const assetAttrsConfig = {
21342
21350
  const isAsyncScriptMap = new WeakMap();
21343
21351
  async function traverseHtml(html, filePath, visitor) {
21344
21352
  // lazy load compiler
21345
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-59a3bcf9.js'); }).then(function (n) { return n.compilerDom_cjs; });
21353
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-ef63fa34.js'); }).then(function (n) { return n.compilerDom_cjs; });
21346
21354
  // @vue/compiler-core doesn't like lowercase doctypes
21347
21355
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21348
21356
  try {
@@ -27622,7 +27630,7 @@ function getRequireStringArg(node) {
27622
27630
  function hasDynamicModuleForPath(source, id, dynamicRequireModuleSet) {
27623
27631
  if (!/^(?:\.{0,2}[/\\]|[A-Za-z]:[/\\])/.test(source)) {
27624
27632
  try {
27625
- const resolvedPath = normalizePathSlashes(resolve$4.sync(source, { basedir: path$t.dirname(id) }));
27633
+ const resolvedPath = normalizePathSlashes(resolve$3.sync(source, { basedir: path$t.dirname(id) }));
27626
27634
  if (dynamicRequireModuleSet.has(resolvedPath)) {
27627
27635
  return true;
27628
27636
  }
@@ -29877,7 +29885,7 @@ function toName(name, entry) {
29877
29885
  * @param {string[]} [options.conditions]
29878
29886
  * @param {boolean} [options.unsafe]
29879
29887
  */
29880
- function resolve$1(pkg, entry='.', options={}) {
29888
+ function resolve(pkg, entry='.', options={}) {
29881
29889
  let { name, exports } = pkg;
29882
29890
 
29883
29891
  if (exports) {
@@ -30190,18 +30198,17 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
30190
30198
  else {
30191
30199
  basedir = root;
30192
30200
  }
30193
- const preserveSymlinks = !!(server === null || server === void 0 ? void 0 : server.config.resolve.preserveSymlinks);
30194
30201
  // nested node module, step-by-step resolve to the basedir of the nestedPath
30195
30202
  if (nestedRoot) {
30196
- basedir = nestedResolveFrom(nestedRoot, basedir, preserveSymlinks);
30203
+ basedir = nestedResolveFrom(nestedRoot, basedir, options.preserveSymlinks);
30197
30204
  }
30198
- const pkg = resolvePackageData(pkgId, basedir, preserveSymlinks);
30205
+ const pkg = resolvePackageData(pkgId, basedir, options.preserveSymlinks);
30199
30206
  if (!pkg) {
30200
30207
  return;
30201
30208
  }
30202
30209
  let resolved = deepMatch
30203
- ? resolveDeepImport('.' + id.slice(pkgId.length), pkg, options, targetWeb, preserveSymlinks)
30204
- : resolvePackageEntry(id, pkg, options, targetWeb, preserveSymlinks);
30210
+ ? resolveDeepImport('.' + id.slice(pkgId.length), pkg, options, targetWeb, options.preserveSymlinks)
30211
+ : resolvePackageEntry(id, pkg, options, targetWeb, options.preserveSymlinks);
30205
30212
  if (!resolved) {
30206
30213
  return;
30207
30214
  }
@@ -30442,7 +30449,7 @@ function resolveExports(pkg, key, options, targetWeb) {
30442
30449
  if (options.conditions) {
30443
30450
  conditions.push(...options.conditions);
30444
30451
  }
30445
- return resolve$1(pkg, key, {
30452
+ return resolve(pkg, key, {
30446
30453
  browser: targetWeb,
30447
30454
  require: options.isRequire,
30448
30455
  conditions
@@ -30559,8 +30566,9 @@ function resolveSSRExternal(config, knownImports) {
30559
30566
  ssrExternals.add(id);
30560
30567
  seen.add(id);
30561
30568
  });
30562
- collectExternals(config.root, ssrExternals, seen);
30563
- for (const dep of knownImports) {
30569
+ collectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen);
30570
+ const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
30571
+ for (const dep of importedDeps) {
30564
30572
  // Assume external if not yet seen
30565
30573
  // At this point, the project root and any linked packages have had their dependencies checked,
30566
30574
  // so we can safely mark any knownImports not yet seen as external. They are guaranteed to be
@@ -30578,7 +30586,7 @@ function resolveSSRExternal(config, knownImports) {
30578
30586
  return externals;
30579
30587
  }
30580
30588
  // do we need to do this ahead of time or could we do it lazily?
30581
- function collectExternals(root, ssrExternals, seen) {
30589
+ function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
30582
30590
  var _a;
30583
30591
  const pkgContent = lookupFile(root, ['package.json']);
30584
30592
  if (!pkgContent) {
@@ -30591,6 +30599,7 @@ function collectExternals(root, ssrExternals, seen) {
30591
30599
  };
30592
30600
  const resolveOptions = {
30593
30601
  root,
30602
+ preserveSymlinks,
30594
30603
  isProduction: false,
30595
30604
  isBuild: true
30596
30605
  };
@@ -30642,7 +30651,7 @@ function collectExternals(root, ssrExternals, seen) {
30642
30651
  // or are there others like SystemJS / AMD that we'd need to handle?
30643
30652
  // for now, we'll just leave this as is
30644
30653
  else if (/\.m?js$/.test(esmEntry)) {
30645
- if (pkg.type === "module" || esmEntry.endsWith('.mjs')) {
30654
+ if (pkg.type === 'module' || esmEntry.endsWith('.mjs')) {
30646
30655
  ssrExternals.add(id);
30647
30656
  continue;
30648
30657
  }
@@ -30654,7 +30663,7 @@ function collectExternals(root, ssrExternals, seen) {
30654
30663
  }
30655
30664
  }
30656
30665
  for (const depRoot of depsToTrace) {
30657
- collectExternals(depRoot, ssrExternals, seen);
30666
+ collectExternals(depRoot, preserveSymlinks, ssrExternals, seen);
30658
30667
  }
30659
30668
  }
30660
30669
  function shouldExternalizeForSSR(id, externals) {
@@ -30670,6 +30679,17 @@ function shouldExternalizeForSSR(id, externals) {
30670
30679
  });
30671
30680
  return should;
30672
30681
  }
30682
+ function getNpmPackageName(importPath) {
30683
+ const parts = importPath.split('/');
30684
+ if (parts[0].startsWith('@')) {
30685
+ if (!parts[1])
30686
+ return null;
30687
+ return `${parts[0]}/${parts[1]}`;
30688
+ }
30689
+ else {
30690
+ return parts[0];
30691
+ }
30692
+ }
30673
30693
 
30674
30694
  function ssrManifestPlugin(config) {
30675
30695
  // module id => preload assets mapping
@@ -42247,7 +42267,7 @@ function errorMiddleware(server, allowNext = false) {
42247
42267
  * https://github.com/preactjs/wmr/blob/main/packages/wmr/src/lib/rollup-plugin-container.js
42248
42268
  */
42249
42269
  let parser = Parser.extend(acornClassFields, acornStaticClassFeatures);
42250
- async function createPluginContainer({ plugins, logger, root, build: { rollupOptions } }, watcher) {
42270
+ async function createPluginContainer({ plugins, logger, root, build: { rollupOptions } }, moduleGraph, watcher) {
42251
42271
  const isDebug = process.env.DEBUG;
42252
42272
  const seenResolves = {};
42253
42273
  const debugResolve = createDebugger('vite:resolve');
@@ -42258,7 +42278,6 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42258
42278
  onlyWhenFocused: 'vite:plugin'
42259
42279
  });
42260
42280
  // ---------------------------------------------------------------------------
42261
- const MODULES = new Map();
42262
42281
  const watchFiles = new Set();
42263
42282
  // get rollup version
42264
42283
  const rollupPkgPath = path$t.resolve(require.resolve('rollup'), '../../package.json');
@@ -42273,6 +42292,36 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42273
42292
  logger.warn(source.cyan(`[plugin:${plugin}] `) +
42274
42293
  source.yellow(`context method ${source.bold(`${method}()`)} is not supported in serve mode. This plugin is likely not vite-compatible.`));
42275
42294
  }
42295
+ // throw when an unsupported ModuleInfo property is accessed,
42296
+ // so that incompatible plugins fail in a non-cryptic way.
42297
+ const ModuleInfoProxy = {
42298
+ get(info, key) {
42299
+ if (key in info) {
42300
+ return info[key];
42301
+ }
42302
+ throw Error(`[vite] The "${key}" property of ModuleInfo is not supported.`);
42303
+ }
42304
+ };
42305
+ // same default value of "moduleInfo.meta" as in Rollup
42306
+ const EMPTY_OBJECT = Object.freeze({});
42307
+ function getModuleInfo(id) {
42308
+ const module = moduleGraph === null || moduleGraph === void 0 ? void 0 : moduleGraph.getModuleById(id);
42309
+ if (!module) {
42310
+ return null;
42311
+ }
42312
+ if (!module.info) {
42313
+ module.info = new Proxy({ id, meta: module.meta || EMPTY_OBJECT }, ModuleInfoProxy);
42314
+ }
42315
+ return module.info;
42316
+ }
42317
+ function updateModuleInfo(id, { meta }) {
42318
+ if (meta) {
42319
+ const moduleInfo = getModuleInfo(id);
42320
+ if (moduleInfo) {
42321
+ moduleInfo.meta = { ...moduleInfo.meta, ...meta };
42322
+ }
42323
+ }
42324
+ }
42276
42325
  // we should create a new context for each async hook pipeline so that the
42277
42326
  // active plugin in that pipeline can be tracked in a concurrency-safe manner.
42278
42327
  // using a class to make creating new contexts more efficient
@@ -42305,19 +42354,12 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42305
42354
  return out;
42306
42355
  }
42307
42356
  getModuleInfo(id) {
42308
- let mod = MODULES.get(id);
42309
- if (mod)
42310
- return mod.info;
42311
- mod = {
42312
- /** @type {import('rollup').ModuleInfo} */
42313
- // @ts-ignore-next
42314
- info: {}
42315
- };
42316
- MODULES.set(id, mod);
42317
- return mod.info;
42357
+ return getModuleInfo(id);
42318
42358
  }
42319
42359
  getModuleIds() {
42320
- return MODULES.keys();
42360
+ return moduleGraph
42361
+ ? moduleGraph.idToModuleMap.keys()
42362
+ : Array.prototype[Symbol.iterator]();
42321
42363
  }
42322
42364
  addWatchFile(id) {
42323
42365
  watchFiles.add(id);
@@ -42483,6 +42525,7 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42483
42525
  ...options
42484
42526
  };
42485
42527
  })(),
42528
+ getModuleInfo,
42486
42529
  async buildStart() {
42487
42530
  await Promise.all(plugins.map((plugin) => {
42488
42531
  if (plugin.buildStart) {
@@ -42547,6 +42590,9 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42547
42590
  ctx._activePlugin = plugin;
42548
42591
  const result = await plugin.load.call(ctx, id, { ssr });
42549
42592
  if (result != null) {
42593
+ if (isObject$3(result)) {
42594
+ updateModuleInfo(id, result);
42595
+ }
42550
42596
  return result;
42551
42597
  }
42552
42598
  }
@@ -42576,9 +42622,13 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42576
42622
  isDebug &&
42577
42623
  debugPluginTransform(timeFrom(start), plugin.name, prettifyUrl(id, root));
42578
42624
  if (isObject$3(result)) {
42579
- code = result.code || '';
42580
- if (result.map)
42581
- ctx.sourcemapChain.push(result.map);
42625
+ if (result.code !== undefined) {
42626
+ code = result.code;
42627
+ if (result.map) {
42628
+ ctx.sourcemapChain.push(result.map);
42629
+ }
42630
+ }
42631
+ updateModuleInfo(id, result);
42582
42632
  }
42583
42633
  else {
42584
42634
  code = result;
@@ -42603,6 +42653,7 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
42603
42653
 
42604
42654
  const debug$b = createDebugger('vite:deps');
42605
42655
  const htmlTypesRE = /\.(html|vue|svelte|astro)$/;
42656
+ const setupRE = /<script\s+setup/;
42606
42657
  // A simple regex to detect import sources. This is only used on
42607
42658
  // <script lang="ts"> blocks in vue (setup only) or svelte files, since
42608
42659
  // seemingly unused imports are dropped by esbuild when transpiling TS which
@@ -42692,6 +42743,7 @@ const commentRE = /<!--(.|[\r\n])*?-->/;
42692
42743
  const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
42693
42744
  const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
42694
42745
  const langRE = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
42746
+ const contextRE = /\bcontext\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
42695
42747
  function esbuildScanPlugin(config, container, depImports, missing, entries) {
42696
42748
  var _a, _b;
42697
42749
  const seen = new Map();
@@ -42718,6 +42770,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42718
42770
  return {
42719
42771
  name: 'vite:dep-scan',
42720
42772
  setup(build) {
42773
+ const moduleScripts = {};
42721
42774
  // external urls
42722
42775
  build.onResolve({ filter: externalRE }, ({ path }) => ({
42723
42776
  path,
@@ -42728,6 +42781,12 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42728
42781
  path,
42729
42782
  external: true
42730
42783
  }));
42784
+ build.onResolve({ filter: virtualModuleRE }, async ({ path, importer }) => {
42785
+ return {
42786
+ path,
42787
+ namespace: 'html'
42788
+ };
42789
+ });
42731
42790
  // html types: extract script contents -----------------------------------
42732
42791
  build.onResolve({ filter: htmlTypesRE }, async ({ path, importer }) => {
42733
42792
  return {
@@ -42735,6 +42794,9 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42735
42794
  namespace: 'html'
42736
42795
  };
42737
42796
  });
42797
+ build.onLoad({ filter: virtualModuleRE, namespace: 'html' }, async ({ path }) => {
42798
+ return moduleScripts[path];
42799
+ });
42738
42800
  // extract scripts inside HTML-like files and treat it as a js module
42739
42801
  build.onLoad({ filter: htmlTypesRE, namespace: 'html' }, async ({ path }) => {
42740
42802
  let raw = fs__default.readFileSync(path, 'utf-8');
@@ -42748,10 +42810,9 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42748
42810
  let match;
42749
42811
  while ((match = regex.exec(raw))) {
42750
42812
  const [, openTag, content] = match;
42751
- const srcMatch = openTag.match(srcRE);
42752
42813
  const typeMatch = openTag.match(typeRE);
42753
- const langMatch = openTag.match(langRE);
42754
42814
  const type = typeMatch && (typeMatch[1] || typeMatch[2] || typeMatch[3]);
42815
+ const langMatch = openTag.match(langRE);
42755
42816
  const lang = langMatch && (langMatch[1] || langMatch[2] || langMatch[3]);
42756
42817
  // skip type="application/ld+json" and other non-JS types
42757
42818
  if (type &&
@@ -42763,12 +42824,30 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42763
42824
  if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
42764
42825
  loader = lang;
42765
42826
  }
42827
+ const srcMatch = openTag.match(srcRE);
42766
42828
  if (srcMatch) {
42767
42829
  const src = srcMatch[1] || srcMatch[2] || srcMatch[3];
42768
42830
  js += `import ${JSON.stringify(src)}\n`;
42769
42831
  }
42770
42832
  else if (content.trim()) {
42771
- js += content + '\n';
42833
+ // There can be module scripts (`<script context="module">` in Svelte and `<script>` in Vue)
42834
+ // or local scripts (`<script>` in Svelte and `<script setup>` in Vue)
42835
+ // We need to handle these separately in case variable names are reused between them
42836
+ const contextMatch = openTag.match(contextRE);
42837
+ const context = contextMatch &&
42838
+ (contextMatch[1] || contextMatch[2] || contextMatch[3]);
42839
+ if ((path.endsWith('.vue') && setupRE.test(raw)) ||
42840
+ (path.endsWith('.svelte') && context !== 'module')) {
42841
+ const id = `virtual-module:${path}`;
42842
+ moduleScripts[id] = {
42843
+ loader,
42844
+ contents: content
42845
+ };
42846
+ js += `import '${id}';\n`;
42847
+ }
42848
+ else {
42849
+ js += content + '\n';
42850
+ }
42772
42851
  }
42773
42852
  }
42774
42853
  // empty singleline & multiline comments to avoid matching comments
@@ -42777,7 +42856,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
42777
42856
  .replace(singlelineCommentsRE, '');
42778
42857
  if (loader.startsWith('ts') &&
42779
42858
  (path.endsWith('.svelte') ||
42780
- (path.endsWith('.vue') && /<script\s+setup/.test(raw)))) {
42859
+ (path.endsWith('.vue') && setupRE.test(raw)))) {
42781
42860
  // when using TS + (Vue + <script setup>) or Svelte, imports may seem
42782
42861
  // unused to esbuild and dropped in the build output, which prevents
42783
42862
  // esbuild from crawling further.
@@ -43043,7 +43122,8 @@ function loadFallbackPlugin() {
43043
43122
  };
43044
43123
  }
43045
43124
 
43046
- function resolveBuildOptions(raw) {
43125
+ function resolveBuildOptions(root, raw) {
43126
+ var _a;
43047
43127
  const resolved = {
43048
43128
  target: 'modules',
43049
43129
  polyfillModulePreload: true,
@@ -43078,6 +43158,30 @@ function resolveBuildOptions(raw) {
43078
43158
  ...raw === null || raw === void 0 ? void 0 : raw.dynamicImportVarsOptions
43079
43159
  }
43080
43160
  };
43161
+ const resolve = (p) => p.startsWith('\0') ? p : path__default.resolve(root, p);
43162
+ resolved.outDir = resolve(resolved.outDir);
43163
+ let input;
43164
+ if ((_a = raw === null || raw === void 0 ? void 0 : raw.rollupOptions) === null || _a === void 0 ? void 0 : _a.input) {
43165
+ input = Array.isArray(raw.rollupOptions.input)
43166
+ ? raw.rollupOptions.input.map(input => resolve(input))
43167
+ : typeof raw.rollupOptions.input === 'object'
43168
+ ? Object.assign(
43169
+ // @ts-ignore
43170
+ ...Object.keys(raw.rollupOptions.input).map(key => ({ [key]: resolve(raw.rollupOptions.input[key]) })))
43171
+ : resolve(raw.rollupOptions.input);
43172
+ }
43173
+ else {
43174
+ input = resolve((raw === null || raw === void 0 ? void 0 : raw.lib)
43175
+ ? raw.lib.entry
43176
+ : typeof (raw === null || raw === void 0 ? void 0 : raw.ssr) === 'string'
43177
+ ? raw.ssr
43178
+ : 'index.html');
43179
+ }
43180
+ if (!!(raw === null || raw === void 0 ? void 0 : raw.ssr) && typeof input === 'string' && input.endsWith('.html')) {
43181
+ throw new Error(`rollupOptions.input should not be an html file when building for SSR. ` +
43182
+ `Please specify a dedicated SSR entry.`);
43183
+ }
43184
+ resolved.rollupOptions.input = input;
43081
43185
  // handle special build targets
43082
43186
  if (resolved.target === 'modules') {
43083
43187
  // Support browserslist
@@ -43156,27 +43260,18 @@ async function build(inlineConfig = {}) {
43156
43260
  }
43157
43261
  }
43158
43262
  async function doBuild(inlineConfig = {}) {
43159
- var _a, _b, _c, _d;
43263
+ var _a, _b, _c;
43160
43264
  const config = await resolveConfig(inlineConfig, 'build', 'production');
43161
43265
  const options = config.build;
43266
+ const input = options.rollupOptions.input;
43267
+ const outDir = options.outDir;
43162
43268
  const ssr = !!options.ssr;
43163
43269
  const libOptions = options.lib;
43164
43270
  config.logger.info(source.cyan(`vite v${require('vite/package.json').version} ${source.green(`building ${ssr ? `SSR bundle ` : ``}for ${config.mode}...`)}`));
43165
- const resolve = (p) => path__default.resolve(config.root, p);
43166
- const input = libOptions
43167
- ? resolve(libOptions.entry)
43168
- : typeof options.ssr === 'string'
43169
- ? resolve(options.ssr)
43170
- : ((_a = options.rollupOptions) === null || _a === void 0 ? void 0 : _a.input) || resolve('index.html');
43171
- if (ssr && typeof input === 'string' && input.endsWith('.html')) {
43172
- throw new Error(`rollupOptions.input should not be an html file when building for SSR. ` +
43173
- `Please specify a dedicated SSR entry.`);
43174
- }
43175
- const outDir = resolve(options.outDir);
43176
43271
  // inject ssr arg to plugin load/transform hooks
43177
43272
  const plugins = (ssr ? config.plugins.map((p) => injectSsrFlagToHooks(p)) : config.plugins);
43178
43273
  // inject ssrExternal if present
43179
- const userExternal = (_b = options.rollupOptions) === null || _b === void 0 ? void 0 : _b.external;
43274
+ const userExternal = (_a = options.rollupOptions) === null || _a === void 0 ? void 0 : _a.external;
43180
43275
  let external = userExternal;
43181
43276
  if (ssr) {
43182
43277
  // see if we have cached deps data available
@@ -43197,7 +43292,6 @@ async function doBuild(inlineConfig = {}) {
43197
43292
  }
43198
43293
  const rollup = require('rollup');
43199
43294
  const rollupOptions = {
43200
- input,
43201
43295
  context: 'globalThis',
43202
43296
  preserveEntrySignatures: ssr
43203
43297
  ? 'allow-extension'
@@ -43254,7 +43348,7 @@ async function doBuild(inlineConfig = {}) {
43254
43348
  };
43255
43349
  };
43256
43350
  // resolve lib mode outputs
43257
- const outputs = resolveBuildOutputs((_c = options.rollupOptions) === null || _c === void 0 ? void 0 : _c.output, libOptions, config.logger);
43351
+ const outputs = resolveBuildOutputs((_b = options.rollupOptions) === null || _b === void 0 ? void 0 : _b.output, libOptions, config.logger);
43258
43352
  // watch file changes with rollup
43259
43353
  if (config.build.watch) {
43260
43354
  config.logger.info(source.cyanBright(`\nwatching for file changes...`));
@@ -43277,7 +43371,7 @@ async function doBuild(inlineConfig = {}) {
43277
43371
  ignored: [
43278
43372
  '**/node_modules/**',
43279
43373
  '**/.git/**',
43280
- ...(((_d = watcherOptions === null || watcherOptions === void 0 ? void 0 : watcherOptions.chokidar) === null || _d === void 0 ? void 0 : _d.ignored) || [])
43374
+ ...(((_c = watcherOptions === null || watcherOptions === void 0 ? void 0 : watcherOptions.chokidar) === null || _c === void 0 ? void 0 : _c.ignored) || [])
43281
43375
  ],
43282
43376
  ignoreInitial: true,
43283
43377
  ignorePermissionErrors: true,
@@ -49231,7 +49325,7 @@ function readFileIfExists(value) {
49231
49325
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49232
49326
  */
49233
49327
  async function createCertificate() {
49234
- const { generate } = await Promise.resolve().then(function () { return require('./dep-777faa4b.js'); }).then(function (n) { return n.index; });
49328
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-90234190.js'); }).then(function (n) { return n.index; });
49235
49329
  const pems = generate(null, {
49236
49330
  algorithm: 'sha256',
49237
49331
  days: 30,
@@ -56542,6 +56636,10 @@ const isDebug$3 = !!process.env.DEBUG;
56542
56636
  const debug$4 = createDebugger('vite:sourcemap', {
56543
56637
  onlyWhenFocused: true
56544
56638
  });
56639
+ // Virtual modules should be prefixed with a null byte to avoid a
56640
+ // false positive "missing source" warning. We also check for certain
56641
+ // prefixes used for special handling in esbuildDepPlugin.
56642
+ const virtualSourceRE = /^(\0|dep:|browser-external:)/;
56545
56643
  async function injectSourcesContent(map, file, logger) {
56546
56644
  let sourceRoot;
56547
56645
  try {
@@ -56551,7 +56649,7 @@ async function injectSourcesContent(map, file, logger) {
56551
56649
  catch { }
56552
56650
  const missingSources = [];
56553
56651
  map.sourcesContent = await Promise.all(map.sources.map((sourcePath) => {
56554
- if (sourcePath) {
56652
+ if (sourcePath && !virtualSourceRE.test(sourcePath)) {
56555
56653
  sourcePath = decodeURI(sourcePath);
56556
56654
  if (sourceRoot) {
56557
56655
  sourcePath = path__default.resolve(sourceRoot, sourcePath);
@@ -57011,7 +57109,7 @@ function isFileServingAllowed(url, server) {
57011
57109
  return true;
57012
57110
  const cleanedUrl = cleanUrl(url);
57013
57111
  const file = ensureLeadingSlash(normalizePath$4(cleanedUrl));
57014
- if (server.config.server.fs.deny.some((i) => minimatch_1(file, i, _matchOptions)))
57112
+ if (server.config.server.fs.deny.some((i) => micromatch_1.isMatch(file, i, _matchOptions)))
57015
57113
  return false;
57016
57114
  if (server.moduleGraph.safeModulesPath.has(file))
57017
57115
  return true;
@@ -57482,13 +57580,13 @@ function invalidateSSRModule(mod, seen) {
57482
57580
  mod.importers.forEach((importer) => invalidateSSRModule(importer, seen));
57483
57581
  }
57484
57582
  class ModuleGraph {
57485
- constructor(container) {
57583
+ constructor(resolveId) {
57584
+ this.resolveId = resolveId;
57486
57585
  this.urlToModuleMap = new Map();
57487
57586
  this.idToModuleMap = new Map();
57488
57587
  // a single file may corresponds to multiple modules with different queries
57489
57588
  this.fileToModulesMap = new Map();
57490
57589
  this.safeModulesPath = new Set();
57491
- this.container = container;
57492
57590
  }
57493
57591
  async getModuleByUrl(rawUrl) {
57494
57592
  const [url] = await this.resolveUrl(rawUrl);
@@ -57510,6 +57608,7 @@ class ModuleGraph {
57510
57608
  }
57511
57609
  }
57512
57610
  invalidateModule(mod, seen = new Set()) {
57611
+ mod.info = undefined;
57513
57612
  mod.transformResult = null;
57514
57613
  mod.ssrTransformResult = null;
57515
57614
  invalidateSSRModule(mod, seen);
@@ -57558,10 +57657,12 @@ class ModuleGraph {
57558
57657
  return noLongerImported;
57559
57658
  }
57560
57659
  async ensureEntryFromUrl(rawUrl) {
57561
- const [url, resolvedId] = await this.resolveUrl(rawUrl);
57660
+ const [url, resolvedId, meta] = await this.resolveUrl(rawUrl);
57562
57661
  let mod = this.urlToModuleMap.get(url);
57563
57662
  if (!mod) {
57564
57663
  mod = new ModuleNode(url);
57664
+ if (meta)
57665
+ mod.meta = meta;
57565
57666
  this.urlToModuleMap.set(url, mod);
57566
57667
  mod.id = resolvedId;
57567
57668
  this.idToModuleMap.set(resolvedId, mod);
@@ -57602,15 +57703,15 @@ class ModuleGraph {
57602
57703
  // 2. resolve its extension so that urls with or without extension all map to
57603
57704
  // the same module
57604
57705
  async resolveUrl(url) {
57605
- var _a;
57606
57706
  url = removeImportQuery(removeTimestampQuery(url));
57607
- const resolvedId = ((_a = (await this.container.resolveId(url))) === null || _a === void 0 ? void 0 : _a.id) || url;
57707
+ const resolved = await this.resolveId(url);
57708
+ const resolvedId = (resolved === null || resolved === void 0 ? void 0 : resolved.id) || url;
57608
57709
  const ext = path$t.extname(cleanUrl(resolvedId));
57609
57710
  const { pathname, search, hash } = require$$0$7.parse(url);
57610
57711
  if (ext && !pathname.endsWith(ext)) {
57611
57712
  url = pathname + ext + (search || '') + (hash || '');
57612
57713
  }
57613
- return [url, resolvedId];
57714
+ return [url, resolvedId, resolved === null || resolved === void 0 ? void 0 : resolved.meta];
57614
57715
  }
57615
57716
  }
57616
57717
 
@@ -57624,7 +57725,8 @@ async function handleHMRUpdate(file, server) {
57624
57725
  const shortFile = getShortName(file, config.root);
57625
57726
  const isConfig = file === config.configFile;
57626
57727
  const isConfigDependency = config.configFileDependencies.some((name) => file === path__default.resolve(name));
57627
- const isEnv = config.inlineConfig.envFile !== false && file.endsWith('.env');
57728
+ const isEnv = config.inlineConfig.envFile !== false &&
57729
+ (file === '.env' || file.startsWith('.env.'));
57628
57730
  if (isConfig || isConfigDependency || isEnv) {
57629
57731
  // auto restart server
57630
57732
  debugHmr(`[config change] ${source.dim(shortFile)}`);
@@ -57732,7 +57834,8 @@ async function handleFileAddUnlink(file, server, isUnlink = false) {
57732
57834
  for (const i in server._globImporters) {
57733
57835
  const { module, importGlobs } = server._globImporters[i];
57734
57836
  for (const { base, pattern } of importGlobs) {
57735
- if (minimatch_1(file, pattern) || minimatch_1(path__default.relative(base, file), pattern)) {
57837
+ if (micromatch_1.isMatch(file, pattern) ||
57838
+ micromatch_1.isMatch(path__default.relative(base, file), pattern)) {
57736
57839
  modules.push(module);
57737
57840
  // We use `onFileChange` to invalidate `module.file` so that subsequent `ssrLoadModule()`
57738
57841
  // calls get fresh glob import results with(out) the newly added(/removed) `file`.
@@ -66849,6 +66952,58 @@ function rebindErrorStacktrace(e, stacktrace) {
66849
66952
  }
66850
66953
  }
66851
66954
 
66955
+ /**
66956
+ * This plugin hooks into Node's module resolution algorithm at runtime,
66957
+ * so that SSR builds can benefit from `resolve.dedupe` like they do
66958
+ * in development.
66959
+ */
66960
+ function ssrRequireHookPlugin(config) {
66961
+ var _a;
66962
+ if (config.command !== 'build' || !((_a = config.resolve.dedupe) === null || _a === void 0 ? void 0 : _a.length)) {
66963
+ return null;
66964
+ }
66965
+ return {
66966
+ name: 'vite:ssr-require-hook',
66967
+ transform(code, id) {
66968
+ const moduleInfo = this.getModuleInfo(id);
66969
+ if (moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.isEntry) {
66970
+ const s = new MagicString(code);
66971
+ s.prepend(`;(${dedupeRequire.toString()})(${JSON.stringify(config.resolve.dedupe)});\n`);
66972
+ return {
66973
+ code: s.toString(),
66974
+ map: s.generateMap({
66975
+ source: id
66976
+ })
66977
+ };
66978
+ }
66979
+ }
66980
+ };
66981
+ }
66982
+ /** Respect the `resolve.dedupe` option in production SSR. */
66983
+ function dedupeRequire(dedupe) {
66984
+ const Module = require('module');
66985
+ const resolveFilename = Module._resolveFilename;
66986
+ Module._resolveFilename = function (request, parent, isMain, options) {
66987
+ if (request[0] !== '.' && request[0] !== '/') {
66988
+ const parts = request.split('/');
66989
+ const pkgName = parts[0][0] === '@' ? parts[0] + '/' + parts[1] : parts[0];
66990
+ if (dedupe.includes(pkgName)) {
66991
+ // Use this module as the parent.
66992
+ parent = module;
66993
+ }
66994
+ }
66995
+ return resolveFilename(request, parent, isMain, options);
66996
+ };
66997
+ }
66998
+ function hookNodeResolve(getResolver) {
66999
+ const Module = require('module');
67000
+ const prevResolver = Module._resolveFilename;
67001
+ Module._resolveFilename = getResolver(prevResolver);
67002
+ return () => {
67003
+ Module._resolveFilename = prevResolver;
67004
+ };
67005
+ }
67006
+
66852
67007
  const pendingModules = new Map();
66853
67008
  const pendingImports = new Map();
66854
67009
  async function ssrLoadModule(url, server, context = { global }, urlStack = []) {
@@ -66897,13 +67052,26 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
66897
67052
  };
66898
67053
  urlStack = urlStack.concat(url);
66899
67054
  const isCircular = (url) => urlStack.includes(url);
67055
+ const { isProduction, resolve: { dedupe }, root } = server.config;
67056
+ const resolveOptions = {
67057
+ conditions: ['node'],
67058
+ dedupe,
67059
+ // Prefer CommonJS modules.
67060
+ extensions: ['.js', '.mjs', '.ts', '.jsx', '.tsx', '.json'],
67061
+ isBuild: true,
67062
+ isProduction,
67063
+ // Disable "module" condition.
67064
+ isRequire: true,
67065
+ mainFields: ['main'],
67066
+ root
67067
+ };
66900
67068
  // Since dynamic imports can happen in parallel, we need to
66901
67069
  // account for multiple pending deps and duplicate imports.
66902
67070
  const pendingDeps = [];
66903
67071
  const ssrImport = async (dep) => {
66904
67072
  var _a, _b;
66905
67073
  if (dep[0] !== '.' && dep[0] !== '/') {
66906
- return nodeImport(dep, mod.file, server.config);
67074
+ return nodeImport(dep, mod.file, resolveOptions);
66907
67075
  }
66908
67076
  dep = unwrapId$1(dep);
66909
67077
  if (!isCircular(dep) && !((_a = pendingImports.get(dep)) === null || _a === void 0 ? void 0 : _a.some(isCircular))) {
@@ -66963,20 +67131,40 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
66963
67131
  return Object.freeze(ssrModule);
66964
67132
  }
66965
67133
  // In node@12+ we can use dynamic import to load CJS and ESM
66966
- async function nodeImport(id, importer, config) {
67134
+ async function nodeImport(id, importer, resolveOptions) {
67135
+ // Node's module resolution is hi-jacked so Vite can ensure the
67136
+ // configured `resolve.dedupe` and `mode` options are respected.
67137
+ const viteResolve = (id, importer) => {
67138
+ const resolved = tryNodeResolve(id, importer, resolveOptions, false);
67139
+ if (!resolved) {
67140
+ const err = new Error(`Cannot find module '${id}' imported from '${importer}'`);
67141
+ err.code = 'ERR_MODULE_NOT_FOUND';
67142
+ throw err;
67143
+ }
67144
+ return resolved.id;
67145
+ };
67146
+ // When an ESM module imports an ESM dependency, this hook is *not* used.
67147
+ const unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => id[0] === '.' || isBuiltin(id)
67148
+ ? nodeResolve(id, parent, isMain, options)
67149
+ : viteResolve(id, parent.id));
66967
67150
  let url;
66968
67151
  // `resolve` doesn't handle `node:` builtins, so handle them directly
66969
67152
  if (id.startsWith('node:') || isBuiltin(id)) {
66970
67153
  url = id;
66971
67154
  }
66972
67155
  else {
66973
- url = resolve(id, importer, config.root, !!config.resolve.preserveSymlinks);
67156
+ url = viteResolve(id, importer);
66974
67157
  if (usingDynamicImport) {
66975
67158
  url = require$$0$7.pathToFileURL(url).toString();
66976
67159
  }
66977
67160
  }
66978
- const mod = await dynamicImport(url);
66979
- return proxyESM(id, mod);
67161
+ try {
67162
+ const mod = await dynamicImport(url);
67163
+ return proxyESM(id, mod);
67164
+ }
67165
+ finally {
67166
+ unhookNodeResolve();
67167
+ }
66980
67168
  }
66981
67169
  // rollup-style default import interop for cjs
66982
67170
  function proxyESM(id, mod) {
@@ -66987,26 +67175,13 @@ function proxyESM(id, mod) {
66987
67175
  : mod;
66988
67176
  return new Proxy(mod, {
66989
67177
  get(mod, prop) {
67178
+ var _a;
66990
67179
  if (prop === 'default')
66991
67180
  return defaultExport;
66992
- return mod[prop];
67181
+ return (_a = mod[prop]) !== null && _a !== void 0 ? _a : defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport[prop];
66993
67182
  }
66994
67183
  });
66995
67184
  }
66996
- const resolveCache = new Map();
66997
- function resolve(id, importer, root, preserveSymlinks) {
66998
- const key = id + importer + root;
66999
- const cached = resolveCache.get(key);
67000
- if (cached) {
67001
- return cached;
67002
- }
67003
- const resolveDir = importer && fs__default.existsSync(cleanUrl(importer))
67004
- ? path__default.dirname(importer)
67005
- : root;
67006
- const resolved = resolveFrom$3(id, resolveDir, preserveSymlinks, true);
67007
- resolveCache.set(key, resolved);
67008
- return resolved;
67009
- }
67010
67185
 
67011
67186
  /**
67012
67187
  * The amount to wait for requests to register newly found dependencies before triggering
@@ -67158,9 +67333,8 @@ async function createServer(inlineConfig = {}) {
67158
67333
  disableGlobbing: true,
67159
67334
  ...watchOptions
67160
67335
  });
67161
- const plugins = config.plugins;
67162
- const container = await createPluginContainer(config, watcher);
67163
- const moduleGraph = new ModuleGraph(container);
67336
+ const moduleGraph = new ModuleGraph((url) => container.resolveId(url));
67337
+ const container = await createPluginContainer(config, moduleGraph, watcher);
67164
67338
  const closeHttpServer = createServerCloseFn(httpServer);
67165
67339
  // eslint-disable-next-line prefer-const
67166
67340
  let exitProcess;
@@ -67267,7 +67441,7 @@ async function createServer(inlineConfig = {}) {
67267
67441
  }
67268
67442
  // apply server configuration hooks from plugins
67269
67443
  const postHooks = [];
67270
- for (const plugin of plugins) {
67444
+ for (const plugin of config.plugins) {
67271
67445
  if (plugin.configureServer) {
67272
67446
  postHooks.push(await plugin.configureServer(server));
67273
67447
  }
@@ -81154,6 +81328,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
81154
81328
  ssrConfig: config.ssr,
81155
81329
  asSrc: true
81156
81330
  }),
81331
+ config.build.ssr ? ssrRequireHookPlugin(config) : null,
81157
81332
  htmlInlineScriptProxyPlugin(config),
81158
81333
  cssPlugin(config),
81159
81334
  config.esbuild !== false ? esbuildPlugin(config.esbuild) : null,
@@ -81444,7 +81619,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
81444
81619
  }
81445
81620
  // resolve public base url
81446
81621
  const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger);
81447
- const resolvedBuildOptions = resolveBuildOptions(config.build);
81622
+ const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build);
81448
81623
  // resolve cache directory
81449
81624
  const pkgPath = lookupFile(resolvedRoot, [`package.json`], true /* pathOnly */);
81450
81625
  const cacheDir = config.cacheDir
@@ -81993,4 +82168,4 @@ exports.send = send$1;
81993
82168
  exports.sortUserPlugins = sortUserPlugins;
81994
82169
  exports.source = source;
81995
82170
  exports.transformWithEsbuild = transformWithEsbuild;
81996
- //# sourceMappingURL=dep-5243d0d3.js.map
82171
+ //# sourceMappingURL=dep-6cab8e8a.js.map