swpp-backends 3.0.0-alpha.1 → 3.0.0-alpha.100
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/index.d.ts +19 -0
- package/dist/index.js +16 -11
- 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 +95 -30
- package/{types → dist}/swpp/SwCompiler.d.ts +12 -8
- package/dist/swpp/SwCompiler.js +16 -6
- package/{types/swpp/config/ConfigLoader.d.ts → dist/swpp/config/ConfigCluster.d.ts} +39 -30
- package/dist/swpp/config/ConfigCluster.js +86 -0
- package/dist/swpp/config/ConfigLoader.d.ts +56 -0
- package/dist/swpp/config/ConfigLoader.js +59 -102
- package/{types → dist}/swpp/database/CompilationEnv.d.ts +19 -6
- package/dist/swpp/database/CompilationEnv.js +74 -40
- package/{types → dist}/swpp/database/CrossDepCode.d.ts +7 -0
- package/dist/swpp/database/CrossDepCode.js +16 -0
- package/dist/swpp/database/DomCode.d.ts +32 -0
- package/dist/swpp/database/DomCode.js +114 -0
- package/{types → dist}/swpp/database/KeyValueDatabase.d.ts +21 -13
- package/dist/swpp/database/KeyValueDatabase.js +50 -17
- package/{types → dist}/swpp/database/RuntimeCoreCode.d.ts +5 -3
- package/dist/swpp/database/RuntimeCoreCode.js +6 -6
- package/{types → dist}/swpp/database/RuntimeDepCode.d.ts +1 -5
- package/dist/swpp/database/RuntimeDepCode.js +0 -11
- package/{types → dist}/swpp/database/RuntimeEventCode.d.ts +1 -1
- package/dist/swpp/database/RuntimeEventCode.js +20 -4
- package/{types → dist}/swpp/untils.d.ts +24 -11
- package/dist/swpp/untils.js +53 -30
- package/package.json +2 -2
- package/dist/resources/sw-dom.js +0 -45
- package/dist/resources/sw-fetch.js +0 -76
- 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/index.d.ts +0 -31
- package/types/swpp/RuntimeEnv.d.ts +0 -39
- package/types/swpp/SwCodeInject.d.ts +0 -17
- 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/RuntimeKeyValueDatabase.d.ts +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** 版本号 */
|
|
2
|
+
export declare const swppVersion: any;
|
|
3
|
+
export { utils, RuntimeException } from './swpp/untils';
|
|
4
|
+
export { ResourcesScanner, FileUpdateTracker, } from './swpp/ResourcesScanner';
|
|
5
|
+
export { JsonBuilder, UpdateJson, UpdateChangeExp, TrackerHeaderDiff } from './swpp/JsonBuilder';
|
|
6
|
+
export { FileParserRegistry, FileParser, FileMark } from './swpp/FileParser';
|
|
7
|
+
export { SwCompiler, CompilationData, RuntimeData, BrowserVersion } from './swpp/SwCompiler';
|
|
8
|
+
export { NetworkFileHandler, FiniteConcurrencyFetcher } from './swpp/NetworkFileHandler';
|
|
9
|
+
export { ConfigLoader } from './swpp/config/ConfigLoader';
|
|
10
|
+
export { KeyValueDatabase } from './swpp/database/KeyValueDatabase';
|
|
11
|
+
export { RuntimeKeyValueDatabase } from './swpp/database/RuntimeKeyValueDatabase';
|
|
12
|
+
export { RuntimeEventCode } from './swpp/database/RuntimeEventCode';
|
|
13
|
+
export { RuntimeCoreCode } from './swpp/database/RuntimeCoreCode';
|
|
14
|
+
export { RuntimeDepCode } from './swpp/database/RuntimeDepCode';
|
|
15
|
+
export { CrossEnv } from './swpp/database/CrossEnv';
|
|
16
|
+
export { CrossDepCode } from './swpp/database/CrossDepCode';
|
|
17
|
+
export { CompilationEnv, AllowNotFoundEnum } from './swpp/database/CompilationEnv';
|
|
18
|
+
export { DomCode } from './swpp/database/DomCode';
|
|
19
|
+
export { defineIndivisibleConfig, defineConfig, defineRuntimeEvent, defineDomConfig, defineRuntimeCore, defineCrossDep, defineRuntimeDep, defineCrossEnv, defineCompilationEnv } from './swpp/config/ConfigCluster';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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.CompilationData = exports.SwCompiler = exports.FileParserRegistry = exports.JsonBuilder = exports.FileUpdateTracker = exports.ResourcesScanner = exports.utils = exports.swppVersion = void 0;
|
|
4
4
|
const untils_1 = require("./swpp/untils");
|
|
5
5
|
/** 版本号 */
|
|
6
|
-
exports.
|
|
6
|
+
exports.swppVersion = require('../package.json').version;
|
|
7
7
|
var untils_2 = require("./swpp/untils");
|
|
8
8
|
Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return untils_2.utils; } });
|
|
9
9
|
var ResourcesScanner_1 = require("./swpp/ResourcesScanner");
|
|
@@ -15,19 +15,12 @@ var FileParser_1 = require("./swpp/FileParser");
|
|
|
15
15
|
Object.defineProperty(exports, "FileParserRegistry", { enumerable: true, get: function () { return FileParser_1.FileParserRegistry; } });
|
|
16
16
|
var SwCompiler_1 = require("./swpp/SwCompiler");
|
|
17
17
|
Object.defineProperty(exports, "SwCompiler", { enumerable: true, get: function () { return SwCompiler_1.SwCompiler; } });
|
|
18
|
+
Object.defineProperty(exports, "CompilationData", { enumerable: true, get: function () { return SwCompiler_1.CompilationData; } });
|
|
18
19
|
Object.defineProperty(exports, "RuntimeData", { enumerable: true, get: function () { return SwCompiler_1.RuntimeData; } });
|
|
19
20
|
var NetworkFileHandler_1 = require("./swpp/NetworkFileHandler");
|
|
20
21
|
Object.defineProperty(exports, "FiniteConcurrencyFetcher", { enumerable: true, get: function () { return NetworkFileHandler_1.FiniteConcurrencyFetcher; } });
|
|
21
22
|
var ConfigLoader_1 = require("./swpp/config/ConfigLoader");
|
|
22
23
|
Object.defineProperty(exports, "ConfigLoader", { enumerable: true, get: function () { return ConfigLoader_1.ConfigLoader; } });
|
|
23
|
-
Object.defineProperty(exports, "defineCompilationEnv", { enumerable: true, get: function () { return ConfigLoader_1.defineCompilationEnv; } });
|
|
24
|
-
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return ConfigLoader_1.defineConfig; } });
|
|
25
|
-
Object.defineProperty(exports, "defineCrossEnv", { enumerable: true, get: function () { return ConfigLoader_1.defineCrossEnv; } });
|
|
26
|
-
Object.defineProperty(exports, "defineCrossDep", { enumerable: true, get: function () { return ConfigLoader_1.defineCrossDep; } });
|
|
27
|
-
Object.defineProperty(exports, "defineRuntimeDep", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeDep; } });
|
|
28
|
-
Object.defineProperty(exports, "defineRuntimeCore", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeCore; } });
|
|
29
|
-
Object.defineProperty(exports, "defineRuntimeEvent", { enumerable: true, get: function () { return ConfigLoader_1.defineRuntimeEvent; } });
|
|
30
|
-
Object.defineProperty(exports, "defineIndivisibleConfig", { enumerable: true, get: function () { return ConfigLoader_1.defineIndivisibleConfig; } });
|
|
31
24
|
var KeyValueDatabase_1 = require("./swpp/database/KeyValueDatabase");
|
|
32
25
|
Object.defineProperty(exports, "KeyValueDatabase", { enumerable: true, get: function () { return KeyValueDatabase_1.KeyValueDatabase; } });
|
|
33
26
|
var RuntimeKeyValueDatabase_1 = require("./swpp/database/RuntimeKeyValueDatabase");
|
|
@@ -45,4 +38,16 @@ Object.defineProperty(exports, "CrossDepCode", { enumerable: true, get: function
|
|
|
45
38
|
var CompilationEnv_1 = require("./swpp/database/CompilationEnv");
|
|
46
39
|
Object.defineProperty(exports, "CompilationEnv", { enumerable: true, get: function () { return CompilationEnv_1.CompilationEnv; } });
|
|
47
40
|
Object.defineProperty(exports, "AllowNotFoundEnum", { enumerable: true, get: function () { return CompilationEnv_1.AllowNotFoundEnum; } });
|
|
48
|
-
|
|
41
|
+
var DomCode_1 = require("./swpp/database/DomCode");
|
|
42
|
+
Object.defineProperty(exports, "DomCode", { enumerable: true, get: function () { return DomCode_1.DomCode; } });
|
|
43
|
+
untils_1.utils.printInfo('INDEX', `欢迎使用 swpp@${exports.swppVersion}`);
|
|
44
|
+
var ConfigCluster_1 = require("./swpp/config/ConfigCluster");
|
|
45
|
+
Object.defineProperty(exports, "defineIndivisibleConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineIndivisibleConfig; } });
|
|
46
|
+
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineConfig; } });
|
|
47
|
+
Object.defineProperty(exports, "defineRuntimeEvent", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeEvent; } });
|
|
48
|
+
Object.defineProperty(exports, "defineDomConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineDomConfig; } });
|
|
49
|
+
Object.defineProperty(exports, "defineRuntimeCore", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeCore; } });
|
|
50
|
+
Object.defineProperty(exports, "defineCrossDep", { enumerable: true, get: function () { return ConfigCluster_1.defineCrossDep; } });
|
|
51
|
+
Object.defineProperty(exports, "defineRuntimeDep", { enumerable: true, get: function () { return ConfigCluster_1.defineRuntimeDep; } });
|
|
52
|
+
Object.defineProperty(exports, "defineCrossEnv", { enumerable: true, get: function () { return ConfigCluster_1.defineCrossEnv; } });
|
|
53
|
+
Object.defineProperty(exports, "defineCompilationEnv", { enumerable: true, get: function () { return ConfigCluster_1.defineCompilationEnv; } });
|
|
@@ -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
48
|
const register = this.compilation.compilationEnv.read('FILE_PARSER');
|
|
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;
|
|
@@ -75,6 +78,7 @@ class ResourcesScanner {
|
|
|
75
78
|
async scanNetworkFile(tracker, urls, record = new Set()) {
|
|
76
79
|
const matchCacheRule = this.compilation.crossDep.read('matchCacheRule');
|
|
77
80
|
const registry = this.compilation.compilationEnv.read('FILE_PARSER');
|
|
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,51 @@ class FileUpdateTracker {
|
|
|
136
150
|
}
|
|
137
151
|
/** 更新一个文件的标识符 */
|
|
138
152
|
update(uri, value) {
|
|
139
|
-
|
|
153
|
+
if (typeof value == 'string') {
|
|
154
|
+
if (value.startsWith('['))
|
|
155
|
+
throw {
|
|
156
|
+
code: untils_1.exceptionNames.invalidValue,
|
|
157
|
+
message: `插入数据("${value}")时,不应当以方括号开头`
|
|
158
|
+
};
|
|
159
|
+
this.map.set(uri, value);
|
|
160
|
+
}
|
|
161
|
+
else if (Array.isArray(value)) {
|
|
162
|
+
this.map.set(uri, JSON.stringify(value));
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
this.map.set(uri, JSON.stringify(Array.from(value)));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 同步指定的稳定资源(同步时会连同同步其连接的稳定资源)
|
|
170
|
+
* @return 直接或间接连接的一些需要扫描的资源
|
|
171
|
+
*/
|
|
172
|
+
syncStable(uri, value, oldTracker) {
|
|
173
|
+
const isStable = this.compilation.compilationEnv.read('isStable');
|
|
174
|
+
this.update(uri.href, value);
|
|
175
|
+
this.addUrl(uri.href);
|
|
176
|
+
const result = [];
|
|
177
|
+
for (let item of value) {
|
|
178
|
+
this.addUrl(item);
|
|
179
|
+
const itemUrl = new URL(item);
|
|
180
|
+
if (isStable(itemUrl)) {
|
|
181
|
+
const oldValue = oldTracker.get(item);
|
|
182
|
+
if (Array.isArray(oldValue)) {
|
|
183
|
+
const son = this.syncStable(itemUrl, oldValue, oldTracker);
|
|
184
|
+
result.push(...son);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
result.push(item);
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
140
191
|
}
|
|
141
192
|
/** 读取一个文件的标识符 */
|
|
142
193
|
get(uri) {
|
|
143
|
-
|
|
194
|
+
const value = this.map.get(this.normalizeUri(uri).href);
|
|
195
|
+
if (!value)
|
|
196
|
+
return;
|
|
197
|
+
return value.startsWith('[') ? JSON.parse(value) : value;
|
|
144
198
|
}
|
|
145
199
|
/** 设置一个 header */
|
|
146
200
|
putHeader(key, value) {
|
|
@@ -155,7 +209,9 @@ class FileUpdateTracker {
|
|
|
155
209
|
if (uri.startsWith('http:'))
|
|
156
210
|
uri = `https:${uri.substring(5)}`;
|
|
157
211
|
const domain = this.compilation.compilationEnv.read('DOMAIN_HOST');
|
|
158
|
-
|
|
212
|
+
const url = new URL(uri, `https://${domain}`);
|
|
213
|
+
const normalizer = this.compilation.crossDep.read('normalizeUrl');
|
|
214
|
+
return new URL(normalizer.runOnNode(url.href));
|
|
159
215
|
}
|
|
160
216
|
/** 添加一个 URL */
|
|
161
217
|
addUrl(url) {
|
|
@@ -170,15 +226,17 @@ class FileUpdateTracker {
|
|
|
170
226
|
* + 在新旧 tracker 中都存在且唯一标识符发生变化
|
|
171
227
|
* + 在新 tracker 中不存在且在旧 tracker 中存在
|
|
172
228
|
*/
|
|
173
|
-
diff(
|
|
229
|
+
async diff() {
|
|
230
|
+
const host = this.compilation.compilationEnv.read('DOMAIN_HOST');
|
|
174
231
|
const diff = new JsonBuilder_1.JsonBuilder(this.compilation, this.allUrl);
|
|
232
|
+
const oldTracker = await this.compilation.compilationEnv.read('SWPP_JSON_FILE').fetchTrackerFile(this.compilation);
|
|
175
233
|
oldTracker.map.forEach((value, key) => {
|
|
176
234
|
if (this.map.has(key)) {
|
|
177
235
|
if (this.get(key) !== value)
|
|
178
|
-
diff.update(key, value);
|
|
236
|
+
diff.update(untils_1.utils.splicingUrl(host, key).href, value);
|
|
179
237
|
}
|
|
180
238
|
else {
|
|
181
|
-
diff.update(key, value);
|
|
239
|
+
diff.update(untils_1.utils.splicingUrl(host, key).href, value);
|
|
182
240
|
}
|
|
183
241
|
});
|
|
184
242
|
this.headers.forEach((value, key) => {
|
|
@@ -210,12 +268,16 @@ class FileUpdateTracker {
|
|
|
210
268
|
json() {
|
|
211
269
|
const result = {
|
|
212
270
|
version: 4,
|
|
213
|
-
tracker: {}
|
|
271
|
+
tracker: {},
|
|
272
|
+
headers: {}
|
|
214
273
|
};
|
|
215
274
|
this.map.forEach((value, key) => {
|
|
216
275
|
result.tracker[key] = value;
|
|
217
276
|
});
|
|
218
|
-
|
|
277
|
+
this.headers.forEach((value, key) => {
|
|
278
|
+
result.headers[key] = value;
|
|
279
|
+
});
|
|
280
|
+
return JSON.stringify(result);
|
|
219
281
|
}
|
|
220
282
|
/** 解序列化数据 */
|
|
221
283
|
static unJson(compilation, jsonStr) {
|
|
@@ -248,9 +310,12 @@ class FileUpdateTracker {
|
|
|
248
310
|
}
|
|
249
311
|
// noinspection JSUnusedGlobalSymbols
|
|
250
312
|
/** 从网络拉取并解析 tracker */
|
|
251
|
-
static async parserJsonFromNetwork(compilation
|
|
252
|
-
const
|
|
253
|
-
const
|
|
313
|
+
static async parserJsonFromNetwork(compilation) {
|
|
314
|
+
const domain = compilation.compilationEnv.read('DOMAIN_HOST');
|
|
315
|
+
const jsonInfo = compilation.compilationEnv.read('SWPP_JSON_FILE');
|
|
316
|
+
const url = untils_1.utils.splicingUrl(domain, jsonInfo.swppPath, jsonInfo.trackerPath);
|
|
317
|
+
const fetcher = compilation.compilationEnv.read('NETWORK_FILE_FETCHER');
|
|
318
|
+
const isNotFound = compilation.compilationEnv.read('isNotFound');
|
|
254
319
|
const notFoundLevel = compilation.compilationEnv.read('ALLOW_NOT_FOUND');
|
|
255
320
|
let error;
|
|
256
321
|
const result = await (async () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CompilationEnv } from './database/CompilationEnv';
|
|
2
2
|
import { CrossDepCode } from './database/CrossDepCode';
|
|
3
|
+
import { DomCode } from './database/DomCode';
|
|
3
4
|
import { RuntimeCoreCode } from './database/RuntimeCoreCode';
|
|
4
5
|
import { RuntimeDepCode } from './database/RuntimeDepCode';
|
|
5
6
|
import { CrossEnv } from './database/CrossEnv';
|
|
@@ -15,24 +16,27 @@ export declare class SwCompiler {
|
|
|
15
16
|
/** 运行时数据 */
|
|
16
17
|
export declare class RuntimeData {
|
|
17
18
|
/** 控制插入顺序 */
|
|
18
|
-
readonly insertOrder: (Exclude<keyof RuntimeData, 'insertOrder'> | string)[];
|
|
19
|
+
readonly insertOrder: (Exclude<keyof RuntimeData, 'insertOrder' | 'domConfig'> | string)[];
|
|
19
20
|
/** 运行时环境变量 */
|
|
20
|
-
|
|
21
|
+
crossEnv: CrossEnv;
|
|
21
22
|
/** 运行时工具函数 */
|
|
22
|
-
|
|
23
|
+
runtimeDep: RuntimeDepCode;
|
|
23
24
|
/** 运行时核心功能函数 */
|
|
24
|
-
|
|
25
|
+
runtimeCore: RuntimeCoreCode;
|
|
25
26
|
/** 运行时事件注册 */
|
|
26
|
-
|
|
27
|
+
runtimeEvent: RuntimeEventCode;
|
|
27
28
|
/** 运行时/编译时工具函数 */
|
|
28
|
-
|
|
29
|
+
crossDep: CrossDepCode;
|
|
30
|
+
/** DOM 相关设置 */
|
|
31
|
+
domConfig: DomCode;
|
|
32
|
+
constructor(compilationData: CompilationData);
|
|
29
33
|
getDatabase(key: string): RuntimeKeyValueDatabase<any, {}>;
|
|
30
34
|
}
|
|
31
35
|
/** 编译时数据 */
|
|
32
|
-
export
|
|
33
|
-
compilationEnv: CompilationEnv;
|
|
36
|
+
export declare class CompilationData {
|
|
34
37
|
crossEnv: CrossEnv;
|
|
35
38
|
crossDep: CrossDepCode;
|
|
39
|
+
compilationEnv: CompilationEnv;
|
|
36
40
|
}
|
|
37
41
|
/** 版本号信息 */
|
|
38
42
|
export interface BrowserVersion {
|
package/dist/swpp/SwCompiler.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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");
|
|
4
5
|
const CrossDepCode_1 = require("./database/CrossDepCode");
|
|
6
|
+
const DomCode_1 = require("./database/DomCode");
|
|
5
7
|
const RuntimeCoreCode_1 = require("./database/RuntimeCoreCode");
|
|
6
8
|
const RuntimeDepCode_1 = require("./database/RuntimeDepCode");
|
|
7
9
|
const CrossEnv_1 = require("./database/CrossEnv");
|
|
@@ -29,21 +31,20 @@ class SwCompiler {
|
|
|
29
31
|
exports.SwCompiler = SwCompiler;
|
|
30
32
|
/** 运行时数据 */
|
|
31
33
|
class RuntimeData {
|
|
32
|
-
constructor() {
|
|
34
|
+
constructor(compilationData) {
|
|
33
35
|
/** 控制插入顺序 */
|
|
34
36
|
this.insertOrder = [
|
|
35
37
|
'crossEnv', 'crossDep', 'runtimeDep', 'runtimeCore', 'runtimeEvent'
|
|
36
38
|
];
|
|
37
|
-
/** 运行时环境变量 */
|
|
38
|
-
this.crossEnv = new CrossEnv_1.CrossEnv();
|
|
39
39
|
/** 运行时工具函数 */
|
|
40
40
|
this.runtimeDep = new RuntimeDepCode_1.RuntimeDepCode();
|
|
41
41
|
/** 运行时核心功能函数 */
|
|
42
42
|
this.runtimeCore = new RuntimeCoreCode_1.RuntimeCoreCode();
|
|
43
43
|
/** 运行时事件注册 */
|
|
44
44
|
this.runtimeEvent = new RuntimeEventCode_1.RuntimeEventCode();
|
|
45
|
-
|
|
46
|
-
this.
|
|
45
|
+
this.crossDep = compilationData.crossDep;
|
|
46
|
+
this.crossEnv = compilationData.crossEnv;
|
|
47
|
+
this.domConfig = new DomCode_1.DomCode(compilationData);
|
|
47
48
|
}
|
|
48
49
|
getDatabase(key) {
|
|
49
50
|
if (!(key in this))
|
|
@@ -61,3 +62,12 @@ class RuntimeData {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
exports.RuntimeData = RuntimeData;
|
|
65
|
+
/** 编译时数据 */
|
|
66
|
+
class CompilationData {
|
|
67
|
+
constructor() {
|
|
68
|
+
this.crossEnv = new CrossEnv_1.CrossEnv();
|
|
69
|
+
this.crossDep = new CrossDepCode_1.CrossDepCode();
|
|
70
|
+
this.compilationEnv = new CompilationEnv_1.CompilationEnv(this.crossEnv, this.crossDep);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.CompilationData = CompilationData;
|