swpp-backends 0.0.1-alpha

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/utils.js ADDED
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.replaceDevRequest = exports.fetchFile = exports.getSource = exports.readEjectData = exports.calcEjectValues = exports.warn = exports.error = void 0;
7
+ const node_fetch_1 = __importDefault(require("node-fetch"));
8
+ const SwppRules_1 = require("./SwppRules");
9
+ const logger = require('hexo-log').default({
10
+ debug: false,
11
+ silent: false
12
+ });
13
+ function error(type, message) {
14
+ logger.error(`[SWPP ${type}] ${message}`);
15
+ }
16
+ exports.error = error;
17
+ function warn(type, message) {
18
+ logger.warn(`[SWPP ${type}] ${message}`);
19
+ }
20
+ exports.warn = warn;
21
+ let ejectData = undefined;
22
+ /**
23
+ * 获取 eject values
24
+ *
25
+ * + **执行该函数前必须调用过 [loadRules]**
26
+ *
27
+ * @param framework 框架对象
28
+ */
29
+ function calcEjectValues(framework) {
30
+ const rules = (0, SwppRules_1.readRules)();
31
+ if (!('ejectValues' in rules))
32
+ return;
33
+ // noinspection JSUnresolvedReference
34
+ const eject = rules.ejectValues?.(framework, rules);
35
+ const nodeEject = {};
36
+ let ejectStr = '';
37
+ for (let key in eject) {
38
+ if (!key.match(/^[A-Za-z0-9]+$/)) {
39
+ logger.error(`[SWPP EjectValues] 变量名 [${key}] 仅允许包含英文字母和阿拉伯数字!`);
40
+ throw '变量名违规:' + key;
41
+ }
42
+ const data = eject[key];
43
+ const str = getSource(data.value, name => {
44
+ if (['string', 'number', 'boolean', 'object', 'array', 'bigint'].includes(name))
45
+ return true;
46
+ logger.error(`[SWPP EjectValue] 不支持导出 ${name} 类型的数据`);
47
+ throw `不支持的键值:key=${key}, value type=${name}`;
48
+ });
49
+ ejectStr += ` ${data.prefix} ${key} = ${str}\n`;
50
+ nodeEject[key] = data.value;
51
+ }
52
+ ejectData = {
53
+ strValue: ejectStr,
54
+ nodeEject
55
+ };
56
+ }
57
+ exports.calcEjectValues = calcEjectValues;
58
+ /**
59
+ * 读取最近的已计算的 eject 数据
60
+ *
61
+ * + **执行该函数前必须调用过 [loadRules]**
62
+ * + **执行该函数前必须调用过 [calcEjectValues]**
63
+ */
64
+ function readEjectData() {
65
+ if (!ejectData)
66
+ throw 'eject data 尚未初始化';
67
+ return ejectData;
68
+ }
69
+ exports.readEjectData = readEjectData;
70
+ /**
71
+ * 获取指定值的 js 源码表达形式
72
+ * @param obj 要转换的对象
73
+ * @param typeChecker 类型检查器,用于筛除不希望映射的类型
74
+ * @param whiteList 白名单,当 obj 为 Object 时将只转换在白名单中的值(不会传递)
75
+ * @param isTop 是否为顶层元素,为 true 且 obj 为 Object 时将去除最外层的大括号,改为 let(不会传递)
76
+ */
77
+ function getSource(obj, typeChecker = undefined, whiteList = undefined, isTop = false) {
78
+ const type = typeof obj;
79
+ if (typeChecker) {
80
+ let value;
81
+ if (type === 'object') {
82
+ value = Array.isArray(obj) ? 'array' : type;
83
+ }
84
+ else
85
+ value = type;
86
+ if (!typeChecker(value))
87
+ return '';
88
+ }
89
+ switch (type) {
90
+ case "undefined": return 'undefined';
91
+ case "object":
92
+ if (Array.isArray(obj)) {
93
+ return '[' + obj.map(it => getSource(it)).join(', ') + ']';
94
+ }
95
+ else {
96
+ let result = isTop ? '' : '{\n';
97
+ result += Object.getOwnPropertyNames(obj)
98
+ .filter(key => !whiteList || whiteList.includes(key))
99
+ .map(key => {
100
+ const value = obj[key];
101
+ let str = getSource(value, typeChecker);
102
+ if (str.length === 0)
103
+ return '';
104
+ if (isTop && whiteList && ['cacheList', 'modifyRequest'].includes(key)) {
105
+ str = str
106
+ .replace(/\(\s*(.*?)\s*,\s*\$eject\s*\)/g, "$1") // 去掉箭头函数参数表中的 $eject
107
+ .replaceAll(/\$eject\.(\w+)/g, (_, match) => `eject${match[0].toUpperCase()}${match.substring(1)}`); // 将函数体中的 $eject.xxx 替换为 ejectXxx
108
+ }
109
+ return isTop ? `let ${key} = ${str}` : `${key}: ${str}`;
110
+ })
111
+ .filter(it => it.length !== 0)
112
+ .join(isTop ? '\n' : ',\n');
113
+ result += isTop ? '' : '}\n';
114
+ return result;
115
+ }
116
+ case "string":
117
+ if (!obj.includes("'"))
118
+ return `'${obj}'`;
119
+ else if (!obj.includes('"'))
120
+ return `"${obj}"`;
121
+ else if (!obj.includes('`'))
122
+ return `\`${obj}\``;
123
+ else
124
+ return `'${obj.replaceAll("'", "\\'")}'`;
125
+ case "bigint": return `${obj.toString()}n`;
126
+ default: return obj.toString();
127
+ case "symbol":
128
+ logger.error("[SWPP ServiceWorkerBuilder] 不支持写入 symbol 类型,请从 sw-rules.js 中移除相关内容!");
129
+ throw '不支持写入 symbol 类型';
130
+ }
131
+ }
132
+ exports.getSource = getSource;
133
+ /**
134
+ * 拉取文件
135
+ *
136
+ * **调用该函数前必须调用过 [loadRules]**
137
+ */
138
+ async function fetchFile(link) {
139
+ const config = (0, SwppRules_1.readRules)().config;
140
+ const url = replaceDevRequest(link);
141
+ const opts = {
142
+ headers: {
143
+ referer: 'kmar-swpp',
144
+ 'User-Agent': 'kmar-swpp'
145
+ },
146
+ timeout: config.external.timeout
147
+ };
148
+ try {
149
+ if (typeof url === 'string') {
150
+ return await (0, node_fetch_1.default)(url, opts);
151
+ }
152
+ else {
153
+ return await fetchSpeed(url);
154
+ }
155
+ }
156
+ catch (err) {
157
+ // @ts-ignore
158
+ if (err.type === 'request-timeout') {
159
+ logger.error(`[SWPP FetchFile] 拉取文件 [${link}] 时出现了超时错误,如果您构建所在的位置无法访问该资源,` +
160
+ "请尝试通过 DevReplace(https://kmar.top/posts/73014407/#4ea71e00)功能解决该问题。");
161
+ throw 'timeout';
162
+ }
163
+ throw err;
164
+ }
165
+ }
166
+ exports.fetchFile = fetchFile;
167
+ /**
168
+ * 替换编译期的 URL(CDN 竞速)
169
+ *
170
+ * **调用该函数前必须调用过 [loadRules]**
171
+ */
172
+ function replaceDevRequest(link) {
173
+ const config = (0, SwppRules_1.readRules)().config;
174
+ return config.external?.replacer(link) ?? link;
175
+ }
176
+ exports.replaceDevRequest = replaceDevRequest;
177
+ /** 通过 CDN 竞速的方式拉取文件 */
178
+ async function fetchSpeed(list) {
179
+ const controllers = new Array(list.length);
180
+ const result = await Promise.any(list.map((it, index) => (0, node_fetch_1.default)(it, {
181
+ signal: (controllers[index] = new AbortController()).signal
182
+ }).then(response => [200, 301, 302, 307, 308].includes(response.status) ? { index, response } : Promise.reject())));
183
+ for (let i = 0; i < controllers.length; i++) {
184
+ if (i !== result.index)
185
+ controllers[i].abort();
186
+ }
187
+ return result.response;
188
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "swpp-backends",
3
+ "version": "0.0.1-alpha",
4
+ "main": "dist/index.js",
5
+ "typings": "types/index.d.ts",
6
+ "description": "Generate a powerful ServiceWorker for your website.",
7
+ "author": "kmar",
8
+ "license": "AGPL-3.0",
9
+ "files": [
10
+ "dist",
11
+ "types"
12
+ ],
13
+ "devDependencies": {
14
+ "@types/css": "^0.0.33",
15
+ "@types/fast-html-parser": "^1.0.2",
16
+ "@types/node": "^20.4.5",
17
+ "gulp": "^4.0.2",
18
+ "typescript": "^5.1.6"
19
+ },
20
+ "dependencies": {
21
+ "@types/node-fetch": "^2.6.4",
22
+ "css": "^3.0.0",
23
+ "fast-html-parser": "^1.0.1",
24
+ "hexo-log": "^4.1.0",
25
+ "node-fetch": "^2.6.12"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+ssh://git@github.com/EmptyDreams/swpp-backends.git"
30
+ },
31
+ "homepage": "https://github.com/EmptyDreams/swpp-backends",
32
+ "keywords": [
33
+ "ServiceWorker",
34
+ "sw"
35
+ ],
36
+ "scripts": {}
37
+ }
@@ -0,0 +1,125 @@
1
+ /** Service Worker Plus Plus 的配置项 */
2
+ export interface SwppConfig {
3
+ serviceWorker?: ServiceWorkerConfig;
4
+ register?: RegisterConfig;
5
+ dom?: DomConfig;
6
+ json?: VersionJsonConfig;
7
+ external?: ExternalMonitorConfig;
8
+ }
9
+ /** 与 ServiceWorker 有关的配置 */
10
+ export interface ServiceWorkerConfig {
11
+ /** 逃生门 */
12
+ escape: number;
13
+ /** 缓存库名称 */
14
+ cacheName: string;
15
+ /** 是否启用调试 */
16
+ debug: boolean;
17
+ }
18
+ /** 与 ServiceWorker 注册有关的配置 */
19
+ export interface RegisterConfig {
20
+ /** 注册成功后执行的代码 */
21
+ onsuccess?: VoidFunction;
22
+ /** 注册失败后执行的代码 */
23
+ onerror: VoidFunction;
24
+ /**
25
+ * 生成注册 ServiceWorker 的 HTML 代码片段
26
+ * @param root 网页根目录的 URL
27
+ * @param framework 框架对象
28
+ * @param pluginConfig swpp 插件配置项
29
+ */
30
+ builder: (root: string, framework: any, pluginConfig: SwppConfig) => string;
31
+ }
32
+ /** 与 DOM 端有关的配置 */
33
+ export interface DomConfig {
34
+ /** 缓存更新成功后触发的操作 */
35
+ onsuccess: VoidFunction;
36
+ }
37
+ /** 与版本文件相关的配置项 */
38
+ export interface VersionJsonConfig {
39
+ /** 更新缓存时允许更新的最大 HTML 数量 */
40
+ maxHtml: number;
41
+ /** update.json 文件的字符数量限制 */
42
+ charLimit: number;
43
+ /** 是否合并指定项目 */
44
+ merge: string[];
45
+ /** 生成 cacheList.json 时忽略的文件 */
46
+ exclude: {
47
+ localhost: RegExp[];
48
+ other: RegExp[];
49
+ };
50
+ }
51
+ /** 外部文件更新监听 */
52
+ export interface ExternalMonitorConfig {
53
+ /** 拉取网络文件的超时时间 */
54
+ timeout: number;
55
+ /** 匹配 JS 代码中的 URL */
56
+ js: ({
57
+ head: string;
58
+ tail: string;
59
+ } | ((jsCode: string) => string[]))[];
60
+ /** 链接不变内容就不变的 URL */
61
+ stable: RegExp[];
62
+ /** 构建过程中将原始 URL 映射为新的 URL */
63
+ replacer: (srcUrl: string) => string[] | string;
64
+ }
65
+ /** Service Worker Plus Plus 的配置项模板 */
66
+ export interface SwppConfigTemplate {
67
+ /** 有关 ServiceWorker 的配置 */
68
+ serviceWorker?: boolean | {
69
+ /** 逃生门 */
70
+ escape?: number;
71
+ /** 缓存库名称 */
72
+ cacheName?: string;
73
+ /** 是否启用调试 */
74
+ debug?: boolean;
75
+ };
76
+ /** 与 ServiceWorker 注册有关的配置 */
77
+ register: boolean | {
78
+ /** 注册成功后执行的代码 */
79
+ onsuccess?: VoidFunction;
80
+ /** 注册失败后执行的代码 */
81
+ onerror?: VoidFunction;
82
+ /**
83
+ * 生成注册 ServiceWorker 的 HTML 代码片段
84
+ * @param root 网页根目录的 URL
85
+ * @param framework 框架对象
86
+ * @param pluginConfig swpp 插件配置项
87
+ */
88
+ builder?: ((root: string, framework: any, pluginConfig: SwppConfig) => string) | undefined;
89
+ };
90
+ /** 与 DOM 端有关的配置 */
91
+ dom?: boolean | {
92
+ /** 缓存更新成功后触发的操作 */
93
+ onsuccess?: VoidFunction;
94
+ };
95
+ /** 与版本文件相关的配置项 */
96
+ json?: boolean | {
97
+ /** 更新缓存时允许更新的最大 HTML 数量 */
98
+ maxHtml?: number;
99
+ /** update.json 文件的字符数量限制 */
100
+ charLimit?: number;
101
+ /** 是否合并指定项目 */
102
+ merge?: string[];
103
+ /** 生成 cacheList.json 时忽略的文件 */
104
+ exclude?: {
105
+ /** 当前网站的 URL */
106
+ localhost?: RegExp[];
107
+ /** 其它网站的 URL */
108
+ other?: RegExp[];
109
+ };
110
+ };
111
+ /** 外部文件更新监听 */
112
+ external?: boolean | {
113
+ /** 拉取网络文件的超时时间 */
114
+ timeout?: number;
115
+ /** 匹配 JS 代码中的 URL */
116
+ js?: ({
117
+ head: string;
118
+ tail: string;
119
+ } | ((jsCode: string) => string[]))[];
120
+ /** 链接不变内容就不变的 URL */
121
+ stable?: RegExp[];
122
+ /** 构建过程中将原始 URL 映射为新的 URL */
123
+ replacer?: (srcUrl: string) => string[] | string;
124
+ };
125
+ }
@@ -0,0 +1,50 @@
1
+ import { AnalyzerResult } from './VersionAnalyzer';
2
+ /** 提交修改 */
3
+ export declare function submitChange(...change: ChangeExpression[]): void;
4
+ /**
5
+ * 加载版本文件
6
+ *
7
+ * + **调用该函数前必须调用过 [loadRules]**
8
+ */
9
+ export declare function loadUpdateJson(url: string): Promise<UpdateJson | null>;
10
+ /**
11
+ * 读取最后一次加载的版本文件
12
+ *
13
+ * + **调用该函数前必须调用过 [loadRules]**
14
+ * + **调用该函数前必须调用过 [loadUpdateJson]**
15
+ */
16
+ export declare function readUpdateJson(): UpdateJson | null;
17
+ /**
18
+ * 构建新的 update json
19
+ *
20
+ * + **执行该函数前必须调用过 [loadRules]**
21
+ * + **调用该函数前必须调用过 [loadCacheJson]**
22
+ * + **执行该函数前必须调用过 [buildVersionJson]**
23
+ * + **执行该函数前必须调用过 [calcEjectValues]**
24
+ *
25
+ * @param root 网站根路径(包括网络协议)
26
+ * @param dif 网站文件变化
27
+ */
28
+ export declare function buildNewInfo(root: string, dif: AnalyzerResult): UpdateJson;
29
+ /**
30
+ * 获取 URL 的缩写形式
31
+ *
32
+ * + **执行该函数前必须调用过 [loadRules]**
33
+ * + **调用该函数前必须调用过 [loadCacheJson]**
34
+ * + **执行该函数前必须调用过 [buildVersionJson]**
35
+ * + **执行该函数前必须调用过 [calcEjectValues]**
36
+ */
37
+ export declare function getShorthand(url: string, offset?: number): string;
38
+ export interface UpdateJson {
39
+ global: number;
40
+ info: UpdateVersionInfo[];
41
+ }
42
+ export interface UpdateVersionInfo {
43
+ version: number;
44
+ change?: ChangeExpression[];
45
+ }
46
+ export interface ChangeExpression {
47
+ flag: FlagStr;
48
+ value?: string | string[];
49
+ }
50
+ export type FlagStr = 'html' | 'end' | 'begin' | 'str' | 'reg';
@@ -0,0 +1,29 @@
1
+ import { VersionJson } from './FileAnalyzer';
2
+ /**
3
+ * 分析两个版本信息的不同
4
+ *
5
+ * + **执行该函数前必须调用过 [loadRules]**
6
+ * + **调用该函数前必须调用过 [loadCacheJson]**
7
+ *
8
+ * @param version 新的版本信息
9
+ */
10
+ export declare function analyzer(version: VersionJson): AnalyzerResult;
11
+ /** 手动添加一个要刷新的 URL */
12
+ export declare function refreshUrl(url: string): void;
13
+ export interface AnalyzerResult {
14
+ /** 是否强制刷新所有缓存 */
15
+ force: boolean;
16
+ /** 被删除的 URL */
17
+ deleted: string[];
18
+ /** 内容变化的 URL */
19
+ variational: string[];
20
+ /** 手动刷新的 URL */
21
+ refresh: string[];
22
+ /** 因 stable 规则变化导致数据变动的 URL */
23
+ rules: {
24
+ /** 新规则将其识别为 stable */
25
+ add: string[];
26
+ /** 新规则将其识别为非 stable */
27
+ remove: string[];
28
+ };
29
+ }
@@ -0,0 +1,147 @@
1
+ /**
2
+ * 版本信息(可以用 JSON 序列化)
3
+ * @see VersionMap
4
+ */
5
+ export interface VersionJson {
6
+ version: number;
7
+ list: VersionMap;
8
+ }
9
+ /**
10
+ * 版本列表
11
+ *
12
+ * + key 为文件的 URL
13
+ * + value {string} 为 URL 对应文件的 md5 值
14
+ * + value {string[]} 为 stable 文件其中包含的 URL
15
+ */
16
+ export interface VersionMap {
17
+ [propName: string]: any;
18
+ }
19
+ /**
20
+ * 判断指定 URL 是否排除
21
+ *
22
+ * + **执行该函数前必须调用过 [loadRules]**
23
+ *
24
+ * @param webRoot 网站域名
25
+ * @param url 要判断的 URL
26
+ */
27
+ export declare function isExclude(webRoot: string, url: string): boolean;
28
+ /**
29
+ * 判断指定 URL 是否是 stable 的
30
+ *
31
+ * + **执行该函数前必须调用过 [loadRules]**
32
+ */
33
+ export declare function isStable(url: string): boolean;
34
+ /**
35
+ * 从指定 URL 加载 cache json
36
+ *
37
+ * + **执行该函数前必须调用过 [loadRules]**
38
+ */
39
+ export declare function loadVersionJson(url: string): Promise<VersionJson>;
40
+ /**
41
+ * 读取最后一次加载的 version json
42
+ *
43
+ * + **执行该函数前必须调用过 [loadRules]**
44
+ * + **调用该函数前必须调用过 [loadCacheJson]**
45
+ */
46
+ export declare function readOldVersionJson(): VersionJson;
47
+ /**
48
+ * 读取最后一次构建的 VersionJson
49
+ *
50
+ * + **执行该函数前必须调用过 [loadRules]**
51
+ * + **调用该函数前必须调用过 [loadCacheJson]**
52
+ * + **执行该函数前必须调用过 [buildVersionJson]**
53
+ * + **执行该函数前必须调用过 [calcEjectValues]**
54
+ */
55
+ export declare function readNewVersionJson(): VersionJson;
56
+ /**
57
+ * 读取新旧版本文件合并后的版本地图
58
+ *
59
+ * + **执行该函数前必须调用过 [loadRules]**
60
+ * + **调用该函数前必须调用过 [loadCacheJson]**
61
+ * + **执行该函数前必须调用过 [buildVersionJson]**
62
+ * + **执行该函数前必须调用过 [calcEjectValues]**
63
+ */
64
+ export declare function readMergeVersionMap(): VersionMap;
65
+ /**
66
+ * 构建一个 cache json
67
+ *
68
+ * + **执行该函数前必须调用过 [loadRules]**
69
+ * + **调用该函数前必须调用过 [loadCacheJson]**
70
+ * + **执行该函数前必须调用过 [calcEjectValues]**
71
+ *
72
+ * @param protocol 网站的网络协议
73
+ * @param webRoot 网站域名(包括二级域名)
74
+ * @param root 网页根目录(首页 index.html 所在目录)
75
+ */
76
+ export declare function buildVersionJson(protocol: ('https://' | 'http://'), webRoot: string, root: string): Promise<VersionJson>;
77
+ /**
78
+ * 检索一个 URL 指向的文件中所有地外部链接
79
+ *
80
+ * 该函数会处理该 URL 指向的文件和文件中直接或间接包含的所有 URL
81
+ *
82
+ * + **执行该函数前必须调用过 [loadRules]**
83
+ * + **调用该函数前必须调用过 [loadCacheJson]**
84
+ * + **执行该函数前必须调用过 [calcEjectValues]**
85
+ *
86
+ * @param webRoot 网站域名
87
+ * @param url 要检索的 URL
88
+ * @param result 存放结果的对象
89
+ * @param event 检索到一个 URL 时触发的事件
90
+ */
91
+ export declare function eachAllLinkInUrl(webRoot: string, url: string, result: VersionMap, event?: (url: string) => void): Promise<void>;
92
+ /**
93
+ * 检索 HTML 文件中的所有外部链接
94
+ *
95
+ * 该函数仅处理 HTML 当中直接或间接包含的 URL,不处理文件本身
96
+ *
97
+ * + **执行该函数前必须调用过 [loadRules]**
98
+ * + **调用该函数前必须调用过 [loadCacheJson]**
99
+ *
100
+ * @param webRoot 网站域名
101
+ * @param content HTML 文件内容
102
+ * @param result 存放结果的对象
103
+ * @param event 检索到 URL 时触发的事件
104
+ */
105
+ export declare function eachAllLinkInHtml(webRoot: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<void>;
106
+ /**
107
+ * 检索 CSS 文件中的所有外部链
108
+ *
109
+ * 该函数仅处理 CSS 当中直接或间接包含的 URL,不处理文件本身
110
+ *
111
+ * + **执行该函数前必须调用过 [loadRules]**
112
+ * + **调用该函数前必须调用过 [loadCacheJson]**
113
+ *
114
+ * @param webRoot 网站域名
115
+ * @param content CSS 文件内容
116
+ * @param result 存放结果的对象
117
+ * @param event 当检索到一个 URL 后触发的事件
118
+ */
119
+ export declare function eachAllLinkInCss(webRoot: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<void>;
120
+ /**
121
+ * 遍历 JS 文件中地所有外部链接
122
+ *
123
+ * 该函数仅处理 JS 当中直接或间接包含的 URL,不处理文件本身
124
+ *
125
+ * + **执行该函数前必须调用过 [loadRules]**
126
+ * + **调用该函数前必须调用过 [loadCacheJson]**
127
+ *
128
+ * @param webRoot 网站域名
129
+ * @param content JS 文件内容
130
+ * @param result 存放结果的对象
131
+ * @param event 当检索到一个 URL 后触发的事件
132
+ */
133
+ export declare function eachAllLinkInJavaScript(webRoot: string, content: string, result: VersionMap, event?: (url: string) => void): Promise<void>;
134
+ /**
135
+ * 查询指定 URL 对应的缓存规则
136
+ *
137
+ * + **执行该函数前必须调用过 [loadRules]**
138
+ * + **执行该函数前必须调用过 [calcEjectValues]**
139
+ */
140
+ export declare function findCache(url: URL | string): any | null;
141
+ /**
142
+ * 替换请求
143
+ *
144
+ * + **执行该函数前必须调用过 [loadRules]**
145
+ * + **执行该函数前必须调用过 [calcEjectValues]**
146
+ */
147
+ export declare function replaceRequest(url: string): string;
@@ -0,0 +1,54 @@
1
+ import { readEjectData, getSource, fetchFile, replaceDevRequest, calcEjectValues } from './Utils';
2
+ import { isExclude, isStable, loadVersionJson, readOldVersionJson, readNewVersionJson, readMergeVersionMap, buildVersionJson, eachAllLinkInUrl, eachAllLinkInHtml, eachAllLinkInCss, eachAllLinkInJavaScript, findCache, replaceRequest } from './FileAnalyzer';
3
+ import { buildServiceWorker } from './ServiceWorkerBuilder';
4
+ import { readRules, loadRules, addRulesMapEvent } from './SwppRules';
5
+ import { readUpdateJson, loadUpdateJson, submitChange, getShorthand, buildNewInfo } from './UpdateJsonBuilder';
6
+ import { refreshUrl, analyzer } from './VersionAnalyzer';
7
+ declare const _default: {
8
+ cache: {
9
+ readEjectData: typeof readEjectData;
10
+ readUpdateJson: typeof readUpdateJson;
11
+ readRules: typeof readRules;
12
+ readMergeVersionMap: typeof readMergeVersionMap;
13
+ readOldVersionJson: typeof readOldVersionJson;
14
+ readNewVersionJson: typeof readNewVersionJson;
15
+ };
16
+ builder: {
17
+ buildServiceWorker: typeof buildServiceWorker;
18
+ buildVersionJson: typeof buildVersionJson;
19
+ buildNewInfo: typeof buildNewInfo;
20
+ calcEjectValues: typeof calcEjectValues;
21
+ analyzer: typeof analyzer;
22
+ };
23
+ loader: {
24
+ loadRules: typeof loadRules;
25
+ loadUpdateJson: typeof loadUpdateJson;
26
+ loadVersionJson: typeof loadVersionJson;
27
+ };
28
+ event: {
29
+ addRulesMapEvent: typeof addRulesMapEvent;
30
+ refreshUrl: typeof refreshUrl;
31
+ submitChange: typeof submitChange;
32
+ };
33
+ utils: {
34
+ getSource: typeof getSource;
35
+ getShorthand: typeof getShorthand;
36
+ findCache: typeof findCache;
37
+ fetchFile: typeof fetchFile;
38
+ replaceDevRequest: typeof replaceDevRequest;
39
+ replaceRequest: typeof replaceRequest;
40
+ isStable: typeof isStable;
41
+ isExclude: typeof isExclude;
42
+ eachAllLinkInUrl: typeof eachAllLinkInUrl;
43
+ eachAllLinkInHtml: typeof eachAllLinkInHtml;
44
+ eachAllLinkInCss: typeof eachAllLinkInCss;
45
+ eachAllLinkInJavaScript: typeof eachAllLinkInJavaScript;
46
+ };
47
+ };
48
+ export default _default;
49
+ export { EjectCache } from './Utils';
50
+ export { VersionJson, VersionMap } from './FileAnalyzer';
51
+ export { ServiceWorkerConfig, SwppConfig, SwppConfigTemplate, DomConfig, VersionJsonConfig, RegisterConfig, ExternalMonitorConfig } from './SwppConfig';
52
+ export { SwppRules, CacheRules, SpareURLs, EjectValue } from './SwppRules';
53
+ export { UpdateJson, UpdateVersionInfo, FlagStr, ChangeExpression } from './UpdateJsonBuilder';
54
+ export { AnalyzerResult } from './VersionAnalyzer';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 构建 sw
3
+ *
4
+ * + **执行该函数前必须调用过 [loadRules]**
5
+ * + **执行该函数前必须调用过 [calcEjectValues]**
6
+ */
7
+ export declare function buildServiceWorker(): string;