Fix warning with vite dev

This commit is contained in:
2026-11-11 14:46:51 -03:00
parent 216d54a0ae
commit 8aa05e104d
9 changed files with 132 additions and 42 deletions
+1 -2
View File
@@ -10,7 +10,7 @@ import {
} from "./context.ts";
import { mergePath, type Method, UrlPatternRouter } from "./router.ts";
import type { FreshConfig, ResolvedFreshConfig } from "./config.ts";
import type { BuildCache } from "./build_cache.ts";
import { type BuildCache, MockBuildCache } from "./build_cache.ts";
import { HttpError } from "./error.ts";
import { STATUS_TEXT } from "@std/http/status";
import type { LayoutConfig, MaybeLazy, Route, RouteConfig } from "./types.ts";
@@ -29,7 +29,6 @@ import {
newNotFoundCmd,
newRouteCmd,
} from "./commands.ts";
import { MockBuildCache } from "./test_utils.ts";
// TODO: Completed type clashes in older Deno versions
// deno-lint-ignore no-explicit-any
+26
View File
@@ -102,6 +102,32 @@ export class ProdBuildCache<State> implements BuildCache<State> {
}
}
/** Fallback build cache for when there's no build output (and for tests). */
export class MockBuildCache<State> implements BuildCache<State> {
#files: FsRouteFile<State>[];
root = "";
clientEntry = "";
islandRegistry: ServerIslandRegistry = new Map();
features = { errorOverlay: false };
constructor(files: FsRouteFile<State>[], mode: "development" | "production") {
this.features.errorOverlay = mode === "development";
this.#files = files;
}
getEntryAssets(): string[] {
return [];
}
getFsRoutes(): Command<State>[] {
return fsItemsToCommands(this.#files);
}
readFile(_pathname: string): Promise<StaticFile | null> {
return Promise.resolve(null);
}
}
export class IslandPreparer {
#namer = new UniqueNamer();
+1 -8
View File
@@ -8,7 +8,7 @@ import * as pathWin32 from "@std/path/windows";
import { encodeHex } from "@std/encoding/hex";
import { fsAdapter } from "../fs.ts";
import type { FileTransformer } from "./file_transformer.ts";
import { assertInDir, pathToSpec } from "../utils.ts";
import { assertInDir, pathToSpec, toPosix } from "../utils.ts";
import type { ResolvedBuildConfig } from "./builder.ts";
import { fsItemsToCommands, type FsRouteFile } from "../fs_routes.ts";
import type { Command } from "../commands.ts";
@@ -17,13 +17,6 @@ import { contentType as getStdContentType } from "@std/media-types/content-type"
const WINDOWS_SEPARATOR = pathWin32.SEPARATOR;
/** Normalize a path to use forward slashes so that generated files
* are portable across operating systems (e.g. build on Windows,
* deploy on Linux). */
export function toPosix(p: string): string {
return p.replaceAll(WINDOWS_SEPARATOR, "/");
}
export interface MemoryFile {
hash: string | null;
contentType: string;
+2 -1
View File
@@ -1,6 +1,7 @@
import { type FsAdapter, fsAdapter } from "../fs.ts";
import type { WalkEntry } from "@std/fs/walk";
import { type FsRouteFileNoMod, toPosix } from "./dev_build_cache.ts";
import type { FsRouteFileNoMod } from "./dev_build_cache.ts";
import { toPosix } from "../utils.ts";
import * as path from "@std/path";
import { pathToPattern } from "../router.ts";
import { CommandType } from "../commands.ts";
+1 -2
View File
@@ -7,10 +7,9 @@ export {
type IslandModChunk,
type PendingStaticFile,
prepareStaticFile,
toPosix,
writeCompiledEntry,
} from "./dev/dev_build_cache.ts";
export { specToName } from "./dev/builder.ts";
export { pathToSpec, UniqueNamer } from "./utils.ts";
export { pathToSpec, toPosix, UniqueNamer } from "./utils.ts";
export { updateCheck } from "./dev/update_check.ts";
export { TEST_FILE_PATTERN, UPDATE_INTERVAL } from "./constants.ts";
+4 -29
View File
@@ -1,13 +1,11 @@
import { Context, type ServerIslandRegistry } from "./context.ts";
import { Context } from "./context.ts";
import type { FsAdapter } from "./fs.ts";
import type { BuildCache, StaticFile } from "./build_cache.ts";
import { type BuildCache, MockBuildCache } from "./build_cache.ts";
import type { ResolvedFreshConfig } from "./config.ts";
import type { WalkEntry } from "@std/fs/walk";
import { DEFAULT_CONN_INFO } from "./app.ts";
import type { Command } from "./commands.ts";
import { fsItemsToCommands, type FsRouteFile } from "./fs_routes.ts";
import * as path from "@std/path";
import { toPosix } from "./dev/dev_build_cache.ts";
import { toPosix } from "./utils.ts";
const STUB = {} as unknown as Deno.ServeHandlerInfo;
@@ -162,30 +160,7 @@ export async function withTmpDir(
};
}
export class MockBuildCache<State> implements BuildCache<State> {
#files: FsRouteFile<State>[];
root = "";
clientEntry = "";
islandRegistry: ServerIslandRegistry = new Map();
features = { errorOverlay: false };
constructor(files: FsRouteFile<State>[], mode: "development" | "production") {
this.features.errorOverlay = mode === "development";
this.#files = files;
}
getEntryAssets(): string[] {
return [];
}
getFsRoutes(): Command<State>[] {
return fsItemsToCommands(this.#files);
}
readFile(_pathname: string): Promise<StaticFile | null> {
return Promise.resolve(null);
}
}
export { MockBuildCache };
/**
* Wrapper around `Deno.test` for integration tests that disables sanitizers.
+7
View File
@@ -2,6 +2,13 @@ import * as path from "@std/path";
import type { Lazy, MaybeLazy } from "./types.ts";
import { pathToFileUrl, relativeUrl } from "./file_url.ts";
/** Normalize a path to use forward slashes so that generated files
* are portable across operating systems (e.g. build on Windows,
* deploy on Linux). */
export function toPosix(p: string): string {
return p.replaceAll("\\", "/");
}
export function assertInDir(
filePath: string,
dir: string,