@serwist/window 8.0.0

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.
@@ -0,0 +1,10 @@
1
+
2
+ > @serwist/window@8.0.0 build /home/runner/work/serwist/serwist/packages/window
3
+ > rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js
4
+
5
+ (node:2592) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
6
+ (Use `node --trace-warnings ...` to show where the warning was created)
7
+ (node:2592) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
8
+ 
9
+ src/index.ts → dist/index.old.cjs, dist/index.js...
10
+ created dist/index.old.cjs, dist/index.js in 7.8s
@@ -0,0 +1,4 @@
1
+
2
+ > @serwist/window@8.0.0 lint /home/runner/work/serwist/serwist/packages/window
3
+ > eslint src --ext ts,tsx,js,jsx,cjs,mjs
4
+
@@ -0,0 +1,4 @@
1
+
2
+ > @serwist/window@8.0.0 typecheck /home/runner/work/serwist/serwist/packages/window
3
+ > tsc
4
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # @serwist/window
2
+
3
+ ## 8.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`e0313f0`](https://github.com/serwist/serwist/commit/e0313f02f661a07ccbe9edc64e44e1af6136c73e) Thanks [@DuCanhGH](https://github.com/DuCanhGH)! - chore: initial release
8
+
9
+ - Reimagined `@serwist/next`.
10
+ - Removed various options.
11
+ - Removed `aggressiveFrontEndNavCaching` to reassess its usefulness.
12
+ - Removed `browserslist`. Use `swcEnvTargets` instead (TODO: add this option).
13
+ - Custom workers have been removed. You should use `swSrc`.
14
+ - Removed `extendDefaultRuntimeCaching`. Use the spread syntax instead (use `import { defaultCache } from "@serwist/next/browser"` to import the default runtimeCaching array).
15
+ - Temporarily removed `fallbacks` to investigate module-friendly alternatives.
16
+ - Removed `swcMinify`.
17
+ - Removed `watchWorkersInDev`.
18
+ - Removed `cacheStartUrl`, `dynamicStartUrl`, and `dynamicStartUrl`. These shall be re-added only when their use cases are made more clear to me.
19
+ - Merged `workboxOptions` with the plugin's options.
20
+ - Removed `swc-loader`, `terser-minify`, `webpack-builders`,... (we now leverage `ChildCompilationPlugin` to compile workers - this change will be backported to `@ducanh2912/next-pwa@10`)
21
+ - Removed the ability to use GenerateSW. `@serwist/sw.installSerwist` is provided as a replacement.
22
+ - `swSrc` is now a required property.
23
+ - Moved minimum support Next.js version from `11.0.0` to `14.0.0`.
24
+ - Removed GenerateSW (replaced by `@serwist/sw.installSerwist`).
25
+ - See `examples/next-basic/app/sw.ts` to see how `installSerwist` should be used.
26
+ - Repurposed `@serwist/sw`.
27
+ - The old package might be reintroduced if there's demand.
28
+ - **Note:** This is just the initial release, and there is still a lot of ground to cover (a lot of legacy code to be removed, a lot of features to be reintroduced,...). Here's to a bright future for the project :\_)
29
+
30
+ ### Patch Changes
31
+
32
+ - Updated dependencies [[`e0313f0`](https://github.com/serwist/serwist/commit/e0313f02f661a07ccbe9edc64e44e1af6136c73e)]:
33
+ - @serwist/core@8.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Google LLC, 2019 ShadowWalker w@weiw.io https://weiw.io, 2023 Serwist
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-window
@@ -0,0 +1,271 @@
1
+ import type { TrustedScriptURL } from "trusted-types/lib";
2
+ import { SerwistEventTarget } from "./utils/SerwistEventTarget.js";
3
+ /**
4
+ * A class to aid in handling service worker registration, updates, and
5
+ * reacting to service worker lifecycle events.
6
+ *
7
+ * @fires `@serwist/window.Serwist.message`
8
+ * @fires `@serwist/window.Serwist.installed`
9
+ * @fires `@serwist/window.Serwist.waiting`
10
+ * @fires `@serwist/window.Serwist.controlling`
11
+ * @fires `@serwist/window.Serwist.activated`
12
+ * @fires `@serwist/window.Serwist.redundant`
13
+ */
14
+ export declare class Serwist extends SerwistEventTarget {
15
+ private readonly _scriptURL;
16
+ private readonly _registerOptions;
17
+ private _updateFoundCount;
18
+ private readonly _swDeferred;
19
+ private readonly _activeDeferred;
20
+ private readonly _controllingDeferred;
21
+ private _registrationTime;
22
+ private _isUpdate?;
23
+ private _compatibleControllingSW?;
24
+ private _registration?;
25
+ private _sw?;
26
+ private readonly _ownSWs;
27
+ private _externalSW?;
28
+ private _waitingTimeout?;
29
+ /**
30
+ * Creates a new Serwist instance with a script URL and service worker
31
+ * options. The script URL and options are the same as those used when
32
+ * calling [navigator.serviceWorker.register(scriptURL, options)](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register).
33
+ *
34
+ * @param scriptURL The service worker script
35
+ * associated with this instance. Using a
36
+ * [`TrustedScriptURL`](https://web.dev/trusted-types/) is supported.
37
+ * @param registerOptions The service worker options associated
38
+ * with this instance.
39
+ */
40
+ constructor(scriptURL: string | TrustedScriptURL, registerOptions?: {});
41
+ /**
42
+ * Registers a service worker for this instances script URL and service
43
+ * worker options. By default this method delays registration until after
44
+ * the window has loaded.
45
+ *
46
+ * @param options
47
+ */
48
+ register({ immediate, }?: {
49
+ /**
50
+ * Setting this to true will register the service worker immediately,
51
+ * even if the window has not loaded (not recommended).
52
+ */
53
+ immediate?: boolean;
54
+ }): Promise<ServiceWorkerRegistration | undefined>;
55
+ /**
56
+ * Checks for updates of the registered service worker.
57
+ */
58
+ update(): Promise<void>;
59
+ /**
60
+ * Resolves to the service worker registered by this instance as soon as it
61
+ * is active. If a service worker was already controlling at registration
62
+ * time then it will resolve to that if the script URLs (and optionally
63
+ * script versions) match, otherwise it will wait until an update is found
64
+ * and activates.
65
+ *
66
+ * @returns
67
+ */
68
+ get active(): Promise<ServiceWorker>;
69
+ /**
70
+ * Resolves to the service worker registered by this instance as soon as it
71
+ * is controlling the page. If a service worker was already controlling at
72
+ * registration time then it will resolve to that if the script URLs (and
73
+ * optionally script versions) match, otherwise it will wait until an update
74
+ * is found and starts controlling the page.
75
+ * Note: the first time a service worker is installed it will active but
76
+ * not start controlling the page unless `clients.claim()` is called in the
77
+ * service worker.
78
+ *
79
+ * @returns
80
+ */
81
+ get controlling(): Promise<ServiceWorker>;
82
+ /**
83
+ * Resolves with a reference to a service worker that matches the script URL
84
+ * of this instance, as soon as it's available.
85
+ *
86
+ * If, at registration time, there's already an active or waiting service
87
+ * worker with a matching script URL, it will be used (with the waiting
88
+ * service worker taking precedence over the active service worker if both
89
+ * match, since the waiting service worker would have been registered more
90
+ * recently).
91
+ * If there's no matching active or waiting service worker at registration
92
+ * time then the promise will not resolve until an update is found and starts
93
+ * installing, at which point the installing service worker is used.
94
+ *
95
+ * @returns
96
+ */
97
+ getSW(): Promise<ServiceWorker>;
98
+ /**
99
+ * Sends the passed data object to the service worker registered by this
100
+ * instance (via `@serwist/window.Serwist.getSW`) and resolves
101
+ * with a response (if any).
102
+ *
103
+ * A response can be set in a message handler in the service worker by
104
+ * calling `event.ports[0].postMessage(...)`, which will resolve the promise
105
+ * returned by `messageSW()`. If no response is set, the promise will never
106
+ * resolve.
107
+ *
108
+ * @param data An object to send to the service worker
109
+ * @returns
110
+ */
111
+ messageSW(data: object): Promise<any>;
112
+ /**
113
+ * Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's
114
+ * currently in the `waiting` state associated with the current registration.
115
+ *
116
+ * If there is no current registration or no service worker is `waiting`,
117
+ * calling this will have no effect.
118
+ */
119
+ messageSkipWaiting(): void;
120
+ /**
121
+ * Checks for a service worker already controlling the page and returns
122
+ * it if its script URL matches.
123
+ *
124
+ * @private
125
+ * @returns
126
+ */
127
+ private _getControllingSWIfCompatible;
128
+ /**
129
+ * Registers a service worker for this instances script URL and register
130
+ * options and tracks the time registration was complete.
131
+ *
132
+ * @private
133
+ */
134
+ private _registerScript;
135
+ /**
136
+ * @private
137
+ */
138
+ private readonly _onUpdateFound;
139
+ /**
140
+ * @private
141
+ * @param originalEvent
142
+ */
143
+ private readonly _onStateChange;
144
+ /**
145
+ * @private
146
+ * @param originalEvent
147
+ */
148
+ private readonly _onControllerChange;
149
+ /**
150
+ * @private
151
+ * @param originalEvent
152
+ */
153
+ private readonly _onMessage;
154
+ }
155
+ /**
156
+ * The `message` event is dispatched any time a `postMessage` is received.
157
+ *
158
+ * @event workbox-window.Workbox#message
159
+ * @type {SerwistEvent}
160
+ * @property {*} data The `data` property from the original `message` event.
161
+ * @property {Event} originalEvent The original [`message`]{@link https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent}
162
+ * event.
163
+ * @property {string} type `message`.
164
+ * @property {MessagePort[]} ports The `ports` value from `originalEvent`.
165
+ * @property {Workbox} target The `Workbox` instance.
166
+ */
167
+ /**
168
+ * The `installed` event is dispatched if the state of a
169
+ * {@link workbox-window.Workbox} instance's
170
+ * {@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw|registered service worker}
171
+ * changes to `installed`.
172
+ *
173
+ * Then can happen either the very first time a service worker is installed,
174
+ * or after an update to the current service worker is found. In the case
175
+ * of an update being found, the event's `isUpdate` property will be `true`.
176
+ *
177
+ * @event workbox-window.Workbox#installed
178
+ * @type {SerwistEvent}
179
+ * @property {ServiceWorker} sw The service worker instance.
180
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
181
+ * event.
182
+ * @property {boolean|undefined} isUpdate True if a service worker was already
183
+ * controlling when this `Workbox` instance called `register()`.
184
+ * @property {boolean|undefined} isExternal True if this event is associated
185
+ * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
186
+ * @property {string} type `installed`.
187
+ * @property {Workbox} target The `Workbox` instance.
188
+ */
189
+ /**
190
+ * The `waiting` event is dispatched if the state of a
191
+ * {@link workbox-window.Workbox} instance's
192
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}
193
+ * changes to `installed` and then doesn't immediately change to `activating`.
194
+ * It may also be dispatched if a service worker with the same
195
+ * [`scriptURL`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/scriptURL}
196
+ * was already waiting when the {@link workbox-window.Workbox#register}
197
+ * method was called.
198
+ *
199
+ * @event workbox-window.Workbox#waiting
200
+ * @type {SerwistEvent}
201
+ * @property {ServiceWorker} sw The service worker instance.
202
+ * @property {Event|undefined} originalEvent The original
203
+ * [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
204
+ * event, or `undefined` in the case where the service worker was waiting
205
+ * to before `.register()` was called.
206
+ * @property {boolean|undefined} isUpdate True if a service worker was already
207
+ * controlling when this `Workbox` instance called `register()`.
208
+ * @property {boolean|undefined} isExternal True if this event is associated
209
+ * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
210
+ * @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with
211
+ * a matching `scriptURL` was already waiting when this `Workbox`
212
+ * instance called `register()`.
213
+ * @property {string} type `waiting`.
214
+ * @property {Workbox} target The `Workbox` instance.
215
+ */
216
+ /**
217
+ * The `controlling` event is dispatched if a
218
+ * [`controllerchange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/oncontrollerchange}
219
+ * fires on the service worker [container]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer}
220
+ * and the [`scriptURL`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/scriptURL}
221
+ * of the new [controller]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/controller}
222
+ * matches the `scriptURL` of the `Workbox` instance's
223
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}.
224
+ *
225
+ * @event workbox-window.Workbox#controlling
226
+ * @type {SerwistEvent}
227
+ * @property {ServiceWorker} sw The service worker instance.
228
+ * @property {Event} originalEvent The original [`controllerchange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/oncontrollerchange}
229
+ * event.
230
+ * @property {boolean|undefined} isUpdate True if a service worker was already
231
+ * controlling when this service worker was registered.
232
+ * @property {boolean|undefined} isExternal True if this event is associated
233
+ * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
234
+ * @property {string} type `controlling`.
235
+ * @property {Workbox} target The `Workbox` instance.
236
+ */
237
+ /**
238
+ * The `activated` event is dispatched if the state of a
239
+ * {@link workbox-window.Workbox} instance's
240
+ * {@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw|registered service worker}
241
+ * changes to `activated`.
242
+ *
243
+ * @event workbox-window.Workbox#activated
244
+ * @type {SerwistEvent}
245
+ * @property {ServiceWorker} sw The service worker instance.
246
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
247
+ * event.
248
+ * @property {boolean|undefined} isUpdate True if a service worker was already
249
+ * controlling when this `Workbox` instance called `register()`.
250
+ * @property {boolean|undefined} isExternal True if this event is associated
251
+ * with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
252
+ * @property {string} type `activated`.
253
+ * @property {Workbox} target The `Workbox` instance.
254
+ */
255
+ /**
256
+ * The `redundant` event is dispatched if the state of a
257
+ * {@link workbox-window.Workbox} instance's
258
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}
259
+ * changes to `redundant`.
260
+ *
261
+ * @event workbox-window.Workbox#redundant
262
+ * @type {SerwistEvent}
263
+ * @property {ServiceWorker} sw The service worker instance.
264
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
265
+ * event.
266
+ * @property {boolean|undefined} isUpdate True if a service worker was already
267
+ * controlling when this `Workbox` instance called `register()`.
268
+ * @property {string} type `redundant`.
269
+ * @property {Workbox} target The `Workbox` instance.
270
+ */
271
+ //# sourceMappingURL=Serwist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Serwist.d.ts","sourceRoot":"","sources":["../src/Serwist.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAgBnE;;;;;;;;;;GAUG;AACH,qBAAa,OAAQ,SAAQ,kBAAkB;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4B;IACvD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAC5D,OAAO,CAAC,iBAAiB,CAAK;IAG9B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA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CAAC,cAAc,CAqF7B;IAEF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAuBlC;IAEF;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,UAAU,CA2BzB;CACH;AAKD;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;GAeG"}
@@ -0,0 +1,5 @@
1
+ import { messageSW } from "./messageSW.js";
2
+ import { Serwist } from "./Serwist.js";
3
+ export { messageSW, Serwist };
4
+ export * from "./utils/SerwistEvent.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AAG9B,cAAc,yBAAyB,CAAC"}