vite 3.0.0-alpha.3 → 3.0.0-alpha.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.
@@ -1,5 +1,5 @@
1
1
  import require$$0 from 'postcss';
2
- import { v as commonjsGlobal } from './dep-6f5ac69c.js';
2
+ import { v as commonjsGlobal } from './dep-aea1d487.js';
3
3
  import path$2 from 'path';
4
4
  import require$$1 from 'crypto';
5
5
  import fs__default from 'fs';
@@ -1,4 +1,4 @@
1
- import { w as getAugmentedNamespace, x as getDefaultExportFromCjs } from './dep-6f5ac69c.js';
1
+ import { w as getAugmentedNamespace, x as getDefaultExportFromCjs } from './dep-aea1d487.js';
2
2
 
3
3
  import { fileURLToPath as __cjs_fileURLToPath } from 'url';
4
4
  import { dirname as __cjs_dirname } from 'path';
@@ -32597,7 +32597,7 @@ const assetAttrsConfig = {
32597
32597
  const isAsyncScriptMap = new WeakMap();
32598
32598
  async function traverseHtml(html, filePath, visitor) {
32599
32599
  // lazy load compiler
32600
- const { parse, transform } = await import('./dep-da8244f4.js').then(function (n) { return n.c; });
32600
+ const { parse, transform } = await import('./dep-35b61ee3.js').then(function (n) { return n.c; });
32601
32601
  // @vue/compiler-core doesn't like lowercase doctypes
32602
32602
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
32603
32603
  try {
@@ -33702,7 +33702,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
33702
33702
  logger: config.logger
33703
33703
  }));
33704
33704
  if (isModule) {
33705
- postcssPlugins.unshift((await import('./dep-b1fc04c1.js').then(function (n) { return n.i; })).default({
33705
+ postcssPlugins.unshift((await import('./dep-28f8c91c.js').then(function (n) { return n.i; })).default({
33706
33706
  ...modulesOptions,
33707
33707
  getJSON(cssFileName, _modules, outputFileName) {
33708
33708
  modules = _modules;
@@ -36303,12 +36303,13 @@ async function discoverProjectDependencies(config, timestamp) {
36303
36303
  const browserHash = getOptimizedBrowserHash(getDepHash(config), deps, timestamp);
36304
36304
  const discovered = {};
36305
36305
  for (const id in deps) {
36306
- const entry = deps[id];
36306
+ const src = deps[id];
36307
36307
  discovered[id] = {
36308
36308
  id,
36309
36309
  file: getOptimizedDepPath(id, config),
36310
- src: entry,
36311
- browserHash: browserHash
36310
+ src,
36311
+ browserHash: browserHash,
36312
+ exportsData: extractExportsData(src, config)
36312
36313
  };
36313
36314
  }
36314
36315
  return discovered;
@@ -36355,15 +36356,21 @@ async function runOptimizeDeps(config, depsInfo) {
36355
36356
  // to wait here. Code that needs to access the cached deps needs to await
36356
36357
  // the optimizedDepInfo.processing promise for each dep
36357
36358
  const qualifiedIds = Object.keys(depsInfo);
36359
+ const processingResult = {
36360
+ metadata,
36361
+ async commit() {
36362
+ // Write metadata file, delete `deps` folder and rename the `processing` folder to `deps`
36363
+ // Processing is done, we can now replace the depsCacheDir with processingCacheDir
36364
+ // Rewire the file paths from the temporal processing dir to the final deps cache dir
36365
+ await removeDir(depsCacheDir);
36366
+ await renameDir(processingCacheDir, depsCacheDir);
36367
+ },
36368
+ cancel() {
36369
+ fs__default.rmSync(processingCacheDir, { recursive: true, force: true });
36370
+ }
36371
+ };
36358
36372
  if (!qualifiedIds.length) {
36359
- return {
36360
- metadata,
36361
- commit() {
36362
- // Write metadata file, delete `deps` folder and rename the `processing` folder to `deps`
36363
- return commitProcessingDepsCacheSync();
36364
- },
36365
- cancel
36366
- };
36373
+ return processingResult;
36367
36374
  }
36368
36375
  // esbuild generates nested directory output with lowest common ancestor base
36369
36376
  // this is unpredictable and makes it difficult to analyze entry / output
@@ -36375,50 +36382,20 @@ async function runOptimizeDeps(config, depsInfo) {
36375
36382
  const idToExports = {};
36376
36383
  const flatIdToExports = {};
36377
36384
  const { plugins = [], ...esbuildOptions } = config.optimizeDeps?.esbuildOptions ?? {};
36378
- await init;
36379
36385
  for (const id in depsInfo) {
36380
- const flatId = flattenId(id);
36381
- const filePath = (flatIdDeps[flatId] = depsInfo[id].src);
36382
- let exportsData;
36383
- if (config.optimizeDeps.extensions?.some((ext) => filePath.endsWith(ext))) {
36384
- // For custom supported extensions, build the entry file to transform it into JS,
36385
- // and then parse with es-module-lexer. Note that the `bundle` option is not `true`,
36386
- // so only the entry file is being transformed.
36387
- const result = await build$3({
36388
- ...esbuildOptions,
36389
- plugins,
36390
- entryPoints: [filePath],
36391
- write: false,
36392
- format: 'esm'
36393
- });
36394
- exportsData = parse$h(result.outputFiles[0].text);
36395
- }
36396
- else {
36397
- const entryContent = fs__default.readFileSync(filePath, 'utf-8');
36398
- try {
36399
- exportsData = parse$h(entryContent);
36400
- }
36401
- catch {
36402
- const loader = esbuildOptions.loader?.[path$p.extname(filePath)] || 'jsx';
36403
- debug$c(`Unable to parse dependency: ${id}. Trying again with a ${loader} transform.`);
36404
- const transformed = await transformWithEsbuild(entryContent, filePath, {
36405
- loader
36406
- });
36407
- // Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
36408
- // This is useful for packages such as Gatsby.
36409
- esbuildOptions.loader = {
36410
- '.js': 'jsx',
36411
- ...esbuildOptions.loader
36412
- };
36413
- exportsData = parse$h(transformed.code);
36414
- }
36415
- for (const { ss, se } of exportsData[0]) {
36416
- const exp = entryContent.slice(ss, se);
36417
- if (/export\s+\*\s+from/.test(exp)) {
36418
- exportsData.hasReExports = true;
36419
- }
36420
- }
36386
+ const src = depsInfo[id].src;
36387
+ const exportsData = await (depsInfo[id].exportsData ??
36388
+ extractExportsData(src, config));
36389
+ if (exportsData.jsxLoader) {
36390
+ // Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
36391
+ // This is useful for packages such as Gatsby.
36392
+ esbuildOptions.loader = {
36393
+ '.js': 'jsx',
36394
+ ...esbuildOptions.loader
36395
+ };
36421
36396
  }
36397
+ const flatId = flattenId(id);
36398
+ flatIdDeps[flatId] = src;
36422
36399
  idToExports[id] = exportsData;
36423
36400
  flatIdToExports[flatId] = exportsData;
36424
36401
  }
@@ -36455,13 +36432,16 @@ async function runOptimizeDeps(config, depsInfo) {
36455
36432
  const processingCacheDirOutputPath = path$p.relative(process.cwd(), processingCacheDir);
36456
36433
  for (const id in depsInfo) {
36457
36434
  const output = esbuildOutputFromId(meta.outputs, id, processingCacheDir);
36435
+ const { exportsData, ...info } = depsInfo[id];
36458
36436
  addOptimizedDepInfo(metadata, 'optimized', {
36459
- ...depsInfo[id],
36460
- needsInterop: needsInterop(id, idToExports[id], output),
36437
+ ...info,
36461
36438
  // We only need to hash the output.imports in to check for stability, but adding the hash
36462
36439
  // and file path gives us a unique hash that may be useful for other things in the future
36463
36440
  fileHash: getHash(metadata.hash + depsInfo[id].file + JSON.stringify(output.imports)),
36464
- browserHash: metadata.browserHash
36441
+ browserHash: metadata.browserHash,
36442
+ // After bundling we have more information and can warn the user about legacy packages
36443
+ // that require manual configuration
36444
+ needsInterop: needsInterop(config, id, idToExports[id], output)
36465
36445
  });
36466
36446
  }
36467
36447
  for (const o of Object.keys(meta.outputs)) {
@@ -36483,23 +36463,7 @@ async function runOptimizeDeps(config, depsInfo) {
36483
36463
  const dataPath = path$p.join(processingCacheDir, '_metadata.json');
36484
36464
  writeFile(dataPath, stringifyOptimizedDepsMetadata(metadata, depsCacheDir));
36485
36465
  debug$c(`deps bundled in ${(performance.now() - start).toFixed(2)}ms`);
36486
- return {
36487
- metadata,
36488
- commit() {
36489
- // Write metadata file, delete `deps` folder and rename the new `processing` folder to `deps` in sync
36490
- return commitProcessingDepsCacheSync();
36491
- },
36492
- cancel
36493
- };
36494
- async function commitProcessingDepsCacheSync() {
36495
- // Processing is done, we can now replace the depsCacheDir with processingCacheDir
36496
- // Rewire the file paths from the temporal processing dir to the final deps cache dir
36497
- await removeDir(depsCacheDir);
36498
- await renameDir(processingCacheDir, depsCacheDir);
36499
- }
36500
- function cancel() {
36501
- fs__default.rmSync(processingCacheDir, { recursive: true, force: true });
36502
- }
36466
+ return processingResult;
36503
36467
  }
36504
36468
  async function findKnownImports(config) {
36505
36469
  const deps = (await scanImports(config)).deps;
@@ -36638,12 +36602,58 @@ function esbuildOutputFromId(outputs, id, cacheDirOutputPath) {
36638
36602
  const flatId = flattenId(id) + '.js';
36639
36603
  return outputs[normalizePath$3(path$p.relative(process.cwd(), path$p.join(cacheDirOutputPath, flatId)))];
36640
36604
  }
36605
+ async function extractExportsData(filePath, config) {
36606
+ await init;
36607
+ let exportsData;
36608
+ const esbuildOptions = config.optimizeDeps?.esbuildOptions ?? {};
36609
+ if (config.optimizeDeps.extensions?.some((ext) => filePath.endsWith(ext))) {
36610
+ // For custom supported extensions, build the entry file to transform it into JS,
36611
+ // and then parse with es-module-lexer. Note that the `bundle` option is not `true`,
36612
+ // so only the entry file is being transformed.
36613
+ const result = await build$3({
36614
+ ...esbuildOptions,
36615
+ entryPoints: [filePath],
36616
+ write: false,
36617
+ format: 'esm'
36618
+ });
36619
+ exportsData = parse$h(result.outputFiles[0].text);
36620
+ }
36621
+ else {
36622
+ const entryContent = fs__default.readFileSync(filePath, 'utf-8');
36623
+ try {
36624
+ exportsData = parse$h(entryContent);
36625
+ }
36626
+ catch {
36627
+ const loader = esbuildOptions.loader?.[path$p.extname(filePath)] || 'jsx';
36628
+ debug$c(`Unable to parse: ${filePath}.\n Trying again with a ${loader} transform.`);
36629
+ const transformed = await transformWithEsbuild(entryContent, filePath, {
36630
+ loader
36631
+ });
36632
+ // Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
36633
+ // This is useful for packages such as Gatsby.
36634
+ esbuildOptions.loader = {
36635
+ '.js': 'jsx',
36636
+ ...esbuildOptions.loader
36637
+ };
36638
+ exportsData = parse$h(transformed.code);
36639
+ exportsData.jsxLoader = true;
36640
+ }
36641
+ for (const { ss, se } of exportsData[0]) {
36642
+ const exp = entryContent.slice(ss, se);
36643
+ if (/export\s+\*\s+from/.test(exp)) {
36644
+ exportsData.hasReExports = true;
36645
+ }
36646
+ }
36647
+ }
36648
+ return exportsData;
36649
+ }
36641
36650
  // https://github.com/vitejs/vite/issues/1724#issuecomment-767619642
36642
36651
  // a list of modules that pretends to be ESM but still uses `require`.
36643
36652
  // this causes esbuild to wrap them as CJS even when its entry appears to be ESM.
36644
36653
  const KNOWN_INTEROP_IDS = new Set(['moment']);
36645
- function needsInterop(id, exportsData, output) {
36646
- if (KNOWN_INTEROP_IDS.has(id)) {
36654
+ function needsInterop(config, id, exportsData, output) {
36655
+ if (config.optimizeDeps?.needsInterop?.includes(id) ||
36656
+ KNOWN_INTEROP_IDS.has(id)) {
36647
36657
  return true;
36648
36658
  }
36649
36659
  const [imports, exports] = exportsData;
@@ -36651,13 +36661,16 @@ function needsInterop(id, exportsData, output) {
36651
36661
  if (!exports.length && !imports.length) {
36652
36662
  return true;
36653
36663
  }
36654
- // if a peer dependency used require() on a ESM dependency, esbuild turns the
36655
- // ESM dependency's entry chunk into a single default export... detect
36656
- // such cases by checking exports mismatch, and force interop.
36657
- const generatedExports = output.exports;
36658
- if (!generatedExports ||
36659
- (isSingleDefaultExport(generatedExports) && !isSingleDefaultExport(exports))) {
36660
- return true;
36664
+ if (output) {
36665
+ // if a peer dependency used require() on a ESM dependency, esbuild turns the
36666
+ // ESM dependency's entry chunk into a single default export... detect
36667
+ // such cases by checking exports mismatch, and force interop.
36668
+ const generatedExports = output.exports;
36669
+ if (!generatedExports ||
36670
+ (isSingleDefaultExport(generatedExports) &&
36671
+ !isSingleDefaultExport(exports))) {
36672
+ return true;
36673
+ }
36661
36674
  }
36662
36675
  return false;
36663
36676
  }
@@ -36710,12 +36723,12 @@ function findOptimizedDepInfoInRecord(dependenciesInfo, callbackFn) {
36710
36723
  }
36711
36724
  }
36712
36725
  }
36713
- async function optimizedDepNeedsInterop(metadata, file) {
36726
+ async function optimizedDepNeedsInterop(metadata, file, config) {
36714
36727
  const depInfo = optimizedDepInfoFromFile(metadata, file);
36715
- if (!depInfo)
36716
- return undefined;
36717
- // Wait until the dependency has been pre-bundled
36718
- await depInfo.processing;
36728
+ if (depInfo?.src && depInfo.needsInterop === undefined) {
36729
+ depInfo.exportsData ?? (depInfo.exportsData = extractExportsData(depInfo.src, config));
36730
+ depInfo.needsInterop = needsInterop(config, depInfo.id, await depInfo.exportsData);
36731
+ }
36719
36732
  return depInfo?.needsInterop;
36720
36733
  }
36721
36734
 
@@ -36736,6 +36749,7 @@ var index$1 = {
36736
36749
  getDepsCacheDir: getDepsCacheDir,
36737
36750
  isOptimizedDepFile: isOptimizedDepFile,
36738
36751
  createIsOptimizedDepUrl: createIsOptimizedDepUrl,
36752
+ extractExportsData: extractExportsData,
36739
36753
  getDepHash: getDepHash,
36740
36754
  optimizedDepInfoFromId: optimizedDepInfoFromId,
36741
36755
  optimizedDepInfoFromFile: optimizedDepInfoFromFile,
@@ -44633,7 +44647,7 @@ async function getCertificate(cacheDir) {
44633
44647
  return content;
44634
44648
  }
44635
44649
  catch {
44636
- const content = (await import('./dep-5eede05c.js')).createCertificate();
44650
+ const content = (await import('./dep-ce833324.js')).createCertificate();
44637
44651
  promises
44638
44652
  .mkdir(cacheDir, { recursive: true })
44639
44653
  .then(() => promises.writeFile(cachePath, content))
@@ -46563,11 +46577,25 @@ function createOptimizedDeps(server) {
46563
46577
  try {
46564
46578
  const processingResult = await runOptimizeDeps(config, newDeps);
46565
46579
  const newData = processingResult.metadata;
46580
+ const needsInteropMismatch = [];
46581
+ for (const dep in metadata.discovered) {
46582
+ const discoveredDepInfo = metadata.discovered[dep];
46583
+ const depInfo = newData.optimized[dep];
46584
+ if (depInfo) {
46585
+ if (discoveredDepInfo.needsInterop !== undefined &&
46586
+ depInfo.needsInterop !== discoveredDepInfo.needsInterop) {
46587
+ // This only happens when a discovered dependency has mixed ESM and CJS syntax
46588
+ // and it hasn't been manually added to optimizeDeps.needsInterop
46589
+ needsInteropMismatch.push(dep);
46590
+ }
46591
+ }
46592
+ }
46566
46593
  // After a re-optimization, if the internal bundled chunks change a full page reload
46567
46594
  // is required. If the files are stable, we can avoid the reload that is expensive
46568
46595
  // for large applications. Comparing their fileHash we can find out if it is safe to
46569
46596
  // keep the current browser state.
46570
- const needsReload = metadata.hash !== newData.hash ||
46597
+ const needsReload = needsInteropMismatch.length > 0 ||
46598
+ metadata.hash !== newData.hash ||
46571
46599
  Object.keys(metadata.optimized).some((dep) => {
46572
46600
  return (metadata.optimized[dep].fileHash !== newData.optimized[dep].fileHash);
46573
46601
  });
@@ -46647,6 +46675,11 @@ function createOptimizedDeps(server) {
46647
46675
  logger.info(colors$1.green(`✨ optimized dependencies changed. reloading`), {
46648
46676
  timestamp: true
46649
46677
  });
46678
+ if (needsInteropMismatch.length > 0) {
46679
+ config.logger.warn(`Mixed ESM and CJS detected in ${colors$1.yellow(needsInteropMismatch.join(', '))}, add ${needsInteropMismatch.length === 1 ? 'it' : 'them'} to optimizeDeps.needsInterop to speed up cold start`, {
46680
+ timestamp: true
46681
+ });
46682
+ }
46650
46683
  fullReload();
46651
46684
  }
46652
46685
  }
@@ -46716,7 +46749,8 @@ function createOptimizedDeps(server) {
46716
46749
  browserHash: getDiscoveredBrowserHash(metadata.hash, depsFromOptimizedDepInfo(metadata.optimized), depsFromOptimizedDepInfo(metadata.discovered)),
46717
46750
  // loading of this pre-bundled dep needs to await for its processing
46718
46751
  // promise to be resolved
46719
- processing: depOptimizationProcessing.promise
46752
+ processing: depOptimizationProcessing.promise,
46753
+ exportsData: extractExportsData(resolved, config)
46720
46754
  });
46721
46755
  // Debounced rerun, let other missing dependencies be discovered before
46722
46756
  // the running next optimizeDeps
@@ -54452,10 +54486,6 @@ function importAnalysisPlugin(config) {
54452
54486
  }
54453
54487
  return [url, resolved.id];
54454
54488
  };
54455
- // Import rewrites, we do them after all the URLs have been resolved
54456
- // to help with the discovery of new dependencies. If we need to wait
54457
- // for each dependency there could be one reload per import
54458
- const importRewrites = [];
54459
54489
  for (let index = 0; index < imports.length; index++) {
54460
54490
  const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex,
54461
54491
  // #2083 User may use escape path,
@@ -54517,51 +54547,51 @@ function importAnalysisPlugin(config) {
54517
54547
  // record as safe modules
54518
54548
  server?.moduleGraph.safeModulesPath.add(fsPathFromUrl(url));
54519
54549
  if (url !== specifier) {
54520
- importRewrites.push(async () => {
54521
- let rewriteDone = false;
54522
- if (server?._optimizedDeps &&
54523
- isOptimizedDepFile(resolvedId, config) &&
54524
- !resolvedId.match(optimizedDepChunkRE)) {
54525
- // for optimized cjs deps, support named imports by rewriting named imports to const assignments.
54526
- // internal optimized chunks don't need es interop and are excluded
54527
- // The browserHash in resolvedId could be stale in which case there will be a full
54528
- // page reload. We could return a 404 in that case but it is safe to return the request
54529
- const file = cleanUrl(resolvedId); // Remove ?v={hash}
54530
- const needsInterop = await optimizedDepNeedsInterop(server._optimizedDeps.metadata, file);
54531
- if (needsInterop === undefined) {
54532
- // Non-entry dynamic imports from dependencies will reach here as there isn't
54533
- // optimize info for them, but they don't need es interop. If the request isn't
54534
- // a dynamic import, then it is an internal Vite error
54535
- if (!file.match(optimizedDepDynamicRE)) {
54536
- config.logger.error(colors$1.red(`Vite Error, ${url} optimized info should be defined`));
54537
- }
54550
+ let rewriteDone = false;
54551
+ if (server?._optimizedDeps &&
54552
+ isOptimizedDepFile(resolvedId, config) &&
54553
+ !resolvedId.match(optimizedDepChunkRE)) {
54554
+ // for optimized cjs deps, support named imports by rewriting named imports to const assignments.
54555
+ // internal optimized chunks don't need es interop and are excluded
54556
+ // The browserHash in resolvedId could be stale in which case there will be a full
54557
+ // page reload. We could return a 404 in that case but it is safe to return the request
54558
+ const file = cleanUrl(resolvedId); // Remove ?v={hash}
54559
+ const needsInterop = await optimizedDepNeedsInterop(server._optimizedDeps.metadata, file, config);
54560
+ if (needsInterop === undefined) {
54561
+ // Non-entry dynamic imports from dependencies will reach here as there isn't
54562
+ // optimize info for them, but they don't need es interop. If the request isn't
54563
+ // a dynamic import, then it is an internal Vite error
54564
+ if (!file.match(optimizedDepDynamicRE)) {
54565
+ config.logger.error(colors$1.red(`Vite Error, ${url} optimized info should be defined`));
54566
+ }
54567
+ }
54568
+ else if (needsInterop) {
54569
+ debug$1(`${url} needs interop`);
54570
+ if (isDynamicImport) {
54571
+ // rewrite `import('package')` to expose the default directly
54572
+ str().overwrite(expStart, expEnd, `import('${url}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`, { contentOnly: true });
54538
54573
  }
54539
- else if (needsInterop) {
54540
- debug$1(`${url} needs interop`);
54541
- if (isDynamicImport) {
54542
- // rewrite `import('package')` to expose the default directly
54543
- str().overwrite(expStart, expEnd, `import('${url}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`, { contentOnly: true });
54574
+ else {
54575
+ const exp = source.slice(expStart, expEnd);
54576
+ const rewritten = transformCjsImport(exp, url, rawUrl, index);
54577
+ if (rewritten) {
54578
+ str().overwrite(expStart, expEnd, rewritten, {
54579
+ contentOnly: true
54580
+ });
54544
54581
  }
54545
54582
  else {
54546
- const exp = source.slice(expStart, expEnd);
54547
- const rewritten = transformCjsImport(exp, url, rawUrl, index);
54548
- if (rewritten) {
54549
- str().overwrite(expStart, expEnd, rewritten, {
54550
- contentOnly: true
54551
- });
54552
- }
54553
- else {
54554
- // #1439 export * from '...'
54555
- str().overwrite(start, end, url, { contentOnly: true });
54556
- }
54583
+ // #1439 export * from '...'
54584
+ str().overwrite(start, end, url, { contentOnly: true });
54557
54585
  }
54558
- rewriteDone = true;
54559
54586
  }
54587
+ rewriteDone = true;
54560
54588
  }
54561
- if (!rewriteDone) {
54562
- str().overwrite(start, end, isDynamicImport ? `'${url}'` : url, { contentOnly: true });
54563
- }
54564
- });
54589
+ }
54590
+ if (!rewriteDone) {
54591
+ str().overwrite(start, end, isDynamicImport ? `'${url}'` : url, {
54592
+ contentOnly: true
54593
+ });
54594
+ }
54565
54595
  }
54566
54596
  // record for HMR import chain analysis
54567
54597
  // make sure to normalize away base
@@ -54671,13 +54701,6 @@ function importAnalysisPlugin(config) {
54671
54701
  });
54672
54702
  });
54673
54703
  }
54674
- // Await for import rewrites that requires dependencies to be pre-bundled to
54675
- // know if es interop is needed after starting further transformRequest calls
54676
- // This will let Vite process deeper into the user code and find more missing
54677
- // dependencies before the next page reload
54678
- for (const rewrite of importRewrites) {
54679
- await rewrite();
54680
- }
54681
54704
  if (s) {
54682
54705
  return {
54683
54706
  code: s.toString(),
@@ -1,4 +1,4 @@
1
- import { v as commonjsGlobal } from './dep-6f5ac69c.js';
1
+ import { v as commonjsGlobal } from './dep-aea1d487.js';
2
2
  import require$$1 from 'crypto';
3
3
  import 'fs';
4
4
  import 'path';
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { u as colors, i as createLogger, e as resolveConfig } from './chunks/dep-6f5ac69c.js';
3
+ import { u as colors, i as createLogger, e as resolveConfig } from './chunks/dep-aea1d487.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'fs';
6
6
  import 'path';
@@ -682,7 +682,7 @@ cli
682
682
  .action(async (root, options) => {
683
683
  // output structure is preserved even after bundling so require()
684
684
  // is ok here
685
- const { createServer } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.A; });
685
+ const { createServer } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.A; });
686
686
  try {
687
687
  const server = await createServer({
688
688
  root,
@@ -727,7 +727,7 @@ cli
727
727
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
728
728
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
729
729
  .action(async (root, options) => {
730
- const { build } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.z; });
730
+ const { build } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.z; });
731
731
  const buildOptions = cleanOptions(options);
732
732
  try {
733
733
  await build({
@@ -750,7 +750,7 @@ cli
750
750
  .command('optimize [root]', 'pre-bundle dependencies')
751
751
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
752
752
  .action(async (root, options) => {
753
- const { optimizeDeps } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.y; });
753
+ const { optimizeDeps } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.y; });
754
754
  try {
755
755
  const config = await resolveConfig({
756
756
  root,
@@ -773,7 +773,7 @@ cli
773
773
  .option('--https', `[boolean] use TLS + HTTP/2`)
774
774
  .option('--open [path]', `[boolean | string] open browser on startup`)
775
775
  .action(async (root, options) => {
776
- const { preview } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.B; });
776
+ const { preview } = await import('./chunks/dep-aea1d487.js').then(function (n) { return n.B; });
777
777
  try {
778
778
  const server = await preview({
779
779
  root,
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
 
4
- var version = "3.0.0-alpha.3";
4
+ var version = "3.0.0-alpha.4";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -23,6 +23,7 @@ import type * as net from 'net';
23
23
  import type { OutgoingHttpHeaders } from 'http';
24
24
  import type { OutputBundle } from 'rollup';
25
25
  import type { OutputChunk } from 'rollup';
26
+ import { parse } from 'es-module-lexer';
26
27
  import type { PartialResolvedId } from 'rollup';
27
28
  import type { Plugin as Plugin_3 } from 'rollup';
28
29
  import type { PluginContext } from 'rollup';
@@ -543,6 +544,12 @@ export declare interface DepOptimizationOptions {
543
544
  * cannot be globs).
544
545
  */
545
546
  exclude?: string[];
547
+ /**
548
+ * Force ESM interop when importing for these dependencies. Some legacy
549
+ * packages advertise themselves as ESM but use `require` internally
550
+ * @experimental
551
+ */
552
+ needsInterop?: string[];
546
553
  /**
547
554
  * Options to pass to esbuild during the dep scanning and optimization
548
555
  *
@@ -629,6 +636,11 @@ export declare interface ExperimentalOptions {
629
636
  importGlobRestoreExtension?: boolean;
630
637
  }
631
638
 
639
+ export declare type ExportsData = ReturnType<typeof parse> & {
640
+ hasReExports?: true;
641
+ jsxLoader?: true;
642
+ };
643
+
632
644
  export declare interface FileSystemServeOptions {
633
645
  /**
634
646
  * Strictly restrict file accessing outside of allowing paths.
@@ -1281,6 +1293,11 @@ export declare interface OptimizedDepInfo {
1281
1293
  * but the bundles may not yet be saved to disk
1282
1294
  */
1283
1295
  processing?: Promise<void>;
1296
+ /**
1297
+ * ExportData cache, discovered deps will parse the src entry to get exports
1298
+ * data used both to define if interop is needed and when pre-bundling
1299
+ */
1300
+ exportsData?: Promise<ExportsData>;
1284
1301
  }
1285
1302
 
1286
1303
  export declare interface OptimizedDeps {
@@ -1,4 +1,4 @@
1
- export { b as build, i as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, l as loadConfigFromFile, k as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, q as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, j as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-6f5ac69c.js';
1
+ export { b as build, i as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, l as loadConfigFromFile, k as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, q as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, j as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-aea1d487.js';
2
2
  import 'fs';
3
3
  import 'path';
4
4
  import 'url';
@@ -4,6 +4,7 @@ import type { ResolvedConfig } from '../config';
4
4
  export declare const debuggerViteDeps: (...args: any[]) => any;
5
5
  export declare type ExportsData = ReturnType<typeof parse> & {
6
6
  hasReExports?: true;
7
+ jsxLoader?: true;
7
8
  };
8
9
  export interface OptimizedDeps {
9
10
  metadata: DepOptimizationMetadata;
@@ -32,6 +33,12 @@ export interface DepOptimizationOptions {
32
33
  * cannot be globs).
33
34
  */
34
35
  exclude?: string[];
36
+ /**
37
+ * Force ESM interop when importing for these dependencies. Some legacy
38
+ * packages advertise themselves as ESM but use `require` internally
39
+ * @experimental
40
+ */
41
+ needsInterop?: string[];
35
42
  /**
36
43
  * Options to pass to esbuild during the dep scanning and optimization
37
44
  *
@@ -87,6 +94,11 @@ export interface OptimizedDepInfo {
87
94
  * but the bundles may not yet be saved to disk
88
95
  */
89
96
  processing?: Promise<void>;
97
+ /**
98
+ * ExportData cache, discovered deps will parse the src entry to get exports
99
+ * data used both to define if interop is needed and when pre-bundling
100
+ */
101
+ exportsData?: Promise<ExportsData>;
90
102
  }
91
103
  export interface DepOptimizationMetadata {
92
104
  /**
@@ -148,7 +160,8 @@ export declare function getOptimizedDepPath(id: string, config: ResolvedConfig):
148
160
  export declare function getDepsCacheDir(config: ResolvedConfig): string;
149
161
  export declare function isOptimizedDepFile(id: string, config: ResolvedConfig): boolean;
150
162
  export declare function createIsOptimizedDepUrl(config: ResolvedConfig): (url: string) => boolean;
163
+ export declare function extractExportsData(filePath: string, config: ResolvedConfig): Promise<ExportsData>;
151
164
  export declare function getDepHash(config: ResolvedConfig): string;
152
165
  export declare function optimizedDepInfoFromId(metadata: DepOptimizationMetadata, id: string): OptimizedDepInfo | undefined;
153
166
  export declare function optimizedDepInfoFromFile(metadata: DepOptimizationMetadata, file: string): OptimizedDepInfo | undefined;
154
- export declare function optimizedDepNeedsInterop(metadata: DepOptimizationMetadata, file: string): Promise<boolean | undefined>;
167
+ export declare function optimizedDepNeedsInterop(metadata: DepOptimizationMetadata, file: string, config: ResolvedConfig): Promise<boolean | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -20,6 +20,7 @@
20
20
  "./client": {
21
21
  "types": "./client.d.ts"
22
22
  },
23
+ "./dist/client/*": "./dist/client/*",
23
24
  "./terser": {
24
25
  "require": "./dist/node-cjs/terser.cjs"
25
26
  }