@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,132 @@
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 { additionalManifestEntriesFactory } from "./additional-manifest-entries.mjs";
9
+ import { prepareManifest } from "./config.mjs";
10
+ import path from "node:path";
11
+ import { errStyle } from "@vite-pwa/workbox-build/utils/colors";
12
+ // src/helpers.ts
13
+ const normalizePathRegexp = /\\/g;
14
+ function normalizePath(path) {
15
+ return path.replace(normalizePathRegexp, "/");
16
+ }
17
+ function resolveFrom(base, value) {
18
+ return normalizePath(path.isAbsolute(value) ? path.relative(base, value) : path.join(base, value));
19
+ }
20
+ function resolveSWSrc(base, value) {
21
+ return normalizePath(path.isAbsolute(value) ? path.relative(base, value) : value);
22
+ }
23
+ function isAbsolute(url) {
24
+ return url.match(/^(?:[a-z]+:)?\/\//i);
25
+ }
26
+ function resolveBasePath(base) {
27
+ if (isAbsolute(base)) return base;
28
+ return !base.startsWith("/") && !base.startsWith("./") ? `/${base}` : base;
29
+ }
30
+ function prepareAdditionalManifestEntriesGenerator(ctx) {
31
+ return additionalManifestEntriesFactory(ctx, (url) => {
32
+ const buildBase = ctx.resolvedOptions.buildBase;
33
+ return path.resolve(ctx.publicDir, url.startsWith(buildBase) ? url.slice(buildBase.length) : url);
34
+ });
35
+ }
36
+ /**
37
+ * Loads the default manifest and normalizes the manifest icons' purpose and scope_extensions.
38
+ *
39
+ * **NOTE**: this function calls `prepareManifest` to load the default manifest.
40
+ *
41
+ * @param ctx The resolved Vite PWA plugin context
42
+ */
43
+ function normalizeManifest(ctx) {
44
+ prepareManifest(ctx.resolvedOptions);
45
+ const manifest = ctx.resolvedOptions.manifest;
46
+ if (manifest) {
47
+ if (manifest.icons) manifest.icons = manifest.icons.map((icon) => {
48
+ if (icon.purpose && Array.isArray(icon.purpose)) icon.purpose = icon.purpose.join(" ");
49
+ return icon;
50
+ });
51
+ if (manifest.shortcuts) manifest.shortcuts.forEach((shortcut) => {
52
+ if (shortcut.icons) shortcut.icons = shortcut.icons.map((icon) => {
53
+ if (icon.purpose && Array.isArray(icon.purpose)) icon.purpose = icon.purpose.join(" ");
54
+ return icon;
55
+ });
56
+ });
57
+ if (manifest.scope_extensions) manifest.scope_extensions = manifest.scope_extensions.map((scopeExtension) => {
58
+ return {
59
+ origin: scopeExtension.origin,
60
+ type: scopeExtension.type ?? "origin"
61
+ };
62
+ });
63
+ }
64
+ }
65
+ function preparePWAAssetsGenerator(ctx) {
66
+ if (ctx.resolvedOptions.pwaAssets && !ctx.resolvedOptions.pwaAssets.disabled) ctx.pwaAssetsGenerator = import("./pwa-assets/generator.mjs").then(({ loadInstructions }) => loadInstructions(ctx)).catch((e) => {
67
+ console.error([
68
+ "",
69
+ errStyle("cyan", `PWA v${ctx.version}`),
70
+ errStyle("yellow", "WARNING: you must install the following dev dependencies to use the PWA assets generator:"),
71
+ errStyle("yellow", "- \"@vite-pwa/assets-generator\""),
72
+ errStyle("yellow", "- \"sharp\" (should be installed when installing @vite-pwa/assets-generator)"),
73
+ errStyle("yellow", "- \"sharp-ico\" (should be installed when installing @vite-pwa/assets-generator)")
74
+ ].join("\n"), e);
75
+ return Promise.resolve(void 0);
76
+ });
77
+ }
78
+ /**
79
+ * Configures the PWA strategy at the resolved PWA options.
80
+ * @param ctx The PWA context.
81
+ * @param cwd The current working directory.
82
+ * @param outDir The output directory.
83
+ * @param immutableAssets The immutable assets directory.
84
+ */
85
+ async function preparePWAStrategy(ctx, cwd, outDir, immutableAssets) {
86
+ const outputPath = path.resolve(cwd, outDir);
87
+ let options;
88
+ switch (ctx.strategy) {
89
+ case "generate-sw":
90
+ ctx.resolvedOptions.generateSW ??= {};
91
+ options = ctx.resolvedOptions.generateSW;
92
+ break;
93
+ case "inject-manifest":
94
+ ctx.resolvedOptions.injectManifest ??= {};
95
+ options = ctx.resolvedOptions.injectManifest;
96
+ break;
97
+ case "build-sw":
98
+ ctx.resolvedOptions.buildSW ??= {};
99
+ options = ctx.resolvedOptions.buildSW;
100
+ }
101
+ if (options) {
102
+ Object.assign(options, { additionalManifestEntriesGenerator: prepareAdditionalManifestEntriesGenerator(ctx) });
103
+ Object.assign(options, { globDirectory: options.globDirectory ? normalizePath(path.relative(cwd, resolveFrom(cwd, options.globDirectory))) : normalizePath(path.relative(cwd, resolveFrom(cwd, outputPath))) });
104
+ if (!("dontCacheBustURLsMatching" in options)) {
105
+ let assetsOutputDir = path.relative(outputPath, path.resolve(outputPath, immutableAssets));
106
+ if (assetsOutputDir.at(-1) !== "/") assetsOutputDir += "/";
107
+ Object.assign(options, { dontCacheBustURLsMatching: new RegExp(`^${assetsOutputDir.replace(/^\.*\//, "")}`) });
108
+ }
109
+ if (ctx.strategy !== "generate-sw") {
110
+ if ("swSrc" in options) Object.assign(options, { swSrc: resolveSWSrc(cwd, options.swSrc) });
111
+ }
112
+ if (ctx.strategy === "generate-sw") {
113
+ if (ctx.resolvedOptions.registerType === "autoUpdate") {
114
+ ctx.resolvedOptions.generateSW.clientsClaim = true;
115
+ ctx.resolvedOptions.generateSW.skipWaiting = true;
116
+ }
117
+ }
118
+ if ("swDest" in options && options.swDest) {
119
+ if (path.dirname(path.resolve(cwd, options.swDest)) !== outputPath) Object.assign(options, { swDest: resolveFrom(outputPath, options.swDest) });
120
+ } else Object.assign(options, { swDest: resolveFrom(outputPath, "sw.js") });
121
+ } else if (!ctx.devEnvironment && ctx.strategy === "self-destroy-sw") {
122
+ const data = ctx.resolvedOptions.selfDestroying;
123
+ if (data) {
124
+ const entries = typeof data.swDest === "string" ? [data.swDest] : data.swDest;
125
+ const newDestSW = [];
126
+ for (const swDest of entries) if (path.dirname(path.resolve(cwd, swDest)) !== outputPath) newDestSW.push(resolveFrom(outputPath, swDest));
127
+ else newDestSW.push(swDest);
128
+ data.swDest = newDestSW;
129
+ }
130
+ }
131
+ }
132
+ export { isAbsolute, normalizeManifest, normalizePath, prepareAdditionalManifestEntriesGenerator, preparePWAAssetsGenerator, preparePWAStrategy, resolveBasePath, resolveFrom, resolveSWSrc };
@@ -0,0 +1,8 @@
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
+ export declare function checkForHtmlHead(html: string): string;
package/dist/html.mjs ADDED
@@ -0,0 +1,28 @@
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 { errStyle } from "@vite-pwa/workbox-build/utils/colors";
9
+ // src/html.ts
10
+ function checkForHtmlHead(html) {
11
+ if (!html.includes("</head>")) {
12
+ if (!html.includes("<body>")) {
13
+ console.warn([
14
+ "",
15
+ errStyle("yellow", "PWA WARNING:"),
16
+ "</head> and <body> tags not found in the html, the service worker and web manifest will not be injected."
17
+ ].join("\n"));
18
+ return html;
19
+ } else console.warn([
20
+ "",
21
+ errStyle("yellow", "PWA WARNING:"),
22
+ "</head> not found in the html, adding it to the html tag: add empty <head></head> to your html to remove this warning."
23
+ ].join("\n"));
24
+ return html.replace("<body>", `<head>\n</head>\n<body>`);
25
+ }
26
+ return html;
27
+ }
28
+ export { checkForHtmlHead };
@@ -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 { C as VitePWAOptions, S as StringLiteralUnion, T as WebManifestData, _ as ResolvedInjectManifest, a as IconPurpose, b as ScopeExtensionsType, c as ManifestOptions, d as ManifestShortcut, f as PWAAssetsIntegrationOptions, g as ResolvedGenerateSW, h as ResolvedBuildSW, i as ExternalVitePWAOptions, l as ManifestScreenshot, m as RegisterSWData, n as Display, o as IconResource, p as PWAAssetsOptions, r as DisplayOverride, s as LaunchHandlerClientMode, t as DevOptions, u as ManifestShareTarget, v as ResolvedPWAAssetsOptions, w as VitePWAStrategy, x as ShareTargetFiles, y as ResolvedVitePWAOptions } from "./types-BhwjnGLn.mjs";
9
+ export type { DevOptions, Display, DisplayOverride, ExternalVitePWAOptions, IconPurpose, IconResource, LaunchHandlerClientMode, ManifestOptions, ManifestScreenshot, ManifestShareTarget, ManifestShortcut, PWAAssetsIntegrationOptions, PWAAssetsOptions, RegisterSWData, ResolvedBuildSW, ResolvedGenerateSW, ResolvedInjectManifest, ResolvedPWAAssetsOptions, ResolvedVitePWAOptions, ScopeExtensionsType, ShareTargetFiles, StringLiteralUnion, VitePWAOptions, VitePWAStrategy, WebManifestData };
@@ -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
+ import { PWAPluginContext } from "./context-types.mjs";
9
+ /**
10
+ * Adds the `registerSW.js` script to the HTML entry point.
11
+ * @param html The HTML entry point.
12
+ * @param ctx The PWA Context.
13
+ * @param dev For dev server
14
+ * @param injectAtDev Inject the script at dev server?
15
+ */
16
+ export declare function injectGenerateRegisterSW(html: string, ctx: PWAPluginContext<any, any, any>, dev: boolean, injectAtDev?: boolean): 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 { createGenerateRegisterSW } from "./create-generate-register-sw-script.mjs";
9
+ import { checkForHtmlHead } from "./html.mjs";
10
+ // src/inject-generate-register-sw.ts
11
+ /**
12
+ * Adds the `registerSW.js` script to the HTML entry point.
13
+ * @param html 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 injectGenerateRegisterSW(html, ctx, dev, injectAtDev = true) {
19
+ const script = await createGenerateRegisterSW(ctx, dev, injectAtDev);
20
+ return script ? checkForHtmlHead(html).replace("</head>", `${script}</head>`) : html;
21
+ }
22
+ export { injectGenerateRegisterSW };
@@ -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
+ * Adds PWA web manifest link to the HTML entry point to the HTML entry point.
11
+ * @param html The HTML entry point.
12
+ * @param ctx The PWA Context.
13
+ */
14
+ export declare function injectWebManifestHtmlLink(html: string, ctx: PWAPluginContext<any, any, any>): string;
@@ -0,0 +1,20 @@
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 { createWebManifestHtmlLink } from "./create-web-manifest-html-link.mjs";
9
+ import { checkForHtmlHead } from "./html.mjs";
10
+ // src/inject-web-manifest-html-link.ts
11
+ /**
12
+ * Adds PWA web manifest link to the HTML entry point to the HTML entry point.
13
+ * @param html The HTML entry point.
14
+ * @param ctx The PWA Context.
15
+ */
16
+ function injectWebManifestHtmlLink(html, ctx) {
17
+ const link = createWebManifestHtmlLink(ctx);
18
+ return checkForHtmlHead(html).replace("</head>", `${link}</head>`);
19
+ }
20
+ export { injectWebManifestHtmlLink };
@@ -0,0 +1,26 @@
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 ManifestOptions, w as VitePWAStrategy } from "./types-BhwjnGLn.mjs";
9
+ import { Bundler, DevSWNames, ExtractStrategy, PWAPluginContext } from "./context-types.mjs";
10
+ import { SWType } from "@vite-pwa/workbox-build/types";
11
+ export declare function preparePWAConfigurationData<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): {
12
+ version: string;
13
+ base: string;
14
+ swEnabled: boolean;
15
+ strategy: ExtractStrategy<UserStrategy>;
16
+ swType: T | undefined;
17
+ swDevEnabled: boolean;
18
+ currentSWType: WorkerType;
19
+ swNames: DevSWNames;
20
+ manifest: false | Partial<ManifestOptions> | undefined;
21
+ };
22
+ export declare function prepareServiceWorkerData<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): {
23
+ swType: WorkerType | undefined;
24
+ chunks: string[] | undefined;
25
+ dependencies: string[];
26
+ };
@@ -0,0 +1,47 @@
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 { normalizePath } from "@vite-pwa/workbox-build/utils/resolve-sw-names";
10
+ import path from "node:path";
11
+ // src/inspector-utils.ts
12
+ function preparePWAConfigurationData(ctx) {
13
+ const resolvedOptions = ctx.resolvedOptions;
14
+ const devOptions = resolvedOptions.devOptions;
15
+ return {
16
+ version,
17
+ base: ctx.base,
18
+ swEnabled: ctx.resolvedOptions.disable === false,
19
+ strategy: ctx.strategy,
20
+ swType: resolvedOptions.swType,
21
+ swDevEnabled: devOptions?.enabled === true,
22
+ currentSWType: ctx.dev.options.swType,
23
+ swNames: ctx.dev.options.swNames,
24
+ manifest: resolvedOptions.manifest
25
+ };
26
+ }
27
+ function prepareServiceWorkerData(ctx) {
28
+ const root = ctx.rootDir;
29
+ const injectManifest = ctx.strategy === "inject-manifest";
30
+ const devOptions = ctx.resolvedOptions.devOptions;
31
+ let chunks = devOptions?.enabled === true && ctx.dev.options?.swAssetKeys ? [...ctx.dev.options.swAssetKeys].filter((d) => !d.endsWith(".map")) : void 0;
32
+ let dependencies = [...ctx.sources].map((d) => normalizePath(path.relative(root, d)));
33
+ if (injectManifest) {
34
+ if (chunks) {
35
+ const swName = `${ctx.base}${ctx.dev.options.swNames.name}`;
36
+ chunks = chunks.map((c) => c === swName ? c : normalizePath(path.relative(root, c)));
37
+ }
38
+ const filename = ctx.resolvedOptions.injectManifest.swSrc;
39
+ dependencies = dependencies.filter((c) => c !== filename);
40
+ }
41
+ return {
42
+ swType: devOptions?.enabled === true ? ctx.dev.options?.swType : void 0,
43
+ chunks,
44
+ dependencies
45
+ };
46
+ }
47
+ export { preparePWAConfigurationData, prepareServiceWorkerData };
@@ -0,0 +1,8 @@
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
+ export declare const inspectorWithInjectManifestWarning: string;
package/dist/logs.mjs ADDED
@@ -0,0 +1,19 @@
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 { INSPECTOR_BASE_PATH } from "./constants.mjs";
9
+ import { errStyle } from "@vite-pwa/workbox-build/utils/colors";
10
+ // src/logs.ts
11
+ const inspectorWithInjectManifestWarning = [
12
+ `\n${errStyle(["yellow", "bold"], "[Vite PWA]")} ${errStyle("yellow", "Vite PWA Inspector won't work as expected")}:\n`,
13
+ `You are using ${errStyle("cyan", "inject-manifest")} strategy, your service worker is ${errStyle("cyan", "static")}.`,
14
+ `If you want to see ${errStyle("cyan", "Vite PWA Inspector")}, you can:`,
15
+ ` - use hard refresh when opening ${errStyle("cyan", "Vite PWA Inspector")} page to bypass the service worker interception or`,
16
+ ` - you can add ${errStyle("green", `'${INSPECTOR_BASE_PATH}'`)} to your ${errStyle("cyan", "NavigationRoute denylist option")}:`,
17
+ ` ${errStyle("green", "registerRoute(new NavigationRoute(createHandlerBoundToURL('index.html'), { denylist: [/^\\/__unplugin_pwa_inspector/] }))")}\n`
18
+ ].join("\n");
19
+ export { inspectorWithInjectManifestWarning };
@@ -0,0 +1,10 @@
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
+ // package.json
9
+ var version = "0.0.3";
10
+ export { version as t };
@@ -0,0 +1,11 @@
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
+ export declare function preparePWAContext<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): PWAPluginContext<B, UserStrategy, T>;
@@ -0,0 +1,135 @@
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 { DEV_SW_NAME, FILE_SW_REGISTER } from "./constants.mjs";
9
+ import { isDualServiceWorker } from "./dual-sw-utilities.mjs";
10
+ import { createGenerateRegisterSW } from "./create-generate-register-sw-script.mjs";
11
+ import { createWebManifestHtmlLink } from "./create-web-manifest-html-link.mjs";
12
+ // src/prepare-pwa-context.ts
13
+ function preparePWAContext(ctx) {
14
+ ctx.webManifestData = () => {
15
+ const options = ctx.resolvedOptions;
16
+ if (!options.manifest) return void 0;
17
+ const url = options.manifestFilename;
18
+ const manifest = createWebManifestHtmlLink(ctx);
19
+ return {
20
+ href: `${ctx.devEnvironment ? options.base : options.buildBase}${url}`,
21
+ useCredentials: options.useCredentials,
22
+ toLinkTag: () => {
23
+ return manifest;
24
+ }
25
+ };
26
+ };
27
+ ctx.registerSWData = async () => {
28
+ const options = ctx.resolvedOptions;
29
+ if (options.disable || ctx.devEnvironment && !options.devOptions?.enabled) return void 0;
30
+ let mode = options.injectRegister;
31
+ if (!mode || ctx.useImportRegister) return;
32
+ if (mode === "auto") {
33
+ options.injectRegister = "script";
34
+ mode = "script";
35
+ }
36
+ let type = "classic";
37
+ let script;
38
+ let shouldRegisterSW = options.injectRegister === "inline" || options.injectRegister === "script" || options.injectRegister === "script-defer";
39
+ if (ctx.devEnvironment) {
40
+ if (options.devOptions?.enabled === true) {
41
+ type = options.devOptions?.type ?? "classic";
42
+ script = await createGenerateRegisterSW(ctx, true, true);
43
+ shouldRegisterSW = true;
44
+ }
45
+ } else {
46
+ script = await createGenerateRegisterSW(ctx, false, true);
47
+ shouldRegisterSW = true;
48
+ }
49
+ const base = ctx.devEnvironment ? options.base : options.buildBase;
50
+ return {
51
+ shouldRegisterSW,
52
+ module: isDualServiceWorker(ctx),
53
+ mode,
54
+ scope: options.scope,
55
+ inlinePath: `${base}${ctx.devEnvironment ? DEV_SW_NAME : FILE_SW_REGISTER}`,
56
+ registerPath: `${base}${FILE_SW_REGISTER}`,
57
+ type,
58
+ toScriptTag: () => {
59
+ return script;
60
+ }
61
+ };
62
+ };
63
+ ctx.build = {
64
+ generateSW: async () => {
65
+ switch (ctx.bundler) {
66
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(ctx.resolvedOptions.generateSW));
67
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-generate-sw").then(({ generateSWLegacy: runGenerateSWLegacy }) => runGenerateSWLegacy(ctx.resolvedOptions.generateSW));
68
+ case "rspack":
69
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(ctx.resolvedOptions.generateSW));
70
+ }
71
+ },
72
+ buildSW: async () => {
73
+ switch (ctx.bundler) {
74
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(ctx.resolvedOptions.buildSW));
75
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-build-sw").then(({ buildSWLegacy: runBuildSWLegacy }) => runBuildSWLegacy(ctx.resolvedOptions.buildSW));
76
+ case "rspack":
77
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(ctx.bundler === "webpack" ? ctx.resolvedOptions.buildSW : ctx.resolvedOptions.buildSW));
78
+ }
79
+ },
80
+ injectManifest: () => import("@vite-pwa/workbox-build/inject-manifest").then(({ injectManifest: runInjectManifest }) => runInjectManifest(ctx.resolvedOptions.injectManifest)),
81
+ selfDestroyingSW: () => import("@vite-pwa/workbox-build/self-destroying-sw").then(({ selfDestroyingSW: runSelfDestroyingSW }) => runSelfDestroyingSW(ctx.resolvedOptions.selfDestroying)).then(() => Promise.resolve(true))
82
+ };
83
+ ctx.dev = {
84
+ options: {
85
+ swName: "",
86
+ swGenerated: false,
87
+ registerSWGenerated: false,
88
+ registerVirtualSWGenerated: false,
89
+ hmrEntryPointGenerated: false,
90
+ swType: ctx.consumerOptions.devOptions?.type ?? "classic",
91
+ swAssetKeys: /* @__PURE__ */ new Set(),
92
+ swAssetsPaths: /* @__PURE__ */ new Map(),
93
+ tempFolder: void 0,
94
+ swNames: {
95
+ hasNames: false,
96
+ name: "",
97
+ classic: "",
98
+ module: "",
99
+ path: "",
100
+ classicPath: "",
101
+ modulePath: "",
102
+ devSWDest: ""
103
+ },
104
+ globDirectory: ""
105
+ },
106
+ generateSW: async (options) => {
107
+ switch (ctx.bundler) {
108
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(Object.assign({}, ctx.resolvedOptions.generateSW ?? {}, options)));
109
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-generate-sw").then(({ generateSWLegacy: runGenerateSWLegacy }) => runGenerateSWLegacy(Object.assign({}, ctx.resolvedOptions.generateSW ?? {}, options)));
110
+ case "rspack":
111
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/generate-sw").then(({ generateSW: runGenerateSW }) => runGenerateSW(Object.assign({}, ctx.resolvedOptions.generateSW ?? {}, options)));
112
+ }
113
+ },
114
+ buildSW: async (options) => {
115
+ switch (ctx.bundler) {
116
+ case "vite": return await import("@vite-pwa/workbox-build/build/vite/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options)));
117
+ case "vite-legacy": return await import("@vite-pwa/workbox-build/build/vite/legacy-build-sw").then(({ buildSWLegacy: runBuildSWLegacy }) => runBuildSWLegacy(Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options)));
118
+ case "rspack":
119
+ case "webpack": return await import("@vite-pwa/workbox-build/build/rolldown/build-sw").then(({ buildSW: runBuildSW }) => runBuildSW(ctx.bundler === "webpack" ? Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options) : Object.assign({}, ctx.resolvedOptions.buildSW ?? {}, options)));
120
+ }
121
+ },
122
+ injectManifest: (options) => import("@vite-pwa/workbox-build/inject-manifest").then(({ injectManifest: runInjectManifest }) => runInjectManifest(Object.assign({}, ctx.resolvedOptions.injectManifest ?? {}, options))),
123
+ selfDestroyingSW: (options) => import("@vite-pwa/workbox-build/self-destroying-sw").then(({ selfDestroyingSW: runSelfDestroyingSW }) => runSelfDestroyingSW(options)).then(() => Promise.resolve(true))
124
+ };
125
+ ctx.runBuild = async () => {
126
+ switch (ctx.strategy) {
127
+ case "self-destroy-sw": return await ctx.build.selfDestroyingSW();
128
+ case "build-sw": return await ctx.build.buildSW();
129
+ case "generate-sw": return await ctx.build.generateSW();
130
+ case "inject-manifest": return await ctx.build.injectManifest();
131
+ }
132
+ };
133
+ return ctx;
134
+ }
135
+ export { preparePWAContext };
@@ -0,0 +1,11 @@
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
+ export declare function prepareSwNames<B extends Bundler, UserStrategy extends VitePWAStrategy, T extends SWType>(ctx: PWAPluginContext<B, UserStrategy, T>): void;
@@ -0,0 +1,45 @@
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 { normalizePath as normalizePath$1 } from "./helpers.mjs";
9
+ import { extractSwDestNameFromSource, resolveSWNames } from "@vite-pwa/workbox-build/utils/resolve-sw-names";
10
+ import path from "node:path";
11
+ // src/prepare-sw-names.ts
12
+ function prepareSwNames(ctx) {
13
+ let options;
14
+ let filename;
15
+ let swSrc;
16
+ switch (ctx.strategy) {
17
+ case "generate-sw":
18
+ swSrc = "";
19
+ options = ctx.resolvedOptions.generateSW;
20
+ filename = ctx.consumerOptions.filename = normalizePath$1(path.resolve(ctx.outDir, ctx.consumerOptions.filename || "sw.js"));
21
+ ctx.resolvedOptions.generateSW.swDest = filename;
22
+ break;
23
+ case "inject-manifest":
24
+ options = ctx.resolvedOptions.injectManifest;
25
+ swSrc = ctx.resolvedOptions.injectManifest.swSrc;
26
+ filename = ctx.consumerOptions.filename = normalizePath$1(path.resolve(ctx.outDir, ctx.consumerOptions.filename || extractSwDestNameFromSource(swSrc)));
27
+ ctx.resolvedOptions.injectManifest.swDest = filename;
28
+ break;
29
+ case "build-sw":
30
+ options = ctx.resolvedOptions.buildSW;
31
+ swSrc = extractSwDestNameFromSource(ctx.resolvedOptions.buildSW.swSrc);
32
+ filename = ctx.consumerOptions.filename = normalizePath$1(path.resolve(ctx.outDir, ctx.consumerOptions.filename || extractSwDestNameFromSource(swSrc)));
33
+ ctx.resolvedOptions.buildSW.swDest = filename;
34
+ }
35
+ if (options) {
36
+ const { swDest, classicSWDest, moduleSWDest } = resolveSWNames(filename, swSrc, ctx.strategy === "generate-sw");
37
+ ctx.swNames = {
38
+ hasNames: true,
39
+ name: swDest,
40
+ classic: classicSWDest,
41
+ module: moduleSWDest
42
+ };
43
+ }
44
+ }
45
+ export { prepareSwNames };
@@ -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 { t as AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ export declare function generate(assetsGeneratorContext: AssetsGeneratorContext): Promise<void>;
@@ -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 { mkdir } from "node:fs/promises";
9
+ import { generateAssets } from "@vite-pwa/assets-generator/api/generate-assets";
10
+ // src/pwa-assets/build.ts
11
+ async function generate(assetsGeneratorContext) {
12
+ await mkdir(assetsGeneratorContext.imageOutDir, { recursive: true });
13
+ await generateAssets(assetsGeneratorContext.assetsInstructions, true, assetsGeneratorContext.imageOutDir);
14
+ }
15
+ export { generate };
@@ -0,0 +1,10 @@
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 AssetsGeneratorContext } from "../types-B60e7Nq4.mjs";
9
+ import { PWAPluginContext } from "../context-types.mjs";
10
+ export declare function loadAssetsGeneratorContext(ctx: PWAPluginContext<any, any, any>, assetsGeneratorContext?: AssetsGeneratorContext): Promise<AssetsGeneratorContext | undefined>;