@vuepress/plugin-pwa 2.0.0-beta.8 → 2.0.0-rc.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.
@@ -1,2 +1,2 @@
1
- export * from './usePwaEvent';
2
- export * from './useSkipWaiting';
1
+ export * from './usePwaEvent.js';
2
+ export * from './useSkipWaiting.js';
@@ -1,2 +1,2 @@
1
- export * from './usePwaEvent';
2
- export * from './useSkipWaiting';
1
+ export * from './usePwaEvent.js';
2
+ export * from './useSkipWaiting.js';
@@ -1,22 +1,13 @@
1
- import type { Emitter, Handler, WildcardHandler } from 'mitt';
1
+ import type { Emitter } from 'mitt';
2
2
  import type { InjectionKey } from 'vue';
3
- export interface PwaEvent extends Emitter {
4
- on(type: 'ready', handler: Handler<ServiceWorkerRegistration>): void;
5
- on(type: 'registered', handler: Handler<ServiceWorkerRegistration>): void;
6
- on(type: 'cached', handler: Handler<ServiceWorkerRegistration>): void;
7
- on(type: 'updatefound', handler: Handler<ServiceWorkerRegistration>): void;
8
- on(type: 'updated', handler: Handler<ServiceWorkerRegistration>): void;
9
- on(type: 'offline', handler: Handler<void>): void;
10
- on(type: 'error', handler: Handler<Error>): void;
11
- on(type: '*', handler: WildcardHandler): void;
12
- emit(type: 'ready', event: ServiceWorkerRegistration): void;
13
- emit(type: 'registered', event: ServiceWorkerRegistration): void;
14
- emit(type: 'cached', event: ServiceWorkerRegistration): void;
15
- emit(type: 'updatefound', event: ServiceWorkerRegistration): void;
16
- emit(type: 'updated', event: ServiceWorkerRegistration): void;
17
- emit(type: 'offline'): void;
18
- emit(type: 'error', event: Error): void;
19
- emit(type: '*', event?: any): void;
20
- }
3
+ export type PwaEvent = Emitter<{
4
+ ready: ServiceWorkerRegistration;
5
+ registered: ServiceWorkerRegistration;
6
+ cached: ServiceWorkerRegistration;
7
+ updatefound: ServiceWorkerRegistration;
8
+ updated: ServiceWorkerRegistration;
9
+ offline: void;
10
+ error: Error;
11
+ }>;
21
12
  export declare const pwaEventSymbol: InjectionKey<PwaEvent>;
22
13
  export declare const usePwaEvent: () => PwaEvent;
@@ -1,9 +1,9 @@
1
1
  import { inject } from 'vue';
2
2
  export const pwaEventSymbol = Symbol('pwaEvent');
3
3
  export const usePwaEvent = () => {
4
- const pawEvent = inject(pwaEventSymbol);
5
- if (!pawEvent) {
4
+ const pwaEvent = inject(pwaEventSymbol);
5
+ if (!pwaEvent) {
6
6
  throw new Error('usePwaEvent() is called without provider.');
7
7
  }
8
- return pawEvent;
8
+ return pwaEvent;
9
9
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@vuepress/client").ClientConfig;
2
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineClientConfig, withBase } from '@vuepress/client';
2
+ import mitt from 'mitt';
3
+ import { onMounted, provide } from 'vue';
4
+ import { pwaEventSymbol } from './composables/index.js';
5
+ const swFilename = __PWA_SW_FILENAME__;
6
+ export default defineClientConfig({
7
+ setup() {
8
+ if (__VUEPRESS_SSR__ || !swFilename)
9
+ return;
10
+ const log = (...args) => console.log('[@vuepress/plugin-pwa]', ...args);
11
+ // create event emitter and provide it
12
+ const event = mitt();
13
+ provide(pwaEventSymbol, event);
14
+ onMounted(async () => {
15
+ // lazy load register-service-worker
16
+ const { register } = await import('register-service-worker');
17
+ // Register service worker
18
+ register(withBase(swFilename), {
19
+ ready(registration) {
20
+ log('Service worker is active.');
21
+ event.emit('ready', registration);
22
+ },
23
+ registered(registration) {
24
+ log('Service worker has been registered.');
25
+ event.emit('registered', registration);
26
+ },
27
+ cached(registration) {
28
+ log('Content has been cached for offline use.');
29
+ event.emit('cached', registration);
30
+ },
31
+ updatefound(registration) {
32
+ log('New content is downloading.');
33
+ event.emit('updatefound', registration);
34
+ },
35
+ updated(registration) {
36
+ log('New content is available, please refresh.');
37
+ event.emit('updated', registration);
38
+ },
39
+ offline() {
40
+ log('No internet connection found. App is running in offline mode.');
41
+ event.emit('offline');
42
+ },
43
+ error(err) {
44
+ log('Error during service worker registration:', err);
45
+ event.emit('error', err);
46
+ },
47
+ });
48
+ });
49
+ },
50
+ });
@@ -1 +1 @@
1
- export * from './composables';
1
+ export * from './composables/index.js';
@@ -1 +1 @@
1
- export * from './composables';
1
+ export * from './composables/index.js';
@@ -1,3 +1,4 @@
1
1
  import type { App } from '@vuepress/core';
2
- import type { GenerateSWConfig } from 'workbox-build';
3
- export declare const generateServiceWorker: (app: App, serviceWorkerFilename: string, generateSWConfig: Partial<GenerateSWConfig>) => Promise<void>;
2
+ import type { GenerateSWOptions } from 'workbox-build';
3
+ export type GenerateSWConfig = Omit<GenerateSWOptions, 'swDest' | 'globDirectory'>;
4
+ export declare const generateServiceWorker: (app: App, serviceWorkerFilename: string, generateSWConfig: GenerateSWConfig) => Promise<void>;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateServiceWorker = void 0;
4
- const utils_1 = require("@vuepress/utils");
1
+ import { logger } from '@vuepress/utils';
5
2
  const assetsExtensions = [
6
3
  // basic
7
4
  'html',
@@ -20,9 +17,9 @@ const assetsExtensions = [
20
17
  'tff',
21
18
  'otf',
22
19
  ];
23
- const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfig) => {
20
+ export const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfig) => {
24
21
  // lazy-load workbox-build
25
- const generateSW = require('workbox-build/build/generate-sw');
22
+ const { generateSW } = await import('workbox-build');
26
23
  const globDirectory = app.dir.dest();
27
24
  const swDest = app.dir.dest(serviceWorkerFilename);
28
25
  const { warnings } = await generateSW({
@@ -35,6 +32,5 @@ const generateServiceWorker = async (app, serviceWorkerFilename, generateSWConfi
35
32
  globDirectory,
36
33
  swDest,
37
34
  });
38
- warnings.forEach((warning) => utils_1.logger.warn('[@vuepress/plugin-pwa]', warning));
35
+ warnings.forEach((warning) => logger.warn('[@vuepress/plugin-pwa]', warning));
39
36
  };
40
- exports.generateServiceWorker = generateServiceWorker;
@@ -1,4 +1,4 @@
1
- import { pwaPlugin } from './pwaPlugin';
2
- export * from './generateServiceWorker';
3
- export * from './pwaPlugin';
1
+ import { pwaPlugin } from './pwaPlugin.js';
2
+ export * from './generateServiceWorker.js';
3
+ export * from './pwaPlugin.js';
4
4
  export default pwaPlugin;
package/lib/node/index.js CHANGED
@@ -1,16 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- const pwaPlugin_1 = require("./pwaPlugin");
14
- __exportStar(require("./generateServiceWorker"), exports);
15
- __exportStar(require("./pwaPlugin"), exports);
16
- exports.default = pwaPlugin_1.pwaPlugin;
1
+ import { pwaPlugin } from './pwaPlugin.js';
2
+ export * from './generateServiceWorker.js';
3
+ export * from './pwaPlugin.js';
4
+ export default pwaPlugin;
@@ -1,9 +1,9 @@
1
1
  import type { Plugin } from '@vuepress/core';
2
- import type { GenerateSWConfig } from 'workbox-build';
2
+ import type { GenerateSWConfig } from './generateServiceWorker.js';
3
3
  /**
4
4
  * Options for @vuepress/plugin-pwa
5
5
  */
6
- export interface PwaPluginOptions extends Omit<GenerateSWConfig, 'swDest' | 'globDirectory'> {
6
+ export interface PwaPluginOptions extends GenerateSWConfig {
7
7
  /**
8
8
  * Filename of the generated service worker file
9
9
  *
@@ -14,4 +14,4 @@ export interface PwaPluginOptions extends Omit<GenerateSWConfig, 'swDest' | 'glo
14
14
  */
15
15
  serviceWorkerFilename?: string;
16
16
  }
17
- export declare const pwaPlugin: Plugin<PwaPluginOptions>;
17
+ export declare const pwaPlugin: ({ serviceWorkerFilename, ...generateSWConfig }?: PwaPluginOptions) => Plugin;
@@ -1,14 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pwaPlugin = void 0;
4
- const utils_1 = require("@vuepress/utils");
5
- const generateServiceWorker_1 = require("./generateServiceWorker");
6
- const pwaPlugin = ({ serviceWorkerFilename = 'service-worker.js', ...generateSWConfig }) => ({
7
- name: '@vuepress/plugin-pwa',
8
- clientAppSetupFiles: utils_1.path.resolve(__dirname, '../client/clientAppSetup.js'),
9
- define: {
10
- __PWA_SW_FILENAME__: serviceWorkerFilename,
11
- },
12
- onGenerated: (app) => utils_1.withSpinner('Generating service worker')(() => generateServiceWorker_1.generateServiceWorker(app, serviceWorkerFilename, generateSWConfig)),
13
- });
14
- exports.pwaPlugin = pwaPlugin;
1
+ import { getDirname, path, withSpinner } from '@vuepress/utils';
2
+ import { generateServiceWorker } from './generateServiceWorker.js';
3
+ const __dirname = getDirname(import.meta.url);
4
+ export const pwaPlugin = ({ serviceWorkerFilename = 'service-worker.js', ...generateSWConfig } = {}) => (app) => {
5
+ const plugin = {
6
+ name: '@vuepress/plugin-pwa',
7
+ };
8
+ if (app.env.isDev) {
9
+ return plugin;
10
+ }
11
+ return {
12
+ ...plugin,
13
+ clientConfigFile: path.resolve(__dirname, '../client/config.js'),
14
+ define: {
15
+ __PWA_SW_FILENAME__: serviceWorkerFilename,
16
+ },
17
+ onGenerated: (app) => withSpinner('Generating service worker')(() => generateServiceWorker(app, serviceWorkerFilename, generateSWConfig)),
18
+ };
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/plugin-pwa",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0-rc.0",
4
4
  "description": "VuePress plugin - progressive web application",
5
5
  "keywords": [
6
6
  "vuepress-plugin",
@@ -18,29 +18,31 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "author": "meteorlxy",
21
- "main": "lib/node/index.js",
22
- "types": "lib/node/index.d.ts",
21
+ "type": "module",
22
+ "exports": {
23
+ ".": "./lib/node/index.js",
24
+ "./client": "./lib/client/index.js",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "./lib/node/index.js",
28
+ "types": "./lib/node/index.d.ts",
23
29
  "files": [
24
30
  "lib"
25
31
  ],
26
- "scripts": {
27
- "build": "tsc -b tsconfig.build.json",
28
- "clean": "rimraf lib *.tsbuildinfo"
29
- },
30
32
  "dependencies": {
31
- "@vuepress/client": "2.0.0-beta.8",
32
- "@vuepress/core": "2.0.0-beta.8",
33
- "@vuepress/utils": "2.0.0-beta.8",
34
- "mitt": "^2.1.0",
33
+ "mitt": "^3.0.1",
35
34
  "register-service-worker": "^1.7.2",
36
- "vue": "^3.0.11",
37
- "workbox-build": "^6.1.2"
38
- },
39
- "devDependencies": {
40
- "@types/workbox-build": "^5.0.0"
35
+ "vue": "^3.3.8",
36
+ "workbox-build": "^7.0.0",
37
+ "@vuepress/client": "2.0.0-rc.0",
38
+ "@vuepress/core": "2.0.0-rc.0",
39
+ "@vuepress/utils": "2.0.0-rc.0"
41
40
  },
42
41
  "publishConfig": {
43
42
  "access": "public"
44
43
  },
45
- "gitHead": "5ab99126fcaecb845248fcf9d3c88c25ce8572cb"
46
- }
44
+ "scripts": {
45
+ "build": "tsc -b tsconfig.build.json",
46
+ "clean": "rimraf lib *.tsbuildinfo"
47
+ }
48
+ }
package/CHANGELOG.md DELETED
@@ -1,187 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.0.0-beta.8](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.7...v2.0.0-beta.8) (2021-04-11)
7
-
8
-
9
- ### Code Refactoring
10
-
11
- * normalize themes and plugins structure ([7781172](https://github.com/vuepress/vuepress-next/commit/77811722401bf1ed1fec44c64158ab0cd1ab3179))
12
-
13
-
14
- ### BREAKING CHANGES
15
-
16
- * client API that provided by plugins should be imported from `plugin-foo/lib/client`
17
-
18
-
19
-
20
-
21
-
22
- # [2.0.0-beta.7](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.6...v2.0.0-beta.7) (2021-04-09)
23
-
24
- **Note:** Version bump only for package @vuepress/plugin-pwa
25
-
26
-
27
-
28
-
29
-
30
- # [2.0.0-beta.6](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.5...v2.0.0-beta.6) (2021-03-26)
31
-
32
- **Note:** Version bump only for package @vuepress/plugin-pwa
33
-
34
-
35
-
36
-
37
-
38
- # [2.0.0-beta.5](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.4...v2.0.0-beta.5) (2021-03-26)
39
-
40
- **Note:** Version bump only for package @vuepress/plugin-pwa
41
-
42
-
43
-
44
-
45
-
46
- # [2.0.0-beta.4](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.3...v2.0.0-beta.4) (2021-03-20)
47
-
48
- **Note:** Version bump only for package @vuepress/plugin-pwa
49
-
50
-
51
-
52
-
53
-
54
- # [2.0.0-beta.1](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.0...v2.0.0-beta.1) (2021-03-13)
55
-
56
- **Note:** Version bump only for package @vuepress/plugin-pwa
57
-
58
-
59
-
60
-
61
-
62
- # [2.0.0-beta.0](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.26...v2.0.0-beta.0) (2021-03-13)
63
-
64
- **Note:** Version bump only for package @vuepress/plugin-pwa
65
-
66
-
67
-
68
-
69
-
70
- # [2.0.0-alpha.25](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.24...v2.0.0-alpha.25) (2021-02-20)
71
-
72
- **Note:** Version bump only for package @vuepress/plugin-pwa
73
-
74
-
75
-
76
-
77
-
78
- # [2.0.0-alpha.24](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.23...v2.0.0-alpha.24) (2021-02-13)
79
-
80
- **Note:** Version bump only for package @vuepress/plugin-pwa
81
-
82
-
83
-
84
-
85
-
86
- # [2.0.0-alpha.23](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.22...v2.0.0-alpha.23) (2021-02-10)
87
-
88
- **Note:** Version bump only for package @vuepress/plugin-pwa
89
-
90
-
91
-
92
-
93
-
94
- # [2.0.0-alpha.22](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.21...v2.0.0-alpha.22) (2021-02-10)
95
-
96
- **Note:** Version bump only for package @vuepress/plugin-pwa
97
-
98
-
99
-
100
-
101
-
102
- # [2.0.0-alpha.20](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.19...v2.0.0-alpha.20) (2021-02-04)
103
-
104
- **Note:** Version bump only for package @vuepress/plugin-pwa
105
-
106
-
107
-
108
-
109
-
110
- # [2.0.0-alpha.19](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.18...v2.0.0-alpha.19) (2021-01-24)
111
-
112
- **Note:** Version bump only for package @vuepress/plugin-pwa
113
-
114
-
115
-
116
-
117
-
118
- # [2.0.0-alpha.18](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.17...v2.0.0-alpha.18) (2021-01-17)
119
-
120
- **Note:** Version bump only for package @vuepress/plugin-pwa
121
-
122
-
123
-
124
-
125
-
126
- # [2.0.0-alpha.17](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.16...v2.0.0-alpha.17) (2021-01-13)
127
-
128
- **Note:** Version bump only for package @vuepress/plugin-pwa
129
-
130
-
131
-
132
-
133
-
134
- # [2.0.0-alpha.16](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.15...v2.0.0-alpha.16) (2021-01-11)
135
-
136
- **Note:** Version bump only for package @vuepress/plugin-pwa
137
-
138
-
139
-
140
-
141
-
142
- # [2.0.0-alpha.15](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.14...v2.0.0-alpha.15) (2021-01-04)
143
-
144
- **Note:** Version bump only for package @vuepress/plugin-pwa
145
-
146
-
147
-
148
-
149
-
150
- # [2.0.0-alpha.14](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.13...v2.0.0-alpha.14) (2021-01-03)
151
-
152
- **Note:** Version bump only for package @vuepress/plugin-pwa
153
-
154
-
155
-
156
-
157
-
158
- # [2.0.0-alpha.13](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.12...v2.0.0-alpha.13) (2020-12-23)
159
-
160
- **Note:** Version bump only for package @vuepress/plugin-pwa
161
-
162
-
163
-
164
-
165
-
166
- # [2.0.0-alpha.12](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.11...v2.0.0-alpha.12) (2020-12-19)
167
-
168
- **Note:** Version bump only for package @vuepress/plugin-pwa
169
-
170
-
171
-
172
-
173
-
174
- # [2.0.0-alpha.9](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.8...v2.0.0-alpha.9) (2020-12-16)
175
-
176
- **Note:** Version bump only for package @vuepress/plugin-pwa
177
-
178
-
179
-
180
-
181
-
182
- # [2.0.0-alpha.8](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.7...v2.0.0-alpha.8) (2020-12-11)
183
-
184
-
185
- ### Features
186
-
187
- * **plugin-pwa:** migrate pwa plugin ([aa54fd6](https://github.com/vuepress/vuepress-next/commit/aa54fd65aa77b32b97de0a38359f1ad07f96f566))
@@ -1,2 +0,0 @@
1
- declare const _default: import("@vuepress/client").ClientAppSetup;
2
- export default _default;
@@ -1,48 +0,0 @@
1
- import mitt from 'mitt';
2
- import { onMounted, provide } from 'vue';
3
- import { defineClientAppSetup, withBase } from '@vuepress/client';
4
- import { pwaEventSymbol } from './composables';
5
- const swFilename = __PWA_SW_FILENAME__;
6
- export default defineClientAppSetup(() => {
7
- if (__DEV__ || __SSR__ || !swFilename)
8
- return;
9
- const log = (...args) => console.log('[@vuepress/plugin-pwa]', ...args);
10
- // create event emitter and provide it
11
- const event = mitt();
12
- provide(pwaEventSymbol, event);
13
- onMounted(async () => {
14
- // lazy load register-service-worker
15
- const { register } = await import('register-service-worker');
16
- // Register service worker
17
- register(withBase(swFilename), {
18
- ready(registration) {
19
- log('Service worker is active.');
20
- event.emit('ready', registration);
21
- },
22
- registered(registration) {
23
- log('Service worker has been registered.');
24
- event.emit('registered', registration);
25
- },
26
- cached(registration) {
27
- log('Content has been cached for offline use.');
28
- event.emit('cached', registration);
29
- },
30
- updatefound(registration) {
31
- log('New content is downloading.');
32
- event.emit('updatefound', registration);
33
- },
34
- updated(registration) {
35
- log('New content is available, please refresh.');
36
- event.emit('updated', registration);
37
- },
38
- offline() {
39
- log('No internet connection found. App is running in offline mode.');
40
- event.emit('offline');
41
- },
42
- error(err) {
43
- log('Error during service worker registration:', err);
44
- event.emit('error', err);
45
- },
46
- });
47
- });
48
- });