vite 7.3.1 → 7.3.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.
@@ -22552,7 +22552,7 @@ const ERR_DENIED_ID = "ERR_DENIED_ID";
22552
22552
  const debugLoad = createDebugger("vite:load");
22553
22553
  const debugTransform = createDebugger("vite:transform");
22554
22554
  const debugCache$1 = createDebugger("vite:cache");
22555
- function transformRequest(environment, url$3, options$1 = {}) {
22555
+ function transformRequest(environment, url$3, options$1) {
22556
22556
  if (environment._closing && environment.config.dev.recoverable) throwClosedServerError();
22557
22557
  const timestamp = monotonicDateNow();
22558
22558
  url$3 = removeTimestampQuery(url$3);
@@ -22616,7 +22616,7 @@ async function loadAndTransform(environment, id, url$3, options$1, timestamp, mo
22616
22616
  const { config: config$2, pluginContainer, logger } = environment;
22617
22617
  const prettyUrl = debugLoad || debugTransform ? prettifyUrl(url$3, config$2.root) : "";
22618
22618
  const moduleGraph = environment.moduleGraph;
22619
- if (options$1.allowId && !options$1.allowId(id)) {
22619
+ if (!options$1.skipFsCheck && id[0] !== "\0" && isServerAccessDeniedForTransform(config$2, id)) {
22620
22620
  const err$2 = /* @__PURE__ */ new Error(`Denied ID ${id}`);
22621
22621
  err$2.code = ERR_DENIED_ID;
22622
22622
  err$2.id = id;
@@ -22628,7 +22628,7 @@ async function loadAndTransform(environment, id, url$3, options$1, timestamp, mo
22628
22628
  const loadResult = await pluginContainer.load(id);
22629
22629
  if (loadResult == null) {
22630
22630
  const file = cleanUrl(id);
22631
- if (environment.config.consumer === "server" || isFileLoadingAllowed(environment.getTopLevelConfig(), slash(file))) {
22631
+ if (options$1.skipFsCheck || isFileLoadingAllowed(environment.getTopLevelConfig(), slash(file))) {
22632
22632
  try {
22633
22633
  code = await fsp.readFile(file, "utf-8");
22634
22634
  debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`);
@@ -24454,7 +24454,7 @@ const rawRE$1 = /[?&]raw\b/;
24454
24454
  const inlineRE$2 = /[?&]inline\b/;
24455
24455
  const svgRE = /\.svg\b/;
24456
24456
  function isServerAccessDeniedForTransform(config$2, id) {
24457
- if (rawRE$1.test(id) || urlRE$1.test(id) || inlineRE$2.test(id) || svgRE.test(id)) return checkLoadingAccess(config$2, id) !== "allowed";
24457
+ if (rawRE$1.test(id) || urlRE$1.test(id) || inlineRE$2.test(id) || svgRE.test(id)) return checkLoadingAccess(config$2, cleanUrl(id)) !== "allowed" || checkLoadingAccess(config$2, id) !== "allowed";
24458
24458
  return false;
24459
24459
  }
24460
24460
  /**
@@ -24500,31 +24500,35 @@ function transformMiddleware(server) {
24500
24500
  }
24501
24501
  const withoutQuery = cleanUrl(url$3);
24502
24502
  try {
24503
- if (withoutQuery.endsWith(".map")) if (environment.depsOptimizer?.isOptimizedDepUrl(url$3)) {
24504
- const sourcemapPath = url$3.startsWith(FS_PREFIX) ? fsPathFromId(url$3) : normalizePath(path.resolve(server.config.root, url$3.slice(1)));
24505
- try {
24506
- const map$1 = JSON.parse(await fsp.readFile(sourcemapPath, "utf-8"));
24507
- applySourcemapIgnoreList(map$1, sourcemapPath, server.config.server.sourcemapIgnoreList, server.config.logger);
24508
- return send(req$4, res, JSON.stringify(map$1), "json", { headers: server.config.server.headers });
24509
- } catch {
24510
- const dummySourceMap = {
24511
- version: 3,
24512
- file: sourcemapPath.replace(/\.map$/, ""),
24513
- sources: [],
24514
- sourcesContent: [],
24515
- names: [],
24516
- mappings: ";;;;;;;;;"
24517
- };
24518
- return send(req$4, res, JSON.stringify(dummySourceMap), "json", {
24519
- cacheControl: "no-cache",
24520
- headers: server.config.server.headers
24521
- });
24503
+ if (withoutQuery.endsWith(".map")) {
24504
+ const depsOptimizer = environment.depsOptimizer;
24505
+ if (depsOptimizer?.isOptimizedDepUrl(url$3)) {
24506
+ const sourcemapPath = url$3.startsWith(FS_PREFIX) ? fsPathFromId(url$3) : normalizePath(path.resolve(server.config.root, url$3.slice(1)));
24507
+ if (!depsOptimizer.isOptimizedDepFile(sourcemapPath)) return next();
24508
+ try {
24509
+ const map$1 = JSON.parse(await fsp.readFile(sourcemapPath, "utf-8"));
24510
+ applySourcemapIgnoreList(map$1, sourcemapPath, server.config.server.sourcemapIgnoreList, server.config.logger);
24511
+ return send(req$4, res, JSON.stringify(map$1), "json", { headers: server.config.server.headers });
24512
+ } catch {
24513
+ const dummySourceMap = {
24514
+ version: 3,
24515
+ file: sourcemapPath.replace(/\.map$/, ""),
24516
+ sources: [],
24517
+ sourcesContent: [],
24518
+ names: [],
24519
+ mappings: ";;;;;;;;;"
24520
+ };
24521
+ return send(req$4, res, JSON.stringify(dummySourceMap), "json", {
24522
+ cacheControl: "no-cache",
24523
+ headers: server.config.server.headers
24524
+ });
24525
+ }
24526
+ } else {
24527
+ const originalUrl = url$3.replace(/\.map($|\?)/, "$1");
24528
+ const map$1 = (await environment.moduleGraph.getModuleByUrl(originalUrl))?.transformResult?.map;
24529
+ if (map$1) return send(req$4, res, JSON.stringify(map$1), "json", { headers: server.config.server.headers });
24530
+ else return next();
24522
24531
  }
24523
- } else {
24524
- const originalUrl = url$3.replace(/\.map($|\?)/, "$1");
24525
- const map$1 = (await environment.moduleGraph.getModuleByUrl(originalUrl))?.transformResult?.map;
24526
- if (map$1) return send(req$4, res, JSON.stringify(map$1), "json", { headers: server.config.server.headers });
24527
- else return next();
24528
24532
  }
24529
24533
  if (publicDirInRoot && url$3.startsWith(publicPath)) warnAboutExplicitPublicPathInUrl(url$3);
24530
24534
  if (req$4.headers["sec-fetch-dest"] === "script" || isJSRequest(url$3) || isImportRequest(url$3) || isCSSRequest(url$3) || isHTMLProxy(url$3)) {
@@ -24539,9 +24543,7 @@ function transformMiddleware(server) {
24539
24543
  return res.end();
24540
24544
  }
24541
24545
  }
24542
- const result = await environment.transformRequest(url$3, { allowId(id) {
24543
- return id[0] === "\0" || !isServerAccessDeniedForTransform(server.config, id);
24544
- } });
24546
+ const result = await environment.transformRequest(url$3);
24545
24547
  if (result) {
24546
24548
  const depsOptimizer = environment.depsOptimizer;
24547
24549
  const type = isDirectCSSRequest(url$3) ? "css" : "js";
@@ -24591,7 +24593,8 @@ function transformMiddleware(server) {
24591
24593
  if (e$1?.code === ERR_LOAD_URL) return next();
24592
24594
  if (e$1?.code === ERR_DENIED_ID) {
24593
24595
  const id = e$1.id;
24594
- const servingAccessResult = checkLoadingAccess(server.config, id);
24596
+ let servingAccessResult = checkLoadingAccess(server.config, cleanUrl(id));
24597
+ if (servingAccessResult === "allowed") servingAccessResult = checkLoadingAccess(server.config, id);
24595
24598
  if (servingAccessResult === "denied") {
24596
24599
  respondWithAccessDenied(id, server, res);
24597
24600
  return true;
@@ -26326,6 +26329,7 @@ function createServerHotChannel() {
26326
26329
  const innerEmitter = new EventEmitter();
26327
26330
  const outsideEmitter = new EventEmitter();
26328
26331
  return {
26332
+ skipFsCheck: true,
26329
26333
  send(payload) {
26330
26334
  outsideEmitter.emit("send", payload);
26331
26335
  },
@@ -34741,6 +34745,10 @@ var DevEnvironment = class extends BaseEnvironment {
34741
34745
  * @internal
34742
34746
  */
34743
34747
  _remoteRunnerOptions;
34748
+ /**
34749
+ * @internal
34750
+ */
34751
+ _skipFsCheck;
34744
34752
  get pluginContainer() {
34745
34753
  if (!this._pluginContainer) throw new Error(`${this.name} environment.pluginContainer called before initialized`);
34746
34754
  return this._pluginContainer;
@@ -34778,9 +34786,11 @@ var DevEnvironment = class extends BaseEnvironment {
34778
34786
  this.moduleGraph = new EnvironmentModuleGraph(name, (url$3) => this.pluginContainer.resolveId(url$3, void 0));
34779
34787
  this._crawlEndFinder = setupOnCrawlEnd();
34780
34788
  this._remoteRunnerOptions = context.remoteRunner ?? {};
34789
+ this._skipFsCheck = !!(context.transport && !(isWebSocketServer in context.transport) && context.transport.skipFsCheck);
34781
34790
  this.hot = context.transport ? isWebSocketServer in context.transport ? context.transport : normalizeHotChannel(context.transport, context.hot) : normalizeHotChannel({}, context.hot);
34782
34791
  this.hot.setInvokeHandler({
34783
34792
  fetchModule: (id, importer, options$2) => {
34793
+ if (context.disableFetchModule) throw new Error("fetchModule is disabled in this environment");
34784
34794
  return this.fetchModule(id, importer, options$2);
34785
34795
  },
34786
34796
  getBuiltins: async () => {
@@ -34831,12 +34841,12 @@ var DevEnvironment = class extends BaseEnvironment {
34831
34841
  async reloadModule(module$1) {
34832
34842
  if (this.config.server.hmr !== false && module$1.file) updateModules(this, module$1.file, [module$1], monotonicDateNow());
34833
34843
  }
34834
- transformRequest(url$3, options$1) {
34835
- return transformRequest(this, url$3, options$1);
34844
+ transformRequest(url$3) {
34845
+ return transformRequest(this, url$3, { skipFsCheck: this._skipFsCheck });
34836
34846
  }
34837
34847
  async warmupRequest(url$3) {
34838
34848
  try {
34839
- await this.transformRequest(url$3);
34849
+ await transformRequest(this, url$3, { skipFsCheck: true });
34840
34850
  } catch (e$1) {
34841
34851
  if (e$1?.code === ERR_OUTDATED_OPTIMIZED_DEP || e$1?.code === ERR_CLOSED_SERVER) return;
34842
34852
  this.logger.error(buildErrorMessage(e$1, [`Pre-transform error: ${e$1.message}`], false), {
@@ -35218,7 +35228,8 @@ function defineConfig(config$2) {
35218
35228
  function defaultCreateClientDevEnvironment(name, config$2, context) {
35219
35229
  return new DevEnvironment(name, config$2, {
35220
35230
  hot: true,
35221
- transport: context.ws
35231
+ transport: context.ws,
35232
+ disableFetchModule: true
35222
35233
  });
35223
35234
  }
35224
35235
  function defaultCreateDevEnvironment(name, config$2) {
@@ -956,7 +956,6 @@ interface TransformOptions {
956
956
  */
957
957
  ssr?: boolean;
958
958
  }
959
- interface TransformOptionsInternal {}
960
959
  //#endregion
961
960
  //#region src/node/server/moduleGraph.d.ts
962
961
  declare class EnvironmentModuleNode {
@@ -1121,6 +1120,11 @@ interface HotChannelClient {
1121
1120
  }
1122
1121
  type HotChannelListener<T$1 extends string = string> = (data: InferCustomEventPayload<T$1>, client: HotChannelClient) => void;
1123
1122
  interface HotChannel<Api = any> {
1123
+ /**
1124
+ * When true, the fs access check is skipped in fetchModule.
1125
+ * Set this for transports that is not exposed over the network.
1126
+ */
1127
+ skipFsCheck?: boolean;
1124
1128
  /**
1125
1129
  * Broadcast events to all clients
1126
1130
  */
@@ -1565,7 +1569,7 @@ declare class DevEnvironment extends BaseEnvironment {
1565
1569
  listen(server: ViteDevServer): Promise<void>;
1566
1570
  fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<moduleRunner_FetchResult>;
1567
1571
  reloadModule(module: EnvironmentModuleNode): Promise<void>;
1568
- transformRequest(url: string, options?: TransformOptionsInternal): Promise<TransformResult | null>;
1572
+ transformRequest(url: string): Promise<TransformResult | null>;
1569
1573
  warmupRequest(url: string): Promise<void>;
1570
1574
  close(): Promise<void>;
1571
1575
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "7.3.1",
3
+ "version": "7.3.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",