vite 5.0.0-beta.0 → 5.0.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.
@@ -1,4 +1,4 @@
1
- import { F as commonjsGlobal, E as getDefaultExportFromCjs } from './dep-4033fb3a.js';
1
+ import { E as commonjsGlobal, D as getDefaultExportFromCjs } from './dep-e31699fa.js';
2
2
  import require$$0__default from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -1,4 +1,4 @@
1
- import { E as getDefaultExportFromCjs } from './dep-4033fb3a.js';
1
+ import { D as getDefaultExportFromCjs } from './dep-e31699fa.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-c423598f.js';
@@ -11861,7 +11861,7 @@ function isInNodeModules(id) {
11861
11861
  return id.includes('node_modules');
11862
11862
  }
11863
11863
  function moduleListContains(moduleList, id) {
11864
- return moduleList?.some((m) => m === id || id.startsWith(m + '/'));
11864
+ return moduleList?.some((m) => m === id || id.startsWith(withTrailingSlash(m)));
11865
11865
  }
11866
11866
  function isOptimizable(id, optimizeDeps) {
11867
11867
  const { extensions } = optimizeDeps;
@@ -11925,6 +11925,12 @@ function fsPathFromId(id) {
11925
11925
  function fsPathFromUrl(url) {
11926
11926
  return fsPathFromId(cleanUrl(url));
11927
11927
  }
11928
+ function withTrailingSlash(path) {
11929
+ if (path[path.length - 1] !== '/') {
11930
+ return `${path}/`;
11931
+ }
11932
+ return path;
11933
+ }
11928
11934
  /**
11929
11935
  * Check if dir is a parent of file
11930
11936
  *
@@ -11935,9 +11941,7 @@ function fsPathFromUrl(url) {
11935
11941
  * @returns true if dir is a parent of file
11936
11942
  */
11937
11943
  function isParentDirectory(dir, file) {
11938
- if (dir[dir.length - 1] !== '/') {
11939
- dir = `${dir}/`;
11940
- }
11944
+ dir = withTrailingSlash(dir);
11941
11945
  return (file.startsWith(dir) ||
11942
11946
  (isCaseInsensitiveFS && file.toLowerCase().startsWith(dir.toLowerCase())));
11943
11947
  }
@@ -12289,7 +12293,7 @@ function optimizeSafeRealPathSync() {
12289
12293
  function ensureWatchedFile(watcher, file, root) {
12290
12294
  if (file &&
12291
12295
  // only need to watch if out of root
12292
- !file.startsWith(root + '/') &&
12296
+ !file.startsWith(withTrailingSlash(root)) &&
12293
12297
  // some rollup plugins use null bytes for private resolved Ids
12294
12298
  !file.includes('\0') &&
12295
12299
  fs$l.existsSync(file)) {
@@ -12729,7 +12733,7 @@ function stripBase(path, base) {
12729
12733
  if (path === base) {
12730
12734
  return '/';
12731
12735
  }
12732
- const devBase = base[base.length - 1] === '/' ? base : base + '/';
12736
+ const devBase = withTrailingSlash(base);
12733
12737
  return path.startsWith(devBase) ? path.slice(devBase.length - 1) : path;
12734
12738
  }
12735
12739
  function arrayEqual(a, b) {
@@ -13086,9 +13090,10 @@ function buildReporterPlugin(config) {
13086
13090
  if (isLarge)
13087
13091
  hasLargeChunks = true;
13088
13092
  const sizeColor = isLarge ? colors$1.yellow : colors$1.dim;
13089
- let log = colors$1.dim(relativeOutDir + '/');
13093
+ let log = colors$1.dim(withTrailingSlash(relativeOutDir));
13090
13094
  log +=
13091
- !config.build.lib && entry.name.startsWith(assetsDir)
13095
+ !config.build.lib &&
13096
+ entry.name.startsWith(withTrailingSlash(assetsDir))
13092
13097
  ? colors$1.dim(assetsDir) +
13093
13098
  group.color(entry.name
13094
13099
  .slice(assetsDir.length)
@@ -13796,8 +13801,8 @@ function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
13796
13801
  }
13797
13802
 
13798
13803
  const debug$f = createDebugger('vite:esbuild');
13799
- const INJECT_HELPERS_IIFE_RE = /^(.*?)((?:const|var)\s+\S+\s*=\s*function\s*\([^)]*\)\s*\{\s*"use strict";)/s;
13800
- const INJECT_HELPERS_UMD_RE = /^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{\s*"use strict";)/s;
13804
+ // IIFE content looks like `var MyLib = function() {`. Spaces are removed when minified
13805
+ const IIFE_BEGIN_RE = /(const|var)\s+\S+\s*=\s*function\(\)\s*\{.*"use strict";/s;
13801
13806
  const validExtensionRE = /\.\w+$/;
13802
13807
  const jsxExtensionsRE = /\.(?:j|t)sx\b/;
13803
13808
  let server;
@@ -14030,16 +14035,26 @@ const buildEsbuildPlugin = (config) => {
14030
14035
  if (config.build.lib) {
14031
14036
  // #7188, esbuild adds helpers out of the UMD and IIFE wrappers, and the
14032
14037
  // names are minified potentially causing collision with other globals.
14033
- // We use a regex to inject the helpers inside the wrappers.
14038
+ // We inject the helpers inside the wrappers.
14039
+ // e.g. turn:
14040
+ // <esbuild helpers> (function(){ /*actual content/* })()
14041
+ // into:
14042
+ // (function(){ <esbuild helpers> /*actual content/* })()
14043
+ // Not using regex because it's too hard to rule out performance issues like #8738 #8099 #10900 #14065
14044
+ // Instead, using plain string index manipulation (indexOf, slice) which is simple and performant
14034
14045
  // We don't need to create a MagicString here because both the helpers and
14035
14046
  // the headers don't modify the sourcemap
14036
- const injectHelpers = opts.format === 'umd'
14037
- ? INJECT_HELPERS_UMD_RE
14038
- : opts.format === 'iife'
14039
- ? INJECT_HELPERS_IIFE_RE
14040
- : undefined;
14041
- if (injectHelpers) {
14042
- res.code = res.code.replace(injectHelpers, (_, helpers, header) => header + helpers);
14047
+ const esbuildCode = res.code;
14048
+ const contentIndex = opts.format === 'iife'
14049
+ ? esbuildCode.match(IIFE_BEGIN_RE)?.index || 0
14050
+ : opts.format === 'umd'
14051
+ ? esbuildCode.indexOf(`(function(`) // same for minified or not
14052
+ : 0;
14053
+ if (contentIndex > 0) {
14054
+ const esbuildHelpers = esbuildCode.slice(0, contentIndex);
14055
+ res.code = esbuildCode
14056
+ .slice(contentIndex)
14057
+ .replace(`"use strict";`, `"use strict";` + esbuildHelpers);
14043
14058
  }
14044
14059
  }
14045
14060
  return res;
@@ -16186,7 +16201,7 @@ function checkPublicFile(url, { publicDir }) {
16186
16201
  return;
16187
16202
  }
16188
16203
  const publicFile = path$o.join(publicDir, cleanUrl(url));
16189
- if (!publicFile.startsWith(publicDir)) {
16204
+ if (!normalizePath$3(publicFile).startsWith(withTrailingSlash(normalizePath$3(publicDir)))) {
16190
16205
  // can happen if URL starts with '../'
16191
16206
  return;
16192
16207
  }
@@ -16211,7 +16226,7 @@ function fileToDevUrl(id, config) {
16211
16226
  // in public dir during dev, keep the url as-is
16212
16227
  rtn = id;
16213
16228
  }
16214
- else if (id.startsWith(config.root)) {
16229
+ else if (id.startsWith(withTrailingSlash(config.root))) {
16215
16230
  // in project root, infer short public path
16216
16231
  rtn = '/' + path$o.posix.relative(config.root, id);
16217
16232
  }
@@ -28096,7 +28111,9 @@ function resolvePlugin(resolveOptions) {
28096
28111
  }
28097
28112
  // URL
28098
28113
  // /foo -> /fs-root/foo
28099
- if (asSrc && id[0] === '/' && (rootInRoot || !id.startsWith(root))) {
28114
+ if (asSrc &&
28115
+ id[0] === '/' &&
28116
+ (rootInRoot || !id.startsWith(withTrailingSlash(root)))) {
28100
28117
  const fsPath = path$o.resolve(root, id.slice(1));
28101
28118
  if ((res = tryFsResolve(fsPath, options))) {
28102
28119
  debug$d?.(`[url] ${colors$1.cyan(id)} -> ${colors$1.dim(res)}`);
@@ -28590,7 +28607,7 @@ async function tryOptimizedResolve(depsOptimizer, id, importer, preserveSymlinks
28590
28607
  idPkgDir = normalizePath$3(idPkgDir);
28591
28608
  }
28592
28609
  // match by src to correctly identify if id belongs to nested dependency
28593
- if (optimizedData.src.startsWith(idPkgDir)) {
28610
+ if (optimizedData.src.startsWith(withTrailingSlash(idPkgDir))) {
28594
28611
  return depsOptimizer.getOptimizedDepId(optimizedData);
28595
28612
  }
28596
28613
  }
@@ -38355,7 +38372,7 @@ function cssPostPlugin(config) {
38355
38372
  };
38356
38373
  return {
38357
38374
  name: 'vite:css-post',
38358
- buildStart() {
38375
+ renderStart() {
38359
38376
  // Ensure new caches for every build (i.e. rebuilding in watch mode)
38360
38377
  pureCssChunks = new Set();
38361
38378
  outputToExtractedCSSMap = new Map();
@@ -38652,6 +38669,7 @@ function cssPostPlugin(config) {
38652
38669
  pureCssChunkNames.forEach((fileName) => {
38653
38670
  removedPureCssFiles.set(fileName, bundle[fileName]);
38654
38671
  delete bundle[fileName];
38672
+ delete bundle[`${fileName}.map`];
38655
38673
  });
38656
38674
  }
38657
38675
  let extractedCss = outputToExtractedCSSMap.get(opts);
@@ -38962,8 +38980,8 @@ function createCachedImport(imp) {
38962
38980
  return cached;
38963
38981
  };
38964
38982
  }
38965
- const importPostcssImport = createCachedImport(() => import('./dep-1d1f72b4.js').then(function (n) { return n.i; }));
38966
- const importPostcssModules = createCachedImport(() => import('./dep-3d0847ee.js').then(function (n) { return n.i; }));
38983
+ const importPostcssImport = createCachedImport(() => import('./dep-c457d7ce.js').then(function (n) { return n.i; }));
38984
+ const importPostcssModules = createCachedImport(() => import('./dep-6db0c752.js').then(function (n) { return n.i; }));
38967
38985
  const importPostcss = createCachedImport(() => import('postcss'));
38968
38986
  /**
38969
38987
  * @experimental
@@ -39629,10 +39647,9 @@ async function compileLightningCSS(id, src, config, urlReplacer) {
39629
39647
  ? (await importLightningCSS()).transformStyleAttribute({
39630
39648
  filename,
39631
39649
  code: Buffer.from(src),
39632
- minify: config.isProduction && !!config.build.cssMinify,
39633
39650
  targets: config.css?.lightningcss?.targets,
39651
+ minify: config.isProduction && !!config.build.cssMinify,
39634
39652
  analyzeDependencies: true,
39635
- visitor: config.css?.lightningcss?.visitor,
39636
39653
  })
39637
39654
  : await (await importLightningCSS()).bundleAsync({
39638
39655
  ...config.css?.lightningcss,
@@ -40285,7 +40302,8 @@ function cjsShouldExternalizeForSSR(id, externals) {
40285
40302
  }
40286
40303
  // deep imports, check ext before externalizing - only externalize
40287
40304
  // extension-less imports and explicit .js imports
40288
- if (id.startsWith(e + '/') && (!path$o.extname(id) || id.endsWith('.js'))) {
40305
+ if (id.startsWith(withTrailingSlash(e)) &&
40306
+ (!path$o.extname(id) || id.endsWith('.js'))) {
40289
40307
  return true;
40290
40308
  }
40291
40309
  });
@@ -41218,7 +41236,9 @@ const debugHmr = createDebugger('vite:hmr');
41218
41236
  const whitespaceRE = /\s/;
41219
41237
  const normalizedClientDir = normalizePath$3(CLIENT_DIR);
41220
41238
  function getShortName(file, root) {
41221
- return file.startsWith(root + '/') ? path$o.posix.relative(root, file) : file;
41239
+ return file.startsWith(withTrailingSlash(root))
41240
+ ? path$o.posix.relative(root, file)
41241
+ : file;
41222
41242
  }
41223
41243
  async function handleHMRUpdate(file, server, configOnly) {
41224
41244
  const { ws, config, moduleGraph } = server;
@@ -41245,7 +41265,7 @@ async function handleHMRUpdate(file, server, configOnly) {
41245
41265
  }
41246
41266
  debugHmr?.(`[file change] ${colors$1.dim(shortFile)}`);
41247
41267
  // (dev only) the client itself cannot be hot updated.
41248
- if (file.startsWith(normalizedClientDir)) {
41268
+ if (file.startsWith(withTrailingSlash(normalizedClientDir))) {
41249
41269
  ws.send({
41250
41270
  type: 'full-reload',
41251
41271
  path: '*',
@@ -41806,7 +41826,7 @@ function importAnalysisPlugin(config) {
41806
41826
  const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer);
41807
41827
  // normalize all imports into resolved URLs
41808
41828
  // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
41809
- if (resolved.id.startsWith(root + '/')) {
41829
+ if (resolved.id.startsWith(withTrailingSlash(root))) {
41810
41830
  // in root: infer short absolute path from root
41811
41831
  url = resolved.id.slice(root.length);
41812
41832
  }
@@ -42038,7 +42058,7 @@ function importAnalysisPlugin(config) {
42038
42058
  });
42039
42059
  }
42040
42060
  }
42041
- else if (!importer.startsWith(clientDir)) {
42061
+ else if (!importer.startsWith(withTrailingSlash(clientDir))) {
42042
42062
  if (!isInNodeModules(importer)) {
42043
42063
  // check @vite-ignore which suppresses dynamic import warning
42044
42064
  const hasViteIgnore = hasViteIgnoreRE.test(
@@ -42147,23 +42167,32 @@ function mergeAcceptedUrls(orderedUrls) {
42147
42167
  function interopNamedImports(str, importSpecifier, rewrittenUrl, importIndex, importer, config) {
42148
42168
  const source = str.original;
42149
42169
  const { s: start, e: end, ss: expStart, se: expEnd, d: dynamicIndex, } = importSpecifier;
42170
+ const exp = source.slice(expStart, expEnd);
42150
42171
  if (dynamicIndex > -1) {
42151
42172
  // rewrite `import('package')` to expose the default directly
42152
- str.overwrite(expStart, expEnd, `import('${rewrittenUrl}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))`, { contentOnly: true });
42173
+ str.overwrite(expStart, expEnd, `import('${rewrittenUrl}').then(m => m.default && m.default.__esModule ? m.default : ({ ...m.default, default: m.default }))` +
42174
+ getLineBreaks(exp), { contentOnly: true });
42153
42175
  }
42154
42176
  else {
42155
- const exp = source.slice(expStart, expEnd);
42156
42177
  const rawUrl = source.slice(start, end);
42157
42178
  const rewritten = transformCjsImport(exp, rewrittenUrl, rawUrl, importIndex, importer, config);
42158
42179
  if (rewritten) {
42159
- str.overwrite(expStart, expEnd, rewritten, { contentOnly: true });
42180
+ str.overwrite(expStart, expEnd, rewritten + getLineBreaks(exp), {
42181
+ contentOnly: true,
42182
+ });
42160
42183
  }
42161
42184
  else {
42162
42185
  // #1439 export * from '...'
42163
- str.overwrite(start, end, rewrittenUrl, { contentOnly: true });
42186
+ str.overwrite(start, end, rewrittenUrl + getLineBreaks(source.slice(start, end)), {
42187
+ contentOnly: true,
42188
+ });
42164
42189
  }
42165
42190
  }
42166
42191
  }
42192
+ // get line breaks to preserve line count for not breaking source maps
42193
+ function getLineBreaks(str) {
42194
+ return str.includes('\n') ? '\n'.repeat(str.split('\n').length - 1) : '';
42195
+ }
42167
42196
  /**
42168
42197
  * Detect import statements to a known optimized CJS dependency and provide
42169
42198
  * ES named imports interop. We do this by rewriting named imports to a variable
@@ -42615,9 +42644,15 @@ function webWorkerPlugin(config) {
42615
42644
  injectEnv = module?.transformResult?.code || '';
42616
42645
  }
42617
42646
  }
42618
- return {
42619
- code: injectEnv + raw,
42620
- };
42647
+ if (injectEnv) {
42648
+ const s = new MagicString(raw);
42649
+ s.prepend(injectEnv);
42650
+ return {
42651
+ code: s.toString(),
42652
+ map: s.generateMap({ hires: 'boundary' }),
42653
+ };
42654
+ }
42655
+ return;
42621
42656
  }
42622
42657
  if (query == null ||
42623
42658
  (query && (query.worker ?? query.sharedworker) == null)) {
@@ -42828,7 +42863,7 @@ function matches(pattern, importee) {
42828
42863
  if (importee === pattern) {
42829
42864
  return true;
42830
42865
  }
42831
- return importee.startsWith(pattern + '/');
42866
+ return importee.startsWith(withTrailingSlash(pattern));
42832
42867
  }
42833
42868
  function getAliasPatterns(entries) {
42834
42869
  if (!entries) {
@@ -44918,7 +44953,7 @@ function expandGlobIds(id, config) {
44918
44953
  }
44919
44954
  const possibleExportPaths = [];
44920
44955
  for (const key in exports) {
44921
- if (key.startsWith('.')) {
44956
+ if (key[0] === '.') {
44922
44957
  if (key.includes('*')) {
44923
44958
  // "./glob/*": {
44924
44959
  // "browser": "./dist/glob/*-browser/*.js", <-- get this one
@@ -45451,7 +45486,6 @@ async function createDepsOptimizer(config, server) {
45451
45486
  if (closed) {
45452
45487
  return;
45453
45488
  }
45454
- const crawlDeps = Object.keys(metadata.discovered);
45455
45489
  // Await for the scan+optimize step running in the background
45456
45490
  // It normally should be over by the time crawling of user code ended
45457
45491
  await depsOptimizer.scanProcessing;
@@ -45459,6 +45493,7 @@ async function createDepsOptimizer(config, server) {
45459
45493
  const result = await optimizationResult.result;
45460
45494
  optimizationResult = undefined;
45461
45495
  currentlyProcessing = false;
45496
+ const crawlDeps = Object.keys(metadata.discovered);
45462
45497
  const scanDeps = Object.keys(result.metadata.optimized);
45463
45498
  if (scanDeps.length === 0 && crawlDeps.length === 0) {
45464
45499
  debug$8?.(colors$1.green(`✨ no dependencies found by the scanner or crawling static imports`));
@@ -45491,6 +45526,7 @@ async function createDepsOptimizer(config, server) {
45491
45526
  }
45492
45527
  }
45493
45528
  else {
45529
+ const crawlDeps = Object.keys(metadata.discovered);
45494
45530
  currentlyProcessing = false;
45495
45531
  if (crawlDeps.length === 0) {
45496
45532
  debug$8?.(colors$1.green(`✨ no dependencies found while crawling the static imports`));
@@ -46658,7 +46694,7 @@ function buildImportAnalysisPlugin(config) {
46658
46694
  }
46659
46695
  // normalize all imports into resolved URLs
46660
46696
  // e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
46661
- if (resolved.id.startsWith(root + '/')) {
46697
+ if (resolved.id.startsWith(withTrailingSlash(root))) {
46662
46698
  // in root: infer short absolute path from root
46663
46699
  url = resolved.id.slice(root.length);
46664
46700
  }
@@ -47664,7 +47700,7 @@ function serveStaticMiddleware(dir, server) {
47664
47700
  }
47665
47701
  if (redirectedPathname) {
47666
47702
  // dir is pre-normalized to posix style
47667
- if (redirectedPathname.startsWith(dir)) {
47703
+ if (redirectedPathname.startsWith(withTrailingSlash(dir))) {
47668
47704
  redirectedPathname = redirectedPathname.slice(dir.length);
47669
47705
  }
47670
47706
  }
@@ -47672,7 +47708,7 @@ function serveStaticMiddleware(dir, server) {
47672
47708
  let fileUrl = path$o.resolve(dir, removeLeadingSlash(resolvedPathname));
47673
47709
  if (resolvedPathname[resolvedPathname.length - 1] === '/' &&
47674
47710
  fileUrl[fileUrl.length - 1] !== '/') {
47675
- fileUrl = fileUrl + '/';
47711
+ fileUrl = withTrailingSlash(fileUrl);
47676
47712
  }
47677
47713
  if (!ensureServingAccess(fileUrl, server, res, next)) {
47678
47714
  return;
@@ -47854,7 +47890,7 @@ function resolveBuildOptions(raw, logger, root) {
47854
47890
  if (resolved.minify === 'false') {
47855
47891
  resolved.minify = false;
47856
47892
  }
47857
- if (resolved.minify === true) {
47893
+ else if (resolved.minify === true) {
47858
47894
  resolved.minify = 'esbuild';
47859
47895
  }
47860
47896
  if (resolved.cssMinify == null) {
@@ -48076,7 +48112,7 @@ function prepareOutDir(outDirs, emptyOutDir, config) {
48076
48112
  if (emptyOutDir == null) {
48077
48113
  for (const outDir of nonDuplicateDirs) {
48078
48114
  if (fs$l.existsSync(outDir) &&
48079
- !normalizePath$3(outDir).startsWith(config.root + '/')) {
48115
+ !normalizePath$3(outDir).startsWith(withTrailingSlash(config.root))) {
48080
48116
  // warn if outDir is outside of root
48081
48117
  config.logger.warn(colors$1.yellow(`\n${colors$1.bold(`(!)`)} outDir ${colors$1.white(colors$1.dim(outDir))} is not inside project root and will not be emptied.\n` +
48082
48118
  `Use --emptyOutDir to override.\n`));
@@ -48440,7 +48476,9 @@ const toOutputFilePathInHtml = toOutputFilePathWithoutRuntime;
48440
48476
  function areSeparateFolders(a, b) {
48441
48477
  const na = normalizePath$3(a);
48442
48478
  const nb = normalizePath$3(b);
48443
- return na !== nb && !na.startsWith(nb + '/') && !nb.startsWith(na + '/');
48479
+ return (na !== nb &&
48480
+ !na.startsWith(withTrailingSlash(nb)) &&
48481
+ !nb.startsWith(withTrailingSlash(na)));
48444
48482
  }
48445
48483
 
48446
48484
  var build$1 = {
@@ -57265,7 +57303,7 @@ function execAsync(command, options) {
57265
57303
  });
57266
57304
  }
57267
57305
 
57268
- function bindShortcuts(server, opts) {
57306
+ function bindCLIShortcuts(server, opts) {
57269
57307
  if (!server.httpServer || !process.stdin.isTTY || process.env.CI) {
57270
57308
  return;
57271
57309
  }
@@ -61982,7 +62020,7 @@ function baseMiddleware({ config, }) {
61982
62020
  }
61983
62021
  else if (req.headers.accept?.includes('text/html')) {
61984
62022
  // non-based page visit
61985
- const redirectPath = url + '/' !== base ? joinUrlSegments(base, url) : base;
62023
+ const redirectPath = withTrailingSlash(url) !== base ? joinUrlSegments(base, url) : base;
61986
62024
  res.writeHead(404, {
61987
62025
  'Content-Type': 'text/html',
61988
62026
  });
@@ -64370,10 +64408,10 @@ function transformMiddleware(server) {
64370
64408
  // check if public dir is inside root dir
64371
64409
  const publicDir = normalizePath$3(server.config.publicDir);
64372
64410
  const rootDir = normalizePath$3(server.config.root);
64373
- if (publicDir.startsWith(rootDir)) {
64411
+ if (publicDir.startsWith(withTrailingSlash(rootDir))) {
64374
64412
  const publicPath = `${publicDir.slice(rootDir.length)}/`;
64375
64413
  // warn explicit public paths
64376
- if (url.startsWith(publicPath)) {
64414
+ if (url.startsWith(withTrailingSlash(publicPath))) {
64377
64415
  let warning;
64378
64416
  if (isImportRequest(url)) {
64379
64417
  const rawUrl = removeImportQuery(url);
@@ -65164,6 +65202,9 @@ async function _createServer(inlineConfig = {}, options) {
65164
65202
  throw new Error('cannot print server URLs before server.listen is called.');
65165
65203
  }
65166
65204
  },
65205
+ bindCLIShortcuts(options) {
65206
+ bindCLIShortcuts(server, options);
65207
+ },
65167
65208
  async restart(forceOptimize) {
65168
65209
  if (!server._restartPromise) {
65169
65210
  server._forceOptimizeOnRestart = !!forceOptimize;
@@ -65477,7 +65518,7 @@ async function restartServer(server) {
65477
65518
  }
65478
65519
  if (shortcutsOptions) {
65479
65520
  shortcutsOptions.print = false;
65480
- bindShortcuts(newServer, shortcutsOptions);
65521
+ bindCLIShortcuts(newServer, shortcutsOptions);
65481
65522
  }
65482
65523
  }
65483
65524
  async function updateCjsSsrExternals(server) {
@@ -65663,6 +65704,9 @@ async function preview(inlineConfig = {}) {
65663
65704
  throw new Error('cannot print server URLs before server is listening.');
65664
65705
  }
65665
65706
  },
65707
+ bindCLIShortcuts(options) {
65708
+ bindCLIShortcuts(server, options);
65709
+ },
65666
65710
  };
65667
65711
  // apply server hooks from plugins
65668
65712
  const postHooks = [];
@@ -65961,7 +66005,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
65961
66005
  configFileDependencies: configFileDependencies.map((name) => normalizePath$3(path$o.resolve(name))),
65962
66006
  inlineConfig,
65963
66007
  root: resolvedRoot,
65964
- base: resolvedBase.endsWith('/') ? resolvedBase : resolvedBase + '/',
66008
+ base: withTrailingSlash(resolvedBase),
65965
66009
  rawBase: resolvedBase,
65966
66010
  resolve: resolveOptions,
65967
66011
  publicDir: resolvedPublicDir,
@@ -66084,7 +66128,7 @@ assetFileNames isn't equal for every build.rollupOptions.output. A single patter
66084
66128
  if (config.legacy?.buildSsrCjsExternalHeuristics ||
66085
66129
  config.ssr?.format === 'cjs') {
66086
66130
  resolved.logger.warn(colors$1.yellow(`
66087
- (!) Experimental legacy.buildSsrCjsExternalHeuristics and ssr.format: 'cjs' are going to be removed in Vite 5.
66131
+ (!) Experimental legacy.buildSsrCjsExternalHeuristics and ssr.format: 'cjs' are going to be removed in Vite 5.
66088
66132
  Find more information and give feedback at https://github.com/vitejs/vite/discussions/13816.
66089
66133
  `));
66090
66134
  }
@@ -66378,4 +66422,4 @@ function isDepsOptimizerEnabled(config, ssr) {
66378
66422
  (command === 'serve' && disabled === 'dev'));
66379
66423
  }
66380
66424
 
66381
- export { loadEnv as A, resolveEnvPrefix as B, colors$1 as C, bindShortcuts as D, getDefaultExportFromCjs as E, commonjsGlobal as F, index$1 as G, build$1 as H, index as I, preview$1 as J, preprocessCSS as a, build as b, createServer as c, resolvePackageData as d, buildErrorMessage as e, formatPostcssSourceMap as f, defineConfig as g, resolveConfig as h, isInNodeModules as i, resolveBaseUrl as j, getDepOptimizationConfig as k, loadConfigFromFile as l, isDepsOptimizerEnabled as m, normalizePath$3 as n, optimizeDeps as o, preview as p, mergeConfig as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, mergeAlias as u, createFilter as v, send$2 as w, createLogger as x, searchForWorkspaceRoot as y, isFileServingAllowed as z };
66425
+ export { loadEnv as A, resolveEnvPrefix as B, colors$1 as C, getDefaultExportFromCjs as D, commonjsGlobal as E, index$1 as F, build$1 as G, index as H, preview$1 as I, preprocessCSS as a, build as b, createServer as c, resolvePackageData as d, buildErrorMessage as e, formatPostcssSourceMap as f, defineConfig as g, resolveConfig as h, isInNodeModules as i, resolveBaseUrl as j, getDepOptimizationConfig as k, loadConfigFromFile as l, isDepsOptimizerEnabled as m, normalizePath$3 as n, optimizeDeps as o, preview as p, mergeConfig as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, mergeAlias as u, createFilter as v, send$2 as w, createLogger as x, searchForWorkspaceRoot as y, isFileServingAllowed as z };
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 { C as colors, D as bindShortcuts, x as createLogger, h as resolveConfig } from './chunks/dep-4033fb3a.js';
5
+ import { C as colors, x as createLogger, h as resolveConfig } from './chunks/dep-e31699fa.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -723,9 +723,20 @@ const convertHost = (v) => {
723
723
  }
724
724
  return v;
725
725
  };
726
+ /**
727
+ * base may be a number (like 0), should convert to empty string
728
+ */
729
+ const convertBase = (v) => {
730
+ if (v === 0) {
731
+ return '';
732
+ }
733
+ return v;
734
+ };
726
735
  cli
727
736
  .option('-c, --config <file>', `[string] use specified config file`)
728
- .option('--base <path>', `[string] public base path (default: /)`)
737
+ .option('--base <path>', `[string] public base path (default: /)`, {
738
+ type: [convertBase],
739
+ })
729
740
  .option('-l, --logLevel <level>', `[string] info | warn | error | silent`)
730
741
  .option('--clearScreen', `[boolean] allow/disable clear screen when logging`)
731
742
  .option('-d, --debug [feat]', `[string | boolean] show debug logs`)
@@ -747,7 +758,7 @@ cli
747
758
  filterDuplicateOptions(options);
748
759
  // output structure is preserved even after bundling so require()
749
760
  // is ok here
750
- const { createServer } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.I; });
761
+ const { createServer } = await import('./chunks/dep-e31699fa.js').then(function (n) { return n.H; });
751
762
  try {
752
763
  const server = await createServer({
753
764
  root,
@@ -770,7 +781,7 @@ cli
770
781
  : '';
771
782
  info(`\n ${colors.green(`${colors.bold('VITE')} v${VERSION}`)} ${startupDurationString}\n`, { clear: !server.config.logger.hasWarned });
772
783
  server.printUrls();
773
- bindShortcuts(server, {
784
+ server.bindCLIShortcuts({
774
785
  print: true,
775
786
  customShortcuts: [
776
787
  profileSession && {
@@ -825,7 +836,7 @@ cli
825
836
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
826
837
  .action(async (root, options) => {
827
838
  filterDuplicateOptions(options);
828
- const { build } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.H; });
839
+ const { build } = await import('./chunks/dep-e31699fa.js').then(function (n) { return n.G; });
829
840
  const buildOptions = cleanOptions(options);
830
841
  try {
831
842
  await build({
@@ -853,7 +864,7 @@ cli
853
864
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
854
865
  .action(async (root, options) => {
855
866
  filterDuplicateOptions(options);
856
- const { optimizeDeps } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.G; });
867
+ const { optimizeDeps } = await import('./chunks/dep-e31699fa.js').then(function (n) { return n.F; });
857
868
  try {
858
869
  const config = await resolveConfig({
859
870
  root,
@@ -880,7 +891,7 @@ cli
880
891
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
881
892
  .action(async (root, options) => {
882
893
  filterDuplicateOptions(options);
883
- const { preview } = await import('./chunks/dep-4033fb3a.js').then(function (n) { return n.J; });
894
+ const { preview } = await import('./chunks/dep-e31699fa.js').then(function (n) { return n.I; });
884
895
  try {
885
896
  const server = await preview({
886
897
  root,
@@ -900,7 +911,7 @@ cli
900
911
  },
901
912
  });
902
913
  server.printUrls();
903
- bindShortcuts(server, { print: true });
914
+ server.bindCLIShortcuts({ print: true });
904
915
  }
905
916
  catch (e) {
906
917
  createLogger(options.logLevel).error(colors.red(`error when starting preview server:\n${e.stack}`), { error: e });
@@ -2,12 +2,10 @@
2
2
 
3
3
  import type { Agent } from 'node:http';
4
4
  import type { BuildOptions as BuildOptions_2 } from 'esbuild';
5
- import type { BundleAsyncOptions } from 'lightningcss';
6
5
  import { ChunkMetadata } from "../../types/metadata.js";
7
6
  import type { ClientRequest } from 'node:http';
8
7
  import type { ClientRequestArgs } from 'node:http';
9
8
  import { ConnectedPayload } from "../../types/hmrPayload.js";
10
- import type { CustomAtRules } from 'lightningcss';
11
9
  import { CustomEventMap } from "../../types/customEvent.js";
12
10
  import { CustomPayload } from "../../types/hmrPayload.js";
13
11
  import type { CustomPluginOptions } from 'rollup';
@@ -121,6 +119,14 @@ export declare interface AwaitWriteFinishOptions {
121
119
  pollInterval?: number
122
120
  }
123
121
 
122
+ export declare type BindCLIShortcutsOptions<Server = ViteDevServer | PreviewServer> = {
123
+ /**
124
+ * Print a one line hint to the terminal.
125
+ */
126
+ print?: boolean;
127
+ customShortcuts?: (CLIShortcut<Server> | undefined | null)[];
128
+ };
129
+
124
130
  /**
125
131
  * Bundles the app for production.
126
132
  * Returns a Promise containing the build result.
@@ -315,6 +321,12 @@ export declare interface BuildOptions {
315
321
 
316
322
  export { ChunkMetadata }
317
323
 
324
+ export declare type CLIShortcut<Server = ViteDevServer | PreviewServer> = {
325
+ key: string;
326
+ description: string;
327
+ action(server: Server): void | Promise<void>;
328
+ };
329
+
318
330
  export declare interface CommonServerOptions {
319
331
  /**
320
332
  * Specify server port. Note if the port is already being used, Vite will
@@ -511,6 +523,13 @@ export declare function createLogger(level?: LogLevel, options?: LoggerOptions):
511
523
 
512
524
  export declare function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>;
513
525
 
526
+ declare interface CSSModulesConfig {
527
+ /** The pattern to use when renaming class names and other identifiers. Default is `[hash]_[local]`. */
528
+ pattern?: string,
529
+ /** Whether to rename dashed identifiers, e.g. custom properties. */
530
+ dashedIdents?: boolean
531
+ }
532
+
514
533
  export declare interface CSSModulesOptions {
515
534
  getJSON?: (cssFileName: string, json: Record<string, string>, outputFileName: string) => void;
516
535
  scopeBehaviour?: 'global' | 'local';
@@ -709,6 +728,13 @@ export declare interface DepsOptimizer {
709
728
  options: DepOptimizationOptions;
710
729
  }
711
730
 
731
+ declare interface Drafts {
732
+ /** Whether to enable CSS nesting. */
733
+ nesting?: boolean,
734
+ /** Whether to enable @custom-media rules. */
735
+ customMedia?: boolean
736
+ }
737
+
712
738
  export { ErrorPayload }
713
739
 
714
740
  export declare interface ESBuildOptions extends EsbuildTransformOptions {
@@ -766,6 +792,32 @@ export declare type ExportsData = {
766
792
  jsxLoader?: boolean;
767
793
  };
768
794
 
795
+ declare const enum Features {
796
+ Nesting = 1,
797
+ NotSelectorList = 2,
798
+ DirSelector = 4,
799
+ LangSelectorList = 8,
800
+ IsSelector = 16,
801
+ TextDecorationThicknessPercent = 32,
802
+ MediaIntervalSyntax = 64,
803
+ MediaRangeSyntax = 128,
804
+ CustomMediaQueries = 256,
805
+ ClampFunction = 512,
806
+ ColorFunction = 1024,
807
+ OklabColors = 2048,
808
+ LabColors = 4096,
809
+ P3Colors = 8192,
810
+ HexAlphaColors = 16384,
811
+ SpaceSeparatedColorNotation = 32768,
812
+ FontFamilySystemUi = 65536,
813
+ DoublePositionGradients = 131072,
814
+ VendorPrefixes = 262144,
815
+ LogicalProperties = 524288,
816
+ Selectors = 31,
817
+ MediaQueries = 448,
818
+ Colors = 64512,
819
+ }
820
+
769
821
  export declare interface FileSystemServeOptions {
770
822
  /**
771
823
  * Strictly restrict file accessing outside of allowing paths.
@@ -1281,7 +1333,20 @@ export declare interface LibraryOptions {
1281
1333
  fileName?: string | ((format: ModuleFormat, entryName: string) => string);
1282
1334
  }
1283
1335
 
1284
- export declare type LightningCSSOptions = Omit<BundleAsyncOptions<CustomAtRules>, 'filename' | 'resolver' | 'minify' | 'sourceMap' | 'analyzeDependencies'>;
1336
+ /**
1337
+ * Options are spread, so you can also use options that are not typed here like
1338
+ * visitor (not exposed because it would impact too much the bundle size)
1339
+ */
1340
+ export declare type LightningCSSOptions = {
1341
+ targets?: Targets
1342
+ include?: Features
1343
+ exclude?: Features
1344
+ drafts?: Drafts
1345
+ nonStandard?: NonStandard
1346
+ pseudoClasses?: PseudoClasses
1347
+ unusedSymbols?: string[]
1348
+ cssModules?: CSSModulesConfig
1349
+ }
1285
1350
 
1286
1351
  export declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel): Promise<{
1287
1352
  path: string;
@@ -1418,6 +1483,11 @@ export declare interface ModulePreloadOptions {
1418
1483
  resolveDependencies?: ResolveModulePreloadDependenciesFn;
1419
1484
  }
1420
1485
 
1486
+ declare interface NonStandard {
1487
+ /** Whether to enable the non-standard >>> and /deep/ selector combinators used by Angular and Vue. */
1488
+ deepSelectorCombinator?: boolean
1489
+ }
1490
+
1421
1491
  export declare function normalizePath(id: string): string;
1422
1492
 
1423
1493
  export declare interface OptimizedDepInfo {
@@ -1673,6 +1743,10 @@ export declare interface PreviewServer {
1673
1743
  * Print server urls
1674
1744
  */
1675
1745
  printUrls(): void;
1746
+ /**
1747
+ * Bind CLI shortcuts
1748
+ */
1749
+ bindCLIShortcuts(options?: BindCLIShortcutsOptions<PreviewServer>): void;
1676
1750
  }
1677
1751
 
1678
1752
  export declare type PreviewServerHook = (this: void, server: PreviewServer) => (() => void) | void | Promise<(() => void) | void>;
@@ -1694,6 +1768,14 @@ export declare interface ProxyOptions extends HttpProxy.ServerOptions {
1694
1768
 
1695
1769
  export { PrunePayload }
1696
1770
 
1771
+ declare interface PseudoClasses {
1772
+ hover?: string,
1773
+ active?: string,
1774
+ focus?: string,
1775
+ focusVisible?: string,
1776
+ focusWithin?: string
1777
+ }
1778
+
1697
1779
  export declare type RenderBuiltAssetUrl = (filename: string, type: {
1698
1780
  type: 'asset' | 'public';
1699
1781
  hostId: string;
@@ -2206,6 +2288,18 @@ export declare interface SSROptions {
2206
2288
 
2207
2289
  export declare type SSRTarget = 'node' | 'webworker';
2208
2290
 
2291
+ declare interface Targets {
2292
+ android?: number,
2293
+ chrome?: number,
2294
+ edge?: number,
2295
+ firefox?: number,
2296
+ ie?: number,
2297
+ ios_saf?: number,
2298
+ opera?: number,
2299
+ safari?: number,
2300
+ samsung?: number
2301
+ }
2302
+
2209
2303
  export declare namespace Terser {
2210
2304
  export type ECMA = 5 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020
2211
2305
 
@@ -2694,6 +2788,10 @@ export declare interface ViteDevServer {
2694
2788
  * Print server urls
2695
2789
  */
2696
2790
  printUrls(): void;
2791
+ /**
2792
+ * Bind CLI shortcuts
2793
+ */
2794
+ bindCLIShortcuts(options?: BindCLIShortcutsOptions<ViteDevServer>): void;
2697
2795
  /**
2698
2796
  * Restart the server.
2699
2797
  *
@@ -1,5 +1,5 @@
1
- import { i as isInNodeModules } from './chunks/dep-4033fb3a.js';
2
- export { b as build, e as buildErrorMessage, v as createFilter, x as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, k as getDepOptimizationConfig, m as isDepsOptimizerEnabled, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, u as mergeAlias, q as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, j as resolveBaseUrl, h as resolveConfig, B as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-4033fb3a.js';
1
+ import { i as isInNodeModules } from './chunks/dep-e31699fa.js';
2
+ export { b as build, e as buildErrorMessage, v as createFilter, x as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, k as getDepOptimizationConfig, m as isDepsOptimizerEnabled, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, u as mergeAlias, q as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, j as resolveBaseUrl, h as resolveConfig, B as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-e31699fa.js';
3
3
  export { VERSION as version } from './constants.js';
4
4
  export { version as esbuildVersion } from 'esbuild';
5
5
  export { VERSION as rollupVersion } from 'rollup';
@@ -3423,6 +3423,12 @@ function fsPathFromId(id) {
3423
3423
  function fsPathFromUrl(url) {
3424
3424
  return fsPathFromId(cleanUrl(url));
3425
3425
  }
3426
+ function withTrailingSlash(path) {
3427
+ if (path[path.length - 1] !== '/') {
3428
+ return `${path}/`;
3429
+ }
3430
+ return path;
3431
+ }
3426
3432
  /**
3427
3433
  * Check if dir is a parent of file
3428
3434
  *
@@ -3433,9 +3439,7 @@ function fsPathFromUrl(url) {
3433
3439
  * @returns true if dir is a parent of file
3434
3440
  */
3435
3441
  function isParentDirectory(dir, file) {
3436
- if (dir[dir.length - 1] !== '/') {
3437
- dir = `${dir}/`;
3438
- }
3442
+ dir = withTrailingSlash(dir);
3439
3443
  return (file.startsWith(dir) ||
3440
3444
  (isCaseInsensitiveFS && file.toLowerCase().startsWith(dir.toLowerCase())));
3441
3445
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.0.0-beta.0",
3
+ "version": "5.0.0-beta.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -28,6 +28,9 @@
28
28
  "types": "./client.d.ts"
29
29
  },
30
30
  "./dist/client/*": "./dist/client/*",
31
+ "./types/*": {
32
+ "types": "./types/*"
33
+ },
31
34
  "./package.json": "./package.json"
32
35
  },
33
36
  "files": [
@@ -121,7 +124,7 @@
121
124
  "ws": "^8.13.0"
122
125
  },
123
126
  "peerDependencies": {
124
- "@types/node": ">= 14",
127
+ "@types/node": "^18.0.0 || >=20.0.0",
125
128
  "less": "*",
126
129
  "lightningcss": "^1.21.0",
127
130
  "sass": "*",
@@ -159,7 +162,7 @@
159
162
  "build-types": "run-s build-types-temp build-types-pre-patch build-types-roll build-types-post-patch build-types-check",
160
163
  "build-types-temp": "tsc --emitDeclarationOnly --outDir temp/node -p src/node",
161
164
  "build-types-pre-patch": "tsx scripts/prePatchTypes.ts",
162
- "build-types-roll": "api-extractor run && rimraf temp",
165
+ "build-types-roll": "tsx scripts/api-extractor.ts run && rimraf temp",
163
166
  "build-types-post-patch": "tsx scripts/postPatchTypes.ts",
164
167
  "build-types-check": "tsx scripts/checkBuiltTypes.ts && tsc --project tsconfig.check.json",
165
168
  "typecheck": "tsc --noEmit",