vite-plugin-refresh-guard 0.1.2 → 0.1.4
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.
- package/CHANGELOG.md +14 -0
- package/README.en.md +23 -0
- package/README.md +23 -0
- package/dist/{checker-gSSR0d-T.d.ts → core/checker.d.ts} +2 -5
- package/dist/{types-DaLsj7ZU.d.ts → core/types.d.ts} +11 -7
- package/dist/index.d.ts +4 -6
- package/dist/react/UpdatePrompt.d.ts +3 -7
- package/dist/react/UpdatePrompt.js +23 -18
- package/dist/react/useVersionCheck.d.ts +4 -7
- package/dist/vue/UpdatePrompt.vue +32 -24
- package/dist/vue/useVersionCheck.d.ts +6 -10
- package/package.json +16 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v0.1.4 (2026-08-11)
|
|
4
|
+
|
|
5
|
+
修复自 v0.1.1(甚至更早)起就存在的发布产物残缺问题:`tsconfig.build.json`(构建脚本 `tsc -p tsconfig.build.json` 这一步依赖的配置文件)一直没有提交进 git,导致:
|
|
6
|
+
|
|
7
|
+
- **GitHub CI 一直是红的**(`npm run build` 在干净 checkout 下找不到这个配置文件而失败),只是发布本身走的是本地手动 `npm publish`,没人注意到。
|
|
8
|
+
- **本地 `npm run build` 因为工作目录里残留着这个未提交的文件而"看起来是好的"**,掩盖了问题。
|
|
9
|
+
- **发布到 npm 的产物里缺失 `dist/core/types.d.ts`、`dist/core/checker.d.ts`**:`dist/vue/UpdatePrompt.vue`、`dist/react/UpdatePrompt.d.ts` 里 `import type { UpdateMode } from '../core/types'` 这个相对路径解析不到目标文件,导致所有消费方用 `vue-tsc`/`tsc` 类型检查时报 `TS2307: Cannot find module '../core/types'`(在两个真实项目 hym-admin、mzmeso-manager 里复现并确认)。
|
|
10
|
+
|
|
11
|
+
这版把 `tsconfig.build.json` 提交进 git,`npm run compat`(typecheck + test + build)全部通过,构建产物里 `dist/core/*.d.ts` 正确生成。
|
|
12
|
+
|
|
13
|
+
## v0.1.3 (2026-08-09)
|
|
14
|
+
|
|
15
|
+
`UpdatePrompt` 默认样式全部改成 `var(--rg-*, 默认值)` 的写法,颜色/圆角都能被外部 CSS 变量覆盖,不用改包源码就能换成自己的品牌色(README 新增"样式定制"一节说明全部变量)。默认样式本身也精修了一版(更大的圆角、更细腻的阴影分层、按钮 hover/active 反馈、标题加了个 ✨),不设置任何变量也比之前顺眼。
|
|
16
|
+
|
|
3
17
|
## v0.1.2 (2026-08-09)
|
|
4
18
|
|
|
5
19
|
修 `UpdatePrompt` 两个实测踩到的问题(在一个真实项目里第一次接入后暴露的):
|
package/README.en.md
CHANGED
|
@@ -157,6 +157,29 @@ deciding "when do we reload" are different product decisions, and coupling them
|
|
|
157
157
|
of the projects this package was extracted from originally did) is how you end up with two
|
|
158
158
|
mechanisms fighting each other.
|
|
159
159
|
|
|
160
|
+
## Styling
|
|
161
|
+
|
|
162
|
+
`UpdatePrompt` ships with a generic blue-on-white look and doesn't assume your brand colors. Every color/radius reads a `--rg-*` CSS custom property first, falling back to a default — set these anywhere in your own global styles (`:root` or any ancestor) to make the modal match your product without touching the package source:
|
|
163
|
+
|
|
164
|
+
```css
|
|
165
|
+
:root {
|
|
166
|
+
--rg-accent: var(--brand); /* primary button color, default #2563eb */
|
|
167
|
+
--rg-accent-fg: #fff; /* primary button text color */
|
|
168
|
+
--rg-radius: 16px; /* modal/toast corner radius */
|
|
169
|
+
--rg-modal-bg: #fff; /* modal background (light) */
|
|
170
|
+
--rg-modal-fg: #111827; /* modal text (light) */
|
|
171
|
+
--rg-modal-bg-dark: #1f2937; /* modal background (dark, paired with :dark or OS dark mode) */
|
|
172
|
+
--rg-modal-fg-dark: #f3f4f6;
|
|
173
|
+
--rg-body-fg: #4b5563; /* body text color */
|
|
174
|
+
--rg-body-fg-dark: #d1d5db;
|
|
175
|
+
--rg-overlay-bg: rgba(15, 15, 20, 0.55); /* backdrop behind the modal */
|
|
176
|
+
--rg-toast-bg: #1f2937; /* toast-auto mode's notice bar */
|
|
177
|
+
--rg-toast-fg: #fff;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
You don't need to set all of them — override just `--rg-accent` for a quick brand match and leave the rest at their defaults.
|
|
182
|
+
|
|
160
183
|
## Why not just service workers?
|
|
161
184
|
|
|
162
185
|
`vite-plugin-pwa`'s `autoUpdate` mode is a perfectly good `silent` implementation if you're
|
package/README.md
CHANGED
|
@@ -146,6 +146,29 @@ import { latestVersion, latestContent } from 'virtual:refresh-guard-changelog'
|
|
|
146
146
|
|
|
147
147
|
从你的 `CHANGELOG.md` 里解析 `## vX.Y.Z (date)` 这种格式的标题(跟 Keep a Changelog 及大多数自动生成的更新日志一致),暴露最新一条的版本号和 markdown 正文。这个功能故意跟"什么时候刷新"的逻辑解耦——"展示更新了什么"和"什么时候该刷新"是两个不同的产品决策,本包最初就是从几个把这两件事强行绑死在一起的项目里抽出来的,绑死的下场就是两套机制互相打架。
|
|
148
148
|
|
|
149
|
+
## 样式定制
|
|
150
|
+
|
|
151
|
+
`UpdatePrompt` 默认是通用蓝白配色,不假设你的品牌色。所有颜色/圆角都先读一个 `--rg-*` CSS 变量,读不到才用默认值——在你自己项目的全局样式里(`:root` 或任意祖先节点)设置这些变量,就能让弹窗跟你的产品长一个样,不用改包的源码:
|
|
152
|
+
|
|
153
|
+
```css
|
|
154
|
+
:root {
|
|
155
|
+
--rg-accent: var(--brand); /* 主按钮颜色,默认 #2563eb */
|
|
156
|
+
--rg-accent-fg: #fff; /* 主按钮文字颜色 */
|
|
157
|
+
--rg-radius: 16px; /* 弹窗/toast 圆角 */
|
|
158
|
+
--rg-modal-bg: #fff; /* 弹窗背景(浅色) */
|
|
159
|
+
--rg-modal-fg: #111827; /* 弹窗文字(浅色) */
|
|
160
|
+
--rg-modal-bg-dark: #1f2937; /* 弹窗背景(深色,配合 :dark 或系统深色模式) */
|
|
161
|
+
--rg-modal-fg-dark: #f3f4f6;
|
|
162
|
+
--rg-body-fg: #4b5563; /* 正文文字颜色 */
|
|
163
|
+
--rg-body-fg-dark: #d1d5db;
|
|
164
|
+
--rg-overlay-bg: rgba(15, 15, 20, 0.55); /* 弹窗背后的遮罩 */
|
|
165
|
+
--rg-toast-bg: #1f2937; /* toast-auto 模式的提示条 */
|
|
166
|
+
--rg-toast-fg: #fff;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
不需要全套都设,只想换主按钮颜色就只设 `--rg-accent` 即可,其余保持默认。
|
|
171
|
+
|
|
149
172
|
## 为什么不干脆只用 service worker
|
|
150
173
|
|
|
151
174
|
如果你已经在跑 service worker,`vite-plugin-pwa` 的 `autoUpdate` 模式本身就是一个很好的 `silent` 实现——本包不是要替代它。本包补的是:一套统一的方式,能拿到 `toast-auto` 或 `modal-blocking` 的体验(裸 service worker 想要这个得自己手写这整套管线);一个不需要 service worker 的、纯靠轮询 `version.json` 的兜底方案;以及独立的更新日志展示层。哪块需要用哪块,互相不绑定。
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { UpdateEvent, UpdateListener, VersionCheckerOptions, VersionInfo } from './types';
|
|
3
2
|
/**
|
|
4
3
|
* Framework-agnostic engine: polls (or is told about) a new version, decides whether to refresh
|
|
5
4
|
* based on `mode`, and guards against reload loops / stale-chunk white-screens. Vue/React
|
|
6
5
|
* adapters are thin wrappers around this — use it directly if you're on something else.
|
|
7
6
|
*/
|
|
8
|
-
declare class UpdateChecker {
|
|
7
|
+
export declare class UpdateChecker {
|
|
9
8
|
private opts;
|
|
10
9
|
private currentVersion;
|
|
11
10
|
private timer;
|
|
@@ -34,5 +33,3 @@ declare class UpdateChecker {
|
|
|
34
33
|
on(event: UpdateEvent, listener: UpdateListener): () => void;
|
|
35
34
|
private emit;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
export { UpdateChecker as U };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
type UpdateMode = 'silent' | 'toast-auto' | 'modal-blocking';
|
|
2
|
-
interface VersionInfo {
|
|
1
|
+
export type UpdateMode = 'silent' | 'toast-auto' | 'modal-blocking';
|
|
2
|
+
export interface VersionInfo {
|
|
3
3
|
version: string;
|
|
4
4
|
buildId?: string;
|
|
5
5
|
commit?: string;
|
|
6
6
|
time?: string;
|
|
7
7
|
}
|
|
8
|
-
interface
|
|
8
|
+
export interface ChangelogInfo {
|
|
9
|
+
/** Latest version heading found in the changelog, e.g. "v1.5.0" */
|
|
10
|
+
version: string;
|
|
11
|
+
/** Rendered body for that version's section (markdown, unprocessed) */
|
|
12
|
+
content: string;
|
|
13
|
+
}
|
|
14
|
+
export interface VersionCheckerOptions {
|
|
9
15
|
/** Where to fetch version info from. Default: '/version.json' (see the Vite plugin, which emits this file at build time). */
|
|
10
16
|
versionUrl?: string;
|
|
11
17
|
/** Poll interval in ms. Default: 5 minutes. Set to 0 to disable polling (e.g. if you only drive checks from a service-worker hook). */
|
|
@@ -42,7 +48,5 @@ interface VersionCheckerOptions {
|
|
|
42
48
|
/** Called immediately before the actual page refresh happens (any mode). Good place to flush analytics, etc. */
|
|
43
49
|
onBeforeRefresh?: () => void;
|
|
44
50
|
}
|
|
45
|
-
type UpdateEvent = 'update-available' | 'refreshing';
|
|
46
|
-
type UpdateListener = (info: VersionInfo | null) => void;
|
|
47
|
-
|
|
48
|
-
export type { UpdateMode as U, VersionCheckerOptions as V, VersionInfo as a, UpdateEvent as b, UpdateListener as c };
|
|
51
|
+
export type UpdateEvent = 'update-available' | 'refreshing';
|
|
52
|
+
export type UpdateListener = (info: VersionInfo | null) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
interface RefreshGuardPluginOptions {
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export interface RefreshGuardPluginOptions {
|
|
4
3
|
/** Version string to bake into version.json and the `__REFRESH_GUARD_VERSION__` define. Default: read from the project's package.json. */
|
|
5
4
|
version?: string;
|
|
6
5
|
/** Include the short git commit hash in version.json. Default: true — silently omitted outside a git repo (e.g. a tarball deploy), never throws. */
|
|
@@ -22,6 +21,5 @@ interface RefreshGuardPluginOptions {
|
|
|
22
21
|
* since HMR already covers that case; point a static-file server or `vite preview` at the
|
|
23
22
|
* build output to see it end to end.
|
|
24
23
|
*/
|
|
25
|
-
declare function refreshGuard(options?: RefreshGuardPluginOptions): Plugin;
|
|
26
|
-
|
|
27
|
-
export { type RefreshGuardPluginOptions, refreshGuard as default, refreshGuard };
|
|
24
|
+
export declare function refreshGuard(options?: RefreshGuardPluginOptions): Plugin;
|
|
25
|
+
export default refreshGuard;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface UpdatePromptProps {
|
|
1
|
+
import type { UpdateMode } from '../core/types';
|
|
2
|
+
export interface UpdatePromptProps {
|
|
5
3
|
visible: boolean;
|
|
6
4
|
mode?: UpdateMode;
|
|
7
5
|
/** Optional: e.g. `latestVersion` from `virtual:refresh-guard-changelog`. */
|
|
@@ -17,6 +15,4 @@ interface UpdatePromptProps {
|
|
|
17
15
|
dark?: boolean;
|
|
18
16
|
onRefresh: () => void;
|
|
19
17
|
}
|
|
20
|
-
declare function UpdatePrompt({ visible, mode, version, changelogHtml, dark, onRefresh }: UpdatePromptProps): react.ReactPortal | null;
|
|
21
|
-
|
|
22
|
-
export { UpdatePrompt, type UpdatePromptProps };
|
|
18
|
+
export declare function UpdatePrompt({ visible, mode, version, changelogHtml, dark, onRefresh }: UpdatePromptProps): import("react").ReactPortal | null;
|
|
@@ -21,10 +21,10 @@ function UpdatePrompt({ visible, mode = "toast-auto", version = null, changelogH
|
|
|
21
21
|
return createPortal(
|
|
22
22
|
/* @__PURE__ */ jsx("div", { style: styles.overlay, role: "alertdialog", "aria-modal": "true", children: /* @__PURE__ */ jsxs("div", { style: modalStyle, children: [
|
|
23
23
|
/* @__PURE__ */ jsxs("h3", { style: styles.title, children: [
|
|
24
|
-
"\u6709\u65B0\u7248\u672C\u53EF\u7528",
|
|
24
|
+
"\u2728 \u6709\u65B0\u7248\u672C\u53EF\u7528",
|
|
25
25
|
version ? `\uFF1A${version}` : ""
|
|
26
26
|
] }),
|
|
27
|
-
changelogHtml ? /* @__PURE__ */ jsx("div", { style: bodyStyle, dangerouslySetInnerHTML: { __html: changelogHtml } }) : /* @__PURE__ */ jsx("p", { style: { ...bodyStyle, color: dark ? "#9ca3af" : "#6b7280" }, children: "\u5237\u65B0\u9875\u9762\u5373\u53EF\u4F7F\u7528\u6700\u65B0\u7248\u672C\u3002" }),
|
|
27
|
+
changelogHtml ? /* @__PURE__ */ jsx("div", { style: bodyStyle, dangerouslySetInnerHTML: { __html: changelogHtml } }) : /* @__PURE__ */ jsx("p", { style: { ...bodyStyle, color: dark ? "var(--rg-body-fg-dark, #9ca3af)" : "var(--rg-body-fg, #6b7280)" }, children: "\u5237\u65B0\u9875\u9762\u5373\u53EF\u4F7F\u7528\u6700\u65B0\u7248\u672C\u3002" }),
|
|
28
28
|
/* @__PURE__ */ jsx("button", { type: "button", style: styles.primaryBtn, onClick: onRefresh, children: "\u7ACB\u5373\u66F4\u65B0" })
|
|
29
29
|
] }) }),
|
|
30
30
|
document.body
|
|
@@ -40,9 +40,9 @@ var styles = {
|
|
|
40
40
|
alignItems: "center",
|
|
41
41
|
gap: 12,
|
|
42
42
|
padding: "10px 16px",
|
|
43
|
-
borderRadius:
|
|
44
|
-
background: "#1f2937",
|
|
45
|
-
color: "#fff",
|
|
43
|
+
borderRadius: "var(--rg-radius, 10px)",
|
|
44
|
+
background: "var(--rg-toast-bg, #1f2937)",
|
|
45
|
+
color: "var(--rg-toast-fg, #fff)",
|
|
46
46
|
fontSize: 13,
|
|
47
47
|
boxShadow: "0 4px 16px rgba(0,0,0,0.2)"
|
|
48
48
|
},
|
|
@@ -52,7 +52,7 @@ var styles = {
|
|
|
52
52
|
borderRadius: 6,
|
|
53
53
|
border: "1px solid rgba(255,255,255,0.3)",
|
|
54
54
|
background: "transparent",
|
|
55
|
-
color: "
|
|
55
|
+
color: "inherit",
|
|
56
56
|
fontSize: 12,
|
|
57
57
|
cursor: "pointer"
|
|
58
58
|
},
|
|
@@ -63,26 +63,31 @@ var styles = {
|
|
|
63
63
|
display: "flex",
|
|
64
64
|
alignItems: "center",
|
|
65
65
|
justifyContent: "center",
|
|
66
|
-
background: "rgba(
|
|
66
|
+
background: "var(--rg-overlay-bg, rgba(15,15,20,0.55))"
|
|
67
67
|
},
|
|
68
68
|
modal: {
|
|
69
69
|
width: "90vw",
|
|
70
70
|
maxWidth: 420,
|
|
71
|
-
padding:
|
|
72
|
-
borderRadius:
|
|
73
|
-
background: "#fff",
|
|
74
|
-
color: "#111827",
|
|
75
|
-
boxShadow: "0
|
|
71
|
+
padding: 28,
|
|
72
|
+
borderRadius: "var(--rg-radius, 16px)",
|
|
73
|
+
background: "var(--rg-modal-bg, #fff)",
|
|
74
|
+
color: "var(--rg-modal-fg, #111827)",
|
|
75
|
+
boxShadow: "0 20px 50px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.08)"
|
|
76
76
|
},
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
modalDark: {
|
|
78
|
+
background: "var(--rg-modal-bg-dark, #1f2937)",
|
|
79
|
+
color: "var(--rg-modal-fg-dark, #f3f4f6)"
|
|
80
|
+
},
|
|
81
|
+
title: { margin: "0 0 14px", fontSize: 17, fontWeight: 700, letterSpacing: "-0.01em" },
|
|
82
|
+
body: { margin: "0 0 22px", fontSize: 13.5, lineHeight: 1.7, color: "var(--rg-body-fg, #4b5563)", maxHeight: "40vh", overflowY: "auto" },
|
|
83
|
+
bodyDark: { color: "var(--rg-body-fg-dark, #d1d5db)" },
|
|
79
84
|
primaryBtn: {
|
|
80
85
|
width: "100%",
|
|
81
|
-
padding:
|
|
86
|
+
padding: 11,
|
|
82
87
|
border: "none",
|
|
83
|
-
borderRadius:
|
|
84
|
-
background: "#2563eb",
|
|
85
|
-
color: "#fff",
|
|
88
|
+
borderRadius: "var(--rg-btn-radius, 10px)",
|
|
89
|
+
background: "var(--rg-accent, #2563eb)",
|
|
90
|
+
color: "var(--rg-accent-fg, #fff)",
|
|
86
91
|
fontSize: 14,
|
|
87
92
|
fontWeight: 600,
|
|
88
93
|
cursor: "pointer"
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { UpdateChecker } from '../core/checker';
|
|
2
|
+
import type { VersionCheckerOptions, VersionInfo } from '../core/types';
|
|
4
3
|
/**
|
|
5
4
|
* React hook wrapping the framework-agnostic UpdateChecker. Mounts/unmounts the checker with
|
|
6
5
|
* the component's lifecycle automatically.
|
|
7
6
|
*
|
|
8
7
|
* @param currentVersion Usually `__REFRESH_GUARD_VERSION__` (injected by the Vite plugin).
|
|
9
8
|
*/
|
|
10
|
-
declare function useVersionCheck(currentVersion: string, options?: VersionCheckerOptions): {
|
|
9
|
+
export declare function useVersionCheck(currentVersion: string, options?: VersionCheckerOptions): {
|
|
11
10
|
hasUpdate: boolean;
|
|
12
11
|
latestInfo: VersionInfo | null;
|
|
13
|
-
mode: UpdateMode;
|
|
12
|
+
mode: import("../core/types").UpdateMode;
|
|
14
13
|
applyUpdate: () => void;
|
|
15
14
|
checkNow: () => Promise<boolean>;
|
|
16
15
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
17
16
|
notifyExternalUpdate: (info?: VersionInfo) => void;
|
|
18
17
|
checker: UpdateChecker;
|
|
19
18
|
};
|
|
20
|
-
|
|
21
|
-
export { useVersionCheck };
|
|
@@ -39,7 +39,7 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
39
39
|
|
|
40
40
|
<div v-if="shown && mode === 'modal-blocking'" class="rg-overlay" role="alertdialog" aria-modal="true">
|
|
41
41
|
<div class="rg-modal" :class="{ 'rg-dark': dark === true, 'rg-light': dark === false }">
|
|
42
|
-
<h3 class="rg-title"
|
|
42
|
+
<h3 class="rg-title">✨ 有新版本可用{{ version ? `:${version}` : '' }}</h3>
|
|
43
43
|
<div v-if="changelogHtml" class="rg-body" v-html="changelogHtml" />
|
|
44
44
|
<p v-else class="rg-body rg-body-empty">刷新页面即可使用最新版本。</p>
|
|
45
45
|
<button type="button" class="rg-primary-btn" @click="emit('refresh')">立即更新</button>
|
|
@@ -49,6 +49,11 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
49
49
|
</template>
|
|
50
50
|
|
|
51
51
|
<style scoped>
|
|
52
|
+
/*
|
|
53
|
+
* Every color/radius here reads from a --rg-* custom property first, falling back to a
|
|
54
|
+
* reasonable default — set these on :root (or any ancestor) in your own app to re-skin the
|
|
55
|
+
* component to your brand instead of living with generic blue-on-white. See README "Styling".
|
|
56
|
+
*/
|
|
52
57
|
.rg-toast {
|
|
53
58
|
position: fixed;
|
|
54
59
|
right: 16px;
|
|
@@ -58,9 +63,9 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
58
63
|
align-items: center;
|
|
59
64
|
gap: 12px;
|
|
60
65
|
padding: 10px 16px;
|
|
61
|
-
border-radius:
|
|
62
|
-
background: #1f2937;
|
|
63
|
-
color: #fff;
|
|
66
|
+
border-radius: var(--rg-radius, 10px);
|
|
67
|
+
background: var(--rg-toast-bg, #1f2937);
|
|
68
|
+
color: var(--rg-toast-fg, #fff);
|
|
64
69
|
font-size: 13px;
|
|
65
70
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
66
71
|
}
|
|
@@ -70,11 +75,12 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
70
75
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
71
76
|
border-radius: 6px;
|
|
72
77
|
background: transparent;
|
|
73
|
-
color:
|
|
78
|
+
color: inherit;
|
|
74
79
|
font-size: 12px;
|
|
75
80
|
cursor: pointer;
|
|
81
|
+
transition: background 0.15s ease;
|
|
76
82
|
}
|
|
77
|
-
.rg-toast-btn:hover { background: rgba(255, 255, 255, 0.
|
|
83
|
+
.rg-toast-btn:hover { background: rgba(255, 255, 255, 0.12); }
|
|
78
84
|
|
|
79
85
|
.rg-overlay {
|
|
80
86
|
position: fixed;
|
|
@@ -83,37 +89,39 @@ const shown = computed(() => props.visible && props.mode !== 'silent')
|
|
|
83
89
|
display: flex;
|
|
84
90
|
align-items: center;
|
|
85
91
|
justify-content: center;
|
|
86
|
-
background: rgba(
|
|
92
|
+
background: var(--rg-overlay-bg, rgba(15, 15, 20, 0.55));
|
|
87
93
|
}
|
|
88
94
|
.rg-modal {
|
|
89
95
|
width: 90vw;
|
|
90
96
|
max-width: 420px;
|
|
91
|
-
padding:
|
|
92
|
-
border-radius:
|
|
93
|
-
background: #fff;
|
|
94
|
-
color: #111827;
|
|
95
|
-
box-shadow: 0
|
|
97
|
+
padding: 28px;
|
|
98
|
+
border-radius: var(--rg-radius, 16px);
|
|
99
|
+
background: var(--rg-modal-bg, #fff);
|
|
100
|
+
color: var(--rg-modal-fg, #111827);
|
|
101
|
+
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
96
102
|
}
|
|
97
|
-
.rg-title { margin: 0 0
|
|
98
|
-
.rg-body { margin: 0 0
|
|
99
|
-
.rg-body-empty { color: #6b7280; }
|
|
103
|
+
.rg-title { margin: 0 0 14px; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
|
|
104
|
+
.rg-body { margin: 0 0 22px; font-size: 13.5px; line-height: 1.7; color: var(--rg-body-fg, #4b5563); max-height: 40vh; overflow-y: auto; }
|
|
105
|
+
.rg-body-empty { color: var(--rg-body-fg, #6b7280); }
|
|
100
106
|
.rg-primary-btn {
|
|
101
107
|
width: 100%;
|
|
102
|
-
padding:
|
|
108
|
+
padding: 11px;
|
|
103
109
|
border: none;
|
|
104
|
-
border-radius:
|
|
105
|
-
background: #2563eb;
|
|
106
|
-
color: #fff;
|
|
110
|
+
border-radius: var(--rg-btn-radius, 10px);
|
|
111
|
+
background: var(--rg-accent, #2563eb);
|
|
112
|
+
color: var(--rg-accent-fg, #fff);
|
|
107
113
|
font-size: 14px;
|
|
108
114
|
font-weight: 600;
|
|
109
115
|
cursor: pointer;
|
|
116
|
+
transition: filter 0.15s ease, transform 0.05s ease;
|
|
110
117
|
}
|
|
111
|
-
.rg-primary-btn:hover {
|
|
118
|
+
.rg-primary-btn:hover { filter: brightness(0.92); }
|
|
119
|
+
.rg-primary-btn:active { transform: scale(0.99); }
|
|
112
120
|
|
|
113
|
-
.rg-modal.rg-dark { background: #1f2937; color: #f3f4f6; }
|
|
114
|
-
.rg-modal.rg-dark .rg-body { color: #d1d5db; }
|
|
121
|
+
.rg-modal.rg-dark { background: var(--rg-modal-bg-dark, #1f2937); color: var(--rg-modal-fg-dark, #f3f4f6); }
|
|
122
|
+
.rg-modal.rg-dark .rg-body { color: var(--rg-body-fg-dark, #d1d5db); }
|
|
115
123
|
@media (prefers-color-scheme: dark) {
|
|
116
|
-
.rg-modal:not(.rg-light) { background: #1f2937; color: #f3f4f6; }
|
|
117
|
-
.rg-modal:not(.rg-light) .rg-body { color: #d1d5db; }
|
|
124
|
+
.rg-modal:not(.rg-light) { background: var(--rg-modal-bg-dark, #1f2937); color: var(--rg-modal-fg-dark, #f3f4f6); }
|
|
125
|
+
.rg-modal:not(.rg-light) .rg-body { color: var(--rg-body-fg-dark, #d1d5db); }
|
|
118
126
|
}
|
|
119
127
|
</style>
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { U as UpdateChecker } from '../checker-gSSR0d-T.js';
|
|
4
|
-
|
|
1
|
+
import { UpdateChecker } from '../core/checker';
|
|
2
|
+
import type { VersionCheckerOptions, VersionInfo } from '../core/types';
|
|
5
3
|
/**
|
|
6
4
|
* Vue composable wrapping the framework-agnostic UpdateChecker. Mounts/unmounts the checker
|
|
7
5
|
* with the component's lifecycle automatically.
|
|
8
6
|
*
|
|
9
7
|
* @param currentVersion Usually `__REFRESH_GUARD_VERSION__` (injected by the Vite plugin).
|
|
10
8
|
*/
|
|
11
|
-
declare function useVersionCheck(currentVersion: string, options?: VersionCheckerOptions): {
|
|
12
|
-
hasUpdate: vue.Ref<boolean, boolean>;
|
|
13
|
-
latestInfo: vue.ShallowRef<VersionInfo | null, VersionInfo | null>;
|
|
14
|
-
mode: UpdateMode;
|
|
9
|
+
export declare function useVersionCheck(currentVersion: string, options?: VersionCheckerOptions): {
|
|
10
|
+
hasUpdate: import("vue").Ref<boolean, boolean>;
|
|
11
|
+
latestInfo: import("vue").ShallowRef<VersionInfo | null, VersionInfo | null>;
|
|
12
|
+
mode: import("../core/types").UpdateMode;
|
|
15
13
|
applyUpdate: () => void;
|
|
16
14
|
checkNow: () => Promise<boolean>;
|
|
17
15
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
18
16
|
notifyExternalUpdate: (info?: VersionInfo) => void;
|
|
19
17
|
checker: UpdateChecker;
|
|
20
18
|
};
|
|
21
|
-
|
|
22
|
-
export { useVersionCheck };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-refresh-guard",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Vite 应用的可配置版本更新检测+刷新方案:静默自动刷新 / 提示后自动刷新 / 弹窗阻断,按产品需要选档位,核心逻辑框架无关,附 Vue/React 适配层。Configurable new-version detection + refresh for Vite apps — silent / toast-auto / modal-blocking, framework-agnostic core with Vue and React adapters.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"CHANGELOG.md"
|
|
50
50
|
],
|
|
51
51
|
"scripts": {
|
|
52
|
-
"build": "tsup src/index.ts src/vue/useVersionCheck.ts src/react/useVersionCheck.ts src/react/UpdatePrompt.tsx --format esm --
|
|
52
|
+
"build": "tsup src/index.ts src/vue/useVersionCheck.ts src/react/useVersionCheck.ts src/react/UpdatePrompt.tsx --format esm --clean && tsc -p tsconfig.build.json && node scripts/copy-assets.mjs",
|
|
53
53
|
"typecheck": "tsc --noEmit",
|
|
54
54
|
"test": "vitest run",
|
|
55
55
|
"compat": "npm run typecheck && npm test && npm run build",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"react": ">=18",
|
|
60
60
|
"react-dom": ">=18",
|
|
61
|
-
"vite": ">=4 <
|
|
61
|
+
"vite": ">=4 <10",
|
|
62
62
|
"vue": ">=3"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
@@ -73,16 +73,19 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"@types/react": "^
|
|
78
|
-
"@types/react-dom": "^
|
|
76
|
+
"@types/node": "^24.10.11",
|
|
77
|
+
"@types/react": "^19.2.18",
|
|
78
|
+
"@types/react-dom": "^19.2.4",
|
|
79
79
|
"jsdom": "^30.0.1",
|
|
80
|
-
"react": "^
|
|
81
|
-
"react-dom": "^
|
|
82
|
-
"tsup": "^8.
|
|
83
|
-
"typescript": "^
|
|
84
|
-
"vite": "^
|
|
85
|
-
"vitest": "^
|
|
86
|
-
"vue": "^3.
|
|
80
|
+
"react": "^19.2.8",
|
|
81
|
+
"react-dom": "^19.2.8",
|
|
82
|
+
"tsup": "^8.5.1",
|
|
83
|
+
"typescript": "^7.0.2",
|
|
84
|
+
"vite": "^8.2.1",
|
|
85
|
+
"vitest": "^4.1.10",
|
|
86
|
+
"vue": "^3.5.41"
|
|
87
|
+
},
|
|
88
|
+
"engines": {
|
|
89
|
+
"node": ">=20.19"
|
|
87
90
|
}
|
|
88
91
|
}
|