vite-plugin-refresh-guard 0.3.1 → 0.4.0
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 +19 -0
- package/README.en.md +5 -0
- package/README.md +5 -0
- package/SKILL.md +3 -1
- package/dist/{chunk-CGDGH2ML.js → chunk-5KLAZESA.js} +32 -7
- package/dist/client.d.ts +8 -0
- package/dist/core/checker.d.ts +20 -3
- package/dist/core/types.d.ts +10 -0
- package/dist/index.d.ts +0 -9
- package/dist/index.js +23 -9
- package/dist/react/useVersionCheck.d.ts +5 -1
- package/dist/react/useVersionCheck.js +4 -2
- package/dist/vue/useVersionCheck.d.ts +5 -1
- package/dist/vue/useVersionCheck.js +4 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v0.4.0 (2026-11-18)
|
|
4
|
+
|
|
5
|
+
> **一句话摘要**:检测基准从 `version` 换成 `buildId`(部署身份)——忘 bump 版本号的连续发版、回滚部署,从此都看得见;同时修掉 CDN 缓存造成的假阴性,以及弹窗「立即刷新」在冷却期内的死按钮。
|
|
6
|
+
|
|
7
|
+
### ✨ 行为变更 (Behavior)
|
|
8
|
+
- **`buildId` 成为首选比对基准**:构建期取 git short SHA(无 git 环境回落时间戳),由插件 `define` 同时注入客户端(`__REFRESH_GUARD_BUILD_ID__`)与 `version.json`。运行时两侧都有 buildId 就比 buildId,否则回落比 `version`(老部署 / 第三方 manifest 不受影响)。
|
|
9
|
+
- 修的场景:CI 里 `package.json` 版本号连续几次发版都没动 → 旧行为完全检测不到更新,且表现为静默失效。
|
|
10
|
+
- 回滚部署同样能感知:version 比对在这个方向上最容易判错(旧 bundle 看到「更老的 version」反而当成新版本)。
|
|
11
|
+
- buildId 可复现:同一 commit 构建多次得到同一个值,线上排查能直接对回提交。
|
|
12
|
+
- `UpdateChecker` 新增 `buildId` 选项;Vue/React 适配层透传,默认自动读注入值,**原调用代码无需改动**。
|
|
13
|
+
|
|
14
|
+
### 🐛 缺陷修复 (Bug Fixes)
|
|
15
|
+
- **`version.json` 请求带 cache-buster**:`cache: 'no-store'` 只绕过浏览器缓存,CDN / 反向代理 / Service Worker 仍可能一直回旧副本,导致永远检测不到更新。现在请求附带 `?t=<ts>`(`versionUrl` 已有查询串时用 `&` 拼接)。
|
|
16
|
+
- **`modal-blocking` 的「立即刷新」在冷却期内是死按钮**:`applyUpdate()` 无条件受 `refreshCooldown` 约束,用户点击被静默吞掉。新增 `applyUpdate({ force: true })` 与 `refreshNow()`(两个适配层都暴露)。
|
|
17
|
+
- **冷却写入时序自锁**:`sessionStorage` 时间戳原先写在 `onBeforeRefresh` 之前,回调抛错会留下「已冷却但没刷新、且冷却期内刷不了」的状态;改为在真正 `reload()` 前最后一步写入。
|
|
18
|
+
|
|
19
|
+
### ⚠️ 破坏性变更与迁移 (Breaking Changes & Migration)
|
|
20
|
+
- 无破坏性变更。对正常 bump 版本号的项目,行为等价;只有依赖「version 不变就不刷新」这一旧语义的用法,需要显式传 `buildId: ''` 退回按 version 比对。
|
|
21
|
+
|
|
3
22
|
## v0.3.1 (2026-10-18)
|
|
4
23
|
|
|
5
24
|
- **组件依赖纯净化 (`UpdateCard.vue`)**:
|
package/README.en.md
CHANGED
|
@@ -122,6 +122,7 @@ running a service worker and want its update event to drive the same toast/modal
|
|
|
122
122
|
```ts
|
|
123
123
|
interface VersionCheckerOptions {
|
|
124
124
|
versionUrl?: string // default '/version.json'
|
|
125
|
+
buildId?: string // this build's deployment id; defaults to the plugin-injected __REFRESH_GUARD_BUILD_ID__. See below
|
|
125
126
|
interval?: number // default 5 minutes; 0 disables polling
|
|
126
127
|
checkOnVisible?: boolean // re-check on tab focus, default true
|
|
127
128
|
mode?: 'silent' | 'toast-auto' | 'modal-blocking' // default 'toast-auto'
|
|
@@ -134,6 +135,10 @@ interface VersionCheckerOptions {
|
|
|
134
135
|
}
|
|
135
136
|
```
|
|
136
137
|
|
|
138
|
+
**The comparison key is `buildId`, not `version`.** They answer different questions: `version` says "which release is this", `buildId` says "is the hashed JS/CSS I'm running still the set being served". Two deploys that never bumped package.json — and rollbacks — are visible only to the build id. A version compare misses them silently, and silent is exactly the failure nobody reports.
|
|
139
|
+
|
|
140
|
+
`buildId` defaults to the git short SHA at build time (timestamp fallback without git) and is injected by the plugin's `define` into both the bundle and `version.json`, so you never pass it by hand. Pass it explicitly only when constructing `UpdateChecker` yourself or aligning ids across builds; an empty string opts back into version comparison.
|
|
141
|
+
|
|
137
142
|
Plugin options (`refreshGuard({ ... })`):
|
|
138
143
|
|
|
139
144
|
```ts
|
package/README.md
CHANGED
|
@@ -136,6 +136,7 @@ function App() {
|
|
|
136
136
|
```ts
|
|
137
137
|
interface VersionCheckerOptions {
|
|
138
138
|
versionUrl?: string // 默认 '/version.json'
|
|
139
|
+
buildId?: string // 本次构建的部署标识;默认取插件注入的 __REFRESH_GUARD_BUILD_ID__。比 version 更准,见下
|
|
139
140
|
interval?: number // 默认 5 分钟;设 0 关闭轮询
|
|
140
141
|
checkOnVisible?: boolean // 标签页重新可见时也查一次,默认 true
|
|
141
142
|
mode?: 'silent' | 'toast-auto' | 'modal-blocking' // 默认 'toast-auto'
|
|
@@ -148,6 +149,10 @@ interface VersionCheckerOptions {
|
|
|
148
149
|
}
|
|
149
150
|
```
|
|
150
151
|
|
|
152
|
+
**检测基准是 `buildId`,不是 `version`。** 这两个问题不一样:`version` 回答"这是第几个发布",`buildId` 回答"我手上这堆带 hash 的 JS/CSS,服务器上还是不是这一份"。忘 `bump` package.json 的连续发版、以及回滚部署,都只有 buildId 看得见——version 比对在这两种情况下是静默漏检,而静默正是最难被发现的那种 bug。
|
|
153
|
+
|
|
154
|
+
`buildId` 默认取构建时的 git short SHA(无 git 环境回落时间戳),由插件的 `define` 同时注入产物与客户端,所以你不用手工传。只有手动构造 `UpdateChecker`、或想跨版本对齐时才需要显式指定;传空串则退回按 `version` 比对。
|
|
155
|
+
|
|
151
156
|
插件配置(`refreshGuard({ ... })`):
|
|
152
157
|
|
|
153
158
|
```ts
|
package/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: refresh-guard
|
|
3
3
|
description: "vite-plugin-refresh-guard 的 agent 接入手册。给 Vite 前端项目加'检测新版本部署→通知→刷新'机制,三档强度可选(静默自动刷新 / toast提示+短延迟自动刷新 / 弹窗阻断必须手动点击),核心逻辑框架无关,Vue/React 各有一份薄适配层,另附全量/最新 CHANGELOG 虚拟模块、运行时拉取模式与开箱即用的新功能卡片组件 UpdateCard。在 Vite 项目里需要处理'部署新版本后用户还在用旧代码/旧chunk 404 白屏'问题,或者想把项目里手写的一次性 version-check 脚本换成可维护的通用方案时用这个。"
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# vite-plugin-refresh-guard
|
|
@@ -45,6 +45,8 @@ export default defineConfig({ plugins: [refreshGuard()] })
|
|
|
45
45
|
## 常见误用(帮用户避坑)
|
|
46
46
|
|
|
47
47
|
- **不要**在 `mode: 'modal-blocking'` 的弹窗外面又加一个背景点击关闭——设计上就是不可关闭的,加了等于白做这一档
|
|
48
|
+
- **不要**把「检测有没有更新」等同于「version 变了」——检测基准是 `buildId`(默认 git short SHA,插件同时注入产物与客户端)。`version` 只在没给 buildId 时才作为兜底;靠它判断会漏掉「忘了 bump package.json 的连续发版」和「回滚部署」,而且漏得很安静
|
|
49
|
+
- **不要**把刷新按钮绑到 `checker.applyUpdate()` 却不传 `force`——冷却期(默认 90s)内那个点击会毫无反应,看起来像按钮坏了。用户显式点击用 `refreshNow()`(或 `applyUpdate({ force: true })`),冷却只管自动刷新路径
|
|
48
50
|
- **不要**绕开 `checker.applyUpdate()` 直接手写 `location.reload()`——会跳过 `refreshCooldown` 防抖,遇到 `version.json` 缓存配置有问题时容易刷新死循环
|
|
49
51
|
- **不要**把"版本更新提示"和"CHANGELOG 展示"强行绑死成一套逻辑——这俩是两码事(一个决定"要不要刷新",一个决定"给用户看什么"),本包故意拆成独立的 `virtual:refresh-guard-changelog` 虚拟模块,各用各的,不想要 changelog 就在插件配置里 `changelog: false`
|
|
50
52
|
- 如果想要更丰富的"功能更新卡片"(含版本号、自动从 Markdown 提取要点、一键刷新与完整日志外链),直接引入 `UpdateCard`(`vite-plugin-refresh-guard/vue/UpdateCard.vue` 或 `vite-plugin-refresh-guard/react/UpdateCard`),不要手写一套卡片弹窗
|
|
@@ -13,6 +13,10 @@ var DEFAULTS = {
|
|
|
13
13
|
guardChunkErrors: true
|
|
14
14
|
};
|
|
15
15
|
var COOLDOWN_KEY = "__refresh_guard_last_refresh__";
|
|
16
|
+
var CACHE_BUSTER = "t";
|
|
17
|
+
function readBakedBuildId() {
|
|
18
|
+
return typeof __REFRESH_GUARD_BUILD_ID__ !== "undefined" ? __REFRESH_GUARD_BUILD_ID__ : void 0;
|
|
19
|
+
}
|
|
16
20
|
var CHUNK_ERROR_PATTERN = /error loading dynamically imported module|failed to fetch dynamically imported module/i;
|
|
17
21
|
var UpdateChecker = class {
|
|
18
22
|
/** @param currentVersion The version baked into *this* running build (e.g. `__APP_VERSION__` from your Vite define, or package.json version). */
|
|
@@ -35,6 +39,7 @@ var UpdateChecker = class {
|
|
|
35
39
|
};
|
|
36
40
|
this.currentVersion = currentVersion;
|
|
37
41
|
this.opts = { ...DEFAULTS, ...options };
|
|
42
|
+
this.buildId = options.buildId ?? readBakedBuildId();
|
|
38
43
|
}
|
|
39
44
|
get hasUpdate() {
|
|
40
45
|
return this._hasUpdate;
|
|
@@ -85,17 +90,28 @@ var UpdateChecker = class {
|
|
|
85
90
|
window.removeEventListener("vite:preloadError", this.chunkErrorHandler);
|
|
86
91
|
window.removeEventListener("unhandledrejection", this.chunkErrorHandler);
|
|
87
92
|
}
|
|
88
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Fetch versionUrl now and react if it differs from the running build. Returns whether an
|
|
95
|
+
* update was found.
|
|
96
|
+
*
|
|
97
|
+
* `cache: 'no-store'` only defeats the browser cache — a CDN or reverse proxy (or a service
|
|
98
|
+
* worker) in front of version.json can keep handing back a stale copy indefinitely, so the
|
|
99
|
+
* request also carries a cache-buster query.
|
|
100
|
+
*/
|
|
89
101
|
async checkNow() {
|
|
90
102
|
let info;
|
|
91
103
|
try {
|
|
92
|
-
const
|
|
104
|
+
const url = this.opts.versionUrl;
|
|
105
|
+
const sep = url.includes("?") ? "&" : "?";
|
|
106
|
+
const resp = await fetch(`${url}${sep}${CACHE_BUSTER}=${Date.now()}`, { cache: "no-store" });
|
|
93
107
|
if (!resp.ok) return false;
|
|
94
108
|
info = await resp.json();
|
|
95
109
|
} catch {
|
|
96
110
|
return false;
|
|
97
111
|
}
|
|
98
|
-
if (!info?.version
|
|
112
|
+
if (!info?.version) return false;
|
|
113
|
+
const changed = this.buildId && info.buildId ? info.buildId !== this.buildId : info.version !== this.currentVersion;
|
|
114
|
+
if (!changed) return false;
|
|
99
115
|
this.handleUpdateFound(info);
|
|
100
116
|
return true;
|
|
101
117
|
}
|
|
@@ -124,16 +140,25 @@ var UpdateChecker = class {
|
|
|
124
140
|
this.autoRefreshTimer = setTimeout(() => this.applyUpdate(), this.opts.autoRefreshDelay);
|
|
125
141
|
}
|
|
126
142
|
}
|
|
127
|
-
/**
|
|
128
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Refresh now (what 'modal-blocking' UIs call on button click). Respects the cooldown guard,
|
|
145
|
+
* which exists to stop *automatic* reload loops: pass `{ force: true }` — or call `refreshNow()`
|
|
146
|
+
* — for an explicit user action, otherwise a click inside the cooldown window does nothing,
|
|
147
|
+
* which reads as a dead button.
|
|
148
|
+
*/
|
|
149
|
+
applyUpdate(options = {}) {
|
|
129
150
|
if (typeof window === "undefined") return;
|
|
130
151
|
const last = Number(sessionStorage.getItem(COOLDOWN_KEY) || 0);
|
|
131
|
-
if (Date.now() - last < this.opts.refreshCooldown) return;
|
|
132
|
-
sessionStorage.setItem(COOLDOWN_KEY, String(Date.now()));
|
|
152
|
+
if (!options.force && Date.now() - last < this.opts.refreshCooldown) return;
|
|
133
153
|
this.opts.onBeforeRefresh?.();
|
|
134
154
|
this.emit("refreshing", this._latestInfo);
|
|
155
|
+
sessionStorage.setItem(COOLDOWN_KEY, String(Date.now()));
|
|
135
156
|
window.location.reload();
|
|
136
157
|
}
|
|
158
|
+
/** "立即刷新" click: a human asking for it outranks the loop guard. */
|
|
159
|
+
refreshNow() {
|
|
160
|
+
this.applyUpdate({ force: true });
|
|
161
|
+
}
|
|
137
162
|
on(event, listener) {
|
|
138
163
|
if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
139
164
|
this.listeners.get(event).add(listener);
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/** Baked in by the `refreshGuard()` Vite plugin's `define`. Pass this straight into `useVersionCheck()` / `new UpdateChecker()`. */
|
|
2
2
|
declare const __REFRESH_GUARD_VERSION__: string
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* This build's deployment identity (the git short SHA, or a timestamp when git isn't available).
|
|
6
|
+
* Baked in by the plugin's `define`; `UpdateChecker` reads it automatically when you don't pass
|
|
7
|
+
* `buildId` explicitly. Comparing it against `version.json` is what catches redeploys that kept
|
|
8
|
+
* the same `package.json` version.
|
|
9
|
+
*/
|
|
10
|
+
declare const __REFRESH_GUARD_BUILD_ID__: string | undefined
|
|
11
|
+
|
|
4
12
|
declare module 'virtual:refresh-guard-changelog' {
|
|
5
13
|
/** Latest version heading found in your changelog file, or null if none/disabled. */
|
|
6
14
|
export const latestVersion: string | null
|
package/dist/core/checker.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type { ParsedChangelog, ChangelogVersionEntry } from './changelog';
|
|
|
10
10
|
export declare class UpdateChecker {
|
|
11
11
|
private opts;
|
|
12
12
|
private currentVersion;
|
|
13
|
+
private buildId;
|
|
13
14
|
private timer;
|
|
14
15
|
private autoRefreshTimer;
|
|
15
16
|
private listeners;
|
|
@@ -31,7 +32,14 @@ export declare class UpdateChecker {
|
|
|
31
32
|
fetchChangelog(customUrl?: string): Promise<ParsedChangelog>;
|
|
32
33
|
start(): void;
|
|
33
34
|
stop(): void;
|
|
34
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Fetch versionUrl now and react if it differs from the running build. Returns whether an
|
|
37
|
+
* update was found.
|
|
38
|
+
*
|
|
39
|
+
* `cache: 'no-store'` only defeats the browser cache — a CDN or reverse proxy (or a service
|
|
40
|
+
* worker) in front of version.json can keep handing back a stale copy indefinitely, so the
|
|
41
|
+
* request also carries a cache-buster query.
|
|
42
|
+
*/
|
|
35
43
|
checkNow(): Promise<boolean>;
|
|
36
44
|
/**
|
|
37
45
|
* Feed an update signal from somewhere other than version.json polling — most commonly
|
|
@@ -39,8 +47,17 @@ export declare class UpdateChecker {
|
|
|
39
47
|
*/
|
|
40
48
|
notifyExternalUpdate(info?: VersionInfo): void;
|
|
41
49
|
private handleUpdateFound;
|
|
42
|
-
/**
|
|
43
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Refresh now (what 'modal-blocking' UIs call on button click). Respects the cooldown guard,
|
|
52
|
+
* which exists to stop *automatic* reload loops: pass `{ force: true }` — or call `refreshNow()`
|
|
53
|
+
* — for an explicit user action, otherwise a click inside the cooldown window does nothing,
|
|
54
|
+
* which reads as a dead button.
|
|
55
|
+
*/
|
|
56
|
+
applyUpdate(options?: {
|
|
57
|
+
force?: boolean;
|
|
58
|
+
}): void;
|
|
59
|
+
/** "立即刷新" click: a human asking for it outranks the loop guard. */
|
|
60
|
+
refreshNow(): void;
|
|
44
61
|
on(event: UpdateEvent, listener: UpdateListener): () => void;
|
|
45
62
|
private emit;
|
|
46
63
|
}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -65,6 +65,16 @@ export interface UpdateCardProps {
|
|
|
65
65
|
export interface VersionCheckerOptions {
|
|
66
66
|
/** Where to fetch version info from. Default: '/version.json' (see the Vite plugin, which emits this file at build time). */
|
|
67
67
|
versionUrl?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Deployment id of *this* running build — usually left unset, in which case the value baked in
|
|
70
|
+
* by the plugin's `define` (`__REFRESH_GUARD_BUILD_ID__`) is used.
|
|
71
|
+
*
|
|
72
|
+
* When both this and the fetched manifest's `buildId` are present, they decide whether an
|
|
73
|
+
* update exists — not `version`. That's the difference between "a new release was published"
|
|
74
|
+
* and "the build I'm running is no longer the one being served": redeploys that kept the same
|
|
75
|
+
* package.json version are caught, and a rollback counts as a change too.
|
|
76
|
+
*/
|
|
77
|
+
buildId?: string;
|
|
68
78
|
/** 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). */
|
|
69
79
|
interval?: number;
|
|
70
80
|
/** Re-check when the tab becomes visible again after being hidden. Default: true. */
|
package/dist/index.d.ts
CHANGED
|
@@ -31,14 +31,5 @@ export interface RefreshGuardPluginOptions {
|
|
|
31
31
|
* 读取并解析 CHANGELOG(返回最新版本号、最新正文及所有历史版本列表)。
|
|
32
32
|
*/
|
|
33
33
|
export declare function readChangelog(root: string, changelogOption: string | false | ChangelogPluginOptions | undefined): ParsedChangelog;
|
|
34
|
-
/**
|
|
35
|
-
* Vite plugin half of refresh-guard: bakes the current build's version into your bundle
|
|
36
|
-
* (as `__REFRESH_GUARD_VERSION__`) and emits a `version.json` manifest that the runtime
|
|
37
|
-
* checker (core/checker.ts, or the Vue/React adapters) polls to detect new deploys.
|
|
38
|
-
*
|
|
39
|
-
* Only runs at build time — `version.json` won't exist under plain `vite dev`, which is fine
|
|
40
|
-
* since HMR already covers that case; point a static-file server or `vite preview` at the
|
|
41
|
-
* build output to see it end to end.
|
|
42
|
-
*/
|
|
43
34
|
export declare function refreshGuard(options?: RefreshGuardPluginOptions): Plugin;
|
|
44
35
|
export default refreshGuard;
|
package/dist/index.js
CHANGED
|
@@ -20,10 +20,17 @@ function readChangelog(root, changelogOption) {
|
|
|
20
20
|
const md = readFileSync(path, "utf-8");
|
|
21
21
|
return parseChangelog(md);
|
|
22
22
|
}
|
|
23
|
+
function readGitCommit(root) {
|
|
24
|
+
try {
|
|
25
|
+
return execSync("git rev-parse --short HEAD", { cwd: root, stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
26
|
+
} catch {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
23
30
|
function refreshGuard(options = {}) {
|
|
24
31
|
let config;
|
|
25
32
|
let version = options.version;
|
|
26
|
-
|
|
33
|
+
let buildId = "";
|
|
27
34
|
let commit = "";
|
|
28
35
|
let changelogPath = "";
|
|
29
36
|
return {
|
|
@@ -41,18 +48,24 @@ function refreshGuard(options = {}) {
|
|
|
41
48
|
version = "0.0.0";
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
|
-
|
|
51
|
+
if (!buildId) {
|
|
52
|
+
commit = options.includeCommit === false ? "" : readGitCommit(root);
|
|
53
|
+
buildId = commit || String(Date.now());
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
define: {
|
|
57
|
+
__REFRESH_GUARD_VERSION__: JSON.stringify(version),
|
|
58
|
+
__REFRESH_GUARD_BUILD_ID__: JSON.stringify(buildId)
|
|
59
|
+
}
|
|
60
|
+
};
|
|
45
61
|
},
|
|
46
62
|
configResolved(resolvedConfig) {
|
|
47
63
|
config = resolvedConfig;
|
|
48
64
|
const relFile = typeof options.changelog === "string" ? options.changelog : typeof options.changelog === "object" && options.changelog?.file ? options.changelog.file : "CHANGELOG.md";
|
|
49
65
|
changelogPath = options.changelog === false ? "" : resolve(config.root, relFile);
|
|
50
|
-
if (options.includeCommit !== false) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} catch {
|
|
54
|
-
commit = "";
|
|
55
|
-
}
|
|
66
|
+
if (!commit && options.includeCommit !== false) {
|
|
67
|
+
commit = readGitCommit(config.root);
|
|
68
|
+
if (commit && buildId !== commit) buildId = commit;
|
|
56
69
|
}
|
|
57
70
|
},
|
|
58
71
|
resolveId(id) {
|
|
@@ -98,7 +111,8 @@ export const changelogUrl = ${JSON.stringify(changelogUrl)};
|
|
|
98
111
|
generateBundle() {
|
|
99
112
|
const manifest = {
|
|
100
113
|
version: version ?? "0.0.0",
|
|
101
|
-
|
|
114
|
+
// Only reachable without a prior config() pass (e.g. a hand-rolled pipeline).
|
|
115
|
+
buildId: buildId || String(Date.now()),
|
|
102
116
|
commit: commit || void 0,
|
|
103
117
|
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
104
118
|
};
|
|
@@ -13,7 +13,11 @@ export declare function useVersionCheck(currentVersion: string, options?: Versio
|
|
|
13
13
|
latestInfo: VersionInfo | null;
|
|
14
14
|
changelog: ParsedChangelog | null;
|
|
15
15
|
mode: import("../core/types").UpdateMode;
|
|
16
|
-
applyUpdate: (
|
|
16
|
+
applyUpdate: (opts?: {
|
|
17
|
+
force?: boolean;
|
|
18
|
+
}) => void;
|
|
19
|
+
/** Explicit "立即刷新" click — bypasses the refresh cooldown. Wire this to your button. */
|
|
20
|
+
refreshNow: () => void;
|
|
17
21
|
checkNow: () => Promise<boolean>;
|
|
18
22
|
fetchChangelog: (url?: string) => Promise<ParsedChangelog>;
|
|
19
23
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UpdateChecker
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-5KLAZESA.js";
|
|
4
4
|
import {
|
|
5
5
|
extractBulletPoints,
|
|
6
6
|
fetchChangelog,
|
|
@@ -39,7 +39,9 @@ function useVersionCheck(currentVersion, options = {}) {
|
|
|
39
39
|
latestInfo,
|
|
40
40
|
changelog,
|
|
41
41
|
mode: options.mode ?? "toast-auto",
|
|
42
|
-
applyUpdate: () => checker.applyUpdate(),
|
|
42
|
+
applyUpdate: (opts) => checker.applyUpdate(opts),
|
|
43
|
+
/** Explicit "立即刷新" click — bypasses the refresh cooldown. Wire this to your button. */
|
|
44
|
+
refreshNow: () => checker.refreshNow(),
|
|
43
45
|
checkNow: () => checker.checkNow(),
|
|
44
46
|
fetchChangelog: (url) => checker.fetchChangelog(url),
|
|
45
47
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
@@ -13,7 +13,11 @@ export declare function useVersionCheck(currentVersion: string, options?: Versio
|
|
|
13
13
|
latestInfo: import("vue").ShallowRef<VersionInfo | null, VersionInfo | null>;
|
|
14
14
|
changelog: import("vue").ShallowRef<ParsedChangelog | null, ParsedChangelog | null>;
|
|
15
15
|
mode: import("../core/types").UpdateMode;
|
|
16
|
-
applyUpdate: (
|
|
16
|
+
applyUpdate: (opts?: {
|
|
17
|
+
force?: boolean;
|
|
18
|
+
}) => void;
|
|
19
|
+
/** Explicit "立即刷新" click — bypasses the refresh cooldown. Wire this to your button. */
|
|
20
|
+
refreshNow: () => void;
|
|
17
21
|
checkNow: () => Promise<boolean>;
|
|
18
22
|
fetchChangelog: (url?: string) => Promise<ParsedChangelog>;
|
|
19
23
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UpdateChecker
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-5KLAZESA.js";
|
|
4
4
|
import {
|
|
5
5
|
extractBulletPoints,
|
|
6
6
|
fetchChangelog,
|
|
@@ -32,7 +32,9 @@ function useVersionCheck(currentVersion, options = {}) {
|
|
|
32
32
|
latestInfo,
|
|
33
33
|
changelog,
|
|
34
34
|
mode: options.mode ?? "toast-auto",
|
|
35
|
-
applyUpdate: () => checker.applyUpdate(),
|
|
35
|
+
applyUpdate: (opts) => checker.applyUpdate(opts),
|
|
36
|
+
/** Explicit "立即刷新" click — bypasses the refresh cooldown. Wire this to your button. */
|
|
37
|
+
refreshNow: () => checker.refreshNow(),
|
|
36
38
|
checkNow: () => checker.checkNow(),
|
|
37
39
|
fetchChangelog: (url) => checker.fetchChangelog(url),
|
|
38
40
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-refresh-guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"$schema": "https://raw.githubusercontent.com/vitejs/vite-plugin-registry/refs/heads/main/data/schema/extended-package-json.schema.json",
|
|
5
5
|
"description": "Vite plugin for web update notification — detect a new version on every page load and prompt users to reload: silent auto reload, force refresh, toast prompt, or blocking modal. Framework-agnostic core with Vue and React adapters. Vite 应用版本更新检测与自动刷新方案。",
|
|
6
6
|
"type": "module",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"typecheck": "tsc --noEmit",
|
|
67
67
|
"test": "vitest run",
|
|
68
68
|
"compat": "npm run typecheck && npm test && npm run build",
|
|
69
|
-
"prepublishOnly": "npm run build && node scripts/prepublish-gate.mjs && node scripts/readme-gate.mjs"
|
|
69
|
+
"prepublishOnly": "npm run build && node scripts/prepublish-gate.mjs && node scripts/readme-gate.mjs && node scripts/version-sync-gate.mjs"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"react": ">=18",
|