swpp-backends 3.0.0-alpha.2 → 3.0.0-alpha.200
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 +2 -2
- package/dist/index.js +7 -7
- package/{types → dist}/swpp/FileParser.d.ts +11 -6
- package/dist/swpp/FileParser.js +27 -13
- package/dist/swpp/JsonBuilder.js +2 -2
- package/dist/swpp/NetworkFileHandler.js +3 -3
- package/{types → dist}/swpp/ResourcesScanner.d.ts +11 -5
- package/dist/swpp/ResourcesScanner.js +99 -46
- package/{types → dist}/swpp/SwCompiler.d.ts +14 -8
- package/dist/swpp/SwCompiler.js +20 -14
- package/{types → dist}/swpp/config/ConfigCluster.d.ts +12 -8
- package/dist/swpp/config/ConfigCluster.js +5 -0
- package/{types → dist}/swpp/config/ConfigLoader.d.ts +6 -3
- package/dist/swpp/config/ConfigLoader.js +48 -60
- package/{types → dist}/swpp/database/CompilationEnv.d.ts +21 -13
- package/dist/swpp/database/CompilationEnv.js +50 -203
- package/dist/swpp/database/CompilationFileParser.d.ts +82 -0
- package/dist/swpp/database/CompilationFileParser.js +263 -0
- package/{types → dist}/swpp/database/CrossDepCode.d.ts +7 -0
- package/dist/swpp/database/CrossDepCode.js +16 -0
- package/{types → dist}/swpp/database/DomCode.d.ts +6 -2
- package/dist/swpp/database/DomCode.js +21 -3
- package/dist/swpp/database/KeyValueDatabase.d.ts +53 -0
- package/dist/swpp/database/KeyValueDatabase.js +58 -25
- package/{types → dist}/swpp/database/RuntimeCoreCode.d.ts +2 -1
- package/dist/swpp/database/RuntimeCoreCode.js +1 -0
- package/{types → dist}/swpp/database/RuntimeDepCode.d.ts +1 -5
- package/dist/swpp/database/RuntimeDepCode.js +0 -11
- package/{types → dist}/swpp/untils.d.ts +17 -18
- package/dist/swpp/untils.js +33 -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/database/KeyValueDatabase.d.ts +0 -53
- package/types/swpp/database/RuntimeEnv.d.ts +0 -5
- /package/{types → dist}/swpp/JsonBuilder.d.ts +0 -0
- /package/{types → dist}/swpp/NetworkFileHandler.d.ts +0 -0
- /package/{types → dist}/swpp/database/CrossEnv.d.ts +0 -0
- /package/{types → dist}/swpp/database/RuntimeEventCode.d.ts +0 -0
- /package/{types → dist}/swpp/database/RuntimeKeyValueDatabase.d.ts +0 -0
|
@@ -3,7 +3,6 @@ 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
8
|
export { ConfigLoader } from './swpp/config/ConfigLoader';
|
|
@@ -15,5 +14,6 @@ export { RuntimeDepCode } from './swpp/database/RuntimeDepCode';
|
|
|
15
14
|
export { CrossEnv } from './swpp/database/CrossEnv';
|
|
16
15
|
export { CrossDepCode } from './swpp/database/CrossDepCode';
|
|
17
16
|
export { CompilationEnv, AllowNotFoundEnum } from './swpp/database/CompilationEnv';
|
|
17
|
+
export { FileMark, FileParser } from './swpp/database/CompilationFileParser';
|
|
18
18
|
export { DomCode } from './swpp/database/DomCode';
|
|
19
|
-
export { defineIndivisibleConfig, defineConfig, defineRuntimeEvent, defineDomConfig, defineRuntimeCore, defineCrossDep, defineRuntimeDep, defineCrossEnv, defineCompilationEnv } from './swpp/config/ConfigCluster';
|
|
19
|
+
export { defineIndivisibleConfig, defineConfig, defineRuntimeEvent, defineDomConfig, defineRuntimeCore, defineCrossDep, defineRuntimeDep, defineCrossEnv, defineCompilationEnv, defineModifier } from './swpp/config/ConfigCluster';
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineCompilationEnv = exports.defineCrossEnv = exports.defineRuntimeDep = exports.defineCrossDep = exports.defineRuntimeCore = exports.defineDomConfig = exports.defineRuntimeEvent = exports.defineConfig = exports.defineIndivisibleConfig = exports.DomCode = exports.AllowNotFoundEnum = exports.CompilationEnv = exports.CrossDepCode = exports.CrossEnv = exports.RuntimeDepCode = exports.RuntimeCoreCode = exports.RuntimeEventCode = exports.RuntimeKeyValueDatabase = exports.KeyValueDatabase = exports.ConfigLoader = exports.FiniteConcurrencyFetcher = exports.RuntimeData = exports.
|
|
4
|
-
|
|
3
|
+
exports.defineModifier = exports.defineCompilationEnv = exports.defineCrossEnv = exports.defineRuntimeDep = exports.defineCrossDep = exports.defineRuntimeCore = exports.defineDomConfig = exports.defineRuntimeEvent = exports.defineConfig = exports.defineIndivisibleConfig = exports.DomCode = exports.AllowNotFoundEnum = exports.CompilationEnv = exports.CrossDepCode = exports.CrossEnv = exports.RuntimeDepCode = exports.RuntimeCoreCode = exports.RuntimeEventCode = exports.RuntimeKeyValueDatabase = exports.KeyValueDatabase = exports.ConfigLoader = exports.FiniteConcurrencyFetcher = exports.RuntimeData = exports.CompilationData = exports.SwCompiler = exports.JsonBuilder = exports.FileUpdateTracker = exports.ResourcesScanner = exports.RuntimeException = exports.utils = exports.swppVersion = void 0;
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
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; } });
|
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "CompilationEnv", { enumerable: true, get: functi
|
|
|
39
39
|
Object.defineProperty(exports, "AllowNotFoundEnum", { enumerable: true, get: function () { return CompilationEnv_1.AllowNotFoundEnum; } });
|
|
40
40
|
var DomCode_1 = require("./swpp/database/DomCode");
|
|
41
41
|
Object.defineProperty(exports, "DomCode", { enumerable: true, get: function () { return DomCode_1.DomCode; } });
|
|
42
|
-
untils_1.utils.printInfo('INDEX', `欢迎使用 swpp@${exports.swppVersion}`);
|
|
43
42
|
var ConfigCluster_1 = require("./swpp/config/ConfigCluster");
|
|
44
43
|
Object.defineProperty(exports, "defineIndivisibleConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineIndivisibleConfig; } });
|
|
45
44
|
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineConfig; } });
|
|
@@ -50,3 +49,4 @@ Object.defineProperty(exports, "defineCrossDep", { enumerable: true, get: functi
|
|
|
50
49
|
Object.defineProperty(exports, "defineRuntimeDep", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeDep; } });
|
|
51
50
|
Object.defineProperty(exports, "defineCrossEnv", { enumerable: true, get: function () { return ConfigCluster_1.defineCrossEnv; } });
|
|
52
51
|
Object.defineProperty(exports, "defineCompilationEnv", { enumerable: true, get: function () { return ConfigCluster_1.defineCompilationEnv; } });
|
|
52
|
+
Object.defineProperty(exports, "defineModifier", { enumerable: true, get: function () { return ConfigCluster_1.defineModifier; } });
|
|
@@ -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
|
}
|
package/dist/swpp/JsonBuilder.js
CHANGED
|
@@ -17,12 +17,12 @@ class JsonBuilder {
|
|
|
17
17
|
}
|
|
18
18
|
// noinspection JSUnusedGlobalSymbols
|
|
19
19
|
async buildJson() {
|
|
20
|
-
const json = await this.compilation.compilationEnv.read('
|
|
20
|
+
const json = await this.compilation.compilationEnv.read('SWPP_JSON_FILE').fetchVersionFile();
|
|
21
21
|
if (json.info.length == 0) {
|
|
22
22
|
json.info.push({ version: 1 });
|
|
23
23
|
return json;
|
|
24
24
|
}
|
|
25
|
-
const newChange = createUpdateChangeExps(this.urls, this.map.
|
|
25
|
+
const newChange = createUpdateChangeExps(this.urls, this.map.keys());
|
|
26
26
|
json.info.unshift({
|
|
27
27
|
version: json.info[0].version + 1,
|
|
28
28
|
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
|
/** 扫描网络文件 */
|
|
@@ -24,9 +25,14 @@ export declare class FileUpdateTracker {
|
|
|
24
25
|
protected allUrl: Set<string>;
|
|
25
26
|
constructor(compilation: CompilationData);
|
|
26
27
|
/** 更新一个文件的标识符 */
|
|
27
|
-
update(uri: string, value: string): void;
|
|
28
|
+
update(uri: string, value: string | Set<string> | string[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* 同步指定的稳定资源(同步时会连同同步其连接的稳定资源)
|
|
31
|
+
* @return 直接或间接连接的一些需要扫描的资源
|
|
32
|
+
*/
|
|
33
|
+
syncStable(uri: URL, value: string[], oldTracker: FileUpdateTracker): string[];
|
|
28
34
|
/** 读取一个文件的标识符 */
|
|
29
|
-
get(uri: string): string | undefined;
|
|
35
|
+
get(uri: string): string | string[] | undefined;
|
|
30
36
|
/** 设置一个 header */
|
|
31
37
|
putHeader(key: string, value: any): void;
|
|
32
38
|
/** 读取一个 header */
|
|
@@ -43,7 +49,7 @@ export declare class FileUpdateTracker {
|
|
|
43
49
|
* + 在新旧 tracker 中都存在且唯一标识符发生变化
|
|
44
50
|
* + 在新 tracker 中不存在且在旧 tracker 中存在
|
|
45
51
|
*/
|
|
46
|
-
diff(
|
|
52
|
+
diff(): Promise<JsonBuilder>;
|
|
47
53
|
/**
|
|
48
54
|
* 将数据序列化为 JSON
|
|
49
55
|
*
|
|
@@ -65,5 +71,5 @@ export declare class FileUpdateTracker {
|
|
|
65
71
|
/** 解序列化数据 */
|
|
66
72
|
static unJson(compilation: CompilationData, jsonStr: string): FileUpdateTracker;
|
|
67
73
|
/** 从网络拉取并解析 tracker */
|
|
68
|
-
static parserJsonFromNetwork(compilation: CompilationData
|
|
74
|
+
static parserJsonFromNetwork(compilation: CompilationData): Promise<FileUpdateTracker>;
|
|
69
75
|
}
|
|
@@ -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
|
});
|
|
@@ -136,11 +150,49 @@ class FileUpdateTracker {
|
|
|
136
150
|
}
|
|
137
151
|
/** 更新一个文件的标识符 */
|
|
138
152
|
update(uri, value) {
|
|
139
|
-
|
|
153
|
+
if (typeof value == 'string') {
|
|
154
|
+
if (value.startsWith('[')) {
|
|
155
|
+
throw new untils_1.RuntimeException(untils_1.exceptionNames.invalidValue, `插入数据("${value}")时,不应当以方括号开头`);
|
|
156
|
+
}
|
|
157
|
+
this.map.set(uri, value);
|
|
158
|
+
}
|
|
159
|
+
else if (Array.isArray(value)) {
|
|
160
|
+
this.map.set(uri, JSON.stringify(value));
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this.map.set(uri, JSON.stringify(Array.from(value)));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 同步指定的稳定资源(同步时会连同同步其连接的稳定资源)
|
|
168
|
+
* @return 直接或间接连接的一些需要扫描的资源
|
|
169
|
+
*/
|
|
170
|
+
syncStable(uri, value, oldTracker) {
|
|
171
|
+
const isStable = this.compilation.compilationEnv.read('isStable');
|
|
172
|
+
this.update(uri.href, value);
|
|
173
|
+
this.addUrl(uri.href);
|
|
174
|
+
const result = [];
|
|
175
|
+
for (let item of value) {
|
|
176
|
+
this.addUrl(item);
|
|
177
|
+
const itemUrl = new URL(item);
|
|
178
|
+
if (isStable(itemUrl)) {
|
|
179
|
+
const oldValue = oldTracker.get(item);
|
|
180
|
+
if (Array.isArray(oldValue)) {
|
|
181
|
+
const son = this.syncStable(itemUrl, oldValue, oldTracker);
|
|
182
|
+
result.push(...son);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
result.push(item);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
140
189
|
}
|
|
141
190
|
/** 读取一个文件的标识符 */
|
|
142
191
|
get(uri) {
|
|
143
|
-
|
|
192
|
+
const value = this.map.get(this.normalizeUri(uri).href);
|
|
193
|
+
if (!value)
|
|
194
|
+
return;
|
|
195
|
+
return value.startsWith('[') ? JSON.parse(value) : value;
|
|
144
196
|
}
|
|
145
197
|
/** 设置一个 header */
|
|
146
198
|
putHeader(key, value) {
|
|
@@ -154,8 +206,10 @@ class FileUpdateTracker {
|
|
|
154
206
|
normalizeUri(uri) {
|
|
155
207
|
if (uri.startsWith('http:'))
|
|
156
208
|
uri = `https:${uri.substring(5)}`;
|
|
157
|
-
const
|
|
158
|
-
|
|
209
|
+
const baseUrl = this.compilation.compilationEnv.read('DOMAIN_HOST');
|
|
210
|
+
const url = new URL(uri, baseUrl);
|
|
211
|
+
const normalizer = this.compilation.crossDep.read('normalizeUrl');
|
|
212
|
+
return new URL(normalizer.runOnNode(url.href));
|
|
159
213
|
}
|
|
160
214
|
/** 添加一个 URL */
|
|
161
215
|
addUrl(url) {
|
|
@@ -170,15 +224,17 @@ class FileUpdateTracker {
|
|
|
170
224
|
* + 在新旧 tracker 中都存在且唯一标识符发生变化
|
|
171
225
|
* + 在新 tracker 中不存在且在旧 tracker 中存在
|
|
172
226
|
*/
|
|
173
|
-
diff(
|
|
227
|
+
async diff() {
|
|
228
|
+
const baseUrl = this.compilation.compilationEnv.read('DOMAIN_HOST');
|
|
174
229
|
const diff = new JsonBuilder_1.JsonBuilder(this.compilation, this.allUrl);
|
|
230
|
+
const oldTracker = await this.compilation.compilationEnv.read('SWPP_JSON_FILE').fetchTrackerFile(this.compilation);
|
|
175
231
|
oldTracker.map.forEach((value, key) => {
|
|
176
232
|
if (this.map.has(key)) {
|
|
177
233
|
if (this.get(key) !== value)
|
|
178
|
-
diff.update(key, value);
|
|
234
|
+
diff.update(untils_1.utils.splicingUrl(baseUrl, key).href, value);
|
|
179
235
|
}
|
|
180
236
|
else {
|
|
181
|
-
diff.update(key, value);
|
|
237
|
+
diff.update(untils_1.utils.splicingUrl(baseUrl, key).href, value);
|
|
182
238
|
}
|
|
183
239
|
});
|
|
184
240
|
this.headers.forEach((value, key) => {
|
|
@@ -210,12 +266,16 @@ class FileUpdateTracker {
|
|
|
210
266
|
json() {
|
|
211
267
|
const result = {
|
|
212
268
|
version: 4,
|
|
213
|
-
tracker: {}
|
|
269
|
+
tracker: {},
|
|
270
|
+
headers: {}
|
|
214
271
|
};
|
|
215
272
|
this.map.forEach((value, key) => {
|
|
216
273
|
result.tracker[key] = value;
|
|
217
274
|
});
|
|
218
|
-
|
|
275
|
+
this.headers.forEach((value, key) => {
|
|
276
|
+
result.headers[key] = value;
|
|
277
|
+
});
|
|
278
|
+
return JSON.stringify(result);
|
|
219
279
|
}
|
|
220
280
|
/** 解序列化数据 */
|
|
221
281
|
static unJson(compilation, jsonStr) {
|
|
@@ -239,18 +299,18 @@ class FileUpdateTracker {
|
|
|
239
299
|
tracker.map.set(key, value.length === 32 ? value : '');
|
|
240
300
|
}
|
|
241
301
|
break;
|
|
242
|
-
default: throw {
|
|
243
|
-
code: untils_1.exceptionNames.unsupportedVersion,
|
|
244
|
-
message: `不支持 ${json.version}`,
|
|
245
|
-
};
|
|
302
|
+
default: throw new untils_1.RuntimeException(untils_1.exceptionNames.unsupportedVersion, `不支持 ${json.version}`);
|
|
246
303
|
}
|
|
247
304
|
return tracker;
|
|
248
305
|
}
|
|
249
306
|
// noinspection JSUnusedGlobalSymbols
|
|
250
307
|
/** 从网络拉取并解析 tracker */
|
|
251
|
-
static async parserJsonFromNetwork(compilation
|
|
252
|
-
const
|
|
253
|
-
const
|
|
308
|
+
static async parserJsonFromNetwork(compilation) {
|
|
309
|
+
const domain = compilation.compilationEnv.read('DOMAIN_HOST');
|
|
310
|
+
const jsonInfo = compilation.compilationEnv.read('SWPP_JSON_FILE');
|
|
311
|
+
const url = untils_1.utils.splicingUrl(domain, jsonInfo.swppPath, jsonInfo.trackerPath);
|
|
312
|
+
const fetcher = compilation.compilationEnv.read('NETWORK_FILE_FETCHER');
|
|
313
|
+
const isNotFound = compilation.compilationEnv.read('isNotFound');
|
|
254
314
|
const notFoundLevel = compilation.compilationEnv.read('ALLOW_NOT_FOUND');
|
|
255
315
|
let error;
|
|
256
316
|
const result = await (async () => {
|
|
@@ -258,10 +318,7 @@ class FileUpdateTracker {
|
|
|
258
318
|
const response = await fetcher.fetch(url);
|
|
259
319
|
if (isNotFound.response(response)) {
|
|
260
320
|
if (notFoundLevel == CompilationEnv_1.AllowNotFoundEnum.REJECT_ALL) {
|
|
261
|
-
error = {
|
|
262
|
-
code: untils_1.exceptionNames.notFound,
|
|
263
|
-
message: `拉取 ${url} 时出现 404 错误`
|
|
264
|
-
};
|
|
321
|
+
error = new untils_1.RuntimeException(untils_1.exceptionNames.notFound, `拉取 ${url} 时出现 404 错误`);
|
|
265
322
|
return;
|
|
266
323
|
}
|
|
267
324
|
untils_1.utils.printWarning('SCANNER', '拉取 tracker 时服务器返回了 404,如果是第一次携带 swpp v3 构建网站请忽视这条信息');
|
|
@@ -275,11 +332,7 @@ class FileUpdateTracker {
|
|
|
275
332
|
untils_1.utils.printWarning('SCANNER', '拉取 tracker 时 DNS 解析失败,如果是第一次携带 swpp v3 构建网站且网站暂时无法解析请忽视这条信息');
|
|
276
333
|
return new FileUpdateTracker(compilation);
|
|
277
334
|
}
|
|
278
|
-
untils_1.
|
|
279
|
-
throw {
|
|
280
|
-
code: untils_1.exceptionNames.error,
|
|
281
|
-
message: `拉取或解析历史 Tracker 时出现错误`
|
|
282
|
-
};
|
|
335
|
+
throw new untils_1.RuntimeException(untils_1.exceptionNames.error, `拉取或解析历史 Tracker 时出现错误`, { cause: e });
|
|
283
336
|
}
|
|
284
337
|
})();
|
|
285
338
|
if (result)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { CompilationEnv } from './database/CompilationEnv';
|
|
2
|
+
import { CompilationFileParser } from './database/CompilationFileParser';
|
|
2
3
|
import { CrossDepCode } from './database/CrossDepCode';
|
|
4
|
+
import { DomCode } from './database/DomCode';
|
|
3
5
|
import { RuntimeCoreCode } from './database/RuntimeCoreCode';
|
|
4
6
|
import { RuntimeDepCode } from './database/RuntimeDepCode';
|
|
5
7
|
import { CrossEnv } from './database/CrossEnv';
|
|
@@ -15,24 +17,28 @@ export declare class SwCompiler {
|
|
|
15
17
|
/** 运行时数据 */
|
|
16
18
|
export declare class RuntimeData {
|
|
17
19
|
/** 控制插入顺序 */
|
|
18
|
-
readonly insertOrder: (Exclude<keyof RuntimeData, 'insertOrder'> | string)[];
|
|
20
|
+
readonly insertOrder: (Exclude<keyof RuntimeData, 'insertOrder' | 'domConfig'> | string)[];
|
|
19
21
|
/** 运行时环境变量 */
|
|
20
|
-
|
|
22
|
+
crossEnv: CrossEnv;
|
|
21
23
|
/** 运行时工具函数 */
|
|
22
|
-
|
|
24
|
+
runtimeDep: RuntimeDepCode;
|
|
23
25
|
/** 运行时核心功能函数 */
|
|
24
|
-
|
|
26
|
+
runtimeCore: RuntimeCoreCode;
|
|
25
27
|
/** 运行时事件注册 */
|
|
26
|
-
|
|
28
|
+
runtimeEvent: RuntimeEventCode;
|
|
27
29
|
/** 运行时/编译时工具函数 */
|
|
28
|
-
|
|
30
|
+
crossDep: CrossDepCode;
|
|
31
|
+
/** DOM 相关设置 */
|
|
32
|
+
domConfig: DomCode;
|
|
33
|
+
constructor(compilationData: CompilationData);
|
|
29
34
|
getDatabase(key: string): RuntimeKeyValueDatabase<any, {}>;
|
|
30
35
|
}
|
|
31
36
|
/** 编译时数据 */
|
|
32
|
-
export
|
|
33
|
-
compilationEnv: CompilationEnv;
|
|
37
|
+
export declare class CompilationData {
|
|
34
38
|
crossEnv: CrossEnv;
|
|
35
39
|
crossDep: CrossDepCode;
|
|
40
|
+
compilationEnv: CompilationEnv;
|
|
41
|
+
fileParser: CompilationFileParser;
|
|
36
42
|
}
|
|
37
43
|
/** 版本号信息 */
|
|
38
44
|
export interface BrowserVersion {
|
package/dist/swpp/SwCompiler.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RuntimeData = exports.SwCompiler = void 0;
|
|
3
|
+
exports.CompilationData = exports.RuntimeData = exports.SwCompiler = void 0;
|
|
4
|
+
const CompilationEnv_1 = require("./database/CompilationEnv");
|
|
5
|
+
const CompilationFileParser_1 = require("./database/CompilationFileParser");
|
|
4
6
|
const CrossDepCode_1 = require("./database/CrossDepCode");
|
|
7
|
+
const DomCode_1 = require("./database/DomCode");
|
|
5
8
|
const RuntimeCoreCode_1 = require("./database/RuntimeCoreCode");
|
|
6
9
|
const RuntimeDepCode_1 = require("./database/RuntimeDepCode");
|
|
7
10
|
const CrossEnv_1 = require("./database/CrossEnv");
|
|
@@ -29,35 +32,38 @@ class SwCompiler {
|
|
|
29
32
|
exports.SwCompiler = SwCompiler;
|
|
30
33
|
/** 运行时数据 */
|
|
31
34
|
class RuntimeData {
|
|
32
|
-
constructor() {
|
|
35
|
+
constructor(compilationData) {
|
|
33
36
|
/** 控制插入顺序 */
|
|
34
37
|
this.insertOrder = [
|
|
35
38
|
'crossEnv', 'crossDep', 'runtimeDep', 'runtimeCore', 'runtimeEvent'
|
|
36
39
|
];
|
|
37
|
-
/** 运行时环境变量 */
|
|
38
|
-
this.crossEnv = new CrossEnv_1.CrossEnv();
|
|
39
40
|
/** 运行时工具函数 */
|
|
40
41
|
this.runtimeDep = new RuntimeDepCode_1.RuntimeDepCode();
|
|
41
42
|
/** 运行时核心功能函数 */
|
|
42
43
|
this.runtimeCore = new RuntimeCoreCode_1.RuntimeCoreCode();
|
|
43
44
|
/** 运行时事件注册 */
|
|
44
45
|
this.runtimeEvent = new RuntimeEventCode_1.RuntimeEventCode();
|
|
45
|
-
|
|
46
|
-
this.
|
|
46
|
+
this.crossDep = compilationData.crossDep;
|
|
47
|
+
this.crossEnv = compilationData.crossEnv;
|
|
48
|
+
this.domConfig = new DomCode_1.DomCode(compilationData);
|
|
47
49
|
}
|
|
48
50
|
getDatabase(key) {
|
|
49
51
|
if (!(key in this))
|
|
50
|
-
throw {
|
|
51
|
-
code: untils_1.exceptionNames.invalidKey,
|
|
52
|
-
message: `传入的 key [${key}] 不在当前对象中存在`
|
|
53
|
-
};
|
|
52
|
+
throw new untils_1.RuntimeException(untils_1.exceptionNames.invalidKey, `传入的 key [${key}] 不在当前对象中存在`);
|
|
54
53
|
if (key == 'insertOrder')
|
|
55
|
-
throw {
|
|
56
|
-
code: untils_1.exceptionNames.invalidKey,
|
|
57
|
-
message: `传入的 key [${key}] 非法`
|
|
58
|
-
};
|
|
54
|
+
throw new untils_1.RuntimeException(untils_1.exceptionNames.invalidKey, `传入的 key [${key}] 非法`);
|
|
59
55
|
// @ts-ignore
|
|
60
56
|
return this[key];
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
59
|
exports.RuntimeData = RuntimeData;
|
|
60
|
+
/** 编译时数据 */
|
|
61
|
+
class CompilationData {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.crossEnv = new CrossEnv_1.CrossEnv();
|
|
64
|
+
this.crossDep = new CrossDepCode_1.CrossDepCode();
|
|
65
|
+
this.compilationEnv = new CompilationEnv_1.CompilationEnv();
|
|
66
|
+
this.fileParser = new CompilationFileParser_1.CompilationFileParser(this);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.CompilationData = CompilationData;
|