@unplugin-pwa/core 0.0.0 → 0.0.2
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/LICENSE +21 -0
- package/README.md +103 -2
- package/client.d.ts +6 -0
- package/dist/additional-manifest-entries.d.mts +10 -0
- package/dist/additional-manifest-entries.mjs +60 -0
- package/dist/build-pwa-asset.d.mts +18 -0
- package/dist/build-pwa-asset.mjs +87 -0
- package/dist/config.d.mts +75 -0
- package/dist/config.mjs +293 -0
- package/dist/constants.d.mts +31 -0
- package/dist/constants.mjs +41 -0
- package/dist/context-types.d.mts +155 -0
- package/dist/context.d.mts +15 -0
- package/dist/context.mjs +58 -0
- package/dist/create-generate-register-sw-script.d.mts +15 -0
- package/dist/create-generate-register-sw-script.mjs +27 -0
- package/dist/create-web-manifest-html-link.d.mts +13 -0
- package/dist/create-web-manifest-html-link.mjs +21 -0
- package/dist/dev/prepare-sw-names-and-glob-directory.d.mts +18 -0
- package/dist/dev/prepare-sw-names-and-glob-directory.mjs +75 -0
- package/dist/dev/prepare-temp-folder.d.mts +9 -0
- package/dist/dev/prepare-temp-folder.mjs +44 -0
- package/dist/dual-sw-utilities.d.mts +9 -0
- package/dist/dual-sw-utilities.mjs +16 -0
- package/dist/generate-register-sw.d.mts +14 -0
- package/dist/generate-register-sw.mjs +22 -0
- package/dist/generate-web-manifest.d.mts +9 -0
- package/dist/generate-web-manifest.mjs +12 -0
- package/dist/helpers.d.mts +33 -0
- package/dist/helpers.mjs +132 -0
- package/dist/html.d.mts +8 -0
- package/dist/html.mjs +28 -0
- package/dist/index.d.mts +9 -0
- package/dist/inject-generate-register-sw.d.mts +16 -0
- package/dist/inject-generate-register-sw.mjs +22 -0
- package/dist/inject-web-manifest-html-link.d.mts +14 -0
- package/dist/inject-web-manifest-html-link.mjs +20 -0
- package/dist/inspector-utils.d.mts +26 -0
- package/dist/inspector-utils.mjs +47 -0
- package/dist/logs.d.mts +8 -0
- package/dist/logs.mjs +19 -0
- package/dist/package-DpKc2x3j.mjs +10 -0
- package/dist/prepare-pwa-context.d.mts +11 -0
- package/dist/prepare-pwa-context.mjs +135 -0
- package/dist/prepare-sw-names.d.mts +11 -0
- package/dist/prepare-sw-names.mjs +45 -0
- package/dist/pwa-assets/build.d.mts +9 -0
- package/dist/pwa-assets/build.mjs +15 -0
- package/dist/pwa-assets/config.d.mts +10 -0
- package/dist/pwa-assets/config.mjs +136 -0
- package/dist/pwa-assets/dev.d.mts +11 -0
- package/dist/pwa-assets/dev.mjs +35 -0
- package/dist/pwa-assets/generator.d.mts +20 -0
- package/dist/pwa-assets/generator.mjs +31 -0
- package/dist/pwa-assets/html.d.mts +11 -0
- package/dist/pwa-assets/html.mjs +47 -0
- package/dist/pwa-assets/manifest.d.mts +10 -0
- package/dist/pwa-assets/manifest.mjs +15 -0
- package/dist/pwa-assets/options.d.mts +9 -0
- package/dist/pwa-assets/options.mjs +34 -0
- package/dist/pwa-assets/types.d.mts +9 -0
- package/dist/pwa-assets/utils.d.mts +11 -0
- package/dist/pwa-assets/utils.mjs +48 -0
- package/dist/resolve-inspector-dist.d.mts +11 -0
- package/dist/resolve-inspector-dist.mjs +25 -0
- package/dist/types-B60e7Nq4.d.mts +67 -0
- package/dist/types-BhwjnGLn.d.mts +703 -0
- package/info.d.ts +71 -0
- package/package.json +133 -7
- package/preact.d.ts +17 -0
- package/pwa-assets.d.ts +40 -0
- package/react-legacy.d.ts +22 -0
- package/react.d.ts +17 -0
- package/solid.d.ts +17 -0
- package/svelte.d.ts +17 -0
- package/types/index.d.ts +43 -0
- package/types/package.json +3 -0
- package/vanillajs.d.ts +13 -0
- package/vue.d.ts +17 -0
- package/index.js +0 -1
|
@@ -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>;
|
package/dist/helpers.mjs
ADDED
|
@@ -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 };
|
package/dist/html.d.mts
ADDED
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 };
|
package/dist/index.d.mts
ADDED
|
@@ -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-DpKc2x3j.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 };
|