Skip to content

Commit d5fc0db

Browse files
committed
fix checkVersionTypeFunc is not defined && update docs
1 parent e488f47 commit d5fc0db

6 files changed

Lines changed: 22 additions & 12 deletions

File tree

CHANGELOG.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 1.7.0
1010

11-
`2023-06-25`
11+
`2023-07-03`
1212

1313
- 🆕 Another method for real-time detection of web application version: By leveraging the browser's cache negotiation mechanism, it checks whether the content of the specified file address has been updated to determine if a new version is available.
1414
- Added `checkOriginSpecifiedFilesUrl` configuration option: After setting this property, the version will be monitored by "checking whether the specified file has been updated" instead of "managing the version number". Pass in a list of file addresses to be monitored, usually the index.html file under a domain name (string array type).

CHANGELOG.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 1.7.0
1010

11-
`2023-06-25`
11+
`2023-07-03`
1212

1313
- 🆕 支持 Web 应用版本实时检测的另一种方法: 通过浏览器的协商缓存原理, 检测**指定文件地址内容是否有更新**来判断是否有新版本可用
1414
- 新增 `checkOriginSpecifiedFilesUrl` 配置项: 设置该属性后将使用 “通过检测指定文件是否有更新” 而不是 “通过管理版本号” 来监测版本, 传入希望监测的文件地址列表, 通常情况为某个域名下的 index.html 文件 (字符串数组类型)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
622622
| config.localPackageVersion | string | The version of the current application usually takes the version field of package.json for comparison with the version.json file of the remote server | | Yes |
623623
| config.pollingTime | number | Time interval for polling monitoring, in ms | 5000 | No |
624624
| config.immediate | boolean | On the first visit, version monitoring will be triggered immediately, and then polling will be conducted at a customized time interval **`v1.5.0`** | false | No |
625-
| config.checkOriginSpecifiedFilesUrl | array | Setting this property will use 'detecting updates in specified file contents' instead of 'version number management' to monitor versions. Pass in the list of file addresses to be monitored, usually the index.html file under a certain domain **`v1.7.0`** | | false |
625+
| config.checkOriginSpecifiedFilesUrl | array | Setting this property will use 'detecting updates in specified file contents' instead of 'version number management' to monitor versions. Pass in the list of file addresses to be monitored, usually the index.html file under a certain domain (Automatic deduplication) **`v1.7.0`** | | false |
626626
| config.checkOriginSpecifiedFilesUrlMode | 'one' / 'all' | 'one' means that if the content of any file address in the list changes, a prompt for an update will be displayed; 'all' means that a prompt for an update will only be displayed when the content of all file addresses in the list changes. (This only takes effect when checkOriginSpecifiedFilesUrl is configured) **`v1.7.0`** | 'one' | false |
627627
| config.enable | boolean | Whether to enable version monitoring. This configuration item can be used to enable version monitoring only in specified environments **`v1.7.0`** | true ||
628628
| config.clearIntervalOnDialog | boolean | When the prompt dialog for a new version appears, clear the timer **`v1.7.0`** | false ||

README.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ sh "export messageJSON='{\"title\": \"This is a title\"}'"
614614
| config.localPackageVersion | string | 当前应用版本号, 通常取 package.json 的 version 字段, 用于与远程服务器的 version.json 文件比较 | |**`v1.7.0`** |
615615
| config.pollingTime | number | 轮询监测的时间间隔, 单位 ms | 5000 ||
616616
| config.immediate | boolean | 第一次访问时, 立即触发版本监测, 之后按自定义时间间隔轮询 **`v1.5.0`** | false ||
617-
| config.checkOriginSpecifiedFilesUrl | array | 设置该属性后将使用 “通过检测指定文件是否有更新” 而不是 “通过管理版本号” 来监测版本, 传入希望监测的文件地址列表, 通常情况为某个域名下的 index.html 文件 **`v1.7.0`** | ||
617+
| config.checkOriginSpecifiedFilesUrl | array | 设置该属性后将使用 “通过检测指定文件是否有更新” 而不是 “通过管理版本号” 来监测版本, 传入希望监测的文件地址列表, 通常情况为某个域名下的 index.html 文件 (自动去重) **`v1.7.0`** | ||
618618
| config.checkOriginSpecifiedFilesUrlMode | 'one' / 'all' | 'one' 表示列表中文件地址只要有一个内容发生改变即提示更新; 'all' 表示列表中文件地址都发生改变时才提示更新. (当 checkOriginSpecifiedFilesUrl 配置后才生效) **`v1.7.0`** | 'one' ||
619619
| config.enable | boolean | 是否启用版本监测, 通过该配置项可以设置版本监测只在指定环境下开启 **`v1.7.0`** | true ||
620620
| config.clearIntervalOnDialog | boolean | 当发现新版本提示弹窗出现后, 清空定时器 **`v1.7.0`** | false ||

index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import {versionTipDialog} from './components/versionTipDialog'
2-
import {createWorker, createWorkerFunc, cancelUpdateFunc} from './utils/index'
2+
import {
3+
createWorker,
4+
createWorkerFunc,
5+
cancelUpdateFunc,
6+
checkVersionTypeFunc,
7+
} from './utils/index'
38

49
/**
510
* Polling monitoring version update (No longer maintain)
@@ -63,7 +68,6 @@ let worker: Worker | undefined = undefined
6368

6469
export const checkVersion = (
6570
config: {
66-
// TODO: 是否去重
6771
checkOriginSpecifiedFilesUrl?: string[]
6872
checkOriginSpecifiedFilesUrlMode?: 'one' | 'all'
6973
originVersionFileUrl?: string
@@ -92,7 +96,7 @@ export const checkVersion = (
9296
if (config.enable === false) return
9397

9498
if (!worker) {
95-
worker = createWorker(createWorkerFunc)
99+
worker = createWorker(createWorkerFunc, [checkVersionTypeFunc])
96100
}
97101

98102
worker.postMessage({
@@ -101,7 +105,7 @@ export const checkVersion = (
101105
immediate: config.immediate || false,
102106
'origin-version-file-url': config.originVersionFileUrl || '',
103107
'check-origin-specified-files-url':
104-
config.checkOriginSpecifiedFilesUrl || [],
108+
[...new Set(config.checkOriginSpecifiedFilesUrl)] || [],
105109
'check-origin-specified-files-url-mode':
106110
config.checkOriginSpecifiedFilesUrlMode || 'one',
107111
'clear-interval-on-dialog': config.clearIntervalOnDialog || false,

utils/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// create package version worker
2-
export const createWorker = (func: () => void) => {
3-
const blob = new Blob(['(' + func.toString() + ')()'])
2+
export const createWorker = (func: () => void, deps?: Array<() => void>) => {
3+
const depsFuncStr = `${deps?.map((_) => _.toString()).join(';\n\n') || ''}`
4+
const blob = new Blob([
5+
`
6+
${depsFuncStr};
7+
(${func.toString()})();
8+
`,
9+
])
410
const url = window.URL.createObjectURL(blob)
511
const worker = new Worker(url)
612
return worker
@@ -156,11 +162,11 @@ export const cancelUpdateFunc = (
156162
}
157163

158164
// check version type
159-
export const checkVersionTypeFunc = (
165+
export function checkVersionTypeFunc(
160166
oldVersion?: string | undefined,
161167
originFileUrl?: string | undefined,
162168
checkOriginSpecifiedFilesUrl?: string[] | undefined
163-
) => {
169+
) {
164170
const checkVersionType =
165171
oldVersion && originFileUrl
166172
? 'check-version'

0 commit comments

Comments
 (0)