@sixb/app 0.1.6 → 0.1.8
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 +20 -0
- package/dist/agents.js +6 -6
- package/dist/agents.js.map +1 -1
- package/dist/browser.d.ts +3 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +9 -0
- package/dist/browser.js.map +9 -0
- package/dist/chunk-e1gj8c1a.js +8 -0
- package/dist/chunk-e1gj8c1a.js.map +10 -0
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -27
- package/dist/index.js.map +4 -4
- package/dist/public-env.d.ts +3 -0
- package/dist/public-env.d.ts.map +1 -0
- package/dist/runtime.d.ts +3 -1
- package/dist/runtime.d.ts.map +1 -1
- package/package.json +12 -6
- package/src/browser.ts +2 -0
- package/src/createCustomApp.ts +47 -15
- package/src/index.ts +1 -0
- package/src/public-env.ts +10 -0
- package/src/runtime.ts +11 -1
package/README.md
CHANGED
|
@@ -8,6 +8,26 @@ Reusable toolkit for project-specific Sixb apps. It owns custom app route scanni
|
|
|
8
8
|
bun add @sixb/app
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Public environment variables
|
|
12
|
+
|
|
13
|
+
Set browser-safe values with the `SIXB_PUBLIC_` prefix:
|
|
14
|
+
|
|
15
|
+
```dotenv
|
|
16
|
+
SIXB_PUBLIC_GOOGLE_MAPS_API_KEY=your-browser-key
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { publicEnv } from "@sixb/app"
|
|
21
|
+
|
|
22
|
+
const key = publicEnv.SIXB_PUBLIC_GOOGLE_MAPS_API_KEY // string | undefined
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Values are strings; missing keys return `undefined`. Only prefixed variables are available.
|
|
26
|
+
Outside the browser, `publicEnv` is empty. With `sixb dev` and `sixb app`, restart the app server
|
|
27
|
+
after changing values; no rebuild is required.
|
|
28
|
+
|
|
29
|
+
Public values are visible to every user. Never use `SIXB_PUBLIC_` for backend secrets.
|
|
30
|
+
|
|
11
31
|
## How It Works
|
|
12
32
|
|
|
13
33
|
The build pipeline has three stages: **scan**, **codegen**, and **build**.
|
package/dist/agents.js
CHANGED
|
@@ -27,12 +27,12 @@ function AgentsPage(props) {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
export {
|
|
30
|
-
|
|
31
|
-
AgentsPage as default,
|
|
32
|
-
agentContext,
|
|
33
|
-
AgentWorkspaceProvider,
|
|
30
|
+
AgentContextProvider,
|
|
34
31
|
AgentPanel,
|
|
35
|
-
|
|
32
|
+
AgentWorkspaceProvider,
|
|
33
|
+
agentContext,
|
|
34
|
+
AgentsPage as default,
|
|
35
|
+
useAgentContext
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
//# debugId=
|
|
38
|
+
//# debugId=3AD9669FC46042C864756E2164756E21
|
package/dist/agents.js.map
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
"import { AgentChatPage, type AgentChatPageProps } from \"@sixb/agent-ui/react-router\"\nimport { createContext, createElement, type PropsWithChildren, useContext } from \"react\"\n\nexport {\n AgentContextProvider,\n type AgentDocumentPreviewRenderer,\n type AgentDocumentPreviewRendererProps,\n type AgentFileRef,\n AgentPanel,\n type AgentPanelProps,\n useAgentContext,\n} from \"@sixb/agent-ui\"\n\nexport { agentContext } from \"@sixb/core/agents/context\"\n\nexport type AgentsPageProps = Omit<AgentChatPageProps, \"routeBase\">\n\ntype AgentWorkspaceConfiguration = Pick<\n AgentsPageProps,\n \"sidebarHeader\" | \"sidebarFooter\" | \"sidebarWidth\" | \"documentPreviewRenderers\"\n>\n\nexport type AgentWorkspaceProviderProps = PropsWithChildren<AgentWorkspaceConfiguration>\n\nconst AgentWorkspaceContext = createContext<AgentWorkspaceConfiguration>({})\n\n/** Configure the framework-owned Agents routes, typically from `app/agents/layout.tsx`. */\nexport function AgentWorkspaceProvider({\n sidebarHeader,\n sidebarFooter,\n sidebarWidth,\n documentPreviewRenderers,\n children,\n}: AgentWorkspaceProviderProps) {\n return createElement(\n AgentWorkspaceContext.Provider,\n { value: { sidebarHeader, sidebarFooter, sidebarWidth, documentPreviewRenderers } },\n children\n )\n}\n\nexport default function AgentsPage(props: AgentsPageProps) {\n const workspaceConfiguration = useContext(AgentWorkspaceContext)\n\n return createElement(AgentChatPage, {\n ...workspaceConfiguration,\n ...props,\n routeBase: \"/agents\",\n })\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";;AAAA;AACA;AAEA;AAAA;AAAA;AAAA;AAAA;AAUA;AAWA,IAAM,wBAAwB,cAA2C,CAAC,CAAC;AAGpE,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAC8B;AAAA,EAC9B,OAAO,cACL,sBAAsB,UACtB,EAAE,OAAO,EAAE,eAAe,eAAe,cAAc,yBAAyB,EAAE,GAClF,QACF;AAAA;AAGF,SAAwB,UAAU,CAAC,OAAwB;AAAA,EACzD,MAAM,yBAAyB,WAAW,qBAAqB;AAAA,EAE/D,OAAO,cAAc,eAAe;AAAA,OAC/B;AAAA,OACA;AAAA,IACH,WAAW;AAAA,EACb,CAAC;AAAA;",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "3AD9669FC46042C864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/public-env.ts
|
|
3
|
+
var runtime = typeof window === "undefined" ? undefined : window.__SIXB_RUNTIME__;
|
|
4
|
+
var publicEnv2 = Object.freeze(Object.assign(Object.create(null), runtime?.publicEnv));
|
|
5
|
+
|
|
6
|
+
export { publicEnv2 };
|
|
7
|
+
|
|
8
|
+
//# debugId=62C3FDDD48F648C464756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/public-env.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"const runtime =\n typeof window === \"undefined\"\n ? undefined\n : (window as Window & { __SIXB_RUNTIME__?: { publicEnv?: Record<string, string> } })\n .__SIXB_RUNTIME__\n\n/** Public environment captured at app-server startup. Missing values are undefined. */\nexport const publicEnv: Readonly<Record<string, string | undefined>> = Object.freeze(\n Object.assign(Object.create(null), runtime?.publicEnv)\n)\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAAA,IAAM,UACJ,OAAO,WAAW,cACd,YACC,OACE;AAGF,IAAM,aAA0D,OAAO,OAC5E,OAAO,OAAO,OAAO,OAAO,IAAI,GAAG,SAAS,SAAS,CACvD;",
|
|
8
|
+
"debugId": "62C3FDDD48F648C464756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCustomApp.d.ts","sourceRoot":"","sources":["../src/createCustomApp.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,EACL,KAAK,cAAc,EAQpB,MAAM,SAAS,CAAA;AAShB,OAAO,EAAE,KAAK,SAAS,EAAkC,MAAM,WAAW,CAAA;AAI1E,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IACl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AU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAA;IAClC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,qBAAqB,CACnB,OAAO,CAAC,EAAE,gCAAgC,GACzC,OAAO,CAAC,+BAA+B,GAAG,IAAI,CAAC,CAAA;IAClD,GAAG,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACpE;AAYD,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAkjBjG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { type CreateCustomAppOptions, type CustomAppBuildOptions, type CustomAppDevOptions, type CustomAppDevServer, type CustomAppInstance, type CustomAppStartOptions, type CustomAuthExperienceBuildOptions, type CustomAuthExperienceBuildResult, createCustomApp, } from "./createCustomApp";
|
|
2
2
|
export { devReloadResponse } from "./dev-reload";
|
|
3
3
|
export type { AppMetadata } from "./metadata";
|
|
4
|
+
export { publicEnv } from "./public-env";
|
|
4
5
|
export { createTailwindCssCompiler, type TailwindCssCompiler, type TailwindCssCompilerOptions, } from "./tailwind";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACpC,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,GAChC,MAAM,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,gCAAgC,EACrC,KAAK,+BAA+B,EACpC,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EACL,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,GAChC,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
publicEnv2
|
|
4
|
+
} from "./chunk-e1gj8c1a.js";
|
|
5
|
+
|
|
2
6
|
// src/createCustomApp.ts
|
|
3
7
|
import { randomBytes } from "crypto";
|
|
4
8
|
import { watch } from "fs";
|
|
@@ -427,6 +431,9 @@ async function fileExists(path) {
|
|
|
427
431
|
}
|
|
428
432
|
|
|
429
433
|
// src/runtime.ts
|
|
434
|
+
function collectPublicEnv() {
|
|
435
|
+
return Object.fromEntries(Object.entries(process.env).filter((entry) => entry[0].startsWith("SIXB_PUBLIC_") && entry[1] !== undefined));
|
|
436
|
+
}
|
|
430
437
|
function renderCustomAppRuntimeScript(config) {
|
|
431
438
|
const safeConfig = JSON.stringify(config).replaceAll("<", "\\u003c");
|
|
432
439
|
return `<script>window.__SIXB_RUNTIME__ = ${safeConfig};</script>`;
|
|
@@ -1862,8 +1869,8 @@ function createTailwindCssCompiler(options) {
|
|
|
1862
1869
|
activeProcess = proc;
|
|
1863
1870
|
const stderr = new Response(proc.stderr).text().catch(() => "");
|
|
1864
1871
|
let timeout;
|
|
1865
|
-
const timedOut = new Promise((
|
|
1866
|
-
timeout = setTimeout(() =>
|
|
1872
|
+
const timedOut = new Promise((resolve) => {
|
|
1873
|
+
timeout = setTimeout(() => resolve("timeout"), timeoutMs);
|
|
1867
1874
|
});
|
|
1868
1875
|
try {
|
|
1869
1876
|
const outcome = await Promise.race([proc.exited, timedOut]);
|
|
@@ -2131,10 +2138,12 @@ async function createCustomApp(options) {
|
|
|
2131
2138
|
const routes = await scanRoutes();
|
|
2132
2139
|
return routes.length > 0;
|
|
2133
2140
|
},
|
|
2134
|
-
async prepareAuthExperience(
|
|
2135
|
-
return await prepareAuthExperience(
|
|
2141
|
+
async prepareAuthExperience(options) {
|
|
2142
|
+
return await prepareAuthExperience(options);
|
|
2136
2143
|
},
|
|
2137
2144
|
async dev(devOptions = {}) {
|
|
2145
|
+
const publicEnv = collectPublicEnv();
|
|
2146
|
+
const withRuntime = (html) => injectRuntimeConfig(html, { apiBaseUrl, audience, authEnabled, publicEnv });
|
|
2138
2147
|
const host = devOptions.host ?? "0.0.0.0";
|
|
2139
2148
|
const port = devOptions.port ?? 3001;
|
|
2140
2149
|
const { htmlPath, manifestPath, sharedHtmlPath, sharedMainPath } = await prepareGeneratedApp();
|
|
@@ -2165,9 +2174,20 @@ async function createCustomApp(options) {
|
|
|
2165
2174
|
"/__sixb/dev-reload.js": getHeadRoute(devReloadResponse),
|
|
2166
2175
|
[customAppManifestRoute]: manifestRoute(manifestPath),
|
|
2167
2176
|
[privateAppShellRoute]: htmlBundleRoute(bundle),
|
|
2168
|
-
...sharedAppDevRoutes(async () => (await ensureSharedBuild()).html,
|
|
2169
|
-
|
|
2170
|
-
|
|
2177
|
+
...sharedAppDevRoutes(async () => injectRuntimeConfig((await ensureSharedBuild()).html, {
|
|
2178
|
+
apiBaseUrl,
|
|
2179
|
+
audience: "app",
|
|
2180
|
+
authEnabled: false,
|
|
2181
|
+
publicEnv
|
|
2182
|
+
}), apiBaseUrl),
|
|
2183
|
+
"/": spaHtmlRoute(() => internalOrigin, {
|
|
2184
|
+
shellRoute: privateAppShellRoute,
|
|
2185
|
+
transformHtml: withRuntime
|
|
2186
|
+
}),
|
|
2187
|
+
"/*": spaHtmlRoute(() => internalOrigin, {
|
|
2188
|
+
shellRoute: privateAppShellRoute,
|
|
2189
|
+
transformHtml: withRuntime
|
|
2190
|
+
})
|
|
2171
2191
|
}
|
|
2172
2192
|
});
|
|
2173
2193
|
async function ensureSharedBuild() {
|
|
@@ -2187,15 +2207,15 @@ async function createCustomApp(options) {
|
|
|
2187
2207
|
entryPath: sharedHtmlPath,
|
|
2188
2208
|
outdir,
|
|
2189
2209
|
scriptEntryPath: sharedMainPath
|
|
2190
|
-
}).then((
|
|
2210
|
+
}).then((result) => {
|
|
2191
2211
|
sharedAssetRoutes = {
|
|
2192
2212
|
...sharedAssetRoutes,
|
|
2193
|
-
...createGeneratedAssetRoutes(outdir,
|
|
2213
|
+
...createGeneratedAssetRoutes(outdir, result.assetPaths)
|
|
2194
2214
|
};
|
|
2195
|
-
sharedBuild =
|
|
2215
|
+
sharedBuild = result;
|
|
2196
2216
|
sharedBuiltSourceVersion = sourceVersion;
|
|
2197
2217
|
server?.reload(serveOptions(htmlBundle));
|
|
2198
|
-
return
|
|
2218
|
+
return result;
|
|
2199
2219
|
}).finally(() => {
|
|
2200
2220
|
sharedBuildPromise = null;
|
|
2201
2221
|
});
|
|
@@ -2291,6 +2311,7 @@ async function createCustomApp(options) {
|
|
|
2291
2311
|
return result;
|
|
2292
2312
|
},
|
|
2293
2313
|
async start(startOptions = {}) {
|
|
2314
|
+
const publicEnv = collectPublicEnv();
|
|
2294
2315
|
const host = startOptions.host ?? "0.0.0.0";
|
|
2295
2316
|
const port = startOptions.port ?? 3001;
|
|
2296
2317
|
const outdir = resolve3(rootDir, startOptions.outdir ?? join7(".sixb", "dist", "app"));
|
|
@@ -2305,12 +2326,14 @@ async function createCustomApp(options) {
|
|
|
2305
2326
|
const indexHtml = injectRuntimeConfig(await Bun.file(indexPath).text(), {
|
|
2306
2327
|
apiBaseUrl: startOptions.apiBaseUrl ?? apiBaseUrl,
|
|
2307
2328
|
audience: startOptions.audience ?? audience,
|
|
2308
|
-
authEnabled: startOptions.authEnabled ?? authEnabled
|
|
2329
|
+
authEnabled: startOptions.authEnabled ?? authEnabled,
|
|
2330
|
+
publicEnv
|
|
2309
2331
|
});
|
|
2310
2332
|
const sharedIndexHtml = injectRuntimeConfig(await Bun.file(sharedIndexPath).text(), {
|
|
2311
2333
|
apiBaseUrl: startOptions.apiBaseUrl ?? apiBaseUrl,
|
|
2312
2334
|
audience: "app",
|
|
2313
|
-
authEnabled: false
|
|
2335
|
+
authEnabled: false,
|
|
2336
|
+
publicEnv
|
|
2314
2337
|
});
|
|
2315
2338
|
const runtimeApiBaseUrl = startOptions.apiBaseUrl ?? apiBaseUrl;
|
|
2316
2339
|
const server = Bun.serve({
|
|
@@ -2346,6 +2369,9 @@ async function createCustomApp(options) {
|
|
|
2346
2369
|
}
|
|
2347
2370
|
const directFile = Bun.file(resolvedPath);
|
|
2348
2371
|
if (await directFile.exists()) {
|
|
2372
|
+
if (resolvedPath === indexPath) {
|
|
2373
|
+
return htmlResponse(req, indexHtml);
|
|
2374
|
+
}
|
|
2349
2375
|
return staticFileResponse(req, resolvedPath, staticAssetHeaders(url.pathname));
|
|
2350
2376
|
}
|
|
2351
2377
|
if (isAssetRequest(url.pathname)) {
|
|
@@ -2353,6 +2379,9 @@ async function createCustomApp(options) {
|
|
|
2353
2379
|
}
|
|
2354
2380
|
const htmlFile = Bun.file(`${resolvedPath}.html`);
|
|
2355
2381
|
if (await htmlFile.exists()) {
|
|
2382
|
+
if (`${resolvedPath}.html` === indexPath) {
|
|
2383
|
+
return htmlResponse(req, indexHtml);
|
|
2384
|
+
}
|
|
2356
2385
|
return fileResponse(req, htmlFile);
|
|
2357
2386
|
}
|
|
2358
2387
|
const nestedIndexFile = Bun.file(join7(resolvedPath, "index.html"));
|
|
@@ -2563,20 +2592,23 @@ function resolveStaticPath(appRoot, pathname) {
|
|
|
2563
2592
|
return resolvedPath;
|
|
2564
2593
|
}
|
|
2565
2594
|
function injectRuntimeConfig(html, config) {
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
}
|
|
2595
|
+
const existingRuntimeScript = /<script>window\.__SIXB_RUNTIME__ = (.*?);<\/script>/;
|
|
2596
|
+
const existingConfig = html.match(existingRuntimeScript)?.[1];
|
|
2569
2597
|
const script = renderCustomAppRuntimeScript({
|
|
2570
|
-
|
|
2571
|
-
|
|
2598
|
+
auth: { audience: config.audience, enabled: config.authEnabled },
|
|
2599
|
+
...existingConfig ? JSON.parse(existingConfig) : {},
|
|
2600
|
+
...config.apiBaseUrl ? {
|
|
2601
|
+
api: { baseUrl: config.apiBaseUrl },
|
|
2602
|
+
auth: { audience: config.audience, enabled: config.authEnabled }
|
|
2603
|
+
} : {},
|
|
2604
|
+
publicEnv: config.publicEnv
|
|
2572
2605
|
});
|
|
2573
|
-
const existingRuntimeScript = /<script>window\.__SIXB_RUNTIME__ = .*?;<\/script>/;
|
|
2574
2606
|
if (existingRuntimeScript.test(html)) {
|
|
2575
|
-
return html.replace(existingRuntimeScript, script);
|
|
2607
|
+
return html.replace(existingRuntimeScript, () => script);
|
|
2576
2608
|
}
|
|
2577
|
-
if (
|
|
2578
|
-
return html.replace(
|
|
2579
|
-
|
|
2609
|
+
if (/<head\b[^>]*>/i.test(html)) {
|
|
2610
|
+
return html.replace(/<head\b[^>]*>/i, (head) => `${head}
|
|
2611
|
+
${script}`);
|
|
2580
2612
|
}
|
|
2581
2613
|
return `${script}
|
|
2582
2614
|
${html}`;
|
|
@@ -2785,7 +2817,7 @@ function spaHtmlRoute(internalOrigin, options = {}) {
|
|
|
2785
2817
|
});
|
|
2786
2818
|
}
|
|
2787
2819
|
const html = restoreAppStaticUrls(await bundleResponse.text()).replace("</head>", '<script src="/__sixb/dev-reload.js"></script></head>');
|
|
2788
|
-
return new Response(html, {
|
|
2820
|
+
return new Response(options.transformHtml?.(html) ?? html, {
|
|
2789
2821
|
status: bundleResponse.status,
|
|
2790
2822
|
statusText: bundleResponse.statusText,
|
|
2791
2823
|
headers: responseHeaders
|
|
@@ -2793,9 +2825,10 @@ function spaHtmlRoute(internalOrigin, options = {}) {
|
|
|
2793
2825
|
});
|
|
2794
2826
|
}
|
|
2795
2827
|
export {
|
|
2796
|
-
|
|
2828
|
+
createCustomApp,
|
|
2797
2829
|
createTailwindCssCompiler,
|
|
2798
|
-
|
|
2830
|
+
devReloadResponse,
|
|
2831
|
+
publicEnv2 as publicEnv
|
|
2799
2832
|
};
|
|
2800
2833
|
|
|
2801
|
-
//# debugId=
|
|
2834
|
+
//# debugId=6856E0633EA3EB7F64756E2164756E21
|