vite 6.4.0 → 6.4.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,4 +1,4 @@
1
- import { P as getDefaultExportFromCjs } from './dep-N2lvmi1C.js';
1
+ import { P as getDefaultExportFromCjs } from './dep-Dq2t6Dq0.js';
2
2
  import require$$0 from 'path';
3
3
  import { l as lib } from './dep-3RmXg9uo.js';
4
4
 
@@ -35509,7 +35509,8 @@ function isUriInFilePath(uri, filePath) {
35509
35509
  function isFileLoadingAllowed(config, filePath) {
35510
35510
  const { fs } = config.server;
35511
35511
  if (!fs.strict) return true;
35512
- if (config.fsDenyGlob(filePath)) return false;
35512
+ const filePathWithoutTrailingSlash = filePath.endsWith("/") ? filePath.slice(0, -1) : filePath;
35513
+ if (config.fsDenyGlob(filePathWithoutTrailingSlash)) return false;
35513
35514
  if (config.safeModulePaths.has(filePath)) return true;
35514
35515
  if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true;
35515
35516
  return false;
@@ -35661,8 +35662,9 @@ async function loadAndTransform(environment, id, url, options, timestamp, mod, r
35661
35662
  const { config, pluginContainer, logger } = environment;
35662
35663
  const prettyUrl = debugLoad || debugTransform ? prettifyUrl(url, config.root) : "";
35663
35664
  const moduleGraph = environment.moduleGraph;
35664
- if (options.allowId && !options.allowId(id)) {
35665
+ if (!options.skipFsCheck && id[0] !== "\0" && isServerAccessDeniedForTransform(config, id)) {
35665
35666
  const err = new Error(`Denied ID ${id}`);
35667
+ err.id = id;
35666
35668
  err.code = ERR_DENIED_ID;
35667
35669
  throw err;
35668
35670
  }
@@ -35675,7 +35677,7 @@ async function loadAndTransform(environment, id, url, options, timestamp, mod, r
35675
35677
  if (options.html && !id.endsWith(".html")) {
35676
35678
  return null;
35677
35679
  }
35678
- if (environment.config.consumer === "server" || isFileLoadingAllowed(environment.getTopLevelConfig(), file)) {
35680
+ if (options.skipFsCheck || isFileLoadingAllowed(environment.getTopLevelConfig(), slash$1(file))) {
35679
35681
  try {
35680
35682
  code = await fsp.readFile(file, "utf-8");
35681
35683
  debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`);
@@ -37133,6 +37135,12 @@ function deniedServingAccessForTransform(url, server, res, next) {
37133
37135
  }
37134
37136
  return false;
37135
37137
  }
37138
+ function isServerAccessDeniedForTransform(config, id) {
37139
+ if (rawRE.test(id) || urlRE.test(id) || inlineRE$2.test(id) || svgRE.test(id)) {
37140
+ return checkLoadingAccess(config, id) !== "allowed";
37141
+ }
37142
+ return false;
37143
+ }
37136
37144
  function cachedTransformMiddleware(server) {
37137
37145
  return function viteCachedTransformMiddleware(req, res, next) {
37138
37146
  const environment = server.environments.client;
@@ -37182,6 +37190,9 @@ function transformMiddleware(server) {
37182
37190
  const depsOptimizer = environment.depsOptimizer;
37183
37191
  if (depsOptimizer?.isOptimizedDepUrl(url)) {
37184
37192
  const sourcemapPath = url.startsWith(FS_PREFIX) ? fsPathFromId(url) : normalizePath$3(path$b.resolve(server.config.root, url.slice(1)));
37193
+ if (!depsOptimizer.isOptimizedDepFile(sourcemapPath)) {
37194
+ return next();
37195
+ }
37185
37196
  try {
37186
37197
  const map = JSON.parse(
37187
37198
  await fsp.readFile(sourcemapPath, "utf-8")
@@ -37252,9 +37263,7 @@ function transformMiddleware(server) {
37252
37263
  }
37253
37264
  const result = await transformRequest(environment, url, {
37254
37265
  html: req.headers.accept?.includes("text/html"),
37255
- allowId(id) {
37256
- return !deniedServingAccessForTransform(id, server, res, next);
37257
- }
37266
+ skipFsCheck: environment._skipFsCheck
37258
37267
  });
37259
37268
  if (result) {
37260
37269
  const depsOptimizer = environment.depsOptimizer;
@@ -37307,7 +37316,23 @@ function transformMiddleware(server) {
37307
37316
  return next();
37308
37317
  }
37309
37318
  if (e?.code === ERR_DENIED_ID) {
37310
- return;
37319
+ const id = e.id;
37320
+ let servingAccessResult = checkLoadingAccess(
37321
+ server.config,
37322
+ cleanUrl(id)
37323
+ );
37324
+ if (servingAccessResult === "allowed") {
37325
+ servingAccessResult = checkLoadingAccess(server.config, id);
37326
+ }
37327
+ if (servingAccessResult === "denied") {
37328
+ respondWithAccessDenied(id, server, res);
37329
+ return true;
37330
+ }
37331
+ if (servingAccessResult === "fallback") {
37332
+ next();
37333
+ return true;
37334
+ }
37335
+ throw new Error(`Unexpected access result for id ${id}`);
37311
37336
  }
37312
37337
  return next(e);
37313
37338
  }
@@ -39655,6 +39680,7 @@ function createServerHotChannel() {
39655
39680
  const innerEmitter = new EventEmitter$4();
39656
39681
  const outsideEmitter = new EventEmitter$4();
39657
39682
  return {
39683
+ skipFsCheck: true,
39658
39684
  send(payload) {
39659
39685
  outsideEmitter.emit("send", payload);
39660
39686
  },
@@ -43940,8 +43966,8 @@ function createCachedImport(imp) {
43940
43966
  return cached;
43941
43967
  };
43942
43968
  }
43943
- const importPostcssImport = createCachedImport(() => import('./dep-BgXtUGwv.js').then(function (n) { return n.i; }));
43944
- const importPostcssModules = createCachedImport(() => import('./dep-DpdbJjFS.js').then(function (n) { return n.i; }));
43969
+ const importPostcssImport = createCachedImport(() => import('./dep-4-IQbZQm.js').then(function (n) { return n.i; }));
43970
+ const importPostcssModules = createCachedImport(() => import('./dep-lpEPC2f9.js').then(function (n) { return n.i; }));
43945
43971
  const importPostcss = createCachedImport(() => import('postcss'));
43946
43972
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
43947
43973
  let alwaysFakeWorkerWorkerControllerCache;
@@ -47833,6 +47859,10 @@ class DevEnvironment extends BaseEnvironment {
47833
47859
  * @internal
47834
47860
  */
47835
47861
  _remoteRunnerOptions;
47862
+ /**
47863
+ * @internal
47864
+ */
47865
+ _skipFsCheck;
47836
47866
  get pluginContainer() {
47837
47867
  if (!this._pluginContainer)
47838
47868
  throw new Error(
@@ -47880,9 +47910,13 @@ class DevEnvironment extends BaseEnvironment {
47880
47910
  );
47881
47911
  this._crawlEndFinder = setupOnCrawlEnd();
47882
47912
  this._remoteRunnerOptions = context.remoteRunner ?? {};
47913
+ this._skipFsCheck = !!(context.transport && !(isWebSocketServer in context.transport) && context.transport.skipFsCheck);
47883
47914
  this.hot = context.transport ? isWebSocketServer in context.transport ? context.transport : normalizeHotChannel(context.transport, context.hot) : normalizeHotChannel({}, context.hot);
47884
47915
  this.hot.setInvokeHandler({
47885
47916
  fetchModule: (id, importer, options2) => {
47917
+ if (context.disableFetchModule) {
47918
+ throw new Error("fetchModule is disabled in this environment");
47919
+ }
47886
47920
  return this.fetchModule(id, importer, options2);
47887
47921
  }
47888
47922
  });
@@ -47940,11 +47974,11 @@ class DevEnvironment extends BaseEnvironment {
47940
47974
  }
47941
47975
  }
47942
47976
  transformRequest(url) {
47943
- return transformRequest(this, url);
47977
+ return transformRequest(this, url, { skipFsCheck: this._skipFsCheck });
47944
47978
  }
47945
47979
  async warmupRequest(url) {
47946
47980
  try {
47947
- await this.transformRequest(url);
47981
+ await transformRequest(this, url, { skipFsCheck: true });
47948
47982
  } catch (e) {
47949
47983
  if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP || e?.code === ERR_CLOSED_SERVER) {
47950
47984
  return;
@@ -48444,7 +48478,8 @@ function defineConfig(config) {
48444
48478
  function defaultCreateClientDevEnvironment(name, config, context) {
48445
48479
  return new DevEnvironment(name, config, {
48446
48480
  hot: true,
48447
- transport: context.ws
48481
+ transport: context.ws,
48482
+ disableFetchModule: true
48448
48483
  });
48449
48484
  }
48450
48485
  function defaultCreateDevEnvironment(name, config) {
@@ -1,4 +1,4 @@
1
- import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-N2lvmi1C.js';
1
+ import { Q as commonjsGlobal, P as getDefaultExportFromCjs } from './dep-Dq2t6Dq0.js';
2
2
  import require$$0$2 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__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-N2lvmi1C.js';
5
+ import { O as colors, I as createLogger, r as resolveConfig } from './chunks/dep-Dq2t6Dq0.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-N2lvmi1C.js').then(function (n) { return n.S; });
751
+ const { createServer } = await import('./chunks/dep-Dq2t6Dq0.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-N2lvmi1C.js').then(function (n) { return n.T; });
846
+ const { createBuilder } = await import('./chunks/dep-Dq2t6Dq0.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-N2lvmi1C.js').then(function (n) { return n.R; });
885
+ const { optimizeDeps } = await import('./chunks/dep-Dq2t6Dq0.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-N2lvmi1C.js').then(function (n) { return n.U; });
912
+ const { preview } = await import('./chunks/dep-Dq2t6Dq0.js').then(function (n) { return n.U; });
913
913
  try {
914
914
  const server = await preview({
915
915
  root,
@@ -1220,6 +1220,11 @@ interface HotChannelClient {
1220
1220
  type HMRBroadcasterClient = HotChannelClient;
1221
1221
  type HotChannelListener<T extends string = string> = (data: InferCustomEventPayload<T>, client: HotChannelClient) => void;
1222
1222
  interface HotChannel<Api = any> {
1223
+ /**
1224
+ * When true, the fs access check is skipped in fetchModule.
1225
+ * Set this for transports that is not exposed over the network.
1226
+ */
1227
+ skipFsCheck?: boolean;
1223
1228
  /**
1224
1229
  * Broadcast events to all clients
1225
1230
  */
@@ -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-N2lvmi1C.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-N2lvmi1C.js';
2
+ import { a as arraify, i as isInNodeModules, D as DevEnvironment } from './chunks/dep-Dq2t6Dq0.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-Dq2t6Dq0.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';
@@ -3417,7 +3417,8 @@ function isUriInFilePath(uri, filePath) {
3417
3417
  function isFileLoadingAllowed(config, filePath) {
3418
3418
  const { fs } = config.server;
3419
3419
  if (!fs.strict) return true;
3420
- if (config.fsDenyGlob(filePath)) return false;
3420
+ const filePathWithoutTrailingSlash = filePath.endsWith("/") ? filePath.slice(0, -1) : filePath;
3421
+ if (config.fsDenyGlob(filePathWithoutTrailingSlash)) return false;
3421
3422
  if (config.safeModulePaths.has(filePath)) return true;
3422
3423
  if (fs.allow.some((uri) => isUriInFilePath(uri, filePath))) return true;
3423
3424
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.4.0",
3
+ "version": "6.4.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",