swpp-backends 1.2.0 → 1.2.1
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 +55 -18
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/FileAnalyzer.js
CHANGED
|
@@ -364,37 +364,62 @@ async function eachAllLinkInHtml(domain, url, content, result, event) {
|
|
|
364
364
|
async function eachAllLinkInCss(domain, url, content, result, event) {
|
|
365
365
|
const root = url.substring(0, url.lastIndexOf('/'));
|
|
366
366
|
const urls = new Set();
|
|
367
|
+
/** 从指定位置开始查询注释 */
|
|
368
|
+
const findComment = (tag, start) => {
|
|
369
|
+
for (let i = start; i < content.length;) {
|
|
370
|
+
const item = content[i];
|
|
371
|
+
switch (item) {
|
|
372
|
+
case tag[0]:
|
|
373
|
+
if (content[i + 1] === tag[1])
|
|
374
|
+
return i;
|
|
375
|
+
++i;
|
|
376
|
+
break;
|
|
377
|
+
case '"':
|
|
378
|
+
case '\'':
|
|
379
|
+
while (true) {
|
|
380
|
+
const index = content.indexOf(item, i + 1);
|
|
381
|
+
if (index < 0)
|
|
382
|
+
return -1;
|
|
383
|
+
i = index + 1;
|
|
384
|
+
if (content[index - 1] !== '\\')
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return -1;
|
|
391
|
+
};
|
|
367
392
|
for (let i = 0; i < content.length;) {
|
|
368
|
-
const left =
|
|
393
|
+
const left = findComment('/*', i);
|
|
369
394
|
let sub;
|
|
370
|
-
if (left
|
|
395
|
+
if (left === -1) {
|
|
371
396
|
sub = content.substring(i);
|
|
372
397
|
i = Number.MAX_VALUE;
|
|
373
398
|
}
|
|
374
399
|
else {
|
|
375
400
|
sub = content.substring(i, left);
|
|
376
|
-
const right =
|
|
377
|
-
if (right
|
|
401
|
+
const right = findComment('*/', left + 2);
|
|
402
|
+
if (right === -1)
|
|
378
403
|
i = Number.MAX_VALUE;
|
|
379
404
|
else
|
|
380
405
|
i = right + 2;
|
|
381
406
|
}
|
|
382
407
|
sub.match(/(url\(.*?\))|(@import\s+['"].*?['"])|((https?:)?\/\/[^\s/$.?#].\S*)/g)
|
|
383
408
|
?.map(it => it.replace(/(^url\((['"]?))|((['"]?)\)$)|(^@import\s+['"])|(['"]$)/g, ''))
|
|
384
|
-
?.
|
|
409
|
+
?.map(it => {
|
|
410
|
+
switch (true) {
|
|
411
|
+
case it.startsWith('http'):
|
|
412
|
+
return it;
|
|
413
|
+
case it.startsWith('//'):
|
|
414
|
+
return 'http' + it;
|
|
415
|
+
case it.startsWith('/'):
|
|
416
|
+
return root + it;
|
|
417
|
+
default:
|
|
418
|
+
return root + '/' + it;
|
|
419
|
+
}
|
|
420
|
+
})?.forEach(it => urls.add(it));
|
|
385
421
|
}
|
|
386
|
-
return Promise.all(Array.from(urls).map(it =>
|
|
387
|
-
switch (true) {
|
|
388
|
-
case it.startsWith('http'):
|
|
389
|
-
return it;
|
|
390
|
-
case it.startsWith('//'):
|
|
391
|
-
return 'http' + it;
|
|
392
|
-
case it.startsWith('/'):
|
|
393
|
-
return root + it;
|
|
394
|
-
default:
|
|
395
|
-
return root + '/' + it;
|
|
396
|
-
}
|
|
397
|
-
}).map(it => eachAllLinkInUrl(domain, it, result, event)));
|
|
422
|
+
return Promise.all(Array.from(urls).map(it => eachAllLinkInUrl(domain, it, result, event)));
|
|
398
423
|
}
|
|
399
424
|
function eachAllLinkInJavaScript(domain, _, content, result, event) {
|
|
400
425
|
const taskList = [];
|
|
@@ -403,6 +428,16 @@ function eachAllLinkInJavaScript(domain, _, content, result, event) {
|
|
|
403
428
|
(0, Utils_1.error)('LinkItorInJS', '不应发生的异常');
|
|
404
429
|
throw 'ruleList 为空';
|
|
405
430
|
}
|
|
431
|
+
const calcRegLength = (item) => {
|
|
432
|
+
let length = item.length;
|
|
433
|
+
for (let i = 0; i < item.length; ++i) {
|
|
434
|
+
if (item[i] === '\\') {
|
|
435
|
+
++i;
|
|
436
|
+
--length;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return length;
|
|
440
|
+
};
|
|
406
441
|
for (let value of ruleList) {
|
|
407
442
|
if (typeof value === 'function') {
|
|
408
443
|
const urls = value(content);
|
|
@@ -412,9 +447,11 @@ function eachAllLinkInJavaScript(domain, _, content, result, event) {
|
|
|
412
447
|
}
|
|
413
448
|
else {
|
|
414
449
|
const { head, tail } = value;
|
|
450
|
+
const headLength = calcRegLength(head);
|
|
451
|
+
const tailLength = calcRegLength(tail);
|
|
415
452
|
const reg = new RegExp(`${head}(['"\`])(.*?)(['"\`])${tail}`, 'mg');
|
|
416
453
|
const list = content.match(reg)
|
|
417
|
-
?.map(it => it.substring(
|
|
454
|
+
?.map(it => it.substring(headLength, it.length - tailLength).trim())
|
|
418
455
|
?.map(it => it.replace(/^['"`]|['"`]$/g, ''));
|
|
419
456
|
if (list) {
|
|
420
457
|
for (let url of list) {
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const UpdateJsonBuilder_1 = require("./UpdateJsonBuilder");
|
|
|
8
8
|
const VersionAnalyzer_1 = require("./VersionAnalyzer");
|
|
9
9
|
// noinspection JSUnusedGlobalSymbols
|
|
10
10
|
exports.default = {
|
|
11
|
-
version: '1.2.
|
|
11
|
+
version: '1.2.1',
|
|
12
12
|
cache: {
|
|
13
13
|
readEjectData: Utils_1.readEjectData, readUpdateJson: UpdateJsonBuilder_1.readUpdateJson,
|
|
14
14
|
readRules: SwppRules_1.readRules, readMergeVersionMap: FileAnalyzer_1.readMergeVersionMap,
|