swpp-backends 0.0.7-alpha → 0.0.8-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.
@@ -237,9 +237,6 @@ async function eachAllLinkInUrl(domain, url, result, event) {
237
237
  copyTree(url);
238
238
  }
239
239
  }
240
- else {
241
- event?.(value);
242
- }
243
240
  };
244
241
  copyTree(url);
245
242
  return;
@@ -256,23 +253,30 @@ async function eachAllLinkInUrl(domain, url, result, event) {
256
253
  }
257
254
  const pathname = new URL(url).pathname;
258
255
  let content;
259
- const relay = [];
260
256
  const nextEvent = (it) => {
261
- relay.push(it);
262
- event?.(it);
257
+ result[url].push(it);
258
+ };
259
+ const update = () => {
260
+ if (stable)
261
+ result[url] = [];
262
+ else
263
+ result[url] = crypto.createHash('md5').update(content).digest('hex');
263
264
  };
264
265
  switch (true) {
265
266
  case pathname.endsWith('.html'):
266
267
  case pathname.endsWith('/'):
267
268
  content = await response.text();
269
+ update();
268
270
  await eachAllLinkInHtml(domain, content, result, nextEvent);
269
271
  break;
270
272
  case pathname.endsWith('.css'):
271
273
  content = await response.text();
274
+ update();
272
275
  await eachAllLinkInCss(domain, content, result, nextEvent);
273
276
  break;
274
277
  case pathname.endsWith('.js'):
275
278
  content = await response.text();
279
+ update();
276
280
  await eachAllLinkInJavaScript(domain, content, result, nextEvent);
277
281
  break;
278
282
  default:
@@ -285,14 +289,6 @@ async function eachAllLinkInUrl(domain, url, result, event) {
285
289
  }
286
290
  break;
287
291
  }
288
- if (content) {
289
- if (stable) {
290
- result[url] = relay;
291
- }
292
- else {
293
- result[url] = crypto.createHash('md5').update(content).digest('hex');
294
- }
295
- }
296
292
  }
297
293
  exports.eachAllLinkInUrl = eachAllLinkInUrl;
298
294
  /**
@@ -337,8 +333,10 @@ async function eachAllLinkInHtml(domain, content, result, event) {
337
333
  else if (node.tagName === 'style') {
338
334
  await eachAllLinkInCss(domain, node.rawText, result, event);
339
335
  }
340
- for (let childNode of node.childNodes) {
341
- await each(childNode);
336
+ if (node.childNodes) {
337
+ for (let childNode of node.childNodes) {
338
+ await each(childNode);
339
+ }
342
340
  }
343
341
  };
344
342
  await each(fast_html_parser_1.default.parse(content, { style: true, script: true }));
@@ -429,7 +427,9 @@ async function eachAllLinkInJavaScript(domain, content, result, event) {
429
427
  exports.eachAllLinkInJavaScript = eachAllLinkInJavaScript;
430
428
  /** 判断一个 URL 是否是外部链接 */
431
429
  function isExternalLink(domain, url) {
432
- return new RegExp(`^(https?:)?\\/\\/${domain}`).test(url);
430
+ if (url[0] === '/' && url[1] !== '/')
431
+ return false;
432
+ return !new RegExp(`^(https?:)?\\/\\/${domain}`).test(url);
433
433
  }
434
434
  /**
435
435
  * 查询指定 URL 对应的缓存规则
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "0.0.7-alpha",
3
+ "version": "0.0.8-alpha",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",