vite 2.9.0-beta.0 → 2.9.0-beta.3

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,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./dep-429629d5.js');
3
+ var index = require('./dep-19d0f55f.js');
4
4
  var require$$1 = require('crypto');
5
5
  require('fs');
6
6
  require('path');
@@ -4464,7 +4464,7 @@ function checkPublicFile(url, { publicDir }) {
4464
4464
  return;
4465
4465
  }
4466
4466
  }
4467
- function fileToUrl(id, config, ctx) {
4467
+ async function fileToUrl(id, config, ctx) {
4468
4468
  if (config.command === 'serve') {
4469
4469
  return fileToDevUrl(id, config);
4470
4470
  }
@@ -18935,7 +18935,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
18935
18935
  replacer: urlReplacer
18936
18936
  }));
18937
18937
  if (isModule) {
18938
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-229a03bb.js'); }).then(function (n) { return n.index; })).default({
18938
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-ca2a26a1.js'); }).then(function (n) { return n.index; })).default({
18939
18939
  ...modulesOptions,
18940
18940
  getJSON(cssFileName, _modules, outputFileName) {
18941
18941
  modules = _modules;
@@ -21393,7 +21393,7 @@ const assetAttrsConfig = {
21393
21393
  const isAsyncScriptMap = new WeakMap();
21394
21394
  async function traverseHtml(html, filePath, visitor) {
21395
21395
  // lazy load compiler
21396
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-026034b4.js'); }).then(function (n) { return n.compilerDom_cjs; });
21396
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-f14ba655.js'); }).then(function (n) { return n.compilerDom_cjs; });
21397
21397
  // @vue/compiler-core doesn't like lowercase doctypes
21398
21398
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21399
21399
  try {
@@ -35633,7 +35633,8 @@ const isDebugEnabled = _debug('vite:deps').enabled;
35633
35633
  async function optimizeDeps(config, force = config.server.force, asCommand = false, newDeps, // missing imports encountered after server has started
35634
35634
  ssr) {
35635
35635
  const { metadata, run } = await createOptimizeDepsRun(config, force, asCommand, null, newDeps, ssr);
35636
- await run();
35636
+ const result = await run();
35637
+ result.commit();
35637
35638
  return metadata;
35638
35639
  }
35639
35640
  /**
@@ -35661,8 +35662,7 @@ ssr) {
35661
35662
  hash: mainHash,
35662
35663
  browserHash: mainHash,
35663
35664
  optimized: {},
35664
- discovered: {},
35665
- processing: processing.promise
35665
+ discovered: {}
35666
35666
  };
35667
35667
  if (!force) {
35668
35668
  let prevData;
@@ -35674,9 +35674,20 @@ ssr) {
35674
35674
  // hash is consistent, no need to re-bundle
35675
35675
  if (prevData && prevData.hash === metadata.hash) {
35676
35676
  log('Hash is consistent. Skipping. Use --force to override.');
35677
+ // Nothing to commit or cancel as we are using the cache, we only
35678
+ // need to resolve the processing promise so requests can move on
35679
+ const resolve = () => {
35680
+ processing.resolve();
35681
+ };
35677
35682
  return {
35678
35683
  metadata: prevData,
35679
- run: () => (processing.resolve(), processing.promise)
35684
+ run: async () => {
35685
+ return {
35686
+ alteredFiles: false,
35687
+ commit: resolve,
35688
+ cancel: resolve
35689
+ };
35690
+ }
35680
35691
  };
35681
35692
  }
35682
35693
  }
@@ -35692,6 +35703,7 @@ ssr) {
35692
35703
  // a hint for Node.js
35693
35704
  // all files in the cache directory should be recognized as ES modules
35694
35705
  writeFile(path__default.resolve(processingCacheDir, 'package.json'), JSON.stringify({ type: 'module' }));
35706
+ let newBrowserHash;
35695
35707
  let deps;
35696
35708
  if (!newDeps) {
35697
35709
  // Initial optimizeDeps at server start. Perform a fast scan using esbuild to
@@ -35713,7 +35725,7 @@ ssr) {
35713
35725
  throw e;
35714
35726
  }
35715
35727
  // update browser hash
35716
- metadata.browserHash = getOptimizedBrowserHash(metadata.hash, deps);
35728
+ newBrowserHash = metadata.browserHash = getOptimizedBrowserHash(metadata.hash, deps);
35717
35729
  // We generate the mapping of dependency ids to their cache file location
35718
35730
  // before processing the dependencies with esbuild. This allow us to continue
35719
35731
  // processing files in the importAnalysis and resolve plugins
@@ -35722,7 +35734,7 @@ ssr) {
35722
35734
  metadata.optimized[id] = {
35723
35735
  file: getOptimizedDepPath(id, config),
35724
35736
  src: entry,
35725
- browserHash: metadata.browserHash,
35737
+ browserHash: newBrowserHash,
35726
35738
  processing: processing.promise
35727
35739
  };
35728
35740
  }
@@ -35731,27 +35743,30 @@ ssr) {
35731
35743
  // Missing dependencies were found at run-time, optimizeDeps called while the
35732
35744
  // server is running
35733
35745
  deps = depsFromOptimizedDepInfo(newDeps);
35734
- // Clone optimized info objects, fileHash, browserHash may be changed for them
35735
- for (const o of Object.keys(newDeps)) {
35736
- metadata.optimized[o] = { ...newDeps[o] };
35737
- }
35738
- // update global browser hash, but keep newDeps individual hashs until we know
35746
+ metadata.optimized = newDeps;
35747
+ // For reruns keep current global browser hash and newDeps individual hashes until we know
35739
35748
  // if files are stable so we can avoid a full page reload
35740
- metadata.browserHash = getOptimizedBrowserHash(metadata.hash, deps);
35749
+ metadata.browserHash = currentData.browserHash;
35750
+ newBrowserHash = getOptimizedBrowserHash(metadata.hash, deps);
35741
35751
  }
35742
35752
  return { metadata, run: prebundleDeps };
35743
35753
  async function prebundleDeps() {
35744
35754
  // We prebundle dependencies with esbuild and cache them, but there is no need
35745
35755
  // to wait here. Code that needs to access the cached deps needs to await
35746
- // the optimizeDepsMetadata.processing promise
35756
+ // the optimizeDepInfo.processing promise for each dep
35747
35757
  var _a, _b, _c, _d;
35748
35758
  const qualifiedIds = Object.keys(deps);
35749
35759
  if (!qualifiedIds.length) {
35750
- // Write metadata file, delete `deps` folder and rename the `processing` folder to `deps`
35751
- commitProcessingDepsCacheSync();
35752
- log(`No dependencies to bundle. Skipping.\n\n\n`);
35753
- processing.resolve();
35754
- return;
35760
+ return {
35761
+ alteredFiles: false,
35762
+ commit() {
35763
+ // Write metadata file, delete `deps` folder and rename the `processing` folder to `deps`
35764
+ commitProcessingDepsCacheSync();
35765
+ log(`No dependencies to bundle. Skipping.\n\n\n`);
35766
+ processing.resolve();
35767
+ },
35768
+ cancel
35769
+ };
35755
35770
  }
35756
35771
  let depsString;
35757
35772
  if (isDebugEnabled) {
@@ -35893,27 +35908,40 @@ ssr) {
35893
35908
  // New deps that ended up with a different hash replaced while doing analysis import are going to
35894
35909
  // return a not found so the browser doesn't cache them. And will properly get loaded after the reload
35895
35910
  for (const id in deps) {
35896
- metadata.optimized[id].browserHash = metadata.browserHash;
35911
+ metadata.optimized[id].browserHash = newBrowserHash;
35897
35912
  }
35913
+ metadata.browserHash = newBrowserHash;
35898
35914
  }
35899
- // Write metadata file, delete `deps` folder and rename the new `processing` folder to `deps` in sync
35900
- commitProcessingDepsCacheSync();
35901
35915
  debug$d(`deps bundled in ${(perf_hooks.performance.now() - start).toFixed(2)}ms`);
35902
- processing.resolve({ alteredFiles });
35903
- return processing.promise;
35916
+ return {
35917
+ alteredFiles,
35918
+ commit() {
35919
+ // Write metadata file, delete `deps` folder and rename the new `processing` folder to `deps` in sync
35920
+ commitProcessingDepsCacheSync();
35921
+ processing.resolve();
35922
+ },
35923
+ cancel
35924
+ };
35904
35925
  }
35905
35926
  function commitProcessingDepsCacheSync() {
35906
- var _a;
35907
35927
  // Rewire the file paths from the temporal processing dir to the final deps cache dir
35908
35928
  const dataPath = path__default.join(processingCacheDir, '_metadata.json');
35909
- writeFile(dataPath, stringifyOptimizedDepsMetadata(metadata));
35929
+ writeFile(dataPath, stringifyOptimizedDepsMetadata(metadata, depsCacheDir));
35910
35930
  // Processing is done, we can now replace the depsCacheDir with processingCacheDir
35911
- if (fs__default.existsSync(depsCacheDir)) {
35912
- const rmSync = (_a = fs__default.rmSync) !== null && _a !== void 0 ? _a : fs__default.rmdirSync; // TODO: Remove after support for Node 12 is dropped
35913
- rmSync(depsCacheDir, { recursive: true });
35914
- }
35931
+ removeDirSync(depsCacheDir);
35915
35932
  fs__default.renameSync(processingCacheDir, depsCacheDir);
35916
35933
  }
35934
+ function cancel() {
35935
+ removeDirSync(processingCacheDir);
35936
+ processing.resolve();
35937
+ }
35938
+ }
35939
+ function removeDirSync(dir) {
35940
+ var _a;
35941
+ if (fs__default.existsSync(dir)) {
35942
+ const rmSync = (_a = fs__default.rmSync) !== null && _a !== void 0 ? _a : fs__default.rmdirSync; // TODO: Remove after support for Node 12 is dropped
35943
+ rmSync(dir, { recursive: true });
35944
+ }
35917
35945
  }
35918
35946
  async function findKnownImports(config) {
35919
35947
  const deps = (await scanImports(config)).deps;
@@ -35991,16 +36019,27 @@ function createIsOptimizedDepUrl(config) {
35991
36019
  };
35992
36020
  }
35993
36021
  function parseOptimizedDepsMetadata(jsonMetadata, depsCacheDir, processing) {
35994
- const metadata = JSON.parse(jsonMetadata);
36022
+ const metadata = JSON.parse(jsonMetadata, (key, value) => {
36023
+ // Paths can be absolute or relative to the deps cache dir where
36024
+ // the _metadata.json is located
36025
+ if (key === 'file' || key === 'src') {
36026
+ return normalizePath$4(path__default.resolve(depsCacheDir, value));
36027
+ }
36028
+ return value;
36029
+ });
35995
36030
  for (const o of Object.keys(metadata.optimized)) {
35996
36031
  metadata.optimized[o].processing = processing;
35997
36032
  }
35998
- return { ...metadata, discovered: {}, processing };
36033
+ return { ...metadata, discovered: {} };
35999
36034
  }
36000
- function stringifyOptimizedDepsMetadata(metadata) {
36035
+ function stringifyOptimizedDepsMetadata(metadata, depsCacheDir) {
36001
36036
  return JSON.stringify(metadata, (key, value) => {
36002
- if (key === 'processing' || key === 'discovered')
36037
+ if (key === 'processing' || key === 'discovered') {
36003
36038
  return;
36039
+ }
36040
+ if (key === 'file' || key === 'src') {
36041
+ return normalizePath$4(path__default.relative(depsCacheDir, value));
36042
+ }
36004
36043
  return value;
36005
36044
  }, 2);
36006
36045
  }
@@ -36068,6 +36107,26 @@ function getDepHash(root, config) {
36068
36107
  });
36069
36108
  return require$$1$1.createHash('sha256').update(content).digest('hex').substring(0, 8);
36070
36109
  }
36110
+ function optimizeDepInfoFromFile(metadata, file) {
36111
+ return (findFileInfo(metadata.optimized, file) ||
36112
+ findFileInfo(metadata.discovered, file));
36113
+ }
36114
+ function findFileInfo(dependenciesInfo, file) {
36115
+ for (const o of Object.keys(dependenciesInfo)) {
36116
+ const info = dependenciesInfo[o];
36117
+ if (info.file === file) {
36118
+ return info;
36119
+ }
36120
+ }
36121
+ }
36122
+ async function optimizedDepNeedsInterop(metadata, file) {
36123
+ const depInfo = optimizeDepInfoFromFile(metadata, file);
36124
+ if (!depInfo)
36125
+ return undefined;
36126
+ // Wait until the dependency has been pre-bundled
36127
+ await depInfo.processing;
36128
+ return depInfo === null || depInfo === void 0 ? void 0 : depInfo.needsInterop;
36129
+ }
36071
36130
 
36072
36131
  var index$1 = {
36073
36132
  __proto__: null,
@@ -36081,7 +36140,9 @@ var index$1 = {
36081
36140
  getDepsCacheDir: getDepsCacheDir,
36082
36141
  getProcessingDepsCacheDir: getProcessingDepsCacheDir,
36083
36142
  isOptimizedDepFile: isOptimizedDepFile,
36084
- createIsOptimizedDepUrl: createIsOptimizedDepUrl
36143
+ createIsOptimizedDepUrl: createIsOptimizedDepUrl,
36144
+ optimizeDepInfoFromFile: optimizeDepInfoFromFile,
36145
+ optimizedDepNeedsInterop: optimizedDepNeedsInterop
36085
36146
  };
36086
36147
 
36087
36148
  /**
@@ -36679,7 +36740,7 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
36679
36740
  // can cache it without re-validation, but only do so for known js types.
36680
36741
  // otherwise we may introduce duplicated modules for externalized files
36681
36742
  // from pre-bundled deps.
36682
- const versionHash = (_b = server._optimizeDepsMetadata) === null || _b === void 0 ? void 0 : _b.hash;
36743
+ const versionHash = (_b = server._optimizeDepsMetadata) === null || _b === void 0 ? void 0 : _b.browserHash;
36683
36744
  if (versionHash && isJsType) {
36684
36745
  resolved = injectQuery(resolved, `v=${versionHash}`);
36685
36746
  }
@@ -36934,12 +36995,24 @@ function getRealPath(resolved, preserveSymlinks) {
36934
36995
  }
36935
36996
 
36936
36997
  const debug$a = createDebugger('vite:ssr-external');
36998
+ /**
36999
+ * Converts "parent > child" syntax to just "child"
37000
+ */
37001
+ function stripNesting(packages) {
37002
+ return packages.map((s) => {
37003
+ const arr = s.split('>');
37004
+ return arr[arr.length - 1].trim();
37005
+ });
37006
+ }
36937
37007
  /**
36938
37008
  * Heuristics for determining whether a dependency should be externalized for
36939
37009
  * server-side rendering.
36940
37010
  */
36941
37011
  function resolveSSRExternal(config, knownImports) {
36942
37012
  var _a;
37013
+ // strip nesting since knownImports may be passed in from optimizeDeps which
37014
+ // supports a "parent > child" syntax
37015
+ knownImports = stripNesting(knownImports);
36943
37016
  const ssrConfig = config.ssr;
36944
37017
  if ((ssrConfig === null || ssrConfig === void 0 ? void 0 : ssrConfig.noExternal) === true) {
36945
37018
  return [];
@@ -37207,7 +37280,12 @@ function assetImportMetaUrlPlugin(config) {
37207
37280
  }
37208
37281
  const url = rawUrl.slice(1, -1);
37209
37282
  const file = path__default.resolve(path__default.dirname(id), url);
37210
- const builtUrl = await fileToUrl(file, config, this);
37283
+ // Get final asset URL. Catch error if the file does not exist,
37284
+ // in which we can resort to the initial URL and let it resolve in runtime
37285
+ const builtUrl = await fileToUrl(file, config, this).catch(() => {
37286
+ config.logger.warnOnce(`\n${exp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
37287
+ return url;
37288
+ });
37211
37289
  s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`);
37212
37290
  }
37213
37291
  if (s) {
@@ -43425,7 +43503,7 @@ async function getCertificate(cacheDir) {
43425
43503
  return content;
43426
43504
  }
43427
43505
  catch {
43428
- const content = (await Promise.resolve().then(function () { return require('./dep-5f1b3f27.js'); })).createCertificate();
43506
+ const content = (await Promise.resolve().then(function () { return require('./dep-192b3800.js'); })).createCertificate();
43429
43507
  fs$n.promises
43430
43508
  .mkdir(cacheDir, { recursive: true })
43431
43509
  .then(() => fs$n.promises.writeFile(cachePath, content))
@@ -47657,7 +47735,8 @@ function createWebSocketServer(server, config, httpsOptions) {
47657
47735
  let wss;
47658
47736
  let httpsServer = undefined;
47659
47737
  const hmr = isObject$3(config.server.hmr) && config.server.hmr;
47660
- const wsServer = (hmr && hmr.server) || server;
47738
+ const wsServer = (hmr && hmr.server) ||
47739
+ ((!(hmr && hmr.port) || hmr.port !== config.server.port) && server);
47661
47740
  if (wsServer) {
47662
47741
  wss = new websocketServer({ noServer: true });
47663
47742
  wsServer.on('upgrade', (req, socket, head) => {
@@ -51294,16 +51373,66 @@ const debugCache$1 = createDebugger('vite:cache');
51294
51373
  const isDebug$3 = !!process.env.DEBUG;
51295
51374
  function transformRequest(url, server, options = {}) {
51296
51375
  const cacheKey = (options.ssr ? 'ssr:' : options.html ? 'html:' : '') + url;
51297
- let request = server._pendingRequests.get(cacheKey);
51298
- if (!request) {
51299
- request = doTransform(url, server, options);
51300
- server._pendingRequests.set(cacheKey, request);
51301
- const done = () => server._pendingRequests.delete(cacheKey);
51302
- request.then(done, done);
51376
+ // This module may get invalidated while we are processing it. For example
51377
+ // when a full page reload is needed after the re-processing of pre-bundled
51378
+ // dependencies when a missing dep is discovered. We save the current time
51379
+ // to compare it to the last invalidation performed to know if we should
51380
+ // cache the result of the transformation or we should discard it as stale.
51381
+ //
51382
+ // A module can be invalidated due to:
51383
+ // 1. A full reload because of pre-bundling newly discovered deps
51384
+ // 2. A full reload after a config change
51385
+ // 3. The file that generated the module changed
51386
+ // 4. Invalidation for a virtual module
51387
+ //
51388
+ // For 1 and 2, a new request for this module will be issued after
51389
+ // the invalidation as part of the browser reloading the page. For 3 and 4
51390
+ // there may not be a new request right away because of HMR handling.
51391
+ // In all cases, the next time this module is requested, it should be
51392
+ // re-processed.
51393
+ //
51394
+ // We save the timestap when we start processing and compare it with the
51395
+ // last time this module is invalidated
51396
+ const timestamp = Date.now();
51397
+ const pending = server._pendingRequests.get(cacheKey);
51398
+ if (pending) {
51399
+ return server.moduleGraph
51400
+ .getModuleByUrl(removeTimestampQuery(url), options.ssr)
51401
+ .then((module) => {
51402
+ if (!module || pending.timestamp > module.lastInvalidationTimestamp) {
51403
+ // The pending request is still valid, we can safely reuse its result
51404
+ return pending.request;
51405
+ }
51406
+ else {
51407
+ // Request 1 for module A (pending.timestamp)
51408
+ // Invalidate module A (module.lastInvalidationTimestamp)
51409
+ // Request 2 for module A (timestamp)
51410
+ // First request has been invalidated, abort it to clear the cache,
51411
+ // then perform a new doTransform.
51412
+ pending.abort();
51413
+ return transformRequest(url, server, options);
51414
+ }
51415
+ });
51303
51416
  }
51417
+ const request = doTransform(url, server, options, timestamp);
51418
+ // Avoid clearing the cache of future requests if aborted
51419
+ let cleared = false;
51420
+ const clearCache = () => {
51421
+ if (!cleared) {
51422
+ server._pendingRequests.delete(cacheKey);
51423
+ cleared = true;
51424
+ }
51425
+ };
51426
+ // Cache the request and clear it once processing is done
51427
+ server._pendingRequests.set(cacheKey, {
51428
+ request,
51429
+ timestamp,
51430
+ abort: clearCache
51431
+ });
51432
+ request.then(clearCache, clearCache);
51304
51433
  return request;
51305
51434
  }
51306
- async function doTransform(url, server, options) {
51435
+ async function doTransform(url, server, options, timestamp) {
51307
51436
  var _a, _b;
51308
51437
  url = removeTimestampQuery(url);
51309
51438
  const { config, pluginContainer, moduleGraph, watcher } = server;
@@ -51411,16 +51540,22 @@ async function doTransform(url, server, options) {
51411
51540
  await injectSourcesContent(map, mod.file, logger);
51412
51541
  }
51413
51542
  }
51414
- if (ssr) {
51415
- return (mod.ssrTransformResult = await ssrTransform(code, map, url));
51416
- }
51417
- else {
51418
- return (mod.transformResult = {
51543
+ const result = ssr
51544
+ ? await ssrTransform(code, map, url)
51545
+ : {
51419
51546
  code,
51420
51547
  map,
51421
51548
  etag: etag_1(code, { weak: true })
51422
- });
51549
+ };
51550
+ // Only cache the result if the module wasn't invalidated while it was
51551
+ // being processed, so it is re-processed next time if it is stale
51552
+ if (timestamp > mod.lastInvalidationTimestamp) {
51553
+ if (ssr)
51554
+ mod.ssrTransformResult = result;
51555
+ else
51556
+ mod.transformResult = result;
51423
51557
  }
51558
+ return result;
51424
51559
  }
51425
51560
 
51426
51561
  const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR';
@@ -51443,6 +51578,7 @@ function optimizedDepsPlugin() {
51443
51578
  const browserHash = versionMatch
51444
51579
  ? versionMatch[1].split('=')[1]
51445
51580
  : undefined;
51581
+ // Search in both the currently optimized and newly discovered deps
51446
51582
  const info = optimizeDepInfoFromFile(metadata, file);
51447
51583
  if (info) {
51448
51584
  if (browserHash && info.browserHash !== browserHash) {
@@ -51499,18 +51635,6 @@ function throwOutdatedRequest(id) {
51499
51635
  // send a 504 status code request timeout
51500
51636
  throw err;
51501
51637
  }
51502
- function optimizeDepInfoFromFile(metadata, file) {
51503
- return (findFileInfo(metadata.optimized, file) ||
51504
- findFileInfo(metadata.discovered, file));
51505
- }
51506
- function findFileInfo(dependenciesInfo, file) {
51507
- for (const o of Object.keys(dependenciesInfo)) {
51508
- const info = dependenciesInfo[o];
51509
- if (info.file === file) {
51510
- return info;
51511
- }
51512
- }
51513
- }
51514
51638
 
51515
51639
  const debugCache = createDebugger('vite:cache');
51516
51640
  const isDebug$1 = !!process.env.DEBUG;
@@ -51633,8 +51757,8 @@ function transformMiddleware(server) {
51633
51757
  }
51634
51758
  catch (e) {
51635
51759
  if ((e === null || e === void 0 ? void 0 : e.code) === ERR_OPTIMIZE_DEPS_PROCESSING_ERROR) {
51760
+ // Skip if response has already been sent
51636
51761
  if (!res.writableEnded) {
51637
- // Don't do anything if response has already been sent
51638
51762
  res.statusCode = 504; // status code request timeout
51639
51763
  res.end();
51640
51764
  }
@@ -51643,8 +51767,8 @@ function transformMiddleware(server) {
51643
51767
  return;
51644
51768
  }
51645
51769
  if ((e === null || e === void 0 ? void 0 : e.code) === ERR_OUTDATED_OPTIMIZED_DEP) {
51770
+ // Skip if response has already been sent
51646
51771
  if (!res.writableEnded) {
51647
- // Don't do anything if response has already been sent
51648
51772
  res.statusCode = 504; // status code request timeout
51649
51773
  res.end();
51650
51774
  }
@@ -51710,8 +51834,25 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
51710
51834
  const { config, moduleGraph } = server;
51711
51835
  const base = config.base || '/';
51712
51836
  const s = new MagicString(html);
51713
- let scriptModuleIndex = -1;
51837
+ let inlineModuleIndex = -1;
51714
51838
  const filePath = cleanUrl(htmlPath);
51839
+ const addInlineModule = (node, ext) => {
51840
+ inlineModuleIndex++;
51841
+ const url = filePath.replace(normalizePath$4(config.root), '');
51842
+ const contents = node.children
51843
+ .map((child) => child.content || '')
51844
+ .join('');
51845
+ // add HTML Proxy to Map
51846
+ addToHTMLProxyCache(config, url, inlineModuleIndex, contents);
51847
+ // inline js module. convert to src="proxy"
51848
+ const modulePath = `${config.base + htmlPath.slice(1)}?html-proxy&index=${inlineModuleIndex}.${ext}`;
51849
+ // invalidate the module so the newly cached contents will be served
51850
+ const module = server === null || server === void 0 ? void 0 : server.moduleGraph.getModuleById(modulePath);
51851
+ if (module) {
51852
+ server === null || server === void 0 ? void 0 : server.moduleGraph.invalidateModule(module);
51853
+ }
51854
+ s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${modulePath}"></script>`);
51855
+ };
51715
51856
  await traverseHtml(html, htmlPath, (node) => {
51716
51857
  if (node.type !== 1 /* ELEMENT */) {
51717
51858
  return;
@@ -51719,29 +51860,16 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
51719
51860
  // script tags
51720
51861
  if (node.tag === 'script') {
51721
51862
  const { src, isModule } = getScriptInfo(node);
51722
- if (isModule) {
51723
- scriptModuleIndex++;
51724
- }
51725
51863
  if (src) {
51726
51864
  processNodeUrl(src, s, config, htmlPath, originalUrl, moduleGraph);
51727
51865
  }
51728
51866
  else if (isModule) {
51729
- const url = filePath.replace(normalizePath$4(config.root), '');
51730
- const contents = node.children
51731
- .map((child) => child.content || '')
51732
- .join('');
51733
- // add HTML Proxy to Map
51734
- addToHTMLProxyCache(config, url, scriptModuleIndex, contents);
51735
- // inline js module. convert to src="proxy"
51736
- const modulePath = `${config.base + htmlPath.slice(1)}?html-proxy&index=${scriptModuleIndex}.js`;
51737
- // invalidate the module so the newly cached contents will be served
51738
- const module = server === null || server === void 0 ? void 0 : server.moduleGraph.getModuleById(modulePath);
51739
- if (module) {
51740
- server === null || server === void 0 ? void 0 : server.moduleGraph.invalidateModule(module);
51741
- }
51742
- s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${modulePath}"></script>`);
51867
+ addInlineModule(node, 'js');
51743
51868
  }
51744
51869
  }
51870
+ if (node.tag === 'style' && node.children.length) {
51871
+ addInlineModule(node, 'css');
51872
+ }
51745
51873
  // elements with [href/src] attrs
51746
51874
  const assetAttrs = assetAttrsConfig[node.tag];
51747
51875
  if (assetAttrs) {
@@ -51826,6 +51954,7 @@ class ModuleNode {
51826
51954
  this.ssrTransformResult = null;
51827
51955
  this.ssrModule = null;
51828
51956
  this.lastHMRTimestamp = 0;
51957
+ this.lastInvalidationTimestamp = 0;
51829
51958
  this.url = url;
51830
51959
  this.type = isDirectCSSRequest(url) ? 'css' : 'js';
51831
51960
  }
@@ -51866,16 +51995,21 @@ class ModuleGraph {
51866
51995
  });
51867
51996
  }
51868
51997
  }
51869
- invalidateModule(mod, seen = new Set()) {
51870
- mod.info = undefined;
51998
+ invalidateModule(mod, seen = new Set(), timestamp = Date.now()) {
51999
+ // Save the timestamp for this invalidation, so we can avoid caching the result of possible already started
52000
+ // processing being done for this module
52001
+ mod.lastInvalidationTimestamp = timestamp;
52002
+ // Don't invalidate mod.info and mod.meta, as they are part of the processing pipeline
52003
+ // Invalidating the transform result is enough to ensure this module is re-processed next time it is requested
51871
52004
  mod.transformResult = null;
51872
52005
  mod.ssrTransformResult = null;
51873
52006
  invalidateSSRModule(mod, seen);
51874
52007
  }
51875
52008
  invalidateAll() {
52009
+ const timestamp = Date.now();
51876
52010
  const seen = new Set();
51877
52011
  this.idToModuleMap.forEach((mod) => {
51878
- this.invalidateModule(mod, seen);
52012
+ this.invalidateModule(mod, seen, timestamp);
51879
52013
  });
51880
52014
  }
51881
52015
  /**
@@ -54343,13 +54477,26 @@ function isPrimitive(value) {
54343
54477
  * a re-bundle + page reload
54344
54478
  */
54345
54479
  const debounceMs = 100;
54346
- function createMissingImporterRegisterFn(server) {
54480
+ function createMissingImporterRegisterFn(server, initialProcessingPromise) {
54347
54481
  const { logger } = server.config;
54348
54482
  let metadata = server._optimizeDepsMetadata;
54349
54483
  let handle;
54350
- let needFullReload = false;
54484
+ let newDepsDiscovered = false;
54351
54485
  let depOptimizationProcessing = newDepOptimizationProcessing();
54352
- let lastDepOptimizationPromise = metadata.processing;
54486
+ let depOptimizationProcessingQueue = [];
54487
+ const resolveEnqueuedProcessingPromises = () => {
54488
+ // Resolve all the processings (including the ones which were delayed)
54489
+ for (const processing of depOptimizationProcessingQueue) {
54490
+ processing.resolve();
54491
+ }
54492
+ depOptimizationProcessingQueue = [];
54493
+ };
54494
+ let enqueuedRerun;
54495
+ let currentlyProcessing = true;
54496
+ initialProcessingPromise.then(() => {
54497
+ currentlyProcessing = false;
54498
+ enqueuedRerun === null || enqueuedRerun === void 0 ? void 0 : enqueuedRerun();
54499
+ });
54353
54500
  async function rerun(ssr) {
54354
54501
  // debounce time to wait for new missing deps finished, issue a new
54355
54502
  // optimization of deps (both old and newly found) once the previous
@@ -54361,70 +54508,70 @@ function createMissingImporterRegisterFn(server) {
54361
54508
  // the previous bundled dependencies have changed.
54362
54509
  // if the rerun fails, server._optimizeDepsMetadata remains untouched,
54363
54510
  // current discovered deps are cleaned, and a fullReload is issued
54364
- // optimizeDeps needs to be run in serie. Await until the previous
54365
- // rerun is finished here. It could happen that two reruns are queued
54366
- // in that case, we only need to run one of them
54367
- const awaitedOptimizeDepsPromise = lastDepOptimizationPromise;
54368
- await lastDepOptimizationPromise;
54369
- if (awaitedOptimizeDepsPromise !== lastDepOptimizationPromise) {
54370
- // There were two or more rerun queued and one of them already
54371
- // started. Only let through the first one, and discard the others
54372
- return;
54373
- }
54374
- if (handle) {
54375
- // New deps could have been found here, skip this rerun. Once the
54376
- // debounce time is over, a new rerun will be issued
54377
- return;
54378
- }
54511
+ // Ensure that rerun is called sequentially
54512
+ enqueuedRerun = undefined;
54513
+ currentlyProcessing = true;
54379
54514
  logger.info(colors$1.yellow(`new dependencies found: ${Object.keys(metadata.discovered).join(', ')}, updating...`), {
54380
54515
  timestamp: true
54381
54516
  });
54382
54517
  // All deps, previous known and newly discovered are rebundled,
54383
54518
  // respect insertion order to keep the metadata file stable
54384
- const newDeps = { ...metadata.optimized, ...metadata.discovered };
54385
- const thisDepOptimizationProcessing = depOptimizationProcessing;
54386
- // Other rerun will await until this run is finished
54387
- lastDepOptimizationPromise = thisDepOptimizationProcessing.promise;
54388
- let processingResult;
54519
+ const newDeps = {};
54520
+ // Clone optimized info objects, fileHash, browserHash may be changed for them
54521
+ for (const dep of Object.keys(metadata.optimized)) {
54522
+ newDeps[dep] = { ...metadata.optimized[dep] };
54523
+ }
54524
+ // Don't clone discovered info objects, they are read after awaited
54525
+ for (const dep of Object.keys(metadata.discovered)) {
54526
+ newDeps[dep] = metadata.discovered[dep];
54527
+ }
54528
+ newDepsDiscovered = false;
54529
+ // Add the current depOptimizationProcessing to the queue, these
54530
+ // promises are going to be resolved once a rerun is committed
54531
+ depOptimizationProcessingQueue.push(depOptimizationProcessing);
54389
54532
  // Create a new promise for the next rerun, discovered missing
54390
54533
  // dependencies will be asigned this promise from this point
54391
54534
  depOptimizationProcessing = newDepOptimizationProcessing();
54392
54535
  let newData = null;
54393
54536
  try {
54394
54537
  const optimizeDeps = await createOptimizeDepsRun(server.config, true, false, metadata, newDeps, ssr);
54395
- // We await the optimizeDeps run here, we are only going to use
54396
- // the newData if there wasn't an error
54397
- newData = optimizeDeps.metadata;
54398
- processingResult = await optimizeDeps.run();
54399
- // update ssr externals
54400
- if (ssr) {
54401
- server._ssrExternals = resolveSSRExternal(server.config, Object.keys(newData.optimized));
54402
- }
54403
- // While optimizeDeps is running, new missing deps may be discovered,
54404
- // in which case they will keep being added to metadata.discovered
54405
- for (const o of Object.keys(metadata.discovered)) {
54406
- if (!newData.optimized[o] && !newData.discovered[o]) {
54407
- newData.discovered[o] = metadata.discovered[o];
54408
- delete metadata.discovered[o];
54409
- }
54410
- }
54411
- newData.processing = thisDepOptimizationProcessing.promise;
54412
- metadata = server._optimizeDepsMetadata = newData;
54413
- if (!needFullReload && !(processingResult === null || processingResult === void 0 ? void 0 : processingResult.alteredFiles)) {
54538
+ const processingResult = await optimizeDeps.run();
54539
+ const commitProcessing = () => {
54540
+ processingResult.commit();
54541
+ newData = optimizeDeps.metadata;
54542
+ // update ssr externals
54543
+ if (ssr) {
54544
+ server._ssrExternals = resolveSSRExternal(server.config, Object.keys(newData.optimized));
54545
+ }
54546
+ // While optimizeDeps is running, new missing deps may be discovered,
54547
+ // in which case they will keep being added to metadata.discovered
54548
+ for (const o of Object.keys(metadata.discovered)) {
54549
+ if (!newData.optimized[o]) {
54550
+ newData.discovered[o] = metadata.discovered[o];
54551
+ }
54552
+ }
54553
+ metadata = server._optimizeDepsMetadata = newData;
54554
+ resolveEnqueuedProcessingPromises();
54555
+ };
54556
+ if (!processingResult.alteredFiles) {
54557
+ commitProcessing();
54414
54558
  logger.info(colors$1.green(`✨ new dependencies pre-bundled...`), {
54415
54559
  timestamp: true
54416
54560
  });
54417
54561
  }
54418
54562
  else {
54419
- if (Object.keys(metadata.discovered).length > 0) {
54563
+ if (newDepsDiscovered) {
54420
54564
  // There are newly discovered deps, and another rerun is about to be
54421
- // excecuted. Avoid the current full reload, but queue it for the next one
54422
- needFullReload = true;
54423
- logger.info(colors$1.green(`✨ dependencies updated, delaying reload as new dependencies have been found...`), {
54565
+ // excecuted. Avoid the current full reload discarding this rerun result
54566
+ // We don't resolve the processing promise, as they will be resolved
54567
+ // once a rerun is committed
54568
+ processingResult.cancel();
54569
+ logger.info(colors$1.green(`✨ delaying reload as new dependencies have been found...`), {
54424
54570
  timestamp: true
54425
54571
  });
54426
54572
  }
54427
54573
  else {
54574
+ commitProcessing();
54428
54575
  logger.info(colors$1.green(`✨ dependencies updated, reloading page...`), {
54429
54576
  timestamp: true
54430
54577
  });
@@ -54434,15 +54581,14 @@ function createMissingImporterRegisterFn(server) {
54434
54581
  }
54435
54582
  catch (e) {
54436
54583
  logger.error(colors$1.red(`error while updating dependencies:\n${e.stack}`), { timestamp: true, error: e });
54584
+ resolveEnqueuedProcessingPromises();
54437
54585
  // Reset missing deps, let the server rediscover the dependencies
54438
54586
  metadata.discovered = {};
54439
54587
  fullReload();
54440
54588
  }
54441
- finally {
54442
- // Rerun finished, resolve the promise to let awaiting requests or
54443
- // other rerun queued be processed
54444
- thisDepOptimizationProcessing.resolve();
54445
- }
54589
+ currentlyProcessing = false;
54590
+ // @ts-ignore
54591
+ enqueuedRerun === null || enqueuedRerun === void 0 ? void 0 : enqueuedRerun();
54446
54592
  }
54447
54593
  function fullReload() {
54448
54594
  // Cached transform results have stale imports (resolved to
@@ -54453,7 +54599,6 @@ function createMissingImporterRegisterFn(server) {
54453
54599
  type: 'full-reload',
54454
54600
  path: '*'
54455
54601
  });
54456
- needFullReload = false;
54457
54602
  }
54458
54603
  return function registerMissingImport(id, resolved, ssr) {
54459
54604
  const optimized = metadata.optimized[id];
@@ -54466,6 +54611,7 @@ function createMissingImporterRegisterFn(server) {
54466
54611
  // It will be processed in the next rerun call
54467
54612
  return missing;
54468
54613
  }
54614
+ newDepsDiscovered = true;
54469
54615
  missing = metadata.discovered[id] = {
54470
54616
  file: getOptimizedDepPath(id, server.config),
54471
54617
  src: resolved,
@@ -54480,11 +54626,15 @@ function createMissingImporterRegisterFn(server) {
54480
54626
  };
54481
54627
  // Debounced rerun, let other missing dependencies be discovered before
54482
54628
  // the running next optimizeDeps
54629
+ enqueuedRerun = undefined;
54483
54630
  if (handle)
54484
54631
  clearTimeout(handle);
54485
54632
  handle = setTimeout(() => {
54486
54633
  handle = undefined;
54487
- rerun(ssr);
54634
+ enqueuedRerun = () => rerun(ssr);
54635
+ if (!currentlyProcessing) {
54636
+ enqueuedRerun();
54637
+ }
54488
54638
  }, debounceMs);
54489
54639
  // Return the path for the optimized bundle, this path is known before
54490
54640
  // esbuild is run to generate the pre-bundle
@@ -54602,7 +54752,6 @@ async function createServer(inlineConfig = {}) {
54602
54752
  let configFileDependencies = [];
54603
54753
  const metadata = server._optimizeDepsMetadata;
54604
54754
  if (metadata) {
54605
- await metadata.processing;
54606
54755
  configFileDependencies = Object.keys(metadata.optimized);
54607
54756
  }
54608
54757
  server._ssrExternals || (server._ssrExternals = resolveSSRExternal(config, configFileDependencies));
@@ -54614,6 +54763,9 @@ async function createServer(inlineConfig = {}) {
54614
54763
  rebindErrorStacktrace(e, stacktrace);
54615
54764
  }
54616
54765
  },
54766
+ ssrRewriteStacktrace(stack) {
54767
+ return ssrRewriteStacktrace(stack, moduleGraph);
54768
+ },
54617
54769
  listen(port, isRestart) {
54618
54770
  return startServer(server, port, isRestart);
54619
54771
  },
@@ -54776,11 +54928,14 @@ async function createServer(inlineConfig = {}) {
54776
54928
  // Don't await for the optimization to finish, we can start the
54777
54929
  // server right away here
54778
54930
  server._optimizeDepsMetadata = optimizeDeps.metadata;
54779
- optimizeDeps.run();
54931
+ // Run deps optimization in parallel
54932
+ const initialProcessingPromise = optimizeDeps
54933
+ .run()
54934
+ .then((result) => result.commit());
54780
54935
  // While running the first optimizeDeps, _registerMissingImport is null
54781
54936
  // so the resolve plugin resolves straight to node_modules during the
54782
54937
  // deps discovery scan phase
54783
- server._registerMissingImport = createMissingImporterRegisterFn(server);
54938
+ server._registerMissingImport = createMissingImporterRegisterFn(server, initialProcessingPromise);
54784
54939
  };
54785
54940
  if (!middlewareMode && httpServer) {
54786
54941
  let isOptimized = false;
@@ -55277,6 +55432,7 @@ const clientDir = normalizePath$4(CLIENT_DIR);
55277
55432
  const skipRE = /\.(map|json)$/;
55278
55433
  const canSkip = (id) => skipRE.test(id) || isDirectCSSRequest(id);
55279
55434
  const optimizedDepChunkRE = /\/chunk-[A-Z0-9]{8}\.js/;
55435
+ const optimizedDepDynamicRE = /-[A-Z0-9]{8}\.js/;
55280
55436
  function isExplicitImportRequired(url) {
55281
55437
  return !isJSRequest(cleanUrl(url)) && !isCSSRequest(url);
55282
55438
  }
@@ -55409,7 +55565,7 @@ function importAnalysisPlugin(config) {
55409
55565
  const isRelative = url.startsWith('.');
55410
55566
  const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
55411
55567
  // normalize all imports into resolved URLs
55412
- // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js`
55568
+ // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
55413
55569
  if (resolved.id.startsWith(root + '/')) {
55414
55570
  // in root: infer short absolute path from root
55415
55571
  url = resolved.id.slice(root.length);
@@ -55470,6 +55626,10 @@ function importAnalysisPlugin(config) {
55470
55626
  }
55471
55627
  return [url, resolved.id];
55472
55628
  };
55629
+ // Import rewrites, we do them after all the URLs have been resolved
55630
+ // to help with the discovery of new dependencies. If we need to wait
55631
+ // for each dependency there could be one reload per import
55632
+ const importRewrites = [];
55473
55633
  for (let index = 0; index < imports.length; index++) {
55474
55634
  const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex,
55475
55635
  // #2083 User may use escape path,
@@ -55553,43 +55713,49 @@ function importAnalysisPlugin(config) {
55553
55713
  const url = normalizedUrl;
55554
55714
  // record as safe modules
55555
55715
  server === null || server === void 0 ? void 0 : server.moduleGraph.safeModulesPath.add(fsPathFromUrl(url));
55556
- // rewrite
55557
55716
  if (url !== specifier) {
55558
- let rewriteDone = false;
55559
- if (isOptimizedDepFile(resolvedId, config)) {
55560
- // for optimized cjs deps, support named imports by rewriting named
55561
- // imports to const assignments.
55562
- const optimizeDepsMetadata = server._optimizeDepsMetadata;
55563
- const { optimized } = optimizeDepsMetadata;
55564
- // The browserHash in resolvedId could be stale in which case there will be a full
55565
- // page reload. We could return a 404 in that case but it is safe to return the request
55566
- const file = cleanUrl(resolvedId); // Remove ?v={hash}
55567
- const dep = Object.keys(optimized).find((k) => optimized[k].file === file);
55568
- // Wait until the dependency has been pre-bundled
55569
- dep && (await optimized[dep].processing);
55570
- if (dep && optimized[dep].needsInterop) {
55571
- debug$1(`${dep} needs interop`);
55572
- if (isDynamicImport) {
55573
- // rewrite `import('package')` to expose the default directly
55574
- str().overwrite(dynamicIndex, end + 1, `import('${url}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`);
55717
+ importRewrites.push(async () => {
55718
+ let rewriteDone = false;
55719
+ if (isOptimizedDepFile(resolvedId, config) &&
55720
+ !resolvedId.match(optimizedDepChunkRE)) {
55721
+ // for optimized cjs deps, support named imports by rewriting named imports to const assignments.
55722
+ // internal optimized chunks don't need es interop and are excluded
55723
+ // The browserHash in resolvedId could be stale in which case there will be a full
55724
+ // page reload. We could return a 404 in that case but it is safe to return the request
55725
+ const file = cleanUrl(resolvedId); // Remove ?v={hash}
55726
+ const needsInterop = await optimizedDepNeedsInterop(server._optimizeDepsMetadata, file);
55727
+ if (needsInterop === undefined) {
55728
+ // Non-entry dynamic imports from dependencies will reach here as there isn't
55729
+ // optimize info for them, but they don't need es interop. If the request isn't
55730
+ // a dynamic import, then it is an internal Vite error
55731
+ if (!file.match(optimizedDepDynamicRE)) {
55732
+ config.logger.error(colors$1.red(`Vite Error, ${url} optimized info should be defined`));
55733
+ }
55575
55734
  }
55576
- else {
55577
- const exp = source.slice(expStart, expEnd);
55578
- const rewritten = transformCjsImport(exp, url, rawUrl, index);
55579
- if (rewritten) {
55580
- str().overwrite(expStart, expEnd, rewritten);
55735
+ else if (needsInterop) {
55736
+ debug$1(`${url} needs interop`);
55737
+ if (isDynamicImport) {
55738
+ // rewrite `import('package')` to expose the default directly
55739
+ str().overwrite(dynamicIndex, end + 1, `import('${url}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`);
55581
55740
  }
55582
55741
  else {
55583
- // #1439 export * from '...'
55584
- str().overwrite(start, end, url);
55742
+ const exp = source.slice(expStart, expEnd);
55743
+ const rewritten = transformCjsImport(exp, url, rawUrl, index);
55744
+ if (rewritten) {
55745
+ str().overwrite(expStart, expEnd, rewritten);
55746
+ }
55747
+ else {
55748
+ // #1439 export * from '...'
55749
+ str().overwrite(start, end, url);
55750
+ }
55585
55751
  }
55752
+ rewriteDone = true;
55586
55753
  }
55587
- rewriteDone = true;
55588
55754
  }
55589
- }
55590
- if (!rewriteDone) {
55591
- str().overwrite(start, end, isDynamicImport ? `'${url}'` : url);
55592
- }
55755
+ if (!rewriteDone) {
55756
+ str().overwrite(start, end, isDynamicImport ? `'${url}'` : url);
55757
+ }
55758
+ });
55593
55759
  }
55594
55760
  // record for HMR import chain analysis
55595
55761
  // make sure to normalize away base
@@ -55685,9 +55851,23 @@ function importAnalysisPlugin(config) {
55685
55851
  if (config.server.preTransformRequests && staticImportedUrls.size) {
55686
55852
  staticImportedUrls.forEach((url) => {
55687
55853
  url = unwrapId$1(removeImportQuery(url)).replace(NULL_BYTE_PLACEHOLDER, '\0');
55688
- transformRequest(url, server, { ssr });
55854
+ transformRequest(url, server, { ssr }).catch((e) => {
55855
+ if ((e === null || e === void 0 ? void 0 : e.code) === ERR_OUTDATED_OPTIMIZED_DEP) {
55856
+ // This are expected errors
55857
+ return;
55858
+ }
55859
+ // Unexpected error, log the issue but avoid an unhandled exception
55860
+ config.logger.error(e.message);
55861
+ });
55689
55862
  });
55690
55863
  }
55864
+ // Await for import rewrites that requires dependencies to be pre-bundled to
55865
+ // know if es interop is needed after starting further transformRequest calls
55866
+ // This will let Vite process deeper into the user code and find more missing
55867
+ // dependencies before the next page reload
55868
+ for (const rewrite of importRewrites) {
55869
+ await rewrite();
55870
+ }
55691
55871
  if (s) {
55692
55872
  return s.toString();
55693
55873
  }
@@ -56050,6 +56230,8 @@ function preAliasPlugin() {
56050
56230
  };
56051
56231
  }
56052
56232
 
56233
+ const nonJsRe = /\.(json)($|\?)/;
56234
+ const isNonJsRequest = (request) => nonJsRe.test(request);
56053
56235
  function definePlugin(config) {
56054
56236
  const isBuild = config.command === 'build';
56055
56237
  const processNodeEnv = {
@@ -56125,6 +56307,7 @@ function definePlugin(config) {
56125
56307
  // exclude html, css and static assets for performance
56126
56308
  isHTMLRequest(id) ||
56127
56309
  isCSSRequest(id) ||
56310
+ isNonJsRequest(id) ||
56128
56311
  config.assetsInclude(id)) {
56129
56312
  return;
56130
56313
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var require$$0 = require('postcss');
4
- var index$1 = require('./dep-429629d5.js');
4
+ var index$1 = require('./dep-19d0f55f.js');
5
5
  var path$2 = require('path');
6
6
  var require$$1 = require('crypto');
7
7
  var fs = require('fs');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./dep-429629d5.js');
3
+ var index = require('./dep-19d0f55f.js');
4
4
 
5
5
  function _mergeNamespaces(n, m) {
6
6
  for (var i = 0; i < m.length; i++) {
package/dist/node/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var require$$0 = require('events');
4
- var index = require('./chunks/dep-429629d5.js');
4
+ var index = require('./chunks/dep-19d0f55f.js');
5
5
  var perf_hooks = require('perf_hooks');
6
6
  require('fs');
7
7
  require('path');
@@ -683,7 +683,7 @@ cli
683
683
  .action(async (root, options) => {
684
684
  // output structure is preserved even after bundling so require()
685
685
  // is ok here
686
- const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.index$1; });
686
+ const { createServer } = await Promise.resolve().then(function () { return require('./chunks/dep-19d0f55f.js'); }).then(function (n) { return n.index$1; });
687
687
  try {
688
688
  const server = await createServer({
689
689
  root,
@@ -732,7 +732,7 @@ cli
732
732
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
733
733
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
734
734
  .action(async (root, options) => {
735
- const { build } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.build$1; });
735
+ const { build } = await Promise.resolve().then(function () { return require('./chunks/dep-19d0f55f.js'); }).then(function (n) { return n.build$1; });
736
736
  const buildOptions = cleanOptions(options);
737
737
  try {
738
738
  await build({
@@ -755,7 +755,7 @@ cli
755
755
  .command('optimize [root]', 'pre-bundle dependencies')
756
756
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
757
757
  .action(async (root, options) => {
758
- const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.index; });
758
+ const { optimizeDeps } = await Promise.resolve().then(function () { return require('./chunks/dep-19d0f55f.js'); }).then(function (n) { return n.index; });
759
759
  try {
760
760
  const config = await index.resolveConfig({
761
761
  root,
@@ -778,7 +778,7 @@ cli
778
778
  .option('--https', `[boolean] use TLS + HTTP/2`)
779
779
  .option('--open [path]', `[boolean | string] open browser on startup`)
780
780
  .action(async (root, options) => {
781
- const { preview } = await Promise.resolve().then(function () { return require('./chunks/dep-429629d5.js'); }).then(function (n) { return n.preview$1; });
781
+ const { preview } = await Promise.resolve().then(function () { return require('./chunks/dep-19d0f55f.js'); }).then(function (n) { return n.preview$1; });
782
782
  try {
783
783
  const server = await preview({
784
784
  root,
@@ -520,11 +520,6 @@ export declare interface DepOptimizationMetadata {
520
520
  * Metadata for each newly discovered dependency after processing
521
521
  */
522
522
  discovered: Record<string, OptimizedDepInfo>;
523
- /**
524
- * During optimization, ids can still be resolved to their final location
525
- * but the bundles may not yet be saved to disk
526
- */
527
- processing: Promise<DepOptimizationResult | undefined>;
528
523
  }
529
524
 
530
525
  export declare interface DepOptimizationOptions {
@@ -579,8 +574,8 @@ export declare interface DepOptimizationOptions {
579
574
  }
580
575
 
581
576
  export declare interface DepOptimizationProcessing {
582
- promise: Promise<DepOptimizationResult | undefined>;
583
- resolve: (result?: DepOptimizationResult) => void;
577
+ promise: Promise<void>;
578
+ resolve: () => void;
584
579
  }
585
580
 
586
581
  export declare interface DepOptimizationResult {
@@ -591,6 +586,13 @@ export declare interface DepOptimizationResult {
591
586
  * for large applications
592
587
  */
593
588
  alteredFiles: boolean;
589
+ /**
590
+ * When doing a re-run, if there are newly discovered dependendencies
591
+ * the page reload will be delayed until the next rerun so the
592
+ * result will be discarded
593
+ */
594
+ commit: () => void;
595
+ cancel: () => void;
594
596
  }
595
597
 
596
598
  export declare interface ErrorPayload {
@@ -1130,7 +1132,7 @@ export declare class ModuleGraph {
1130
1132
  getModuleById(id: string): ModuleNode | undefined;
1131
1133
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
1132
1134
  onFileChange(file: string): void;
1133
- invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>): void;
1135
+ invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>, timestamp?: number): void;
1134
1136
  invalidateAll(): void;
1135
1137
  /**
1136
1138
  * Update the module graph based on a module's updated imports information
@@ -1164,6 +1166,7 @@ export declare class ModuleNode {
1164
1166
  ssrTransformResult: TransformResult | null;
1165
1167
  ssrModule: Record<string, any> | null;
1166
1168
  lastHMRTimestamp: number;
1169
+ lastInvalidationTimestamp: number;
1167
1170
  constructor(url: string);
1168
1171
  }
1169
1172
 
@@ -1179,7 +1182,7 @@ export declare interface OptimizedDepInfo {
1179
1182
  * During optimization, ids can still be resolved to their final location
1180
1183
  * but the bundles may not yet be saved to disk
1181
1184
  */
1182
- processing: Promise<DepOptimizationResult | undefined>;
1185
+ processing: Promise<void>;
1183
1186
  }
1184
1187
 
1185
1188
  /**
@@ -2160,7 +2163,11 @@ export declare interface ViteDevServer {
2160
2163
  fixStacktrace?: boolean;
2161
2164
  }): Promise<Record<string, any>>;
2162
2165
  /**
2163
- * Fix ssr error stacktrace
2166
+ * Returns a fixed version of the given stack
2167
+ */
2168
+ ssrRewriteStacktrace(stack: string): string;
2169
+ /**
2170
+ * Mutates the given SSR error by rewriting the stacktrace
2164
2171
  */
2165
2172
  ssrFixStacktrace(e: Error): void;
2166
2173
  /**
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./chunks/dep-429629d5.js');
5
+ var index = require('./chunks/dep-19d0f55f.js');
6
6
  require('fs');
7
7
  require('path');
8
8
  require('tty');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "2.9.0-beta.0",
3
+ "version": "2.9.0-beta.3",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "Native-ESM powered web dev build tool",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
45
45
  "dependencies": {
46
- "esbuild": "^0.14.14",
46
+ "esbuild": "^0.14.27",
47
47
  "postcss": "^8.4.6",
48
48
  "resolve": "^1.22.0",
49
49
  "rollup": "^2.59.0"