Skip to content

Commit f773d0d

Browse files
feat(vite): add update checker (#3372)
1 parent 5781123 commit f773d0d

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

packages/fresh/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export const DAY = HOUR * 24;
1010
export const WEEK = DAY * 7;
1111

1212
export const ASSET_CACHE_BUST_KEY = "__frsh_c";
13+
14+
export const UPDATE_INTERVAL = DAY;

packages/fresh/src/dev/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { parseDirPath } from "../config.ts";
2525
import { pathToExportName, UniqueNamer } from "../utils.ts";
2626
import { checkDenoCompilerOptions } from "./check.ts";
2727
import { crawlFsItem } from "./fs_crawl.ts";
28-
import { DAY } from "../constants.ts";
28+
import { UPDATE_INTERVAL } from "../constants.ts";
2929

3030
export interface BuildOptions {
3131
/**
@@ -158,7 +158,7 @@ export class Builder<State = any> {
158158
options: ListenOptions = {},
159159
): Promise<void> {
160160
// Run update check in background
161-
updateCheck(DAY).catch(() => {});
161+
updateCheck(UPDATE_INTERVAL).catch(() => {});
162162

163163
this.config.mode = "development";
164164

packages/fresh/src/dev/update_check.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getFreshCacheDir(): string | null {
4040
return null;
4141
}
4242

43-
async function fetchLatestVersion() {
43+
async function fetchLatestVersion(): Promise<string> {
4444
const res = await fetch("https://dl.deno.land/fresh/release-latest.txt");
4545
if (res.ok) {
4646
return (await res.text()).trim().replace(/^v/, "");
@@ -49,7 +49,7 @@ async function fetchLatestVersion() {
4949
throw new Error(`Could not fetch latest version.`);
5050
}
5151

52-
function readCurrentVersion() {
52+
function readCurrentVersion(): string {
5353
return CURRENT_FRESH_VERSION;
5454
}
5555

packages/fresh/src/internals_dev.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ export {
1010
} from "./dev/dev_build_cache.ts";
1111
export { specToName } from "./dev/builder.ts";
1212
export { pathToSpec, UniqueNamer } from "./utils.ts";
13+
export { updateCheck } from "./dev/update_check.ts";
14+
export { UPDATE_INTERVAL } from "./constants.ts";

packages/plugin-vite/src/mod.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import { clientSnapshot } from "./plugins/client_snapshot.ts";
1414
import { serverSnapshot } from "./plugins/server_snapshot.ts";
1515
import { patches } from "./plugins/patches.ts";
1616
import process from "node:process";
17-
import { specToName, UniqueNamer } from "@fresh/core/internal-dev";
17+
import {
18+
specToName,
19+
UniqueNamer,
20+
UPDATE_INTERVAL,
21+
updateCheck,
22+
} from "@fresh/core/internal-dev";
1823
import { checkImports } from "./plugins/verify_imports.ts";
1924
import { isBuiltin } from "node:module";
2025

@@ -147,6 +152,9 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
147152
};
148153
},
149154
configResolved(vConfig) {
155+
// Run update check in background
156+
updateCheck(UPDATE_INTERVAL).catch(() => {});
157+
150158
fConfig.islandsDir = pathWithRoot(fConfig.islandsDir, vConfig.root);
151159
fConfig.routeDir = pathWithRoot(fConfig.routeDir, vConfig.root);
152160

0 commit comments

Comments
 (0)