@serwist/window 9.0.0-preview.9 → 9.0.1
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/dist/Serwist.d.ts +7 -9
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/index.internal.d.ts +3 -0
- package/dist/index.internal.d.ts.map +1 -0
- package/dist/index.internal.js +7 -0
- package/dist/index.js +3 -7
- package/dist/messageSW.d.ts +3 -4
- package/dist/messageSW.d.ts.map +1 -1
- package/dist/utils/isCurrentPageOutOfScope.d.ts +2 -0
- package/dist/utils/isCurrentPageOutOfScope.d.ts.map +1 -0
- package/package.json +17 -6
- package/src/Serwist.ts +10 -16
- package/src/index.internal.ts +3 -0
- package/src/messageSW.ts +3 -4
- package/src/utils/isCurrentPageOutOfScope.ts +5 -0
package/dist/Serwist.d.ts
CHANGED
|
@@ -95,23 +95,21 @@ export declare class Serwist extends SerwistEventTarget {
|
|
|
95
95
|
getSW(): Promise<ServiceWorker>;
|
|
96
96
|
/**
|
|
97
97
|
* Sends the passed data object to the service worker registered by this
|
|
98
|
-
* instance (via
|
|
99
|
-
* with a response (if any).
|
|
98
|
+
* instance (via `getSW`) and resolves with a response (if any).
|
|
100
99
|
*
|
|
101
|
-
* A response can be
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* resolve.
|
|
100
|
+
* A response can be sent by calling `event.ports[0].postMessage(...)`, which will
|
|
101
|
+
* resolve the promise returned by `messageSW()`. If no response is sent, the promise
|
|
102
|
+
* will never resolve.
|
|
105
103
|
*
|
|
106
104
|
* @param data An object to send to the service worker
|
|
107
105
|
* @returns
|
|
108
106
|
*/
|
|
109
107
|
messageSW(data: any): Promise<any>;
|
|
110
108
|
/**
|
|
111
|
-
* Sends a `{type:
|
|
112
|
-
* currently
|
|
109
|
+
* Sends a `{ type: "SKIP_WAITING" }` message to the service worker that is
|
|
110
|
+
* currently waiting and associated with the current registration.
|
|
113
111
|
*
|
|
114
|
-
* If there is no current registration or no service worker is
|
|
112
|
+
* If there is no current registration, or no service worker is waiting,
|
|
115
113
|
* calling this will have no effect.
|
|
116
114
|
*/
|
|
117
115
|
messageSkipWaiting(): void;
|
package/dist/Serwist.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAiBnE;;;;;;;;;;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,CAA2C;IACvE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2C;IAC3E,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA2C;IAEhF,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,SAAS,CAAC,CAAU;IAC5B,OAAO,CAAC,wBAAwB,CAAC,CAAgB;IACjD,OAAO,CAAC,aAAa,CAAC,CAA4B;IAClD,OAAO,CAAC,GAAG,CAAC,CAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,WAAW,CAAC,CAAgB;IACpC,OAAO,CAAC,eAAe,CAAC,CAAS;IAEjC;;;;;;;;OAQG;gBACS,SAAS,EAAE,MAAM,GAAG,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src/index.internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAE7E,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Deferred, logger } from '
|
|
1
|
+
import { Deferred, logger } from 'serwist/internal';
|
|
2
|
+
import { isCurrentPageOutOfScope } from './index.internal.js';
|
|
2
3
|
|
|
3
4
|
const messageSW = (sw, data)=>{
|
|
4
5
|
return new Promise((resolve)=>{
|
|
@@ -126,12 +127,7 @@ class Serwist extends SerwistEventTarget {
|
|
|
126
127
|
logger.debug("A service worker with a different script URL is currently controlling the page. The browser is now fetching the new script now...");
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
-
const scopeURL = new URL(this._registerOptions.scope || this._scriptURL.toString(), document.baseURI);
|
|
131
|
-
const scopeURLBasePath = new URL("./", scopeURL.href).pathname;
|
|
132
|
-
return !location.pathname.startsWith(scopeURLBasePath);
|
|
133
|
-
};
|
|
134
|
-
if (currentPageIsOutOfScope()) {
|
|
130
|
+
if (isCurrentPageOutOfScope(this._registerOptions.scope || this._scriptURL.toString())) {
|
|
135
131
|
logger.warn("The current page is not in scope for the registered service worker. Was this a mistake?");
|
|
136
132
|
}
|
|
137
133
|
}
|
package/dist/messageSW.d.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Sends a data object to a service worker via `postMessage` and resolves with
|
|
3
3
|
* a response (if any).
|
|
4
4
|
*
|
|
5
|
-
* A response can be
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* resolve.
|
|
5
|
+
* A response can be sent by calling `event.ports[0].postMessage(...)`, which will
|
|
6
|
+
* resolve the promise returned by `messageSW()`. If no response is sent, the promise
|
|
7
|
+
* will never resolve.
|
|
9
8
|
*
|
|
10
9
|
* @param sw The service worker to send the message to.
|
|
11
10
|
* @param data An object to send to the service worker.
|
package/dist/messageSW.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageSW.d.ts","sourceRoot":"","sources":["../src/messageSW.ts"],"names":[],"mappings":"AAQA
|
|
1
|
+
{"version":3,"file":"messageSW.d.ts","sourceRoot":"","sources":["../src/messageSW.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,OAAQ,aAAa,QAAQ,GAAG,KAAG,QAAQ,GAAG,CAQnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isCurrentPageOutOfScope.d.ts","sourceRoot":"","sources":["../../src/utils/isCurrentPageOutOfScope.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,UAAW,MAAM,YAIpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/window",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simplifies communications with Serwist packages running in the service worker",
|
|
6
6
|
"files": [
|
|
@@ -18,26 +18,37 @@
|
|
|
18
18
|
],
|
|
19
19
|
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
20
20
|
"license": "MIT",
|
|
21
|
-
"repository": "serwist/serwist",
|
|
21
|
+
"repository": "https://github.com/serwist/serwist",
|
|
22
22
|
"bugs": "https://github.com/serwist/serwist/issues",
|
|
23
23
|
"homepage": "https://serwist.pages.dev",
|
|
24
24
|
"main": "./dist/index.js",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
|
+
"typesVersions": {
|
|
27
|
+
"*": {
|
|
28
|
+
"internal": [
|
|
29
|
+
"./dist/index.internal.d.ts"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
26
33
|
"exports": {
|
|
27
34
|
".": {
|
|
28
35
|
"types": "./dist/index.d.ts",
|
|
29
36
|
"default": "./dist/index.js"
|
|
30
37
|
},
|
|
38
|
+
"./internal": {
|
|
39
|
+
"types": "./dist/index.internal.d.ts",
|
|
40
|
+
"default": "./dist/index.internal.js"
|
|
41
|
+
},
|
|
31
42
|
"./package.json": "./package.json"
|
|
32
43
|
},
|
|
33
44
|
"dependencies": {
|
|
34
45
|
"@types/trusted-types": "2.0.7",
|
|
35
|
-
"
|
|
46
|
+
"serwist": "9.0.0"
|
|
36
47
|
},
|
|
37
48
|
"devDependencies": {
|
|
38
|
-
"rollup": "4.
|
|
39
|
-
"typescript": "5.
|
|
40
|
-
"@serwist/
|
|
49
|
+
"rollup": "4.14.3",
|
|
50
|
+
"typescript": "5.5.0-dev.20240415",
|
|
51
|
+
"@serwist/configs": "9.0.1"
|
|
41
52
|
},
|
|
42
53
|
"peerDependencies": {
|
|
43
54
|
"typescript": ">=5.0.0"
|
package/src/Serwist.ts
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { Deferred, logger } from "
|
|
9
|
+
import { Deferred, logger } from "serwist/internal";
|
|
10
10
|
import type { TrustedScriptURL } from "trusted-types/lib";
|
|
11
11
|
|
|
12
12
|
import { messageSW } from "./messageSW.js";
|
|
13
13
|
import type { SerwistLifecycleEventMap } from "./utils/SerwistEvent.js";
|
|
14
14
|
import { SerwistEvent } from "./utils/SerwistEvent.js";
|
|
15
15
|
import { SerwistEventTarget } from "./utils/SerwistEventTarget.js";
|
|
16
|
+
import { isCurrentPageOutOfScope } from "./utils/isCurrentPageOutOfScope.js";
|
|
16
17
|
import { urlsMatch } from "./utils/urlsMatch.js";
|
|
17
18
|
|
|
18
19
|
// The time a SW must be in the waiting phase before we can conclude
|
|
@@ -172,12 +173,7 @@ export class Serwist extends SerwistEventTarget {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
const scopeURL = new URL(this._registerOptions.scope || this._scriptURL.toString(), document.baseURI);
|
|
177
|
-
const scopeURLBasePath = new URL("./", scopeURL.href).pathname;
|
|
178
|
-
return !location.pathname.startsWith(scopeURLBasePath);
|
|
179
|
-
};
|
|
180
|
-
if (currentPageIsOutOfScope()) {
|
|
176
|
+
if (isCurrentPageOutOfScope(this._registerOptions.scope || this._scriptURL.toString())) {
|
|
181
177
|
logger.warn("The current page is not in scope for the registered service worker. Was this a mistake?");
|
|
182
178
|
}
|
|
183
179
|
}
|
|
@@ -255,13 +251,11 @@ export class Serwist extends SerwistEventTarget {
|
|
|
255
251
|
|
|
256
252
|
/**
|
|
257
253
|
* Sends the passed data object to the service worker registered by this
|
|
258
|
-
* instance (via
|
|
259
|
-
* with a response (if any).
|
|
254
|
+
* instance (via `getSW`) and resolves with a response (if any).
|
|
260
255
|
*
|
|
261
|
-
* A response can be
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* resolve.
|
|
256
|
+
* A response can be sent by calling `event.ports[0].postMessage(...)`, which will
|
|
257
|
+
* resolve the promise returned by `messageSW()`. If no response is sent, the promise
|
|
258
|
+
* will never resolve.
|
|
265
259
|
*
|
|
266
260
|
* @param data An object to send to the service worker
|
|
267
261
|
* @returns
|
|
@@ -273,10 +267,10 @@ export class Serwist extends SerwistEventTarget {
|
|
|
273
267
|
}
|
|
274
268
|
|
|
275
269
|
/**
|
|
276
|
-
* Sends a `{type:
|
|
277
|
-
* currently
|
|
270
|
+
* Sends a `{ type: "SKIP_WAITING" }` message to the service worker that is
|
|
271
|
+
* currently waiting and associated with the current registration.
|
|
278
272
|
*
|
|
279
|
-
* If there is no current registration or no service worker is
|
|
273
|
+
* If there is no current registration, or no service worker is waiting,
|
|
280
274
|
* calling this will have no effect.
|
|
281
275
|
*/
|
|
282
276
|
messageSkipWaiting(): void {
|
package/src/messageSW.ts
CHANGED
|
@@ -10,10 +10,9 @@
|
|
|
10
10
|
* Sends a data object to a service worker via `postMessage` and resolves with
|
|
11
11
|
* a response (if any).
|
|
12
12
|
*
|
|
13
|
-
* A response can be
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* resolve.
|
|
13
|
+
* A response can be sent by calling `event.ports[0].postMessage(...)`, which will
|
|
14
|
+
* resolve the promise returned by `messageSW()`. If no response is sent, the promise
|
|
15
|
+
* will never resolve.
|
|
17
16
|
*
|
|
18
17
|
* @param sw The service worker to send the message to.
|
|
19
18
|
* @param data An object to send to the service worker.
|