vite 6.3.3 → 6.3.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.
@@ -13026,7 +13026,7 @@ function esbuildCjsExternalPlugin(externals, platform) {
13026
13026
  (args) => ({
13027
13027
  contents: `import * as m from ${JSON.stringify(
13028
13028
  nonFacadePrefix + args.path
13029
- )};module.exports = m;`
13029
+ )};module.exports = { ...m };`
13030
13030
  })
13031
13031
  );
13032
13032
  }
@@ -35348,8 +35348,11 @@ function sirv (dir, opts={}) {
35348
35348
  }
35349
35349
 
35350
35350
  const knownJavascriptExtensionRE = /\.(?:[tj]sx?|[cm][tj]s)$/;
35351
+ const ERR_DENIED_FILE = "ERR_DENIED_FILE";
35351
35352
  const sirvOptions = ({
35352
- getHeaders
35353
+ config,
35354
+ getHeaders,
35355
+ disableFsServeCheck
35353
35356
  }) => {
35354
35357
  return {
35355
35358
  dev: true,
@@ -35365,6 +35368,19 @@ const sirvOptions = ({
35365
35368
  res.setHeader(name, headers[name]);
35366
35369
  }
35367
35370
  }
35371
+ },
35372
+ shouldServe: disableFsServeCheck ? void 0 : (filePath) => {
35373
+ const servingAccessResult = checkLoadingAccess(config, filePath);
35374
+ if (servingAccessResult === "denied") {
35375
+ const error = new Error("denied access");
35376
+ error.code = ERR_DENIED_FILE;
35377
+ error.path = filePath;
35378
+ throw error;
35379
+ }
35380
+ if (servingAccessResult === "fallback") {
35381
+ return false;
35382
+ }
35383
+ return true;
35368
35384
  }
35369
35385
  };
35370
35386
  };
@@ -35373,7 +35389,9 @@ function servePublicMiddleware(server, publicFiles) {
35373
35389
  const serve = sirv(
35374
35390
  dir,
35375
35391
  sirvOptions({
35376
- getHeaders: () => server.config.server.headers
35392
+ config: server.config,
35393
+ getHeaders: () => server.config.server.headers,
35394
+ disableFsServeCheck: true
35377
35395
  })
35378
35396
  );
35379
35397
  const toFilePath = (url) => {
@@ -35399,6 +35417,7 @@ function serveStaticMiddleware(server) {
35399
35417
  const serve = sirv(
35400
35418
  dir,
35401
35419
  sirvOptions({
35420
+ config: server.config,
35402
35421
  getHeaders: () => server.config.server.headers
35403
35422
  })
35404
35423
  );
@@ -35429,38 +35448,46 @@ function serveStaticMiddleware(server) {
35429
35448
  if (resolvedPathname.endsWith("/") && fileUrl[fileUrl.length - 1] !== "/") {
35430
35449
  fileUrl = withTrailingSlash(fileUrl);
35431
35450
  }
35432
- if (!ensureServingAccess(fileUrl, server, res, next)) {
35433
- return;
35434
- }
35435
35451
  if (redirectedPathname) {
35436
35452
  url.pathname = encodeURI(redirectedPathname);
35437
35453
  req.url = url.href.slice(url.origin.length);
35438
35454
  }
35439
- serve(req, res, next);
35455
+ try {
35456
+ serve(req, res, next);
35457
+ } catch (e) {
35458
+ if (e && "code" in e && e.code === ERR_DENIED_FILE) {
35459
+ respondWithAccessDenied(e.path, server, res);
35460
+ return;
35461
+ }
35462
+ throw e;
35463
+ }
35440
35464
  };
35441
35465
  }
35442
35466
  function serveRawFsMiddleware(server) {
35443
35467
  const serveFromRoot = sirv(
35444
35468
  "/",
35445
- sirvOptions({ getHeaders: () => server.config.server.headers })
35469
+ sirvOptions({
35470
+ config: server.config,
35471
+ getHeaders: () => server.config.server.headers
35472
+ })
35446
35473
  );
35447
35474
  return function viteServeRawFsMiddleware(req, res, next) {
35448
35475
  if (req.url.startsWith(FS_PREFIX)) {
35449
35476
  const url = new URL(req.url, "http://example.com");
35450
35477
  const pathname = decodeURI(url.pathname);
35451
- if (!ensureServingAccess(
35452
- slash$1(path$b.resolve(fsPathFromId(pathname))),
35453
- server,
35454
- res,
35455
- next
35456
- )) {
35457
- return;
35458
- }
35459
35478
  let newPathname = pathname.slice(FS_PREFIX.length);
35460
35479
  if (isWindows$3) newPathname = newPathname.replace(/^[A-Z]:/i, "");
35461
35480
  url.pathname = encodeURI(newPathname);
35462
35481
  req.url = url.href.slice(url.origin.length);
35463
- serveFromRoot(req, res, next);
35482
+ try {
35483
+ serveFromRoot(req, res, next);
35484
+ } catch (e) {
35485
+ if (e && "code" in e && e.code === ERR_DENIED_FILE) {
35486
+ respondWithAccessDenied(e.path, server, res);
35487
+ return;
35488
+ }
35489
+ throw e;
35490
+ }
35464
35491
  } else {
35465
35492
  next();
35466
35493
  }
@@ -35484,25 +35511,35 @@ function isFileLoadingAllowed(config, filePath) {
35484
35511
  if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true;
35485
35512
  return false;
35486
35513
  }
35487
- function ensureServingAccess(url, server, res, next) {
35514
+ function checkLoadingAccess(config, path2) {
35515
+ if (isFileLoadingAllowed(config, slash$1(path2))) {
35516
+ return "allowed";
35517
+ }
35518
+ if (isFileReadable(path2)) {
35519
+ return "denied";
35520
+ }
35521
+ return "fallback";
35522
+ }
35523
+ function checkServingAccess(url, server) {
35488
35524
  if (isFileServingAllowed(url, server)) {
35489
- return true;
35525
+ return "allowed";
35490
35526
  }
35491
35527
  if (isFileReadable(cleanUrl(url))) {
35492
- const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
35493
- const hintMessage = `
35528
+ return "denied";
35529
+ }
35530
+ return "fallback";
35531
+ }
35532
+ function respondWithAccessDenied(url, server, res) {
35533
+ const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
35534
+ const hintMessage = `
35494
35535
  ${server.config.server.fs.allow.map((i) => `- ${i}`).join("\n")}
35495
35536
 
35496
35537
  Refer to docs https://vite.dev/config/server-options.html#server-fs-allow for configurations and more details.`;
35497
- server.config.logger.error(urlMessage);
35498
- server.config.logger.warnOnce(hintMessage + "\n");
35499
- res.statusCode = 403;
35500
- res.write(renderRestrictedErrorHTML(urlMessage + "\n" + hintMessage));
35501
- res.end();
35502
- } else {
35503
- next();
35504
- }
35505
- return false;
35538
+ server.config.logger.error(urlMessage);
35539
+ server.config.logger.warnOnce(hintMessage + "\n");
35540
+ res.statusCode = 403;
35541
+ res.write(renderRestrictedErrorHTML(urlMessage + "\n" + hintMessage));
35542
+ res.end();
35506
35543
  }
35507
35544
  function renderRestrictedErrorHTML(msg) {
35508
35545
  const html = String.raw;
@@ -37080,7 +37117,18 @@ const rawRE = /[?&]raw\b/;
37080
37117
  const inlineRE$2 = /[?&]inline\b/;
37081
37118
  const svgRE = /\.svg\b/;
37082
37119
  function deniedServingAccessForTransform(url, server, res, next) {
37083
- return (rawRE.test(url) || urlRE.test(url) || inlineRE$2.test(url) || svgRE.test(url)) && !ensureServingAccess(url, server, res, next);
37120
+ if (rawRE.test(url) || urlRE.test(url) || inlineRE$2.test(url) || svgRE.test(url)) {
37121
+ const servingAccessResult = checkServingAccess(url, server);
37122
+ if (servingAccessResult === "denied") {
37123
+ respondWithAccessDenied(url, server, res);
37124
+ return true;
37125
+ }
37126
+ if (servingAccessResult === "fallback") {
37127
+ next();
37128
+ return true;
37129
+ }
37130
+ }
37131
+ return false;
37084
37132
  }
37085
37133
  function cachedTransformMiddleware(server) {
37086
37134
  return function viteCachedTransformMiddleware(req, res, next) {
@@ -43864,8 +43912,8 @@ function createCachedImport(imp) {
43864
43912
  return cached;
43865
43913
  };
43866
43914
  }
43867
- const importPostcssImport = createCachedImport(() => import('./dep-DD7x-aKn.js').then(function (n) { return n.i; }));
43868
- const importPostcssModules = createCachedImport(() => import('./dep-CixbwhWq.js').then(function (n) { return n.i; }));
43915
+ const importPostcssImport = createCachedImport(() => import('./dep-SOJpRpBL.js').then(function (n) { return n.i; }));
43916
+ const importPostcssModules = createCachedImport(() => import('./dep-D5ITTxnT.js').then(function (n) { return n.i; }));
43869
43917
  const importPostcss = createCachedImport(() => import('postcss'));
43870
43918
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
43871
43919
  let alwaysFakeWorkerWorkerControllerCache;
@@ -1,4 +1,4 @@
1
- import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-BMIURPaQ.js';
1
+ import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-Bn81Esdm.js';
2
2
  import require$$0$2 from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -1,4 +1,4 @@
1
- import { P as getDefaultExportFromCjs } from './dep-BMIURPaQ.js';
1
+ import { P as getDefaultExportFromCjs } from './dep-Bn81Esdm.js';
2
2
  import require$$0 from 'path';
3
3
  import { l as lib } from './dep-3RmXg9uo.js';
4
4
 
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs__default from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-BMIURPaQ.js';
5
+ import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-Bn81Esdm.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -748,7 +748,7 @@ cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--
748
748
  `[boolean] force the optimizer to ignore the cache and re-bundle`
749
749
  ).action(async (root, options) => {
750
750
  filterDuplicateOptions(options);
751
- const { createServer } = await import('./chunks/dep-BMIURPaQ.js').then(function (n) { return n.S; });
751
+ const { createServer } = await import('./chunks/dep-Bn81Esdm.js').then(function (n) { return n.S; });
752
752
  try {
753
753
  const server = await createServer({
754
754
  root,
@@ -843,7 +843,7 @@ cli.command("build [root]", "build for production").option("--target <target>",
843
843
  ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--app", `[boolean] same as \`builder: {}\``).action(
844
844
  async (root, options) => {
845
845
  filterDuplicateOptions(options);
846
- const { createBuilder } = await import('./chunks/dep-BMIURPaQ.js').then(function (n) { return n.T; });
846
+ const { createBuilder } = await import('./chunks/dep-Bn81Esdm.js').then(function (n) { return n.T; });
847
847
  const buildOptions = cleanGlobalCLIOptions(
848
848
  cleanBuilderCLIOptions(options)
849
849
  );
@@ -882,7 +882,7 @@ cli.command(
882
882
  ).action(
883
883
  async (root, options) => {
884
884
  filterDuplicateOptions(options);
885
- const { optimizeDeps } = await import('./chunks/dep-BMIURPaQ.js').then(function (n) { return n.R; });
885
+ const { optimizeDeps } = await import('./chunks/dep-Bn81Esdm.js').then(function (n) { return n.R; });
886
886
  try {
887
887
  const config = await resolveConfig(
888
888
  {
@@ -909,7 +909,7 @@ ${e.stack}`),
909
909
  cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`, { type: [convertHost] }).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--open [path]", `[boolean | string] open browser on startup`).option("--outDir <dir>", `[string] output directory (default: dist)`).action(
910
910
  async (root, options) => {
911
911
  filterDuplicateOptions(options);
912
- const { preview } = await import('./chunks/dep-BMIURPaQ.js').then(function (n) { return n.U; });
912
+ const { preview } = await import('./chunks/dep-Bn81Esdm.js').then(function (n) { return n.U; });
913
913
  try {
914
914
  const server = await preview({
915
915
  root,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { PluginHooks, RollupError, SourceMap, ModuleInfo, PartialResolvedId, RollupOptions, InputOption, ModuleFormat, WatcherOptions, RollupOutput, RollupWatcher, InputOptions, CustomPluginOptions, LoadResult, SourceDescription, PluginContextMeta, RollupLog, OutputBundle, OutputChunk, ObjectHook, ResolveIdResult, ExistingRawSourceMap, SourceMapInput, GetManualChunk } from 'rollup';
2
+ import { PluginHooks, RollupError, SourceMap, ModuleInfo, PartialResolvedId, RollupOptions, InputOption, ModuleFormat, WatcherOptions, RollupOutput, RollupWatcher, PluginContext, InputOptions, CustomPluginOptions, LoadResult, SourceDescription, PluginContextMeta, RollupLog, OutputBundle, OutputChunk, ObjectHook, ResolveIdResult, TransformPluginContext, ExistingRawSourceMap, SourceMapInput, GetManualChunk } from 'rollup';
3
3
  import * as rollup from 'rollup';
4
4
  export { rollup as Rollup };
5
5
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
@@ -3240,12 +3240,6 @@ interface PluginContextExtension {
3240
3240
  interface HotUpdatePluginContext {
3241
3241
  environment: DevEnvironment;
3242
3242
  }
3243
- interface PluginContext extends rollup.PluginContext, PluginContextExtension {
3244
- }
3245
- interface ResolveIdPluginContext extends rollup.PluginContext, PluginContextExtension {
3246
- }
3247
- interface TransformPluginContext extends rollup.TransformPluginContext, PluginContextExtension {
3248
- }
3249
3243
  declare module 'rollup' {
3250
3244
  interface MinimalPluginContext extends PluginContextExtension {
3251
3245
  }
@@ -3280,7 +3274,7 @@ interface Plugin<A = any> extends rollup.Plugin<A> {
3280
3274
  /**
3281
3275
  * extend hooks with ssr flag
3282
3276
  */
3283
- resolveId?: ObjectHook<(this: ResolveIdPluginContext, source: string, importer: string | undefined, options: {
3277
+ resolveId?: ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: {
3284
3278
  attributes: Record<string, string>;
3285
3279
  custom?: CustomPluginOptions;
3286
3280
  ssr?: boolean;
@@ -4202,11 +4196,9 @@ declare function searchForWorkspaceRoot(current: string, root?: string): string;
4202
4196
 
4203
4197
  /**
4204
4198
  * Check if the url is allowed to be served, via the `server.fs` config.
4199
+ * @deprecated Use the `isFileLoadingAllowed` function instead.
4205
4200
  */
4206
4201
  declare function isFileServingAllowed(config: ResolvedConfig, url: string): boolean;
4207
- /**
4208
- * @deprecated Use the `isFileServingAllowed(config, url)` signature instead.
4209
- */
4210
4202
  declare function isFileServingAllowed(url: string, server: ViteDevServer): boolean;
4211
4203
  declare function isFileLoadingAllowed(config: ResolvedConfig, filePath: string): boolean;
4212
4204
 
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { a as arraify, i as isInNodeModules, D as DevEnvironment } from './chunks/dep-BMIURPaQ.js';
3
- export { B as BuildEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-BMIURPaQ.js';
2
+ import { a as arraify, i as isInNodeModules, D as DevEnvironment } from './chunks/dep-Bn81Esdm.js';
3
+ export { B as BuildEnvironment, f as build, m as buildErrorMessage, g as createBuilder, F as createFilter, h as createIdResolver, I as createLogger, n as createRunnableDevEnvironment, c as createServer, y as createServerHotChannel, w as createServerModuleRunner, x as createServerModuleRunnerTransport, d as defineConfig, v as fetchModule, j as formatPostcssSourceMap, L as isFileLoadingAllowed, K as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, M as loadEnv, E as mergeAlias, C as mergeConfig, z as moduleRunnerTransform, A as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, N as resolveEnvPrefix, G as rollupVersion, u as runnerImport, J as searchForWorkspaceRoot, H as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Bn81Esdm.js';
4
4
  export { defaultAllowedOrigins, DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import 'node:fs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.3.3",
3
+ "version": "6.3.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",