feat(vite): add update checker (#3372)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<State = any> {
|
||||
options: ListenOptions = {},
|
||||
): Promise<void> {
|
||||
// Run update check in background
|
||||
updateCheck(DAY).catch(() => {});
|
||||
updateCheck(UPDATE_INTERVAL).catch(() => {});
|
||||
|
||||
this.config.mode = "development";
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ function getFreshCacheDir(): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
async function fetchLatestVersion() {
|
||||
async function fetchLatestVersion(): Promise<string> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user