swpp-backends 0.0.8-alpha → 0.0.10-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.
@@ -41,13 +41,15 @@ const Utils_1 = require("./Utils");
41
41
  * @param root 根目录
42
42
  * @param cb 回调函数(接收的参数是文件的相对路径)
43
43
  */
44
- function eachAllFile(root, cb) {
44
+ async function eachAllFile(root, cb) {
45
45
  const stats = fs_1.default.statSync(root);
46
46
  if (stats.isFile())
47
- cb(root);
47
+ await cb(root);
48
48
  else {
49
49
  const files = fs_1.default.readdirSync(root);
50
- files.forEach(it => eachAllFile(path_1.default.join(root, it), cb));
50
+ for (let it of files) {
51
+ await eachAllFile(path_1.default.join(root, it), cb);
52
+ }
51
53
  }
52
54
  }
53
55
  /**
@@ -99,10 +101,10 @@ exports.loadVersionJson = loadVersionJson;
99
101
  let _oldVersionJson;
100
102
  let _newVersionJson;
101
103
  let _mergeVersionMap;
102
- const event = [];
104
+ const event = new Map();
103
105
  /** 提交要存储到 version json 的值 */
104
- function submitCacheInfo(value) {
105
- event.push(value);
106
+ function submitCacheInfo(key, value) {
107
+ event.set(key, value);
106
108
  }
107
109
  exports.submitCacheInfo = submitCacheInfo;
108
110
  /**
@@ -165,8 +167,8 @@ exports.readMergeVersionMap = readMergeVersionMap;
165
167
  */
166
168
  async function buildVersionJson(protocol, domain, root) {
167
169
  const list = {};
168
- eachAllFile(root, async (path) => {
169
- const endIndex = path.length - (path.endsWith('/index.html') ? 10 : 0);
170
+ await eachAllFile(root, async (path) => {
171
+ const endIndex = path.length - (/[\/\\]index\.html$/.test(path) ? 10 : 0);
170
172
  const url = new URL(protocol + path_1.default.join(domain, path.substring(root.length, endIndex)));
171
173
  const pathname = url.pathname;
172
174
  if (isExclude(domain, pathname))
@@ -254,7 +256,8 @@ async function eachAllLinkInUrl(domain, url, result, event) {
254
256
  const pathname = new URL(url).pathname;
255
257
  let content;
256
258
  const nextEvent = (it) => {
257
- result[url].push(it);
259
+ if (stable)
260
+ result[url].push(it);
258
261
  };
259
262
  const update = () => {
260
263
  if (stable)
@@ -360,10 +363,9 @@ async function eachAllLinkInCss(domain, content, result, event) {
360
363
  if (!any)
361
364
  return;
362
365
  for (let rule of any) {
366
+ if (rule.declarations)
367
+ await each(rule.declarations);
363
368
  switch (rule.type) {
364
- case 'rule':
365
- await each(rule.declarations);
366
- break;
367
369
  case 'declaration':
368
370
  const value = rule.value;
369
371
  const list = value.match(/url\(['"]?([^'")]+)['"]?\)/g)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "0.0.8-alpha",
3
+ "version": "0.0.10-alpha",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -41,7 +41,7 @@ export declare function isStable(url: string): boolean;
41
41
  */
42
42
  export declare function loadVersionJson(url: string): Promise<VersionJson>;
43
43
  /** 提交要存储到 version json 的值 */
44
- export declare function submitCacheInfo(value: any): void;
44
+ export declare function submitCacheInfo(key: string, value: any): void;
45
45
  /**
46
46
  * 读取最后一次加载的 version json
47
47
  *