@broberg/pwa 0.1.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/dist/sw.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ export { S as SKIP_WAITING, a as SKIP_WAITING_MESSAGE, b as SkipWaitingMessage } from './message-CBBmtYuB.js';
2
+
3
+ /**
4
+ * The minimal slice of a service-worker global scope this helper needs.
5
+ * Kept as a local interface so the package doesn't pull in the `webworker`
6
+ * TS lib (which clashes with `dom`) and stays trivially testable.
7
+ */
8
+ interface SkipWaitingScope {
9
+ addEventListener(type: "message", listener: (event: {
10
+ data?: unknown;
11
+ }) => void): void;
12
+ skipWaiting(): Promise<void> | void;
13
+ }
14
+ /**
15
+ * Wire the service-worker side of the update handshake: when the client calls
16
+ * `applyUpdate()` (posts `SKIP_WAITING`), the worker activates immediately.
17
+ *
18
+ * Call it once inside your service worker, before other setup:
19
+ *
20
+ * ```ts
21
+ * import { listenForSkipWaiting } from "@broberg/pwa/sw";
22
+ * listenForSkipWaiting();
23
+ * ```
24
+ *
25
+ * Serwist/Workbox users: keep `skipWaiting: false` (so activation is
26
+ * user-gated by the banner, not automatic) and `clientsClaim: true`.
27
+ */
28
+ declare function listenForSkipWaiting(scope?: SkipWaitingScope): void;
29
+
30
+ export { type SkipWaitingScope, listenForSkipWaiting };
package/dist/sw.js ADDED
@@ -0,0 +1,16 @@
1
+ import { SKIP_WAITING } from './chunk-ERNF6MZL.js';
2
+ export { SKIP_WAITING, SKIP_WAITING_MESSAGE } from './chunk-ERNF6MZL.js';
3
+
4
+ // src/sw.ts
5
+ function listenForSkipWaiting(scope) {
6
+ const target = scope ?? globalThis;
7
+ target.addEventListener("message", (event) => {
8
+ if (event.data?.type === SKIP_WAITING) {
9
+ void target.skipWaiting();
10
+ }
11
+ });
12
+ }
13
+
14
+ export { listenForSkipWaiting };
15
+ //# sourceMappingURL=sw.js.map
16
+ //# sourceMappingURL=sw.js.map
package/dist/sw.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sw.ts"],"names":[],"mappings":";;;;AAgCO,SAAS,qBAAqB,KAAA,EAAgC;AACnE,EAAA,MAAM,SACJ,KAAA,IAAU,UAAA;AACZ,EAAA,MAAA,CAAO,gBAAA,CAAiB,SAAA,EAAW,CAAC,KAAA,KAAU;AAC5C,IAAA,IAAK,KAAA,CAAM,IAAA,EAA4B,IAAA,KAAS,YAAA,EAAc;AAC5D,MAAA,KAAK,OAAO,WAAA,EAAY;AAAA,IAC1B;AAAA,EACF,CAAC,CAAA;AACH","file":"sw.js","sourcesContent":["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"]}
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@broberg/pwa",
3
+ "version": "0.1.0",
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
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/index.cjs"
20
+ },
21
+ "./react": {
22
+ "types": "./dist/react.d.ts",
23
+ "import": "./dist/react.js",
24
+ "require": "./dist/react.cjs"
25
+ },
26
+ "./sw": {
27
+ "types": "./dist/sw.d.ts",
28
+ "import": "./dist/sw.js",
29
+ "require": "./dist/sw.cjs"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "build": "tsup",
34
+ "test": "vitest run",
35
+ "typecheck": "tsc --noEmit"
36
+ },
37
+ "peerDependencies": {
38
+ "react": ">=18.0.0"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "react": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@testing-library/react": "^16.0.0",
47
+ "@types/react": "^19.0.0",
48
+ "happy-dom": "^15.0.0",
49
+ "react": "^19.0.0",
50
+ "react-dom": "^19.0.0",
51
+ "tsup": "^8.3.0",
52
+ "typescript": "^5.6.0",
53
+ "vitest": "^2.1.0"
54
+ },
55
+ "keywords": [
56
+ "pwa",
57
+ "progressive-web-app",
58
+ "service-worker",
59
+ "update",
60
+ "skipwaiting",
61
+ "new-version",
62
+ "add-to-home-screen",
63
+ "install",
64
+ "offline",
65
+ "serwist",
66
+ "workbox",
67
+ "react",
68
+ "broberg"
69
+ ],
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/broberg-ai/components.git",
73
+ "directory": "packages/pwa"
74
+ },
75
+ "publishConfig": {
76
+ "access": "public"
77
+ }
78
+ }