swpp-backends 0.0.1-alpha.0 → 0.0.2-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/SwppConfig.js +2 -0
- package/dist/UpdateJsonBuilder.js +281 -0
- package/dist/VersionAnalyzer.js +62 -0
- package/dist/fileAnalyzer.js +325 -76
- package/dist/index.js +32 -25
- package/dist/resources/sw-template.js +15 -23
- package/dist/serviceWorkerBuilder.js +18 -10
- package/dist/swppRules.js +34 -16
- package/dist/utils.js +42 -14
- package/package.json +36 -21
- package/{src/SwppConfig.ts → types/SwppConfig.d.ts} +125 -125
- package/types/UpdateJsonBuilder.d.ts +50 -0
- package/types/VersionAnalyzer.d.ts +29 -0
- package/types/fileAnalyzer.d.ts +149 -0
- package/types/index.d.ts +55 -0
- package/types/serviceWorkerBuilder.d.ts +7 -0
- package/types/swppRules.d.ts +101 -0
- package/types/utils.d.ts +41 -0
- package/gulpfile.js +0 -3
- package/src/FileAnalyzer.ts +0 -417
- package/src/ServiceWorkerBuilder.ts +0 -156
- package/src/SwppRules.ts +0 -200
- package/src/UpdateJsonBuilder.ts +0 -279
- package/src/Utils.ts +0 -195
- package/src/VersionAnalyzer.ts +0 -77
- package/src/index.ts +0 -64
- package/src/resources/sw-dom.js +0 -51
- package/src/resources/sw-template.js +0 -257
- package/tsconfig.json +0 -109
package/src/VersionAnalyzer.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {readOldVersionJson, VersionJson} from './FileAnalyzer'
|
|
2
|
-
|
|
3
|
-
const extraUrl = new Set<string>()
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 分析两个版本信息的不同
|
|
7
|
-
*
|
|
8
|
-
* + **执行该函数前必须调用过 [loadRules]**
|
|
9
|
-
* + **调用该函数前必须调用过 [loadCacheJson]**
|
|
10
|
-
*
|
|
11
|
-
* @param version 新的版本信息
|
|
12
|
-
*/
|
|
13
|
-
export function analyzer(version: VersionJson): AnalyzerResult {
|
|
14
|
-
const oldVersion = readOldVersionJson()
|
|
15
|
-
const result: AnalyzerResult = {
|
|
16
|
-
force: false,
|
|
17
|
-
deleted: [],
|
|
18
|
-
variational: [],
|
|
19
|
-
refresh: [],
|
|
20
|
-
rules: {
|
|
21
|
-
add: [] as string[],
|
|
22
|
-
remove: [] as string[]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (version.version !== oldVersion.version) {
|
|
26
|
-
result.force = true
|
|
27
|
-
return result
|
|
28
|
-
}
|
|
29
|
-
for (let url in oldVersion.list) {
|
|
30
|
-
if (extraUrl.has(url)) {
|
|
31
|
-
result.refresh.push(url)
|
|
32
|
-
extraUrl.delete(url)
|
|
33
|
-
continue
|
|
34
|
-
}
|
|
35
|
-
const oldValue = oldVersion.list[url]
|
|
36
|
-
const newValue = version.list[url]
|
|
37
|
-
if (!newValue) {
|
|
38
|
-
result.deleted.push(url)
|
|
39
|
-
continue
|
|
40
|
-
}
|
|
41
|
-
const oldType = typeof oldValue
|
|
42
|
-
const newType = typeof newValue
|
|
43
|
-
if (oldType !== newType) {
|
|
44
|
-
if (newType === 'string')
|
|
45
|
-
result.rules.remove.push(url)
|
|
46
|
-
else
|
|
47
|
-
result.rules.add.push(url)
|
|
48
|
-
} else if (oldType === 'string' && newValue !== oldValue) {
|
|
49
|
-
result.variational.push(url)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
extraUrl.forEach(url => result.refresh.push(url))
|
|
53
|
-
return result
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** 手动添加一个要刷新的 URL */
|
|
57
|
-
export function refreshUrl(url: string) {
|
|
58
|
-
extraUrl.add(url)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface AnalyzerResult {
|
|
62
|
-
/** 是否强制刷新所有缓存 */
|
|
63
|
-
force: boolean,
|
|
64
|
-
/** 被删除的 URL */
|
|
65
|
-
deleted: string[],
|
|
66
|
-
/** 内容变化的 URL */
|
|
67
|
-
variational: string[],
|
|
68
|
-
/** 手动刷新的 URL */
|
|
69
|
-
refresh: string[],
|
|
70
|
-
/** 因 stable 规则变化导致数据变动的 URL */
|
|
71
|
-
rules: {
|
|
72
|
-
/** 新规则将其识别为 stable */
|
|
73
|
-
add: string[],
|
|
74
|
-
/** 新规则将其识别为非 stable */
|
|
75
|
-
remove: string[]
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {readEjectData, getSource, fetchFile, replaceDevRequest, calcEjectValues} from './Utils'
|
|
2
|
-
import {
|
|
3
|
-
isExclude,
|
|
4
|
-
isStable,
|
|
5
|
-
loadVersionJson,
|
|
6
|
-
readOldVersionJson,
|
|
7
|
-
readNewVersionJson,
|
|
8
|
-
readMergeVersionMap,
|
|
9
|
-
buildVersionJson,
|
|
10
|
-
eachAllLinkInUrl,
|
|
11
|
-
eachAllLinkInHtml,
|
|
12
|
-
eachAllLinkInCss,
|
|
13
|
-
eachAllLinkInJavaScript,
|
|
14
|
-
findCache,
|
|
15
|
-
replaceRequest
|
|
16
|
-
} from './FileAnalyzer'
|
|
17
|
-
import {buildServiceWorker} from './ServiceWorkerBuilder'
|
|
18
|
-
import {readRules, loadRules, addRulesMapEvent} from './SwppRules'
|
|
19
|
-
import {readUpdateJson, loadUpdateJson, submitChange, getShorthand, buildNewInfo} from './UpdateJsonBuilder'
|
|
20
|
-
import {refreshUrl, analyzer} from './VersionAnalyzer'
|
|
21
|
-
|
|
22
|
-
// noinspection JSUnusedGlobalSymbols
|
|
23
|
-
export default {
|
|
24
|
-
cache: {
|
|
25
|
-
readEjectData, readUpdateJson,
|
|
26
|
-
readRules, readMergeVersionMap,
|
|
27
|
-
readOldVersionJson, readNewVersionJson
|
|
28
|
-
},
|
|
29
|
-
builder: {
|
|
30
|
-
buildServiceWorker,
|
|
31
|
-
buildVersionJson,
|
|
32
|
-
buildNewInfo,
|
|
33
|
-
calcEjectValues,
|
|
34
|
-
analyzer
|
|
35
|
-
},
|
|
36
|
-
loader: {
|
|
37
|
-
loadRules, loadUpdateJson, loadVersionJson
|
|
38
|
-
},
|
|
39
|
-
event: {
|
|
40
|
-
addRulesMapEvent, refreshUrl, submitChange
|
|
41
|
-
},
|
|
42
|
-
utils: {
|
|
43
|
-
getSource, getShorthand, findCache,
|
|
44
|
-
fetchFile, replaceDevRequest, replaceRequest,
|
|
45
|
-
isStable, isExclude,
|
|
46
|
-
eachAllLinkInUrl, eachAllLinkInHtml, eachAllLinkInCss, eachAllLinkInJavaScript
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// types
|
|
51
|
-
export {EjectCache} from './Utils'
|
|
52
|
-
export {VersionJson, VersionMap} from './FileAnalyzer'
|
|
53
|
-
export {
|
|
54
|
-
ServiceWorkerConfig,
|
|
55
|
-
SwppConfig,
|
|
56
|
-
SwppConfigTemplate,
|
|
57
|
-
DomConfig,
|
|
58
|
-
VersionJsonConfig,
|
|
59
|
-
RegisterConfig,
|
|
60
|
-
ExternalMonitorConfig
|
|
61
|
-
} from './SwppConfig'
|
|
62
|
-
export {SwppRules, CacheRules, SpareURLs, EjectValue} from './SwppRules'
|
|
63
|
-
export {UpdateJson, UpdateVersionInfo, FlagStr, ChangeExpression} from './UpdateJsonBuilder'
|
|
64
|
-
export {AnalyzerResult} from './VersionAnalyzer'
|
package/src/resources/sw-dom.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
2
|
-
/** 检查 SW 是否可用 */
|
|
3
|
-
const checkServiceWorker = () => 'serviceWorker' in navigator && navigator.serviceWorker.controller
|
|
4
|
-
/** 发送信息到 sw */
|
|
5
|
-
const postMessage2SW = type => navigator.serviceWorker.controller.postMessage(type)
|
|
6
|
-
const pjaxUpdate = url => new Promise(resolve => {
|
|
7
|
-
const type = url.endsWith('js') ? 'script' : 'link'
|
|
8
|
-
const name = type.length === 4 ? 'href' : 'src'
|
|
9
|
-
for (let item of document.querySelectorAll(type)) {
|
|
10
|
-
const itUrl = item[name]
|
|
11
|
-
if (url.length > itUrl ? url.endsWith(itUrl) : itUrl.endsWith(url)) {
|
|
12
|
-
const newEle = document.createElement(type)
|
|
13
|
-
const content = item.text || item.textContent || item.innerHTML || ''
|
|
14
|
-
Array.from(item.attributes).forEach(attr => newEle.setAttribute(attr.name, attr.value))
|
|
15
|
-
newEle.appendChild(document.createTextNode(content))
|
|
16
|
-
item.parentNode.replaceChildren(newEle, item)
|
|
17
|
-
return resolve(true)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
resolve(false)
|
|
21
|
-
})
|
|
22
|
-
if (!checkServiceWorker()) return
|
|
23
|
-
if (sessionStorage.getItem('updated')) {
|
|
24
|
-
sessionStorage.removeItem('updated')
|
|
25
|
-
// ${onSuccess}
|
|
26
|
-
} else postMessage2SW('update')
|
|
27
|
-
navigator.serviceWorker.addEventListener('message', event => {
|
|
28
|
-
const data = event.data
|
|
29
|
-
switch (data.type) {
|
|
30
|
-
case 'update':
|
|
31
|
-
const list = data.update
|
|
32
|
-
if (!list) break
|
|
33
|
-
sessionStorage.setItem('updated', '1')
|
|
34
|
-
// noinspection JSUnresolvedVariable,JSUnresolvedFunction
|
|
35
|
-
if (window.Pjax?.isSupported()) {
|
|
36
|
-
Promise.all(list.map(url => {
|
|
37
|
-
if (url.endsWith('.js'))
|
|
38
|
-
return pjaxUpdate(url)
|
|
39
|
-
if (url.endsWith('.css'))
|
|
40
|
-
return pjaxUpdate(url)
|
|
41
|
-
return Promise.resolve()
|
|
42
|
-
})).then(() => location.reload())
|
|
43
|
-
} else location.reload()
|
|
44
|
-
break
|
|
45
|
-
case 'escape':
|
|
46
|
-
sessionStorage.setItem('updated', '1')
|
|
47
|
-
location.reload()
|
|
48
|
-
break
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
})
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
// noinspection JSIgnoredPromiseFromCall
|
|
2
|
-
|
|
3
|
-
(() => {
|
|
4
|
-
/** 缓存库名称 */
|
|
5
|
-
const CACHE_NAME = '@$$[cacheName]'
|
|
6
|
-
/** 控制信息存储地址(必须以`/`结尾) */
|
|
7
|
-
const CTRL_PATH = 'https://id.v3/'
|
|
8
|
-
|
|
9
|
-
// [insertion site] values
|
|
10
|
-
|
|
11
|
-
/** 控制信息读写操作 */
|
|
12
|
-
const dbVersion = {
|
|
13
|
-
write: (id) => caches.open(CACHE_NAME)
|
|
14
|
-
.then(cache => cache.put(CTRL_PATH, new Response(JSON.stringify(id)))),
|
|
15
|
-
read: () => caches.match(CTRL_PATH).then(response => response?.json())
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
self.addEventListener('install', () => {
|
|
19
|
-
self.skipWaiting()
|
|
20
|
-
const escape = '@$$[escape]'
|
|
21
|
-
dbVersion.read().then(oldVersion => {
|
|
22
|
-
if (oldVersion && oldVersion.escape !== escape) {
|
|
23
|
-
oldVersion.escape = escape
|
|
24
|
-
// noinspection JSUnresolvedVariable
|
|
25
|
-
caches.delete(CACHE_NAME)
|
|
26
|
-
.then(() => clients.matchAll())
|
|
27
|
-
.then(list => list.forEach(client => client.postMessage({type: 'escape'})))
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
// sw 激活后立即对所有页面生效,而非等待刷新
|
|
33
|
-
// noinspection JSUnresolvedReference
|
|
34
|
-
self.addEventListener('activate', event => event.waitUntil(clients.claim()))
|
|
35
|
-
|
|
36
|
-
// noinspection JSFileReferences
|
|
37
|
-
const { cacheList, fetchFile, getSpareUrls } = require('../sw-rules')
|
|
38
|
-
|
|
39
|
-
// 检查请求是否成功
|
|
40
|
-
// noinspection JSUnusedLocalSymbols
|
|
41
|
-
const checkResponse = response => response.ok || [301, 302, 307, 308].includes(response.status)
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 删除指定缓存
|
|
45
|
-
* @param list 要删除的缓存列表
|
|
46
|
-
* @return {Promise<string[]>} 删除的缓存的URL列表
|
|
47
|
-
*/
|
|
48
|
-
const deleteCache = list => caches.open(CACHE_NAME).then(cache => cache.keys()
|
|
49
|
-
.then(keys => Promise.all(
|
|
50
|
-
keys.map(async it => {
|
|
51
|
-
const url = it.url
|
|
52
|
-
if (url !== CTRL_PATH && list.match(url)) {
|
|
53
|
-
// [debug delete]
|
|
54
|
-
// noinspection ES6MissingAwait,JSCheckFunctionSignatures
|
|
55
|
-
cache.delete(it)
|
|
56
|
-
return url
|
|
57
|
-
}
|
|
58
|
-
return null
|
|
59
|
-
})
|
|
60
|
-
)).then(list => list.filter(it => it))
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
self.addEventListener('fetch', event => {
|
|
64
|
-
let request = event.request
|
|
65
|
-
if (request.method !== 'GET' || !request.url.startsWith('http')) return
|
|
66
|
-
// [modifyRequest call]
|
|
67
|
-
const url = new URL(request.url)
|
|
68
|
-
// [blockRequest call]
|
|
69
|
-
const cacheRule = findCache(url)
|
|
70
|
-
if (cacheRule) {
|
|
71
|
-
let key = `https://${url.host}${url.pathname}`
|
|
72
|
-
if (key.endsWith('/index.html')) key = key.substring(0, key.length - 10)
|
|
73
|
-
if (cacheRule.search) key += url.search
|
|
74
|
-
event.respondWith(caches.match(key)
|
|
75
|
-
.then(cache => cache ?? fetchFile(request, true)
|
|
76
|
-
.then(response => {
|
|
77
|
-
if (checkResponse(response)) {
|
|
78
|
-
const clone = response.clone()
|
|
79
|
-
caches.open(CACHE_NAME).then(it => it.put(key, clone))
|
|
80
|
-
// [debug put]
|
|
81
|
-
}
|
|
82
|
-
return response
|
|
83
|
-
})
|
|
84
|
-
)
|
|
85
|
-
)
|
|
86
|
-
} else {
|
|
87
|
-
const spare = getSpareUrls(request.url)
|
|
88
|
-
if (spare) event.respondWith(fetchFile(request, false, spare))
|
|
89
|
-
// [modifyRequest else-if]
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
self.addEventListener('message', event => {
|
|
94
|
-
// [debug message]
|
|
95
|
-
if (event.data === 'update')
|
|
96
|
-
updateJson().then(info =>
|
|
97
|
-
// noinspection JSUnresolvedVariable
|
|
98
|
-
event.source.postMessage({
|
|
99
|
-
type: 'update',
|
|
100
|
-
update: info.list,
|
|
101
|
-
version: info.version,
|
|
102
|
-
})
|
|
103
|
-
)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
/** 判断指定url击中了哪一种缓存,都没有击中则返回null */
|
|
107
|
-
function findCache(url) {
|
|
108
|
-
if (url.hostname === 'localhost') return
|
|
109
|
-
for (let key in cacheList) {
|
|
110
|
-
const value = cacheList[key]
|
|
111
|
-
if (value.match(url)) return value
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 根据JSON删除缓存
|
|
117
|
-
* @returns {Promise<{version, list}>}
|
|
118
|
-
*/
|
|
119
|
-
const updateJson = () => {
|
|
120
|
-
/**
|
|
121
|
-
* 解析elements,并把结果输出到list中
|
|
122
|
-
* @return boolean 是否刷新全站缓存
|
|
123
|
-
*/
|
|
124
|
-
const parseChange = (list, elements, ver) => {
|
|
125
|
-
for (let element of elements) {
|
|
126
|
-
const {version, change} = element
|
|
127
|
-
if (version === ver) return false
|
|
128
|
-
if (change) {
|
|
129
|
-
for (let it of change)
|
|
130
|
-
list.push(new CacheChangeExpression(it))
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// 跨版本幅度过大,直接清理全站
|
|
134
|
-
return true
|
|
135
|
-
}
|
|
136
|
-
/** 解析字符串 */
|
|
137
|
-
const parseJson = json => dbVersion.read().then(oldVersion => {
|
|
138
|
-
const {info, global} = json
|
|
139
|
-
const newVersion = {global, local: info[0].version, escape: oldVersion?.escape}
|
|
140
|
-
//新用户不进行更新操作
|
|
141
|
-
if (!oldVersion) {
|
|
142
|
-
dbVersion.write(newVersion)
|
|
143
|
-
return newVersion
|
|
144
|
-
}
|
|
145
|
-
let list = new VersionList()
|
|
146
|
-
let refresh = parseChange(list, info, oldVersion.local)
|
|
147
|
-
dbVersion.write(newVersion)
|
|
148
|
-
// [debug escape]
|
|
149
|
-
//如果需要清理全站
|
|
150
|
-
if (refresh) {
|
|
151
|
-
if (global !== oldVersion.global) list.refresh = true
|
|
152
|
-
else list.clean(new CacheChangeExpression({'flag': 'all'}))
|
|
153
|
-
}
|
|
154
|
-
return {list, version: newVersion}
|
|
155
|
-
})
|
|
156
|
-
return fetchFile(new Request('/update.json'), false)
|
|
157
|
-
.then(response => {
|
|
158
|
-
if (checkResponse(response))
|
|
159
|
-
return response.json().then(json =>
|
|
160
|
-
parseJson(json).then(result => {
|
|
161
|
-
return result.list ? deleteCache(result.list)
|
|
162
|
-
.then(list => list.length === 0 ? null : list)
|
|
163
|
-
.then(list => ({list, version: result.version}))
|
|
164
|
-
: {version: result}
|
|
165
|
-
}
|
|
166
|
-
)
|
|
167
|
-
)
|
|
168
|
-
else throw `加载 update.json 时遇到异常,状态码:${response.status}`
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 版本列表
|
|
174
|
-
* @constructor
|
|
175
|
-
*/
|
|
176
|
-
function VersionList() {
|
|
177
|
-
|
|
178
|
-
const list = []
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* 推送一个表达式
|
|
182
|
-
* @param element {CacheChangeExpression} 要推送的表达式
|
|
183
|
-
*/
|
|
184
|
-
this.push = element => {
|
|
185
|
-
list.push(element)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 清除列表,并将指定元素推入列表中
|
|
190
|
-
* @param element {CacheChangeExpression} 要推入的元素,留空表示不推入
|
|
191
|
-
*/
|
|
192
|
-
this.clean = element => {
|
|
193
|
-
list.length = 0
|
|
194
|
-
if (!element) this.push(element)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 判断指定 URL 是否和某一条规则匹配
|
|
199
|
-
* @param url {string} URL
|
|
200
|
-
* @return {boolean}
|
|
201
|
-
*/
|
|
202
|
-
this.match = url => {
|
|
203
|
-
if (this.refresh) return true
|
|
204
|
-
else {
|
|
205
|
-
for (let it of list) {
|
|
206
|
-
if (it.match(url)) return true
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return false
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// noinspection SpellCheckingInspection
|
|
215
|
-
/**
|
|
216
|
-
* 缓存更新匹配规则表达式
|
|
217
|
-
* @param json 格式{"flag": ..., "value": ...}
|
|
218
|
-
* @see https://kmar.top/posts/bcfe8408/#23bb4130
|
|
219
|
-
* @constructor
|
|
220
|
-
*/
|
|
221
|
-
function CacheChangeExpression(json) {
|
|
222
|
-
const checkCache = url => {
|
|
223
|
-
const cache = findCache(new URL(url))
|
|
224
|
-
return !cache || cache.clean
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* 遍历所有value
|
|
228
|
-
* @param action {function(string): boolean} 接受value并返回bool的函数
|
|
229
|
-
* @return {boolean} 如果value只有一个则返回`action(value)`,否则返回所有运算的或运算(带短路)
|
|
230
|
-
*/
|
|
231
|
-
const forEachValues = action => {
|
|
232
|
-
const value = json.value
|
|
233
|
-
if (Array.isArray(value)) {
|
|
234
|
-
for (let it of value) {
|
|
235
|
-
if (action(it)) return true
|
|
236
|
-
}
|
|
237
|
-
return false
|
|
238
|
-
} else return action(value)
|
|
239
|
-
}
|
|
240
|
-
const getMatch = () => {
|
|
241
|
-
switch (json['flag']) {
|
|
242
|
-
case 'html':
|
|
243
|
-
return url => url.match(/(\/|\.html)$/)
|
|
244
|
-
case 'end':
|
|
245
|
-
return url => forEachValues(value => url.endsWith(value))
|
|
246
|
-
case 'begin':
|
|
247
|
-
return url => forEachValues(value => url.startsWith(value))
|
|
248
|
-
case 'str':
|
|
249
|
-
return url => forEachValues(value => url.includes(value))
|
|
250
|
-
case 'reg':
|
|
251
|
-
return url => forEachValues(value => url.match(new RegExp(value, 'i')))
|
|
252
|
-
default: throw `未知表达式:${JSON.stringify(json)}`
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
this.match = getMatch()
|
|
256
|
-
}
|
|
257
|
-
})()
|
package/tsconfig.json
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Projects */
|
|
6
|
-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
-
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
-
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
-
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
-
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
-
|
|
13
|
-
/* Language and Environment */
|
|
14
|
-
"target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
-
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
-
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
-
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
-
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
-
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
-
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
-
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
-
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
-
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
-
|
|
27
|
-
/* Modules */
|
|
28
|
-
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
-
"rootDir": "./src/", /* Specify the root folder within your source files. */
|
|
30
|
-
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
-
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
-
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
-
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
-
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
-
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
-
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
-
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
-
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
40
|
-
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
41
|
-
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
42
|
-
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
43
|
-
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
44
|
-
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
45
|
-
|
|
46
|
-
/* JavaScript Support */
|
|
47
|
-
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
48
|
-
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
49
|
-
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
50
|
-
|
|
51
|
-
/* Emit */
|
|
52
|
-
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
53
|
-
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
54
|
-
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
55
|
-
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
56
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
57
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
-
"outDir": "./dist/", /* Specify an output folder for all emitted files. */
|
|
59
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
61
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
62
|
-
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
63
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
64
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
65
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
66
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
67
|
-
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
68
|
-
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
69
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
70
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
71
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
72
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
73
|
-
"declarationDir": "./types/", /* Specify the output directory for generated declaration files. */
|
|
74
|
-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
75
|
-
|
|
76
|
-
/* Interop Constraints */
|
|
77
|
-
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
78
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
79
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
|
-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
81
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
82
|
-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
83
|
-
|
|
84
|
-
/* Type Checking */
|
|
85
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
86
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
87
|
-
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
88
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
89
|
-
"strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
90
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
91
|
-
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
92
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
93
|
-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
94
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
95
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
96
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
97
|
-
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
98
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
99
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
100
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
101
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
102
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
103
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
104
|
-
|
|
105
|
-
/* Completeness */
|
|
106
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
107
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
108
|
-
}
|
|
109
|
-
}
|