vite 4.5.13 → 4.5.14

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 { E as getDefaultExportFromCjs } from './dep-42dae6ba.js';
1
+ import { F as getDefaultExportFromCjs } from './dep-827b23df.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';
@@ -38995,8 +38995,8 @@ function createCachedImport(imp) {
38995
38995
  return cached;
38996
38996
  };
38997
38997
  }
38998
- const importPostcssImport = createCachedImport(() => import('./dep-6e2b5186.js').then(function (n) { return n.i; }));
38999
- const importPostcssModules = createCachedImport(() => import('./dep-e967375e.js').then(function (n) { return n.i; }));
38998
+ const importPostcssImport = createCachedImport(() => import('./dep-7ec6f216.js').then(function (n) { return n.i; }));
38999
+ const importPostcssModules = createCachedImport(() => import('./dep-f1e8587f.js').then(function (n) { return n.i; }));
39000
39000
  const importPostcss = createCachedImport(() => import('postcss'));
39001
39001
  /**
39002
39002
  * @experimental
@@ -47624,7 +47624,8 @@ function escapeHtml$1(string) {
47624
47624
  var escapeHtml$2 = /*@__PURE__*/getDefaultExportFromCjs(escapeHtml_1);
47625
47625
 
47626
47626
  const knownJavascriptExtensionRE = /\.[tj]sx?$/;
47627
- const sirvOptions = ({ headers, shouldServe, }) => {
47627
+ const ERR_DENIED_FILE = 'ERR_DENIED_FILE';
47628
+ const sirvOptions = ({ server, headers, shouldServe, disableFsServeCheck, }) => {
47628
47629
  return {
47629
47630
  dev: true,
47630
47631
  etag: true,
@@ -47644,13 +47645,32 @@ const sirvOptions = ({ headers, shouldServe, }) => {
47644
47645
  }
47645
47646
  }
47646
47647
  },
47647
- shouldServe,
47648
+ shouldServe: disableFsServeCheck
47649
+ ? shouldServe
47650
+ : (filePath) => {
47651
+ const servingAccessResult = checkLoadingAccess(server, filePath);
47652
+ if (servingAccessResult === 'denied') {
47653
+ const error = new Error('denied access');
47654
+ error.code = ERR_DENIED_FILE;
47655
+ error.path = filePath;
47656
+ throw error;
47657
+ }
47658
+ if (servingAccessResult === 'fallback') {
47659
+ return false;
47660
+ }
47661
+ if (shouldServe) {
47662
+ return shouldServe(filePath);
47663
+ }
47664
+ return true;
47665
+ },
47648
47666
  };
47649
47667
  };
47650
- function servePublicMiddleware(dir, headers) {
47668
+ function servePublicMiddleware(dir, server, headers) {
47651
47669
  const serve = sirv(dir, sirvOptions({
47670
+ server,
47652
47671
  headers,
47653
47672
  shouldServe: (filePath) => shouldServeFile(filePath, dir),
47673
+ disableFsServeCheck: true,
47654
47674
  }));
47655
47675
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
47656
47676
  return function viteServePublicMiddleware(req, res, next) {
@@ -47663,6 +47683,7 @@ function servePublicMiddleware(dir, headers) {
47663
47683
  }
47664
47684
  function serveStaticMiddleware(dir, server) {
47665
47685
  const serve = sirv(dir, sirvOptions({
47686
+ server,
47666
47687
  headers: server.config.server.headers,
47667
47688
  }));
47668
47689
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
@@ -47697,23 +47718,28 @@ function serveStaticMiddleware(dir, server) {
47697
47718
  }
47698
47719
  }
47699
47720
  const resolvedPathname = redirectedPathname || pathname;
47700
- let fileUrl = path$o.resolve(dir, removeLeadingSlash(resolvedPathname));
47701
- if (resolvedPathname[resolvedPathname.length - 1] === '/' &&
47702
- fileUrl[fileUrl.length - 1] !== '/') {
47703
- fileUrl = withTrailingSlash(fileUrl);
47704
- }
47705
- if (!ensureServingAccess(fileUrl, server, res, next)) {
47706
- return;
47707
- }
47721
+ path$o.resolve(dir, removeLeadingSlash(resolvedPathname));
47708
47722
  if (redirectedPathname) {
47709
47723
  url.pathname = encodeURI(redirectedPathname);
47710
47724
  req.url = url.href.slice(url.origin.length);
47711
47725
  }
47712
- serve(req, res, next);
47726
+ try {
47727
+ serve(req, res, next);
47728
+ }
47729
+ catch (e) {
47730
+ if (e && 'code' in e && e.code === ERR_DENIED_FILE) {
47731
+ respondWithAccessDenied(e.path, server, res);
47732
+ return;
47733
+ }
47734
+ throw e;
47735
+ }
47713
47736
  };
47714
47737
  }
47715
47738
  function serveRawFsMiddleware(server) {
47716
- const serveFromRoot = sirv('/', sirvOptions({ headers: server.config.server.headers }));
47739
+ const serveFromRoot = sirv('/', sirvOptions({
47740
+ server,
47741
+ headers: server.config.server.headers,
47742
+ }));
47717
47743
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
47718
47744
  return function viteServeRawFsMiddleware(req, res, next) {
47719
47745
  const url = new URL(req.url.replace(/^\/{2,}/, '/'), 'http://example.com');
@@ -47723,16 +47749,21 @@ function serveRawFsMiddleware(server) {
47723
47749
  // searching based from fs root.
47724
47750
  if (url.pathname.startsWith(FS_PREFIX)) {
47725
47751
  const pathname = decodeURI(url.pathname);
47726
- // restrict files outside of `fs.allow`
47727
- if (!ensureServingAccess(slash$1(path$o.resolve(fsPathFromId(pathname))), server, res, next)) {
47728
- return;
47729
- }
47730
47752
  let newPathname = pathname.slice(FS_PREFIX.length);
47731
47753
  if (isWindows$4)
47732
47754
  newPathname = newPathname.replace(/^[A-Z]:/i, '');
47733
47755
  url.pathname = encodeURI(newPathname);
47734
47756
  req.url = url.href.slice(url.origin.length);
47735
- serveFromRoot(req, res, next);
47757
+ try {
47758
+ serveFromRoot(req, res, next);
47759
+ }
47760
+ catch (e) {
47761
+ if (e && 'code' in e && e.code === ERR_DENIED_FILE) {
47762
+ respondWithAccessDenied(e.path, server, res);
47763
+ return;
47764
+ }
47765
+ throw e;
47766
+ }
47736
47767
  }
47737
47768
  else {
47738
47769
  next();
@@ -47741,41 +47772,62 @@ function serveRawFsMiddleware(server) {
47741
47772
  }
47742
47773
  /**
47743
47774
  * Check if the url is allowed to be served, via the `server.fs` config.
47775
+ * @deprecated Use the `isFileLoadingAllowed` function instead.
47744
47776
  */
47745
47777
  function isFileServingAllowed(url, server) {
47746
47778
  if (!server.config.server.fs.strict)
47747
47779
  return true;
47748
- const file = fsPathFromUrl(url);
47749
- if (server._fsDenyGlob(file))
47780
+ const filePath = fsPathFromUrl(url);
47781
+ return isFileLoadingAllowed(server, filePath);
47782
+ }
47783
+ function isUriInFilePath(uri, filePath) {
47784
+ return isSameFileUri(uri, filePath) || isParentDirectory(uri, filePath);
47785
+ }
47786
+ function isFileLoadingAllowed(server, filePath) {
47787
+ const { fs } = server.config.server;
47788
+ if (!fs.strict)
47789
+ return true;
47790
+ if (server._fsDenyGlob(filePath))
47750
47791
  return false;
47751
- if (server.moduleGraph.safeModulesPath.has(file))
47792
+ if (server.moduleGraph.safeModulesPath.has(filePath))
47752
47793
  return true;
47753
- if (server.config.server.fs.allow.some((uri) => isSameFileUri(uri, file) || isParentDirectory(uri, file)))
47794
+ if (fs.allow.some((uri) => isUriInFilePath(uri, filePath)))
47754
47795
  return true;
47755
47796
  return false;
47756
47797
  }
47757
- function ensureServingAccess(url, server, res, next) {
47798
+ function checkLoadingAccess(server, path) {
47799
+ if (isFileLoadingAllowed(server, slash$1(path))) {
47800
+ return 'allowed';
47801
+ }
47802
+ if (isFileReadable(path)) {
47803
+ return 'denied';
47804
+ }
47805
+ // if the file doesn't exist, we shouldn't restrict this path as it can
47806
+ // be an API call. Middlewares would issue a 404 if the file isn't handled
47807
+ return 'fallback';
47808
+ }
47809
+ function checkServingAccess(url, server) {
47758
47810
  if (isFileServingAllowed(url, server)) {
47759
- return true;
47811
+ return 'allowed';
47760
47812
  }
47761
47813
  if (isFileReadable(cleanUrl(url))) {
47762
- const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
47763
- const hintMessage = `
47814
+ return 'denied';
47815
+ }
47816
+ // if the file doesn't exist, we shouldn't restrict this path as it can
47817
+ // be an API call. Middlewares would issue a 404 if the file isn't handled
47818
+ return 'fallback';
47819
+ }
47820
+ function respondWithAccessDenied(url, server, res) {
47821
+ const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
47822
+ const hintMessage = `
47764
47823
  ${server.config.server.fs.allow.map((i) => `- ${i}`).join('\n')}
47765
47824
 
47766
47825
  Refer to docs https://vitejs.dev/config/server-options.html#server-fs-allow for configurations and more details.`;
47767
- server.config.logger.error(urlMessage);
47768
- server.config.logger.warnOnce(hintMessage + '\n');
47769
- res.statusCode = 403;
47770
- res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
47771
- res.end();
47772
- }
47773
- else {
47774
- // if the file doesn't exist, we shouldn't restrict this path as it can
47775
- // be an API call. Middlewares would issue a 404 if the file isn't handled
47776
- next();
47777
- }
47778
- return false;
47826
+ server.config.logger.error(urlMessage);
47827
+ server.config.logger.warnOnce(hintMessage + '\n');
47828
+ res.statusCode = 403;
47829
+ res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
47830
+ res.end();
47779
47831
  }
47780
47832
  function renderRestrictedErrorHTML(msg) {
47781
47833
  // to have syntax highlighting and autocompletion in IDE
@@ -64503,11 +64555,21 @@ const rawRE = /[?&]raw\b/;
64503
64555
  const inlineRE = /[?&]inline\b/;
64504
64556
  const svgRE = /\.svg\b/;
64505
64557
  function deniedServingAccessForTransform(url, server, res, next) {
64506
- return ((rawRE.test(url) ||
64558
+ if (rawRE.test(url) ||
64507
64559
  urlRE.test(url) ||
64508
64560
  inlineRE.test(url) ||
64509
- svgRE.test(url)) &&
64510
- !ensureServingAccess(url, server, res, next));
64561
+ svgRE.test(url)) {
64562
+ const servingAccessResult = checkServingAccess(url, server);
64563
+ if (servingAccessResult === 'denied') {
64564
+ respondWithAccessDenied(url, server, res);
64565
+ return true;
64566
+ }
64567
+ if (servingAccessResult === 'fallback') {
64568
+ next();
64569
+ return true;
64570
+ }
64571
+ }
64572
+ return false;
64511
64573
  }
64512
64574
  function transformMiddleware(server) {
64513
64575
  const { config: { root, logger }, moduleGraph, } = server;
@@ -65532,7 +65594,7 @@ async function _createServer(inlineConfig = {}, options) {
65532
65594
  // this applies before the transform middleware so that these files are served
65533
65595
  // as-is without transforms.
65534
65596
  if (config.publicDir) {
65535
- middlewares.use(servePublicMiddleware(config.publicDir, config.server.headers));
65597
+ middlewares.use(servePublicMiddleware(config.publicDir, server, config.server.headers));
65536
65598
  }
65537
65599
  // main transform middleware
65538
65600
  middlewares.use(transformMiddleware(server));
@@ -66648,4 +66710,4 @@ function isDepsOptimizerEnabled(config, ssr) {
66648
66710
  (command === 'serve' && disabled === 'dev'));
66649
66711
  }
66650
66712
 
66651
- 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 };
66713
+ export { isFileLoadingAllowed as A, loadEnv as B, resolveEnvPrefix as C, colors$1 as D, bindShortcuts as E, getDefaultExportFromCjs as F, commonjsGlobal as G, index$1 as H, build$1 as I, index as J, preview$1 as K, 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 };
@@ -1,4 +1,4 @@
1
- import { F as commonjsGlobal, E as getDefaultExportFromCjs } from './dep-42dae6ba.js';
1
+ import { G as commonjsGlobal, F as getDefaultExportFromCjs } from './dep-827b23df.js';
2
2
  import require$$0__default from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
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-42dae6ba.js';
5
+ import { D as colors, E as bindShortcuts, x as createLogger, h as resolveConfig } from './chunks/dep-827b23df.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -759,7 +759,7 @@ cli
759
759
  filterDuplicateOptions(options);
760
760
  // output structure is preserved even after bundling so require()
761
761
  // is ok here
762
- const { createServer } = await import('./chunks/dep-42dae6ba.js').then(function (n) { return n.I; });
762
+ const { createServer } = await import('./chunks/dep-827b23df.js').then(function (n) { return n.J; });
763
763
  try {
764
764
  const server = await createServer({
765
765
  root,
@@ -837,7 +837,7 @@ cli
837
837
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
838
838
  .action(async (root, options) => {
839
839
  filterDuplicateOptions(options);
840
- const { build } = await import('./chunks/dep-42dae6ba.js').then(function (n) { return n.H; });
840
+ const { build } = await import('./chunks/dep-827b23df.js').then(function (n) { return n.I; });
841
841
  const buildOptions = cleanOptions(options);
842
842
  try {
843
843
  await build({
@@ -865,7 +865,7 @@ cli
865
865
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
866
866
  .action(async (root, options) => {
867
867
  filterDuplicateOptions(options);
868
- const { optimizeDeps } = await import('./chunks/dep-42dae6ba.js').then(function (n) { return n.G; });
868
+ const { optimizeDeps } = await import('./chunks/dep-827b23df.js').then(function (n) { return n.H; });
869
869
  try {
870
870
  const config = await resolveConfig({
871
871
  root,
@@ -892,7 +892,7 @@ cli
892
892
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
893
893
  .action(async (root, options) => {
894
894
  filterDuplicateOptions(options);
895
- const { preview } = await import('./chunks/dep-42dae6ba.js').then(function (n) { return n.J; });
895
+ const { preview } = await import('./chunks/dep-827b23df.js').then(function (n) { return n.K; });
896
896
  try {
897
897
  const server = await preview({
898
898
  root,
@@ -1290,8 +1290,11 @@ export declare const isCSSRequest: (request: string) => boolean;
1290
1290
 
1291
1291
  export declare function isDepsOptimizerEnabled(config: ResolvedConfig, ssr: boolean): boolean;
1292
1292
 
1293
+ export declare function isFileLoadingAllowed(server: ViteDevServer, filePath: string): boolean;
1294
+
1293
1295
  /**
1294
1296
  * Check if the url is allowed to be served, via the `server.fs` config.
1297
+ * @deprecated Use the `isFileLoadingAllowed` function instead.
1295
1298
  */
1296
1299
  export declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
1297
1300
 
@@ -1,5 +1,5 @@
1
- import { i as isInNodeModules } from './chunks/dep-42dae6ba.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-42dae6ba.js';
1
+ import { i as isInNodeModules } from './chunks/dep-827b23df.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, A as isFileLoadingAllowed, z as isFileServingAllowed, l as loadConfigFromFile, B 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, C as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-827b23df.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';
@@ -3995,16 +3995,26 @@ function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
3995
3995
 
3996
3996
  /**
3997
3997
  * Check if the url is allowed to be served, via the `server.fs` config.
3998
+ * @deprecated Use the `isFileLoadingAllowed` function instead.
3998
3999
  */
3999
4000
  function isFileServingAllowed(url, server) {
4000
4001
  if (!server.config.server.fs.strict)
4001
4002
  return true;
4002
- const file = fsPathFromUrl(url);
4003
- if (server._fsDenyGlob(file))
4003
+ const filePath = fsPathFromUrl(url);
4004
+ return isFileLoadingAllowed(server, filePath);
4005
+ }
4006
+ function isUriInFilePath(uri, filePath) {
4007
+ return isSameFileUri(uri, filePath) || isParentDirectory(uri, filePath);
4008
+ }
4009
+ function isFileLoadingAllowed(server, filePath) {
4010
+ const { fs } = server.config.server;
4011
+ if (!fs.strict)
4012
+ return true;
4013
+ if (server._fsDenyGlob(filePath))
4004
4014
  return false;
4005
- if (server.moduleGraph.safeModulesPath.has(file))
4015
+ if (server.moduleGraph.safeModulesPath.has(filePath))
4006
4016
  return true;
4007
- if (server.config.server.fs.allow.some((uri) => isSameFileUri(uri, file) || isParentDirectory(uri, file)))
4017
+ if (fs.allow.some((uri) => isUriInFilePath(uri, filePath)))
4008
4018
  return true;
4009
4019
  return false;
4010
4020
  }
@@ -4531,6 +4541,7 @@ exports.rollupVersion = rollup.VERSION;
4531
4541
  exports.createFilter = createFilter;
4532
4542
  exports.createLogger = createLogger;
4533
4543
  exports.isCSSRequest = isCSSRequest;
4544
+ exports.isFileLoadingAllowed = isFileLoadingAllowed;
4534
4545
  exports.isFileServingAllowed = isFileServingAllowed;
4535
4546
  exports.loadEnv = loadEnv;
4536
4547
  exports.mergeAlias = mergeAlias;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "4.5.13",
3
+ "version": "4.5.14",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",