vite 4.0.0-alpha.1 → 4.0.0-alpha.2

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$1 from 'postcss';
2
- import { A as commonjsGlobal } from './dep-7d777026.js';
2
+ import { A as commonjsGlobal } from './dep-b8ca7cde.js';
3
3
  import require$$0 from 'path';
4
4
  import require$$5 from 'crypto';
5
5
  import require$$0__default from 'fs';
@@ -11974,16 +11974,10 @@ function writeFile(filename, content) {
11974
11974
  }
11975
11975
  fs$l.writeFileSync(filename, content);
11976
11976
  }
11977
- /**
11978
- * Use fs.statSync(filename) instead of fs.existsSync(filename)
11979
- * #2051 if we don't have read permission on a directory, existsSync() still
11980
- * works and will result in massively slow subsequent checks (which are
11981
- * unnecessary in the first place)
11982
- */
11983
11977
  function isFileReadable(filename) {
11984
11978
  try {
11985
- const stat = fs$l.statSync(filename, { throwIfNoEntry: false });
11986
- return !!stat;
11979
+ fs$l.accessSync(filename, fs$l.constants.R_OK);
11980
+ return true;
11987
11981
  }
11988
11982
  catch {
11989
11983
  return false;
@@ -12492,18 +12486,22 @@ const isNonDriveRelativeAbsolutePath = (p) => {
12492
12486
  * consistent behaviour between dev and prod and across operating systems.
12493
12487
  */
12494
12488
  function shouldServe(url, assetsDir) {
12495
- // viteTestUrl is set to something like http://localhost:4173/ and then many tests make calls
12496
- // like `await page.goto(viteTestUrl + '/example')` giving us URLs beginning with a double slash
12497
- const pathname = decodeURI(new URL$3(url.startsWith('//') ? url.substring(1) : url, 'http://example.com')
12498
- .pathname);
12499
- const file = path$o.join(assetsDir, pathname);
12500
- if (!fs$l.existsSync(file) ||
12501
- (isCaseInsensitiveFS && // can skip case check on Linux
12502
- !fs$l.statSync(file).isDirectory() &&
12503
- !hasCorrectCase(file, assetsDir))) {
12489
+ try {
12490
+ // viteTestUrl is set to something like http://localhost:4173/ and then many tests make calls
12491
+ // like `await page.goto(viteTestUrl + '/example')` giving us URLs beginning with a double slash
12492
+ const pathname = decodeURI(new URL$3(url.startsWith('//') ? url.substring(1) : url, 'http://example.com').pathname);
12493
+ const file = path$o.join(assetsDir, pathname);
12494
+ if (!fs$l.existsSync(file) ||
12495
+ (isCaseInsensitiveFS && // can skip case check on Linux
12496
+ !fs$l.statSync(file).isDirectory() &&
12497
+ !hasCorrectCase(file, assetsDir))) {
12498
+ return false;
12499
+ }
12500
+ return true;
12501
+ }
12502
+ catch (err) {
12504
12503
  return false;
12505
12504
  }
12506
- return true;
12507
12505
  }
12508
12506
  /**
12509
12507
  * Note that we can't use realpath here, because we don't want to follow
@@ -32325,14 +32323,13 @@ function lookup(extn) {
32325
32323
  return mimes$1[!~idx ? tmp : tmp.substring(++idx)];
32326
32324
  }
32327
32325
 
32328
- const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g;
32329
- const duplicateAssets = new WeakMap();
32326
+ const assetUrlRE = /__VITE_ASSET__([a-z\d]+)__(?:\$_(.*?)__)?/g;
32330
32327
  const rawRE = /(\?|&)raw(?:&|$)/;
32331
32328
  const urlRE = /(\?|&)url(?:&|$)/;
32332
32329
  const assetCache = new WeakMap();
32333
- const assetHashToFilenameMap = new WeakMap();
32334
- // save hashes of the files that has been emitted in build watch
32335
- const emittedHashMap = new WeakMap();
32330
+ // chunk.name is the basename for the asset ignoring the directory structure
32331
+ // For the manifest, we need to preserve the original file path
32332
+ const generatedAssets = new WeakMap();
32336
32333
  // add own dictionary entry by directly assigning mrmime
32337
32334
  function registerCustomMime() {
32338
32335
  // https://github.com/lukeed/mrmime/issues/3
@@ -32355,10 +32352,8 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
32355
32352
  // In both cases, the wrapping should already be fine
32356
32353
  while ((match = assetUrlRE.exec(code))) {
32357
32354
  s || (s = new MagicString(code));
32358
- const [full, hash, postfix = ''] = match;
32359
- // some internal plugins may still need to emit chunks (e.g. worker) so
32360
- // fallback to this.getFileName for that. TODO: remove, not needed
32361
- const file = getAssetFilename(hash, config) || ctx.getFileName(hash);
32355
+ const [full, referenceId, postfix = ''] = match;
32356
+ const file = ctx.getFileName(referenceId);
32362
32357
  chunk.viteMetadata.importedAssets.add(cleanUrl(file));
32363
32358
  const filename = file + postfix;
32364
32359
  const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', config, toRelativeRuntime);
@@ -32385,15 +32380,12 @@ function renderAssetUrlInJS(ctx, config, chunk, opts, code) {
32385
32380
  * Also supports loading plain strings with import text from './foo.txt?raw'
32386
32381
  */
32387
32382
  function assetPlugin(config) {
32388
- // assetHashToFilenameMap initialization in buildStart causes getAssetFilename to return undefined
32389
- assetHashToFilenameMap.set(config, new Map());
32390
32383
  registerCustomMime();
32391
32384
  return {
32392
32385
  name: 'vite:asset',
32393
32386
  buildStart() {
32394
32387
  assetCache.set(config, new Map());
32395
- emittedHashMap.set(config, new Set());
32396
- duplicateAssets.set(config, new Map());
32388
+ generatedAssets.set(config, new Map());
32397
32389
  },
32398
32390
  resolveId(id) {
32399
32391
  if (!config.assetsInclude(cleanUrl(id))) {
@@ -32490,9 +32482,6 @@ function fileToDevUrl(id, config) {
32490
32482
  const base = joinUrlSegments(config.server?.origin ?? '', config.base);
32491
32483
  return joinUrlSegments(base, rtn.replace(/^\//, ''));
32492
32484
  }
32493
- function getAssetFilename(hash, config) {
32494
- return assetHashToFilenameMap.get(config)?.get(hash);
32495
- }
32496
32485
  function getPublicAssetFilename(hash, config) {
32497
32486
  return publicAssetUrlCache.get(config)?.get(hash);
32498
32487
  }
@@ -32637,41 +32626,17 @@ async function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false
32637
32626
  }
32638
32627
  else {
32639
32628
  // emit as asset
32640
- // rollup supports `import.meta.ROLLUP_FILE_URL_*`, but it generates code
32641
- // that uses runtime url sniffing and it can be verbose when targeting
32642
- // non-module format. It also fails to cascade the asset content change
32643
- // into the chunk's hash, so we have to do our own content hashing here.
32644
- // https://bundlers.tooling.report/hashing/asset-cascade/
32645
- // https://github.com/rollup/rollup/issues/3415
32646
- const map = assetHashToFilenameMap.get(config);
32647
- const contentHash = getHash(content);
32648
32629
  const { search, hash } = parse$j(id);
32649
32630
  const postfix = (search || '') + (hash || '');
32650
- const fileName = assetFileNamesToFileName(resolveAssetFileNames(config), file, contentHash, content);
32651
- if (!map.has(contentHash)) {
32652
- map.set(contentHash, fileName);
32653
- }
32654
- const emittedSet = emittedHashMap.get(config);
32655
- const duplicates = duplicateAssets.get(config);
32656
- const name = normalizePath$3(path$o.relative(config.root, file));
32657
- if (!emittedSet.has(contentHash)) {
32658
- pluginContext.emitFile({
32659
- name,
32660
- fileName,
32661
- type: 'asset',
32662
- source: content
32663
- });
32664
- emittedSet.add(contentHash);
32665
- }
32666
- else {
32667
- duplicates.set(name, {
32668
- name,
32669
- fileName: map.get(contentHash),
32670
- type: 'asset',
32671
- source: content
32672
- });
32673
- }
32674
- url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}`; // TODO_BASE
32631
+ const referenceId = pluginContext.emitFile({
32632
+ // Ignore directory structure for asset file names
32633
+ name: path$o.basename(file),
32634
+ type: 'asset',
32635
+ source: content
32636
+ });
32637
+ const originalName = normalizePath$3(path$o.relative(config.root, file));
32638
+ generatedAssets.get(config).set(referenceId, { originalName });
32639
+ url = `__VITE_ASSET__${referenceId}__${postfix ? `$_${postfix}__` : ``}`; // TODO_BASE
32675
32640
  }
32676
32641
  cache.set(id, url);
32677
32642
  return url;
@@ -33747,9 +33712,6 @@ function tryFsResolve(fsPath, options, tryIndex = true, targetWeb = true) {
33747
33712
  }
33748
33713
  }
33749
33714
  function tryResolveFile(file, postfix, options, tryIndex, targetWeb, tryPrefix, skipPackageJson) {
33750
- // #2051 if we don't have read permission on a directory, existsSync() still
33751
- // works and will result in massively slow subsequent checks (which are
33752
- // unnecessary in the first place)
33753
33715
  if (isFileReadable(file)) {
33754
33716
  if (!fs$l.statSync(file).isDirectory()) {
33755
33717
  return getRealPath(file, options.preserveSymlinks) + postfix;
@@ -35501,9 +35463,8 @@ function updateModules(file, modules, timestamp, { config, ws }) {
35501
35463
  debugHmr(picocolors.exports.yellow(`no update happened `) + picocolors.exports.dim(file));
35502
35464
  return;
35503
35465
  }
35504
- config.logger.info(updates
35505
- .map(({ path }) => picocolors.exports.green(`hmr update `) + picocolors.exports.dim(path))
35506
- .join('\n'), { clear: true, timestamp: true });
35466
+ config.logger.info(picocolors.exports.green(`hmr update `) +
35467
+ picocolors.exports.dim([...new Set(updates.map((u) => u.path))].join(', ')), { clear: true, timestamp: true });
35507
35468
  ws.send({
35508
35469
  type: 'update',
35509
35470
  updates
@@ -43059,7 +43020,7 @@ function buildHtmlPlugin(config) {
43059
43020
  });
43060
43021
  // resolve asset url references
43061
43022
  result = result.replace(assetUrlRE, (_, fileHash, postfix = '') => {
43062
- return (toOutputAssetFilePath(getAssetFilename(fileHash, config)) + postfix);
43023
+ return toOutputAssetFilePath(this.getFileName(fileHash)) + postfix;
43063
43024
  });
43064
43025
  result = result.replace(publicAssetUrlRE, (_, fileHash) => {
43065
43026
  return normalizePath$3(toOutputPublicAssetFilePath(getPublicAssetFilename(fileHash, config)));
@@ -43555,7 +43516,7 @@ function cssPostPlugin(config) {
43555
43516
  const cssEntryFiles = cssEntryFilesCache.get(config);
43556
43517
  const publicAssetUrlMap = publicAssetUrlCache.get(config);
43557
43518
  // resolve asset URL placeholders to their built file URLs
43558
- function resolveAssetUrlsInCss(chunkCSS, cssAssetName) {
43519
+ const resolveAssetUrlsInCss = (chunkCSS, cssAssetName) => {
43559
43520
  const encodedPublicUrls = encodePublicUrlsInCSS(config);
43560
43521
  const relative = config.base === './' || config.base === '';
43561
43522
  const cssAssetDirname = encodedPublicUrls || relative
@@ -43570,7 +43531,7 @@ function cssPostPlugin(config) {
43570
43531
  };
43571
43532
  // replace asset url references with resolved url.
43572
43533
  chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => {
43573
- const filename = getAssetFilename(fileHash, config) + postfix;
43534
+ const filename = this.getFileName(fileHash) + postfix;
43574
43535
  chunk.viteMetadata.importedAssets.add(cleanUrl(filename));
43575
43536
  return toOutputFilePathInCss(filename, 'asset', cssAssetName, 'css', config, toRelative);
43576
43537
  });
@@ -43583,7 +43544,7 @@ function cssPostPlugin(config) {
43583
43544
  });
43584
43545
  }
43585
43546
  return chunkCSS;
43586
- }
43547
+ };
43587
43548
  function ensureFileExt(name, ext) {
43588
43549
  return normalizePath$3(path$o.format({ ...path$o.parse(name), base: undefined, ext }));
43589
43550
  }
@@ -43853,10 +43814,9 @@ async function compileCSS(id, code, config, urlReplacer) {
43853
43814
  }));
43854
43815
  }
43855
43816
  if (isModule) {
43856
- postcssPlugins.unshift((await import('./dep-6d760e82.js').then(function (n) { return n.i; })).default({
43817
+ postcssPlugins.unshift((await import('./dep-2a67faac.js').then(function (n) { return n.i; })).default({
43857
43818
  ...modulesOptions,
43858
- // TODO: convert null to undefined (`null` should be removed from `CSSModulesOptions.localsConvention`)
43859
- localsConvention: modulesOptions?.localsConvention ?? undefined,
43819
+ localsConvention: modulesOptions?.localsConvention,
43860
43820
  getJSON(cssFileName, _modules, outputFileName) {
43861
43821
  modules = _modules;
43862
43822
  if (modulesOptions && typeof modulesOptions.getJSON === 'function') {
@@ -44620,28 +44580,43 @@ function manifestPlugin(config) {
44620
44580
  }
44621
44581
  return manifestChunk;
44622
44582
  }
44623
- function createAsset(chunk) {
44583
+ function createAsset(chunk, src) {
44624
44584
  const manifestChunk = {
44625
44585
  file: chunk.fileName,
44626
- src: chunk.name
44586
+ src
44627
44587
  };
44628
44588
  if (cssEntryFiles.has(chunk.name))
44629
44589
  manifestChunk.isEntry = true;
44630
44590
  return manifestChunk;
44631
44591
  }
44632
44592
  const cssEntryFiles = cssEntryFilesCache.get(config);
44593
+ const fileNameToAssetMeta = new Map();
44594
+ generatedAssets.get(config).forEach((asset, referenceId) => {
44595
+ const fileName = this.getFileName(referenceId);
44596
+ fileNameToAssetMeta.set(fileName, asset);
44597
+ });
44598
+ const fileNameToAsset = new Map();
44633
44599
  for (const file in bundle) {
44634
44600
  const chunk = bundle[file];
44635
44601
  if (chunk.type === 'chunk') {
44636
44602
  manifest[getChunkName(chunk)] = createChunk(chunk);
44637
44603
  }
44638
44604
  else if (chunk.type === 'asset' && typeof chunk.name === 'string') {
44639
- manifest[chunk.name] = createAsset(chunk);
44605
+ // Add every unique asset to the manifest, keyed by its original name
44606
+ const src = fileNameToAssetMeta.get(chunk.fileName)?.originalName ?? chunk.name;
44607
+ const asset = createAsset(chunk, src);
44608
+ manifest[src] = asset;
44609
+ fileNameToAsset.set(chunk.fileName, asset);
44610
+ }
44611
+ }
44612
+ // Add duplicate assets to the manifest
44613
+ fileNameToAssetMeta.forEach(({ originalName }, fileName) => {
44614
+ if (!manifest[originalName]) {
44615
+ const asset = fileNameToAsset.get(fileName);
44616
+ if (asset) {
44617
+ manifest[originalName] = asset;
44618
+ }
44640
44619
  }
44641
- }
44642
- duplicateAssets.get(config).forEach((asset) => {
44643
- const chunk = createAsset(asset);
44644
- manifest[asset.name] = chunk;
44645
44620
  });
44646
44621
  outputCount++;
44647
44622
  const output = config.build.rollupOptions?.output;
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { z as picocolors, v as createLogger, g as resolveConfig } from './chunks/dep-7d777026.js';
5
+ import { z as picocolors, v as createLogger, g as resolveConfig } from './chunks/dep-b8ca7cde.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:url';
8
8
  import 'node:module';
@@ -719,7 +719,7 @@ cli
719
719
  filterDuplicateOptions(options);
720
720
  // output structure is preserved even after bundling so require()
721
721
  // is ok here
722
- const { createServer } = await import('./chunks/dep-7d777026.js').then(function (n) { return n.D; });
722
+ const { createServer } = await import('./chunks/dep-b8ca7cde.js').then(function (n) { return n.D; });
723
723
  try {
724
724
  const server = await createServer({
725
725
  root,
@@ -772,7 +772,7 @@ cli
772
772
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
773
773
  .action(async (root, options) => {
774
774
  filterDuplicateOptions(options);
775
- const { build } = await import('./chunks/dep-7d777026.js').then(function (n) { return n.C; });
775
+ const { build } = await import('./chunks/dep-b8ca7cde.js').then(function (n) { return n.C; });
776
776
  const buildOptions = cleanOptions(options);
777
777
  try {
778
778
  await build({
@@ -800,7 +800,7 @@ cli
800
800
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
801
801
  .action(async (root, options) => {
802
802
  filterDuplicateOptions(options);
803
- const { optimizeDeps } = await import('./chunks/dep-7d777026.js').then(function (n) { return n.B; });
803
+ const { optimizeDeps } = await import('./chunks/dep-b8ca7cde.js').then(function (n) { return n.B; });
804
804
  try {
805
805
  const config = await resolveConfig({
806
806
  root,
@@ -825,7 +825,7 @@ cli
825
825
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
826
826
  .action(async (root, options) => {
827
827
  filterDuplicateOptions(options);
828
- const { preview } = await import('./chunks/dep-7d777026.js').then(function (n) { return n.E; });
828
+ const { preview } = await import('./chunks/dep-b8ca7cde.js').then(function (n) { return n.E; });
829
829
  try {
830
830
  const server = await preview({
831
831
  root,
@@ -498,9 +498,9 @@ export declare interface CSSModulesOptions {
498
498
  generateScopedName?: string | ((name: string, filename: string, css: string) => string);
499
499
  hashPrefix?: string;
500
500
  /**
501
- * default: null
501
+ * default: undefined
502
502
  */
503
- localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly' | null;
503
+ localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
504
504
  }
505
505
 
506
506
  export declare interface CSSOptions {
@@ -1,4 +1,4 @@
1
- export { b as build, q as createFilter, v as createLogger, c as createServer, e as defineConfig, f as formatPostcssSourceMap, i as getDepOptimizationConfig, j as isDepsOptimizerEnabled, l as loadConfigFromFile, x as loadEnv, k as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, h as resolveBaseUrl, g as resolveConfig, y as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-7d777026.js';
1
+ export { b as build, q as createFilter, v as createLogger, c as createServer, e as defineConfig, f as formatPostcssSourceMap, i as getDepOptimizationConfig, j as isDepsOptimizerEnabled, l as loadConfigFromFile, x as loadEnv, k as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, h as resolveBaseUrl, g as resolveConfig, y as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, w as searchForWorkspaceRoot, u as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-b8ca7cde.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -3444,16 +3444,10 @@ function lookupFile(dir, formats, options) {
3444
3444
  return lookupFile(parentDir, formats, options);
3445
3445
  }
3446
3446
  }
3447
- /**
3448
- * Use fs.statSync(filename) instead of fs.existsSync(filename)
3449
- * #2051 if we don't have read permission on a directory, existsSync() still
3450
- * works and will result in massively slow subsequent checks (which are
3451
- * unnecessary in the first place)
3452
- */
3453
3447
  function isFileReadable(filename) {
3454
3448
  try {
3455
- const stat = fs$1.statSync(filename, { throwIfNoEntry: false });
3456
- return !!stat;
3449
+ fs$1.accessSync(filename, fs$1.constants.R_OK);
3450
+ return true;
3457
3451
  }
3458
3452
  catch {
3459
3453
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
package/types/alias.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export type {
2
- Alias,
3
- ResolverFunction,
4
- ResolverObject,
5
- AliasOptions
6
- } from '../dist/node'
@@ -1 +0,0 @@
1
- export type { AnymatchFn, AnymatchPattern, Matcher } from '../dist/node'
@@ -1,11 +0,0 @@
1
- export type {
2
- FSWatcher,
3
- WatchOptions,
4
- AwaitWriteFinishOptions
5
- } from '../dist/node'
6
-
7
- import type { FSWatcher, WatchOptions } from '../dist/node'
8
- export function watch(
9
- paths: string | ReadonlyArray<string>,
10
- options?: WatchOptions
11
- ): FSWatcher
@@ -1 +0,0 @@
1
- export type { RollupCommonJSOptions } from '../dist/node'
@@ -1 +0,0 @@
1
- export type { Connect } from '../dist/node'
@@ -1 +0,0 @@
1
- export type { RollupDynamicImportVarsOptions } from '../dist/node'
@@ -1 +0,0 @@
1
- export type { HttpProxy } from '../dist/node'
package/types/terser.d.ts DELETED
@@ -1 +0,0 @@
1
- export type { Terser } from '../dist/node'
package/types/ws.d.ts DELETED
@@ -1 +0,0 @@
1
- export type { WebSocket, WebSocketAlias } from '../dist/node'