@unplugin-pwa/core 0.0.1 → 0.0.3

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.
Files changed (65) hide show
  1. package/dist/additional-manifest-entries.d.mts +10 -0
  2. package/dist/additional-manifest-entries.mjs +60 -0
  3. package/dist/build-pwa-asset.d.mts +18 -0
  4. package/dist/build-pwa-asset.mjs +87 -0
  5. package/dist/config.d.mts +75 -0
  6. package/dist/config.mjs +293 -0
  7. package/dist/constants.d.mts +31 -0
  8. package/dist/constants.mjs +41 -0
  9. package/dist/context-types.d.mts +155 -0
  10. package/dist/context.d.mts +15 -0
  11. package/dist/context.mjs +58 -0
  12. package/dist/create-generate-register-sw-script.d.mts +15 -0
  13. package/dist/create-generate-register-sw-script.mjs +27 -0
  14. package/dist/create-web-manifest-html-link.d.mts +13 -0
  15. package/dist/create-web-manifest-html-link.mjs +21 -0
  16. package/dist/dev/prepare-sw-names-and-glob-directory.d.mts +18 -0
  17. package/dist/dev/prepare-sw-names-and-glob-directory.mjs +75 -0
  18. package/dist/dev/prepare-temp-folder.d.mts +9 -0
  19. package/dist/dev/prepare-temp-folder.mjs +44 -0
  20. package/dist/dual-sw-utilities.d.mts +9 -0
  21. package/dist/dual-sw-utilities.mjs +16 -0
  22. package/dist/generate-register-sw.d.mts +14 -0
  23. package/dist/generate-register-sw.mjs +22 -0
  24. package/dist/generate-web-manifest.d.mts +9 -0
  25. package/dist/generate-web-manifest.mjs +12 -0
  26. package/dist/helpers.d.mts +33 -0
  27. package/dist/helpers.mjs +132 -0
  28. package/dist/html.d.mts +8 -0
  29. package/dist/html.mjs +28 -0
  30. package/dist/index.d.mts +9 -0
  31. package/dist/inject-generate-register-sw.d.mts +16 -0
  32. package/dist/inject-generate-register-sw.mjs +22 -0
  33. package/dist/inject-web-manifest-html-link.d.mts +14 -0
  34. package/dist/inject-web-manifest-html-link.mjs +20 -0
  35. package/dist/inspector-utils.d.mts +26 -0
  36. package/dist/inspector-utils.mjs +47 -0
  37. package/dist/logs.d.mts +8 -0
  38. package/dist/logs.mjs +19 -0
  39. package/dist/package-zuOn_aH6.mjs +10 -0
  40. package/dist/prepare-pwa-context.d.mts +11 -0
  41. package/dist/prepare-pwa-context.mjs +135 -0
  42. package/dist/prepare-sw-names.d.mts +11 -0
  43. package/dist/prepare-sw-names.mjs +45 -0
  44. package/dist/pwa-assets/build.d.mts +9 -0
  45. package/dist/pwa-assets/build.mjs +15 -0
  46. package/dist/pwa-assets/config.d.mts +10 -0
  47. package/dist/pwa-assets/config.mjs +136 -0
  48. package/dist/pwa-assets/dev.d.mts +11 -0
  49. package/dist/pwa-assets/dev.mjs +35 -0
  50. package/dist/pwa-assets/generator.d.mts +20 -0
  51. package/dist/pwa-assets/generator.mjs +31 -0
  52. package/dist/pwa-assets/html.d.mts +11 -0
  53. package/dist/pwa-assets/html.mjs +47 -0
  54. package/dist/pwa-assets/manifest.d.mts +10 -0
  55. package/dist/pwa-assets/manifest.mjs +15 -0
  56. package/dist/pwa-assets/options.d.mts +9 -0
  57. package/dist/pwa-assets/options.mjs +34 -0
  58. package/dist/pwa-assets/types.d.mts +9 -0
  59. package/dist/pwa-assets/utils.d.mts +11 -0
  60. package/dist/pwa-assets/utils.mjs +48 -0
  61. package/dist/resolve-inspector-dist.d.mts +11 -0
  62. package/dist/resolve-inspector-dist.mjs +25 -0
  63. package/dist/types-B60e7Nq4.d.mts +67 -0
  64. package/dist/types-BhwjnGLn.d.mts +703 -0
  65. package/package.json +1 -1
@@ -0,0 +1,155 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { r as PWAAssetsGenerator } from "./types-B60e7Nq4.mjs";
9
+ import { C as VitePWAOptions, T as WebManifestData, m as RegisterSWData, w as VitePWAStrategy, y as ResolvedVitePWAOptions } from "./types-BhwjnGLn.mjs";
10
+ import { Hookable } from "hookable";
11
+ import { BuildResult, SWType } from "@vite-pwa/workbox-build/types";
12
+ import { BuildGenerateSWOptions, BuildWithSourcesResult } from "@vite-pwa/workbox-build/build/types";
13
+ import { InjectManifestStrategyOptions, SelfDestroyingStrategyOptions } from "@vite-pwa/workbox-build/config/types";
14
+ export type Bundler = 'vite' | 'vite-legacy' | 'webpack' | 'rspack';
15
+ export type BuildSWType<B extends Bundler, T extends SWType> = B extends 'vite' ? import('@vite-pwa/workbox-build/build/vite/types').BuildServiceWorkerOptions<T> : B extends 'vite-legacy' ? import('@vite-pwa/workbox-build/build/vite/legacy-types').LegacyBuildServiceWorkerOptions<T> : import('@vite-pwa/workbox-build/build/rolldown/types').BuildServiceWorkerOptions<T>;
16
+ export type ExtractStrategy<UserStrategy extends VitePWAStrategy> = UserStrategy extends 'generateSW' ? 'generate-sw' : UserStrategy extends 'generate-sw' ? 'generate-sw' : UserStrategy extends 'buildSW' ? 'build-sw' : UserStrategy extends 'build-sw' ? 'build-sw' : UserStrategy extends 'injectManifest' ? 'inject-manifest' : UserStrategy extends 'inject-manifest' ? 'inject-manifest' : UserStrategy extends 'selfDestroySW' ? 'self-destroy-sw' : UserStrategy extends 'self-destroy-sw' ? 'self-destroy-sw' : 'generate-sw';
17
+ export interface PWABuildContext {
18
+ generateSW: () => Promise<BuildResult>;
19
+ buildSW: () => Promise<BuildWithSourcesResult>;
20
+ injectManifest: () => Promise<BuildResult>;
21
+ selfDestroyingSW: () => Promise<boolean>;
22
+ }
23
+ export interface SWNames {
24
+ hasNames: boolean;
25
+ name: string;
26
+ classic: string;
27
+ module: string;
28
+ }
29
+ export interface DevSWNames extends SWNames {
30
+ path: string;
31
+ classicPath: string;
32
+ modulePath: string;
33
+ devSWDest: string;
34
+ }
35
+ /**
36
+ * The type of PWA asset.
37
+ */
38
+ export type PwaAsset = 'register-sw' | 'virtual-register-sw';
39
+ /**
40
+ * Custom PWA asset resolver for `registerSW.js` and PWA virtual modules.
41
+ *
42
+ * When `virtual-register-sw` the virtualName won't be undefined:
43
+ * - 'register' for `virtual:pwa-register`
44
+ * - 'vue' for `virtual:pwa-register/vue`
45
+ * - 'svelte' for `virtual:pwa-register/svelte`
46
+ * - 'react' for `virtual:pwa-register/react`
47
+ * - 'react-legacy' for `virtual:pwa-register/react-legacy`
48
+ * - 'preact' for `virtual:pwa-register/preact`
49
+ * - 'solid' for `virtual:pwa-register/solid`
50
+ *
51
+ * @param asset The asset type to resolve
52
+ * @param virtualName The virtual module name when asset is `virtual-register-sw`
53
+ * @return The generated PWA asset
54
+ */
55
+ export type CustomPwaAssetResolver = (asset: PwaAsset, virtualName?: string) => Promise<string>;
56
+ export interface PWABuildDevContext<B extends Bundler, T extends SWType> {
57
+ options: {
58
+ /**
59
+ * The current service worker name.
60
+ */
61
+ swName: string;
62
+ /**
63
+ * The current service worker type.
64
+ */
65
+ swType: WorkerType;
66
+ swGenerated: boolean;
67
+ registerSWGenerated: boolean;
68
+ registerVirtualSWGenerated: boolean;
69
+ hmrEntryPointGenerated: boolean;
70
+ navigateFallbackAllowlist?: RegExp[];
71
+ swAssetKeys: Set<string>;
72
+ swAssetsPaths: Map<string, string>;
73
+ tempFolder: string;
74
+ /**
75
+ * Hook to allow remove prefixes: for example _nuxt/
76
+ */
77
+ mapSWSourcemapFile?: (url: string) => string | undefined;
78
+ /**
79
+ * Names and paths to resolve service workers.
80
+ */
81
+ swNames: DevSWNames;
82
+ /**
83
+ * The globDirectory to cache only entry point.
84
+ */
85
+ globDirectory: string;
86
+ };
87
+ generateSW: (options: Partial<BuildGenerateSWOptions<T>>) => Promise<BuildResult>;
88
+ buildSW: (options: Partial<BuildSWType<B, T>>) => Promise<BuildWithSourcesResult>;
89
+ injectManifest: (options: Partial<InjectManifestStrategyOptions>) => Promise<BuildResult>;
90
+ selfDestroyingSW: (options: SelfDestroyingStrategyOptions) => Promise<boolean>;
91
+ }
92
+ export interface ConfigurePWAOptions {
93
+ outDir: string;
94
+ /**
95
+ * Used to generate the dontCache
96
+ */
97
+ immutableAssets: string;
98
+ cwd: string;
99
+ }
100
+ export type HookResult = void | Promise<void>;
101
+ export interface PWAHooks {
102
+ 'context:ready': (error?: unknown) => HookResult;
103
+ 'service-worker:generated': () => HookResult;
104
+ 'service-worker:switched': () => HookResult;
105
+ }
106
+ export interface PWAPluginContext<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType> {
107
+ bundler: B;
108
+ version: string;
109
+ strategy: ExtractStrategy<UserStrategy>;
110
+ consumerOptions: Partial<VitePWAOptions<UserStrategy, T>>;
111
+ externalConfigurationLoader: boolean;
112
+ resolvedOptions: Partial<ResolvedVitePWAOptions<ExtractStrategy<UserStrategy>, T>>;
113
+ useImportRegister: boolean;
114
+ devEnvironment: boolean;
115
+ isPreview: boolean;
116
+ hmrRequiresSwitcher?: true;
117
+ pwaAssetsGenerator: Promise<PWAAssetsGenerator | undefined>;
118
+ build: PWABuildContext;
119
+ dev: PWABuildDevContext<B, T>;
120
+ publicDir: string;
121
+ rootDir: string;
122
+ outDir: string;
123
+ base: string;
124
+ sources: Set<string>;
125
+ swNames: SWNames;
126
+ /**
127
+ * When using `inject-manifest` this hook will resolve if the service worker is inside public directory.
128
+ *
129
+ * Integrations can override this hook, for example, Vite integration will check the `publicDir`, or Nuxt will
130
+ * check Nitro public dirs.
131
+ */
132
+ injectManifestSWAtPublicDir: () => boolean;
133
+ /**
134
+ * The custom resolver to resolve PWA assets for `registerSW.js` and virtual PWA modules.
135
+ */
136
+ customPwaAssetResolver: CustomPwaAssetResolver;
137
+ /**
138
+ * Returns the PWA web manifest url for the manifest link:
139
+ * <link rel="manifest" href="<webManifestUrl>" />
140
+ *
141
+ * Will also return if the manifest will require credentials:
142
+ * <link rel="manifest" href="<webManifestUrl>" crossorigin="use-credentials" />
143
+ */
144
+ webManifestData: () => WebManifestData | undefined;
145
+ /**
146
+ * How the service worker is being registered in the application.
147
+ *
148
+ * This option will help some integrations to inject the corresponding script in the head.
149
+ */
150
+ registerSWData: () => Promise<RegisterSWData & {
151
+ module: boolean;
152
+ } | undefined>;
153
+ runBuild: () => Promise<BuildResult | boolean>;
154
+ hooks: Hookable<PWAHooks>;
155
+ }
@@ -0,0 +1,15 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { C as VitePWAOptions, w as VitePWAStrategy } from "./types-BhwjnGLn.mjs";
9
+ import { Bundler, PWAPluginContext } from "./context-types.mjs";
10
+ import { SWType } from "@vite-pwa/workbox-build/types";
11
+ export declare function createPWAContext<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(bundler: B, userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<B, UserStrategy, T>;
12
+ export declare function createVitePWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'vite', UserStrategy, T>;
13
+ export declare function createViteLegacyPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'vite-legacy', UserStrategy, T>;
14
+ export declare function createWebpackPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'webpack', UserStrategy, T>;
15
+ export declare function createRspackPWAContext<UserStrategy extends VitePWAStrategy, T extends SWType>(userOptions?: Partial<VitePWAOptions<UserStrategy, T>>): PWAPluginContext<'rspack', UserStrategy, T>;
@@ -0,0 +1,58 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { t as version } from "./package-zuOn_aH6.mjs";
9
+ import { preparePWAContext } from "./prepare-pwa-context.mjs";
10
+ import process from "node:process";
11
+ import { Hookable } from "hookable";
12
+ // src/context.ts
13
+ function createPWAContext(bundler, userOptions = {}) {
14
+ return preparePWAContext({
15
+ bundler,
16
+ version,
17
+ strategy: void 0,
18
+ consumerOptions: userOptions,
19
+ externalConfigurationLoader: false,
20
+ resolvedOptions: void 0,
21
+ useImportRegister: false,
22
+ devEnvironment: false,
23
+ isPreview: false,
24
+ pwaAssetsGenerator: Promise.resolve(void 0),
25
+ build: void 0,
26
+ dev: void 0,
27
+ base: void 0,
28
+ swNames: {
29
+ hasNames: false,
30
+ name: "",
31
+ classic: "",
32
+ module: ""
33
+ },
34
+ sources: /* @__PURE__ */ new Set(),
35
+ outDir: void 0,
36
+ publicDir: void 0,
37
+ rootDir: process.cwd(),
38
+ customPwaAssetResolver: void 0,
39
+ webManifestData: void 0,
40
+ registerSWData: void 0,
41
+ runBuild: void 0,
42
+ injectManifestSWAtPublicDir: void 0,
43
+ hooks: new Hookable()
44
+ });
45
+ }
46
+ function createVitePWAContext(userOptions = {}) {
47
+ return createPWAContext("vite", userOptions);
48
+ }
49
+ function createViteLegacyPWAContext(userOptions = {}) {
50
+ return createPWAContext("vite-legacy", userOptions);
51
+ }
52
+ function createWebpackPWAContext(userOptions = {}) {
53
+ return createPWAContext("webpack", userOptions);
54
+ }
55
+ function createRspackPWAContext(userOptions = {}) {
56
+ return createPWAContext("rspack", userOptions);
57
+ }
58
+ export { createPWAContext, createRspackPWAContext, createViteLegacyPWAContext, createVitePWAContext, createWebpackPWAContext };
@@ -0,0 +1,15 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { PWAPluginContext } from "./context-types.mjs";
9
+ /**
10
+ * Creates the `registerSW.js` script to be added to the HTML entry point.
11
+ * @param ctx The PWA Context.
12
+ * @param dev For dev server
13
+ * @param injectAtDev Inject the script at dev server?
14
+ */
15
+ export declare function createGenerateRegisterSW(ctx: PWAPluginContext<any, any, any>, dev: boolean, injectAtDev?: boolean): Promise<string | undefined>;
@@ -0,0 +1,27 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { FILE_SW_REGISTER } from "./constants.mjs";
9
+ import { isDualServiceWorker } from "./dual-sw-utilities.mjs";
10
+ import { generateRegisterSW } from "./generate-register-sw.mjs";
11
+ // src/create-generate-register-sw-script.ts
12
+ /**
13
+ * Creates the `registerSW.js` script to be added to the HTML entry point.
14
+ * @param ctx The PWA Context.
15
+ * @param dev For dev server
16
+ * @param injectAtDev Inject the script at dev server?
17
+ */
18
+ async function createGenerateRegisterSW(ctx, dev, injectAtDev = true) {
19
+ if (dev && !injectAtDev) return;
20
+ const options = isDualServiceWorker(ctx) ? " type=\"module\"" : "";
21
+ if (ctx.resolvedOptions.injectRegister === "inline") return `<script id="unplugin-pwa:inline-sw"${options}>${await generateRegisterSW(ctx)}<\/script>`;
22
+ if (ctx.resolvedOptions.injectRegister === "script" || ctx.resolvedOptions.injectRegister === "script-defer") {
23
+ const hasDefer = ctx.resolvedOptions.injectRegister === "script-defer";
24
+ return `<script id="unplugin-pwa:register-sw" src="${dev ? ctx.resolvedOptions.base : ctx.resolvedOptions.buildBase}${FILE_SW_REGISTER}"${hasDefer ? " defer" : ""}${options}><\/script>`;
25
+ }
26
+ }
27
+ export { createGenerateRegisterSW };
@@ -0,0 +1,13 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { PWAPluginContext } from "./context-types.mjs";
9
+ /**
10
+ * Creates the PWA web manifest link to be added to the HTML entry point.
11
+ * @param ctx The PWA Context.
12
+ */
13
+ export declare function createWebManifestHtmlLink(ctx: PWAPluginContext<any, any, any>): string;
@@ -0,0 +1,21 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ // src/create-web-manifest-html-link.ts
9
+ /**
10
+ * Creates the PWA web manifest link to be added to the HTML entry point.
11
+ * @param ctx The PWA Context.
12
+ */
13
+ function createWebManifestHtmlLink(ctx) {
14
+ const options = ctx.resolvedOptions;
15
+ const crossorigin = options.useCredentials ? " crossorigin=\"use-credentials\"" : "";
16
+ if (ctx.devEnvironment) {
17
+ const name = `${options.base}${options.manifestFilename || "manifest.webmanifest"}`;
18
+ return options.manifest ? `<link rel="manifest" href="${name}"${crossorigin}>` : "";
19
+ } else return options.manifest ? `<link rel="manifest" href="${options.buildBase}${options.manifestFilename}"${crossorigin}>` : "";
20
+ }
21
+ export { createWebManifestHtmlLink };
@@ -0,0 +1,18 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { w as VitePWAStrategy } from "../types-BhwjnGLn.mjs";
9
+ import { Bundler, PWAPluginContext } from "../context-types.mjs";
10
+ import { SWType } from "@vite-pwa/workbox-build/types";
11
+ /**
12
+ * Prepare the service worker names, the glob directory and the temp folder.
13
+ *
14
+ * **NOTE**: if the PWA plugin context has `swNames.hasNames` set to `true` at the dev options, this function will return immediately.
15
+ *
16
+ * @param ctx The PWA Vite plugin context.
17
+ */
18
+ export declare function prepareSwNamesAndGlobDirectory<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): Promise<void>;
@@ -0,0 +1,75 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { isDualServiceWorker } from "../dual-sw-utilities.mjs";
9
+ import { prepareTempFolder } from "./prepare-temp-folder.mjs";
10
+ import { normalizePath, resolveSWNames } from "@vite-pwa/workbox-build/utils/resolve-sw-names";
11
+ import path from "node:path";
12
+ import process from "node:process";
13
+ // src/dev/prepare-sw-names-and-glob-directory.ts
14
+ /**
15
+ * Prepare the service worker names, the glob directory and the temp folder.
16
+ *
17
+ * **NOTE**: if the PWA plugin context has `swNames.hasNames` set to `true` at the dev options, this function will return immediately.
18
+ *
19
+ * @param ctx The PWA Vite plugin context.
20
+ */
21
+ async function prepareSwNamesAndGlobDirectory(ctx) {
22
+ if (ctx.dev.options.swNames.hasNames) return;
23
+ let options;
24
+ let swSrc;
25
+ switch (ctx.strategy) {
26
+ case "generate-sw":
27
+ swSrc = "";
28
+ options = ctx.resolvedOptions.generateSW;
29
+ break;
30
+ case "inject-manifest":
31
+ options = ctx.resolvedOptions.injectManifest;
32
+ swSrc = ctx.resolvedOptions.injectManifest.swSrc;
33
+ break;
34
+ case "build-sw":
35
+ options = ctx.resolvedOptions.buildSW;
36
+ swSrc = ctx.resolvedOptions.buildSW.swSrc;
37
+ }
38
+ if (options) {
39
+ await prepareTempFolder(ctx);
40
+ const internalDevOptions = ctx.dev.options;
41
+ const folder = internalDevOptions.tempFolder;
42
+ const root = process.cwd();
43
+ let relativeSwDest;
44
+ let devSWDest;
45
+ if (path.isAbsolute(ctx.outDir)) devSWDest = normalizePath(path.relative(root, path.resolve(folder, options.swDest)));
46
+ else {
47
+ const outputFolder = path.resolve(process.cwd(), ctx.outDir);
48
+ relativeSwDest = path.relative(outputFolder, options.swDest);
49
+ devSWDest = normalizePath(path.relative(root, path.resolve(folder, relativeSwDest)));
50
+ }
51
+ const { swDest, swDestPath, classicSWDest, classicSWDestPath, moduleSWDest, moduleSWDestPath } = resolveSWNames(devSWDest, swSrc, ctx.strategy === "generate-sw");
52
+ if (isDualServiceWorker(ctx)) {
53
+ if (ctx.resolvedOptions.devOptions?.type === "module") {
54
+ internalDevOptions.swName = moduleSWDest;
55
+ internalDevOptions.swType = "module";
56
+ } else {
57
+ internalDevOptions.swName = classicSWDest;
58
+ internalDevOptions.swType = "classic";
59
+ }
60
+ } else {
61
+ internalDevOptions.swName = swDest;
62
+ internalDevOptions.swType = ctx.resolvedOptions.devOptions?.type === "module" ? "module" : "classic";
63
+ }
64
+ internalDevOptions.globDirectory = normalizePath(path.relative(root, folder));
65
+ internalDevOptions.swNames.devSWDest = devSWDest;
66
+ internalDevOptions.swNames.path = normalizePath(path.resolve(root, swDest));
67
+ internalDevOptions.swNames.name = swDestPath;
68
+ internalDevOptions.swNames.classic = classicSWDestPath;
69
+ internalDevOptions.swNames.classicPath = normalizePath(path.resolve(root, classicSWDest));
70
+ internalDevOptions.swNames.module = moduleSWDestPath;
71
+ internalDevOptions.swNames.modulePath = normalizePath(path.resolve(root, moduleSWDest));
72
+ internalDevOptions.swNames.hasNames = true;
73
+ }
74
+ }
75
+ export { prepareSwNamesAndGlobDirectory };
@@ -0,0 +1,9 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { PWAPluginContext } from "../context-types.mjs";
9
+ export declare function prepareTempFolder(ctx: PWAPluginContext<any, any, any>): Promise<void>;
@@ -0,0 +1,44 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import process from "node:process";
11
+ import { pathToFileURL } from "node:url";
12
+ // src/dev/prepare-temp-folder.ts
13
+ function tryStatSync(file) {
14
+ try {
15
+ return fs.statSync(file, { throwIfNoEntry: false });
16
+ } catch {}
17
+ }
18
+ function findNearestNodeModules(basedir) {
19
+ while (basedir) {
20
+ const pkgPath = path.join(basedir, "node_modules");
21
+ if (tryStatSync(pkgPath)?.isDirectory()) return pkgPath;
22
+ const nextBasedir = path.dirname(basedir);
23
+ if (nextBasedir === basedir) break;
24
+ basedir = nextBasedir;
25
+ }
26
+ return null;
27
+ }
28
+ function resolveTempFolder() {
29
+ const base = pathToFileURL(`${process.cwd()}/`).href;
30
+ const nodeModulesDir = typeof process.versions.deno === "string" ? void 0 : findNearestNodeModules(base);
31
+ return nodeModulesDir ? path.resolve(nodeModulesDir, ".pwa-dev-dist") : path.resolve(process.cwd(), base, ".pwa-dev-dist");
32
+ }
33
+ async function prepareTempFolder(ctx) {
34
+ const internalOptions = ctx.dev.options;
35
+ const tempFolderResolver = ctx.resolvedOptions.devOptions?.resolveTempFolder;
36
+ const tempFolder = internalOptions.tempFolder ? internalOptions.tempFolder : tempFolderResolver ? await tempFolderResolver() : resolveTempFolder();
37
+ fs.rmSync(tempFolder, {
38
+ force: true,
39
+ recursive: true
40
+ });
41
+ fs.mkdirSync(tempFolder, { recursive: true });
42
+ ctx.dev.options.tempFolder = tempFolder;
43
+ }
44
+ export { prepareTempFolder };
@@ -0,0 +1,9 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { PWAPluginContext } from "./context-types.mjs";
9
+ export declare function isDualServiceWorker(ctx: PWAPluginContext<any, any, any>): boolean;
@@ -0,0 +1,16 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ // src/dual-sw-utilities.ts
9
+ function isDualServiceWorker(ctx) {
10
+ switch (ctx.strategy) {
11
+ case "generate-sw": return ctx.resolvedOptions.generateSW?.swType === "classic-and-module";
12
+ case "build-sw": return ctx.resolvedOptions.buildSW?.swType === "classic-and-module";
13
+ }
14
+ return false;
15
+ }
16
+ export { isDualServiceWorker };
@@ -0,0 +1,14 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { PWAPluginContext } from "./context-types.mjs";
9
+ /**
10
+ * Generates `registerSW.js` file for the service worker registration.
11
+ * @param ctx The PWA plugin context.
12
+ * @return The code of `registerSW.js` or `undefined` if it is not required.
13
+ */
14
+ export declare function generateRegisterSW(ctx: PWAPluginContext<any, any, any>): Promise<string | undefined>;
@@ -0,0 +1,22 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import "./constants.mjs";
9
+ import { existsSync } from "node:fs";
10
+ import { resolve } from "node:path";
11
+ // src/generate-register-sw.ts
12
+ /**
13
+ * Generates `registerSW.js` file for the service worker registration.
14
+ * @param ctx The PWA plugin context.
15
+ * @return The code of `registerSW.js` or `undefined` if it is not required.
16
+ */
17
+ async function generateRegisterSW(ctx) {
18
+ if (ctx.resolvedOptions.injectRegister === "auto") ctx.resolvedOptions.injectRegister = ctx.useImportRegister ? null : "script";
19
+ if (!(ctx.resolvedOptions.injectRegister === "script" || ctx.resolvedOptions.injectRegister === "script-defer") || existsSync(resolve(ctx.publicDir, "registerSW.js"))) return;
20
+ return await ctx.customPwaAssetResolver("register-sw");
21
+ }
22
+ export { generateRegisterSW };
@@ -0,0 +1,9 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { PWAPluginContext } from "./context-types.mjs";
9
+ export declare function generateWebManifest(ctx: PWAPluginContext<any, any, any>): string;
@@ -0,0 +1,12 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ // src/generate-web-manifest.ts
9
+ function generateWebManifest(ctx) {
10
+ return `${JSON.stringify(ctx.resolvedOptions.manifest, null, ctx.resolvedOptions.minify ? 0 : 2)}\n`;
11
+ }
12
+ export { generateWebManifest };
@@ -0,0 +1,33 @@
1
+ /*!
2
+ MIT License
3
+
4
+ Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
5
+
6
+ https://github.com/userquin/quini-pwa-monorepo/blob/main/LICENSE.
7
+ */
8
+ import { w as VitePWAStrategy } from "./types-BhwjnGLn.mjs";
9
+ import { Bundler, PWAPluginContext } from "./context-types.mjs";
10
+ import { ManifestEntry, SWType } from "@vite-pwa/workbox-build/types";
11
+ export declare function normalizePath(path: string): string;
12
+ export declare function resolveFrom(base: string, value: string): string;
13
+ export declare function resolveSWSrc(base: string, value: string): string;
14
+ export declare function isAbsolute(url: string): RegExpMatchArray | null;
15
+ export declare function resolveBasePath(base: string): string;
16
+ export declare function prepareAdditionalManifestEntriesGenerator(ctx: PWAPluginContext<any, any, any>): () => AsyncGenerator<string | ManifestEntry, undefined, void>;
17
+ /**
18
+ * Loads the default manifest and normalizes the manifest icons' purpose and scope_extensions.
19
+ *
20
+ * **NOTE**: this function calls `prepareManifest` to load the default manifest.
21
+ *
22
+ * @param ctx The resolved Vite PWA plugin context
23
+ */
24
+ export declare function normalizeManifest(ctx: PWAPluginContext<any, any, any>): void;
25
+ export declare function preparePWAAssetsGenerator<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): void;
26
+ /**
27
+ * Configures the PWA strategy at the resolved PWA options.
28
+ * @param ctx The PWA context.
29
+ * @param cwd The current working directory.
30
+ * @param outDir The output directory.
31
+ * @param immutableAssets The immutable assets directory.
32
+ */
33
+ export declare function preparePWAStrategy<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>, cwd: string, outDir: string, immutableAssets: string): Promise<void>;