vite 2.9.0-beta.0 → 2.9.0-beta.1

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-62435a6f.js');
4
4
  var require$$1 = require('crypto');
5
5
  require('fs');
6
6
  require('path');
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./dep-429629d5.js');
3
+ var index = require('./dep-62435a6f.js');
4
4
 
5
5
  function _mergeNamespaces(n, m) {
6
6
  for (var i = 0; i < m.length; i++) {
@@ -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-62435a6f.js');
5
5
  var path$2 = require('path');
6
6
  var require$$1 = require('crypto');
7
7
  var fs = require('fs');
@@ -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-47674adb.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-28bf75e1.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 {
@@ -35692,6 +35692,7 @@ ssr) {
35692
35692
  // a hint for Node.js
35693
35693
  // all files in the cache directory should be recognized as ES modules
35694
35694
  writeFile(path__default.resolve(processingCacheDir, 'package.json'), JSON.stringify({ type: 'module' }));
35695
+ let newBrowserHash;
35695
35696
  let deps;
35696
35697
  if (!newDeps) {
35697
35698
  // Initial optimizeDeps at server start. Perform a fast scan using esbuild to
@@ -35713,7 +35714,7 @@ ssr) {
35713
35714
  throw e;
35714
35715
  }
35715
35716
  // update browser hash
35716
- metadata.browserHash = getOptimizedBrowserHash(metadata.hash, deps);
35717
+ newBrowserHash = metadata.browserHash = getOptimizedBrowserHash(metadata.hash, deps);
35717
35718
  // We generate the mapping of dependency ids to their cache file location
35718
35719
  // before processing the dependencies with esbuild. This allow us to continue
35719
35720
  // processing files in the importAnalysis and resolve plugins
@@ -35722,7 +35723,7 @@ ssr) {
35722
35723
  metadata.optimized[id] = {
35723
35724
  file: getOptimizedDepPath(id, config),
35724
35725
  src: entry,
35725
- browserHash: metadata.browserHash,
35726
+ browserHash: newBrowserHash,
35726
35727
  processing: processing.promise
35727
35728
  };
35728
35729
  }
@@ -35731,13 +35732,11 @@ ssr) {
35731
35732
  // Missing dependencies were found at run-time, optimizeDeps called while the
35732
35733
  // server is running
35733
35734
  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
35735
+ metadata.optimized = newDeps;
35736
+ // For reruns keep current global browser hash and newDeps individual hashes until we know
35739
35737
  // if files are stable so we can avoid a full page reload
35740
- metadata.browserHash = getOptimizedBrowserHash(metadata.hash, deps);
35738
+ metadata.browserHash = currentData.browserHash;
35739
+ newBrowserHash = getOptimizedBrowserHash(metadata.hash, deps);
35741
35740
  }
35742
35741
  return { metadata, run: prebundleDeps };
35743
35742
  async function prebundleDeps() {
@@ -35893,8 +35892,9 @@ ssr) {
35893
35892
  // New deps that ended up with a different hash replaced while doing analysis import are going to
35894
35893
  // return a not found so the browser doesn't cache them. And will properly get loaded after the reload
35895
35894
  for (const id in deps) {
35896
- metadata.optimized[id].browserHash = metadata.browserHash;
35895
+ metadata.optimized[id].browserHash = newBrowserHash;
35897
35896
  }
35897
+ metadata.browserHash = newBrowserHash;
35898
35898
  }
35899
35899
  // Write metadata file, delete `deps` folder and rename the new `processing` folder to `deps` in sync
35900
35900
  commitProcessingDepsCacheSync();
@@ -35906,7 +35906,7 @@ ssr) {
35906
35906
  var _a;
35907
35907
  // Rewire the file paths from the temporal processing dir to the final deps cache dir
35908
35908
  const dataPath = path__default.join(processingCacheDir, '_metadata.json');
35909
- writeFile(dataPath, stringifyOptimizedDepsMetadata(metadata));
35909
+ writeFile(dataPath, stringifyOptimizedDepsMetadata(metadata, depsCacheDir));
35910
35910
  // Processing is done, we can now replace the depsCacheDir with processingCacheDir
35911
35911
  if (fs__default.existsSync(depsCacheDir)) {
35912
35912
  const rmSync = (_a = fs__default.rmSync) !== null && _a !== void 0 ? _a : fs__default.rmdirSync; // TODO: Remove after support for Node 12 is dropped
@@ -35991,16 +35991,27 @@ function createIsOptimizedDepUrl(config) {
35991
35991
  };
35992
35992
  }
35993
35993
  function parseOptimizedDepsMetadata(jsonMetadata, depsCacheDir, processing) {
35994
- const metadata = JSON.parse(jsonMetadata);
35994
+ const metadata = JSON.parse(jsonMetadata, (key, value) => {
35995
+ // Paths can be absolute or relative to the deps cache dir where
35996
+ // the _metadata.json is located
35997
+ if (key === 'file' || key === 'src') {
35998
+ return normalizePath$4(path__default.resolve(depsCacheDir, value));
35999
+ }
36000
+ return value;
36001
+ });
35995
36002
  for (const o of Object.keys(metadata.optimized)) {
35996
36003
  metadata.optimized[o].processing = processing;
35997
36004
  }
35998
36005
  return { ...metadata, discovered: {}, processing };
35999
36006
  }
36000
- function stringifyOptimizedDepsMetadata(metadata) {
36007
+ function stringifyOptimizedDepsMetadata(metadata, depsCacheDir) {
36001
36008
  return JSON.stringify(metadata, (key, value) => {
36002
- if (key === 'processing' || key === 'discovered')
36009
+ if (key === 'processing' || key === 'discovered') {
36003
36010
  return;
36011
+ }
36012
+ if (key === 'file' || key === 'src') {
36013
+ return normalizePath$4(path__default.relative(depsCacheDir, value));
36014
+ }
36004
36015
  return value;
36005
36016
  }, 2);
36006
36017
  }
@@ -36068,6 +36079,26 @@ function getDepHash(root, config) {
36068
36079
  });
36069
36080
  return require$$1$1.createHash('sha256').update(content).digest('hex').substring(0, 8);
36070
36081
  }
36082
+ function optimizeDepInfoFromFile(metadata, file) {
36083
+ return (findFileInfo(metadata.optimized, file) ||
36084
+ findFileInfo(metadata.discovered, file));
36085
+ }
36086
+ function findFileInfo(dependenciesInfo, file) {
36087
+ for (const o of Object.keys(dependenciesInfo)) {
36088
+ const info = dependenciesInfo[o];
36089
+ if (info.file === file) {
36090
+ return info;
36091
+ }
36092
+ }
36093
+ }
36094
+ async function optimizedDepNeedsInterop(metadata, file) {
36095
+ const depInfo = optimizeDepInfoFromFile(metadata, file);
36096
+ if (!depInfo)
36097
+ return undefined;
36098
+ // Wait until the dependency has been pre-bundled
36099
+ await depInfo.processing;
36100
+ return depInfo === null || depInfo === void 0 ? void 0 : depInfo.needsInterop;
36101
+ }
36071
36102
 
36072
36103
  var index$1 = {
36073
36104
  __proto__: null,
@@ -36081,7 +36112,9 @@ var index$1 = {
36081
36112
  getDepsCacheDir: getDepsCacheDir,
36082
36113
  getProcessingDepsCacheDir: getProcessingDepsCacheDir,
36083
36114
  isOptimizedDepFile: isOptimizedDepFile,
36084
- createIsOptimizedDepUrl: createIsOptimizedDepUrl
36115
+ createIsOptimizedDepUrl: createIsOptimizedDepUrl,
36116
+ optimizeDepInfoFromFile: optimizeDepInfoFromFile,
36117
+ optimizedDepNeedsInterop: optimizedDepNeedsInterop
36085
36118
  };
36086
36119
 
36087
36120
  /**
@@ -36679,7 +36712,7 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
36679
36712
  // can cache it without re-validation, but only do so for known js types.
36680
36713
  // otherwise we may introduce duplicated modules for externalized files
36681
36714
  // from pre-bundled deps.
36682
- const versionHash = (_b = server._optimizeDepsMetadata) === null || _b === void 0 ? void 0 : _b.hash;
36715
+ const versionHash = (_b = server._optimizeDepsMetadata) === null || _b === void 0 ? void 0 : _b.browserHash;
36683
36716
  if (versionHash && isJsType) {
36684
36717
  resolved = injectQuery(resolved, `v=${versionHash}`);
36685
36718
  }
@@ -37207,7 +37240,12 @@ function assetImportMetaUrlPlugin(config) {
37207
37240
  }
37208
37241
  const url = rawUrl.slice(1, -1);
37209
37242
  const file = path__default.resolve(path__default.dirname(id), url);
37210
- const builtUrl = await fileToUrl(file, config, this);
37243
+ // Get final asset URL. Catch error if the file does not exist,
37244
+ // in which we can resort to the initial URL and let it resolve in runtime
37245
+ const builtUrl = await fileToUrl(file, config, this).catch(() => {
37246
+ config.logger.warnOnce(`\n${exp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
37247
+ return url;
37248
+ });
37211
37249
  s.overwrite(index, index + exp.length, `new URL(${JSON.stringify(builtUrl)}, self.location)`);
37212
37250
  }
37213
37251
  if (s) {
@@ -43425,7 +43463,7 @@ async function getCertificate(cacheDir) {
43425
43463
  return content;
43426
43464
  }
43427
43465
  catch {
43428
- const content = (await Promise.resolve().then(function () { return require('./dep-5f1b3f27.js'); })).createCertificate();
43466
+ const content = (await Promise.resolve().then(function () { return require('./dep-1cf708c4.js'); })).createCertificate();
43429
43467
  fs$n.promises
43430
43468
  .mkdir(cacheDir, { recursive: true })
43431
43469
  .then(() => fs$n.promises.writeFile(cachePath, content))
@@ -47657,7 +47695,8 @@ function createWebSocketServer(server, config, httpsOptions) {
47657
47695
  let wss;
47658
47696
  let httpsServer = undefined;
47659
47697
  const hmr = isObject$3(config.server.hmr) && config.server.hmr;
47660
- const wsServer = (hmr && hmr.server) || server;
47698
+ const wsServer = (hmr && hmr.server) ||
47699
+ ((!(hmr && hmr.port) || hmr.port !== config.server.port) && server);
47661
47700
  if (wsServer) {
47662
47701
  wss = new websocketServer({ noServer: true });
47663
47702
  wsServer.on('upgrade', (req, socket, head) => {
@@ -51294,16 +51333,66 @@ const debugCache$1 = createDebugger('vite:cache');
51294
51333
  const isDebug$3 = !!process.env.DEBUG;
51295
51334
  function transformRequest(url, server, options = {}) {
51296
51335
  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);
51336
+ // This module may get invalidated while we are processing it. For example
51337
+ // when a full page reload is needed after the re-processing of pre-bundled
51338
+ // dependencies when a missing dep is discovered. We save the current time
51339
+ // to compare it to the last invalidation performed to know if we should
51340
+ // cache the result of the transformation or we should discard it as stale.
51341
+ //
51342
+ // A module can be invalidated due to:
51343
+ // 1. A full reload because of pre-bundling newly discovered deps
51344
+ // 2. A full reload after a config change
51345
+ // 3. The file that generated the module changed
51346
+ // 4. Invalidation for a virtual module
51347
+ //
51348
+ // For 1 and 2, a new request for this module will be issued after
51349
+ // the invalidation as part of the browser reloading the page. For 3 and 4
51350
+ // there may not be a new request right away because of HMR handling.
51351
+ // In all cases, the next time this module is requested, it should be
51352
+ // re-processed.
51353
+ //
51354
+ // We save the timestap when we start processing and compare it with the
51355
+ // last time this module is invalidated
51356
+ const timestamp = Date.now();
51357
+ const pending = server._pendingRequests.get(cacheKey);
51358
+ if (pending) {
51359
+ return server.moduleGraph
51360
+ .getModuleByUrl(removeTimestampQuery(url), options.ssr)
51361
+ .then((module) => {
51362
+ if (!module || pending.timestamp > module.lastInvalidationTimestamp) {
51363
+ // The pending request is still valid, we can safely reuse its result
51364
+ return pending.request;
51365
+ }
51366
+ else {
51367
+ // Request 1 for module A (pending.timestamp)
51368
+ // Invalidate module A (module.lastInvalidationTimestamp)
51369
+ // Request 2 for module A (timestamp)
51370
+ // First request has been invalidated, abort it to clear the cache,
51371
+ // then perform a new doTransform.
51372
+ pending.abort();
51373
+ return transformRequest(url, server, options);
51374
+ }
51375
+ });
51303
51376
  }
51377
+ const request = doTransform(url, server, options, timestamp);
51378
+ // Avoid clearing the cache of future requests if aborted
51379
+ let cleared = false;
51380
+ const clearCache = () => {
51381
+ if (!cleared) {
51382
+ server._pendingRequests.delete(cacheKey);
51383
+ cleared = true;
51384
+ }
51385
+ };
51386
+ // Cache the request and clear it once processing is done
51387
+ server._pendingRequests.set(cacheKey, {
51388
+ request,
51389
+ timestamp,
51390
+ abort: clearCache
51391
+ });
51392
+ request.then(clearCache, clearCache);
51304
51393
  return request;
51305
51394
  }
51306
- async function doTransform(url, server, options) {
51395
+ async function doTransform(url, server, options, timestamp) {
51307
51396
  var _a, _b;
51308
51397
  url = removeTimestampQuery(url);
51309
51398
  const { config, pluginContainer, moduleGraph, watcher } = server;
@@ -51411,16 +51500,22 @@ async function doTransform(url, server, options) {
51411
51500
  await injectSourcesContent(map, mod.file, logger);
51412
51501
  }
51413
51502
  }
51414
- if (ssr) {
51415
- return (mod.ssrTransformResult = await ssrTransform(code, map, url));
51416
- }
51417
- else {
51418
- return (mod.transformResult = {
51503
+ const result = ssr
51504
+ ? await ssrTransform(code, map, url)
51505
+ : {
51419
51506
  code,
51420
51507
  map,
51421
51508
  etag: etag_1(code, { weak: true })
51422
- });
51509
+ };
51510
+ // Only cache the result if the module wasn't invalidated while it was
51511
+ // being processed, so it is re-processed next time if it is stale
51512
+ if (timestamp > mod.lastInvalidationTimestamp) {
51513
+ if (ssr)
51514
+ mod.ssrTransformResult = result;
51515
+ else
51516
+ mod.transformResult = result;
51423
51517
  }
51518
+ return result;
51424
51519
  }
51425
51520
 
51426
51521
  const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR';
@@ -51443,6 +51538,7 @@ function optimizedDepsPlugin() {
51443
51538
  const browserHash = versionMatch
51444
51539
  ? versionMatch[1].split('=')[1]
51445
51540
  : undefined;
51541
+ // Search in both the currently optimized and newly discovered deps
51446
51542
  const info = optimizeDepInfoFromFile(metadata, file);
51447
51543
  if (info) {
51448
51544
  if (browserHash && info.browserHash !== browserHash) {
@@ -51499,18 +51595,6 @@ function throwOutdatedRequest(id) {
51499
51595
  // send a 504 status code request timeout
51500
51596
  throw err;
51501
51597
  }
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
51598
 
51515
51599
  const debugCache = createDebugger('vite:cache');
51516
51600
  const isDebug$1 = !!process.env.DEBUG;
@@ -51633,8 +51717,8 @@ function transformMiddleware(server) {
51633
51717
  }
51634
51718
  catch (e) {
51635
51719
  if ((e === null || e === void 0 ? void 0 : e.code) === ERR_OPTIMIZE_DEPS_PROCESSING_ERROR) {
51720
+ // Skip if response has already been sent
51636
51721
  if (!res.writableEnded) {
51637
- // Don't do anything if response has already been sent
51638
51722
  res.statusCode = 504; // status code request timeout
51639
51723
  res.end();
51640
51724
  }
@@ -51643,8 +51727,8 @@ function transformMiddleware(server) {
51643
51727
  return;
51644
51728
  }
51645
51729
  if ((e === null || e === void 0 ? void 0 : e.code) === ERR_OUTDATED_OPTIMIZED_DEP) {
51730
+ // Skip if response has already been sent
51646
51731
  if (!res.writableEnded) {
51647
- // Don't do anything if response has already been sent
51648
51732
  res.statusCode = 504; // status code request timeout
51649
51733
  res.end();
51650
51734
  }
@@ -51710,8 +51794,25 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
51710
51794
  const { config, moduleGraph } = server;
51711
51795
  const base = config.base || '/';
51712
51796
  const s = new MagicString(html);
51713
- let scriptModuleIndex = -1;
51797
+ let inlineModuleIndex = -1;
51714
51798
  const filePath = cleanUrl(htmlPath);
51799
+ const addInlineModule = (node, ext) => {
51800
+ inlineModuleIndex++;
51801
+ const url = filePath.replace(normalizePath$4(config.root), '');
51802
+ const contents = node.children
51803
+ .map((child) => child.content || '')
51804
+ .join('');
51805
+ // add HTML Proxy to Map
51806
+ addToHTMLProxyCache(config, url, inlineModuleIndex, contents);
51807
+ // inline js module. convert to src="proxy"
51808
+ const modulePath = `${config.base + htmlPath.slice(1)}?html-proxy&index=${inlineModuleIndex}.${ext}`;
51809
+ // invalidate the module so the newly cached contents will be served
51810
+ const module = server === null || server === void 0 ? void 0 : server.moduleGraph.getModuleById(modulePath);
51811
+ if (module) {
51812
+ server === null || server === void 0 ? void 0 : server.moduleGraph.invalidateModule(module);
51813
+ }
51814
+ s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${modulePath}"></script>`);
51815
+ };
51715
51816
  await traverseHtml(html, htmlPath, (node) => {
51716
51817
  if (node.type !== 1 /* ELEMENT */) {
51717
51818
  return;
@@ -51719,29 +51820,16 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
51719
51820
  // script tags
51720
51821
  if (node.tag === 'script') {
51721
51822
  const { src, isModule } = getScriptInfo(node);
51722
- if (isModule) {
51723
- scriptModuleIndex++;
51724
- }
51725
51823
  if (src) {
51726
51824
  processNodeUrl(src, s, config, htmlPath, originalUrl, moduleGraph);
51727
51825
  }
51728
51826
  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>`);
51827
+ addInlineModule(node, 'js');
51743
51828
  }
51744
51829
  }
51830
+ if (node.tag === 'style' && node.children.length) {
51831
+ addInlineModule(node, 'css');
51832
+ }
51745
51833
  // elements with [href/src] attrs
51746
51834
  const assetAttrs = assetAttrsConfig[node.tag];
51747
51835
  if (assetAttrs) {
@@ -51826,6 +51914,7 @@ class ModuleNode {
51826
51914
  this.ssrTransformResult = null;
51827
51915
  this.ssrModule = null;
51828
51916
  this.lastHMRTimestamp = 0;
51917
+ this.lastInvalidationTimestamp = 0;
51829
51918
  this.url = url;
51830
51919
  this.type = isDirectCSSRequest(url) ? 'css' : 'js';
51831
51920
  }
@@ -51866,16 +51955,21 @@ class ModuleGraph {
51866
51955
  });
51867
51956
  }
51868
51957
  }
51869
- invalidateModule(mod, seen = new Set()) {
51870
- mod.info = undefined;
51958
+ invalidateModule(mod, seen = new Set(), timestamp = Date.now()) {
51959
+ // Save the timestamp for this invalidation, so we can avoid caching the result of possible already started
51960
+ // processing being done for this module
51961
+ mod.lastInvalidationTimestamp = timestamp;
51962
+ // Don't invalidate mod.info and mod.meta, as they are part of the processing pipeline
51963
+ // Invalidating the transform result is enough to ensure this module is re-processed next time it is requested
51871
51964
  mod.transformResult = null;
51872
51965
  mod.ssrTransformResult = null;
51873
51966
  invalidateSSRModule(mod, seen);
51874
51967
  }
51875
51968
  invalidateAll() {
51969
+ const timestamp = Date.now();
51876
51970
  const seen = new Set();
51877
51971
  this.idToModuleMap.forEach((mod) => {
51878
- this.invalidateModule(mod, seen);
51972
+ this.invalidateModule(mod, seen, timestamp);
51879
51973
  });
51880
51974
  }
51881
51975
  /**
@@ -54381,7 +54475,12 @@ function createMissingImporterRegisterFn(server) {
54381
54475
  });
54382
54476
  // All deps, previous known and newly discovered are rebundled,
54383
54477
  // respect insertion order to keep the metadata file stable
54384
- const newDeps = { ...metadata.optimized, ...metadata.discovered };
54478
+ // Clone optimized info objects, fileHash, browserHash may be changed for them
54479
+ const clonedOptimizedDeps = {};
54480
+ for (const o of Object.keys(metadata.optimized)) {
54481
+ clonedOptimizedDeps[o] = { ...metadata.optimized[o] };
54482
+ }
54483
+ const newDeps = { ...clonedOptimizedDeps, ...metadata.discovered };
54385
54484
  const thisDepOptimizationProcessing = depOptimizationProcessing;
54386
54485
  // Other rerun will await until this run is finished
54387
54486
  lastDepOptimizationPromise = thisDepOptimizationProcessing.promise;
@@ -54403,9 +54502,8 @@ function createMissingImporterRegisterFn(server) {
54403
54502
  // While optimizeDeps is running, new missing deps may be discovered,
54404
54503
  // in which case they will keep being added to metadata.discovered
54405
54504
  for (const o of Object.keys(metadata.discovered)) {
54406
- if (!newData.optimized[o] && !newData.discovered[o]) {
54505
+ if (!newData.optimized[o]) {
54407
54506
  newData.discovered[o] = metadata.discovered[o];
54408
- delete metadata.discovered[o];
54409
54507
  }
54410
54508
  }
54411
54509
  newData.processing = thisDepOptimizationProcessing.promise;
@@ -54614,6 +54712,9 @@ async function createServer(inlineConfig = {}) {
54614
54712
  rebindErrorStacktrace(e, stacktrace);
54615
54713
  }
54616
54714
  },
54715
+ ssrRewriteStacktrace(stack) {
54716
+ return ssrRewriteStacktrace(stack, moduleGraph);
54717
+ },
54617
54718
  listen(port, isRestart) {
54618
54719
  return startServer(server, port, isRestart);
54619
54720
  },
@@ -55556,19 +55657,19 @@ function importAnalysisPlugin(config) {
55556
55657
  // rewrite
55557
55658
  if (url !== specifier) {
55558
55659
  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;
55660
+ if (isOptimizedDepFile(resolvedId, config) &&
55661
+ !resolvedId.match(optimizedDepChunkRE)) {
55662
+ // for optimized cjs deps, support named imports by rewriting named imports to const assignments.
55663
+ // internal optimized chunks don't need es interop and are excluded
55564
55664
  // The browserHash in resolvedId could be stale in which case there will be a full
55565
55665
  // page reload. We could return a 404 in that case but it is safe to return the request
55566
55666
  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`);
55667
+ const needsInterop = await optimizedDepNeedsInterop(server._optimizeDepsMetadata, file);
55668
+ if (needsInterop === undefined) {
55669
+ config.logger.error(colors$1.red(`Vite Error, ${url} optimized info should be defined`));
55670
+ }
55671
+ else if (needsInterop) {
55672
+ debug$1(`${url} needs interop`);
55572
55673
  if (isDynamicImport) {
55573
55674
  // rewrite `import('package')` to expose the default directly
55574
55675
  str().overwrite(dynamicIndex, end + 1, `import('${url}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`);
@@ -56050,6 +56151,8 @@ function preAliasPlugin() {
56050
56151
  };
56051
56152
  }
56052
56153
 
56154
+ const nonJsRe = /\.(json)($|\?)/;
56155
+ const isNonJsRequest = (request) => nonJsRe.test(request);
56053
56156
  function definePlugin(config) {
56054
56157
  const isBuild = config.command === 'build';
56055
56158
  const processNodeEnv = {
@@ -56125,6 +56228,7 @@ function definePlugin(config) {
56125
56228
  // exclude html, css and static assets for performance
56126
56229
  isHTMLRequest(id) ||
56127
56230
  isCSSRequest(id) ||
56231
+ isNonJsRequest(id) ||
56128
56232
  config.assetsInclude(id)) {
56129
56233
  return;
56130
56234
  }
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-62435a6f.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-62435a6f.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-62435a6f.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-62435a6f.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-62435a6f.js'); }).then(function (n) { return n.preview$1; });
782
782
  try {
783
783
  const server = await preview({
784
784
  root,
@@ -1130,7 +1130,7 @@ export declare class ModuleGraph {
1130
1130
  getModuleById(id: string): ModuleNode | undefined;
1131
1131
  getModulesByFile(file: string): Set<ModuleNode> | undefined;
1132
1132
  onFileChange(file: string): void;
1133
- invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>): void;
1133
+ invalidateModule(mod: ModuleNode, seen?: Set<ModuleNode>, timestamp?: number): void;
1134
1134
  invalidateAll(): void;
1135
1135
  /**
1136
1136
  * Update the module graph based on a module's updated imports information
@@ -1164,6 +1164,7 @@ export declare class ModuleNode {
1164
1164
  ssrTransformResult: TransformResult | null;
1165
1165
  ssrModule: Record<string, any> | null;
1166
1166
  lastHMRTimestamp: number;
1167
+ lastInvalidationTimestamp: number;
1167
1168
  constructor(url: string);
1168
1169
  }
1169
1170
 
@@ -2160,7 +2161,11 @@ export declare interface ViteDevServer {
2160
2161
  fixStacktrace?: boolean;
2161
2162
  }): Promise<Record<string, any>>;
2162
2163
  /**
2163
- * Fix ssr error stacktrace
2164
+ * Returns a fixed version of the given stack
2165
+ */
2166
+ ssrRewriteStacktrace(stack: string): string;
2167
+ /**
2168
+ * Mutates the given SSR error by rewriting the stacktrace
2164
2169
  */
2165
2170
  ssrFixStacktrace(e: Error): void;
2166
2171
  /**
@@ -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-62435a6f.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.1",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "description": "Native-ESM powered web dev build tool",