@broberg/pwa 0.5.0 → 0.6.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.
- package/README.md +20 -0
- package/dist/pwa-sw.global.js +20 -0
- package/dist/pwa-sw.global.js.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -8,6 +8,26 @@ as one small, framework- and bundler-agnostic package instead of a fifth copy.
|
|
|
8
8
|
npm i @broberg/pwa
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## 0.6.0 — a classic service worker can use it too: `pwa-sw.global.js` (F021.10)
|
|
12
|
+
|
|
13
|
+
A service worker in `public/` is a static file and cannot `import` — so
|
|
14
|
+
`@broberg/pwa/sw` (an ES module) was out of reach. Now:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
cp node_modules/@broberg/pwa/dist/pwa-sw.global.js public/ # e.g. in "prebuild"
|
|
18
|
+
```
|
|
19
|
+
```js
|
|
20
|
+
// public/sw.js
|
|
21
|
+
importScripts('/sw.global.js'); // @broberg/webpush, if you use it
|
|
22
|
+
importScripts('/pwa-sw.global.js'); // «Opdatér nu» works — the listener is attached for you
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Do not call `listenForSkipWaiting` again in that worker (listeners add up).
|
|
26
|
+
`self.BrobergPwa = { listenForSkipWaiting, SKIP_WAITING }` is there if you need
|
|
27
|
+
the constant. The file is named `pwa-sw.global.js` so it can sit beside
|
|
28
|
+
webpush's `sw.global.js` without overwriting it. Exported as
|
|
29
|
+
`@broberg/pwa/sw.global`. Additive — nothing else changed.
|
|
30
|
+
|
|
11
31
|
## 0.5.0 — PNG icons, so «Add to Home Screen» on an iPhone shows the logo (F021.9)
|
|
12
32
|
|
|
13
33
|
New `pwa-icons` bin + `@broberg/pwa/raster` — see «PNG icons» below. Additive:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// src/message.ts
|
|
4
|
+
var SKIP_WAITING = "SKIP_WAITING";
|
|
5
|
+
|
|
6
|
+
// src/sw.ts
|
|
7
|
+
function listenForSkipWaiting(scope) {
|
|
8
|
+
const target = scope ?? globalThis;
|
|
9
|
+
target.addEventListener("message", (event) => {
|
|
10
|
+
if (event.data?.type === SKIP_WAITING) {
|
|
11
|
+
void target.skipWaiting();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/sw.global.ts
|
|
17
|
+
listenForSkipWaiting(self);
|
|
18
|
+
self.BrobergPwa = { listenForSkipWaiting, SKIP_WAITING };
|
|
19
|
+
})();
|
|
20
|
+
//# sourceMappingURL=pwa-sw.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/message.ts","../src/sw.ts","../src/sw.global.ts"],"sourcesContent":["/**\n * The single source of the client↔service-worker \"activate the waiting worker\"\n * message. Both the client controller (`applyUpdate`) and the SW helper\n * (`listenForSkipWaiting`) import it so the contract can never drift.\n */\nexport const SKIP_WAITING = \"SKIP_WAITING\" as const;\n\nexport const SKIP_WAITING_MESSAGE = { type: SKIP_WAITING } as const;\n\nexport type SkipWaitingMessage = typeof SKIP_WAITING_MESSAGE;\n","import { SKIP_WAITING } from \"./message.js\";\n\nexport { SKIP_WAITING, SKIP_WAITING_MESSAGE } from \"./message.js\";\nexport type { SkipWaitingMessage } from \"./message.js\";\n\n/**\n * The minimal slice of a service-worker global scope this helper needs.\n * Kept as a local interface so the package doesn't pull in the `webworker`\n * TS lib (which clashes with `dom`) and stays trivially testable.\n */\nexport interface SkipWaitingScope {\n addEventListener(\n type: \"message\",\n listener: (event: { data?: unknown }) => void,\n ): void;\n skipWaiting(): Promise<void> | void;\n}\n\n/**\n * Wire the service-worker side of the update handshake: when the client calls\n * `applyUpdate()` (posts `SKIP_WAITING`), the worker activates immediately.\n *\n * Call it once inside your service worker, before other setup:\n *\n * ```ts\n * import { listenForSkipWaiting } from \"@broberg/pwa/sw\";\n * listenForSkipWaiting();\n * ```\n *\n * Serwist/Workbox users: keep `skipWaiting: false` (so activation is\n * user-gated by the banner, not automatic) and `clientsClaim: true`.\n */\nexport function listenForSkipWaiting(scope?: SkipWaitingScope): void {\n const target =\n scope ?? (globalThis as unknown as SkipWaitingScope);\n target.addEventListener(\"message\", (event) => {\n if ((event.data as { type?: string })?.type === SKIP_WAITING) {\n void target.skipWaiting();\n }\n });\n}\n","// F021.10 — CLASSIC-script build of the service-worker half (sales-F001.7).\n//\n// A service worker in `public/` is a static file: it never passes through a\n// bundler and cannot `import` from node_modules, so `@broberg/pwa/sw` (an ES\n// module) was out of reach and each app would have copied listenForSkipWaiting.\n// Same pattern as @broberg/webpush's sw.global.js:\n//\n// // public/sw.js\n// importScripts('/sw.global.js'); // @broberg/webpush\n// importScripts('/pwa-sw.global.js'); // this file — «Opdatér nu» works\n//\n// The listener is attached on load; do NOT call listenForSkipWaiting again\n// (addEventListener is additive). The file is named pwa-sw.global.js so it can\n// sit in public/ beside webpush's sw.global.js without overwriting it.\nimport { listenForSkipWaiting, SKIP_WAITING } from \"./sw\";\n\nlistenForSkipWaiting(self as unknown as Parameters<typeof listenForSkipWaiting>[0]);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\n(self as any).BrobergPwa = { listenForSkipWaiting, SKIP_WAITING };\n"],"mappings":";;;AAKO,MAAM,eAAe;;;AC2BrB,WAAS,qBAAqB,OAAgC;AACnE,UAAM,SACJ,SAAU;AACZ,WAAO,iBAAiB,WAAW,CAAC,UAAU;AAC5C,UAAK,MAAM,MAA4B,SAAS,cAAc;AAC5D,aAAK,OAAO,YAAY;AAAA,MAC1B;AAAA,IACF,CAAC;AAAA,EACH;;;ACxBA,uBAAqB,IAA6D;AAGlF,EAAC,KAAa,aAAa,EAAE,sBAAsB,aAAa;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/pwa",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Fleet PWA primitive: a framework-agnostic service-worker update-detection controller (new-version-available lifecycle) + a React hook and unstyled banner skeleton + a service-worker skip-waiting helper. Zero runtime deps; ship-dark.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"import": "./dist/raster.js",
|
|
44
44
|
"require": "./dist/raster.cjs"
|
|
45
45
|
},
|
|
46
|
+
"./sw.global": {
|
|
47
|
+
"default": "./dist/pwa-sw.global.js"
|
|
48
|
+
},
|
|
46
49
|
"./package.json": "./package.json"
|
|
47
50
|
},
|
|
48
51
|
"scripts": {
|