swpp-backends 3.0.0-alpha.3 → 3.0.0-alpha.310
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/{types → dist}/index.d.ts +5 -4
- package/dist/index.js +25 -17
- package/{types → dist}/swpp/FileParser.d.ts +11 -6
- package/dist/swpp/FileParser.js +27 -13
- package/{types → dist}/swpp/JsonBuilder.d.ts +1 -3
- package/dist/swpp/JsonBuilder.js +3 -7
- package/dist/swpp/NetworkFileHandler.js +3 -3
- package/{types → dist}/swpp/ResourcesScanner.d.ts +11 -14
- package/dist/swpp/ResourcesScanner.js +94 -70
- package/{types → dist}/swpp/SwCompiler.d.ts +21 -8
- package/dist/swpp/SwCompiler.js +49 -15
- package/{types → dist}/swpp/config/ConfigCluster.d.ts +98 -63
- package/dist/swpp/config/ConfigCluster.js +60 -48
- package/dist/swpp/config/ConfigLoader.d.ts +78 -0
- package/dist/swpp/config/ConfigLoader.js +180 -89
- package/dist/swpp/config/SpecialConfig.d.ts +29 -0
- package/dist/swpp/config/SpecialConfig.js +53 -0
- package/{types → dist}/swpp/database/CompilationEnv.d.ts +19 -16
- package/dist/swpp/database/CompilationEnv.js +41 -197
- package/dist/swpp/database/CompilationFileParser.d.ts +81 -0
- package/dist/swpp/database/CompilationFileParser.js +267 -0
- package/{types → dist}/swpp/database/CrossDepCode.d.ts +4 -0
- package/dist/swpp/database/CrossDepCode.js +27 -1
- package/dist/swpp/database/CrossEnv.js +19 -2
- package/{types → dist}/swpp/database/DomCode.d.ts +4 -1
- package/dist/swpp/database/DomCode.js +34 -5
- package/dist/swpp/database/KeyValueDatabase.d.ts +72 -0
- package/dist/swpp/database/KeyValueDatabase.js +122 -27
- package/{types → dist}/swpp/database/RuntimeCoreCode.d.ts +2 -1
- package/dist/swpp/database/RuntimeCoreCode.js +6 -5
- package/{types → dist}/swpp/database/RuntimeDepCode.d.ts +8 -14
- package/dist/swpp/database/RuntimeDepCode.js +30 -50
- package/{types → dist}/swpp/database/RuntimeEventCode.d.ts +4 -0
- package/dist/swpp/database/RuntimeEventCode.js +8 -1
- package/{types → dist}/swpp/database/RuntimeKeyValueDatabase.d.ts +1 -1
- package/dist/swpp/database/RuntimeKeyValueDatabase.js +2 -2
- package/dist/swpp/debug/CallChainRecorder.d.ts +5 -0
- package/dist/swpp/debug/CallChainRecorder.js +29 -0
- package/{types → dist}/swpp/untils.d.ts +25 -18
- package/dist/swpp/untils.js +47 -53
- package/package.json +2 -2
- package/types/DomBuilder.d.ts +0 -6
- package/types/FileAnalyzer.d.ts +0 -96
- package/types/ServiceWorkerBuilder.d.ts +0 -7
- package/types/SwppConfig.d.ts +0 -139
- package/types/SwppRules.d.ts +0 -117
- package/types/UpdateJsonBuilder.d.ts +0 -44
- package/types/Utils.d.ts +0 -43
- package/types/Variant.d.ts +0 -58
- package/types/VersionAnalyzer.d.ts +0 -27
- package/types/browser/ServiceWorkerRuntimeTypes.d.ts +0 -18
- package/types/swpp/RuntimeEnv.d.ts +0 -39
- package/types/swpp/SwCodeInject.d.ts +0 -17
- package/types/swpp/config/ConfigLoader.d.ts +0 -53
- package/types/swpp/database/KeyValueDatabase.d.ts +0 -53
- package/types/swpp/database/RuntimeEnv.d.ts +0 -5
- /package/{types → dist}/swpp/NetworkFileHandler.d.ts +0 -0
- /package/{types → dist}/swpp/database/CrossEnv.d.ts +0 -0
|
@@ -3,11 +3,9 @@ export declare const swppVersion: any;
|
|
|
3
3
|
export { utils, RuntimeException } from './swpp/untils';
|
|
4
4
|
export { ResourcesScanner, FileUpdateTracker, } from './swpp/ResourcesScanner';
|
|
5
5
|
export { JsonBuilder, UpdateJson, UpdateChangeExp, TrackerHeaderDiff } from './swpp/JsonBuilder';
|
|
6
|
-
export { FileParserRegistry, FileParser, FileMark } from './swpp/FileParser';
|
|
7
6
|
export { SwCompiler, CompilationData, RuntimeData, BrowserVersion } from './swpp/SwCompiler';
|
|
8
7
|
export { NetworkFileHandler, FiniteConcurrencyFetcher } from './swpp/NetworkFileHandler';
|
|
9
|
-
export {
|
|
10
|
-
export { KeyValueDatabase } from './swpp/database/KeyValueDatabase';
|
|
8
|
+
export { KeyValueDatabase, readThisValue } from './swpp/database/KeyValueDatabase';
|
|
11
9
|
export { RuntimeKeyValueDatabase } from './swpp/database/RuntimeKeyValueDatabase';
|
|
12
10
|
export { RuntimeEventCode } from './swpp/database/RuntimeEventCode';
|
|
13
11
|
export { RuntimeCoreCode } from './swpp/database/RuntimeCoreCode';
|
|
@@ -15,5 +13,8 @@ export { RuntimeDepCode } from './swpp/database/RuntimeDepCode';
|
|
|
15
13
|
export { CrossEnv } from './swpp/database/CrossEnv';
|
|
16
14
|
export { CrossDepCode } from './swpp/database/CrossDepCode';
|
|
17
15
|
export { CompilationEnv, AllowNotFoundEnum } from './swpp/database/CompilationEnv';
|
|
16
|
+
export { FileMark, FileParser } from './swpp/database/CompilationFileParser';
|
|
18
17
|
export { DomCode } from './swpp/database/DomCode';
|
|
19
|
-
export {
|
|
18
|
+
export { ConfigLoader, defineConfig, defineRuntimeEvent, defineDomConfig, defineRuntimeCore, defineCrossDep, defineRuntimeDep, defineCrossEnv, defineCompilationEnv, defineCompilationFP, defineModifier } from './swpp/config/ConfigLoader';
|
|
19
|
+
export { SpecialConfig, IndivisibleConfig, NoCacheConfig } from './swpp/config/SpecialConfig';
|
|
20
|
+
export { defineNoCacheConfig, defineIndivisibleConfig, defineLazyInitConfig } from './swpp/config/ConfigCluster';
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineCompilationEnv = exports.defineCrossEnv = exports.defineRuntimeDep = exports.defineCrossDep = exports.defineRuntimeCore = exports.defineDomConfig = exports.defineRuntimeEvent = exports.defineConfig = exports.
|
|
4
|
-
const untils_1 = require("./swpp/untils");
|
|
4
|
+
exports.defineLazyInitConfig = exports.defineIndivisibleConfig = exports.defineNoCacheConfig = exports.NoCacheConfig = exports.IndivisibleConfig = exports.SpecialConfig = exports.defineModifier = exports.defineCompilationFP = exports.defineCompilationEnv = exports.defineCrossEnv = exports.defineRuntimeDep = exports.defineCrossDep = exports.defineRuntimeCore = exports.defineDomConfig = exports.defineRuntimeEvent = exports.defineConfig = exports.ConfigLoader = exports.DomCode = exports.AllowNotFoundEnum = exports.CompilationEnv = exports.CrossDepCode = exports.CrossEnv = exports.RuntimeDepCode = exports.RuntimeCoreCode = exports.RuntimeEventCode = exports.RuntimeKeyValueDatabase = exports.readThisValue = exports.KeyValueDatabase = exports.FiniteConcurrencyFetcher = exports.RuntimeData = exports.CompilationData = exports.SwCompiler = exports.JsonBuilder = exports.FileUpdateTracker = exports.ResourcesScanner = exports.RuntimeException = exports.utils = exports.swppVersion = void 0;
|
|
5
5
|
/** 版本号 */
|
|
6
6
|
exports.swppVersion = require('../package.json').version;
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return
|
|
7
|
+
var untils_1 = require("./swpp/untils");
|
|
8
|
+
Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return untils_1.utils; } });
|
|
9
|
+
Object.defineProperty(exports, "RuntimeException", { enumerable: true, get: function () { return untils_1.RuntimeException; } });
|
|
9
10
|
var ResourcesScanner_1 = require("./swpp/ResourcesScanner");
|
|
10
11
|
Object.defineProperty(exports, "ResourcesScanner", { enumerable: true, get: function () { return ResourcesScanner_1.ResourcesScanner; } });
|
|
11
12
|
Object.defineProperty(exports, "FileUpdateTracker", { enumerable: true, get: function () { return ResourcesScanner_1.FileUpdateTracker; } });
|
|
12
13
|
var JsonBuilder_1 = require("./swpp/JsonBuilder");
|
|
13
14
|
Object.defineProperty(exports, "JsonBuilder", { enumerable: true, get: function () { return JsonBuilder_1.JsonBuilder; } });
|
|
14
|
-
var FileParser_1 = require("./swpp/FileParser");
|
|
15
|
-
Object.defineProperty(exports, "FileParserRegistry", { enumerable: true, get: function () { return FileParser_1.FileParserRegistry; } });
|
|
16
15
|
var SwCompiler_1 = require("./swpp/SwCompiler");
|
|
17
16
|
Object.defineProperty(exports, "SwCompiler", { enumerable: true, get: function () { return SwCompiler_1.SwCompiler; } });
|
|
17
|
+
Object.defineProperty(exports, "CompilationData", { enumerable: true, get: function () { return SwCompiler_1.CompilationData; } });
|
|
18
18
|
Object.defineProperty(exports, "RuntimeData", { enumerable: true, get: function () { return SwCompiler_1.RuntimeData; } });
|
|
19
19
|
var NetworkFileHandler_1 = require("./swpp/NetworkFileHandler");
|
|
20
20
|
Object.defineProperty(exports, "FiniteConcurrencyFetcher", { enumerable: true, get: function () { return NetworkFileHandler_1.FiniteConcurrencyFetcher; } });
|
|
21
|
-
var ConfigLoader_1 = require("./swpp/config/ConfigLoader");
|
|
22
|
-
Object.defineProperty(exports, "ConfigLoader", { enumerable: true, get: function () { return ConfigLoader_1.ConfigLoader; } });
|
|
23
21
|
var KeyValueDatabase_1 = require("./swpp/database/KeyValueDatabase");
|
|
24
22
|
Object.defineProperty(exports, "KeyValueDatabase", { enumerable: true, get: function () { return KeyValueDatabase_1.KeyValueDatabase; } });
|
|
23
|
+
Object.defineProperty(exports, "readThisValue", { enumerable: true, get: function () { return KeyValueDatabase_1.readThisValue; } });
|
|
25
24
|
var RuntimeKeyValueDatabase_1 = require("./swpp/database/RuntimeKeyValueDatabase");
|
|
26
25
|
Object.defineProperty(exports, "RuntimeKeyValueDatabase", { enumerable: true, get: function () { return RuntimeKeyValueDatabase_1.RuntimeKeyValueDatabase; } });
|
|
27
26
|
var RuntimeEventCode_1 = require("./swpp/database/RuntimeEventCode");
|
|
@@ -39,14 +38,23 @@ Object.defineProperty(exports, "CompilationEnv", { enumerable: true, get: functi
|
|
|
39
38
|
Object.defineProperty(exports, "AllowNotFoundEnum", { enumerable: true, get: function () { return CompilationEnv_1.AllowNotFoundEnum; } });
|
|
40
39
|
var DomCode_1 = require("./swpp/database/DomCode");
|
|
41
40
|
Object.defineProperty(exports, "DomCode", { enumerable: true, get: function () { return DomCode_1.DomCode; } });
|
|
42
|
-
|
|
41
|
+
var ConfigLoader_1 = require("./swpp/config/ConfigLoader");
|
|
42
|
+
Object.defineProperty(exports, "ConfigLoader", { enumerable: true, get: function () { return ConfigLoader_1.ConfigLoader; } });
|
|
43
|
+
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return ConfigLoader_1.defineConfig; } });
|
|
44
|
+
Object.defineProperty(exports, "defineRuntimeEvent", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeEvent; } });
|
|
45
|
+
Object.defineProperty(exports, "defineDomConfig", { enumerable: true, get: function () { return ConfigLoader_1.defineDomConfig; } });
|
|
46
|
+
Object.defineProperty(exports, "defineRuntimeCore", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeCore; } });
|
|
47
|
+
Object.defineProperty(exports, "defineCrossDep", { enumerable: true, get: function () { return ConfigLoader_1.defineCrossDep; } });
|
|
48
|
+
Object.defineProperty(exports, "defineRuntimeDep", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeDep; } });
|
|
49
|
+
Object.defineProperty(exports, "defineCrossEnv", { enumerable: true, get: function () { return ConfigLoader_1.defineCrossEnv; } });
|
|
50
|
+
Object.defineProperty(exports, "defineCompilationEnv", { enumerable: true, get: function () { return ConfigLoader_1.defineCompilationEnv; } });
|
|
51
|
+
Object.defineProperty(exports, "defineCompilationFP", { enumerable: true, get: function () { return ConfigLoader_1.defineCompilationFP; } });
|
|
52
|
+
Object.defineProperty(exports, "defineModifier", { enumerable: true, get: function () { return ConfigLoader_1.defineModifier; } });
|
|
53
|
+
var SpecialConfig_1 = require("./swpp/config/SpecialConfig");
|
|
54
|
+
Object.defineProperty(exports, "SpecialConfig", { enumerable: true, get: function () { return SpecialConfig_1.SpecialConfig; } });
|
|
55
|
+
Object.defineProperty(exports, "IndivisibleConfig", { enumerable: true, get: function () { return SpecialConfig_1.IndivisibleConfig; } });
|
|
56
|
+
Object.defineProperty(exports, "NoCacheConfig", { enumerable: true, get: function () { return SpecialConfig_1.NoCacheConfig; } });
|
|
43
57
|
var ConfigCluster_1 = require("./swpp/config/ConfigCluster");
|
|
58
|
+
Object.defineProperty(exports, "defineNoCacheConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineNoCacheConfig; } });
|
|
44
59
|
Object.defineProperty(exports, "defineIndivisibleConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineIndivisibleConfig; } });
|
|
45
|
-
Object.defineProperty(exports, "
|
|
46
|
-
Object.defineProperty(exports, "defineRuntimeEvent", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeEvent; } });
|
|
47
|
-
Object.defineProperty(exports, "defineDomConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineDomConfig; } });
|
|
48
|
-
Object.defineProperty(exports, "defineRuntimeCore", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeCore; } });
|
|
49
|
-
Object.defineProperty(exports, "defineCrossDep", { enumerable: true, get: function () { return ConfigCluster_1.defineCrossDep; } });
|
|
50
|
-
Object.defineProperty(exports, "defineRuntimeDep", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeDep; } });
|
|
51
|
-
Object.defineProperty(exports, "defineCrossEnv", { enumerable: true, get: function () { return ConfigCluster_1.defineCrossEnv; } });
|
|
52
|
-
Object.defineProperty(exports, "defineCompilationEnv", { enumerable: true, get: function () { return ConfigCluster_1.defineCompilationEnv; } });
|
|
60
|
+
Object.defineProperty(exports, "defineLazyInitConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineLazyInitConfig; } });
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import * as crypto from 'node:crypto';
|
|
2
|
+
import { FileUpdateTracker } from './ResourcesScanner';
|
|
2
3
|
import { CompilationData } from './SwCompiler';
|
|
3
4
|
export declare class FileParserRegistry {
|
|
4
5
|
private compilation;
|
|
6
|
+
private oldTracker?;
|
|
5
7
|
private map;
|
|
6
|
-
constructor(compilation: CompilationData,
|
|
7
|
-
|
|
8
|
-
});
|
|
8
|
+
constructor(compilation: CompilationData, oldTracker?: FileUpdateTracker | undefined);
|
|
9
|
+
/** 注册一种处理器 */
|
|
9
10
|
registry(type: string, parser: FileParser<any>): void;
|
|
10
11
|
/** 判断是否支持指定类型 */
|
|
11
12
|
containsType(type: string): boolean;
|
|
12
13
|
/** 解析本地文件 */
|
|
13
|
-
parserLocalFile(path: string): Promise<Set<string>>;
|
|
14
|
+
parserLocalFile(path: string, cb?: (content: crypto.BinaryLike) => void, force?: boolean): Promise<Set<string>>;
|
|
14
15
|
/** 解析网络文件 */
|
|
15
16
|
parserNetworkFile(response: Response, callback?: (content: crypto.BinaryLike) => Promise<any> | any): Promise<Set<string>>;
|
|
16
17
|
/**
|
|
@@ -58,8 +59,12 @@ export interface FileParser<T extends crypto.BinaryLike> {
|
|
|
58
59
|
export interface FileMark {
|
|
59
60
|
/** URL */
|
|
60
61
|
file: string;
|
|
61
|
-
/**
|
|
62
|
-
|
|
62
|
+
/**
|
|
63
|
+
* 文件标识符或子文件列表
|
|
64
|
+
*
|
|
65
|
+
* 如果链接为稳定链接,则为子文件列表,否则为文件标识符
|
|
66
|
+
*/
|
|
67
|
+
mark: string | Set<string>;
|
|
63
68
|
/** URL 列表 */
|
|
64
69
|
urls: Set<string>;
|
|
65
70
|
}
|
package/dist/swpp/FileParser.js
CHANGED
|
@@ -8,13 +8,12 @@ exports.buildFileParser = buildFileParser;
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const untils_1 = require("./untils");
|
|
10
10
|
class FileParserRegistry {
|
|
11
|
-
constructor(compilation,
|
|
11
|
+
constructor(compilation, oldTracker) {
|
|
12
12
|
this.compilation = compilation;
|
|
13
|
+
this.oldTracker = oldTracker;
|
|
13
14
|
this.map = new Map();
|
|
14
|
-
for (let key in obj) {
|
|
15
|
-
this.map.set(key, obj[key]);
|
|
16
|
-
}
|
|
17
15
|
}
|
|
16
|
+
/** 注册一种处理器 */
|
|
18
17
|
registry(type, parser) {
|
|
19
18
|
this.map.set(type, parser);
|
|
20
19
|
}
|
|
@@ -23,20 +22,33 @@ class FileParserRegistry {
|
|
|
23
22
|
return this.map.has(type);
|
|
24
23
|
}
|
|
25
24
|
/** 解析本地文件 */
|
|
26
|
-
async parserLocalFile(path) {
|
|
27
|
-
const parser = this.map.get(path_1.default.extname(path));
|
|
28
|
-
if (!parser)
|
|
25
|
+
async parserLocalFile(path, cb, force) {
|
|
26
|
+
const parser = this.map.get(path_1.default.extname(path).substring(1));
|
|
27
|
+
if (!parser) {
|
|
28
|
+
if (force && cb) {
|
|
29
|
+
const reader = this.compilation.compilationEnv.read('readLocalFile');
|
|
30
|
+
const content = await reader(path);
|
|
31
|
+
cb(content);
|
|
32
|
+
}
|
|
29
33
|
return new Set();
|
|
34
|
+
}
|
|
30
35
|
const content = await parser.readFromLocal(this.compilation, path);
|
|
36
|
+
cb?.(content);
|
|
31
37
|
return await parser.extractUrls(this.compilation, content);
|
|
32
38
|
}
|
|
33
39
|
/** 解析网络文件 */
|
|
34
40
|
async parserNetworkFile(response, callback) {
|
|
35
|
-
const fileHandler = this.compilation.compilationEnv.read('
|
|
41
|
+
const fileHandler = this.compilation.compilationEnv.read('NETWORK_FILE_FETCHER');
|
|
36
42
|
const contentType = fileHandler.getUrlContentType(response.url, response);
|
|
37
43
|
const parser = this.map.get(contentType);
|
|
38
|
-
if (!parser)
|
|
44
|
+
if (!parser) {
|
|
45
|
+
if (callback) {
|
|
46
|
+
const blob = await response.blob();
|
|
47
|
+
const array = await blob.stream().getReader().read();
|
|
48
|
+
callback(array.value);
|
|
49
|
+
}
|
|
39
50
|
return new Set();
|
|
51
|
+
}
|
|
40
52
|
const content = await parser.readFromNetwork(this.compilation, response);
|
|
41
53
|
if (callback)
|
|
42
54
|
await callback(content);
|
|
@@ -48,11 +60,13 @@ class FileParserRegistry {
|
|
|
48
60
|
* @param isCached 该链接指向的资源是否需要缓存
|
|
49
61
|
*/
|
|
50
62
|
async parserUrlFile(url, isCached) {
|
|
51
|
-
const fileHandler = this.compilation.compilationEnv.read('
|
|
63
|
+
const fileHandler = this.compilation.compilationEnv.read('NETWORK_FILE_FETCHER');
|
|
52
64
|
const contentType = fileHandler.getUrlContentType(url);
|
|
53
65
|
if (!contentType && !isCached)
|
|
54
66
|
return { file: url, mark: '', urls: new Set() };
|
|
55
67
|
const parser = this.map.get(contentType);
|
|
68
|
+
if (!parser && !isCached)
|
|
69
|
+
return { file: url, mark: '', urls: new Set() };
|
|
56
70
|
if (parser?.calcUrl) {
|
|
57
71
|
const result = await parser.calcUrl(url);
|
|
58
72
|
if (result)
|
|
@@ -61,13 +75,13 @@ class FileParserRegistry {
|
|
|
61
75
|
...result
|
|
62
76
|
};
|
|
63
77
|
}
|
|
64
|
-
const fetcher = this.compilation.compilationEnv.read('
|
|
78
|
+
const fetcher = this.compilation.compilationEnv.read('NETWORK_FILE_FETCHER');
|
|
65
79
|
const urls = new Set();
|
|
66
80
|
let mark = '';
|
|
67
81
|
await fetcher.fetch(url)
|
|
68
|
-
.then(response => this.parserNetworkFile(response, content => {
|
|
82
|
+
.then(response => this.parserNetworkFile(response, isCached ? content => {
|
|
69
83
|
mark = untils_1.utils.calcHash(content);
|
|
70
|
-
}))
|
|
84
|
+
} : undefined))
|
|
71
85
|
.then(urls => urls.forEach(it => urls.add(it)));
|
|
72
86
|
return { file: url, mark, urls };
|
|
73
87
|
}
|
|
@@ -2,11 +2,9 @@ import { CompilationData } from './SwCompiler';
|
|
|
2
2
|
export declare class JsonBuilder {
|
|
3
3
|
private compilation;
|
|
4
4
|
private urls;
|
|
5
|
-
private headers;
|
|
6
5
|
private map;
|
|
7
|
-
constructor(compilation: CompilationData, urls: Set<string>,
|
|
6
|
+
constructor(compilation: CompilationData, urls: Set<string>, map?: Map<string, string>);
|
|
8
7
|
update(key: string, value: string): void;
|
|
9
|
-
putHeader(key: string, value: TrackerHeaderDiff): void;
|
|
10
8
|
buildJson(): Promise<UpdateJson>;
|
|
11
9
|
private zipJson;
|
|
12
10
|
private limitJson;
|
package/dist/swpp/JsonBuilder.js
CHANGED
|
@@ -3,26 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.JsonBuilder = void 0;
|
|
4
4
|
const untils_1 = require("./untils");
|
|
5
5
|
class JsonBuilder {
|
|
6
|
-
constructor(compilation, urls,
|
|
6
|
+
constructor(compilation, urls, map = new Map()) {
|
|
7
7
|
this.compilation = compilation;
|
|
8
8
|
this.urls = urls;
|
|
9
|
-
this.headers = headers;
|
|
10
9
|
this.map = map;
|
|
11
10
|
}
|
|
12
11
|
update(key, value) {
|
|
13
12
|
this.map.set(key, value);
|
|
14
13
|
}
|
|
15
|
-
putHeader(key, value) {
|
|
16
|
-
this.headers.set(key, value);
|
|
17
|
-
}
|
|
18
14
|
// noinspection JSUnusedGlobalSymbols
|
|
19
15
|
async buildJson() {
|
|
20
|
-
const json = await this.compilation.compilationEnv.read('
|
|
16
|
+
const json = await this.compilation.compilationEnv.read('SWPP_JSON_FILE').fetchVersionFile();
|
|
21
17
|
if (json.info.length == 0) {
|
|
22
18
|
json.info.push({ version: 1 });
|
|
23
19
|
return json;
|
|
24
20
|
}
|
|
25
|
-
const newChange = createUpdateChangeExps(this.urls, this.map.
|
|
21
|
+
const newChange = createUpdateChangeExps(this.urls, this.map.keys());
|
|
26
22
|
json.info.unshift({
|
|
27
23
|
version: json.info[0].version + 1,
|
|
28
24
|
change: [newChange]
|
|
@@ -11,7 +11,7 @@ class FiniteConcurrencyFetcher {
|
|
|
11
11
|
this.fetchingCount = 0;
|
|
12
12
|
this.waitList = [];
|
|
13
13
|
this.limit = 100;
|
|
14
|
-
this.referer = 'swpp
|
|
14
|
+
this.referer = 'https://swpp.example.com';
|
|
15
15
|
this.userAgent = 'swpp-backends';
|
|
16
16
|
this.headers = {};
|
|
17
17
|
}
|
|
@@ -52,7 +52,7 @@ class FiniteConcurrencyFetcher {
|
|
|
52
52
|
contentType = 'html';
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
|
-
contentType = path_1.default.extname(url);
|
|
55
|
+
contentType = path_1.default.extname(url).substring(1);
|
|
56
56
|
}
|
|
57
57
|
if (!contentType) {
|
|
58
58
|
if (response)
|
|
@@ -60,7 +60,7 @@ class FiniteConcurrencyFetcher {
|
|
|
60
60
|
if (contentType.startsWith('text/'))
|
|
61
61
|
contentType = contentType.substring(5);
|
|
62
62
|
if (contentType === 'javascript')
|
|
63
|
-
contentType = '
|
|
63
|
+
contentType = 'js';
|
|
64
64
|
}
|
|
65
65
|
return contentType;
|
|
66
66
|
}
|
|
@@ -5,7 +5,8 @@ import { CompilationData } from './SwCompiler';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class ResourcesScanner {
|
|
7
7
|
private compilation;
|
|
8
|
-
|
|
8
|
+
private oldTracker?;
|
|
9
|
+
constructor(compilation: CompilationData, oldTracker?: FileUpdateTracker | undefined);
|
|
9
10
|
/** 扫描指定目录下的所有文件 */
|
|
10
11
|
scanLocalFile(path: string): Promise<FileUpdateTracker>;
|
|
11
12
|
/** 扫描网络文件 */
|
|
@@ -16,21 +17,20 @@ export declare class ResourcesScanner {
|
|
|
16
17
|
*/
|
|
17
18
|
export declare class FileUpdateTracker {
|
|
18
19
|
protected compilation: CompilationData;
|
|
19
|
-
/** 附加信息 */
|
|
20
|
-
protected headers: Map<string, any>;
|
|
21
20
|
/** 存储列表,key 为文件路径,value 为文件的唯一标识符 */
|
|
22
21
|
protected map: Map<string, string>;
|
|
23
22
|
/** 存储所有存在的 URL */
|
|
24
23
|
protected allUrl: Set<string>;
|
|
25
24
|
constructor(compilation: CompilationData);
|
|
26
25
|
/** 更新一个文件的标识符 */
|
|
27
|
-
update(uri: string, value: string): void;
|
|
26
|
+
update(uri: string, value: string | Set<string> | string[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* 同步指定的稳定资源(同步时会连同同步其连接的稳定资源)
|
|
29
|
+
* @return 直接或间接连接的一些需要扫描的资源
|
|
30
|
+
*/
|
|
31
|
+
syncStable(uri: URL, value: string[], oldTracker: FileUpdateTracker): string[];
|
|
28
32
|
/** 读取一个文件的标识符 */
|
|
29
|
-
get(uri: string): string | undefined;
|
|
30
|
-
/** 设置一个 header */
|
|
31
|
-
putHeader(key: string, value: any): void;
|
|
32
|
-
/** 读取一个 header */
|
|
33
|
-
getHeader(key: string): any | undefined;
|
|
33
|
+
get(uri: string): string | string[] | undefined;
|
|
34
34
|
/** 归一化 uri */
|
|
35
35
|
normalizeUri(uri: string): URL;
|
|
36
36
|
/** 添加一个 URL */
|
|
@@ -43,7 +43,7 @@ export declare class FileUpdateTracker {
|
|
|
43
43
|
* + 在新旧 tracker 中都存在且唯一标识符发生变化
|
|
44
44
|
* + 在新 tracker 中不存在且在旧 tracker 中存在
|
|
45
45
|
*/
|
|
46
|
-
diff(
|
|
46
|
+
diff(): Promise<JsonBuilder>;
|
|
47
47
|
/**
|
|
48
48
|
* 将数据序列化为 JSON
|
|
49
49
|
*
|
|
@@ -52,9 +52,6 @@ export declare class FileUpdateTracker {
|
|
|
52
52
|
* ```json
|
|
53
53
|
* {
|
|
54
54
|
* "version": 4,
|
|
55
|
-
* "headers": {
|
|
56
|
-
* [key: string]: any
|
|
57
|
-
* },
|
|
58
55
|
* "tracker" {
|
|
59
56
|
* [uri: string]: string
|
|
60
57
|
* }
|
|
@@ -65,5 +62,5 @@ export declare class FileUpdateTracker {
|
|
|
65
62
|
/** 解序列化数据 */
|
|
66
63
|
static unJson(compilation: CompilationData, jsonStr: string): FileUpdateTracker;
|
|
67
64
|
/** 从网络拉取并解析 tracker */
|
|
68
|
-
static parserJsonFromNetwork(compilation: CompilationData
|
|
65
|
+
static parserJsonFromNetwork(compilation: CompilationData): Promise<FileUpdateTracker>;
|
|
69
66
|
}
|
|
@@ -37,36 +37,39 @@ const untils_1 = require("./untils");
|
|
|
37
37
|
* 资源文件扫描器
|
|
38
38
|
*/
|
|
39
39
|
class ResourcesScanner {
|
|
40
|
-
constructor(compilation) {
|
|
40
|
+
constructor(compilation, oldTracker) {
|
|
41
41
|
this.compilation = compilation;
|
|
42
|
+
this.oldTracker = oldTracker;
|
|
42
43
|
}
|
|
43
44
|
// noinspection JSUnusedGlobalSymbols
|
|
44
45
|
/** 扫描指定目录下的所有文件 */
|
|
45
46
|
async scanLocalFile(path) {
|
|
46
47
|
const matchCacheRule = this.compilation.crossDep.read('matchCacheRule');
|
|
47
|
-
const register = this.compilation.
|
|
48
|
+
const register = this.compilation.fileParser;
|
|
49
|
+
const jsonInfo = this.compilation.compilationEnv.read('SWPP_JSON_FILE');
|
|
50
|
+
const excludes = [
|
|
51
|
+
path_1.default.posix.join(path, jsonInfo.swppPath, jsonInfo.versionPath),
|
|
52
|
+
path_1.default.posix.join(path, jsonInfo.swppPath, jsonInfo.trackerPath),
|
|
53
|
+
path_1.default.posix.join(path, this.compilation.compilationEnv.read('SERVICE_WORKER') + '.js')
|
|
54
|
+
];
|
|
48
55
|
const urls = new Set();
|
|
49
56
|
const tracker = new FileUpdateTracker(this.compilation);
|
|
50
57
|
await traverseDirectory(path, async (file) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
stream.on('data', data => hash.update(data));
|
|
58
|
+
if (excludes.includes(file))
|
|
59
|
+
return;
|
|
54
60
|
const localUrl = tracker.normalizeUri(file.substring(path.length));
|
|
55
|
-
|
|
61
|
+
const isCached = !!matchCacheRule.runOnNode(localUrl);
|
|
62
|
+
if (isCached) {
|
|
56
63
|
tracker.addUrl(localUrl.href);
|
|
57
64
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
resolve();
|
|
67
|
-
});
|
|
68
|
-
stream.on('error', err => reject(err));
|
|
69
|
-
});
|
|
65
|
+
const set = await register.parserLocalFile(file, content => {
|
|
66
|
+
if (isCached) {
|
|
67
|
+
const hash = crypto.createHash('md5');
|
|
68
|
+
hash.update(content);
|
|
69
|
+
tracker.update(localUrl.pathname, hash.digest('hex'));
|
|
70
|
+
}
|
|
71
|
+
}, isCached);
|
|
72
|
+
set.forEach(it => urls.add(it));
|
|
70
73
|
});
|
|
71
74
|
await this.scanNetworkFile(tracker, urls);
|
|
72
75
|
return tracker;
|
|
@@ -74,7 +77,8 @@ class ResourcesScanner {
|
|
|
74
77
|
/** 扫描网络文件 */
|
|
75
78
|
async scanNetworkFile(tracker, urls, record = new Set()) {
|
|
76
79
|
const matchCacheRule = this.compilation.crossDep.read('matchCacheRule');
|
|
77
|
-
const registry = this.compilation.
|
|
80
|
+
const registry = this.compilation.fileParser;
|
|
81
|
+
const isStable = this.compilation.compilationEnv.read('isStable');
|
|
78
82
|
const appendedUrls = new Set();
|
|
79
83
|
const taskList = new Array(urls.size);
|
|
80
84
|
let i = 0;
|
|
@@ -87,9 +91,19 @@ class ResourcesScanner {
|
|
|
87
91
|
if (isCached) {
|
|
88
92
|
tracker.addUrl(normalizeUri.href);
|
|
89
93
|
}
|
|
94
|
+
if (isStable(normalizeUri)) {
|
|
95
|
+
const oldValue = this.oldTracker?.get?.(normalizeUri.href);
|
|
96
|
+
if (Array.isArray(oldValue)) {
|
|
97
|
+
const list = tracker.syncStable(normalizeUri, oldValue, this.oldTracker);
|
|
98
|
+
list.forEach(it => appendedUrls.add(it));
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
90
102
|
taskList[i++] = registry.parserUrlFile(normalizeUri.href, !!isCached)
|
|
91
103
|
.then(value => {
|
|
92
|
-
|
|
104
|
+
if (isCached) {
|
|
105
|
+
tracker.update(value.file, value.mark);
|
|
106
|
+
}
|
|
93
107
|
value.urls.forEach(it => appendedUrls.add(it));
|
|
94
108
|
}).catch(err => untils_1.utils.printError('SCAN NETWORK FILE', err));
|
|
95
109
|
}
|
|
@@ -112,7 +126,7 @@ async function traverseDirectory(dir, callback) {
|
|
|
112
126
|
if (err)
|
|
113
127
|
reject(err);
|
|
114
128
|
else {
|
|
115
|
-
Promise.all(files.map(it => traverseDirectory(path_1.default.join(dir, it), callback))).then(() => resolve());
|
|
129
|
+
Promise.all(files.map(it => traverseDirectory(path_1.default.posix.join(dir, it), callback))).then(() => resolve());
|
|
116
130
|
}
|
|
117
131
|
});
|
|
118
132
|
});
|
|
@@ -127,8 +141,6 @@ async function traverseDirectory(dir, callback) {
|
|
|
127
141
|
class FileUpdateTracker {
|
|
128
142
|
constructor(compilation) {
|
|
129
143
|
this.compilation = compilation;
|
|
130
|
-
/** 附加信息 */
|
|
131
|
-
this.headers = new Map();
|
|
132
144
|
/** 存储列表,key 为文件路径,value 为文件的唯一标识符 */
|
|
133
145
|
this.map = new Map();
|
|
134
146
|
/** 存储所有存在的 URL */
|
|
@@ -136,26 +148,58 @@ class FileUpdateTracker {
|
|
|
136
148
|
}
|
|
137
149
|
/** 更新一个文件的标识符 */
|
|
138
150
|
update(uri, value) {
|
|
139
|
-
|
|
151
|
+
if (typeof value == 'string') {
|
|
152
|
+
if (value.startsWith('[')) {
|
|
153
|
+
throw new untils_1.RuntimeException(untils_1.exceptionNames.invalidValue, `插入数据("${value}")时,不应当以方括号开头`);
|
|
154
|
+
}
|
|
155
|
+
this.map.set(uri, value);
|
|
156
|
+
}
|
|
157
|
+
else if (Array.isArray(value)) {
|
|
158
|
+
this.map.set(uri, JSON.stringify(value));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.map.set(uri, JSON.stringify(Array.from(value)));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 同步指定的稳定资源(同步时会连同同步其连接的稳定资源)
|
|
166
|
+
* @return 直接或间接连接的一些需要扫描的资源
|
|
167
|
+
*/
|
|
168
|
+
syncStable(uri, value, oldTracker) {
|
|
169
|
+
const isStable = this.compilation.compilationEnv.read('isStable');
|
|
170
|
+
this.update(uri.href, value);
|
|
171
|
+
this.addUrl(uri.href);
|
|
172
|
+
const result = [];
|
|
173
|
+
for (let item of value) {
|
|
174
|
+
this.addUrl(item);
|
|
175
|
+
const itemUrl = new URL(item);
|
|
176
|
+
if (isStable(itemUrl)) {
|
|
177
|
+
const oldValue = oldTracker.get(item);
|
|
178
|
+
if (Array.isArray(oldValue)) {
|
|
179
|
+
const son = this.syncStable(itemUrl, oldValue, oldTracker);
|
|
180
|
+
result.push(...son);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
result.push(item);
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
140
187
|
}
|
|
141
188
|
/** 读取一个文件的标识符 */
|
|
142
189
|
get(uri) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.headers.set(key, value);
|
|
148
|
-
}
|
|
149
|
-
/** 读取一个 header */
|
|
150
|
-
getHeader(key) {
|
|
151
|
-
return this.headers.get(key);
|
|
190
|
+
const value = this.map.get(this.normalizeUri(uri).href);
|
|
191
|
+
if (!value)
|
|
192
|
+
return;
|
|
193
|
+
return value.startsWith('[') ? JSON.parse(value) : value;
|
|
152
194
|
}
|
|
153
195
|
/** 归一化 uri */
|
|
154
196
|
normalizeUri(uri) {
|
|
155
197
|
if (uri.startsWith('http:'))
|
|
156
198
|
uri = `https:${uri.substring(5)}`;
|
|
157
|
-
const
|
|
158
|
-
|
|
199
|
+
const baseUrl = this.compilation.compilationEnv.read('DOMAIN_HOST');
|
|
200
|
+
const url = new URL(uri, baseUrl);
|
|
201
|
+
const normalizer = this.compilation.crossDep.read('normalizeUrl');
|
|
202
|
+
return new URL(normalizer.runOnNode(url.href));
|
|
159
203
|
}
|
|
160
204
|
/** 添加一个 URL */
|
|
161
205
|
addUrl(url) {
|
|
@@ -170,23 +214,19 @@ class FileUpdateTracker {
|
|
|
170
214
|
* + 在新旧 tracker 中都存在且唯一标识符发生变化
|
|
171
215
|
* + 在新 tracker 中不存在且在旧 tracker 中存在
|
|
172
216
|
*/
|
|
173
|
-
diff(
|
|
217
|
+
async diff() {
|
|
218
|
+
const baseUrl = this.compilation.compilationEnv.read('DOMAIN_HOST');
|
|
174
219
|
const diff = new JsonBuilder_1.JsonBuilder(this.compilation, this.allUrl);
|
|
220
|
+
const oldTracker = await this.compilation.compilationEnv.read('SWPP_JSON_FILE').fetchTrackerFile(this.compilation);
|
|
175
221
|
oldTracker.map.forEach((value, key) => {
|
|
176
222
|
if (this.map.has(key)) {
|
|
177
223
|
if (this.get(key) !== value)
|
|
178
|
-
diff.update(key, value);
|
|
224
|
+
diff.update(untils_1.utils.splicingUrl(baseUrl, key).href, value);
|
|
179
225
|
}
|
|
180
226
|
else {
|
|
181
|
-
diff.update(key, value);
|
|
227
|
+
diff.update(untils_1.utils.splicingUrl(baseUrl, key).href, value);
|
|
182
228
|
}
|
|
183
229
|
});
|
|
184
|
-
this.headers.forEach((value, key) => {
|
|
185
|
-
diff.putHeader(key, {
|
|
186
|
-
oldValue: oldTracker.getHeader(key),
|
|
187
|
-
newValue: value
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
230
|
return diff;
|
|
191
231
|
}
|
|
192
232
|
// noinspection JSUnusedGlobalSymbols
|
|
@@ -198,9 +238,6 @@ class FileUpdateTracker {
|
|
|
198
238
|
* ```json
|
|
199
239
|
* {
|
|
200
240
|
* "version": 4,
|
|
201
|
-
* "headers": {
|
|
202
|
-
* [key: string]: any
|
|
203
|
-
* },
|
|
204
241
|
* "tracker" {
|
|
205
242
|
* [uri: string]: string
|
|
206
243
|
* }
|
|
@@ -215,7 +252,7 @@ class FileUpdateTracker {
|
|
|
215
252
|
this.map.forEach((value, key) => {
|
|
216
253
|
result.tracker[key] = value;
|
|
217
254
|
});
|
|
218
|
-
return JSON.stringify(result
|
|
255
|
+
return JSON.stringify(result);
|
|
219
256
|
}
|
|
220
257
|
/** 解序列化数据 */
|
|
221
258
|
static unJson(compilation, jsonStr) {
|
|
@@ -223,34 +260,28 @@ class FileUpdateTracker {
|
|
|
223
260
|
const json = JSON.parse(jsonStr);
|
|
224
261
|
switch (json.version) {
|
|
225
262
|
case 4:
|
|
226
|
-
for (let key in json.headers) {
|
|
227
|
-
tracker.headers.set(key, json.headers[key]);
|
|
228
|
-
}
|
|
229
263
|
for (let key in json.tracker) {
|
|
230
264
|
tracker.map.set(key, json.tracker[key]);
|
|
231
265
|
}
|
|
232
266
|
break;
|
|
233
267
|
case 3:
|
|
234
|
-
for (let key in json['external']) {
|
|
235
|
-
tracker.headers.set(key, json['external'][key]);
|
|
236
|
-
}
|
|
237
268
|
for (let key in json.list) {
|
|
238
269
|
const value = json.list[key];
|
|
239
270
|
tracker.map.set(key, value.length === 32 ? value : '');
|
|
240
271
|
}
|
|
241
272
|
break;
|
|
242
|
-
default: throw {
|
|
243
|
-
code: untils_1.exceptionNames.unsupportedVersion,
|
|
244
|
-
message: `不支持 ${json.version}`,
|
|
245
|
-
};
|
|
273
|
+
default: throw new untils_1.RuntimeException(untils_1.exceptionNames.unsupportedVersion, `不支持 ${json.version}`);
|
|
246
274
|
}
|
|
247
275
|
return tracker;
|
|
248
276
|
}
|
|
249
277
|
// noinspection JSUnusedGlobalSymbols
|
|
250
278
|
/** 从网络拉取并解析 tracker */
|
|
251
|
-
static async parserJsonFromNetwork(compilation
|
|
252
|
-
const
|
|
253
|
-
const
|
|
279
|
+
static async parserJsonFromNetwork(compilation) {
|
|
280
|
+
const domain = compilation.compilationEnv.read('DOMAIN_HOST');
|
|
281
|
+
const jsonInfo = compilation.compilationEnv.read('SWPP_JSON_FILE');
|
|
282
|
+
const url = untils_1.utils.splicingUrl(domain, jsonInfo.swppPath, jsonInfo.trackerPath);
|
|
283
|
+
const fetcher = compilation.compilationEnv.read('NETWORK_FILE_FETCHER');
|
|
284
|
+
const isNotFound = compilation.compilationEnv.read('isNotFound');
|
|
254
285
|
const notFoundLevel = compilation.compilationEnv.read('ALLOW_NOT_FOUND');
|
|
255
286
|
let error;
|
|
256
287
|
const result = await (async () => {
|
|
@@ -258,10 +289,7 @@ class FileUpdateTracker {
|
|
|
258
289
|
const response = await fetcher.fetch(url);
|
|
259
290
|
if (isNotFound.response(response)) {
|
|
260
291
|
if (notFoundLevel == CompilationEnv_1.AllowNotFoundEnum.REJECT_ALL) {
|
|
261
|
-
error = {
|
|
262
|
-
code: untils_1.exceptionNames.notFound,
|
|
263
|
-
message: `拉取 ${url} 时出现 404 错误`
|
|
264
|
-
};
|
|
292
|
+
error = new untils_1.RuntimeException(untils_1.exceptionNames.notFound, `拉取 ${url} 时出现 404 错误`);
|
|
265
293
|
return;
|
|
266
294
|
}
|
|
267
295
|
untils_1.utils.printWarning('SCANNER', '拉取 tracker 时服务器返回了 404,如果是第一次携带 swpp v3 构建网站请忽视这条信息');
|
|
@@ -275,11 +303,7 @@ class FileUpdateTracker {
|
|
|
275
303
|
untils_1.utils.printWarning('SCANNER', '拉取 tracker 时 DNS 解析失败,如果是第一次携带 swpp v3 构建网站且网站暂时无法解析请忽视这条信息');
|
|
276
304
|
return new FileUpdateTracker(compilation);
|
|
277
305
|
}
|
|
278
|
-
untils_1.
|
|
279
|
-
throw {
|
|
280
|
-
code: untils_1.exceptionNames.error,
|
|
281
|
-
message: `拉取或解析历史 Tracker 时出现错误`
|
|
282
|
-
};
|
|
306
|
+
throw new untils_1.RuntimeException(untils_1.exceptionNames.error, `拉取或解析历史 Tracker 时出现错误`, { cause: e });
|
|
283
307
|
}
|
|
284
308
|
})();
|
|
285
309
|
if (result)
|