swpp-backends 2.3.10 → 2.3.12

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.
@@ -25,7 +25,7 @@ function buildDomJs() {
25
25
  template = template.replaceAll(key, `const onSuccess = ${config.onsuccess.toString()};`);
26
26
  }
27
27
  else {
28
- template = template.replaceAll(key, '');
28
+ template = template.replaceAll(key, 'const onSuccess = () => {}');
29
29
  }
30
30
  return template;
31
31
  }
@@ -47,6 +47,56 @@
47
47
  // noinspection JSUnresolvedReference
48
48
  self.addEventListener('activate', event => event.waitUntil(clients.claim()))
49
49
 
50
+ /**
51
+ * 基础 fetch
52
+ * @param request {Request|string}
53
+ * @param banCache {boolean} 是否禁用缓存
54
+ * @param cors {boolean} 是否启用 cors
55
+ * @param optional {RequestInit?} 额外的配置项
56
+ * @return {Promise<Response>}
57
+ */
58
+ const baseFetcher = (request, banCache, cors, optional) => {
59
+ if (!optional) optional = {}
60
+ optional.cache = banCache ? 'no-store' : 'default'
61
+ if (cors) {
62
+ optional.mode = 'cors'
63
+ optional.credentials = 'same-origin'
64
+ }
65
+ return fetch(request, optional)
66
+ }
67
+
68
+ /**
69
+ * 添加 cors 配置请求指定资源
70
+ * @param request {Request}
71
+ * @param optional {RequestInit?} 额外的配置项
72
+ * @return {Promise<Response>}
73
+ */
74
+ const fetchWithCache = (request, optional) =>
75
+ baseFetcher(request, false, isCors(request), optional)
76
+
77
+ // noinspection JSUnusedLocalSymbols
78
+ /**
79
+ * 添加 cors 配置请求指定资源
80
+ * @param request {Request}
81
+ * @param banCache {boolean} 是否禁用 HTTP 缓存
82
+ * @param optional {RequestInit?} 额外的配置项
83
+ * @return {Promise<Response>}
84
+ */
85
+ const fetchWithCors = (request, banCache, optional) =>
86
+ baseFetcher(request, banCache, true, optional)
87
+
88
+ /**
89
+ * 判断指定 url 击中了哪一种缓存,都没有击中则返回 null
90
+ * @param url {URL}
91
+ */
92
+ const findCache = url => {
93
+ if (url.hostname === 'localhost') return
94
+ for (let key in cacheRules) {
95
+ const value = cacheRules[key]
96
+ if (value.match(url)) return value
97
+ }
98
+ }
99
+
50
100
  // noinspection JSFileReferences
51
101
  const { cacheRules, fetchFile, isCors, isMemoryQueue } = require('../sw-rules')
52
102
 
@@ -152,56 +202,6 @@
152
202
  })
153
203
  })
154
204
 
155
- /**
156
- * 基础 fetch
157
- * @param request {Request|string}
158
- * @param banCache {boolean} 是否禁用缓存
159
- * @param cors {boolean} 是否启用 cors
160
- * @param optional {RequestInit?} 额外的配置项
161
- * @return {Promise<Response>}
162
- */
163
- const baseFetcher = (request, banCache, cors, optional) => {
164
- if (!optional) optional = {}
165
- optional.cache = banCache ? 'no-store' : 'default'
166
- if (cors) {
167
- optional.mode = 'cors'
168
- optional.credentials = 'same-origin'
169
- }
170
- return fetch(request, optional)
171
- }
172
-
173
- /**
174
- * 添加 cors 配置请求指定资源
175
- * @param request {Request}
176
- * @param optional {RequestInit?} 额外的配置项
177
- * @return {Promise<Response>}
178
- */
179
- const fetchWithCache = (request, optional) =>
180
- baseFetcher(request, false, isCors(request), optional)
181
-
182
- // noinspection JSUnusedLocalSymbols
183
- /**
184
- * 添加 cors 配置请求指定资源
185
- * @param request {Request}
186
- * @param banCache {boolean} 是否禁用 HTTP 缓存
187
- * @param optional {RequestInit?} 额外的配置项
188
- * @return {Promise<Response>}
189
- */
190
- const fetchWithCors = (request, banCache, optional) =>
191
- baseFetcher(request, banCache, true, optional)
192
-
193
- /**
194
- * 判断指定 url 击中了哪一种缓存,都没有击中则返回 null
195
- * @param url {URL}
196
- */
197
- const findCache = url => {
198
- if (url.hostname === 'localhost') return
199
- for (let key in cacheRules) {
200
- const value = cacheRules[key]
201
- if (value.match(url)) return value
202
- }
203
- }
204
-
205
205
  /**
206
206
  * 根据JSON删除缓存
207
207
  * @returns {Promise<UpdateInfo>}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "2.3.10",
3
+ "version": "2.3.12",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -13,14 +13,14 @@
13
13
  "devDependencies": {
14
14
  "@types/fast-html-parser": "^1.0.2",
15
15
  "@types/node": "^20.4.5",
16
- "@types/node-fetch": "^2.6.4",
16
+ "@types/node-fetch": "^2.6.11",
17
17
  "gulp": "^4.0.2",
18
18
  "typescript": "^5.1.6"
19
19
  },
20
20
  "dependencies": {
21
21
  "fast-html-parser": "^1.0.1",
22
22
  "hexo-log": "^4.1.0",
23
- "node-fetch": "^2.6.12"
23
+ "node-fetch": "^2.7.0"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",