swpp-backends 1.0.3 → 1.0.4
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 +24 -23
- package/package.json +1 -1
- package/types/FileAnalyzer.d.ts +4 -4
package/dist/FileAnalyzer.js
CHANGED
|
@@ -47,9 +47,7 @@ async function eachAllFile(root, cb) {
|
|
|
47
47
|
await cb(root);
|
|
48
48
|
else {
|
|
49
49
|
const files = fs_1.default.readdirSync(root);
|
|
50
|
-
|
|
51
|
-
await eachAllFile(path_1.default.join(root, it), cb);
|
|
52
|
-
}
|
|
50
|
+
await Promise.all(files.map(it => eachAllFile(path_1.default.join(root, it), cb)));
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
@@ -277,18 +275,15 @@ async function eachAllLinkInUrl(domain, url, result, event) {
|
|
|
277
275
|
case pathname.endsWith('/'):
|
|
278
276
|
content = await response.text();
|
|
279
277
|
update();
|
|
280
|
-
|
|
281
|
-
break;
|
|
278
|
+
return eachAllLinkInHtml(domain, url.substring(0, url.lastIndexOf('/') + 1), content, result, nextEvent);
|
|
282
279
|
case pathname.endsWith('.css'):
|
|
283
280
|
content = await response.text();
|
|
284
281
|
update();
|
|
285
|
-
|
|
286
|
-
break;
|
|
282
|
+
return eachAllLinkInCss(domain, url.substring(0, url.lastIndexOf('/') + 1), content, result, nextEvent);
|
|
287
283
|
case pathname.endsWith('.js'):
|
|
288
284
|
content = await response.text();
|
|
289
285
|
update();
|
|
290
|
-
|
|
291
|
-
break;
|
|
286
|
+
return eachAllLinkInJavaScript(domain, content, result, nextEvent);
|
|
292
287
|
default:
|
|
293
288
|
if (stable) {
|
|
294
289
|
result[url] = [];
|
|
@@ -316,7 +311,8 @@ exports.eachAllLinkInUrl = eachAllLinkInUrl;
|
|
|
316
311
|
* @param event 检索到 URL 时触发的事件
|
|
317
312
|
*/
|
|
318
313
|
async function eachAllLinkInHtml(domain, root, content, result, event) {
|
|
319
|
-
const
|
|
314
|
+
const taskList = [];
|
|
315
|
+
const each = (node) => {
|
|
320
316
|
let url = undefined;
|
|
321
317
|
switch (node.tagName) {
|
|
322
318
|
case 'link':
|
|
@@ -336,17 +332,17 @@ async function eachAllLinkInHtml(domain, root, content, result, event) {
|
|
|
336
332
|
break;
|
|
337
333
|
}
|
|
338
334
|
if (url) {
|
|
339
|
-
|
|
335
|
+
taskList.push(eachAllLinkInUrl(domain, url, result, event));
|
|
340
336
|
}
|
|
341
337
|
else if (node.tagName === 'script') {
|
|
342
|
-
|
|
338
|
+
taskList.push(eachAllLinkInJavaScript(domain, node.rawText, result, event));
|
|
343
339
|
}
|
|
344
340
|
else if (node.tagName === 'style') {
|
|
345
|
-
|
|
341
|
+
taskList.push(eachAllLinkInCss(domain, root, node.rawText, result, event));
|
|
346
342
|
}
|
|
347
343
|
if (node.childNodes) {
|
|
348
344
|
for (let childNode of node.childNodes) {
|
|
349
|
-
|
|
345
|
+
each(childNode);
|
|
350
346
|
}
|
|
351
347
|
}
|
|
352
348
|
};
|
|
@@ -358,7 +354,8 @@ async function eachAllLinkInHtml(domain, root, content, result, event) {
|
|
|
358
354
|
(0, Utils_1.error)('HtmlParser', `HTML [root=${root}] 中存在错误语法`);
|
|
359
355
|
}
|
|
360
356
|
if (html)
|
|
361
|
-
|
|
357
|
+
each(html);
|
|
358
|
+
return Promise.all(taskList);
|
|
362
359
|
}
|
|
363
360
|
exports.eachAllLinkInHtml = eachAllLinkInHtml;
|
|
364
361
|
/**
|
|
@@ -376,12 +373,13 @@ exports.eachAllLinkInHtml = eachAllLinkInHtml;
|
|
|
376
373
|
* @param event 当检索到一个 URL 后触发的事件
|
|
377
374
|
*/
|
|
378
375
|
async function eachAllLinkInCss(domain, root, content, result, event) {
|
|
379
|
-
const
|
|
376
|
+
const taskList = [];
|
|
377
|
+
const each = (any) => {
|
|
380
378
|
if (!any)
|
|
381
379
|
return;
|
|
382
380
|
for (let rule of any) {
|
|
383
381
|
if (rule.declarations)
|
|
384
|
-
|
|
382
|
+
each(rule.declarations);
|
|
385
383
|
switch (rule.type) {
|
|
386
384
|
case 'declaration':
|
|
387
385
|
const value = rule.value;
|
|
@@ -395,13 +393,13 @@ async function eachAllLinkInCss(domain, root, content, result, event) {
|
|
|
395
393
|
else
|
|
396
394
|
url = root + url;
|
|
397
395
|
}
|
|
398
|
-
|
|
396
|
+
taskList.push(eachAllLinkInUrl(domain, url, result, event));
|
|
399
397
|
}
|
|
400
398
|
}
|
|
401
399
|
break;
|
|
402
400
|
case 'import':
|
|
403
401
|
const url = rule.import.trim().replace(/^["']|["']$/g, '');
|
|
404
|
-
|
|
402
|
+
taskList.push(eachAllLinkInUrl(domain, url, result, event));
|
|
405
403
|
break;
|
|
406
404
|
}
|
|
407
405
|
}
|
|
@@ -414,7 +412,8 @@ async function eachAllLinkInCss(domain, root, content, result, event) {
|
|
|
414
412
|
(0, Utils_1.error)('CssParser', `CSS [root=${root}] 中存在错误语法`);
|
|
415
413
|
}
|
|
416
414
|
if (css)
|
|
417
|
-
|
|
415
|
+
each(css);
|
|
416
|
+
return Promise.all(taskList);
|
|
418
417
|
}
|
|
419
418
|
exports.eachAllLinkInCss = eachAllLinkInCss;
|
|
420
419
|
/**
|
|
@@ -430,7 +429,8 @@ exports.eachAllLinkInCss = eachAllLinkInCss;
|
|
|
430
429
|
* @param result 存放结果的对象
|
|
431
430
|
* @param event 当检索到一个 URL 后触发的事件
|
|
432
431
|
*/
|
|
433
|
-
|
|
432
|
+
function eachAllLinkInJavaScript(domain, content, result, event) {
|
|
433
|
+
const taskList = [];
|
|
434
434
|
const ruleList = (0, SwppRules_1.readRules)().config?.external?.js;
|
|
435
435
|
if (!ruleList) {
|
|
436
436
|
(0, Utils_1.error)('LinkItorInJS', '不应发生的异常');
|
|
@@ -440,7 +440,7 @@ async function eachAllLinkInJavaScript(domain, content, result, event) {
|
|
|
440
440
|
if (typeof value === 'function') {
|
|
441
441
|
const urls = value(content);
|
|
442
442
|
for (let url of urls) {
|
|
443
|
-
|
|
443
|
+
taskList.push(eachAllLinkInUrl(domain, url, result, event));
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
446
|
else {
|
|
@@ -451,11 +451,12 @@ async function eachAllLinkInJavaScript(domain, content, result, event) {
|
|
|
451
451
|
?.map(it => it.replace(/^['"`]|['"`]$/g, ''));
|
|
452
452
|
if (list) {
|
|
453
453
|
for (let url of list) {
|
|
454
|
-
|
|
454
|
+
taskList.push(eachAllLinkInUrl(domain, url, result, event));
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
|
+
return Promise.all(taskList);
|
|
459
460
|
}
|
|
460
461
|
exports.eachAllLinkInJavaScript = eachAllLinkInJavaScript;
|
|
461
462
|
/** 判断一个 URL 是否是外部链接 */
|
package/package.json
CHANGED
package/types/FileAnalyzer.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export declare function buildVersionJson(protocol: ('https://' | 'http://'), dom
|
|
|
93
93
|
* @param result 存放结果的对象
|
|
94
94
|
* @param event 检索到一个 URL 时触发的事件
|
|
95
95
|
*/
|
|
96
|
-
export declare function eachAllLinkInUrl(domain: string, url: string, result: VersionMap, event?: (url: string) => void): Promise<void>;
|
|
96
|
+
export declare function eachAllLinkInUrl(domain: string, url: string, result: VersionMap, event?: (url: string) => void): Promise<void | any[]>;
|
|
97
97
|
/**
|
|
98
98
|
* 检索 HTML 文件中的所有外部链接
|
|
99
99
|
*
|
|
@@ -108,7 +108,7 @@ export declare function eachAllLinkInUrl(domain: string, url: string, result: Ve
|
|
|
108
108
|
* @param result 存放结果的对象
|
|
109
109
|
* @param event 检索到 URL 时触发的事件
|
|
110
110
|
*/
|
|
111
|
-
export declare function eachAllLinkInHtml(domain: string, root: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<
|
|
111
|
+
export declare function eachAllLinkInHtml(domain: string, root: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<any[]>;
|
|
112
112
|
/**
|
|
113
113
|
* 检索 CSS 文件中的所有外部链
|
|
114
114
|
*
|
|
@@ -123,7 +123,7 @@ export declare function eachAllLinkInHtml(domain: string, root: string, content:
|
|
|
123
123
|
* @param result 存放结果的对象
|
|
124
124
|
* @param event 当检索到一个 URL 后触发的事件
|
|
125
125
|
*/
|
|
126
|
-
export declare function eachAllLinkInCss(domain: string, root: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<void>;
|
|
126
|
+
export declare function eachAllLinkInCss(domain: string, root: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<void[]>;
|
|
127
127
|
/**
|
|
128
128
|
* 遍历 JS 文件中地所有外部链接
|
|
129
129
|
*
|
|
@@ -137,7 +137,7 @@ export declare function eachAllLinkInCss(domain: string, root: string, content:
|
|
|
137
137
|
* @param result 存放结果的对象
|
|
138
138
|
* @param event 当检索到一个 URL 后触发的事件
|
|
139
139
|
*/
|
|
140
|
-
export declare function eachAllLinkInJavaScript(domain: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<
|
|
140
|
+
export declare function eachAllLinkInJavaScript(domain: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<any[]>;
|
|
141
141
|
/**
|
|
142
142
|
* 查询指定 URL 对应的缓存规则
|
|
143
143
|
*
|