swpp-backends 2.0.3 → 2.0.5
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/dist/FileAnalyzer.js +6 -3
- package/dist/UpdateJsonBuilder.js +6 -1
- package/dist/index.js +1 -1
- package/dist/resources/sw-template.js +4 -12
- package/package.json +1 -1
package/dist/FileAnalyzer.js
CHANGED
|
@@ -108,10 +108,13 @@ async function buildVersionJson(protocol, domain, root) {
|
|
|
108
108
|
cacheInfoMap.forEach((value, key) => {
|
|
109
109
|
external[key] = value;
|
|
110
110
|
});
|
|
111
|
-
|
|
111
|
+
if ('update' in rules) {
|
|
112
|
+
external.swppFlag = rules.update.flag;
|
|
113
|
+
}
|
|
114
|
+
return (0, Variant_1.writeVariant)('newVersionJson', (0, Utils_1.deepFreeze)({
|
|
112
115
|
version: 3,
|
|
113
116
|
list, external
|
|
114
|
-
});
|
|
117
|
+
}));
|
|
115
118
|
}
|
|
116
119
|
exports.buildVersionJson = buildVersionJson;
|
|
117
120
|
/**
|
|
@@ -384,7 +387,7 @@ async function eachAllLinkInCss(domain, url, content, result, event) {
|
|
|
384
387
|
i = right + 2;
|
|
385
388
|
}
|
|
386
389
|
sub.match(/(url\(.*?\))|(@import\s+['"].*?['"])|((https?:)?\/\/[^\s/$.?#].\S*)/g)
|
|
387
|
-
?.map(it => it.replace(/(^url\((['"]?))|((['"]
|
|
390
|
+
?.map(it => it.replace(/(^url\(\s*(['"]?))|((['"]?\s*)\)$)|(^@import\s+['"])|(['"]$)/g, ''))
|
|
388
391
|
?.map(it => {
|
|
389
392
|
switch (true) {
|
|
390
393
|
case it.startsWith('http'):
|
|
@@ -31,7 +31,7 @@ function buildUpdateJson(root, dif) {
|
|
|
31
31
|
(0, Utils_1.error)('UpdateJsonBuilder', '规则文件的 update 项目必须包含 flag 值!');
|
|
32
32
|
throw '规则文件的 update 不合规';
|
|
33
33
|
}
|
|
34
|
-
if (userUpdate.flag === (0, Variant_1.readOldVersionJson)()?.external?.
|
|
34
|
+
if (userUpdate.flag === (0, Variant_1.readOldVersionJson)()?.external?.swppFlag)
|
|
35
35
|
userUpdate = undefined;
|
|
36
36
|
}
|
|
37
37
|
// 如果需要强制刷新直接返回
|
|
@@ -272,6 +272,11 @@ function zipJson(json) {
|
|
|
272
272
|
* + **执行该函数前必须调用过 [calcEjectValues]**
|
|
273
273
|
*/
|
|
274
274
|
function getShorthand(url, offset = 0) {
|
|
275
|
+
if (url.endsWith('/')) {
|
|
276
|
+
const startIndex = url.indexOf('//') + 2;
|
|
277
|
+
if (url.indexOf('/', startIndex) === url.length - 1)
|
|
278
|
+
return '/';
|
|
279
|
+
}
|
|
275
280
|
const map = (0, Variant_1.readMergeVersionMap)();
|
|
276
281
|
let collide = new Set();
|
|
277
282
|
for (let mapKey in map) {
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const VersionAnalyzer_1 = require("./VersionAnalyzer");
|
|
|
10
10
|
const DomBuilder_1 = require("./DomBuilder");
|
|
11
11
|
// noinspection JSUnusedGlobalSymbols
|
|
12
12
|
exports.default = {
|
|
13
|
-
version: '2.0.
|
|
13
|
+
version: '2.0.5',
|
|
14
14
|
cache: {
|
|
15
15
|
readEjectData: Utils_1.readEjectData, readUpdateJson: Variant_1.readUpdateJson,
|
|
16
16
|
readRules: Variant_1.readRules, readMergeVersionMap: Variant_1.readMergeVersionMap,
|
|
@@ -148,8 +148,8 @@
|
|
|
148
148
|
// [debug escape]
|
|
149
149
|
//如果需要清理全站
|
|
150
150
|
if (refresh) {
|
|
151
|
-
if (global !== oldVersion.global) list.
|
|
152
|
-
else list.
|
|
151
|
+
if (global !== oldVersion.global) list.force = true
|
|
152
|
+
else list.refresh = true
|
|
153
153
|
}
|
|
154
154
|
return {list, version: newVersion}
|
|
155
155
|
})
|
|
@@ -185,22 +185,14 @@
|
|
|
185
185
|
list.push(element)
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
/**
|
|
189
|
-
* 清除列表,并将指定元素推入列表中
|
|
190
|
-
* @param element {CacheChangeExpression} 要推入的元素,留空表示不推入
|
|
191
|
-
*/
|
|
192
|
-
this.clean = element => {
|
|
193
|
-
list.length = 0
|
|
194
|
-
if (!element) this.push(element)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
188
|
/**
|
|
198
189
|
* 判断指定 URL 是否和某一条规则匹配
|
|
199
190
|
* @param url {string} URL
|
|
200
191
|
* @return {boolean}
|
|
201
192
|
*/
|
|
202
193
|
this.match = url => {
|
|
203
|
-
if (this.
|
|
194
|
+
if (this.force) return true
|
|
195
|
+
else if (this.refresh) return findCache(url).clean
|
|
204
196
|
else {
|
|
205
197
|
for (let it of list) {
|
|
206
198
|
if (it.match(url)) return true
|