diff --git a/packages/fresh/src/constants.ts b/packages/fresh/src/constants.ts index faacb8b4..e8b4991a 100644 --- a/packages/fresh/src/constants.ts +++ b/packages/fresh/src/constants.ts @@ -10,3 +10,5 @@ export const DAY = HOUR * 24; export const WEEK = DAY * 7; export const ASSET_CACHE_BUST_KEY = "__frsh_c"; + +export const UPDATE_INTERVAL = DAY; diff --git a/packages/fresh/src/dev/builder.ts b/packages/fresh/src/dev/builder.ts index 1495e8a6..d833176d 100644 --- a/packages/fresh/src/dev/builder.ts +++ b/packages/fresh/src/dev/builder.ts @@ -25,7 +25,7 @@ import { parseDirPath } from "../config.ts"; import { pathToExportName, UniqueNamer } from "../utils.ts"; import { checkDenoCompilerOptions } from "./check.ts"; import { crawlFsItem } from "./fs_crawl.ts"; -import { DAY } from "../constants.ts"; +import { UPDATE_INTERVAL } from "../constants.ts"; export interface BuildOptions { /** @@ -158,7 +158,7 @@ export class Builder { options: ListenOptions = {}, ): Promise { // Run update check in background - updateCheck(DAY).catch(() => {}); + updateCheck(UPDATE_INTERVAL).catch(() => {}); this.config.mode = "development"; diff --git a/packages/fresh/src/dev/update_check.ts b/packages/fresh/src/dev/update_check.ts index 7fc689db..7e324e30 100644 --- a/packages/fresh/src/dev/update_check.ts +++ b/packages/fresh/src/dev/update_check.ts @@ -40,7 +40,7 @@ function getFreshCacheDir(): string | null { return null; } -async function fetchLatestVersion() { +async function fetchLatestVersion(): Promise { const res = await fetch("https://dl.deno.land/fresh/release-latest.txt"); if (res.ok) { return (await res.text()).trim().replace(/^v/, ""); @@ -49,7 +49,7 @@ async function fetchLatestVersion() { throw new Error(`Could not fetch latest version.`); } -function readCurrentVersion() { +function readCurrentVersion(): string { return CURRENT_FRESH_VERSION; } diff --git a/packages/fresh/src/internals_dev.ts b/packages/fresh/src/internals_dev.ts index 930f1860..691a93af 100644 --- a/packages/fresh/src/internals_dev.ts +++ b/packages/fresh/src/internals_dev.ts @@ -10,3 +10,5 @@ export { } from "./dev/dev_build_cache.ts"; export { specToName } from "./dev/builder.ts"; export { pathToSpec, UniqueNamer } from "./utils.ts"; +export { updateCheck } from "./dev/update_check.ts"; +export { UPDATE_INTERVAL } from "./constants.ts"; diff --git a/packages/plugin-vite/src/mod.ts b/packages/plugin-vite/src/mod.ts index 5fd19188..89fd189e 100644 --- a/packages/plugin-vite/src/mod.ts +++ b/packages/plugin-vite/src/mod.ts @@ -14,7 +14,12 @@ import { clientSnapshot } from "./plugins/client_snapshot.ts"; import { serverSnapshot } from "./plugins/server_snapshot.ts"; import { patches } from "./plugins/patches.ts"; import process from "node:process"; -import { specToName, UniqueNamer } from "@fresh/core/internal-dev"; +import { + specToName, + UniqueNamer, + UPDATE_INTERVAL, + updateCheck, +} from "@fresh/core/internal-dev"; import { checkImports } from "./plugins/verify_imports.ts"; import { isBuiltin } from "node:module"; @@ -147,6 +152,9 @@ export function fresh(config?: FreshViteConfig): Plugin[] { }; }, configResolved(vConfig) { + // Run update check in background + updateCheck(UPDATE_INTERVAL).catch(() => {}); + fConfig.islandsDir = pathWithRoot(fConfig.islandsDir, vConfig.root); fConfig.routeDir = pathWithRoot(fConfig.routeDir, vConfig.root);