swpp-backends 1.0.2 → 1.0.3

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.
@@ -22,7 +22,7 @@ function buildServiceWorker() {
22
22
  const templatePath = path_1.default.resolve('./', module.path, 'resources/sw-template.js');
23
23
  // 获取拓展文件
24
24
  let cache = (0, Utils_1.getSource)(rules, undefined, [
25
- 'cacheList', 'modifyRequest', 'getCdnList', 'getSpareUrls', 'blockRequest', 'fetchFile',
25
+ 'cacheRules', 'modifyRequest', 'getRaceUrls', 'getSpareUrls', 'blockRequest', 'fetchFile',
26
26
  ...('external' in rules && Array.isArray(rules.external) ? rules.external : [])
27
27
  ], true) + '\n';
28
28
  if (!fetchFile) {
@@ -39,7 +39,7 @@ function buildServiceWorker() {
39
39
  cache += `(${(0, Utils_1.getSource)(rules['afterJoin'])})()\n`;
40
40
  if ('afterTheme' in rules)
41
41
  cache += `(${(0, Utils_1.getSource)(rules['afterTheme'])})()\n`;
42
- const keyword = "const { cacheList, fetchFile, getSpareUrls } = require('../sw-rules')";
42
+ const keyword = "const { cacheRules, fetchFile, getRaceUrls } = require('../sw-rules')";
43
43
  // noinspection JSUnresolvedVariable
44
44
  let content = fs_1.default.readFileSync(templatePath, 'utf8')
45
45
  .replaceAll("// [insertion site] values", eject?.strValue ?? '')
@@ -83,7 +83,7 @@ const JS_CODE_DEF_FETCH_FILE = `
83
83
  credentials: 'same-origin'
84
84
  })
85
85
  `;
86
- // getCdnList 函数的代码
86
+ // getRaceUrls 函数的代码
87
87
  const JS_CODE_GET_CDN_LIST = `
88
88
  const fetchFile = (request, banCache) => {
89
89
  const fetchArgs = {
@@ -91,7 +91,7 @@ const JS_CODE_GET_CDN_LIST = `
91
91
  mode: 'cors',
92
92
  credentials: 'same-origin'
93
93
  }
94
- const list = getCdnList(request.url)
94
+ const list = getRaceUrls(request.url)
95
95
  if (!list || !Promise.any) return fetch(request, fetchArgs)
96
96
  const res = list.map(url => new Request(url, request))
97
97
  const controllers = []
package/dist/Utils.js CHANGED
@@ -105,7 +105,7 @@ function getSource(obj, typeChecker = undefined, whiteList = undefined, isTop =
105
105
  let str = getSource(value, typeChecker);
106
106
  if (str.length === 0)
107
107
  return '';
108
- if (isTop && whiteList && ['cacheList', 'modifyRequest'].includes(key)) {
108
+ if (isTop && whiteList && ['cacheRules', 'modifyRequest'].includes(key)) {
109
109
  str = str
110
110
  .replace(/\(\s*(.*?)\s*,\s*\$eject\s*\)/g, "$1") // 去掉箭头函数参数表中的 $eject
111
111
  .replaceAll(/\$eject\.(\w+)/g, (_, match) => `eject${match[0].toUpperCase()}${match.substring(1)}`); // 将函数体中的 $eject.xxx 替换为 ejectXxx
@@ -34,7 +34,7 @@
34
34
  self.addEventListener('activate', event => event.waitUntil(clients.claim()))
35
35
 
36
36
  // noinspection JSFileReferences
37
- const { cacheList, fetchFile, getSpareUrls } = require('../sw-rules')
37
+ const { cacheRules, fetchFile, getSpareUrls } = require('../sw-rules')
38
38
 
39
39
  // 检查请求是否成功
40
40
  // noinspection JSUnusedLocalSymbols
@@ -106,8 +106,8 @@
106
106
  /** 判断指定url击中了哪一种缓存,都没有击中则返回null */
107
107
  function findCache(url) {
108
108
  if (url.hostname === 'localhost') return
109
- for (let key in cacheList) {
110
- const value = cacheList[key]
109
+ for (let key in cacheRules) {
110
+ const value = cacheRules[key]
111
111
  if (value.match(url)) return value
112
112
  }
113
113
  }
@@ -219,10 +219,6 @@
219
219
  * @constructor
220
220
  */
221
221
  function CacheChangeExpression(json) {
222
- const checkCache = url => {
223
- const cache = findCache(new URL(url))
224
- return !cache || cache.clean
225
- }
226
222
  /**
227
223
  * 遍历所有value
228
224
  * @param action {function(string): boolean} 接受value并返回bool的函数
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -42,7 +42,7 @@ export interface VersionJsonConfig {
42
42
  charLimit: number;
43
43
  /** 是否合并指定项目 */
44
44
  merge: string[];
45
- /** 生成 cacheList.json 时忽略的文件 */
45
+ /** 生成版本信息时忽略的文件 */
46
46
  exclude: {
47
47
  localhost: RegExp[];
48
48
  other: RegExp[];
@@ -100,7 +100,7 @@ export interface SwppConfigTemplate {
100
100
  charLimit?: number;
101
101
  /** 是否合并指定项目 */
102
102
  merge?: string[];
103
- /** 生成 cacheList.json 时忽略的文件 */
103
+ /** 生成版本信息时忽略的文件 */
104
104
  exclude?: {
105
105
  /** 当前网站的 URL */
106
106
  localhost?: RegExp[];
File without changes
File without changes
File without changes