textbrowser 0.39.0 → 0.40.3
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/.eslintrc.js +2 -0
- package/.ncurc.js +8 -0
- package/CHANGES.md +32 -0
- package/README.md +21 -16
- package/dist/WorkInfo-es.js +4659 -0
- package/dist/activateCallback-es.js +158 -0
- package/dist/index-es.js +83 -85
- package/dist/index-es.min.js +1 -1
- package/dist/index-umd.js +84 -86
- package/dist/index-umd.min.js +1 -1
- package/package.json +44 -44
- package/resources/index.js +1 -1
- package/resources/utils/Metadata.js +6 -1
- package/resources/utils/ServiceWorker.js +3 -1
- package/resources/workDisplay.js +0 -1
- package/server/main-cjs.js +186 -26
- package/server/main.js +1 -3
- package/sw-sample.js +17 -24
- package/.remarkrc +0 -11
- package/dist/WorkInfo-umd.js +0 -4666
- package/dist/activateCallback-umd.js +0 -166
package/sw-sample.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
/* eslint-env browser, serviceworker */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// support:
|
|
8
|
-
// https://stackoverflow.com/a/45578811/271577
|
|
9
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=824647
|
|
10
|
-
// import getJSON from './node_modules/simple-get-json/dist/index-es.js';
|
|
11
|
-
// import activateCallback from 'node_modules/textbrowser/resources/activateCallback.js';
|
|
12
|
-
// import {getWorkFiles} from './WorkInfo.js';
|
|
13
|
-
importScripts('node_modules/simple-get-json/dist/index.js');
|
|
14
|
-
importScripts('node_modules/textbrowser/dist/WorkInfo-umd.js');
|
|
15
|
-
importScripts('node_modules/textbrowser/dist/activateCallback-umd.js');
|
|
16
|
-
|
|
17
|
-
const CACHE_VERSION = '0.34.0';
|
|
1
|
+
/* eslint-env browser, serviceworker -- Service worker */
|
|
2
|
+
|
|
3
|
+
import {getJSON} from './node_modules/simple-get-json/dist/index-es.js';
|
|
4
|
+
import activateCallback from './node_modules/textbrowser/dist/activateCallback-es.js';
|
|
5
|
+
import {getWorkFiles} from './node_modules/textbrowser/dist/WorkInfo-es.js';
|
|
6
|
+
|
|
18
7
|
const CURRENT_CACHES = {
|
|
19
|
-
prefetch: 'prefetch-cache-v'
|
|
8
|
+
prefetch: 'prefetch-cache-v'
|
|
20
9
|
};
|
|
21
10
|
const minutes = 60 * 1000;
|
|
22
11
|
|
|
@@ -41,6 +30,7 @@ async function post ({type, message = type}) {
|
|
|
41
30
|
clients.forEach((client) => {
|
|
42
31
|
// Although we only need one client to which to send
|
|
43
32
|
// arguments, we want to signal phase complete to all
|
|
33
|
+
// eslint-disable-next-line unicorn/require-post-message-target-origin -- In worker
|
|
44
34
|
client.postMessage({message, type});
|
|
45
35
|
});
|
|
46
36
|
}
|
|
@@ -60,7 +50,7 @@ function log (...messages) {
|
|
|
60
50
|
*
|
|
61
51
|
* @param {Error} error
|
|
62
52
|
* @param {string[]} messages
|
|
63
|
-
* @returns {Promise<void>}
|
|
53
|
+
* @returns {Promise<void>}
|
|
64
54
|
*/
|
|
65
55
|
function logError (error, ...messages) {
|
|
66
56
|
const message = messages.join(' ');
|
|
@@ -192,14 +182,16 @@ async function install (time) {
|
|
|
192
182
|
namespace, languages, files, userStaticFiles
|
|
193
183
|
} = getConfigDefaults(json);
|
|
194
184
|
|
|
195
|
-
|
|
185
|
+
const {version} = await getJSON('./package.json');
|
|
186
|
+
|
|
187
|
+
console.log('opening cache', namespace + CURRENT_CACHES.prefetch + version);
|
|
196
188
|
const [
|
|
197
189
|
cache,
|
|
198
190
|
userDataFiles,
|
|
199
191
|
{languages: langs}
|
|
200
192
|
] = await Promise.all([
|
|
201
|
-
caches.open(namespace + CURRENT_CACHES.prefetch),
|
|
202
|
-
|
|
193
|
+
caches.open(namespace + CURRENT_CACHES.prefetch + version),
|
|
194
|
+
getWorkFiles(files),
|
|
203
195
|
getJSON(languages)
|
|
204
196
|
]);
|
|
205
197
|
log('Install: Retrieved dependency values');
|
|
@@ -240,7 +232,7 @@ async function install (time) {
|
|
|
240
232
|
return cache.put(urlToPrefetch, response);
|
|
241
233
|
} catch (error) {
|
|
242
234
|
logError(error, 'Not caching ' + urlToPrefetch + ' due to ' + error);
|
|
243
|
-
|
|
235
|
+
throw error;
|
|
244
236
|
}
|
|
245
237
|
});
|
|
246
238
|
await Promise.all(cachePromises);
|
|
@@ -273,8 +265,9 @@ async function activate (time) {
|
|
|
273
265
|
caches.keys()
|
|
274
266
|
]);
|
|
275
267
|
const {namespace, files, basePath} = getConfigDefaults(json);
|
|
268
|
+
const {version} = await getJSON('./package.json');
|
|
276
269
|
|
|
277
|
-
const expectedCacheNames = Object.values(CURRENT_CACHES).map((n) => namespace + n);
|
|
270
|
+
const expectedCacheNames = Object.values(CURRENT_CACHES).map((n) => namespace + n + version);
|
|
278
271
|
cacheNames.map(async (cacheName) => {
|
|
279
272
|
if (!expectedCacheNames.includes(cacheName)) {
|
|
280
273
|
log('Activate: Deleting out of date cache:', cacheName);
|