@parlor/shell-web 0.4.3 → 0.4.4
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/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAA+B,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGhF,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAA+B,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGhF,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AASlE,eAAO,MAAM,sBAAsB,aAAa,CAAC;AACjD,mGAAmG;AACnG,eAAO,MAAM,wBAAwB,YACnC,uCAAuC,EACvC,yCAAyC,CACjC,CAAC;AACX,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACpD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,wGAAwG;IACxG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,mGAAmG;IACnG,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACvC;AAoCD,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY;;;;;;aAOnC,YAAY;;;EAIxB;AAmBD,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,UAAe,GACvB,YAAY,EAAE,CA0FhB"}
|
package/dist/plugin.js
CHANGED
|
@@ -10,6 +10,7 @@ import { VitePWA } from "vite-plugin-pwa";
|
|
|
10
10
|
import { appCsp, metaCsp, serializeCsp } from "./csp.js";
|
|
11
11
|
import { routeGeneratorOptions, routesDirectory, routeTreeFile } from "./route-tree.js";
|
|
12
12
|
import { pageMatcher, serverRoutes } from "./server-routes.js";
|
|
13
|
+
import { serviceWorkerRegistration } from "./service-worker.js";
|
|
13
14
|
import { renderModule } from "./ssr.js";
|
|
14
15
|
export const FRAMEWORK_ROUTE_PREFIX = "/_parlor";
|
|
15
16
|
/** OAuth discovery lives at the origin root (RFC 8414, RFC 9728), outside the framework prefix. */
|
|
@@ -129,10 +130,13 @@ export function parlorWeb(config, options = {}) {
|
|
|
129
130
|
if (config.web.ssr)
|
|
130
131
|
plugins.push(renderModule(config, root));
|
|
131
132
|
if (config.web.pwa && !options.render) {
|
|
132
|
-
plugins.push(VitePWA({
|
|
133
|
+
plugins.push(serviceWorkerRegistration(), VitePWA({
|
|
133
134
|
registerType: "autoUpdate",
|
|
135
|
+
injectRegister: false,
|
|
134
136
|
manifest: webManifest(config),
|
|
135
137
|
workbox: {
|
|
138
|
+
skipWaiting: true,
|
|
139
|
+
clientsClaim: true,
|
|
136
140
|
navigateFallbackDenylist: [
|
|
137
141
|
FRAMEWORK_ROUTE_PREFIX,
|
|
138
142
|
...OAUTH_DISCOVERY_PREFIXES,
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,S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EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;gBACvE,kEAAkE;gBAClE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG;oBAChB,CAAC,CAAC;wBACE,gBAAgB,EAAE,IAAI;wBACtB,WAAW,EAAE,CAAC,sBAAsB,EAAE,YAAY,CAAC;qBACpD;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;YACD,WAAW,EAAE;gBACX,wBAAwB,EAAE,CAAC,GAAG,EAAE,EAAE;oBAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC;oBACvC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG;wBAAE,OAAO;oBACrC,GAAG,CAAC,OAAO,CAAC,yBAAyB,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACjE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CACxB,CAAC;gBACJ,CAAC;aACF;SACF,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\n\nimport { pagePattern } from \"@parlor/agent-ui\";\nimport { agentManifest, DEFAULT_ROUTE_TREE } from \"@parlor/agent-ui/vite\";\nimport { GENERATED_DIR, generatedDir, type ParlorConfig } from \"@parlor/config\";\nimport { tanstackRouter } from \"@tanstack/router-plugin/vite\";\nimport react from \"@vitejs/plugin-react\";\nimport { defaultClientConditions, type PluginOption } from \"vite\";\nimport { VitePWA } from \"vite-plugin-pwa\";\n\nimport { appCsp, metaCsp, serializeCsp } from \"./csp.js\";\nimport { routeGeneratorOptions, routesDirectory, routeTreeFile } from \"./route-tree.js\";\nimport { pageMatcher, serverRoutes } from \"./server-routes.js\";\nimport { renderModule } from \"./ssr.js\";\n\nexport const FRAMEWORK_ROUTE_PREFIX = \"/_parlor\";\n/** OAuth discovery lives at the origin root (RFC 8414, RFC 9728), outside the framework prefix. */\nexport const OAUTH_DISCOVERY_PREFIXES = [\n \"/.well-known/oauth-protected-resource\",\n \"/.well-known/oauth-authorization-server\",\n] as const;\nexport { DEFAULT_ROUTE_TREE };\n\nexport interface WebOptions {\n readonly conditions?: readonly string[] | undefined;\n readonly serverUrl?: string | undefined;\n /** The origin every target of one `parlor dev` signs for and pairs with, when it is not this page's. */\n readonly appOrigin?: string | undefined;\n readonly root?: string | undefined;\n /** Writes the policy into the built `index.html` for shells that serve it without HTTP headers. */\n readonly cspMeta?: boolean | undefined;\n /** Builds the server render module (`web.ssr`) instead of the browser app. */\n readonly render?: boolean | undefined;\n}\n\nfunction isFrameworkPath(url: string | undefined): boolean {\n const path = (url ?? \"\").split(\"?\")[0] ?? \"\";\n return [FRAMEWORK_ROUTE_PREFIX, ...OAUTH_DISCOVERY_PREFIXES].some(\n (prefix) => path === prefix || path.startsWith(`${prefix}/`),\n );\n}\n\nfunction cspPlugin(config: ParlorConfig, options: WebOptions): PluginOption {\n const serverOrigin = options.serverUrl || undefined;\n return {\n name: \"parlor:csp\",\n configureServer(server) {\n const header = serializeCsp(appCsp(config, { serverOrigin, dev: true }));\n server.middlewares.use((request, response, next) => {\n if (!isFrameworkPath(request.url)) {\n response.setHeader(\"content-security-policy\", header);\n }\n next();\n });\n },\n transformIndexHtml(_html, context) {\n if (context.server || !options.cspMeta) return;\n const content = serializeCsp(metaCsp(appCsp(config, { serverOrigin })));\n return [\n {\n tag: \"meta\",\n attrs: { \"http-equiv\": \"Content-Security-Policy\", content },\n injectTo: \"head-prepend\",\n },\n ];\n },\n };\n}\n\nexport function webManifest(config: ParlorConfig) {\n return {\n id: config.app.id,\n name: config.app.name,\n short_name: config.app.name,\n ...(config.app.description ? { description: config.app.description } : {}),\n start_url: \"/\",\n display: \"standalone\" as const,\n theme_color: config.web.themeColor,\n background_color: config.web.backgroundColor,\n };\n}\n\nfunction fileRoutes(config: ParlorConfig, root: string): PluginOption[] {\n if (!existsSync(resolve(root, routesDirectory(config)))) return [];\n return [\n tanstackRouter({ ...routeGeneratorOptions(config, root), autoCodeSplitting: true }),\n ];\n}\n\nfunction titlePlugin(config: ParlorConfig): PluginOption {\n return {\n name: \"parlor:title\",\n transformIndexHtml(html) {\n if (/<title>/i.test(html)) return;\n return [{ tag: \"title\", children: config.app.name, injectTo: \"head\" }];\n },\n };\n}\n\nexport function parlorWeb(\n config: ParlorConfig,\n options: WebOptions = {},\n): PluginOption[] {\n const conditions = options.conditions ?? [];\n const root = options.root ?? process.cwd();\n const generated = generatedDir(root);\n const ownGeneratedDir = generated !== resolve(root, GENERATED_DIR);\n const manifest = agentManifest({\n app: {\n id: config.app.id,\n name: config.app.name,\n ...(config.app.description ? { description: config.app.description } : {}),\n ...(config.app.scheme ? { scheme: config.app.scheme } : {}),\n },\n routeTree: routeTreeFile(config),\n generatedDir: generated,\n });\n const plugins: PluginOption[] = [\n ...fileRoutes(config, root),\n react(),\n cspPlugin(config, options),\n titlePlugin(config),\n manifest,\n serverRoutes(\n config.server.port,\n pageMatcher(() => manifest.api?.manifest()),\n {\n // A native shell's platform conditions: it runs the static build, never a server render.\n render: config.web.ssr !== undefined && conditions.length === 0,\n },\n ),\n {\n name: \"parlor:web\",\n config: () => ({\n define: {\n \"import.meta.env.PARLOR_SERVER_URL\": JSON.stringify(options.serverUrl ?? \"\"),\n \"import.meta.env.PARLOR_APP_ORIGIN\": JSON.stringify(options.appOrigin ?? \"\"),\n \"import.meta.env.PARLOR_APP_SCHEME\": JSON.stringify(config.app.scheme ?? \"\"),\n },\n resolve: { conditions: [...defaultClientConditions, ...conditions] },\n // A run with its own generated directory may run beside another Vite on this root.\n ...(ownGeneratedDir ? { cacheDir: join(generated, \"vite\") } : {}),\n server: {\n port: config.web.port,\n strictPort: true,\n watch: { ignored: [`**/${GENERATED_DIR}/**`, join(generated, \"**\")] },\n proxy: Object.fromEntries(\n [FRAMEWORK_ROUTE_PREFIX, ...OAUTH_DISCOVERY_PREFIXES].map((prefix) => [\n prefix,\n `http://localhost:${config.server.port}`,\n ]),\n ),\n },\n }),\n },\n ];\n if (config.web.ssr) plugins.push(renderModule(config, root));\n if (config.web.pwa && !options.render) {\n plugins.push(\n VitePWA({\n registerType: \"autoUpdate\",\n manifest: webManifest(config),\n workbox: {\n navigateFallbackDenylist: [\n FRAMEWORK_ROUTE_PREFIX,\n ...OAUTH_DISCOVERY_PREFIXES,\n ].map((prefix) => new RegExp(`^${prefix.replaceAll(\".\", \"\\\\.\")}(/|$)`)),\n // A cached shell would stand in for the pages the server renders.\n ...(config.web.ssr\n ? {\n navigateFallback: null,\n globIgnores: [\"**/node_modules/**/*\", \"index.html\"],\n }\n : {}),\n },\n integration: {\n beforeBuildServiceWorker: (pwa) => {\n const pages = manifest.api?.manifest();\n if (!pages || config.web.ssr) return;\n pwa.workbox.navigateFallbackAllowlist = pages.routes.map((route) =>\n pagePattern(route.path),\n );\n },\n },\n }),\n );\n }\n return plugins;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAqB,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAqB,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAi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,CAAC,EAAE,CAAC;aACR;YACD,WAAW,EAAE;gBACX,wBAAwB,EAAE,CAAC,GAAG,EAAE,EAAE;oBAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC;oBACvC,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG;wBAAE,OAAO;oBACrC,GAAG,CAAC,OAAO,CAAC,yBAAyB,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACjE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CACxB,CAAC;gBACJ,CAAC;aACF;SACF,CAAC,CACH,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join, resolve } from \"node:path\";\n\nimport { pagePattern } from \"@parlor/agent-ui\";\nimport { agentManifest, DEFAULT_ROUTE_TREE } from \"@parlor/agent-ui/vite\";\nimport { GENERATED_DIR, generatedDir, type ParlorConfig } from \"@parlor/config\";\nimport { tanstackRouter } from \"@tanstack/router-plugin/vite\";\nimport react from \"@vitejs/plugin-react\";\nimport { defaultClientConditions, type PluginOption } from \"vite\";\nimport { VitePWA } from \"vite-plugin-pwa\";\n\nimport { appCsp, metaCsp, serializeCsp } from \"./csp.js\";\nimport { routeGeneratorOptions, routesDirectory, routeTreeFile } from \"./route-tree.js\";\nimport { pageMatcher, serverRoutes } from \"./server-routes.js\";\nimport { serviceWorkerRegistration } from \"./service-worker.js\";\nimport { renderModule } from \"./ssr.js\";\n\nexport const FRAMEWORK_ROUTE_PREFIX = \"/_parlor\";\n/** OAuth discovery lives at the origin root (RFC 8414, RFC 9728), outside the framework prefix. */\nexport const OAUTH_DISCOVERY_PREFIXES = [\n \"/.well-known/oauth-protected-resource\",\n \"/.well-known/oauth-authorization-server\",\n] as const;\nexport { DEFAULT_ROUTE_TREE };\n\nexport interface WebOptions {\n readonly conditions?: readonly string[] | undefined;\n readonly serverUrl?: string | undefined;\n /** The origin every target of one `parlor dev` signs for and pairs with, when it is not this page's. */\n readonly appOrigin?: string | undefined;\n readonly root?: string | undefined;\n /** Writes the policy into the built `index.html` for shells that serve it without HTTP headers. */\n readonly cspMeta?: boolean | undefined;\n /** Builds the server render module (`web.ssr`) instead of the browser app. */\n readonly render?: boolean | undefined;\n}\n\nfunction isFrameworkPath(url: string | undefined): boolean {\n const path = (url ?? \"\").split(\"?\")[0] ?? \"\";\n return [FRAMEWORK_ROUTE_PREFIX, ...OAUTH_DISCOVERY_PREFIXES].some(\n (prefix) => path === prefix || path.startsWith(`${prefix}/`),\n );\n}\n\nfunction cspPlugin(config: ParlorConfig, options: WebOptions): PluginOption {\n const serverOrigin = options.serverUrl || undefined;\n return {\n name: \"parlor:csp\",\n configureServer(server) {\n const header = serializeCsp(appCsp(config, { serverOrigin, dev: true }));\n server.middlewares.use((request, response, next) => {\n if (!isFrameworkPath(request.url)) {\n response.setHeader(\"content-security-policy\", header);\n }\n next();\n });\n },\n transformIndexHtml(_html, context) {\n if (context.server || !options.cspMeta) return;\n const content = serializeCsp(metaCsp(appCsp(config, { serverOrigin })));\n return [\n {\n tag: \"meta\",\n attrs: { \"http-equiv\": \"Content-Security-Policy\", content },\n injectTo: \"head-prepend\",\n },\n ];\n },\n };\n}\n\nexport function webManifest(config: ParlorConfig) {\n return {\n id: config.app.id,\n name: config.app.name,\n short_name: config.app.name,\n ...(config.app.description ? { description: config.app.description } : {}),\n start_url: \"/\",\n display: \"standalone\" as const,\n theme_color: config.web.themeColor,\n background_color: config.web.backgroundColor,\n };\n}\n\nfunction fileRoutes(config: ParlorConfig, root: string): PluginOption[] {\n if (!existsSync(resolve(root, routesDirectory(config)))) return [];\n return [\n tanstackRouter({ ...routeGeneratorOptions(config, root), autoCodeSplitting: true }),\n ];\n}\n\nfunction titlePlugin(config: ParlorConfig): PluginOption {\n return {\n name: \"parlor:title\",\n transformIndexHtml(html) {\n if (/<title>/i.test(html)) return;\n return [{ tag: \"title\", children: config.app.name, injectTo: \"head\" }];\n },\n };\n}\n\nexport function parlorWeb(\n config: ParlorConfig,\n options: WebOptions = {},\n): PluginOption[] {\n const conditions = options.conditions ?? [];\n const root = options.root ?? process.cwd();\n const generated = generatedDir(root);\n const ownGeneratedDir = generated !== resolve(root, GENERATED_DIR);\n const manifest = agentManifest({\n app: {\n id: config.app.id,\n name: config.app.name,\n ...(config.app.description ? { description: config.app.description } : {}),\n ...(config.app.scheme ? { scheme: config.app.scheme } : {}),\n },\n routeTree: routeTreeFile(config),\n generatedDir: generated,\n });\n const plugins: PluginOption[] = [\n ...fileRoutes(config, root),\n react(),\n cspPlugin(config, options),\n titlePlugin(config),\n manifest,\n serverRoutes(\n config.server.port,\n pageMatcher(() => manifest.api?.manifest()),\n {\n // A native shell's platform conditions: it runs the static build, never a server render.\n render: config.web.ssr !== undefined && conditions.length === 0,\n },\n ),\n {\n name: \"parlor:web\",\n config: () => ({\n define: {\n \"import.meta.env.PARLOR_SERVER_URL\": JSON.stringify(options.serverUrl ?? \"\"),\n \"import.meta.env.PARLOR_APP_ORIGIN\": JSON.stringify(options.appOrigin ?? \"\"),\n \"import.meta.env.PARLOR_APP_SCHEME\": JSON.stringify(config.app.scheme ?? \"\"),\n },\n resolve: { conditions: [...defaultClientConditions, ...conditions] },\n // A run with its own generated directory may run beside another Vite on this root.\n ...(ownGeneratedDir ? { cacheDir: join(generated, \"vite\") } : {}),\n server: {\n port: config.web.port,\n strictPort: true,\n watch: { ignored: [`**/${GENERATED_DIR}/**`, join(generated, \"**\")] },\n proxy: Object.fromEntries(\n [FRAMEWORK_ROUTE_PREFIX, ...OAUTH_DISCOVERY_PREFIXES].map((prefix) => [\n prefix,\n `http://localhost:${config.server.port}`,\n ]),\n ),\n },\n }),\n },\n ];\n if (config.web.ssr) plugins.push(renderModule(config, root));\n if (config.web.pwa && !options.render) {\n plugins.push(\n serviceWorkerRegistration(),\n VitePWA({\n registerType: \"autoUpdate\",\n injectRegister: false,\n manifest: webManifest(config),\n workbox: {\n skipWaiting: true,\n clientsClaim: true,\n navigateFallbackDenylist: [\n FRAMEWORK_ROUTE_PREFIX,\n ...OAUTH_DISCOVERY_PREFIXES,\n ].map((prefix) => new RegExp(`^${prefix.replaceAll(\".\", \"\\\\.\")}(/|$)`)),\n // A cached shell would stand in for the pages the server renders.\n ...(config.web.ssr\n ? {\n navigateFallback: null,\n globIgnores: [\"**/node_modules/**/*\", \"index.html\"],\n }\n : {}),\n },\n integration: {\n beforeBuildServiceWorker: (pwa) => {\n const pages = manifest.api?.manifest();\n if (!pages || config.web.ssr) return;\n pwa.workbox.navigateFallbackAllowlist = pages.routes.map((route) =>\n pagePattern(route.path),\n );\n },\n },\n }),\n );\n }\n return plugins;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export declare const SERVICE_WORKER_REGISTRATION = "register-sw.js";
|
|
3
|
+
/**
|
|
4
|
+
* Registers the service worker, and reloads a page that an older build's worker served once
|
|
5
|
+
* the new build's worker takes it over, so a deploy reaches open and reopened pages.
|
|
6
|
+
*/
|
|
7
|
+
export declare function serviceWorkerRegistrationSource(base: string): string;
|
|
8
|
+
export declare function serviceWorkerRegistration(): Plugin;
|
|
9
|
+
//# sourceMappingURL=service-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-worker.d.ts","sourceRoot":"","sources":["../src/service-worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAcpE;AAED,wBAAgB,yBAAyB,IAAI,MAAM,CAuBlD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const SERVICE_WORKER_REGISTRATION = "register-sw.js";
|
|
2
|
+
/**
|
|
3
|
+
* Registers the service worker, and reloads a page that an older build's worker served once
|
|
4
|
+
* the new build's worker takes it over, so a deploy reaches open and reopened pages.
|
|
5
|
+
*/
|
|
6
|
+
export function serviceWorkerRegistrationSource(base) {
|
|
7
|
+
return `if ("serviceWorker" in navigator) {
|
|
8
|
+
window.addEventListener("load", () => {
|
|
9
|
+
const updating = navigator.serviceWorker.controller !== null;
|
|
10
|
+
let reloaded = false;
|
|
11
|
+
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
|
12
|
+
if (!updating || reloaded) return;
|
|
13
|
+
reloaded = true;
|
|
14
|
+
window.location.reload();
|
|
15
|
+
});
|
|
16
|
+
navigator.serviceWorker.register(${JSON.stringify(`${base}sw.js`)}, { scope: ${JSON.stringify(base)} });
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
export function serviceWorkerRegistration() {
|
|
22
|
+
let base = "/";
|
|
23
|
+
return {
|
|
24
|
+
name: "parlor:service-worker-registration",
|
|
25
|
+
apply: "build",
|
|
26
|
+
configResolved(resolved) {
|
|
27
|
+
base = resolved.base;
|
|
28
|
+
},
|
|
29
|
+
generateBundle() {
|
|
30
|
+
this.emitFile({
|
|
31
|
+
type: "asset",
|
|
32
|
+
fileName: SERVICE_WORKER_REGISTRATION,
|
|
33
|
+
source: serviceWorkerRegistrationSource(base),
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
transformIndexHtml: () => [
|
|
37
|
+
{
|
|
38
|
+
tag: "script",
|
|
39
|
+
attrs: { src: `${base}${SERVICE_WORKER_REGISTRATION}`, defer: true },
|
|
40
|
+
injectTo: "head",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=service-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-worker.js","sourceRoot":"","sources":["../src/service-worker.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,2BAA2B,GAAG,gBAAgB,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,+BAA+B,CAAC,IAAY;IAC1D,OAAO;;;;;;;;;uCAS8B,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,OAAO,CAAC,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;;;CAGtG,CAAC;AACF,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,OAAO;QACL,IAAI,EAAE,oCAAoC;QAC1C,KAAK,EAAE,OAAO;QACd,cAAc,CAAC,QAAQ;YACrB,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QACD,cAAc;YACZ,IAAI,CAAC,QAAQ,CAAC;gBACZ,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,2BAA2B;gBACrC,MAAM,EAAE,+BAA+B,CAAC,IAAI,CAAC;aAC9C,CAAC,CAAC;QACL,CAAC;QACD,kBAAkB,EAAE,GAAG,EAAE,CAAC;YACxB;gBACE,GAAG,EAAE,QAAQ;gBACb,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,2BAA2B,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;gBACpE,QAAQ,EAAE,MAAM;aACjB;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from \"vite\";\n\nexport const SERVICE_WORKER_REGISTRATION = \"register-sw.js\";\n\n/**\n * Registers the service worker, and reloads a page that an older build's worker served once\n * the new build's worker takes it over, so a deploy reaches open and reopened pages.\n */\nexport function serviceWorkerRegistrationSource(base: string): string {\n return `if (\"serviceWorker\" in navigator) {\n window.addEventListener(\"load\", () => {\n const updating = navigator.serviceWorker.controller !== null;\n let reloaded = false;\n navigator.serviceWorker.addEventListener(\"controllerchange\", () => {\n if (!updating || reloaded) return;\n reloaded = true;\n window.location.reload();\n });\n navigator.serviceWorker.register(${JSON.stringify(`${base}sw.js`)}, { scope: ${JSON.stringify(base)} });\n });\n}\n`;\n}\n\nexport function serviceWorkerRegistration(): Plugin {\n let base = \"/\";\n return {\n name: \"parlor:service-worker-registration\",\n apply: \"build\",\n configResolved(resolved) {\n base = resolved.base;\n },\n generateBundle() {\n this.emitFile({\n type: \"asset\",\n fileName: SERVICE_WORKER_REGISTRATION,\n source: serviceWorkerRegistrationSource(base),\n });\n },\n transformIndexHtml: () => [\n {\n tag: \"script\",\n attrs: { src: `${base}${SERVICE_WORKER_REGISTRATION}`, defer: true },\n injectTo: \"head\",\n },\n ],\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parlor/shell-web",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"homepage": "https://cychien.github.io/parlor",
|
|
5
5
|
"bugs": "https://github.com/cychien/parlor/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"vite-plugin-pwa": "^2.0.0",
|
|
26
26
|
"workbox-build": "^7.4.1",
|
|
27
27
|
"workbox-window": "^7.4.1",
|
|
28
|
-
"@parlor/
|
|
29
|
-
"@parlor/
|
|
28
|
+
"@parlor/agent-ui": "0.4.4",
|
|
29
|
+
"@parlor/config": "0.4.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@tanstack/react-query": "^5.104.1",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"typescript": "^7.0.2",
|
|
39
39
|
"vite": "^8.3.5",
|
|
40
40
|
"vitest": "^5.0.3",
|
|
41
|
-
"@parlor/client": "0.4.
|
|
41
|
+
"@parlor/client": "0.4.4"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"vite": "^8.0.0"
|