vite-plugin-refresh-guard 0.2.2 → 0.3.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 +13 -0
- package/README.en.md +63 -9
- package/README.md +63 -4
- package/SKILL.md +2 -1
- package/dist/{chunk-ULA5FWKW.js → chunk-CGDGH2ML.js} +35 -2
- package/dist/chunk-JLHX4WLS.js +67 -0
- package/dist/client.d.ts +8 -0
- package/dist/core/changelog.d.ts +34 -0
- package/dist/core/checker.d.ts +12 -1
- package/dist/core/types.d.ts +60 -2
- package/dist/index.d.ts +20 -11
- package/dist/index.js +29 -10
- package/dist/react/UpdateCard.d.ts +8 -0
- package/dist/react/UpdateCard.js +275 -0
- package/dist/react/useVersionCheck.d.ts +6 -2
- package/dist/react/useVersionCheck.js +16 -1
- package/dist/vue/UpdateCard.vue +356 -0
- package/dist/vue/useVersionCheck.d.ts +6 -2
- package/dist/vue/useVersionCheck.js +16 -1
- package/package.json +7 -2
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { UpdateChecker } from '../core/checker';
|
|
2
|
-
import type { VersionCheckerOptions, VersionInfo } from '../core/types';
|
|
1
|
+
import { UpdateChecker, fetchChangelog, parseChangelog, extractBulletPoints } from '../core/checker';
|
|
2
|
+
import type { VersionCheckerOptions, VersionInfo, ParsedChangelog, ChangelogVersionEntry, UpdateCardProps } from '../core/types';
|
|
3
|
+
export { fetchChangelog, parseChangelog, extractBulletPoints };
|
|
4
|
+
export type { VersionCheckerOptions, VersionInfo, ParsedChangelog, ChangelogVersionEntry, UpdateCardProps, };
|
|
3
5
|
/**
|
|
4
6
|
* Vue composable wrapping the framework-agnostic UpdateChecker. Mounts/unmounts the checker
|
|
5
7
|
* with the component's lifecycle automatically.
|
|
@@ -9,9 +11,11 @@ import type { VersionCheckerOptions, VersionInfo } from '../core/types';
|
|
|
9
11
|
export declare function useVersionCheck(currentVersion: string, options?: VersionCheckerOptions): {
|
|
10
12
|
hasUpdate: import("vue").Ref<boolean, boolean>;
|
|
11
13
|
latestInfo: import("vue").ShallowRef<VersionInfo | null, VersionInfo | null>;
|
|
14
|
+
changelog: import("vue").ShallowRef<ParsedChangelog | null, ParsedChangelog | null>;
|
|
12
15
|
mode: import("../core/types").UpdateMode;
|
|
13
16
|
applyUpdate: () => void;
|
|
14
17
|
checkNow: () => Promise<boolean>;
|
|
18
|
+
fetchChangelog: (url?: string) => Promise<ParsedChangelog>;
|
|
15
19
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
16
20
|
notifyExternalUpdate: (info?: VersionInfo) => void;
|
|
17
21
|
checker: UpdateChecker;
|
|
@@ -1,33 +1,48 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UpdateChecker
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-CGDGH2ML.js";
|
|
4
|
+
import {
|
|
5
|
+
extractBulletPoints,
|
|
6
|
+
fetchChangelog,
|
|
7
|
+
parseChangelog
|
|
8
|
+
} from "../chunk-JLHX4WLS.js";
|
|
4
9
|
|
|
5
10
|
// src/vue/useVersionCheck.ts
|
|
6
11
|
import { onMounted, onUnmounted, ref, shallowRef } from "vue";
|
|
7
12
|
function useVersionCheck(currentVersion, options = {}) {
|
|
8
13
|
const hasUpdate = ref(false);
|
|
9
14
|
const latestInfo = shallowRef(null);
|
|
15
|
+
const changelog = shallowRef(null);
|
|
10
16
|
const checker = new UpdateChecker(currentVersion, options);
|
|
11
17
|
const off = checker.on("update-available", (info) => {
|
|
12
18
|
hasUpdate.value = true;
|
|
13
19
|
latestInfo.value = info;
|
|
14
20
|
});
|
|
21
|
+
const offChangelog = checker.on("changelog-loaded", (parsed) => {
|
|
22
|
+
changelog.value = parsed;
|
|
23
|
+
});
|
|
15
24
|
onMounted(() => checker.start());
|
|
16
25
|
onUnmounted(() => {
|
|
17
26
|
checker.stop();
|
|
18
27
|
off();
|
|
28
|
+
offChangelog();
|
|
19
29
|
});
|
|
20
30
|
return {
|
|
21
31
|
hasUpdate,
|
|
22
32
|
latestInfo,
|
|
33
|
+
changelog,
|
|
23
34
|
mode: options.mode ?? "toast-auto",
|
|
24
35
|
applyUpdate: () => checker.applyUpdate(),
|
|
25
36
|
checkNow: () => checker.checkNow(),
|
|
37
|
+
fetchChangelog: (url) => checker.fetchChangelog(url),
|
|
26
38
|
/** Feed a vite-plugin-pwa `onNeedRefresh` (or any other out-of-band) signal into the same mode logic. */
|
|
27
39
|
notifyExternalUpdate: (info) => checker.notifyExternalUpdate(info),
|
|
28
40
|
checker
|
|
29
41
|
};
|
|
30
42
|
}
|
|
31
43
|
export {
|
|
44
|
+
extractBulletPoints,
|
|
45
|
+
fetchChangelog,
|
|
46
|
+
parseChangelog,
|
|
32
47
|
useVersionCheck
|
|
33
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-refresh-guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"import": "./dist/vue/useVersionCheck.js"
|
|
42
42
|
},
|
|
43
43
|
"./vue/UpdatePrompt.vue": "./dist/vue/UpdatePrompt.vue",
|
|
44
|
+
"./vue/UpdateCard.vue": "./dist/vue/UpdateCard.vue",
|
|
44
45
|
"./react": {
|
|
45
46
|
"types": "./dist/react/useVersionCheck.d.ts",
|
|
46
47
|
"import": "./dist/react/useVersionCheck.js"
|
|
@@ -48,6 +49,10 @@
|
|
|
48
49
|
"./react/UpdatePrompt": {
|
|
49
50
|
"types": "./dist/react/UpdatePrompt.d.ts",
|
|
50
51
|
"import": "./dist/react/UpdatePrompt.js"
|
|
52
|
+
},
|
|
53
|
+
"./react/UpdateCard": {
|
|
54
|
+
"types": "./dist/react/UpdateCard.d.ts",
|
|
55
|
+
"import": "./dist/react/UpdateCard.js"
|
|
51
56
|
}
|
|
52
57
|
},
|
|
53
58
|
"files": [
|
|
@@ -57,7 +62,7 @@
|
|
|
57
62
|
"CHANGELOG.md"
|
|
58
63
|
],
|
|
59
64
|
"scripts": {
|
|
60
|
-
"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",
|
|
65
|
+
"build": "tsup src/index.ts src/vue/useVersionCheck.ts src/react/useVersionCheck.ts src/react/UpdatePrompt.tsx src/react/UpdateCard.tsx --format esm --clean && tsc -p tsconfig.build.json && node scripts/copy-assets.mjs",
|
|
61
66
|
"typecheck": "tsc --noEmit",
|
|
62
67
|
"test": "vitest run",
|
|
63
68
|
"compat": "npm run typecheck && npm test && npm run build",
|