tempest-react-sdk 0.82.0 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/bin/lib/openapi/generate.hostile.test.mjs +91 -0
- package/bin/lib/openapi/generate.mjs +42 -3
- package/dist/auth/create-tempest-auth.cjs +1 -1
- package/dist/auth/create-tempest-auth.cjs.map +1 -1
- package/dist/auth/create-tempest-auth.js +201 -153
- package/dist/auth/create-tempest-auth.js.map +1 -1
- package/dist/http/resumable-upload.cjs +1 -1
- package/dist/http/resumable-upload.cjs.map +1 -1
- package/dist/http/resumable-upload.js +124 -75
- package/dist/http/resumable-upload.js.map +1 -1
- package/dist/http/upload-with-progress.cjs +1 -1
- package/dist/http/upload-with-progress.cjs.map +1 -1
- package/dist/http/upload-with-progress.js +108 -44
- package/dist/http/upload-with-progress.js.map +1 -1
- package/dist/payments/PixCheckout.cjs +2 -0
- package/dist/payments/PixCheckout.cjs.map +1 -0
- package/dist/payments/PixCheckout.js +171 -0
- package/dist/payments/PixCheckout.js.map +1 -0
- package/dist/payments/PixCheckout.module.cjs +3 -0
- package/dist/payments/PixCheckout.module.cjs.map +1 -0
- package/dist/payments/PixCheckout.module.js +22 -0
- package/dist/payments/PixCheckout.module.js.map +1 -0
- package/dist/payments/format.cjs +2 -0
- package/dist/payments/format.cjs.map +1 -0
- package/dist/payments/format.js +9 -0
- package/dist/payments/format.js.map +1 -0
- package/dist/payments/mercado-pago.cjs +2 -0
- package/dist/payments/mercado-pago.cjs.map +1 -0
- package/dist/payments/mercado-pago.js +27 -0
- package/dist/payments/mercado-pago.js.map +1 -0
- package/dist/payments/outcome.cjs +2 -0
- package/dist/payments/outcome.cjs.map +1 -0
- package/dist/payments/outcome.js +108 -0
- package/dist/payments/outcome.js.map +1 -0
- package/dist/payments/types.cjs +2 -0
- package/dist/payments/types.cjs.map +1 -0
- package/dist/payments/types.js +16 -0
- package/dist/payments/types.js.map +1 -0
- package/dist/payments/use-mercado-pago-card.cjs +2 -0
- package/dist/payments/use-mercado-pago-card.cjs.map +1 -0
- package/dist/payments/use-mercado-pago-card.js +120 -0
- package/dist/payments/use-mercado-pago-card.js.map +1 -0
- package/dist/payments/use-pix-charge.cjs +2 -0
- package/dist/payments/use-pix-charge.cjs.map +1 -0
- package/dist/payments/use-pix-charge.js +63 -0
- package/dist/payments/use-pix-charge.js.map +1 -0
- package/dist/query/offline-persistence.cjs +1 -1
- package/dist/query/offline-persistence.cjs.map +1 -1
- package/dist/query/offline-persistence.js +57 -44
- package/dist/query/offline-persistence.js.map +1 -1
- package/dist/styles/PixCheckout.css +2 -0
- package/dist/styles/component/PixCheckout.css +18 -0
- package/dist/styles/manifest.json +6 -0
- package/dist/styles/payments.css +18 -0
- package/dist/styles.css +1 -1
- package/dist/sw/cache.cjs +1 -1
- package/dist/sw/cache.cjs.map +1 -1
- package/dist/sw/cache.js +82 -32
- package/dist/sw/cache.js.map +1 -1
- package/dist/sw.d.ts +21 -1
- package/dist/tempest-react-sdk.cjs +1 -1
- package/dist/tempest-react-sdk.d.ts +748 -10
- package/dist/tempest-react-sdk.js +104 -97
- package/dist/vite/base-url.cjs +1 -1
- package/dist/vite/base-url.cjs.map +1 -1
- package/dist/vite/base-url.js +5 -1
- package/dist/vite/base-url.js.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs +1 -1
- package/dist/vite/tempest-pwa-dev-sw.cjs.map +1 -1
- package/dist/vite/tempest-pwa-dev-sw.js +96 -31
- package/dist/vite/tempest-pwa-dev-sw.js.map +1 -1
- package/dist/vite/tempest-pwa-manifest.cjs +2 -2
- package/dist/vite/tempest-pwa-manifest.cjs.map +1 -1
- package/dist/vite/tempest-pwa-manifest.js +32 -16
- package/dist/vite/tempest-pwa-manifest.js.map +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.ts +63 -12
- package/dist/vite.js +4 -4
- package/package.json +1 -1
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import { basePrefix as e } from "./base-url.js";
|
|
2
|
-
import { resolve as
|
|
1
|
+
import { basePrefix as e, toOutputFile as t } from "./base-url.js";
|
|
2
|
+
import { resolve as n } from "node:path";
|
|
3
3
|
//#region src/vite/tempest-pwa-dev-sw.ts
|
|
4
|
-
|
|
4
|
+
var r = "tempest-pwa-dev-sw";
|
|
5
|
+
function i(e) {
|
|
6
|
+
return `/* tempest-precache-version: ${e} */\n`;
|
|
7
|
+
}
|
|
8
|
+
function a(e, t) {
|
|
9
|
+
let n = e[t];
|
|
10
|
+
if (n?.type !== "asset") return;
|
|
11
|
+
let r = typeof n.source == "string" ? n.source : new TextDecoder().decode(n.source);
|
|
12
|
+
try {
|
|
13
|
+
let e = JSON.parse(r);
|
|
14
|
+
return typeof e.version == "string" ? e.version : void 0;
|
|
15
|
+
} catch {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function o(e) {
|
|
5
20
|
return async (t, n, r) => {
|
|
6
21
|
let i = (t.url ?? "").split("?")[0];
|
|
7
22
|
if (e.matches(i, e.swUrl)) try {
|
|
@@ -16,63 +31,113 @@ function n(e) {
|
|
|
16
31
|
}))) : r();
|
|
17
32
|
};
|
|
18
33
|
}
|
|
19
|
-
function
|
|
20
|
-
let { swSrc:
|
|
21
|
-
function
|
|
34
|
+
function s(s = {}) {
|
|
35
|
+
let { swSrc: c = "src/sw.ts", swUrl: l = "/sw.js", manifestUrl: u = "/precache-manifest.json", enabled: d = !0, build: f = !0 } = s, p = process.cwd(), m = "/", h = !1, g = "production", _, v, y = !0, b = "warn";
|
|
36
|
+
function x(t, n) {
|
|
22
37
|
if (t === n) return !0;
|
|
23
|
-
let r = e(
|
|
38
|
+
let r = e(m);
|
|
24
39
|
return r !== "/" && t === `${r}${n.replace(/^\//, "")}`;
|
|
25
40
|
}
|
|
26
|
-
let
|
|
27
|
-
async function
|
|
28
|
-
return
|
|
29
|
-
entryPoints: [
|
|
41
|
+
let S = null, C = null;
|
|
42
|
+
async function w() {
|
|
43
|
+
return S || (S = await (await import("esbuild")).context({
|
|
44
|
+
entryPoints: [n(p, c)],
|
|
30
45
|
bundle: !0,
|
|
31
46
|
format: "iife",
|
|
32
47
|
platform: "browser",
|
|
33
48
|
target: "es2020",
|
|
34
49
|
write: !1,
|
|
35
|
-
absWorkingDir:
|
|
50
|
+
absWorkingDir: p,
|
|
36
51
|
logLevel: "silent"
|
|
37
|
-
}),
|
|
52
|
+
}), S);
|
|
38
53
|
}
|
|
39
|
-
function
|
|
40
|
-
if (
|
|
54
|
+
function T() {
|
|
55
|
+
if (C) return C;
|
|
41
56
|
let e = (async () => {
|
|
42
|
-
let e = (await (await
|
|
57
|
+
let e = (await (await w()).rebuild()).outputFiles?.[0]?.text;
|
|
43
58
|
if (e === void 0) throw Error("esbuild produced no service-worker output");
|
|
44
59
|
return e;
|
|
45
60
|
})();
|
|
46
|
-
|
|
61
|
+
C = e;
|
|
47
62
|
let t = () => {
|
|
48
|
-
|
|
63
|
+
C = null;
|
|
49
64
|
};
|
|
50
65
|
return e.then(t, t), e;
|
|
51
66
|
}
|
|
52
|
-
async function
|
|
53
|
-
let e =
|
|
54
|
-
|
|
67
|
+
async function E() {
|
|
68
|
+
let e = S;
|
|
69
|
+
S = null, C = null, await e?.dispose();
|
|
70
|
+
}
|
|
71
|
+
async function D() {
|
|
72
|
+
let e = await (await import("vite")).build({
|
|
73
|
+
configFile: !1,
|
|
74
|
+
root: p,
|
|
75
|
+
mode: g,
|
|
76
|
+
envDir: _,
|
|
77
|
+
envPrefix: v,
|
|
78
|
+
publicDir: !1,
|
|
79
|
+
logLevel: b,
|
|
80
|
+
build: {
|
|
81
|
+
write: !1,
|
|
82
|
+
emptyOutDir: !1,
|
|
83
|
+
copyPublicDir: !1,
|
|
84
|
+
sourcemap: !1,
|
|
85
|
+
minify: y,
|
|
86
|
+
lib: {
|
|
87
|
+
entry: n(p, c),
|
|
88
|
+
formats: ["iife"],
|
|
89
|
+
name: "sw",
|
|
90
|
+
fileName: () => "sw.js"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}), t = Array.isArray(e) ? e : [e];
|
|
94
|
+
for (let { output: e = [] } of t) {
|
|
95
|
+
let t = e.find((e) => e.type === "chunk" && e.isEntry);
|
|
96
|
+
if (t?.code !== void 0) return t.code;
|
|
97
|
+
}
|
|
98
|
+
throw Error("the build produced no service-worker chunk");
|
|
55
99
|
}
|
|
56
100
|
return {
|
|
57
|
-
name:
|
|
58
|
-
|
|
101
|
+
name: r,
|
|
102
|
+
api: {
|
|
103
|
+
swUrl: l,
|
|
104
|
+
build: f
|
|
105
|
+
},
|
|
59
106
|
async buildEnd() {
|
|
60
|
-
await
|
|
107
|
+
await E();
|
|
61
108
|
},
|
|
62
109
|
configResolved(e) {
|
|
63
|
-
|
|
110
|
+
p = e.root ?? process.cwd(), m = e.base ?? "/", h = e.command === "build" && !e.build?.ssr, g = e.mode ?? "production", _ = e.envDir, v = e.envPrefix, y = e.build?.minify ?? !0, b = e.logLevel === "silent" || e.logLevel === "error" ? e.logLevel : "warn";
|
|
64
111
|
},
|
|
65
112
|
configureServer(e) {
|
|
66
|
-
|
|
67
|
-
swUrl:
|
|
68
|
-
manifestUrl:
|
|
69
|
-
matches:
|
|
70
|
-
buildWorker:
|
|
113
|
+
d && (e.httpServer?.once("close", () => void E()), e.middlewares.use(o({
|
|
114
|
+
swUrl: l,
|
|
115
|
+
manifestUrl: u,
|
|
116
|
+
matches: x,
|
|
117
|
+
buildWorker: T
|
|
71
118
|
})));
|
|
119
|
+
},
|
|
120
|
+
generateBundle: {
|
|
121
|
+
order: "post",
|
|
122
|
+
async handler(e, n) {
|
|
123
|
+
if (!h || !f) return;
|
|
124
|
+
let r;
|
|
125
|
+
try {
|
|
126
|
+
r = await D();
|
|
127
|
+
} catch (e) {
|
|
128
|
+
this.error(`[tempest-pwa-dev-sw] could not bundle the service worker "${c}" into ${l}: ${e instanceof Error ? e.message : String(e)}. Fix the entry, point \`swSrc\` at it, or pass \`build: false\` if another step bundles the worker.`);
|
|
129
|
+
}
|
|
130
|
+
let o = a(n, t(m, u));
|
|
131
|
+
this.emitFile({
|
|
132
|
+
type: "asset",
|
|
133
|
+
fileName: t(m, l),
|
|
134
|
+
source: o === void 0 ? r : i(o) + r
|
|
135
|
+
});
|
|
136
|
+
}
|
|
72
137
|
}
|
|
73
138
|
};
|
|
74
139
|
}
|
|
75
140
|
//#endregion
|
|
76
|
-
export { r as tempestPwaDevSw };
|
|
141
|
+
export { r as PWA_WORKER_PLUGIN_NAME, i as precacheVersionBanner, s as tempestPwaDevSw };
|
|
77
142
|
|
|
78
143
|
//# sourceMappingURL=tempest-pwa-dev-sw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tempest-pwa-dev-sw.js","names":["createDevSwMiddleware","url","req","deps","source","res","error","next","tempestPwaDevSw","options","root","base","matches","target","prefix","basePrefix","context","pending","ensureContext","resolve","swSrc","buildWorker","run","text","clear","disposeContext","current","config","enabled","server"],"sources":["../../src/vite/tempest-pwa-dev-sw.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport { basePrefix } from \"./base-url\";\nimport type { TempestVitePlugin } from \"./tempest-pwa-manifest\";\n\n/** Options for {@link tempestPwaDevSw}. */\nexport interface TempestPwaDevSwOptions {\n /** Service-worker entry, relative to the project root. Default `src/sw.ts`. */\n swSrc?: string;\n /**\n * URL the worker is served at (must match `registerServiceWorker`).\n * Default `/sw.js`.\n *\n * Write it relative to the site root; requests are matched against both the\n * bare path and the path prefixed with the resolved Vite `base`, so a\n * project served from a subpath is handled without extra configuration.\n */\n swUrl?: string;\n /**\n * Dev URL of the precache manifest. Default `/precache-manifest.json`.\n * Matched the same way as {@link TempestPwaDevSwOptions.swUrl}.\n */\n manifestUrl?: string;\n /** Serve the worker in dev. Default `true`; set `false` to opt out. */\n enabled?: boolean;\n}\n\n/**\n * The dev middleware: serve the compiled worker, and a placeholder manifest.\n *\n * Extracted from the plugin so the request handling reads on its own — the\n * plugin body is then only wiring. The manifest is deliberately empty in dev:\n * precaching a set of URLs Vite rewrites on every change would serve stale\n * modules, and the worker's runtime routes still work without it.\n *\n * @param deps - The two URLs, the path matcher and the incremental build.\n * @returns A connect-style middleware.\n */\nfunction createDevSwMiddleware(deps: {\n swUrl: string;\n manifestUrl: string;\n matches: (url: string, target: string) => boolean;\n buildWorker: () => Promise<string>;\n}): (\n req: { url?: string },\n res: {\n statusCode?: number;\n setHeader: (name: string, value: string) => void;\n end: (body: string) => void;\n },\n next: () => void,\n) => Promise<void> {\n return async (req, res, next) => {\n const url = (req.url ?? \"\").split(\"?\")[0];\n\n if (deps.matches(url, deps.swUrl)) {\n try {\n const source = await deps.buildWorker();\n res.setHeader(\"Content-Type\", \"application/javascript\");\n res.setHeader(\"Service-Worker-Allowed\", \"/\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.end(source);\n } catch (error) {\n res.statusCode = 500;\n res.end(`// SW dev build failed:\\n// ${String(error)}`);\n }\n return;\n }\n\n if (deps.matches(url, deps.manifestUrl)) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.end(JSON.stringify({ version: \"dev\", urls: [] }));\n return;\n }\n\n next();\n };\n}\n\n/**\n * Dev-server plugin that makes the service worker available under `npm run dev`.\n *\n * The production worker is bundled at build time (`vite.sw.config.ts`), so in\n * dev there is no `/sw.js` to register. This plugin compiles `swSrc` on the fly\n * with esbuild — through one incremental context, not a cold build per request —\n * and serves it as a classic worker, plus an empty `precache-manifest.json` (there are no hashed build assets to precache in\n * dev — push and runtime caching still work). It closes the \"SW in dev\" gap\n * that otherwise only `vite-plugin-pwa`'s `devOptions` covered.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaDevSw } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({ plugins: [tempestPwaDevSw()] });\n */\nexport function tempestPwaDevSw(options: TempestPwaDevSwOptions = {}): TempestVitePlugin {\n const {\n swSrc = \"src/sw.ts\",\n swUrl = \"/sw.js\",\n manifestUrl = \"/precache-manifest.json\",\n enabled = true,\n } = options;\n\n let root = process.cwd();\n let base = \"/\";\n\n /**\n * Whether a request path addresses `target`.\n *\n * Both the bare path and the base-prefixed one are accepted. Which of the\n * two arrives depends on where this middleware lands relative to Vite's own\n * base handling, and a project served from a subpath would otherwise never\n * match — the browser asks for `/app/sw.js` while the option says `/sw.js`.\n */\n function matches(url: string, target: string): boolean {\n if (url === target) return true;\n const prefix = basePrefix(base);\n if (prefix === \"/\") return false;\n return url === `${prefix}${target.replace(/^\\//, \"\")}`;\n }\n\n /**\n * The slice of esbuild's incremental API this plugin uses.\n *\n * Typed structurally rather than imported: `esbuild` is not a dependency of\n * this package. It is resolved at runtime from the app's own tree, where Vite\n * already brings it, so importing its types would add a build-time dependency\n * the runtime does not have.\n */\n interface BuildContext {\n rebuild(): Promise<{ outputFiles?: readonly { text: string }[] }>;\n dispose(): Promise<void>;\n }\n\n let context: BuildContext | null = null;\n let pending: Promise<string> | null = null;\n\n /**\n * The incremental build context, created on the first request that needs it.\n *\n * Lazy because a project that never registers a worker should not pay for an\n * esbuild child process, and because `apply: \"serve\"` still loads this module\n * in a build.\n *\n * @returns The context, reused across requests.\n */\n async function ensureContext(): Promise<BuildContext> {\n if (context) return context;\n const esbuild = (await import(\"esbuild\")) as unknown as {\n context(options: Record<string, unknown>): Promise<BuildContext>;\n };\n context = await esbuild.context({\n entryPoints: [resolve(root, swSrc)],\n bundle: true,\n format: \"iife\",\n platform: \"browser\",\n target: \"es2020\",\n write: false,\n absWorkingDir: root,\n logLevel: \"silent\",\n });\n return context;\n }\n\n /**\n * Bundle the worker, reusing the previous graph.\n *\n * `esbuild.build()` per request was a cold bundle every time, and the request\n * count is not one per session: `Cache-Control: no-cache` guarantees one per\n * page load, and Chrome re-fetches the worker script on every navigation and\n * on its own update checks. `rebuild()` reuses the graph and only redoes what\n * changed on disk.\n *\n * Single-flight, because those requests arrive in bursts and esbuild does not\n * promise anything about concurrent `rebuild()` calls on one context. Callers\n * that land while a bundle is in flight share its result, which is the right\n * answer anyway — they asked for the same file at the same moment.\n *\n * @returns The bundled worker source.\n */\n function buildWorker(): Promise<string> {\n if (pending) return pending;\n\n const run = (async (): Promise<string> => {\n const ctx = await ensureContext();\n const result = await ctx.rebuild();\n const text = result.outputFiles?.[0]?.text;\n if (text === undefined) throw new Error(\"esbuild produced no service-worker output\");\n return text;\n })();\n\n pending = run;\n const clear = (): void => {\n pending = null;\n };\n run.then(clear, clear);\n return run;\n }\n\n /**\n * Tear the context down, releasing esbuild's child process.\n *\n * Idempotent, because it is wired to both the dev server closing and the\n * plugin's `buildEnd`. Without it, restarting the dev server leaks one esbuild\n * process per restart.\n */\n async function disposeContext(): Promise<void> {\n const current = context;\n context = null;\n pending = null;\n await current?.dispose();\n }\n\n const plugin: Plugin = {\n name: \"tempest-pwa-dev-sw\",\n apply: \"serve\",\n async buildEnd() {\n await disposeContext();\n },\n configResolved(config) {\n root = config.root ?? process.cwd();\n base = config.base ?? \"/\";\n },\n configureServer(server) {\n if (!enabled) return;\n\n server.httpServer?.once(\"close\", () => void disposeContext());\n\n server.middlewares.use(\n createDevSwMiddleware({ swUrl, manifestUrl, matches, buildWorker }),\n );\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"mappings":";;;AAsCA,SAASA,EAAsB,GAaZ;CACf,OAAO,OAAO,GAAK,GAAK,MAAS;EAC7B,IAAMC,KAAOC,EAAI,OAAO,GAAA,CAAI,MAAM,GAAG,CAAC,CAAC;EAEvC,IAAIC,EAAK,QAAQF,GAAKE,EAAK,KAAK,GAC5B,IAAI;GACA,IAAMC,IAAS,MAAMD,EAAK,YAAY;GAItC,AAHAE,EAAI,UAAU,gBAAgB,wBAAwB,GACtDA,EAAI,UAAU,0BAA0B,GAAG,GAC3CA,EAAI,UAAU,iBAAiB,UAAU,GACzCA,EAAI,IAAID,CAAM;EAClB,SAASE,GAAO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F;CACX;CASA,eAAeG,IAAgC;EAC3C,IAAMC,IAAUV;EAGhB,AAFA,IAAU,MACV,IAAU,MACV,MAAMU,GAAS,QAAQ;CAC3B;CAuBA,OAAO;EApBH,MAAM;EACN,OAAO;EACP,MAAM,WAAW;GACb,MAAMD,EAAe;EACzB;EACA,eAAe,GAAQ;GAEnB,AADA,IAAOE,EAAO,QAAQ,QAAQ,IAAI,GAClC,IAAOA,EAAO,QAAQ;EAC1B;EACA,gBAAgB,GAAQ;GACpB,AAAKC,MAELC,EAAO,YAAY,KAAK,eAAe,KAAKJ,EAAe,CAAC,GAE5DI,EAAO,YAAY,IACf7B,EAAsB;IAAE;IAAO;IAAa;IAAS;GAAY,CAAC,CACtE;EACJ;CAGG;AACX"}
|
|
1
|
+
{"version":3,"file":"tempest-pwa-dev-sw.js","names":["PWA_WORKER_PLUGIN_NAME","precacheVersionBanner","version","readManifestVersion","asset","bundle","fileName","source","parsed","createDevSwMiddleware","url","req","deps","res","error","next","tempestPwaDevSw","options","root","base","isBuild","mode","envDir","envPrefix","minify","logLevel","matches","target","prefix","basePrefix","context","pending","ensureContext","resolve","swSrc","buildWorker","run","text","clear","disposeContext","current","bundleWorkerForProduction","result","outputs","entry","output","item","config","enabled","server","build","swUrl","toOutputFile","manifestUrl"],"sources":["../../src/vite/tempest-pwa-dev-sw.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport { basePrefix, toOutputFile } from \"./base-url\";\nimport type { TempestVitePlugin } from \"./tempest-pwa-manifest\";\n\n/** Options for {@link tempestPwaDevSw}. */\nexport interface TempestPwaDevSwOptions {\n /** Service-worker entry, relative to the project root. Default `src/sw.ts`. */\n swSrc?: string;\n /**\n * URL the worker is served at (must match `registerServiceWorker`).\n * Default `/sw.js`.\n *\n * Write it relative to the site root; requests are matched against both the\n * bare path and the path prefixed with the resolved Vite `base`, so a\n * project served from a subpath is handled without extra configuration.\n */\n swUrl?: string;\n /**\n * Dev URL of the precache manifest. Default `/precache-manifest.json`.\n * Matched the same way as {@link TempestPwaDevSwOptions.swUrl}.\n */\n manifestUrl?: string;\n /** Serve the worker in dev. Default `true`; set `false` to opt out. */\n enabled?: boolean;\n /**\n * Bundle `swSrc` into the production build as `swUrl`. Default `true`.\n *\n * Set `false` only when another step bundles the worker (a second\n * `vite build --config vite.sw.config.ts`, `vite-plugin-pwa`). That is also\n * what tells {@link tempestPwaManifest} the worker is external, so its\n * missing-worker check stands down.\n */\n build?: boolean;\n}\n\n/** Name of the plugin {@link tempestPwaDevSw} returns, looked up by the manifest plugin. */\nexport const PWA_WORKER_PLUGIN_NAME = \"tempest-pwa-dev-sw\";\n\n/**\n * What {@link tempestPwaDevSw} publishes on its plugin `api`, for sibling plugins.\n *\n * {@link tempestPwaManifest} reads it to know which file the worker lands at and\n * whether this build emits it at all.\n */\nexport interface TempestPwaWorkerApi {\n /** URL the worker is served and emitted at. */\n swUrl: string;\n /** Whether this plugin bundles the worker into the production build. */\n build: boolean;\n}\n\n/**\n * The comment prepended to the production worker, carrying the precache version.\n *\n * The browser installs a new service worker only when the bytes of `sw.js`\n * change. A deploy that touches the app but not `src/sw.ts` would otherwise ship\n * a byte-identical worker: it never reinstalls, `installPrecache` never re-runs,\n * and the offline shell keeps serving the previous deploy. The manifest\n * `version` is a hash of every precached URL, so it changes exactly when the\n * precache does.\n *\n * @param version - The `version` of the emitted precache manifest.\n * @returns A one-line block comment.\n */\nexport function precacheVersionBanner(version: string): string {\n return `/* tempest-precache-version: ${version} */\\n`;\n}\n\n/**\n * The `version` of the precache manifest this build emitted, when there is one.\n *\n * @param bundle - The output bundle, as Rollup/Rolldown hands it to `generateBundle`.\n * @param fileName - Where the manifest was emitted, relative to `outDir`.\n * @returns The version, or `undefined` when the manifest is absent or unreadable.\n */\nfunction readManifestVersion(\n bundle: Record<string, { type?: string; source?: unknown }>,\n fileName: string,\n): string | undefined {\n const asset = bundle[fileName];\n if (asset?.type !== \"asset\") return undefined;\n const source =\n typeof asset.source === \"string\"\n ? asset.source\n : new TextDecoder().decode(asset.source as Uint8Array);\n try {\n const parsed = JSON.parse(source) as { version?: unknown };\n return typeof parsed.version === \"string\" ? parsed.version : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The dev middleware: serve the compiled worker, and a placeholder manifest.\n *\n * Extracted from the plugin so the request handling reads on its own — the\n * plugin body is then only wiring. The manifest is deliberately empty in dev:\n * precaching a set of URLs Vite rewrites on every change would serve stale\n * modules, and the worker's runtime routes still work without it.\n *\n * @param deps - The two URLs, the path matcher and the incremental build.\n * @returns A connect-style middleware.\n */\nfunction createDevSwMiddleware(deps: {\n swUrl: string;\n manifestUrl: string;\n matches: (url: string, target: string) => boolean;\n buildWorker: () => Promise<string>;\n}): (\n req: { url?: string },\n res: {\n statusCode?: number;\n setHeader: (name: string, value: string) => void;\n end: (body: string) => void;\n },\n next: () => void,\n) => Promise<void> {\n return async (req, res, next) => {\n const url = (req.url ?? \"\").split(\"?\")[0];\n\n if (deps.matches(url, deps.swUrl)) {\n try {\n const source = await deps.buildWorker();\n res.setHeader(\"Content-Type\", \"application/javascript\");\n res.setHeader(\"Service-Worker-Allowed\", \"/\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.end(source);\n } catch (error) {\n res.statusCode = 500;\n res.end(`// SW dev build failed:\\n// ${String(error)}`);\n }\n return;\n }\n\n if (deps.matches(url, deps.manifestUrl)) {\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Cache-Control\", \"no-cache\");\n res.end(JSON.stringify({ version: \"dev\", urls: [] }));\n return;\n }\n\n next();\n };\n}\n\n/**\n * Service-worker plugin: serves `swSrc` under `npm run dev` and bundles it into\n * the production build.\n *\n * In dev there is no `/sw.js` to register. This plugin compiles `swSrc` on the\n * fly with esbuild — through one incremental context, not a cold build per\n * request — and serves it as a classic worker, plus an empty\n * `precache-manifest.json` (there are no hashed build assets to precache in\n * dev — push and runtime caching still work).\n *\n * In `vite build` it bundles the same entry with Vite's own `build()` (IIFE, so\n * it registers as a classic worker, exactly what the old `vite.sw.config.ts`\n * produced) and emits it at `swUrl`. Before 0.83.0 it was serve-only: an app\n * with this plugin and {@link tempestPwaManifest} worked in dev and shipped a\n * production build with no `sw.js` and a zero exit code, so registration\n * 404'd and `navigator.serviceWorker.ready` never resolved. The emitted worker\n * starts with the precache `version` (see {@link precacheVersionBanner}), so\n * every deploy that changes the precache changes the worker bytes and the\n * browser installs it. Pass `build: false` when another step bundles the\n * worker.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaDevSw, tempestPwaManifest } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({ plugins: [tempestPwaManifest(), tempestPwaDevSw()] });\n */\nexport function tempestPwaDevSw(options: TempestPwaDevSwOptions = {}): TempestVitePlugin {\n const {\n swSrc = \"src/sw.ts\",\n swUrl = \"/sw.js\",\n manifestUrl = \"/precache-manifest.json\",\n enabled = true,\n build = true,\n } = options;\n\n let root = process.cwd();\n let base = \"/\";\n let isBuild = false;\n let mode = \"production\";\n let envDir: string | false | undefined;\n let envPrefix: string | string[] | undefined;\n let minify: boolean | string = true;\n let logLevel: \"silent\" | \"error\" | \"warn\" = \"warn\";\n\n /**\n * Whether a request path addresses `target`.\n *\n * Both the bare path and the base-prefixed one are accepted. Which of the\n * two arrives depends on where this middleware lands relative to Vite's own\n * base handling, and a project served from a subpath would otherwise never\n * match — the browser asks for `/app/sw.js` while the option says `/sw.js`.\n */\n function matches(url: string, target: string): boolean {\n if (url === target) return true;\n const prefix = basePrefix(base);\n if (prefix === \"/\") return false;\n return url === `${prefix}${target.replace(/^\\//, \"\")}`;\n }\n\n /**\n * The slice of esbuild's incremental API this plugin uses.\n *\n * Typed structurally rather than imported: `esbuild` is not a dependency of\n * this package. It is resolved at runtime from the app's own tree, where Vite\n * already brings it, so importing its types would add a build-time dependency\n * the runtime does not have.\n */\n interface BuildContext {\n rebuild(): Promise<{ outputFiles?: readonly { text: string }[] }>;\n dispose(): Promise<void>;\n }\n\n let context: BuildContext | null = null;\n let pending: Promise<string> | null = null;\n\n /**\n * The incremental build context, created on the first request that needs it.\n *\n * Lazy because a project that never registers a worker should not pay for an\n * esbuild child process, and because `apply: \"serve\"` still loads this module\n * in a build.\n *\n * @returns The context, reused across requests.\n */\n async function ensureContext(): Promise<BuildContext> {\n if (context) return context;\n const esbuild = (await import(\"esbuild\")) as unknown as {\n context(options: Record<string, unknown>): Promise<BuildContext>;\n };\n context = await esbuild.context({\n entryPoints: [resolve(root, swSrc)],\n bundle: true,\n format: \"iife\",\n platform: \"browser\",\n target: \"es2020\",\n write: false,\n absWorkingDir: root,\n logLevel: \"silent\",\n });\n return context;\n }\n\n /**\n * Bundle the worker, reusing the previous graph.\n *\n * `esbuild.build()` per request was a cold bundle every time, and the request\n * count is not one per session: `Cache-Control: no-cache` guarantees one per\n * page load, and Chrome re-fetches the worker script on every navigation and\n * on its own update checks. `rebuild()` reuses the graph and only redoes what\n * changed on disk.\n *\n * Single-flight, because those requests arrive in bursts and esbuild does not\n * promise anything about concurrent `rebuild()` calls on one context. Callers\n * that land while a bundle is in flight share its result, which is the right\n * answer anyway — they asked for the same file at the same moment.\n *\n * @returns The bundled worker source.\n */\n function buildWorker(): Promise<string> {\n if (pending) return pending;\n\n const run = (async (): Promise<string> => {\n const ctx = await ensureContext();\n const result = await ctx.rebuild();\n const text = result.outputFiles?.[0]?.text;\n if (text === undefined) throw new Error(\"esbuild produced no service-worker output\");\n return text;\n })();\n\n pending = run;\n const clear = (): void => {\n pending = null;\n };\n run.then(clear, clear);\n return run;\n }\n\n /**\n * Tear the context down, releasing esbuild's child process.\n *\n * Idempotent, because it is wired to both the dev server closing and the\n * plugin's `buildEnd`. Without it, restarting the dev server leaks one esbuild\n * process per restart.\n */\n async function disposeContext(): Promise<void> {\n const current = context;\n context = null;\n pending = null;\n await current?.dispose();\n }\n\n /**\n * Bundle `swSrc` for production with the host's own Vite.\n *\n * Vite's `build()` rather than esbuild: Vite 8 lists esbuild only as an\n * optional peer, so a fresh app may not have it, while the `vite` running\n * this plugin is always there. The config mirrors the `vite.sw.config.ts`\n * the PWA template used to ship — IIFE lib build, one entry, no app plugins —\n * plus the app's `mode`, `envDir` and `envPrefix`, so `import.meta.env`\n * inside the worker sees the same `VITE_*` values as the page. Its log level\n * is the app's, capped at `warn`, so the nested build adds no size table to\n * the output but a `silent` build stays silent.\n *\n * @returns The bundled worker source.\n */\n async function bundleWorkerForProduction(): Promise<string> {\n const vite = (await import(\"vite\")) as unknown as {\n build(config: Record<string, unknown>): Promise<unknown>;\n };\n const result = await vite.build({\n configFile: false,\n root,\n mode,\n envDir,\n envPrefix,\n publicDir: false,\n logLevel,\n build: {\n write: false,\n emptyOutDir: false,\n copyPublicDir: false,\n sourcemap: false,\n minify,\n lib: {\n entry: resolve(root, swSrc),\n formats: [\"iife\"],\n name: \"sw\",\n fileName: () => \"sw.js\",\n },\n },\n });\n const outputs = (Array.isArray(result) ? result : [result]) as {\n output?: { type: string; isEntry?: boolean; code?: string }[];\n }[];\n for (const { output = [] } of outputs) {\n const entry = output.find((item) => item.type === \"chunk\" && item.isEntry);\n if (entry?.code !== undefined) return entry.code;\n }\n throw new Error(\"the build produced no service-worker chunk\");\n }\n\n const api: TempestPwaWorkerApi = { swUrl, build };\n\n const plugin: Plugin = {\n name: PWA_WORKER_PLUGIN_NAME,\n api,\n async buildEnd() {\n await disposeContext();\n },\n configResolved(config) {\n root = config.root ?? process.cwd();\n base = config.base ?? \"/\";\n isBuild = config.command === \"build\" && !config.build?.ssr;\n mode = config.mode ?? \"production\";\n envDir = config.envDir;\n envPrefix = config.envPrefix;\n minify = config.build?.minify ?? true;\n logLevel =\n config.logLevel === \"silent\" || config.logLevel === \"error\"\n ? config.logLevel\n : \"warn\";\n },\n configureServer(server) {\n if (!enabled) return;\n\n server.httpServer?.once(\"close\", () => void disposeContext());\n\n server.middlewares.use(\n createDevSwMiddleware({ swUrl, manifestUrl, matches, buildWorker }),\n );\n },\n generateBundle: {\n order: \"post\",\n async handler(_outputOptions, bundle) {\n if (!isBuild || !build) return;\n let source: string;\n try {\n source = await bundleWorkerForProduction();\n } catch (error) {\n this.error(\n `[tempest-pwa-dev-sw] could not bundle the service worker \"${swSrc}\" ` +\n `into ${swUrl}: ${error instanceof Error ? error.message : String(error)}. ` +\n \"Fix the entry, point `swSrc` at it, or pass `build: false` if another \" +\n \"step bundles the worker.\",\n );\n }\n const version = readManifestVersion(\n bundle as Record<string, { type?: string; source?: unknown }>,\n toOutputFile(base, manifestUrl),\n );\n this.emitFile({\n type: \"asset\",\n fileName: toOutputFile(base, swUrl),\n source:\n version === undefined ? source : precacheVersionBanner(version) + source,\n });\n },\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"mappings":";;;AAqCA,IAAaA,IAAyB;AA4BtC,SAAgBC,EAAsB,GAAyB;CAC3D,OAAO,gCAAgCC,EAAQ;AACnD;AASA,SAASC,EACL,GACA,GACkB;CAClB,IAAMC,IAAQC,EAAOC;CACrB,IAAIF,GAAO,SAAS,SAAS;CAC7B,IAAMG,IACF,OAAOH,EAAM,UAAW,WAClBA,EAAM,SACN,IAAI,YAAY,CAAC,CAAC,OAAOA,EAAM,MAAoB;CAC7D,IAAI;EACA,IAAMI,IAAS,KAAK,MAAMD,CAAM;EAChC,OAAO,OAAOC,EAAO,WAAY,WAAWA,EAAO,UAAU,KAAA;CACjE,QAAQ;EACJ;CACJ;AACJ;AAaA,SAASC,EAAsB,GAaZ;CACf,OAAO,OAAO,GAAK,GAAK,MAAS;EAC7B,IAAMC,KAAOC,EAAI,OAAO,GAAA,CAAI,MAAM,GAAG,CAAC,CAAC;EAEvC,IAAIC,EAAK,QAAQF,GAAKE,EAAK,KAAK,GAC5B,IAAI;GACA,IAAML,IAAS,MAAMK,EAAK,YAAY;GAItC,AAHAC,EAAI,UAAU,gBAAgB,wBAAwB,GACtDA,EAAI,UAAU,0BAA0B,GAAG,GAC3CA,EAAI,UAAU,iBAAiB,UAAU,GACzCA,EAAI,IAAI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C,EAAO,YAAY,KAAK,eAAe,KAAKV,EAAe,CAAC,GAE5DU,EAAO,YAAY,IACfxC,EAAsB;IAAE;IAAO;IAAa;IAAS;GAAY,CAAC,CACtE;EACJ;EACA,gBAAgB;GACZ,OAAO;GACP,MAAM,QAAQ,GAAgB,GAAQ;IAClC,IAAI,CAACW,KAAW,CAAC8B,GAAO;IACxB,IAAI3C;IACJ,IAAI;KACA,IAAS,MAAMkC,EAA0B;IAC7C,SAAS3B,GAAO;KACZ,KAAK,MACD,6DAA6DoB,EAAM,SACvDiB,EAAM,IAAIrC,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK,EAAE,qGAGjF;IACJ;IACA,IAAMZ,IAAUC,EACZE,GACA+C,EAAajC,GAAMkC,CAAW,CAClC;IACA,KAAK,SAAS;KACV,MAAM;KACN,UAAUD,EAAajC,GAAMgC,CAAK;KAClC,QACIjD,MAAY,KAAA,IAAYK,IAASN,EAAsBC,CAAO,IAAIK;IAC1E,CAAC;GACL;EACJ;CAGG;AACX"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const e=require("./base-url.cjs");function t(t,n){return`${e.basePrefix(t)}${n}`.replace(/([^:]\/)\/+/g,`$1`)}function
|
|
2
|
-
`));this.emitFile({type:`asset`,fileName:
|
|
1
|
+
const e=require("./base-url.cjs"),t=require("./tempest-pwa-dev-sw.cjs");let n=require("node:path"),r=require("node:fs");function i(t,i,a,o){let s=e.toOutputFile(i,t);if(s in a)return!0;if(!o)return!1;let c=(0,n.join)(o,s);return(0,r.existsSync)(c)&&(0,r.statSync)(c).isFile()}function a(t,n){return`${e.basePrefix(t)}${n}`.replace(/([^:]\/)\/+/g,`$1`)}function o(t,n){let r=e.basePrefix(t);return r===`/`?n.startsWith(`/`)?n:`/${n}`:n.startsWith(r)?n:`${r}${n.replace(/^\//,``)}`}function s(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)>>>0;return t.toString(16)}function c(n={}){let{fileName:r=`precache-manifest.json`,additionalUrls:c=[],exclude:l=/\.map$/,includeHtml:u=!0,appShell:d=`/index.html`,serviceWorker:f}=n,p=`/`,m=``,h=`/sw.js`;return{name:`tempest-pwa-manifest`,apply:`build`,configResolved(e){p=e.base??`/`,m=e.publicDir??``;let n=(e.plugins??[]).find(e=>e.name===t.PWA_WORKER_PLUGIN_NAME)?.api;h=f===void 0?n?n.build?n.swUrl:!1:`/sw.js`:f},generateBundle(e,t){let n=new Set(c.map(e=>o(p,e)));d&&n.add(o(p,d));for(let e of Object.keys(t))e!==r&&(l.test(e)||(u||!e.endsWith(`.html`))&&n.add(a(p,e)));let i=[...n].sort(),f=s(i.join(`
|
|
2
|
+
`));this.emitFile({type:`asset`,fileName:r,source:JSON.stringify({version:f,urls:i})})},writeBundle(t,n){let a=c.filter(e=>!/^[a-z][a-z\d+.-]*:/i.test(e)&&!i(e,p,n,m));a.length>0&&this.error(`[tempest-pwa-manifest] additionalUrls lists ${a.join(`, `)}, which is neither in public/ nor in the build output. In production that URL answers with the SPA fallback or a 404, so the precache would store index.html under its name or fail the worker install. Move the file into public/, or drop the entry — a file Vite hashes into assets/ (a web manifest linked from index.html) is already precached.`),h!==!1&&(e.toOutputFile(p,h)in n||this.error(`[tempest-pwa-manifest] the build emitted ${r} but no service worker at ${h}. In production the registration 404s and navigator.serviceWorker.ready never resolves (push, updates and offline hang without an error). Add tempestPwaDevSw() — it bundles src/sw.ts into this build — or, if a separate step bundles the worker after this one, pass tempestPwaManifest({ serviceWorker: false }) or tempestPwaDevSw({ build: false }).`))}}}exports.tempestPwaManifest=c;
|
|
3
3
|
//# sourceMappingURL=tempest-pwa-manifest.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tempest-pwa-manifest.cjs","names":["basePrefix","require_base_url","joinBase","base","file","withBase","prefix","url","hash","h","i","input","tempestPwaManifest","options","config","urls","additionalUrls","appShell","bundle","fileName","exclude","includeHtml","list","version"],"sources":["../../src/vite/tempest-pwa-manifest.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { basePrefix } from \"./base-url\";\n\n/**\n * A Vite plugin object. Typed loosely so the SDK's published declarations stay\n * free of `vite`'s internal types (which the `.d.ts` rollup can't analyze);\n * assign the result straight into a `plugins: [...]` array.\n */\nexport type TempestVitePlugin = { name: string } & Record<string, unknown>;\n\n/** Options for {@link tempestPwaManifest}. */\nexport interface TempestPwaManifestOptions {\n /** Output file name (under the build root). Default `precache-manifest.json`. */\n fileName?: string;\n /**\n * Extra URLs to precache that Vite doesn't emit into the bundle — typically\n * `public/` assets like the web manifest and icons. Default `[]`.\n *\n * Write these relative to the site root (`/icon.svg`); the resolved Vite\n * `base` is prefixed for you. An entry that already carries the base is\n * left alone, so spelling it out by hand is still correct.\n */\n additionalUrls?: string[];\n /** Emitted files matching this are skipped. Default `/\\.map$/` (source maps). */\n exclude?: RegExp;\n /** Include emitted `.html` documents (the app shell). Default `true`. */\n includeHtml?: boolean;\n /**\n * App-shell document always added to the manifest, even if Vite emits it\n * after this plugin runs. Must match `installPrecache`'s `navigateFallback`\n * so offline navigations resolve. Pass `false` to disable. Default `/index.html`.\n *\n * Like {@link TempestPwaManifestOptions.additionalUrls}, this is prefixed\n * with the resolved Vite `base`.\n */\n appShell?: string | false;\n}\n\nfunction joinBase(base: string, file: string): string {\n return `${basePrefix(base)}${file}`.replace(/([^:]\\/)\\/+/g, \"$1\");\n}\n\n/**\n * Prefix a caller-supplied, root-absolute URL with the resolved Vite `base`.\n *\n * Idempotent: a URL that already starts with the base is returned untouched,\n * so configs written before this was applied — spelling the base out by hand —\n * keep producing the same manifest instead of gaining a doubled prefix.\n */\nfunction withBase(base: string, url: string): string {\n const prefix = basePrefix(base);\n if (prefix === \"/\") return url.startsWith(\"/\") ? url : `/${url}`;\n if (url.startsWith(prefix)) return url;\n return `${prefix}${url.replace(/^\\//, \"\")}`;\n}\n\n/** Deterministic djb2 hash → hex. Stable across rebuilds with the same assets. */\nfunction hash(input: string): string {\n let h = 5381;\n for (let i = 0; i < input.length; i++) {\n h = ((h << 5) + h + input.charCodeAt(i)) >>> 0;\n }\n return h.toString(16);\n}\n\n/**\n * Vite build plugin that emits a `precache-manifest.json` listing every built\n * asset (plus any `additionalUrls`) as root-absolute URLs, with a content-based\n * `version`. It is the dependency-free counterpart to Workbox's `__WB_MANIFEST`:\n * `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service\n * worker's `install` event to cache the app shell for offline use.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaManifest } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * plugins: [tempestPwaManifest({ additionalUrls: [\"/manifest.webmanifest\", \"/icon.svg\"] })],\n * });\n */\nexport function tempestPwaManifest(options: TempestPwaManifestOptions = {}): TempestVitePlugin {\n const {\n fileName = \"precache-manifest.json\",\n additionalUrls = [],\n exclude = /\\.map$/,\n includeHtml = true,\n appShell = \"/index.html\",\n } = options;\n\n let base = \"/\";\n\n const plugin: Plugin = {\n name: \"tempest-pwa-manifest\",\n apply: \"build\",\n configResolved(config) {\n base = config.base ?? \"/\";\n },\n generateBundle(_outputOptions, bundle) {\n const urls = new Set<string>(additionalUrls.map((url) => withBase(base, url)));\n // Vite may emit index.html after this hook, so guarantee the shell.\n if (appShell) urls.add(withBase(base, appShell));\n for (const file of Object.keys(bundle)) {\n if (file === fileName) continue;\n if (exclude.test(file)) continue;\n if (!includeHtml && file.endsWith(\".html\")) continue;\n urls.add(joinBase(base, file));\n }\n\n const list = [...urls].sort();\n const version = hash(list.join(\"\\n\"));\n this.emitFile({\n type: \"asset\",\n fileName,\n source: JSON.stringify({ version, urls: list }),\n });\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"mappings":"A,kCAsCA,SAASE,EAAS,EAAc,EAAsB,CAClD,MAAO,GAAGF,EAAAA,WAAWG,CAAI,IAAIC,IAAO,QAAQ,eAAgB,IAAI,CACpE,CASA,SAASC,EAAS,EAAc,EAAqB,CACjD,IAAMC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ync","basePrefix","PWA_WORKER_PLUGIN_NAME","require_base_url","require_tempest_pwa_dev_sw","node_path","node_fs","resolvesToFile","file","base","url","bundle","publicDir","path","joinBase","withBase","prefix","hash","h","i","input","tempestPwaManifest","options","expectedWorker","config","worker","item","serviceWorker","urls","additionalUrls","appShell","fileName","exclude","includeHtml","list","version","missing"],"sources":["../../src/vite/tempest-pwa-manifest.ts"],"sourcesContent":["import { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport { basePrefix, toOutputFile } from \"./base-url\";\nimport { PWA_WORKER_PLUGIN_NAME } from \"./tempest-pwa-dev-sw\";\nimport type { TempestPwaWorkerApi } from \"./tempest-pwa-dev-sw\";\n\n/**\n * A Vite plugin object. Typed loosely so the SDK's published declarations stay\n * free of `vite`'s internal types (which the `.d.ts` rollup can't analyze);\n * assign the result straight into a `plugins: [...]` array.\n */\nexport type TempestVitePlugin = { name: string } & Record<string, unknown>;\n\n/** Options for {@link tempestPwaManifest}. */\nexport interface TempestPwaManifestOptions {\n /** Output file name (under the build root). Default `precache-manifest.json`. */\n fileName?: string;\n /**\n * Extra URLs to precache that Vite doesn't emit into the bundle — typically\n * `public/` assets like the web manifest and icons. Default `[]`.\n *\n * Write these relative to the site root (`/icon.svg`); the resolved Vite\n * `base` is prefixed for you. An entry that already carries the base is\n * left alone, so spelling it out by hand is still correct.\n *\n * Every same-origin entry must be a file in `public/` or in the bundle, or\n * the build fails. A URL that resolves to nothing is answered in production\n * by the SPA fallback (`index.html`) or a 404, so the precache would store\n * the app shell under that name, or fail the worker's install outright. The\n * usual culprit is a web manifest linked from `index.html` but kept outside\n * `public/`: Vite hashes it into `assets/`, where it is already precached.\n * Absolute `http(s):` URLs are not checked.\n */\n additionalUrls?: string[];\n /** Emitted files matching this are skipped. Default `/\\.map$/` (source maps). */\n exclude?: RegExp;\n /** Include emitted `.html` documents (the app shell). Default `true`. */\n includeHtml?: boolean;\n /**\n * App-shell document always added to the manifest, even if Vite emits it\n * after this plugin runs. Must match `installPrecache`'s `navigateFallback`\n * so offline navigations resolve. Pass `false` to disable. Default `/index.html`.\n *\n * Like {@link TempestPwaManifestOptions.additionalUrls}, this is prefixed\n * with the resolved Vite `base`.\n */\n appShell?: string | false;\n /**\n * URL of the service worker that reads this manifest. The build fails when\n * no file is emitted at that URL. Default: the `swUrl` of\n * {@link tempestPwaDevSw} when it is in the plugin list, `/sw.js` otherwise.\n *\n * A precache manifest is only read by a worker, and a build that ships the\n * manifest without the worker exits 0 while registration 404s in\n * production — `navigator.serviceWorker.ready` never resolves and push,\n * updates and offline all hang without a message. Pass `false` when the\n * worker is bundled by a separate step after this build (a second\n * `vite build --config vite.sw.config.ts`); `tempestPwaDevSw({ build: false })`\n * already says the same and needs nothing here.\n */\n serviceWorker?: string | false;\n}\n\n/**\n * Whether `url` names something the build can serve: a bundle entry or a file\n * in the public directory.\n *\n * @param url - The URL as written in `additionalUrls`.\n * @param base - Vite's resolved `base`.\n * @param bundle - The final output bundle.\n * @param publicDir - The resolved public directory, or `\"\"` when disabled.\n * @returns `true` when the URL resolves to a real file.\n */\nfunction resolvesToFile(\n url: string,\n base: string,\n bundle: Record<string, unknown>,\n publicDir: string,\n): boolean {\n const file = toOutputFile(base, url);\n if (file in bundle) return true;\n if (!publicDir) return false;\n const path = join(publicDir, file);\n return existsSync(path) && statSync(path).isFile();\n}\n\nfunction joinBase(base: string, file: string): string {\n return `${basePrefix(base)}${file}`.replace(/([^:]\\/)\\/+/g, \"$1\");\n}\n\n/**\n * Prefix a caller-supplied, root-absolute URL with the resolved Vite `base`.\n *\n * Idempotent: a URL that already starts with the base is returned untouched,\n * so configs written before this was applied — spelling the base out by hand —\n * keep producing the same manifest instead of gaining a doubled prefix.\n */\nfunction withBase(base: string, url: string): string {\n const prefix = basePrefix(base);\n if (prefix === \"/\") return url.startsWith(\"/\") ? url : `/${url}`;\n if (url.startsWith(prefix)) return url;\n return `${prefix}${url.replace(/^\\//, \"\")}`;\n}\n\n/** Deterministic djb2 hash → hex. Stable across rebuilds with the same assets. */\nfunction hash(input: string): string {\n let h = 5381;\n for (let i = 0; i < input.length; i++) {\n h = ((h << 5) + h + input.charCodeAt(i)) >>> 0;\n }\n return h.toString(16);\n}\n\n/**\n * Vite build plugin that emits a `precache-manifest.json` listing every built\n * asset (plus any `additionalUrls`) as root-absolute URLs, with a content-based\n * `version`. It is the dependency-free counterpart to Workbox's `__WB_MANIFEST`:\n * `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service\n * worker's `install` event to cache the app shell for offline use.\n *\n * Two mistakes that used to ship in silence now fail the build, after the bundle\n * is written: no service worker emitted at\n * {@link TempestPwaManifestOptions.serviceWorker}, and an `additionalUrls`\n * entry that is neither in `public/` nor in the bundle. Pair it with\n * {@link tempestPwaDevSw}, which bundles `src/sw.ts` into the same build.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaDevSw, tempestPwaManifest } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * plugins: [\n * tempestPwaManifest({ additionalUrls: [\"/manifest.webmanifest\", \"/icon.svg\"] }),\n * tempestPwaDevSw(),\n * ],\n * });\n */\nexport function tempestPwaManifest(options: TempestPwaManifestOptions = {}): TempestVitePlugin {\n const {\n fileName = \"precache-manifest.json\",\n additionalUrls = [],\n exclude = /\\.map$/,\n includeHtml = true,\n appShell = \"/index.html\",\n serviceWorker,\n } = options;\n\n let base = \"/\";\n let publicDir = \"\";\n let expectedWorker: string | false = \"/sw.js\";\n\n const plugin: Plugin = {\n name: \"tempest-pwa-manifest\",\n apply: \"build\",\n configResolved(config) {\n base = config.base ?? \"/\";\n publicDir = config.publicDir ?? \"\";\n const worker = (config.plugins ?? []).find(\n (item) => item.name === PWA_WORKER_PLUGIN_NAME,\n )?.api as TempestPwaWorkerApi | undefined;\n if (serviceWorker !== undefined) expectedWorker = serviceWorker;\n else if (worker) expectedWorker = worker.build ? worker.swUrl : false;\n else expectedWorker = \"/sw.js\";\n },\n generateBundle(_outputOptions, bundle) {\n const urls = new Set<string>(additionalUrls.map((url) => withBase(base, url)));\n // Vite may emit index.html after this hook, so guarantee the shell.\n if (appShell) urls.add(withBase(base, appShell));\n for (const file of Object.keys(bundle)) {\n if (file === fileName) continue;\n if (exclude.test(file)) continue;\n if (!includeHtml && file.endsWith(\".html\")) continue;\n urls.add(joinBase(base, file));\n }\n\n const list = [...urls].sort();\n const version = hash(list.join(\"\\n\"));\n this.emitFile({\n type: \"asset\",\n fileName,\n source: JSON.stringify({ version, urls: list }),\n });\n },\n writeBundle(_outputOptions, bundle) {\n const missing = additionalUrls.filter(\n (url) =>\n !/^[a-z][a-z\\d+.-]*:/i.test(url) &&\n !resolvesToFile(url, base, bundle, publicDir),\n );\n if (missing.length > 0) {\n this.error(\n `[tempest-pwa-manifest] additionalUrls lists ${missing.join(\", \")}, which is ` +\n \"neither in public/ nor in the build output. In production that URL \" +\n \"answers with the SPA fallback or a 404, so the precache would store \" +\n \"index.html under its name or fail the worker install. Move the file \" +\n \"into public/, or drop the entry — a file Vite hashes into assets/ \" +\n \"(a web manifest linked from index.html) is already precached.\",\n );\n }\n\n if (expectedWorker === false) return;\n if (toOutputFile(base, expectedWorker) in bundle) return;\n this.error(\n `[tempest-pwa-manifest] the build emitted ${fileName} but no service worker ` +\n `at ${expectedWorker}. In production the registration 404s and ` +\n \"navigator.serviceWorker.ready never resolves (push, updates and offline \" +\n \"hang without an error). Add tempestPwaDevSw() — it bundles src/sw.ts into \" +\n \"this build — or, if a separate step bundles the worker after this one, \" +\n \"pass tempestPwaManifest({ serviceWorker: false }) or \" +\n \"tempestPwaDevSw({ build: false }).\",\n );\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"mappings":"A,wHA0EA,SAASU,EACL,EACA,EACA,EACA,EACO,CACP,IAAMC,EAAOX,EAAAA,aAAaY,EAAMC,CAAG,EACnC,GAAIF,KAAQG,EAAQ,MAAO,GAC3B,GAAI,CAACC,EAAW,MAAO,GACvB,IAAMC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EAAe,IAAK,GAAQd,EAASN,EAAMC,CAAG,CAAC,CAAC,EAEzEoB,GAAUF,EAAK,IAAIb,EAASN,EAAMqB,CAAQ,CAAC,EAC/C,IAAK,IAAMtB,KAAQ,OAAO,KAAKG,CAAM,EAC7BH,IAASuB,IACTC,EAAQ,KAAKxB,CAAI,IAChByB,GAAe,GAAK,SAAS,OAAO,IACzCL,EAAK,IAAId,EAASL,EAAMD,CAAI,CAAC,GAGjC,IAAM0B,EAAO,CAAC,GAAGN,CAAI,CAAC,CAAC,KAAK,EACtBO,EAAUlB,EAAKiB,EAAK,KAAK;CAAI,CAAC,EACpC,KAAK,SAAS,CACV,KAAM,QACN,WACA,OAAQ,KAAK,UAAU,CAAE,UAAS,KAAMA,CAAK,CAAC,CAClD,CAAC,CACL,EACA,YAAY,EAAgB,EAAQ,CAChC,IAAME,EAAUP,EAAe,OAC1B,GACG,CAAC,sBAAsB,KAAKnB,CAAG,GAC/B,CAACH,EAAeG,EAAKD,EAAME,EAAQC,CAAS,CACpD,EACIwB,EAAQ,OAAS,GACjB,KAAK,MACD,+CAA+CA,EAAQ,KAAK,IAAI,EAAE,sVAMtE,EAGAb,IAAmB,KACnB1B,EAAAA,aAAaY,EAAMc,CAAc,IAAKZ,GAC1C,KAAK,MACD,4CAA4CoB,EAAS,4BAC3CR,EAAe,2VAM7B,EACJ,CAGG,CACX,C"}
|
|
@@ -1,42 +1,58 @@
|
|
|
1
|
-
import { basePrefix as e } from "./base-url.js";
|
|
1
|
+
import { basePrefix as e, toOutputFile as t } from "./base-url.js";
|
|
2
|
+
import { PWA_WORKER_PLUGIN_NAME as n } from "./tempest-pwa-dev-sw.js";
|
|
3
|
+
import { join as r } from "node:path";
|
|
4
|
+
import { existsSync as i, statSync as a } from "node:fs";
|
|
2
5
|
//#region src/vite/tempest-pwa-manifest.ts
|
|
3
|
-
function
|
|
6
|
+
function o(e, n, o, s) {
|
|
7
|
+
let c = t(n, e);
|
|
8
|
+
if (c in o) return !0;
|
|
9
|
+
if (!s) return !1;
|
|
10
|
+
let l = r(s, c);
|
|
11
|
+
return i(l) && a(l).isFile();
|
|
12
|
+
}
|
|
13
|
+
function s(t, n) {
|
|
4
14
|
return `${e(t)}${n}`.replace(/([^:]\/)\/+/g, "$1");
|
|
5
15
|
}
|
|
6
|
-
function
|
|
16
|
+
function c(t, n) {
|
|
7
17
|
let r = e(t);
|
|
8
18
|
return r === "/" ? n.startsWith("/") ? n : `/${n}` : n.startsWith(r) ? n : `${r}${n.replace(/^\//, "")}`;
|
|
9
19
|
}
|
|
10
|
-
function
|
|
20
|
+
function l(e) {
|
|
11
21
|
let t = 5381;
|
|
12
22
|
for (let n = 0; n < e.length; n++) t = (t << 5) + t + e.charCodeAt(n) >>> 0;
|
|
13
23
|
return t.toString(16);
|
|
14
24
|
}
|
|
15
|
-
function
|
|
16
|
-
let { fileName:
|
|
25
|
+
function u(e = {}) {
|
|
26
|
+
let { fileName: r = "precache-manifest.json", additionalUrls: i = [], exclude: a = /\.map$/, includeHtml: u = !0, appShell: d = "/index.html", serviceWorker: f } = e, p = "/", m = "", h = "/sw.js";
|
|
17
27
|
return {
|
|
18
28
|
name: "tempest-pwa-manifest",
|
|
19
29
|
apply: "build",
|
|
20
30
|
configResolved(e) {
|
|
21
|
-
|
|
31
|
+
p = e.base ?? "/", m = e.publicDir ?? "";
|
|
32
|
+
let t = (e.plugins ?? []).find((e) => e.name === n)?.api;
|
|
33
|
+
h = f === void 0 ? t ? t.build ? t.swUrl : !1 : "/sw.js" : f;
|
|
22
34
|
},
|
|
23
|
-
generateBundle(e,
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
for (let e of Object.keys(
|
|
27
|
-
let
|
|
35
|
+
generateBundle(e, t) {
|
|
36
|
+
let n = new Set(i.map((e) => c(p, e)));
|
|
37
|
+
d && n.add(c(p, d));
|
|
38
|
+
for (let e of Object.keys(t)) e !== r && (a.test(e) || (u || !e.endsWith(".html")) && n.add(s(p, e)));
|
|
39
|
+
let o = [...n].sort(), f = l(o.join("\n"));
|
|
28
40
|
this.emitFile({
|
|
29
41
|
type: "asset",
|
|
30
|
-
fileName:
|
|
42
|
+
fileName: r,
|
|
31
43
|
source: JSON.stringify({
|
|
32
|
-
version:
|
|
33
|
-
urls:
|
|
44
|
+
version: f,
|
|
45
|
+
urls: o
|
|
34
46
|
})
|
|
35
47
|
});
|
|
48
|
+
},
|
|
49
|
+
writeBundle(e, n) {
|
|
50
|
+
let a = i.filter((e) => !/^[a-z][a-z\d+.-]*:/i.test(e) && !o(e, p, n, m));
|
|
51
|
+
a.length > 0 && this.error(`[tempest-pwa-manifest] additionalUrls lists ${a.join(", ")}, which is neither in public/ nor in the build output. In production that URL answers with the SPA fallback or a 404, so the precache would store index.html under its name or fail the worker install. Move the file into public/, or drop the entry — a file Vite hashes into assets/ (a web manifest linked from index.html) is already precached.`), h !== !1 && (t(p, h) in n || this.error(`[tempest-pwa-manifest] the build emitted ${r} but no service worker at ${h}. In production the registration 404s and navigator.serviceWorker.ready never resolves (push, updates and offline hang without an error). Add tempestPwaDevSw() — it bundles src/sw.ts into this build — or, if a separate step bundles the worker after this one, pass tempestPwaManifest({ serviceWorker: false }) or tempestPwaDevSw({ build: false }).`));
|
|
36
52
|
}
|
|
37
53
|
};
|
|
38
54
|
}
|
|
39
55
|
//#endregion
|
|
40
|
-
export {
|
|
56
|
+
export { u as tempestPwaManifest };
|
|
41
57
|
|
|
42
58
|
//# sourceMappingURL=tempest-pwa-manifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tempest-pwa-manifest.js","names":["joinBase","basePrefix","base","file","withBase","prefix","url","hash","h","i","input","tempestPwaManifest","options","config","urls","additionalUrls","appShell","bundle","fileName","exclude","includeHtml","list","version"],"sources":["../../src/vite/tempest-pwa-manifest.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { basePrefix } from \"./base-url\";\n\n/**\n * A Vite plugin object. Typed loosely so the SDK's published declarations stay\n * free of `vite`'s internal types (which the `.d.ts` rollup can't analyze);\n * assign the result straight into a `plugins: [...]` array.\n */\nexport type TempestVitePlugin = { name: string } & Record<string, unknown>;\n\n/** Options for {@link tempestPwaManifest}. */\nexport interface TempestPwaManifestOptions {\n /** Output file name (under the build root). Default `precache-manifest.json`. */\n fileName?: string;\n /**\n * Extra URLs to precache that Vite doesn't emit into the bundle — typically\n * `public/` assets like the web manifest and icons. Default `[]`.\n *\n * Write these relative to the site root (`/icon.svg`); the resolved Vite\n * `base` is prefixed for you. An entry that already carries the base is\n * left alone, so spelling it out by hand is still correct.\n */\n additionalUrls?: string[];\n /** Emitted files matching this are skipped. Default `/\\.map$/` (source maps). */\n exclude?: RegExp;\n /** Include emitted `.html` documents (the app shell). Default `true`. */\n includeHtml?: boolean;\n /**\n * App-shell document always added to the manifest, even if Vite emits it\n * after this plugin runs. Must match `installPrecache`'s `navigateFallback`\n * so offline navigations resolve. Pass `false` to disable. Default `/index.html`.\n *\n * Like {@link TempestPwaManifestOptions.additionalUrls}, this is prefixed\n * with the resolved Vite `base`.\n */\n appShell?: string | false;\n}\n\nfunction joinBase(base: string, file: string): string {\n return `${basePrefix(base)}${file}`.replace(/([^:]\\/)\\/+/g, \"$1\");\n}\n\n/**\n * Prefix a caller-supplied, root-absolute URL with the resolved Vite `base`.\n *\n * Idempotent: a URL that already starts with the base is returned untouched,\n * so configs written before this was applied — spelling the base out by hand —\n * keep producing the same manifest instead of gaining a doubled prefix.\n */\nfunction withBase(base: string, url: string): string {\n const prefix = basePrefix(base);\n if (prefix === \"/\") return url.startsWith(\"/\") ? url : `/${url}`;\n if (url.startsWith(prefix)) return url;\n return `${prefix}${url.replace(/^\\//, \"\")}`;\n}\n\n/** Deterministic djb2 hash → hex. Stable across rebuilds with the same assets. */\nfunction hash(input: string): string {\n let h = 5381;\n for (let i = 0; i < input.length; i++) {\n h = ((h << 5) + h + input.charCodeAt(i)) >>> 0;\n }\n return h.toString(16);\n}\n\n/**\n * Vite build plugin that emits a `precache-manifest.json` listing every built\n * asset (plus any `additionalUrls`) as root-absolute URLs, with a content-based\n * `version`. It is the dependency-free counterpart to Workbox's `__WB_MANIFEST`:\n * `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service\n * worker's `install` event to cache the app shell for offline use.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaManifest } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * plugins: [tempestPwaManifest({ additionalUrls: [\"/manifest.webmanifest\", \"/icon.svg\"] })],\n * });\n */\nexport function tempestPwaManifest(options: TempestPwaManifestOptions = {}): TempestVitePlugin {\n const {\n fileName = \"precache-manifest.json\",\n additionalUrls = [],\n exclude = /\\.map$/,\n includeHtml = true,\n appShell = \"/index.html\",\n } = options;\n\n let base = \"/\";\n\n const plugin: Plugin = {\n name: \"tempest-pwa-manifest\",\n apply: \"build\",\n configResolved(config) {\n base = config.base ?? \"/\";\n },\n generateBundle(_outputOptions, bundle) {\n const urls = new Set<string>(additionalUrls.map((url) => withBase(base, url)));\n // Vite may emit index.html after this hook, so guarantee the shell.\n if (appShell) urls.add(withBase(base, appShell));\n for (const file of Object.keys(bundle)) {\n if (file === fileName) continue;\n if (exclude.test(file)) continue;\n if (!includeHtml && file.endsWith(\".html\")) continue;\n urls.add(joinBase(base, file));\n }\n\n const list = [...urls].sort();\n const version = hash(list.join(\"\\n\"));\n this.emitFile({\n type: \"asset\",\n fileName,\n source: JSON.stringify({ version, urls: list }),\n });\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"mappings":";;AAsCA,SAASA,EAAS,GAAc,GAAsB;CAClD,OAAO,GAAGC,EAAWC,CAAI,IAAIC,IAAO,QAAQ,gBAAgB,IAAI;AACpE;AASA,SAASC,EAAS,GAAc,GAAqB;CACjD,IAAMC,IAASJ,EAAWC,CAAI;CAG9B,OAFIG,MAAW,MAAYC,EAAI,WAAW,GAAG,IAAIA,IAAM,IAAIA,MACvDA,EAAI,WAAWD,CAAM,IAAUC,IAC5B,GAAGD,IAASC,EAAI,QAAQ,OAAO,EAAE;AAC5C;AAGA,SAASC,EAAK,GAAuB;CACjC,IAAIC,IAAI;CACR,KAAK,IAAIC,IAAI,GAAGA,IAAIC,EAAM,QAAQ,KAC9B,KAAMF,KAAK,KAAKA,IAAIE,EAAM,WAAWD,CAAC,MAAO;CAEjD,OAAOD,EAAE,SAAS,EAAE;AACxB;AAiBA,SAAgBG,EAAmB,IAAqC,CAAC,GAAsB;CAC3F,IAAM,EACF,cAAW,0BACX,oBAAiB,CAAC,GAClB,aAAU,UACV,iBAAc,IACd,cAAW,kBACXC,GAEAV,IAAO;CA6BX,OAAO;EA1BH,MAAM;EACN,OAAO;EACP,eAAe,GAAQ;GACnB,IAAOW,EAAO,QAAQ;EAC1B;EACA,eAAe,GAAgB,GAAQ;GACnC,IAAMC,IAAO,IAAI,IAAYC,EAAe,KAAK,MAAQX,EAASF,GAAMI,CAAG,CAAC,CAAC;GAE7E,AAAIU,KAAUF,EAAK,IAAIV,EAASF,GAAMc,CAAQ,CAAC;GAC/C,KAAK,IAAMb,KAAQ,OAAO,KAAKc,CAAM,GACjC,AAAId,MAASe,MACTC,EAAQ,KAAKhB,CAAI,MAChBiB,KAAe,GAAK,SAAS,OAAO,MACzCN,EAAK,IAAId,EAASE,GAAMC,CAAI,CAAC;GAGjC,IAAMkB,IAAO,CAAC,GAAGP,CAAI,CAAC,CAAC,KAAK,GACtBQ,IAAUf,EAAKc,EAAK,KAAK,IAAI,CAAC;GACpC,KAAK,SAAS;IACV,MAAM;IACN;IACA,QAAQ,KAAK,UAAU;KAAE;KAAS,MAAMA;IAAK,CAAC;GAClD,CAAC;EACL;CAGG;AACX"}
|
|
1
|
+
{"version":3,"file":"tempest-pwa-manifest.js","names":["resolvesToFile","file","toOutputFile","base","url","bundle","publicDir","path","join","existsSync","statSync","joinBase","basePrefix","withBase","prefix","hash","h","i","input","tempestPwaManifest","options","expectedWorker","config","worker","item","PWA_WORKER_PLUGIN_NAME","serviceWorker","urls","additionalUrls","appShell","fileName","exclude","includeHtml","list","version","missing"],"sources":["../../src/vite/tempest-pwa-manifest.ts"],"sourcesContent":["import { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Plugin } from \"vite\";\nimport { basePrefix, toOutputFile } from \"./base-url\";\nimport { PWA_WORKER_PLUGIN_NAME } from \"./tempest-pwa-dev-sw\";\nimport type { TempestPwaWorkerApi } from \"./tempest-pwa-dev-sw\";\n\n/**\n * A Vite plugin object. Typed loosely so the SDK's published declarations stay\n * free of `vite`'s internal types (which the `.d.ts` rollup can't analyze);\n * assign the result straight into a `plugins: [...]` array.\n */\nexport type TempestVitePlugin = { name: string } & Record<string, unknown>;\n\n/** Options for {@link tempestPwaManifest}. */\nexport interface TempestPwaManifestOptions {\n /** Output file name (under the build root). Default `precache-manifest.json`. */\n fileName?: string;\n /**\n * Extra URLs to precache that Vite doesn't emit into the bundle — typically\n * `public/` assets like the web manifest and icons. Default `[]`.\n *\n * Write these relative to the site root (`/icon.svg`); the resolved Vite\n * `base` is prefixed for you. An entry that already carries the base is\n * left alone, so spelling it out by hand is still correct.\n *\n * Every same-origin entry must be a file in `public/` or in the bundle, or\n * the build fails. A URL that resolves to nothing is answered in production\n * by the SPA fallback (`index.html`) or a 404, so the precache would store\n * the app shell under that name, or fail the worker's install outright. The\n * usual culprit is a web manifest linked from `index.html` but kept outside\n * `public/`: Vite hashes it into `assets/`, where it is already precached.\n * Absolute `http(s):` URLs are not checked.\n */\n additionalUrls?: string[];\n /** Emitted files matching this are skipped. Default `/\\.map$/` (source maps). */\n exclude?: RegExp;\n /** Include emitted `.html` documents (the app shell). Default `true`. */\n includeHtml?: boolean;\n /**\n * App-shell document always added to the manifest, even if Vite emits it\n * after this plugin runs. Must match `installPrecache`'s `navigateFallback`\n * so offline navigations resolve. Pass `false` to disable. Default `/index.html`.\n *\n * Like {@link TempestPwaManifestOptions.additionalUrls}, this is prefixed\n * with the resolved Vite `base`.\n */\n appShell?: string | false;\n /**\n * URL of the service worker that reads this manifest. The build fails when\n * no file is emitted at that URL. Default: the `swUrl` of\n * {@link tempestPwaDevSw} when it is in the plugin list, `/sw.js` otherwise.\n *\n * A precache manifest is only read by a worker, and a build that ships the\n * manifest without the worker exits 0 while registration 404s in\n * production — `navigator.serviceWorker.ready` never resolves and push,\n * updates and offline all hang without a message. Pass `false` when the\n * worker is bundled by a separate step after this build (a second\n * `vite build --config vite.sw.config.ts`); `tempestPwaDevSw({ build: false })`\n * already says the same and needs nothing here.\n */\n serviceWorker?: string | false;\n}\n\n/**\n * Whether `url` names something the build can serve: a bundle entry or a file\n * in the public directory.\n *\n * @param url - The URL as written in `additionalUrls`.\n * @param base - Vite's resolved `base`.\n * @param bundle - The final output bundle.\n * @param publicDir - The resolved public directory, or `\"\"` when disabled.\n * @returns `true` when the URL resolves to a real file.\n */\nfunction resolvesToFile(\n url: string,\n base: string,\n bundle: Record<string, unknown>,\n publicDir: string,\n): boolean {\n const file = toOutputFile(base, url);\n if (file in bundle) return true;\n if (!publicDir) return false;\n const path = join(publicDir, file);\n return existsSync(path) && statSync(path).isFile();\n}\n\nfunction joinBase(base: string, file: string): string {\n return `${basePrefix(base)}${file}`.replace(/([^:]\\/)\\/+/g, \"$1\");\n}\n\n/**\n * Prefix a caller-supplied, root-absolute URL with the resolved Vite `base`.\n *\n * Idempotent: a URL that already starts with the base is returned untouched,\n * so configs written before this was applied — spelling the base out by hand —\n * keep producing the same manifest instead of gaining a doubled prefix.\n */\nfunction withBase(base: string, url: string): string {\n const prefix = basePrefix(base);\n if (prefix === \"/\") return url.startsWith(\"/\") ? url : `/${url}`;\n if (url.startsWith(prefix)) return url;\n return `${prefix}${url.replace(/^\\//, \"\")}`;\n}\n\n/** Deterministic djb2 hash → hex. Stable across rebuilds with the same assets. */\nfunction hash(input: string): string {\n let h = 5381;\n for (let i = 0; i < input.length; i++) {\n h = ((h << 5) + h + input.charCodeAt(i)) >>> 0;\n }\n return h.toString(16);\n}\n\n/**\n * Vite build plugin that emits a `precache-manifest.json` listing every built\n * asset (plus any `additionalUrls`) as root-absolute URLs, with a content-based\n * `version`. It is the dependency-free counterpart to Workbox's `__WB_MANIFEST`:\n * `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service\n * worker's `install` event to cache the app shell for offline use.\n *\n * Two mistakes that used to ship in silence now fail the build, after the bundle\n * is written: no service worker emitted at\n * {@link TempestPwaManifestOptions.serviceWorker}, and an `additionalUrls`\n * entry that is neither in `public/` nor in the bundle. Pair it with\n * {@link tempestPwaDevSw}, which bundles `src/sw.ts` into the same build.\n *\n * @example\n * // vite.config.ts\n * import { createViteConfig, tempestPwaDevSw, tempestPwaManifest } from \"tempest-react-sdk/vite\";\n *\n * export default createViteConfig({\n * plugins: [\n * tempestPwaManifest({ additionalUrls: [\"/manifest.webmanifest\", \"/icon.svg\"] }),\n * tempestPwaDevSw(),\n * ],\n * });\n */\nexport function tempestPwaManifest(options: TempestPwaManifestOptions = {}): TempestVitePlugin {\n const {\n fileName = \"precache-manifest.json\",\n additionalUrls = [],\n exclude = /\\.map$/,\n includeHtml = true,\n appShell = \"/index.html\",\n serviceWorker,\n } = options;\n\n let base = \"/\";\n let publicDir = \"\";\n let expectedWorker: string | false = \"/sw.js\";\n\n const plugin: Plugin = {\n name: \"tempest-pwa-manifest\",\n apply: \"build\",\n configResolved(config) {\n base = config.base ?? \"/\";\n publicDir = config.publicDir ?? \"\";\n const worker = (config.plugins ?? []).find(\n (item) => item.name === PWA_WORKER_PLUGIN_NAME,\n )?.api as TempestPwaWorkerApi | undefined;\n if (serviceWorker !== undefined) expectedWorker = serviceWorker;\n else if (worker) expectedWorker = worker.build ? worker.swUrl : false;\n else expectedWorker = \"/sw.js\";\n },\n generateBundle(_outputOptions, bundle) {\n const urls = new Set<string>(additionalUrls.map((url) => withBase(base, url)));\n // Vite may emit index.html after this hook, so guarantee the shell.\n if (appShell) urls.add(withBase(base, appShell));\n for (const file of Object.keys(bundle)) {\n if (file === fileName) continue;\n if (exclude.test(file)) continue;\n if (!includeHtml && file.endsWith(\".html\")) continue;\n urls.add(joinBase(base, file));\n }\n\n const list = [...urls].sort();\n const version = hash(list.join(\"\\n\"));\n this.emitFile({\n type: \"asset\",\n fileName,\n source: JSON.stringify({ version, urls: list }),\n });\n },\n writeBundle(_outputOptions, bundle) {\n const missing = additionalUrls.filter(\n (url) =>\n !/^[a-z][a-z\\d+.-]*:/i.test(url) &&\n !resolvesToFile(url, base, bundle, publicDir),\n );\n if (missing.length > 0) {\n this.error(\n `[tempest-pwa-manifest] additionalUrls lists ${missing.join(\", \")}, which is ` +\n \"neither in public/ nor in the build output. In production that URL \" +\n \"answers with the SPA fallback or a 404, so the precache would store \" +\n \"index.html under its name or fail the worker install. Move the file \" +\n \"into public/, or drop the entry — a file Vite hashes into assets/ \" +\n \"(a web manifest linked from index.html) is already precached.\",\n );\n }\n\n if (expectedWorker === false) return;\n if (toOutputFile(base, expectedWorker) in bundle) return;\n this.error(\n `[tempest-pwa-manifest] the build emitted ${fileName} but no service worker ` +\n `at ${expectedWorker}. In production the registration 404s and ` +\n \"navigator.serviceWorker.ready never resolves (push, updates and offline \" +\n \"hang without an error). Add tempestPwaDevSw() — it bundles src/sw.ts into \" +\n \"this build — or, if a separate step bundles the worker after this one, \" +\n \"pass tempestPwaManifest({ serviceWorker: false }) or \" +\n \"tempestPwaDevSw({ build: false }).\",\n );\n },\n };\n\n return plugin as TempestVitePlugin;\n}\n"],"mappings":";;;;;AA0EA,SAASA,EACL,GACA,GACA,GACA,GACO;CACP,IAAMC,IAAOC,EAAaC,GAAMC,CAAG;CACnC,IAAIH,KAAQI,GAAQ,OAAO;CAC3B,IAAI,CAACC,GAAW,OAAO;CACvB,IAAMC,IAAOC,EAAKF,GAAWL,CAAI;CACjC,OAAOQ,EAAWF,CAAI,KAAKG,EAASH,CAAI,CAAC,CAAC,OAAO;AACrD;AAEA,SAASI,EAAS,GAAc,GAAsB;CAClD,OAAO,GAAGC,EAAWT,CAAI,IAAIF,IAAO,QA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IAAIhB,EAASR,GAAMF,CAAI,CAAC;GAGjC,IAAMgC,IAAO,CAAC,GAAGN,CAAI,CAAC,CAAC,KAAK,GACtBO,IAAUnB,EAAKkB,EAAK,KAAK,IAAI,CAAC;GACpC,KAAK,SAAS;IACV,MAAM;IACN;IACA,QAAQ,KAAK,UAAU;KAAE;KAAS,MAAMA;IAAK,CAAC;GAClD,CAAC;EACL;EACA,YAAY,GAAgB,GAAQ;GAChC,IAAME,IAAUP,EAAe,QAC1B,MACG,CAAC,sBAAsB,KAAKxB,CAAG,KAC/B,CAACJ,EAAeI,GAAKD,GAAME,GAAQC,CAAS,CACpD;GAYA,AAXI6B,EAAQ,SAAS,KACjB,KAAK,MACD,+CAA+CA,EAAQ,KAAK,IAAI,EAAE,sVAMtE,GAGAd,MAAmB,OACnBnB,EAAaC,GAAMkB,CAAc,KAAKhB,KAC1C,KAAK,MACD,4CAA4CyB,EAAS,4BAC3CT,EAAe,2VAM7B;EACJ;CAGG;AACX"}
|
package/dist/vite.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./vite/tempest-icons.cjs"),t=require("./vite/tempest-vitest.cjs"),n=require("./vite/create-vite-config.cjs"),r=require("./vite/tempest-pwa-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./vite/tempest-icons.cjs"),t=require("./vite/tempest-vitest.cjs"),n=require("./vite/create-vite-config.cjs"),r=require("./vite/tempest-pwa-dev-sw.cjs"),i=require("./vite/tempest-pwa-manifest.cjs"),a=require("./vite/tempest-pwa-icons.cjs"),o=require("./vite/tempest-styles.cjs"),s=require("./vite/tempest-csp.cjs");exports.createViteConfig=n.createViteConfig,exports.tempestCsp=s.tempestCsp,exports.tempestIcons=e.tempestIcons,exports.tempestPwaDevSw=r.tempestPwaDevSw,exports.tempestPwaIcons=a.tempestPwaIcons,exports.tempestPwaManifest=i.tempestPwaManifest,exports.tempestStyles=o.tempestStyles,exports.tempestVitest=t.tempestVitest;
|
package/dist/vite.d.ts
CHANGED
|
@@ -300,20 +300,31 @@ export declare interface TempestIconsOptions {
|
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* dev there is no `/sw.js` to register. This plugin compiles `swSrc` on the
|
|
307
|
-
* with esbuild — through one incremental context, not a cold build per
|
|
308
|
-
* and serves it as a classic worker, plus an empty
|
|
309
|
-
*
|
|
310
|
-
*
|
|
303
|
+
* Service-worker plugin: serves `swSrc` under `npm run dev` and bundles it into
|
|
304
|
+
* the production build.
|
|
305
|
+
*
|
|
306
|
+
* In dev there is no `/sw.js` to register. This plugin compiles `swSrc` on the
|
|
307
|
+
* fly with esbuild — through one incremental context, not a cold build per
|
|
308
|
+
* request — and serves it as a classic worker, plus an empty
|
|
309
|
+
* `precache-manifest.json` (there are no hashed build assets to precache in
|
|
310
|
+
* dev — push and runtime caching still work).
|
|
311
|
+
*
|
|
312
|
+
* In `vite build` it bundles the same entry with Vite's own `build()` (IIFE, so
|
|
313
|
+
* it registers as a classic worker, exactly what the old `vite.sw.config.ts`
|
|
314
|
+
* produced) and emits it at `swUrl`. Before 0.83.0 it was serve-only: an app
|
|
315
|
+
* with this plugin and {@link tempestPwaManifest} worked in dev and shipped a
|
|
316
|
+
* production build with no `sw.js` and a zero exit code, so registration
|
|
317
|
+
* 404'd and `navigator.serviceWorker.ready` never resolved. The emitted worker
|
|
318
|
+
* starts with the precache `version` (see {@link precacheVersionBanner}), so
|
|
319
|
+
* every deploy that changes the precache changes the worker bytes and the
|
|
320
|
+
* browser installs it. Pass `build: false` when another step bundles the
|
|
321
|
+
* worker.
|
|
311
322
|
*
|
|
312
323
|
* @example
|
|
313
324
|
* // vite.config.ts
|
|
314
|
-
* import { createViteConfig, tempestPwaDevSw } from "tempest-react-sdk/vite";
|
|
325
|
+
* import { createViteConfig, tempestPwaDevSw, tempestPwaManifest } from "tempest-react-sdk/vite";
|
|
315
326
|
*
|
|
316
|
-
* export default createViteConfig({ plugins: [tempestPwaDevSw()] });
|
|
327
|
+
* export default createViteConfig({ plugins: [tempestPwaManifest(), tempestPwaDevSw()] });
|
|
317
328
|
*/
|
|
318
329
|
export declare function tempestPwaDevSw(options?: TempestPwaDevSwOptions): TempestVitePlugin;
|
|
319
330
|
|
|
@@ -337,6 +348,15 @@ export declare interface TempestPwaDevSwOptions {
|
|
|
337
348
|
manifestUrl?: string;
|
|
338
349
|
/** Serve the worker in dev. Default `true`; set `false` to opt out. */
|
|
339
350
|
enabled?: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* Bundle `swSrc` into the production build as `swUrl`. Default `true`.
|
|
353
|
+
*
|
|
354
|
+
* Set `false` only when another step bundles the worker (a second
|
|
355
|
+
* `vite build --config vite.sw.config.ts`, `vite-plugin-pwa`). That is also
|
|
356
|
+
* what tells {@link tempestPwaManifest} the worker is external, so its
|
|
357
|
+
* missing-worker check stands down.
|
|
358
|
+
*/
|
|
359
|
+
build?: boolean;
|
|
340
360
|
}
|
|
341
361
|
|
|
342
362
|
/**
|
|
@@ -395,12 +415,21 @@ export declare interface TempestPwaIconsOptions {
|
|
|
395
415
|
* `installPrecache` (from `tempest-react-sdk/sw`) reads this file at the service
|
|
396
416
|
* worker's `install` event to cache the app shell for offline use.
|
|
397
417
|
*
|
|
418
|
+
* Two mistakes that used to ship in silence now fail the build, after the bundle
|
|
419
|
+
* is written: no service worker emitted at
|
|
420
|
+
* {@link TempestPwaManifestOptions.serviceWorker}, and an `additionalUrls`
|
|
421
|
+
* entry that is neither in `public/` nor in the bundle. Pair it with
|
|
422
|
+
* {@link tempestPwaDevSw}, which bundles `src/sw.ts` into the same build.
|
|
423
|
+
*
|
|
398
424
|
* @example
|
|
399
425
|
* // vite.config.ts
|
|
400
|
-
* import { createViteConfig, tempestPwaManifest } from "tempest-react-sdk/vite";
|
|
426
|
+
* import { createViteConfig, tempestPwaDevSw, tempestPwaManifest } from "tempest-react-sdk/vite";
|
|
401
427
|
*
|
|
402
428
|
* export default createViteConfig({
|
|
403
|
-
* plugins: [
|
|
429
|
+
* plugins: [
|
|
430
|
+
* tempestPwaManifest({ additionalUrls: ["/manifest.webmanifest", "/icon.svg"] }),
|
|
431
|
+
* tempestPwaDevSw(),
|
|
432
|
+
* ],
|
|
404
433
|
* });
|
|
405
434
|
*/
|
|
406
435
|
export declare function tempestPwaManifest(options?: TempestPwaManifestOptions): TempestVitePlugin;
|
|
@@ -416,6 +445,14 @@ export declare interface TempestPwaManifestOptions {
|
|
|
416
445
|
* Write these relative to the site root (`/icon.svg`); the resolved Vite
|
|
417
446
|
* `base` is prefixed for you. An entry that already carries the base is
|
|
418
447
|
* left alone, so spelling it out by hand is still correct.
|
|
448
|
+
*
|
|
449
|
+
* Every same-origin entry must be a file in `public/` or in the bundle, or
|
|
450
|
+
* the build fails. A URL that resolves to nothing is answered in production
|
|
451
|
+
* by the SPA fallback (`index.html`) or a 404, so the precache would store
|
|
452
|
+
* the app shell under that name, or fail the worker's install outright. The
|
|
453
|
+
* usual culprit is a web manifest linked from `index.html` but kept outside
|
|
454
|
+
* `public/`: Vite hashes it into `assets/`, where it is already precached.
|
|
455
|
+
* Absolute `http(s):` URLs are not checked.
|
|
419
456
|
*/
|
|
420
457
|
additionalUrls?: string[];
|
|
421
458
|
/** Emitted files matching this are skipped. Default `/\.map$/` (source maps). */
|
|
@@ -431,6 +468,20 @@ export declare interface TempestPwaManifestOptions {
|
|
|
431
468
|
* with the resolved Vite `base`.
|
|
432
469
|
*/
|
|
433
470
|
appShell?: string | false;
|
|
471
|
+
/**
|
|
472
|
+
* URL of the service worker that reads this manifest. The build fails when
|
|
473
|
+
* no file is emitted at that URL. Default: the `swUrl` of
|
|
474
|
+
* {@link tempestPwaDevSw} when it is in the plugin list, `/sw.js` otherwise.
|
|
475
|
+
*
|
|
476
|
+
* A precache manifest is only read by a worker, and a build that ships the
|
|
477
|
+
* manifest without the worker exits 0 while registration 404s in
|
|
478
|
+
* production — `navigator.serviceWorker.ready` never resolves and push,
|
|
479
|
+
* updates and offline all hang without a message. Pass `false` when the
|
|
480
|
+
* worker is bundled by a separate step after this build (a second
|
|
481
|
+
* `vite build --config vite.sw.config.ts`); `tempestPwaDevSw({ build: false })`
|
|
482
|
+
* already says the same and needs nothing here.
|
|
483
|
+
*/
|
|
484
|
+
serviceWorker?: string | false;
|
|
434
485
|
}
|
|
435
486
|
|
|
436
487
|
/**
|
package/dist/vite.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { tempestIcons as e } from "./vite/tempest-icons.js";
|
|
2
2
|
import { tempestVitest as t } from "./vite/tempest-vitest.js";
|
|
3
3
|
import { createViteConfig as n } from "./vite/create-vite-config.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { tempestPwaDevSw as r } from "./vite/tempest-pwa-dev-sw.js";
|
|
5
|
+
import { tempestPwaManifest as i } from "./vite/tempest-pwa-manifest.js";
|
|
6
|
+
import { tempestPwaIcons as a } from "./vite/tempest-pwa-icons.js";
|
|
7
7
|
import { tempestStyles as o } from "./vite/tempest-styles.js";
|
|
8
8
|
import { tempestCsp as s } from "./vite/tempest-csp.js";
|
|
9
|
-
export { n as createViteConfig, s as tempestCsp, e as tempestIcons,
|
|
9
|
+
export { n as createViteConfig, s as tempestCsp, e as tempestIcons, r as tempestPwaDevSw, a as tempestPwaIcons, i as tempestPwaManifest, o as tempestStyles, t as tempestVitest };
|