swpp-backends 3.0.0-alpha.4 → 3.0.0-alpha.401
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/cli-index.d.ts +1 -0
- package/dist/cli-index.js +8 -0
- package/{types → dist}/index.d.ts +6 -5
- package/dist/index.js +26 -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 +18 -14
- package/dist/swpp/ResourcesScanner.js +100 -73
- package/{types → dist}/swpp/SwCompiler.d.ts +21 -8
- package/dist/swpp/SwCompiler.js +51 -15
- package/dist/swpp/cli.d.ts +11 -0
- package/dist/swpp/cli.js +113 -0
- package/{types → dist}/swpp/config/ConfigCluster.d.ts +105 -63
- package/dist/swpp/config/ConfigCluster.js +67 -48
- package/dist/swpp/config/ConfigLoader.d.ts +79 -0
- package/dist/swpp/config/ConfigLoader.js +192 -87
- package/dist/swpp/config/SpecialConfig.d.ts +38 -0
- package/dist/swpp/config/SpecialConfig.js +70 -0
- package/{types → dist}/swpp/database/CompilationEnv.d.ts +16 -14
- package/dist/swpp/database/CompilationEnv.js +41 -211
- package/dist/swpp/database/CompilationFileParser.d.ts +81 -0
- package/dist/swpp/database/CompilationFileParser.js +269 -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 +120 -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 +14 -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 +30 -18
- package/dist/swpp/untils.js +74 -53
- package/dist/test.js +1 -0
- package/package.json +8 -5
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cli_1 = require("./swpp/cli");
|
|
4
|
+
const untils_1 = require("./swpp/untils");
|
|
5
|
+
(0, cli_1.initCommand)().catch(e => {
|
|
6
|
+
untils_1.utils.printError('COMMAND', '执行指令时出现异常');
|
|
7
|
+
throw e;
|
|
8
|
+
});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/** 版本号 */
|
|
2
|
-
export declare const swppVersion:
|
|
2
|
+
export declare const swppVersion: string;
|
|
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 { defineIndivisibleConfig, defineContextConfig, defineNoCacheConfig, 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.defineNoCacheConfig = exports.defineContextConfig = exports.defineIndivisibleConfig = 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,24 @@ 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");
|
|
44
58
|
Object.defineProperty(exports, "defineIndivisibleConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineIndivisibleConfig; } });
|
|
45
|
-
Object.defineProperty(exports, "
|
|
46
|
-
Object.defineProperty(exports, "
|
|
47
|
-
Object.defineProperty(exports, "
|
|
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; } });
|
|
59
|
+
Object.defineProperty(exports, "defineContextConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineContextConfig; } });
|
|
60
|
+
Object.defineProperty(exports, "defineNoCacheConfig", { enumerable: true, get: function () { return ConfigCluster_1.defineNoCacheConfig; } });
|
|
61
|
+
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('SWPP_JSON_FILE').
|
|
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,32 +5,39 @@ 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
|
/** 扫描网络文件 */
|
|
12
13
|
private scanNetworkFile;
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* 遍历目录下的所有文件
|
|
17
|
+
* @param dir
|
|
18
|
+
* @param callback
|
|
19
|
+
*/
|
|
20
|
+
export declare function traverseDirectory(dir: string, callback: (file: string) => Promise<any> | any): Promise<void>;
|
|
14
21
|
/**
|
|
15
22
|
* 文件更新监听器
|
|
16
23
|
*/
|
|
17
24
|
export declare class FileUpdateTracker {
|
|
18
25
|
protected compilation: CompilationData;
|
|
19
|
-
|
|
20
|
-
protected headers: Map<string, any>;
|
|
26
|
+
private oldTracker?;
|
|
21
27
|
/** 存储列表,key 为文件路径,value 为文件的唯一标识符 */
|
|
22
28
|
protected map: Map<string, string>;
|
|
23
29
|
/** 存储所有存在的 URL */
|
|
24
30
|
protected allUrl: Set<string>;
|
|
25
|
-
constructor(compilation: CompilationData);
|
|
31
|
+
constructor(compilation: CompilationData, oldTracker?: FileUpdateTracker | undefined);
|
|
26
32
|
/** 更新一个文件的标识符 */
|
|
27
|
-
update(uri: string, value: string): void;
|
|
33
|
+
update(uri: string, value: string | Set<string> | string[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* 同步指定的稳定资源(同步时会连同同步其连接的稳定资源)
|
|
36
|
+
* @return 直接或间接连接的一些需要扫描的资源
|
|
37
|
+
*/
|
|
38
|
+
syncStable(uri: URL, value: string[], oldTracker: FileUpdateTracker): string[];
|
|
28
39
|
/** 读取一个文件的标识符 */
|
|
29
|
-
get(uri: string): string | undefined;
|
|
30
|
-
/** 设置一个 header */
|
|
31
|
-
putHeader(key: string, value: any): void;
|
|
32
|
-
/** 读取一个 header */
|
|
33
|
-
getHeader(key: string): any | undefined;
|
|
40
|
+
get(uri: string): string | string[] | undefined;
|
|
34
41
|
/** 归一化 uri */
|
|
35
42
|
normalizeUri(uri: string): URL;
|
|
36
43
|
/** 添加一个 URL */
|
|
@@ -43,7 +50,7 @@ export declare class FileUpdateTracker {
|
|
|
43
50
|
* + 在新旧 tracker 中都存在且唯一标识符发生变化
|
|
44
51
|
* + 在新 tracker 中不存在且在旧 tracker 中存在
|
|
45
52
|
*/
|
|
46
|
-
diff(
|
|
53
|
+
diff(): Promise<JsonBuilder>;
|
|
47
54
|
/**
|
|
48
55
|
* 将数据序列化为 JSON
|
|
49
56
|
*
|
|
@@ -52,9 +59,6 @@ export declare class FileUpdateTracker {
|
|
|
52
59
|
* ```json
|
|
53
60
|
* {
|
|
54
61
|
* "version": 4,
|
|
55
|
-
* "headers": {
|
|
56
|
-
* [key: string]: any
|
|
57
|
-
* },
|
|
58
62
|
* "tracker" {
|
|
59
63
|
* [uri: string]: string
|
|
60
64
|
* }
|