swpp-backends 2.3.1 → 2.3.2

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.
@@ -21,7 +21,7 @@ function buildDomJs() {
21
21
  }
22
22
  let template = fs_1.default.readFileSync(path_1.default.resolve('./', module.path, 'resources/sw-dom.js'), 'utf-8');
23
23
  if (config.onsuccess)
24
- template = template.replaceAll('// ${onSuccess}', `(${config.onsuccess.toString()})()`);
24
+ template = template.replaceAll('const {onSuccess} = require(\'../config\')', `const onSuccess = ${config.onsuccess.toString()};`);
25
25
  return template;
26
26
  }
27
27
  exports.buildDomJs = buildDomJs;
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ const VersionAnalyzer_1 = require("./VersionAnalyzer");
10
10
  const DomBuilder_1 = require("./DomBuilder");
11
11
  // noinspection JSUnusedGlobalSymbols
12
12
  exports.default = {
13
- version: '2.3.1',
13
+ version: '2.3.2',
14
14
  cache: {
15
15
  readEjectData: Utils_1.readEjectData, readUpdateJson: Variant_1.readUpdateJson,
16
16
  readRules: Variant_1.readRules, readMergeVersionMap: Variant_1.readMergeVersionMap,
@@ -19,26 +19,26 @@ document.addEventListener('DOMContentLoaded', () => {
19
19
  }
20
20
  }
21
21
  const SESSION_KEY = 'updated'
22
+ // noinspection JSFileReferences
23
+ const {onSuccess} = require('../config')
22
24
  if (sessionStorage.getItem(SESSION_KEY)) {
25
+ onSuccess()
23
26
  sessionStorage.removeItem(SESSION_KEY);
24
- // ${onSuccess}
25
27
  } else postMessage2SW('update')
26
28
  navigator.serviceWorker.addEventListener('message', event => {
27
- sessionStorage.setItem(SESSION_KEY, '1')
28
29
  const data = event.data
29
- switch (data.type) {
30
- case 'update':
31
- const list = data.list
32
- // noinspection JSUnresolvedVariable,JSUnresolvedFunction
33
- if (list && window.Pjax?.isSupported()) {
34
- list.filter(url => /\.(js|css)$/.test(url))
35
- .forEach(pjaxUpdate)
36
- }
37
- location.reload()
38
- break
39
- case 'escape':
40
- location.reload()
41
- break
30
+ sessionStorage.setItem(SESSION_KEY, data.type)
31
+ let list = data.list?.filter(url => /\.(js|css)$/.test(url))
32
+ if (list) {
33
+ // noinspection JSUnresolvedReference
34
+ if (window.Pjax?.isSupported?.())
35
+ list.forEach(pjaxUpdate)
36
+ location.reload()
37
+ } else {
38
+ const newVersion = data.new, oldVersion = data.old
39
+ if (oldVersion && (newVersion.global !== oldVersion.global || newVersion.local !== oldVersion.local)) {
40
+ onSuccess()
41
+ }
42
42
  }
43
43
  })
44
44
  })
@@ -28,13 +28,16 @@
28
28
  readVersion().then(async oldVersion => {
29
29
  // noinspection JSIncompatibleTypesComparison
30
30
  if (oldVersion && oldVersion.escape !== escape) {
31
- // noinspection JSValidateTypes
32
- oldVersion.escape = escape
31
+ const list = await caches.open(CACHE_NAME)
32
+ .then(cache => cache.keys())
33
+ .then(keys => keys?.map(it => it.url))
33
34
  await caches.delete(CACHE_NAME)
34
- await writeVersion(oldVersion)
35
+ const info = await updateJson()
36
+ info.type = 'escape'
37
+ info.list = list
35
38
  // noinspection JSUnresolvedReference
36
- const list = await clients.matchAll()
37
- list.forEach(client => client.postMessage({type: 'escape'}))
39
+ const clientList = await clients.matchAll()
40
+ clientList.forEach(client => client.postMessage(info))
38
41
  }
39
42
  })
40
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",