@sixb/app 0.1.3 → 0.1.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/README.md +33 -12
- package/dist/agents.d.ts +1 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/agents.js.map +1 -1
- package/dist/codegen.d.ts +4 -3
- package/dist/codegen.d.ts.map +1 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.js +323 -102
- package/dist/index.js.map +6 -6
- package/dist/scanner.d.ts +24 -6
- package/dist/scanner.d.ts.map +1 -1
- package/package.json +7 -3
- package/src/agents.ts +1 -1
- package/src/build.ts +6 -4
- package/src/codegen.ts +233 -25
- package/src/createCustomApp.ts +10 -10
- package/src/scanner.ts +191 -46
package/dist/scanner.d.ts
CHANGED
|
@@ -6,14 +6,32 @@ export interface PageRoute {
|
|
|
6
6
|
/** Relative path from the app directory, e.g. "remote/[id]/page.tsx" */
|
|
7
7
|
relativePath: string;
|
|
8
8
|
}
|
|
9
|
+
export interface AppRouteLayout {
|
|
10
|
+
/** React Router prefix owned by this layout, e.g. "/remote/:id". */
|
|
11
|
+
path: string;
|
|
12
|
+
/** Absolute file path. */
|
|
13
|
+
filePath: string;
|
|
14
|
+
/** Relative path from the app directory, e.g. "remote/[id]/layout.tsx". */
|
|
15
|
+
relativePath: string;
|
|
16
|
+
}
|
|
17
|
+
export interface AppRouteDiscovery {
|
|
18
|
+
readonly pages: readonly PageRoute[];
|
|
19
|
+
/** Descendant layouts only. The root layout remains the global app wrapper. */
|
|
20
|
+
readonly layouts: readonly AppRouteLayout[];
|
|
21
|
+
}
|
|
9
22
|
/**
|
|
10
|
-
* Recursively scans an `app/` directory for
|
|
11
|
-
* converts them to React Router route paths.
|
|
23
|
+
* Recursively scans an `app/` directory for page modules and descendant layouts.
|
|
12
24
|
*
|
|
13
|
-
* - `app/page.tsx`
|
|
14
|
-
* - `app/about/page.tsx`
|
|
15
|
-
* - `app/remote/[id]/page.tsx`
|
|
16
|
-
* -
|
|
25
|
+
* - `app/page.tsx` -> page `/`
|
|
26
|
+
* - `app/about/page.tsx` -> page `/about`
|
|
27
|
+
* - `app/remote/[id]/page.tsx` -> page `/remote/:id`
|
|
28
|
+
* - `app/remote/[id]/layout.tsx` -> layout `/remote/:id/**`
|
|
29
|
+
* - `app/layout.tsx` remains the global wrapper and is not returned as a route layout.
|
|
30
|
+
* - Files and folders starting with `_` are skipped.
|
|
17
31
|
*/
|
|
32
|
+
export declare function scanAppRoutes(appDir: string): Promise<AppRouteDiscovery>;
|
|
33
|
+
/** Preserve the existing flat inspection contract while route generation uses the richer scan. */
|
|
18
34
|
export declare function scanPages(appDir: string): Promise<PageRoute[]>;
|
|
35
|
+
/** Treat parameter names as labels when comparing route ownership and overrides. */
|
|
36
|
+
export declare function routePatternKey(path: string): string;
|
|
19
37
|
//# sourceMappingURL=scanner.d.ts.map
|
package/dist/scanner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,SAAS;IACxB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,wEAAwE;IACxE,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAA;IACZ,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,2EAA2E;IAC3E,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,CAAA;IACpC,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAC5C;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAO9E;AAED,kGAAkG;AAClG,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAEpE;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Custom app toolkit for Sixb projects — route scanning, dev serving, and production builds",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -43,12 +43,13 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "bun ../../scripts/build-package.ts",
|
|
46
|
+
"test:e2e": "bun test ./tests/build-browser.e2e.ts",
|
|
46
47
|
"typecheck": "tsc --noEmit",
|
|
47
48
|
"prepack": "bun run build"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@sixb/agent-ui": "^0.1.
|
|
51
|
-
"@sixb/core": "^0.1.
|
|
51
|
+
"@sixb/agent-ui": "^0.1.4",
|
|
52
|
+
"@sixb/core": "^0.1.4",
|
|
52
53
|
"@sixb/ui": "^0.1.1",
|
|
53
54
|
"@tailwindcss/cli": "^4.2.2",
|
|
54
55
|
"tailwindcss": "^4.1.18"
|
|
@@ -60,8 +61,11 @@
|
|
|
60
61
|
"react-router-dom": "^7.0.0"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
64
|
+
"@testing-library/react": "^16.3.2",
|
|
63
65
|
"@types/bun": "latest",
|
|
64
66
|
"@types/react": "^19.0.0",
|
|
67
|
+
"happy-dom": "^20.11.6",
|
|
68
|
+
"libphonenumber-js": "1.13.9",
|
|
65
69
|
"typescript": "^5.7.0"
|
|
66
70
|
},
|
|
67
71
|
"license": "MIT",
|
package/src/agents.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type AgentWorkspaceProviderProps = PropsWithChildren<AgentWorkspaceChrome
|
|
|
21
21
|
|
|
22
22
|
const AgentWorkspaceContext = createContext<AgentWorkspaceChrome>({})
|
|
23
23
|
|
|
24
|
-
/** Configure the framework-owned Agents routes from
|
|
24
|
+
/** Configure the framework-owned Agents routes, typically from `app/agents/layout.tsx`. */
|
|
25
25
|
export function AgentWorkspaceProvider({
|
|
26
26
|
sidebarHeader,
|
|
27
27
|
sidebarFooter,
|
package/src/build.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs"
|
|
2
2
|
import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises"
|
|
3
|
-
import { basename, dirname,
|
|
3
|
+
import { basename, dirname, join, resolve } from "node:path"
|
|
4
4
|
import { promisify } from "node:util"
|
|
5
5
|
import {
|
|
6
6
|
brotliCompress as brotliCompressCallback,
|
|
@@ -229,9 +229,11 @@ const extensionlessSourceImportPlugin: Bun.BunPlugin = {
|
|
|
229
229
|
// A direct TypeScript entry with splitting exposes a Bun 1.3 resolver edge in linked workspace
|
|
230
230
|
// packages: extensionless relative imports such as `../json` can fail even though `json.ts`
|
|
231
231
|
// exists. HTML entries masked it, but HTML splitting can point at the wrong dynamic chunk.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
// Let Bun resolve already-explicit imports without entering this hook. On affected Bun
|
|
233
|
+
// releases (including 1.3.14 and 1.4.0), merely intercepting a package's explicit `.js`
|
|
234
|
+
// imports and returning `undefined` can corrupt DCE: subclass wrappers remain in the bundle
|
|
235
|
+
// while their imported superclass is removed.
|
|
236
|
+
build.onResolve({ filter: /^\.\.?\/(?:.*\/)?[^/.]+$/ }, (args) => {
|
|
235
237
|
const base = resolve(dirname(args.importer), args.path)
|
|
236
238
|
for (const candidate of [
|
|
237
239
|
`${base}.ts`,
|
package/src/codegen.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { AuthSessionAudience } from "@sixb/core"
|
|
|
4
4
|
import { renderAppManifest } from "./manifest"
|
|
5
5
|
import { resolveAppMetadata } from "./metadata"
|
|
6
6
|
import { renderCustomAppRuntimeScript } from "./runtime"
|
|
7
|
-
import type
|
|
7
|
+
import { type AppRouteLayout, type PageRoute, routePatternKey } from "./scanner"
|
|
8
8
|
|
|
9
9
|
export interface BuiltInRouteManifestEntry {
|
|
10
10
|
readonly path: string
|
|
@@ -14,30 +14,35 @@ export interface BuiltInRouteManifestEntry {
|
|
|
14
14
|
|
|
15
15
|
export interface GenerateRouteManifestOptions {
|
|
16
16
|
readonly builtInRoutes?: readonly BuiltInRouteManifestEntry[]
|
|
17
|
+
readonly layouts?: readonly AppRouteLayout[]
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export const AUTH_EXPERIENCE_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__"
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* Generates `.sixb/generated/routes.ts` with static
|
|
23
|
+
* Generates `.sixb/generated/routes.ts` with static page/layout imports. Modules are
|
|
23
24
|
* eager on purpose: project-specific apps bundle small, and a single bundle
|
|
24
25
|
* (one JS file, one render-blocking CSS file) means no Suspense gap or
|
|
25
26
|
* late-arriving styles when navigating — matching how Atlas routes.
|
|
26
27
|
*/
|
|
27
28
|
export async function generateRouteManifest(
|
|
28
|
-
routes: PageRoute[],
|
|
29
|
+
routes: readonly PageRoute[],
|
|
29
30
|
generatedDir: string,
|
|
30
31
|
options: GenerateRouteManifestOptions = {}
|
|
31
32
|
): Promise<string> {
|
|
32
33
|
await mkdir(generatedDir, { recursive: true })
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const pages = [...routes].sort(compareRouteModules)
|
|
36
|
+
const pageImports = pages
|
|
35
37
|
.map((route, index) => {
|
|
36
38
|
const rel = relativeTo(generatedDir, route.filePath)
|
|
37
39
|
return `import Page${index} from ${JSON.stringify(rel)}`
|
|
38
40
|
})
|
|
39
41
|
.join("\n")
|
|
40
|
-
const
|
|
42
|
+
const projectRoutePatterns = new Set(pages.map((route) => routePatternKey(route.path)))
|
|
43
|
+
const builtInRoutes = (options.builtInRoutes ?? []).filter(
|
|
44
|
+
(route) => !projectRoutePatterns.has(routePatternKey(route.path))
|
|
45
|
+
)
|
|
41
46
|
const builtInImports = builtInRoutes
|
|
42
47
|
.map((route, index) => {
|
|
43
48
|
if (route.exportName) {
|
|
@@ -47,23 +52,61 @@ export async function generateRouteManifest(
|
|
|
47
52
|
return `import BuiltInPage${index} from ${JSON.stringify(route.moduleSpecifier)}`
|
|
48
53
|
})
|
|
49
54
|
.join("\n")
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
.
|
|
55
|
+
const routePatterns = [...pages, ...builtInRoutes].map((route) => routePatternKey(route.path))
|
|
56
|
+
const layouts = [...(options.layouts ?? [])]
|
|
57
|
+
.filter((layout) => {
|
|
58
|
+
const layoutPattern = routePatternKey(layout.path)
|
|
59
|
+
return routePatterns.some(
|
|
60
|
+
(routePattern) =>
|
|
61
|
+
routePattern === layoutPattern || routePattern.startsWith(`${layoutPattern}/`)
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
.sort(compareRouteModules)
|
|
65
|
+
const layoutImports = layouts
|
|
66
|
+
.map((layout, index) => {
|
|
67
|
+
const rel = relativeTo(generatedDir, layout.filePath)
|
|
68
|
+
return `import Layout${index} from ${JSON.stringify(rel)}`
|
|
69
|
+
})
|
|
53
70
|
.join("\n")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
|
|
72
|
+
const tree = createRouteTree()
|
|
73
|
+
for (const [index, layout] of layouts.entries()) {
|
|
74
|
+
insertRouteLayout(tree, layout, `Layout${index}`)
|
|
75
|
+
}
|
|
76
|
+
for (const [index, route] of pages.entries()) {
|
|
77
|
+
insertRoutePage(tree, route.path, `Page${index}`, route.relativePath)
|
|
78
|
+
}
|
|
79
|
+
for (const [index, route] of builtInRoutes.entries()) {
|
|
80
|
+
insertRoutePage(
|
|
81
|
+
tree,
|
|
82
|
+
route.path,
|
|
83
|
+
`BuiltInPage${index}`,
|
|
84
|
+
`${route.moduleSpecifier} (${route.path})`
|
|
57
85
|
)
|
|
58
|
-
|
|
59
|
-
const routeEntries = [entries, builtInEntries].filter(Boolean).join("\n")
|
|
60
|
-
const importEntries = [imports, builtInImports].filter(Boolean).join("\n")
|
|
86
|
+
}
|
|
61
87
|
|
|
88
|
+
const importEntries = [
|
|
89
|
+
'import { createElement } from "react"',
|
|
90
|
+
layouts.length > 0
|
|
91
|
+
? 'import { Outlet, type RouteObject } from "react-router-dom"'
|
|
92
|
+
: 'import type { RouteObject } from "react-router-dom"',
|
|
93
|
+
pageImports,
|
|
94
|
+
builtInImports,
|
|
95
|
+
layoutImports,
|
|
96
|
+
]
|
|
97
|
+
.filter(Boolean)
|
|
98
|
+
.join("\n")
|
|
99
|
+
const routePaths = [
|
|
100
|
+
...pages.map((route) => route.path),
|
|
101
|
+
...builtInRoutes.map((route) => route.path),
|
|
102
|
+
]
|
|
62
103
|
const content = `${importEntries}
|
|
63
104
|
|
|
105
|
+
export const routePaths = ${JSON.stringify(routePaths, null, 2)} as const
|
|
106
|
+
|
|
64
107
|
export const routes = [
|
|
65
|
-
${
|
|
66
|
-
]
|
|
108
|
+
${renderRootRouteObjects(tree)}
|
|
109
|
+
] satisfies RouteObject[]
|
|
67
110
|
`
|
|
68
111
|
|
|
69
112
|
const outPath = join(generatedDir, "routes.ts")
|
|
@@ -71,6 +114,164 @@ ${routeEntries}
|
|
|
71
114
|
return outPath
|
|
72
115
|
}
|
|
73
116
|
|
|
117
|
+
interface RouteTreePage {
|
|
118
|
+
readonly componentName: string
|
|
119
|
+
readonly source: string
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface RouteTreeLayout {
|
|
123
|
+
readonly componentName: string
|
|
124
|
+
readonly source: string
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface RouteTreeNode {
|
|
128
|
+
readonly segment: string
|
|
129
|
+
readonly children: Map<string, RouteTreeNode>
|
|
130
|
+
page?: RouteTreePage
|
|
131
|
+
layout?: RouteTreeLayout
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function createRouteTree(segment = ""): RouteTreeNode {
|
|
135
|
+
return { segment, children: new Map() }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function insertRouteLayout(
|
|
139
|
+
root: RouteTreeNode,
|
|
140
|
+
layout: AppRouteLayout,
|
|
141
|
+
componentName: string
|
|
142
|
+
): void {
|
|
143
|
+
if (layout.path === "/") {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`[SixbCustomApp] Root layout ${layout.relativePath} must remain the global app wrapper.`
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
const node = resolveRouteNode(root, layout.path, layout.relativePath)
|
|
149
|
+
if (node.layout) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`[SixbCustomApp] Conflicting layouts '${node.layout.source}' and '${layout.relativePath}' own route '${layout.path}'.`
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
node.layout = { componentName, source: layout.relativePath }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function insertRoutePage(
|
|
158
|
+
root: RouteTreeNode,
|
|
159
|
+
path: string,
|
|
160
|
+
componentName: string,
|
|
161
|
+
source: string
|
|
162
|
+
): void {
|
|
163
|
+
const node = resolveRouteNode(root, path, source)
|
|
164
|
+
if (node.page) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`[SixbCustomApp] Conflicting pages '${node.page.source}' and '${source}' match route '${path}'.`
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
node.page = { componentName, source }
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function resolveRouteNode(root: RouteTreeNode, path: string, source: string): RouteTreeNode {
|
|
173
|
+
let node = root
|
|
174
|
+
for (const segment of splitRoutePath(path)) {
|
|
175
|
+
const key = segment.startsWith(":") ? ":" : segment.toLowerCase()
|
|
176
|
+
const existing = node.children.get(key)
|
|
177
|
+
if (existing) {
|
|
178
|
+
if (
|
|
179
|
+
existing.segment.startsWith(":") &&
|
|
180
|
+
segment.startsWith(":") &&
|
|
181
|
+
existing.segment !== segment
|
|
182
|
+
) {
|
|
183
|
+
throw new Error(
|
|
184
|
+
`[SixbCustomApp] Route '${source}' uses dynamic segment '${segment}', but '${existing.segment}' already owns the same route position. Use one parameter name consistently.`
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
node = existing
|
|
188
|
+
continue
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const child = createRouteTree(segment)
|
|
192
|
+
node.children.set(key, child)
|
|
193
|
+
node = child
|
|
194
|
+
}
|
|
195
|
+
return node
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function renderRootRouteObjects(root: RouteTreeNode): string {
|
|
199
|
+
const lines: string[] = []
|
|
200
|
+
if (root.page) {
|
|
201
|
+
lines.push(` { path: "/", element: createElement(${root.page.componentName}) },`)
|
|
202
|
+
}
|
|
203
|
+
for (const child of sortedRenderableChildren(root)) {
|
|
204
|
+
lines.push(...renderRouteNode(child, 1))
|
|
205
|
+
}
|
|
206
|
+
return lines.join("\n")
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function renderRouteNode(node: RouteTreeNode, depth: number): string[] {
|
|
210
|
+
const indent = " ".repeat(depth)
|
|
211
|
+
const children = sortedRenderableChildren(node)
|
|
212
|
+
if (!node.layout && node.page && children.length === 0) {
|
|
213
|
+
return [
|
|
214
|
+
`${indent}{ path: ${JSON.stringify(node.segment)}, element: createElement(${node.page.componentName}) },`,
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const lines = [`${indent}{`, `${indent} path: ${JSON.stringify(node.segment)},`]
|
|
219
|
+
if (node.layout) {
|
|
220
|
+
lines.push(
|
|
221
|
+
`${indent} element: createElement(${node.layout.componentName}, { children: createElement(Outlet) }),`
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
lines.push(`${indent} children: [`)
|
|
225
|
+
if (node.page) {
|
|
226
|
+
lines.push(`${indent} { index: true, element: createElement(${node.page.componentName}) },`)
|
|
227
|
+
}
|
|
228
|
+
for (const child of children) {
|
|
229
|
+
lines.push(...renderRouteNode(child, depth + 2))
|
|
230
|
+
}
|
|
231
|
+
lines.push(`${indent} ],`, `${indent}},`)
|
|
232
|
+
return lines
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function sortedRenderableChildren(node: RouteTreeNode): RouteTreeNode[] {
|
|
236
|
+
return [...node.children.values()].filter(hasPageDescendant).sort((a, b) => {
|
|
237
|
+
const aDynamic = a.segment.startsWith(":")
|
|
238
|
+
const bDynamic = b.segment.startsWith(":")
|
|
239
|
+
if (aDynamic !== bDynamic) return aDynamic ? 1 : -1
|
|
240
|
+
return compareText(a.segment, b.segment)
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function hasPageDescendant(node: RouteTreeNode): boolean {
|
|
245
|
+
if (node.page) return true
|
|
246
|
+
for (const child of node.children.values()) {
|
|
247
|
+
if (hasPageDescendant(child)) return true
|
|
248
|
+
}
|
|
249
|
+
return false
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function splitRoutePath(path: string): string[] {
|
|
253
|
+
if (path === "/") return []
|
|
254
|
+
if (!path.startsWith("/")) {
|
|
255
|
+
throw new Error(`[SixbCustomApp] Route path '${path}' must start with '/'.`)
|
|
256
|
+
}
|
|
257
|
+
const segments = path.slice(1).split("/")
|
|
258
|
+
if (segments.some((segment) => !segment)) {
|
|
259
|
+
throw new Error(`[SixbCustomApp] Route path '${path}' contains an empty segment.`)
|
|
260
|
+
}
|
|
261
|
+
return segments
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function compareRouteModules(
|
|
265
|
+
a: Pick<AppRouteLayout, "path" | "relativePath">,
|
|
266
|
+
b: Pick<AppRouteLayout, "path" | "relativePath">
|
|
267
|
+
): number {
|
|
268
|
+
return compareText(a.path, b.path) || compareText(a.relativePath, b.relativePath)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function compareText(a: string, b: string): number {
|
|
272
|
+
return a < b ? -1 : a > b ? 1 : 0
|
|
273
|
+
}
|
|
274
|
+
|
|
74
275
|
/** Generates the optional browser entry served by the API for `/auth/*`. */
|
|
75
276
|
export async function generateAuthExperienceEntry(
|
|
76
277
|
projectRoot: string,
|
|
@@ -273,7 +474,13 @@ export async function generateAppEntry(
|
|
|
273
474
|
const mainContent = `import React from "react"
|
|
274
475
|
import { createRoot, type Root } from "react-dom/client"
|
|
275
476
|
import { signOut } from "@sixb/client"
|
|
276
|
-
import {
|
|
477
|
+
import {
|
|
478
|
+
BrowserRouter,
|
|
479
|
+
matchPath,
|
|
480
|
+
useLocation,
|
|
481
|
+
useNavigate,
|
|
482
|
+
useRoutes,
|
|
483
|
+
} from "react-router-dom"
|
|
277
484
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
|
278
485
|
import {
|
|
279
486
|
configureSixbBrowserClient,
|
|
@@ -281,7 +488,7 @@ import {
|
|
|
281
488
|
readSixbBrowserRuntimeConfig,
|
|
282
489
|
requireSixbBrowserAuthSession,
|
|
283
490
|
} from "@sixb/client/browser"
|
|
284
|
-
import { routes } from "./routes"
|
|
491
|
+
import { routePaths, routes } from "./routes"
|
|
285
492
|
${globalsCssImport}
|
|
286
493
|
${layoutImport}
|
|
287
494
|
|
|
@@ -381,7 +588,7 @@ function InternalLinkInterceptor() {
|
|
|
381
588
|
if (isReservedPath(url.pathname)) return
|
|
382
589
|
// Only intercept destinations the app actually routes; anything else may
|
|
383
590
|
// be a real server resource and keeps native navigation.
|
|
384
|
-
if (!
|
|
591
|
+
if (!routePaths.some((path) => matchPath(path, url.pathname))) return
|
|
385
592
|
// Same-document hash links keep native scroll behavior.
|
|
386
593
|
if (
|
|
387
594
|
url.hash &&
|
|
@@ -585,6 +792,12 @@ function RoutedErrorBoundary({ children }: { children: React.ReactNode }) {
|
|
|
585
792
|
)
|
|
586
793
|
}
|
|
587
794
|
|
|
795
|
+
const appRoutes = [...routes, { path: "*", element: <NotFoundView /> }]
|
|
796
|
+
|
|
797
|
+
function AppRoutes() {
|
|
798
|
+
return useRoutes(appRoutes)
|
|
799
|
+
}
|
|
800
|
+
|
|
588
801
|
function App() {
|
|
589
802
|
return (
|
|
590
803
|
<QueryClientProvider client={queryClient}>
|
|
@@ -592,12 +805,7 @@ function App() {
|
|
|
592
805
|
<InternalLinkInterceptor />
|
|
593
806
|
<RoutedErrorBoundary>
|
|
594
807
|
${layoutWrapperStart}
|
|
595
|
-
<
|
|
596
|
-
{routes.map((route) => (
|
|
597
|
-
<Route key={route.path} path={route.path} element={<route.component />} />
|
|
598
|
-
))}
|
|
599
|
-
<Route path="*" element={<NotFoundView />} />
|
|
600
|
-
</Routes>
|
|
808
|
+
<AppRoutes />
|
|
601
809
|
${layoutWrapperEnd}
|
|
602
810
|
</RoutedErrorBoundary>
|
|
603
811
|
</BrowserRouter>
|
package/src/createCustomApp.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
generateRouteManifest,
|
|
18
18
|
} from "./codegen"
|
|
19
19
|
import { renderCustomAppRuntimeScript } from "./runtime"
|
|
20
|
-
import { type PageRoute,
|
|
20
|
+
import { type PageRoute, routePatternKey, scanAppRoutes } from "./scanner"
|
|
21
21
|
import { type CustomAppStylesheet, resolveCustomAppStylesheet } from "./styles"
|
|
22
22
|
import { createTailwindCssCompiler, type TailwindCssCompiler } from "./tailwind"
|
|
23
23
|
|
|
@@ -98,11 +98,7 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
|
|
|
98
98
|
const agentRoutesEnabled = options.agentRoutes ?? true
|
|
99
99
|
|
|
100
100
|
async function scanRoutes(): Promise<PageRoute[]> {
|
|
101
|
-
|
|
102
|
-
return []
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return await scanPages(appDir)
|
|
101
|
+
return [...(await scanAppRoutes(appDir)).pages]
|
|
106
102
|
}
|
|
107
103
|
|
|
108
104
|
let tailwindCompiler: TailwindCssCompiler | null = null
|
|
@@ -236,14 +232,18 @@ export async function createCustomApp(options: CreateCustomAppOptions): Promise<
|
|
|
236
232
|
manifestPath: string
|
|
237
233
|
routes: PageRoute[]
|
|
238
234
|
}> {
|
|
239
|
-
const
|
|
235
|
+
const discovery = await scanAppRoutes(appDir)
|
|
236
|
+
const routes = [...discovery.pages]
|
|
240
237
|
if (routes.length === 0) {
|
|
241
238
|
throw new Error(`[SixbCustomApp] No app routes found in ${appDir}`)
|
|
242
239
|
}
|
|
243
240
|
|
|
244
241
|
const builtInRoutes = agentRoutesEnabled ? builtInAgentRoutesFor(routes) : []
|
|
245
242
|
const stylesheets = await prepareStylesheets(builtInRoutes)
|
|
246
|
-
await generateRouteManifest(routes, generatedDir, {
|
|
243
|
+
await generateRouteManifest(routes, generatedDir, {
|
|
244
|
+
builtInRoutes,
|
|
245
|
+
layouts: discovery.layouts,
|
|
246
|
+
})
|
|
247
247
|
const { htmlPath, mainPath, manifestPath } = await generateAppEntry(rootDir, generatedDir, {
|
|
248
248
|
apiBaseUrl,
|
|
249
249
|
audience,
|
|
@@ -530,10 +530,10 @@ async function pathExists(path: string): Promise<boolean> {
|
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
function builtInAgentRoutesFor(routes: readonly PageRoute[]): BuiltInRouteManifestEntry[] {
|
|
533
|
-
const
|
|
533
|
+
const projectRoutePatterns = new Set(routes.map((route) => routePatternKey(route.path)))
|
|
534
534
|
|
|
535
535
|
return builtInAgentRoutePaths
|
|
536
|
-
.filter((path) => !
|
|
536
|
+
.filter((path) => !projectRoutePatterns.has(routePatternKey(path)))
|
|
537
537
|
.map((path) => ({
|
|
538
538
|
path,
|
|
539
539
|
moduleSpecifier: builtInAgentRouteModule,
|