@vaadin/hilla-file-router 24.6.0-beta2 → 24.6.0-beta4
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/package.json +5 -4
- package/runtime/RouterConfigurationBuilder.d.ts.map +1 -1
- package/runtime/RouterConfigurationBuilder.js +120 -69
- package/runtime/RouterConfigurationBuilder.js.map +2 -2
- package/runtime/createMenuItems.d.ts +1 -0
- package/runtime/createMenuItems.d.ts.map +1 -1
- package/runtime/createMenuItems.js +1 -1
- package/runtime/createRoute.d.ts +10 -1
- package/runtime/createRoute.d.ts.map +1 -1
- package/runtime/createRoute.js +11 -1
- package/runtime/createRoute.js.map +2 -2
- package/shared/transformTree.d.ts +1 -1
- package/shared/transformTree.d.ts.map +1 -1
- package/shared/transformTree.js +2 -2
- package/shared/transformTree.js.map +2 -2
- package/types.d.ts +5 -0
- package/vite-plugin/applyLayouts.d.ts.map +1 -1
- package/vite-plugin/applyLayouts.js +22 -39
- package/vite-plugin/applyLayouts.js.map +2 -2
- package/vite-plugin/createRoutesFromMeta.d.ts +1 -7
- package/vite-plugin/createRoutesFromMeta.d.ts.map +1 -1
- package/vite-plugin/createRoutesFromMeta.js +93 -81
- package/vite-plugin/createRoutesFromMeta.js.map +2 -2
- package/vite-plugin/createViewConfigJson.d.ts.map +1 -1
- package/vite-plugin/createViewConfigJson.js +2 -1
- package/vite-plugin/createViewConfigJson.js.map +2 -2
- package/vite-plugin/generateRuntimeFiles.d.ts.map +1 -1
- package/vite-plugin/generateRuntimeFiles.js +11 -3
- package/vite-plugin/generateRuntimeFiles.js.map +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-file-router",
|
|
3
|
-
"version": "24.6.0-
|
|
3
|
+
"version": "24.6.0-beta4",
|
|
4
4
|
"description": "Hilla file-based router",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"@types/sinon": "^10.0.17",
|
|
71
71
|
"@types/sinon-chai": "^3.2.12",
|
|
72
72
|
"chai-as-promised": "^7.1.1",
|
|
73
|
+
"chai-deep-equal-ignore-undefined": "^1.1.1",
|
|
73
74
|
"chai-fs": "^2.0.0",
|
|
74
75
|
"chai-like": "^1.1.1",
|
|
75
76
|
"deep-equal-in-any-order": "^2.0.6",
|
|
@@ -79,9 +80,9 @@
|
|
|
79
80
|
"type-fest": "^4.9.0"
|
|
80
81
|
},
|
|
81
82
|
"dependencies": {
|
|
82
|
-
"@vaadin/hilla-generator-utils": "24.6.0-
|
|
83
|
-
"@vaadin/hilla-react-auth": "24.6.0-
|
|
84
|
-
"@vaadin/hilla-react-signals": "24.6.0-
|
|
83
|
+
"@vaadin/hilla-generator-utils": "24.6.0-beta4",
|
|
84
|
+
"@vaadin/hilla-react-auth": "24.6.0-beta4",
|
|
85
|
+
"@vaadin/hilla-react-signals": "24.6.0-beta4",
|
|
85
86
|
"react": "^18.2.0",
|
|
86
87
|
"rollup": "^4.12.0",
|
|
87
88
|
"typescript": "5.6.2"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterConfigurationBuilder.d.ts","sourceRoot":"","sources":["../src/runtime/RouterConfigurationBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"RouterConfigurationBuilder.d.ts","sourceRoot":"","sources":["../src/runtime/RouterConfigurationBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,OAAO,CAAC;AAC1D,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EACV,aAAa,EAGb,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EAC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,mBAAmB;CAqGzD"}
|
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
import { convertComponentNameToTitle } from "../shared/convertComponentNameToTitle.js";
|
|
7
7
|
import { transformTree } from "../shared/transformTree.js";
|
|
8
8
|
function isReactRouteModule(module) {
|
|
9
|
-
|
|
9
|
+
if (!module) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return "default" in module && typeof module.default === "function" || "config" in module && typeof module.config === "object";
|
|
10
13
|
}
|
|
11
14
|
function createRouteEntry(route) {
|
|
12
15
|
return [`${route.path ?? ""}-${route.children ? "n" : "i"}`, route];
|
|
@@ -17,40 +20,11 @@ var RouteHandleFlags = /* @__PURE__ */ ((RouteHandleFlags2) => {
|
|
|
17
20
|
RouteHandleFlags2["SKIP_LAYOUTS"] = "skipLayouts";
|
|
18
21
|
return RouteHandleFlags2;
|
|
19
22
|
})(RouteHandleFlags || {});
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return transformTree(
|
|
26
|
-
originalRoutes,
|
|
27
|
-
(routes, next) => (
|
|
28
|
-
// Split a single routes list onto two separate lists.
|
|
29
|
-
routes.reduce(
|
|
30
|
-
(lists, route) => {
|
|
31
|
-
if (rule(route)) {
|
|
32
|
-
lists.match.push(route);
|
|
33
|
-
return lists;
|
|
34
|
-
}
|
|
35
|
-
if (!route.children?.length) {
|
|
36
|
-
lists.default.push(route);
|
|
37
|
-
return lists;
|
|
38
|
-
}
|
|
39
|
-
const childrenLists = next(...route.children);
|
|
40
|
-
for (const category of categories) {
|
|
41
|
-
if (childrenLists[category].length) {
|
|
42
|
-
lists[category].push({
|
|
43
|
-
...route,
|
|
44
|
-
children: childrenLists[category]
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return lists;
|
|
49
|
-
},
|
|
50
|
-
{ match: [], default: [] }
|
|
51
|
-
)
|
|
52
|
-
)
|
|
53
|
-
);
|
|
23
|
+
function getRouteHandleFlag(route, flag) {
|
|
24
|
+
if (typeof route.handle === "object" && flag in route.handle) {
|
|
25
|
+
return route.handle[flag];
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
54
28
|
}
|
|
55
29
|
class RouterConfigurationBuilder {
|
|
56
30
|
#modifiers = [];
|
|
@@ -75,7 +49,9 @@ class RouterConfigurationBuilder {
|
|
|
75
49
|
if (added) {
|
|
76
50
|
const { module, path, flowLayout } = added;
|
|
77
51
|
if (!isReactRouteModule(module)) {
|
|
78
|
-
throw new Error(
|
|
52
|
+
throw new Error(
|
|
53
|
+
`The module for the "${path}" section doesn't have the React component exported by default or a ViewConfig object exported as "config"`
|
|
54
|
+
);
|
|
79
55
|
}
|
|
80
56
|
const element = module?.default ? createElement(module.default) : void 0;
|
|
81
57
|
const handle = {
|
|
@@ -118,7 +94,7 @@ class RouterConfigurationBuilder {
|
|
|
118
94
|
{ index: true, element: createElement(component), handle: config }
|
|
119
95
|
];
|
|
120
96
|
this.update(fallbackRoutes, (original, added, children) => {
|
|
121
|
-
if (original && !
|
|
97
|
+
if (original && !getRouteHandleFlag(original, "ignoreFallback" /* IGNORE_FALLBACK */)) {
|
|
122
98
|
if (!children) {
|
|
123
99
|
return original;
|
|
124
100
|
}
|
|
@@ -148,24 +124,65 @@ class RouterConfigurationBuilder {
|
|
|
148
124
|
if (!originalRoutes) {
|
|
149
125
|
return originalRoutes;
|
|
150
126
|
}
|
|
151
|
-
const
|
|
127
|
+
const result = transformTree(
|
|
152
128
|
originalRoutes,
|
|
153
|
-
|
|
129
|
+
null,
|
|
130
|
+
(routes, next) => (
|
|
131
|
+
// Split a single routes list onto three separate lists:
|
|
132
|
+
// - A list of server routes
|
|
133
|
+
// - A list of client routes
|
|
134
|
+
// - A list of routes which will be moved to either server or client
|
|
135
|
+
// list. It depends on the parent route.
|
|
136
|
+
routes.reduce(
|
|
137
|
+
(lists, route) => {
|
|
138
|
+
const { server, client, ambivalent } = next(route.children ?? []);
|
|
139
|
+
const flag = getRouteHandleFlag(route, "flowLayout" /* FLOW_LAYOUT */);
|
|
140
|
+
if (flag === true) {
|
|
141
|
+
lists.server.push({
|
|
142
|
+
...route,
|
|
143
|
+
children: server.length + ambivalent.length > 0 ? [...server, ...ambivalent] : void 0
|
|
144
|
+
});
|
|
145
|
+
} else if (server.length > 0) {
|
|
146
|
+
lists.server.push({
|
|
147
|
+
...route,
|
|
148
|
+
children: server
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (flag === false || client.length > 0) {
|
|
152
|
+
lists.client.push({
|
|
153
|
+
...route,
|
|
154
|
+
children: client.length > 0 ? client : void 0
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (flag === void 0 && (lists.server.every(({ path }) => path !== route.path) || ambivalent.length > 0)) {
|
|
158
|
+
lists.ambivalent.push({
|
|
159
|
+
...route,
|
|
160
|
+
children: ambivalent.length > 0 ? ambivalent : void 0
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return lists;
|
|
164
|
+
},
|
|
165
|
+
{ server: [], client: [], ambivalent: [] }
|
|
166
|
+
)
|
|
167
|
+
)
|
|
154
168
|
);
|
|
155
169
|
return [
|
|
156
|
-
...
|
|
157
|
-
// The server
|
|
158
|
-
//
|
|
170
|
+
...result.server.length ? [
|
|
171
|
+
// The server routes are wrapped with the route that has a layout
|
|
172
|
+
// element. It also has the `IGNORE_FALLBACK` flag to remove the
|
|
173
|
+
// fallback route from reach.
|
|
159
174
|
{
|
|
160
175
|
element: createElement(layoutComponent),
|
|
161
|
-
children:
|
|
176
|
+
children: result.server,
|
|
162
177
|
handle: {
|
|
163
178
|
["ignoreFallback" /* IGNORE_FALLBACK */]: true
|
|
164
179
|
}
|
|
165
180
|
}
|
|
166
181
|
] : [],
|
|
167
|
-
// The client
|
|
168
|
-
...
|
|
182
|
+
// The client routes are preserved without wrapping.
|
|
183
|
+
...result.client,
|
|
184
|
+
// The ambivalent routes are considered as client routes.
|
|
185
|
+
...result.ambivalent
|
|
169
186
|
];
|
|
170
187
|
});
|
|
171
188
|
return this;
|
|
@@ -193,6 +210,7 @@ class RouterConfigurationBuilder {
|
|
|
193
210
|
this.#modifiers.push(
|
|
194
211
|
(existingRoutes) => transformTree(
|
|
195
212
|
[existingRoutes, routes],
|
|
213
|
+
null,
|
|
196
214
|
([original, added], next) => {
|
|
197
215
|
if (original && added) {
|
|
198
216
|
const originalMap = new Map(original.map((route) => createRouteEntry(route)));
|
|
@@ -203,11 +221,11 @@ class RouterConfigurationBuilder {
|
|
|
203
221
|
const addedRoute = addedMap.get(path);
|
|
204
222
|
let route;
|
|
205
223
|
if (originalRoute && addedRoute) {
|
|
206
|
-
route = callback(originalRoute, addedRoute, next(originalRoute.children, addedRoute.children));
|
|
224
|
+
route = callback(originalRoute, addedRoute, next([originalRoute.children, addedRoute.children]));
|
|
207
225
|
} else if (originalRoute) {
|
|
208
|
-
route = callback(originalRoute, void 0, next(originalRoute.children, void 0));
|
|
226
|
+
route = callback(originalRoute, void 0, next([originalRoute.children, void 0]));
|
|
209
227
|
} else {
|
|
210
|
-
route = callback(void 0, addedRoute, next(void 0, addedRoute.children));
|
|
228
|
+
route = callback(void 0, addedRoute, next([void 0, addedRoute.children]));
|
|
211
229
|
}
|
|
212
230
|
if (route) {
|
|
213
231
|
originalMap.set(path, route);
|
|
@@ -215,9 +233,9 @@ class RouterConfigurationBuilder {
|
|
|
215
233
|
}
|
|
216
234
|
return [...originalMap.values()];
|
|
217
235
|
} else if (original) {
|
|
218
|
-
return original.map((route) => callback(route, void 0, next(route.children, void 0))).filter((r) => r != null);
|
|
236
|
+
return original.map((route) => callback(route, void 0, next([route.children, void 0]))).filter((r) => r != null);
|
|
219
237
|
} else if (added) {
|
|
220
|
-
return added.map((route) => callback(void 0, route, next(void 0, route.children))).filter((r) => r != null);
|
|
238
|
+
return added.map((route) => callback(void 0, route, next([void 0, route.children]))).filter((r) => r != null);
|
|
221
239
|
}
|
|
222
240
|
return void 0;
|
|
223
241
|
}
|
|
@@ -233,7 +251,22 @@ class RouterConfigurationBuilder {
|
|
|
233
251
|
const routes = this.#modifiers.reduce((acc, mod) => mod(acc) ?? acc, void 0) ?? [];
|
|
234
252
|
return {
|
|
235
253
|
routes,
|
|
236
|
-
router: createBrowserRouter([...routes], {
|
|
254
|
+
router: createBrowserRouter([...routes], {
|
|
255
|
+
basename: new URL(document.baseURI).pathname,
|
|
256
|
+
future: {
|
|
257
|
+
// eslint-disable-next-line camelcase
|
|
258
|
+
v7_fetcherPersist: true,
|
|
259
|
+
// eslint-disable-next-line camelcase
|
|
260
|
+
v7_normalizeFormMethod: true,
|
|
261
|
+
// eslint-disable-next-line camelcase
|
|
262
|
+
v7_partialHydration: true,
|
|
263
|
+
// eslint-disable-next-line camelcase
|
|
264
|
+
v7_relativeSplatPath: true,
|
|
265
|
+
// eslint-disable-next-line camelcase
|
|
266
|
+
v7_skipActionErrorRevalidation: true
|
|
267
|
+
},
|
|
268
|
+
...options
|
|
269
|
+
})
|
|
237
270
|
};
|
|
238
271
|
}
|
|
239
272
|
#withLayoutSkipping() {
|
|
@@ -241,33 +274,51 @@ class RouterConfigurationBuilder {
|
|
|
241
274
|
if (!originalRoutes) {
|
|
242
275
|
return originalRoutes;
|
|
243
276
|
}
|
|
244
|
-
const
|
|
277
|
+
const result = transformTree(
|
|
245
278
|
originalRoutes,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
279
|
+
null,
|
|
280
|
+
(routes, next) => (
|
|
281
|
+
// Split a single routes list onto two separate lists.
|
|
282
|
+
routes.reduce(
|
|
283
|
+
(lists, route) => {
|
|
284
|
+
if (getRouteHandleFlag(route, "skipLayouts" /* SKIP_LAYOUTS */)) {
|
|
285
|
+
lists.skipped.push(route);
|
|
286
|
+
return lists;
|
|
287
|
+
}
|
|
288
|
+
if (!route.children?.length) {
|
|
289
|
+
lists.regular.push(route);
|
|
290
|
+
return lists;
|
|
291
|
+
}
|
|
292
|
+
const { skipped, regular } = next(route.children ?? []);
|
|
293
|
+
if (skipped.length > 0) {
|
|
294
|
+
const { element, ...rest } = route;
|
|
295
|
+
lists.skipped.push({
|
|
296
|
+
...rest,
|
|
297
|
+
children: skipped
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
if (regular.length > 0) {
|
|
301
|
+
lists.regular.push({
|
|
302
|
+
...route,
|
|
303
|
+
children: regular
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return lists;
|
|
307
|
+
},
|
|
308
|
+
{ skipped: [], regular: [] }
|
|
309
|
+
)
|
|
310
|
+
)
|
|
260
311
|
);
|
|
261
312
|
return [
|
|
262
|
-
...
|
|
313
|
+
...result.skipped.length ? [
|
|
263
314
|
{
|
|
264
|
-
children:
|
|
315
|
+
children: result.skipped,
|
|
265
316
|
handle: {
|
|
266
317
|
["ignoreFallback" /* IGNORE_FALLBACK */]: true
|
|
267
318
|
}
|
|
268
319
|
}
|
|
269
320
|
] : [],
|
|
270
|
-
...
|
|
321
|
+
...result.regular
|
|
271
322
|
];
|
|
272
323
|
});
|
|
273
324
|
return this;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/runtime/RouterConfigurationBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/consistent-type-assertions */\nimport { protectRoute } from '@vaadin/hilla-react-auth';\nimport { type ComponentType, createElement } from 'react';\nimport {\n createBrowserRouter,\n type IndexRouteObject,\n type NonIndexRouteObject,\n type RouteObject,\n} from 'react-router-dom';\nimport type { TupleToUnion } from 'type-fest';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport { transformTree } from '../shared/transformTree.js';\nimport type {\n AgnosticRoute,\n Module,\n RouteModule,\n RouterBuildOptions,\n RouterConfiguration,\n ViewConfig,\n} from '../types.js';\n\ninterface RouteBase {\n path?: string;\n children?: readonly this[];\n}\n\nfunction isReactRouteModule(module?: Module): module is RouteModule<ComponentType> | undefined {\n return module ? 'default' in module && typeof module.default === 'function' : true;\n}\n\nexport type RouteList = readonly RouteObject[];\nexport type WritableRouteList = RouteObject[];\n\nexport type RouteTransformer<T> = (\n original: RouteObject | undefined,\n overriding: T | undefined,\n children?: RouteList,\n) => RouteObject | undefined;\n\nexport type RouteListSplittingRule = (route: RouteObject) => boolean;\n\ntype RoutesModifier = (routes: RouteList | undefined) => RouteList | undefined;\n\nfunction createRouteEntry<T extends RouteBase>(route: T): readonly [key: string, value: T] {\n return [`${route.path ?? ''}-${route.children ? 'n' : 'i'}`, route];\n}\n\nenum RouteHandleFlags {\n FLOW_LAYOUT = 'flowLayout',\n IGNORE_FALLBACK = 'ignoreFallback',\n SKIP_LAYOUTS = 'skipLayouts',\n}\n\nfunction hasRouteHandleFlag<T extends RouteHandleFlags>(route: RouteObject, flag: T): boolean {\n return typeof route.handle === 'object' && flag in route.handle && (route.handle as Record<T, boolean>)[flag];\n}\n\nconst categories = ['default', 'match'] as const;\n\ntype Category = TupleToUnion<typeof categories>;\n\nfunction split(originalRoutes: RouteList, rule: RouteListSplittingRule): Readonly<Record<Category, RouteList>> {\n return transformTree<RouteList, Readonly<Record<Category, RouteList>>>(originalRoutes, (routes, next) =>\n // Split a single routes list onto two separate lists.\n routes.reduce<Record<Category, WritableRouteList>>(\n (lists, route) => {\n if (rule(route)) {\n // If the route satisfies the rule, it goes to the first list.\n lists.match.push(route);\n return lists;\n }\n\n if (!route.children?.length) {\n // Leaf routes go to the second list.\n lists.default.push(route);\n return lists;\n }\n\n // Route children: separate them to different subtrees, and copy the\n // current route to either or both the lists with the respective\n // subtree as children.\n const childrenLists = next(...route.children);\n\n for (const category of categories) {\n if (childrenLists[category].length) {\n lists[category].push({\n ...route,\n children: childrenLists[category],\n } as RouteObject);\n }\n }\n\n return lists;\n },\n { match: [], default: [] },\n ),\n );\n}\n\n/**\n * A builder for creating a Vaadin-specific router for React with\n * authentication and server routes support.\n */\nexport class RouterConfigurationBuilder {\n readonly #modifiers: RoutesModifier[] = [];\n\n /**\n * Adds the given routes to the current list of routes. All the routes are\n * deeply merged to preserve the path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withReactRoutes(routes: RouteList): this {\n return this.update(routes);\n }\n\n /**\n * Adds the given file routes to the current list of routes. All the routes\n * are transformed to React RouterObjects and deeply merged to preserve the\n * path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withFileRoutes(routes: readonly AgnosticRoute[]): this {\n return this.update(routes, (original, added, children) => {\n if (added) {\n const { module, path, flowLayout } = added;\n if (!isReactRouteModule(module)) {\n throw new Error(`The module for the \"${path}\" section doesn't have the React component exported by default`);\n }\n\n const element = module?.default ? createElement(module.default) : undefined;\n const handle = {\n ...module?.config,\n title: module?.config?.title ?? convertComponentNameToTitle(module?.default),\n flowLayout: module?.config?.flowLayout ?? flowLayout,\n };\n\n if (path === '' && !children) {\n return {\n ...original,\n element,\n handle,\n index: true,\n } as IndexRouteObject;\n }\n\n return {\n ...original,\n path: module?.config?.route ?? path,\n element,\n children,\n handle,\n } as NonIndexRouteObject;\n }\n\n return original;\n });\n }\n\n /**\n * Adds the given server route element to each branch of the current list of\n * routes.\n *\n * @param component - The React component to add to each branch of the\n * current list of routes.\n * @param config - An optional configuration that will be applied to\n * each fallback component.\n */\n withFallback(component: ComponentType, config?: ViewConfig): this {\n this.withLayout(component);\n\n // Fallback adds two routes, so that the index (empty path) has a fallback too\n const fallbackRoutes: RouteList = [\n { path: '*', element: createElement(component), handle: config },\n { index: true, element: createElement(component), handle: config },\n ];\n\n this.update(fallbackRoutes, (original, added, children) => {\n if (original && !hasRouteHandleFlag(original, RouteHandleFlags.IGNORE_FALLBACK)) {\n if (!children) {\n return original;\n }\n\n const _fallback = [...fallbackRoutes];\n\n if (children.some(({ path }) => path === '*')) {\n _fallback.shift();\n }\n\n if (children.some(({ index: i, path }) => i ?? path?.includes('?'))) {\n _fallback.pop();\n }\n\n return {\n ...original,\n children: [...children, ..._fallback],\n } as RouteObject;\n }\n\n return added!;\n });\n\n return this;\n }\n\n /**\n * Adds the layoutComponent as the parent layout to views with the flowLayouts ViewConfiguration set.\n *\n * @param layoutComponent - layout component to use, usually Flow\n */\n withLayout(layoutComponent: ComponentType): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n const { match: serverList, default: clientList } = split(originalRoutes, (route) =>\n hasRouteHandleFlag(route, RouteHandleFlags.FLOW_LAYOUT),\n );\n\n return [\n ...(serverList.length\n ? [\n // The server subtree is wrapped with the server layout component,\n // which applies the top-level server layout to all matches.\n {\n element: createElement(layoutComponent),\n children: serverList as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n // The client route subtree is preserved without wrapping.\n ...clientList,\n ];\n });\n\n return this;\n }\n\n /**\n * Protects all the routes that require authentication. For more details see\n * {@link @vaadin/hilla-react-auth#protectRoutes} function.\n *\n * @param redirectPath - the path to redirect to if the route is protected\n * and the user is not authenticated.\n */\n protect(redirectPath?: string): this {\n this.update(undefined, (route, _, children) => {\n const finalRoute = protectRoute(route!, redirectPath);\n finalRoute.children = children as RouteObject[] | undefined;\n return finalRoute;\n });\n\n return this;\n }\n\n update<T extends RouteBase>(routes: undefined, callback: RouteTransformer<undefined>): this;\n update<T extends RouteBase>(routes: readonly T[], callback?: RouteTransformer<T>): this;\n update<T extends RouteBase>(\n routes: readonly T[] | undefined,\n callback: RouteTransformer<T | undefined> = (original, overriding, children) =>\n ({\n ...original,\n ...overriding,\n children,\n }) as RouteObject,\n ): this {\n this.#modifiers.push((existingRoutes) =>\n transformTree<[RouteList | undefined, readonly T[] | undefined], RouteList | undefined>(\n [existingRoutes, routes],\n ([original, added], next) => {\n if (original && added) {\n const originalMap = new Map(original.map((route) => createRouteEntry(route)));\n const addedMap = new Map(added.map((route) => createRouteEntry(route)));\n\n const paths = new Set([...originalMap.keys(), ...addedMap.keys()]);\n\n for (const path of paths) {\n const originalRoute = originalMap.get(path);\n const addedRoute = addedMap.get(path);\n\n let route: RouteObject | undefined;\n if (originalRoute && addedRoute) {\n route = callback(originalRoute, addedRoute, next(originalRoute.children, addedRoute.children));\n } else if (originalRoute) {\n route = callback(originalRoute, undefined, next(originalRoute.children, undefined));\n } else {\n route = callback(undefined, addedRoute, next(undefined, addedRoute!.children));\n }\n\n if (route) {\n originalMap.set(path, route);\n }\n }\n\n return [...originalMap.values()];\n } else if (original) {\n return original\n .map((route) => callback(route, undefined, next(route.children, undefined)))\n .filter((r) => r != null);\n } else if (added) {\n return added\n .map((route) => callback(undefined, route, next(undefined, route.children)))\n .filter((r) => r != null);\n }\n\n return undefined;\n },\n ),\n );\n return this;\n }\n\n /**\n * Builds the router with the current list of routes.\n */\n build(options?: RouterBuildOptions): RouterConfiguration {\n this.#withLayoutSkipping();\n const routes = this.#modifiers.reduce<RouteList | undefined>((acc, mod) => mod(acc) ?? acc, undefined) ?? [];\n\n return {\n routes,\n router: createBrowserRouter([...routes], { basename: new URL(document.baseURI).pathname, ...options }),\n };\n }\n\n #withLayoutSkipping(): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n const { match: noLayoutList, default: layoutList } = split(originalRoutes, (route) =>\n hasRouteHandleFlag(route, RouteHandleFlags.SKIP_LAYOUTS),\n );\n\n const finalNoLayoutList = transformTree<RouteList, RouteList>(noLayoutList, (routes, next) =>\n routes.map((route) => {\n if (hasRouteHandleFlag(route, RouteHandleFlags.SKIP_LAYOUTS)) {\n return route;\n }\n\n const { element, ...rest } = route;\n return route.children?.length\n ? ({\n ...rest,\n children: next(...route.children),\n } as RouteObject)\n : rest;\n }),\n );\n\n return [\n ...(finalNoLayoutList.length\n ? [\n {\n children: finalNoLayoutList as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n ...layoutList,\n ];\n });\n\n return this;\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAA6B,qBAAqB;AAClD;AAAA,EACE;AAAA,OAIK;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/consistent-type-assertions */\nimport { protectRoute } from '@vaadin/hilla-react-auth';\nimport { type ComponentType, createElement } from 'react';\nimport {\n createBrowserRouter,\n type IndexRouteObject,\n type NonIndexRouteObject,\n type RouteObject,\n} from 'react-router-dom';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport { transformTree } from '../shared/transformTree.js';\nimport type {\n AgnosticRoute,\n Module,\n RouteModule,\n RouterBuildOptions,\n RouterConfiguration,\n ViewConfig,\n} from '../types.js';\n\ninterface RouteBase {\n path?: string;\n children?: readonly this[];\n}\n\nfunction isReactRouteModule(module?: Module): module is RouteModule<ComponentType> | undefined {\n if (!module) {\n return true;\n }\n\n return (\n ('default' in module && typeof module.default === 'function') ||\n ('config' in module && typeof module.config === 'object')\n );\n}\n\nexport type RouteList = readonly RouteObject[];\nexport type WritableRouteList = RouteObject[];\n\nexport type RouteTransformer<T> = (\n original: RouteObject | undefined,\n overriding: T | undefined,\n children?: RouteList,\n) => RouteObject | undefined;\n\nexport type RouteListSplittingRule = (route: RouteObject) => boolean;\n\ntype RoutesModifier = (routes: RouteList | undefined) => RouteList | undefined;\n\nfunction createRouteEntry<T extends RouteBase>(route: T): readonly [key: string, value: T] {\n return [`${route.path ?? ''}-${route.children ? 'n' : 'i'}`, route];\n}\n\nenum RouteHandleFlags {\n FLOW_LAYOUT = 'flowLayout',\n IGNORE_FALLBACK = 'ignoreFallback',\n SKIP_LAYOUTS = 'skipLayouts',\n}\n\nfunction getRouteHandleFlag<T extends RouteHandleFlags>(route: RouteObject, flag: T): boolean | undefined {\n if (typeof route.handle === 'object' && flag in route.handle) {\n return (route.handle as Record<T, boolean>)[flag];\n }\n\n return undefined;\n}\n\n/**\n * A builder for creating a Vaadin-specific router for React with\n * authentication and server routes support.\n */\nexport class RouterConfigurationBuilder {\n readonly #modifiers: RoutesModifier[] = [];\n\n /**\n * Adds the given routes to the current list of routes. All the routes are\n * deeply merged to preserve the path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withReactRoutes(routes: RouteList): this {\n return this.update(routes);\n }\n\n /**\n * Adds the given file routes to the current list of routes. All the routes\n * are transformed to React RouterObjects and deeply merged to preserve the\n * path uniqueness.\n *\n * @param routes - A list of routes to add to the current list.\n */\n withFileRoutes(routes: readonly AgnosticRoute[]): this {\n return this.update(routes, (original, added, children) => {\n if (added) {\n const { module, path, flowLayout } = added;\n if (!isReactRouteModule(module)) {\n throw new Error(\n `The module for the \"${path}\" section doesn't have the React component exported by default or a ViewConfig object exported as \"config\"`,\n );\n }\n\n const element = module?.default ? createElement(module.default) : undefined;\n const handle = {\n ...module?.config,\n title: module?.config?.title ?? convertComponentNameToTitle(module?.default),\n flowLayout: module?.config?.flowLayout ?? flowLayout,\n };\n\n if (path === '' && !children) {\n return {\n ...original,\n element,\n handle,\n index: true,\n } as IndexRouteObject;\n }\n\n return {\n ...original,\n path: module?.config?.route ?? path,\n element,\n children,\n handle,\n } as NonIndexRouteObject;\n }\n\n return original;\n });\n }\n\n /**\n * Adds the given server route element to each branch of the current list of\n * routes.\n *\n * @param component - The React component to add to each branch of the\n * current list of routes.\n * @param config - An optional configuration that will be applied to\n * each fallback component.\n */\n withFallback(component: ComponentType, config?: ViewConfig): this {\n this.withLayout(component);\n\n // Fallback adds two routes, so that the index (empty path) has a fallback too\n const fallbackRoutes: RouteList = [\n { path: '*', element: createElement(component), handle: config },\n { index: true, element: createElement(component), handle: config },\n ];\n\n this.update(fallbackRoutes, (original, added, children) => {\n if (original && !getRouteHandleFlag(original, RouteHandleFlags.IGNORE_FALLBACK)) {\n if (!children) {\n return original;\n }\n\n const _fallback = [...fallbackRoutes];\n\n if (children.some(({ path }) => path === '*')) {\n _fallback.shift();\n }\n\n if (children.some(({ index: i, path }) => i ?? path?.includes('?'))) {\n _fallback.pop();\n }\n\n return {\n ...original,\n children: [...children, ..._fallback],\n } as RouteObject;\n }\n\n return added!;\n });\n\n return this;\n }\n\n /**\n * Adds the layoutComponent as the parent layout to views with the flowLayouts ViewConfiguration set.\n *\n * @param layoutComponent - layout component to use, usually Flow\n */\n withLayout(layoutComponent: ComponentType): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n type Accumulator<T extends RouteList> = Readonly<{\n server: T;\n client: T;\n ambivalent: T;\n }>;\n\n const result = transformTree<RouteList, Accumulator<RouteList>>(originalRoutes, null, (routes, next) =>\n // Split a single routes list onto three separate lists:\n // - A list of server routes\n // - A list of client routes\n // - A list of routes which will be moved to either server or client\n // list. It depends on the parent route.\n routes.reduce<Accumulator<WritableRouteList>>(\n (lists, route) => {\n const { server, client, ambivalent } = next(route.children ?? []);\n\n const flag = getRouteHandleFlag(route, RouteHandleFlags.FLOW_LAYOUT);\n\n // If the route has `flowLayout` flag explicitly enabled, it goes to\n // the server list. The children are also affected by the flag\n // unless they have it explicitly disabled.\n if (flag === true) {\n lists.server.push({\n ...route,\n children: server.length + ambivalent.length > 0 ? [...server, ...ambivalent] : undefined,\n } as RouteObject);\n } else if (server.length > 0) {\n // Even if the route doesn't have the flag, it goes to the server\n // list if any of the children has the flag enabled.\n lists.server.push({\n ...route,\n children: server,\n } as RouteObject);\n }\n\n // If the route has `flowLayout` flag explicitly disabled, it goes\n // to the client list. The route children are not affected by the\n // flag.\n if (flag === false || client.length > 0) {\n lists.client.push({\n ...route,\n children: client.length > 0 ? client : undefined,\n } as RouteObject);\n }\n\n // The route without the flag go to the `default` list. Then it will\n // be moved to either server or client list based on the parent\n // route.\n if (\n flag === undefined &&\n (lists.server.every(({ path }) => path !== route.path) || ambivalent.length > 0)\n ) {\n lists.ambivalent.push({\n ...route,\n children: ambivalent.length > 0 ? ambivalent : undefined,\n } as RouteObject);\n }\n\n return lists;\n },\n { server: [], client: [], ambivalent: [] },\n ),\n );\n\n return [\n ...(result.server.length\n ? [\n // The server routes are wrapped with the route that has a layout\n // element. It also has the `IGNORE_FALLBACK` flag to remove the\n // fallback route from reach.\n {\n element: createElement(layoutComponent),\n children: result.server as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n // The client routes are preserved without wrapping.\n ...result.client,\n // The ambivalent routes are considered as client routes.\n ...result.ambivalent,\n ];\n });\n\n return this;\n }\n\n /**\n * Protects all the routes that require authentication. For more details see\n * {@link @vaadin/hilla-react-auth#protectRoutes} function.\n *\n * @param redirectPath - the path to redirect to if the route is protected\n * and the user is not authenticated.\n */\n protect(redirectPath?: string): this {\n this.update(undefined, (route, _, children) => {\n const finalRoute = protectRoute(route!, redirectPath);\n finalRoute.children = children as RouteObject[] | undefined;\n return finalRoute;\n });\n\n return this;\n }\n\n update<T extends RouteBase>(routes: undefined, callback: RouteTransformer<undefined>): this;\n update<T extends RouteBase>(routes: readonly T[], callback?: RouteTransformer<T>): this;\n update<T extends RouteBase>(\n routes: readonly T[] | undefined,\n callback: RouteTransformer<T | undefined> = (original, overriding, children) =>\n ({\n ...original,\n ...overriding,\n children,\n }) as RouteObject,\n ): this {\n this.#modifiers.push((existingRoutes) =>\n transformTree<[RouteList | undefined, readonly T[] | undefined], RouteList | undefined>(\n [existingRoutes, routes],\n null,\n ([original, added], next) => {\n if (original && added) {\n const originalMap = new Map(original.map((route) => createRouteEntry(route)));\n const addedMap = new Map(added.map((route) => createRouteEntry(route)));\n\n const paths = new Set([...originalMap.keys(), ...addedMap.keys()]);\n\n for (const path of paths) {\n const originalRoute = originalMap.get(path);\n const addedRoute = addedMap.get(path);\n\n let route: RouteObject | undefined;\n if (originalRoute && addedRoute) {\n route = callback(originalRoute, addedRoute, next([originalRoute.children, addedRoute.children]));\n } else if (originalRoute) {\n route = callback(originalRoute, undefined, next([originalRoute.children, undefined]));\n } else {\n route = callback(undefined, addedRoute, next([undefined, addedRoute!.children]));\n }\n\n if (route) {\n originalMap.set(path, route);\n }\n }\n\n return [...originalMap.values()];\n } else if (original) {\n return original\n .map((route) => callback(route, undefined, next([route.children, undefined])))\n .filter((r) => r != null);\n } else if (added) {\n return added\n .map((route) => callback(undefined, route, next([undefined, route.children])))\n .filter((r) => r != null);\n }\n\n return undefined;\n },\n ),\n );\n return this;\n }\n\n /**\n * Builds the router with the current list of routes.\n */\n build(options?: RouterBuildOptions): RouterConfiguration {\n this.#withLayoutSkipping();\n const routes = this.#modifiers.reduce<RouteList | undefined>((acc, mod) => mod(acc) ?? acc, undefined) ?? [];\n\n return {\n routes,\n router: createBrowserRouter([...routes], {\n basename: new URL(document.baseURI).pathname,\n future: {\n // eslint-disable-next-line camelcase\n v7_fetcherPersist: true,\n // eslint-disable-next-line camelcase\n v7_normalizeFormMethod: true,\n // eslint-disable-next-line camelcase\n v7_partialHydration: true,\n // eslint-disable-next-line camelcase\n v7_relativeSplatPath: true,\n // eslint-disable-next-line camelcase\n v7_skipActionErrorRevalidation: true,\n },\n ...options,\n }),\n };\n }\n\n #withLayoutSkipping(): this {\n this.#modifiers.push((originalRoutes) => {\n if (!originalRoutes) {\n return originalRoutes;\n }\n\n type Accumulator<T extends RouteList> = Readonly<{\n skipped: T;\n regular: T;\n }>;\n\n const result = transformTree<RouteList, Accumulator<RouteList>>(originalRoutes, null, (routes, next) =>\n // Split a single routes list onto two separate lists.\n routes.reduce<Accumulator<WritableRouteList>>(\n (lists, route) => {\n // If the route has `skipLayout` flag, it goes to the `skipped` list.\n if (getRouteHandleFlag(route, RouteHandleFlags.SKIP_LAYOUTS)) {\n lists.skipped.push(route);\n return lists;\n }\n\n // If the route is leaf, it goes to the `regular` list.\n if (!route.children?.length) {\n lists.regular.push(route);\n return lists;\n }\n\n // As of children, we have to split them into two lists as well.\n const { skipped, regular } = next(route.children ?? []);\n\n // If we have `skipped` list of children, we have to remove the\n // `element` property of the router to prevent the layout from\n // rendering. Then, we add the current route to the `skipped` list.\n if (skipped.length > 0) {\n const { element, ...rest } = route;\n\n lists.skipped.push({\n ...rest,\n children: skipped,\n } as RouteObject);\n }\n\n // In case of `regular` children, we just add the current route to\n // the `regular` list if there are any children.\n if (regular.length > 0) {\n lists.regular.push({\n ...route,\n children: regular,\n } as RouteObject);\n }\n\n return lists;\n },\n { skipped: [], regular: [] },\n ),\n );\n\n // We don't need a fallback for the skipped routes, so we have to wrap\n // them with the route with the `IGNORE_FALLBACK` flag.\n return [\n ...(result.skipped.length\n ? [\n {\n children: result.skipped as RouteObject[],\n handle: {\n [RouteHandleFlags.IGNORE_FALLBACK]: true,\n },\n },\n ]\n : []),\n ...result.regular,\n ];\n });\n\n return this;\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAA6B,qBAAqB;AAClD;AAAA,EACE;AAAA,OAIK;AACP,SAAS,mCAAmC;AAC5C,SAAS,qBAAqB;AAe9B,SAAS,mBAAmB,QAAmE;AAC7F,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SACG,aAAa,UAAU,OAAO,OAAO,YAAY,cACjD,YAAY,UAAU,OAAO,OAAO,WAAW;AAEpD;AAeA,SAAS,iBAAsC,OAA4C;AACzF,SAAO,CAAC,GAAG,MAAM,QAAQ,EAAE,IAAI,MAAM,WAAW,MAAM,GAAG,IAAI,KAAK;AACpE;AAEA,IAAK,mBAAL,kBAAKA,sBAAL;AACE,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,qBAAkB;AAClB,EAAAA,kBAAA,kBAAe;AAHZ,SAAAA;AAAA,GAAA;AAML,SAAS,mBAA+C,OAAoB,MAA8B;AACxG,MAAI,OAAO,MAAM,WAAW,YAAY,QAAQ,MAAM,QAAQ;AAC5D,WAAQ,MAAM,OAA8B,IAAI;AAAA,EAClD;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,GAAG,KAAK,IAAI;AAE7B,sBAAM,QAAQ,KAAK;AAAA,kBACjB,GAAG;AAAA,kBACH,UAAU;AAAA,gBACZ,CAAgB;AAAA,cAClB;AAIA,kBAAI,QAAQ,SAAS,GAAG;AACtB,sBAAM,QAAQ,KAAK;AAAA,kBACjB,GAAG;AAAA,kBACH,UAAU;AAAA,gBACZ,CAAgB;AAAA,cAClB;AAEA,qBAAO;AAAA,YACT;AAAA,YACA,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC,EAAE;AAAA,UAC7B;AAAA;AAAA,MACF;AAIA,aAAO;AAAA,QACL,GAAI,OAAO,QAAQ,SACf;AAAA,UACE;AAAA,YACE,UAAU,OAAO;AAAA,YACjB,QAAQ;AAAA,cACN,CAAC,sCAAgC,GAAG;AAAA,YACtC;AAAA,UACF;AAAA,QACF,IACA,CAAC;AAAA,QACL,GAAG,OAAO;AAAA,MACZ;AAAA,IACF,CAAC;AAED,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["RouteHandleFlags"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMenuItems.d.ts","sourceRoot":"","sources":["../src/runtime/createMenuItems.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAC;AAExD,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"createMenuItems.d.ts","sourceRoot":"","sources":["../src/runtime/createMenuItems.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAC;AAExD,eAAO,MAAM,WAAW;;;;;;;;aA0BZ,CAAC;aAKc,CAAA;eAEC,CAAC;YAE3B,CAAC;;iBAnCsE,CAAC;AAE1E;;;;;;;GAOG;AACH,wBAAgB,eAAe,IAAI,SAAS,QAAQ,EAAE,CA0BrD"}
|
|
@@ -2,7 +2,7 @@ function __REGISTER__(feature, vaadinObj = window.Vaadin ??= {}) {
|
|
|
2
2
|
vaadinObj.registrations ??= [];
|
|
3
3
|
vaadinObj.registrations.push({
|
|
4
4
|
is: feature ? `${"@vaadin/hilla-file-router"}/${feature}` : "@vaadin/hilla-file-router",
|
|
5
|
-
version: "24.6.0-
|
|
5
|
+
version: "24.6.0-beta4"
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
8
|
import { signal } from "@vaadin/hilla-react-signals";
|
package/runtime/createRoute.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type { AgnosticRoute, Module } from '../types.js';
|
|
1
|
+
import type { AgnosticRoute, Module, ViewConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extends a router module's config with additional properties. The original
|
|
4
|
+
* module config is preferred over the extension.
|
|
5
|
+
*
|
|
6
|
+
* @param module - The module to extend.
|
|
7
|
+
* @param config - The extension config.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function extendModule(module: Module | null, config?: ViewConfig): Module;
|
|
2
11
|
/**
|
|
3
12
|
* Create a single framework-agnostic route object. Later, it can be transformed into a framework-specific route object,
|
|
4
13
|
* e.g., the one used by React Router.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoute.d.ts","sourceRoot":"","sources":["../src/runtime/createRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"createRoute.d.ts","sourceRoot":"","sources":["../src/runtime/createRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,CAQ/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,CAAC;AAC9F,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,CAAC"}
|
package/runtime/createRoute.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
function extendModule(module, config) {
|
|
2
|
+
return {
|
|
3
|
+
...module,
|
|
4
|
+
config: {
|
|
5
|
+
...config,
|
|
6
|
+
...module?.config
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
1
10
|
function createRoute(path, moduleOrChildren, children) {
|
|
2
11
|
let module;
|
|
3
12
|
if (Array.isArray(moduleOrChildren)) {
|
|
@@ -12,6 +21,7 @@ function createRoute(path, moduleOrChildren, children) {
|
|
|
12
21
|
};
|
|
13
22
|
}
|
|
14
23
|
export {
|
|
15
|
-
createRoute
|
|
24
|
+
createRoute,
|
|
25
|
+
extendModule
|
|
16
26
|
};
|
|
17
27
|
//# sourceMappingURL=createRoute.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/runtime/createRoute.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AgnosticRoute, Module } from '../types.js';\n\n/**\n * Create a single framework-agnostic route object. Later, it can be transformed into a framework-specific route object,\n * e.g., the one used by React Router.\n *\n * @param path - A route path segment.\n * @param children - An array of child routes.\n *\n * @returns A framework-agnostic route object.\n */\nexport function createRoute(path: string, children?: readonly AgnosticRoute[]): AgnosticRoute;\nexport function createRoute(path: string, module: Module, children?: readonly AgnosticRoute[]): AgnosticRoute;\nexport function createRoute(\n path: string,\n moduleOrChildren?: Module | readonly AgnosticRoute[],\n children?: readonly AgnosticRoute[],\n): AgnosticRoute {\n let module: Module | undefined;\n if (Array.isArray(moduleOrChildren)) {\n // eslint-disable-next-line no-param-reassign\n children = moduleOrChildren;\n } else {\n module = moduleOrChildren as Module | undefined;\n }\n\n return {\n path,\n module,\n children,\n };\n}\n"],
|
|
5
|
-
"mappings": "AAaO,SAAS,YACd,MACA,kBACA,UACe;AACf,MAAI;AACJ,MAAI,MAAM,QAAQ,gBAAgB,GAAG;AAEnC,eAAW;AAAA,EACb,OAAO;AACL,aAAS;AAAA,EACX;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { AgnosticRoute, Module, ViewConfig } from '../types.js';\n\n/**\n * Extends a router module's config with additional properties. The original\n * module config is preferred over the extension.\n *\n * @param module - The module to extend.\n * @param config - The extension config.\n * @returns\n */\nexport function extendModule(module: Module | null, config?: ViewConfig): Module {\n return {\n ...module,\n config: {\n ...config,\n ...(module?.config as ViewConfig),\n },\n };\n}\n\n/**\n * Create a single framework-agnostic route object. Later, it can be transformed into a framework-specific route object,\n * e.g., the one used by React Router.\n *\n * @param path - A route path segment.\n * @param children - An array of child routes.\n *\n * @returns A framework-agnostic route object.\n */\nexport function createRoute(path: string, children?: readonly AgnosticRoute[]): AgnosticRoute;\nexport function createRoute(path: string, module: Module, children?: readonly AgnosticRoute[]): AgnosticRoute;\nexport function createRoute(\n path: string,\n moduleOrChildren?: Module | readonly AgnosticRoute[],\n children?: readonly AgnosticRoute[],\n): AgnosticRoute {\n let module: Module | undefined;\n if (Array.isArray(moduleOrChildren)) {\n // eslint-disable-next-line no-param-reassign\n children = moduleOrChildren;\n } else {\n module = moduleOrChildren as Module | undefined;\n }\n\n return {\n path,\n module,\n children,\n };\n}\n"],
|
|
5
|
+
"mappings": "AAUO,SAAS,aAAa,QAAuB,QAA6B;AAC/E,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,MACN,GAAG;AAAA,MACH,GAAI,QAAQ;AAAA,IACd;AAAA,EACF;AACF;AAaO,SAAS,YACd,MACA,kBACA,UACe;AACf,MAAI;AACJ,MAAI,MAAM,QAAQ,gBAAgB,GAAG;AAEnC,eAAW;AAAA,EACb,OAAO;AACL,aAAS;AAAA,EACX;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function transformTree<T extends readonly unknown[], U>(nodes: T, transformer: (nodes: T, next: (
|
|
1
|
+
export declare function transformTree<T extends readonly unknown[], U, C extends object | null = null>(nodes: T, context: C, transformer: (nodes: T, next: (nodes: T, ctx?: C) => U, context: C) => U): U;
|
|
2
2
|
//# sourceMappingURL=transformTree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformTree.d.ts","sourceRoot":"","sources":["../src/shared/transformTree.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"transformTree.d.ts","sourceRoot":"","sources":["../src/shared/transformTree.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,IAAI,EAC3F,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GACvE,CAAC,CAEH"}
|
package/shared/transformTree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function transformTree(nodes, transformer) {
|
|
2
|
-
return transformer(nodes, (
|
|
1
|
+
function transformTree(nodes, context, transformer) {
|
|
2
|
+
return transformer(nodes, (n, ctx = context) => transformTree(n, ctx, transformer), context);
|
|
3
3
|
}
|
|
4
4
|
export {
|
|
5
5
|
transformTree
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/shared/transformTree.ts"],
|
|
4
|
-
"sourcesContent": ["export function transformTree<T extends readonly unknown[], U>(\n nodes: T,\n transformer: (nodes: T, next: (
|
|
5
|
-
"mappings": "AAAO,SAAS,cACd,OACA,aACG;AACH,SAAO,YAAY,OAAO,
|
|
4
|
+
"sourcesContent": ["export function transformTree<T extends readonly unknown[], U, C extends object | null = null>(\n nodes: T,\n context: C,\n transformer: (nodes: T, next: (nodes: T, ctx?: C) => U, context: C) => U,\n): U {\n return transformer(nodes, (n, ctx = context) => transformTree(n, ctx, transformer), context);\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAAS,cACd,OACA,SACA,aACG;AACH,SAAO,YAAY,OAAO,CAAC,GAAG,MAAM,YAAY,cAAc,GAAG,KAAK,WAAW,GAAG,OAAO;AAC7F;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/types.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export type ViewConfig = Readonly<{
|
|
|
31
31
|
*/
|
|
32
32
|
flowLayout?: boolean;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Set to true to make the view render without enclosing in any layouts.
|
|
36
|
+
*/
|
|
37
|
+
skipLayouts?: boolean;
|
|
38
|
+
|
|
34
39
|
menu?: Readonly<{
|
|
35
40
|
/**
|
|
36
41
|
* Title to use in the menu. Falls back the title property of the view
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyLayouts.d.ts","sourceRoot":"","sources":["../src/vite-plugin/applyLayouts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"applyLayouts.d.ts","sourceRoot":"","sources":["../src/vite-plugin/applyLayouts.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAMH;;;;;;GAMG;AACH,wBAA8B,YAAY,CACxC,SAAS,EAAE,SAAS,SAAS,EAAE,EAC/B,WAAW,EAAE,GAAG,GACf,OAAO,CAAC,SAAS,SAAS,EAAE,CAAC,CA0B/B"}
|
|
@@ -1,46 +1,29 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
1
|
import { readFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const routeWithFlowLayout = {
|
|
8
|
-
...route,
|
|
9
|
-
flowLayout: true
|
|
10
|
-
};
|
|
11
|
-
return route.children ? {
|
|
12
|
-
...routeWithFlowLayout,
|
|
13
|
-
children: route.children.map(enableFlowLayout)
|
|
14
|
-
} : routeWithFlowLayout;
|
|
15
|
-
}
|
|
16
|
-
function layoutExists(layoutPaths, path) {
|
|
17
|
-
const splitPath = path.split("/");
|
|
18
|
-
return layoutPaths.some((layout) => {
|
|
19
|
-
if (layout.length === 0) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
const splitLayout = layout.split("/");
|
|
23
|
-
if (splitLayout.length > splitPath.length) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
for (let i = 0; i < splitLayout.length; i++) {
|
|
27
|
-
if (splitPath[i] !== splitLayout[i]) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
});
|
|
2
|
+
import { join, relative } from "node:path/posix";
|
|
3
|
+
import { transformTree } from "../shared/transformTree.js";
|
|
4
|
+
function strip(path) {
|
|
5
|
+
return path.replace(/^\/*(.+)\/*$/u, "$1");
|
|
33
6
|
}
|
|
34
7
|
async function applyLayouts(routeMeta, layoutsFile) {
|
|
35
|
-
|
|
36
|
-
|
|
8
|
+
try {
|
|
9
|
+
const layoutContents = await readFile(layoutsFile, "utf-8");
|
|
10
|
+
const availableLayouts = JSON.parse(layoutContents);
|
|
11
|
+
const layoutPaths = availableLayouts.map((layout) => strip(layout.path));
|
|
12
|
+
return transformTree(
|
|
13
|
+
routeMeta,
|
|
14
|
+
{ path: "" },
|
|
15
|
+
(metas, next, ctx) => metas.map((meta) => {
|
|
16
|
+
const currentPath = join(ctx.path, strip(meta.path));
|
|
17
|
+
const children = meta.children ? next(meta.children, { path: currentPath }) : void 0;
|
|
18
|
+
return layoutPaths.some((path) => !relative(path, currentPath).startsWith("..")) ? { ...meta, flowLayout: true, children } : { ...meta, children };
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
23
|
+
return routeMeta;
|
|
24
|
+
}
|
|
25
|
+
throw e;
|
|
37
26
|
}
|
|
38
|
-
const layoutContents = await readFile(layoutsFile, "utf-8");
|
|
39
|
-
const availableLayouts = JSON.parse(layoutContents);
|
|
40
|
-
const layoutPaths = availableLayouts.map((layout) => stripLeadingSlash(layout.path));
|
|
41
|
-
return routeMeta.map(
|
|
42
|
-
(route) => layoutExists(layoutPaths, stripLeadingSlash(route.path)) ? enableFlowLayout(route) : route
|
|
43
|
-
);
|
|
44
27
|
}
|
|
45
28
|
export {
|
|
46
29
|
applyLayouts as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/vite-plugin/applyLayouts.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { readFile } from 'node:fs/promises';\nimport { join, relative } from 'node:path/posix';\nimport { transformTree } from '../shared/transformTree.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\n\n/**\n * The information about a particular server-side layout.\n */\nexport type LayoutMeta = Readonly<{\n path: string;\n}>;\n\nfunction strip(path: string) {\n return path.replace(/^\\/*(.+)\\/*$/u, '$1');\n}\n\n/**\n * Enables Flow layout flag on the matching routes based on the information from the layouts JSON file.\n *\n * @param routeMeta - The routes tree to process.\n * @param layoutsFile - The server layouts JSON file.\n * @returns Processed routes tree.\n */\nexport default async function applyLayouts(\n routeMeta: readonly RouteMeta[],\n layoutsFile: URL,\n): Promise<readonly RouteMeta[]> {\n try {\n const layoutContents = await readFile(layoutsFile, 'utf-8');\n const availableLayouts: readonly LayoutMeta[] = JSON.parse(layoutContents);\n const layoutPaths = availableLayouts.map((layout) => strip(layout.path));\n\n return transformTree<readonly RouteMeta[], readonly RouteMeta[], { path: string }>(\n routeMeta,\n { path: '' },\n (metas, next, ctx) =>\n metas.map((meta) => {\n const currentPath = join(ctx.path, strip(meta.path));\n const children = meta.children ? next(meta.children, { path: currentPath }) : undefined;\n\n return layoutPaths.some((path) => !relative(path, currentPath).startsWith('..'))\n ? { ...meta, flowLayout: true, children }\n : { ...meta, children };\n }),\n );\n } catch (e: unknown) {\n if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {\n return routeMeta;\n }\n\n throw e;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,MAAM,gBAAgB;AAC/B,SAAS,qBAAqB;AAU9B,SAAS,MAAM,MAAc;AAC3B,SAAO,KAAK,QAAQ,iBAAiB,IAAI;AAC3C;AASA,eAAO,aACL,WACA,aAC+B;AAC/B,MAAI;AACF,UAAM,iBAAiB,MAAM,SAAS,aAAa,OAAO;AAC1D,UAAM,mBAA0C,KAAK,MAAM,cAAc;AACzE,UAAM,cAAc,iBAAiB,IAAI,CAAC,WAAW,MAAM,OAAO,IAAI,CAAC;AAEvE,WAAO;AAAA,MACL;AAAA,MACA,EAAE,MAAM,GAAG;AAAA,MACX,CAAC,OAAO,MAAM,QACZ,MAAM,IAAI,CAAC,SAAS;AAClB,cAAM,cAAc,KAAK,IAAI,MAAM,MAAM,KAAK,IAAI,CAAC;AACnD,cAAM,WAAW,KAAK,WAAW,KAAK,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC,IAAI;AAE9E,eAAO,YAAY,KAAK,CAAC,SAAS,CAAC,SAAS,MAAM,WAAW,EAAE,WAAW,IAAI,CAAC,IAC3E,EAAE,GAAG,MAAM,YAAY,MAAM,SAAS,IACtC,EAAE,GAAG,MAAM,SAAS;AAAA,MAC1B,CAAC;AAAA,IACL;AAAA,EACF,SAAS,GAAY;AACnB,QAAI,aAAa,SAAS,UAAU,KAAK,EAAE,SAAS,UAAU;AAC5D,aAAO;AAAA,IACT;AAEA,UAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import type { RouteMeta } from './collectRoutesFromFS.js';
|
|
2
2
|
import type { RuntimeFileUrls } from './generateRuntimeFiles.js';
|
|
3
|
-
|
|
4
|
-
* Loads all the files from the received metadata and creates a framework-agnostic route tree.
|
|
5
|
-
*
|
|
6
|
-
* @param views - The abstract route tree.
|
|
7
|
-
* @param generatedDir - The directory where the generated view file will be stored.
|
|
8
|
-
*/
|
|
9
|
-
export default function createRoutesFromMeta(views: readonly RouteMeta[], { code: codeFile }: RuntimeFileUrls): string;
|
|
3
|
+
export default function createRoutesFromMeta(views: readonly RouteMeta[], urls: RuntimeFileUrls): string;
|
|
10
4
|
//# sourceMappingURL=createRoutesFromMeta.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRoutesFromMeta.d.ts","sourceRoot":"","sources":["../src/vite-plugin/createRoutesFromMeta.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createRoutesFromMeta.d.ts","sourceRoot":"","sources":["../src/vite-plugin/createRoutesFromMeta.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAuIjE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAEvG"}
|
|
@@ -1,95 +1,107 @@
|
|
|
1
|
-
import { relative, sep } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
1
|
import { template, transform as transformer } from "@vaadin/hilla-generator-utils/ast.js";
|
|
4
2
|
import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
|
|
5
|
-
import
|
|
6
|
-
|
|
3
|
+
import DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
|
|
4
|
+
import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.js";
|
|
5
|
+
import ts, {} from "typescript";
|
|
7
6
|
import { transformTree } from "../shared/transformTree.js";
|
|
8
7
|
import { convertFSRouteSegmentToURLPatternFormat } from "./utils.js";
|
|
9
8
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const fileExtensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
10
|
+
class RouteFromMetaProcessor {
|
|
11
|
+
#manager;
|
|
12
|
+
#views;
|
|
13
|
+
constructor(views, { json: jsonFile, code: codeFile }) {
|
|
14
|
+
this.#views = views;
|
|
15
|
+
const codeDir = new URL("./", codeFile);
|
|
16
|
+
this.#manager = new DependencyManager(new PathManager({ extension: ".js", relativeTo: codeDir }));
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
const currentId = id;
|
|
48
|
-
id += 1;
|
|
49
|
-
let mod;
|
|
50
|
-
if (file2) {
|
|
51
|
-
mod = `Page${currentId}`;
|
|
52
|
-
imports.push(createImport(mod, relativize(file2, codeDir)));
|
|
53
|
-
} else if (layout) {
|
|
54
|
-
mod = `Layout${currentId}`;
|
|
55
|
-
imports.push(createImport(mod, relativize(layout, codeDir)));
|
|
56
|
-
}
|
|
57
|
-
return createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, _children);
|
|
18
|
+
/**
|
|
19
|
+
* Loads all the files from the received metadata and creates a framework-agnostic route tree.
|
|
20
|
+
*
|
|
21
|
+
* @param views - The abstract route tree.
|
|
22
|
+
* @param generatedDir - The directory where the generated view file will be stored.
|
|
23
|
+
*/
|
|
24
|
+
process() {
|
|
25
|
+
const {
|
|
26
|
+
paths,
|
|
27
|
+
imports: { named, namespace }
|
|
28
|
+
} = this.#manager;
|
|
29
|
+
const errors = [];
|
|
30
|
+
const routes = transformTree(this.#views, null, (metas, next) => {
|
|
31
|
+
errors.push(
|
|
32
|
+
...metas.map((route) => route.path).filter((item, index, arr) => arr.indexOf(item) !== index).map((dup) => `console.error("Two views share the same path: ${dup}");`)
|
|
33
|
+
);
|
|
34
|
+
return metas.map(({ file: file2, layout, path, children, flowLayout }) => {
|
|
35
|
+
let _children;
|
|
36
|
+
if (children) {
|
|
37
|
+
_children = next(children);
|
|
38
|
+
}
|
|
39
|
+
let mod;
|
|
40
|
+
if (file2) {
|
|
41
|
+
const fileExt = fileExtensions.find((ext) => file2.pathname.endsWith(ext));
|
|
42
|
+
mod = namespace.add(paths.createRelativePath(file2, fileExt), `Page`);
|
|
43
|
+
} else if (layout) {
|
|
44
|
+
const fileExt = fileExtensions.find((ext) => layout.pathname.endsWith(ext));
|
|
45
|
+
mod = namespace.add(paths.createRelativePath(layout, fileExt), `Layout`);
|
|
46
|
+
}
|
|
47
|
+
const moduleExtension = flowLayout ? { flowLayout } : void 0;
|
|
48
|
+
return this.#createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, moduleExtension, _children);
|
|
49
|
+
});
|
|
58
50
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
'import { createRoute } from "@vaadin/hilla-file-router/runtime.js";',
|
|
63
|
-
([statement]) => statement
|
|
64
|
-
);
|
|
65
|
-
imports.unshift(createRouteImport);
|
|
66
|
-
}
|
|
67
|
-
imports.unshift(
|
|
68
|
-
template(
|
|
69
|
-
'import type { AgnosticRoute } from "@vaadin/hilla-file-router/types.js";',
|
|
70
|
-
([statement]) => statement
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
const routeDeclaration = template(
|
|
74
|
-
`import a from 'IMPORTS';
|
|
51
|
+
const agnosticRouteId = named.getIdentifier("@vaadin/hilla-file-router/types.js", "AgnosticRoute") ?? named.add("@vaadin/hilla-file-router/types.js", "AgnosticRoute", true);
|
|
52
|
+
let routeDeclaration = template(
|
|
53
|
+
`${errors.join("\n")}
|
|
75
54
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const routes: readonly AgnosticRoute[] = ROUTE;
|
|
55
|
+
const routes: readonly AGNOSTIC_ROUTE[] = ROUTE;
|
|
79
56
|
|
|
80
57
|
export default routes;
|
|
81
58
|
`,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
]
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
59
|
+
[
|
|
60
|
+
transformer(
|
|
61
|
+
(node) => ts.isIdentifier(node) && node.text === "ROUTE" ? ts.factory.createArrayLiteralExpression(routes, true) : node
|
|
62
|
+
),
|
|
63
|
+
transformer((node) => ts.isIdentifier(node) && node.text === "AGNOSTIC_ROUTE" ? agnosticRouteId : node)
|
|
64
|
+
]
|
|
65
|
+
);
|
|
66
|
+
routeDeclaration = [...this.#manager.imports.toCode(), ...routeDeclaration];
|
|
67
|
+
const file = createSourceFile(routeDeclaration, "file-routes.ts");
|
|
68
|
+
return printer.printFile(file);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create an abstract route creation function call. The nested function calls
|
|
72
|
+
* create a route tree.
|
|
73
|
+
*
|
|
74
|
+
* @param path - The path of the route.
|
|
75
|
+
* @param mod - The name of the route module imported as a namespace.
|
|
76
|
+
* @param children - The list of child route call expressions.
|
|
77
|
+
*/
|
|
78
|
+
#createRouteData(path, mod, extension, children) {
|
|
79
|
+
const { named } = this.#manager.imports;
|
|
80
|
+
let extendModuleId;
|
|
81
|
+
let modNode = "";
|
|
82
|
+
if (extension) {
|
|
83
|
+
extendModuleId = named.getIdentifier("@vaadin/hilla-file-router/runtime.js", "extendModule") ?? named.add("@vaadin/hilla-file-router/runtime.js", "extendModule");
|
|
84
|
+
modNode = `, EXTEND_MODULE(MOD, ${JSON.stringify(extension)})`;
|
|
85
|
+
} else if (mod) {
|
|
86
|
+
modNode = `, MOD`;
|
|
87
|
+
}
|
|
88
|
+
const createRouteId = named.getIdentifier("@vaadin/hilla-file-router/runtime.js", "createRoute") ?? named.add("@vaadin/hilla-file-router/runtime.js", "createRoute");
|
|
89
|
+
return template(
|
|
90
|
+
`const route = CREATE_ROUTE("${path}", ${modNode}${children ? `, CHILDREN` : ""})`,
|
|
91
|
+
([statement]) => statement.declarationList.declarations[0].initializer,
|
|
92
|
+
[
|
|
93
|
+
transformer(
|
|
94
|
+
(node) => ts.isIdentifier(node) && node.text === "CHILDREN" ? ts.factory.createArrayLiteralExpression(children, true) : node
|
|
95
|
+
),
|
|
96
|
+
transformer((node) => ts.isIdentifier(node) && node.text === "MOD" ? mod ?? ts.factory.createNull() : node),
|
|
97
|
+
transformer((node) => ts.isIdentifier(node) && node.text === "EXTEND_MODULE" ? extendModuleId : node),
|
|
98
|
+
transformer((node) => ts.isIdentifier(node) && node.text === "CREATE_ROUTE" ? createRouteId : node)
|
|
99
|
+
]
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function createRoutesFromMeta(views, urls) {
|
|
104
|
+
return new RouteFromMetaProcessor(views, urls).process();
|
|
93
105
|
}
|
|
94
106
|
export {
|
|
95
107
|
createRoutesFromMeta as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/vite-plugin/createRoutesFromMeta.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,
|
|
4
|
+
"sourcesContent": ["import { template, transform as transformer } from '@vaadin/hilla-generator-utils/ast.js';\nimport createSourceFile from '@vaadin/hilla-generator-utils/createSourceFile.js';\nimport DependencyManager from '@vaadin/hilla-generator-utils/dependencies/DependencyManager.js';\nimport PathManager from '@vaadin/hilla-generator-utils/dependencies/PathManager.js';\nimport ts, { type CallExpression, type Identifier, type VariableStatement } from 'typescript';\n\nimport { transformTree } from '../shared/transformTree.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport type { RuntimeFileUrls } from './generateRuntimeFiles.js';\nimport { convertFSRouteSegmentToURLPatternFormat } from './utils.js';\n\nconst printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\nconst fileExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n\nclass RouteFromMetaProcessor {\n readonly #manager: DependencyManager;\n readonly #views: readonly RouteMeta[];\n\n constructor(views: readonly RouteMeta[], { json: jsonFile, code: codeFile }: RuntimeFileUrls) {\n this.#views = views;\n\n const codeDir = new URL('./', codeFile);\n this.#manager = new DependencyManager(new PathManager({ extension: '.js', relativeTo: codeDir }));\n }\n\n /**\n * Loads all the files from the received metadata and creates a framework-agnostic route tree.\n *\n * @param views - The abstract route tree.\n * @param generatedDir - The directory where the generated view file will be stored.\n */\n process(): string {\n const {\n paths,\n imports: { named, namespace },\n } = this.#manager;\n const errors: string[] = [];\n\n const routes = transformTree<readonly RouteMeta[], readonly CallExpression[]>(this.#views, null, (metas, next) => {\n errors.push(\n ...metas\n .map((route) => route.path)\n .filter((item, index, arr) => arr.indexOf(item) !== index)\n .map((dup) => `console.error(\"Two views share the same path: ${dup}\");`),\n );\n\n return metas.map(({ file, layout, path, children, flowLayout }) => {\n let _children: readonly CallExpression[] | undefined;\n\n if (children) {\n _children = next(children);\n }\n\n let mod: Identifier | undefined;\n if (file) {\n const fileExt = fileExtensions.find((ext) => file.pathname.endsWith(ext));\n mod = namespace.add(paths.createRelativePath(file, fileExt), `Page`);\n } else if (layout) {\n const fileExt = fileExtensions.find((ext) => layout.pathname.endsWith(ext));\n mod = namespace.add(paths.createRelativePath(layout, fileExt), `Layout`);\n }\n\n const moduleExtension = flowLayout ? { flowLayout } : undefined;\n\n return this.#createRouteData(convertFSRouteSegmentToURLPatternFormat(path), mod, moduleExtension, _children);\n });\n });\n\n const agnosticRouteId =\n named.getIdentifier('@vaadin/hilla-file-router/types.js', 'AgnosticRoute') ??\n named.add('@vaadin/hilla-file-router/types.js', 'AgnosticRoute', true);\n\n let routeDeclaration = template(\n `${errors.join('\\n')}\n\nconst routes: readonly AGNOSTIC_ROUTE[] = ROUTE;\n\nexport default routes;\n`,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'ROUTE' ? ts.factory.createArrayLiteralExpression(routes, true) : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'AGNOSTIC_ROUTE' ? agnosticRouteId : node)),\n ],\n );\n\n routeDeclaration = [...this.#manager.imports.toCode(), ...routeDeclaration];\n\n const file = createSourceFile(routeDeclaration, 'file-routes.ts');\n return printer.printFile(file);\n }\n\n /**\n * Create an abstract route creation function call. The nested function calls\n * create a route tree.\n *\n * @param path - The path of the route.\n * @param mod - The name of the route module imported as a namespace.\n * @param children - The list of child route call expressions.\n */\n #createRouteData(\n path: string,\n mod: Identifier | undefined,\n extension?: Readonly<Record<string, unknown>>,\n children?: readonly CallExpression[],\n ): CallExpression {\n const { named } = this.#manager.imports;\n\n let extendModuleId: Identifier | undefined;\n let modNode = '';\n\n if (extension) {\n extendModuleId =\n named.getIdentifier('@vaadin/hilla-file-router/runtime.js', 'extendModule') ??\n named.add('@vaadin/hilla-file-router/runtime.js', 'extendModule');\n modNode = `, EXTEND_MODULE(MOD, ${JSON.stringify(extension)})`;\n } else if (mod) {\n modNode = `, MOD`;\n }\n\n const createRouteId =\n named.getIdentifier('@vaadin/hilla-file-router/runtime.js', 'createRoute') ??\n named.add('@vaadin/hilla-file-router/runtime.js', 'createRoute');\n\n return template(\n `const route = CREATE_ROUTE(\"${path}\", ${modNode}${children ? `, CHILDREN` : ''})`,\n ([statement]) => (statement as VariableStatement).declarationList.declarations[0].initializer as CallExpression,\n [\n transformer((node) =>\n ts.isIdentifier(node) && node.text === 'CHILDREN'\n ? ts.factory.createArrayLiteralExpression(children, true)\n : node,\n ),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'MOD' ? (mod ?? ts.factory.createNull()) : node)),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'EXTEND_MODULE' ? extendModuleId : node)),\n transformer((node) => (ts.isIdentifier(node) && node.text === 'CREATE_ROUTE' ? createRouteId : node)),\n ],\n );\n }\n}\n\nexport default function createRoutesFromMeta(views: readonly RouteMeta[], urls: RuntimeFileUrls): string {\n return new RouteFromMetaProcessor(views, urls).process();\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,UAAU,aAAa,mBAAmB;AACnD,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AACxB,OAAO,YAA0E;AAEjF,SAAS,qBAAqB;AAG9B,SAAS,+CAA+C;AAExD,MAAM,UAAU,GAAG,cAAc,EAAE,SAAS,GAAG,YAAY,SAAS,CAAC;AAErE,MAAM,iBAAiB,CAAC,O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E,CAAC,CAAC,SAAS,MAAO,UAAgC,gBAAgB,aAAa,CAAC,EAAE;AAAA,MAClF;AAAA,QACE;AAAA,UAAY,CAAC,SACX,GAAG,aAAa,IAAI,KAAK,KAAK,SAAS,aACnC,GAAG,QAAQ,6BAA6B,UAAU,IAAI,IACtD;AAAA,QACN;AAAA,QACA,YAAY,CAAC,SAAU,GAAG,aAAa,IAAI,KAAK,KAAK,SAAS,QAAS,OAAO,GAAG,QAAQ,WAAW,IAAK,IAAK;AAAA,QAC9G,YAAY,CAAC,SAAU,GAAG,aAAa,IAAI,KAAK,KAAK,SAAS,kBAAkB,iBAAiB,IAAK;AAAA,QACtG,YAAY,CAAC,SAAU,GAAG,aAAa,IAAI,KAAK,KAAK,SAAS,iBAAiB,gBAAgB,IAAK;AAAA,MACtG;AAAA,IACF;AAAA,EACF;AACF;AAEe,SAAR,qBAAsC,OAA6B,MAA+B;AACvG,SAAO,IAAI,uBAAuB,OAAO,IAAI,EAAE,QAAQ;AACzD;",
|
|
6
6
|
"names": ["file"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createViewConfigJson.d.ts","sourceRoot":"","sources":["../src/vite-plugin/createViewConfigJson.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgB1D;;;;;GAKG;AACH,wBAA8B,oBAAoB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"createViewConfigJson.d.ts","sourceRoot":"","sources":["../src/vite-plugin/createViewConfigJson.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAgB1D;;;;;GAKG;AACH,wBAA8B,oBAAoB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA8E/F"}
|
|
@@ -13,9 +13,10 @@ function* walkAST(node) {
|
|
|
13
13
|
async function createViewConfigJson(views) {
|
|
14
14
|
const res = await transformTree(
|
|
15
15
|
views,
|
|
16
|
+
null,
|
|
16
17
|
async (routes, next) => await Promise.all(
|
|
17
18
|
routes.map(async ({ path, file, layout, children, flowLayout }) => {
|
|
18
|
-
const newChildren = children ? await next(
|
|
19
|
+
const newChildren = children ? await next(children) : void 0;
|
|
19
20
|
if (!file && !layout) {
|
|
20
21
|
return {
|
|
21
22
|
route: convertFSRouteSegmentToURLPatternFormat(path),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/vite-plugin/createViewConfigJson.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFile } from 'node:fs/promises';\nimport { Script } from 'node:vm';\nimport ts, { type Node } from 'typescript';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport type { ServerViewConfig } from '../shared/internal.js';\nimport { transformTree } from '../shared/transformTree.js';\nimport type { ViewConfig } from '../types.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport { convertFSRouteSegmentToURLPatternFormat, extractParameterFromRouteSegment } from './utils.js';\n\n/**\n * Walks the TypeScript AST using the deep-first search algorithm.\n *\n * @param node - The node to walk.\n */\nfunction* walkAST(node: Node): Generator<Node> {\n yield node;\n\n for (const child of node.getChildren()) {\n yield* walkAST(child);\n }\n}\n\n/**\n * Creates a map of all leaf routes to their configuration. This file is used by the server to provide server-side\n * routes along with managing the client-side routes.\n *\n * @param views - The route metadata tree.\n */\nexport default async function createViewConfigJson(views: readonly RouteMeta[]): Promise<string> {\n const res = await transformTree<readonly RouteMeta[], Promise<readonly ServerViewConfig[]>>(\n views,\n async (routes, next) =>\n await Promise.all(\n routes.map(async ({ path, file, layout, children, flowLayout }) => {\n const newChildren = children ? await next(
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,OAAO,YAAuB;AAC9B,SAAS,mCAAmC;AAE5C,SAAS,qBAAqB;AAG9B,SAAS,yCAAyC,wCAAwC;AAO1F,UAAU,QAAQ,MAA6B;AAC7C,QAAM;AAEN,aAAW,SAAS,KAAK,YAAY,GAAG;AACtC,WAAO,QAAQ,KAAK;AAAA,EACtB;AACF;AAQA,eAAO,qBAA4C,OAA8C;AAC/F,QAAM,MAAM,MAAM;AAAA,IAChB;AAAA,IACA,OAAO,QAAQ,SACb,MAAM,QAAQ;AAAA,MACZ,OAAO,IAAI,OAAO,EAAE,MAAM,MAAM,QAAQ,UAAU,WAAW,MAAM;AACjE,cAAM,cAAc,WAAW,MAAM,KAAK,
|
|
4
|
+
"sourcesContent": ["import { readFile } from 'node:fs/promises';\nimport { Script } from 'node:vm';\nimport ts, { type Node } from 'typescript';\nimport { convertComponentNameToTitle } from '../shared/convertComponentNameToTitle.js';\nimport type { ServerViewConfig } from '../shared/internal.js';\nimport { transformTree } from '../shared/transformTree.js';\nimport type { ViewConfig } from '../types.js';\nimport type { RouteMeta } from './collectRoutesFromFS.js';\nimport { convertFSRouteSegmentToURLPatternFormat, extractParameterFromRouteSegment } from './utils.js';\n\n/**\n * Walks the TypeScript AST using the deep-first search algorithm.\n *\n * @param node - The node to walk.\n */\nfunction* walkAST(node: Node): Generator<Node> {\n yield node;\n\n for (const child of node.getChildren()) {\n yield* walkAST(child);\n }\n}\n\n/**\n * Creates a map of all leaf routes to their configuration. This file is used by the server to provide server-side\n * routes along with managing the client-side routes.\n *\n * @param views - The route metadata tree.\n */\nexport default async function createViewConfigJson(views: readonly RouteMeta[]): Promise<string> {\n const res = await transformTree<readonly RouteMeta[], Promise<readonly ServerViewConfig[]>>(\n views,\n null,\n async (routes, next) =>\n await Promise.all(\n routes.map(async ({ path, file, layout, children, flowLayout }) => {\n const newChildren = children ? await next(children) : undefined;\n\n if (!file && !layout) {\n return {\n route: convertFSRouteSegmentToURLPatternFormat(path),\n params: extractParameterFromRouteSegment(path),\n children: newChildren,\n } satisfies ServerViewConfig;\n }\n\n const sourceFile = ts.createSourceFile(\n 'f.ts',\n await readFile(file ?? layout!, 'utf8'),\n ts.ScriptTarget.ESNext,\n true,\n );\n let config: ViewConfig | undefined;\n let waitingForIdentifier = false;\n let componentName: string | undefined;\n\n for (const node of walkAST(sourceFile)) {\n if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.name.text === 'config') {\n if (node.initializer && ts.isObjectLiteralExpression(node.initializer)) {\n const code = node.initializer.getText(sourceFile);\n const script = new Script(`(${code})`);\n config = script.runInThisContext() as ViewConfig;\n if (config.flowLayout === undefined) {\n const copy = JSON.parse(JSON.stringify(config));\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n copy.flowLayout = flowLayout ?? false;\n config = copy;\n }\n }\n } else if (node.getText(sourceFile).startsWith('export default')) {\n waitingForIdentifier = true;\n } else if (waitingForIdentifier && ts.isIdentifier(node)) {\n componentName = node.text;\n waitingForIdentifier = false;\n }\n }\n\n if (config === undefined) {\n config = { flowLayout: flowLayout ?? false };\n }\n\n let title: string;\n\n if (config.title) {\n ({ title } = config);\n } else {\n if (!componentName) {\n throw new Error(\n `The file \"${String(file ?? layout!)}\" must contain a default export of a component whose name will be used as title by default`,\n );\n }\n\n title = convertComponentNameToTitle(componentName);\n }\n\n return {\n route: convertFSRouteSegmentToURLPatternFormat(path),\n ...config,\n params: extractParameterFromRouteSegment(config.route ?? path),\n title,\n children: newChildren ?? (layout ? [] : undefined),\n } satisfies ServerViewConfig;\n }),\n ),\n );\n\n return JSON.stringify(res, undefined, 2);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AACvB,OAAO,YAAuB;AAC9B,SAAS,mCAAmC;AAE5C,SAAS,qBAAqB;AAG9B,SAAS,yCAAyC,wCAAwC;AAO1F,UAAU,QAAQ,MAA6B;AAC7C,QAAM;AAEN,aAAW,SAAS,KAAK,YAAY,GAAG;AACtC,WAAO,QAAQ,KAAK;AA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AAEA,YAAI,WAAW,QAAW;AACxB,mBAAS,EAAE,YAAY,cAAc,MAAM;AAAA,QAC7C;AAEA,YAAI;AAEJ,YAAI,OAAO,OAAO;AAChB,WAAC,EAAE,MAAM,IAAI;AAAA,QACf,OAAO;AACL,cAAI,CAAC,eAAe;AAClB,kBAAM,IAAI;AAAA,cACR,aAAa,OAAO,QAAQ,MAAO,CAAC;AAAA,YACtC;AAAA,UACF;AAEA,kBAAQ,4BAA4B,aAAa;AAAA,QACnD;AAEA,eAAO;AAAA,UACL,OAAO,wCAAwC,IAAI;AAAA,UACnD,GAAG;AAAA,UACH,QAAQ,iCAAiC,OAAO,SAAS,IAAI;AAAA,UAC7D;AAAA,UACA,UAAU,gBAAgB,SAAS,CAAC,IAAI;AAAA,QAC1C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACJ;AAEA,SAAO,KAAK,UAAU,KAAK,QAAW,CAAC;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRuntimeFiles.d.ts","sourceRoot":"","sources":["../src/vite-plugin/generateRuntimeFiles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateRuntimeFiles.d.ts","sourceRoot":"","sources":["../src/vite-plugin/generateRuntimeFiles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAMnC;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC;IACrC;;;OAGG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC;IACV;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC;CACd,CAAC,CAAC;AAiCH;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,GAAG,EACb,IAAI,EAAE,eAAe,EACrB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,IAAI,CAAC,CA8Bf"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
1
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
2
|
import applyLayouts from "./applyLayouts.js";
|
|
4
|
-
import collectRoutesFromFS from "./collectRoutesFromFS.js";
|
|
3
|
+
import collectRoutesFromFS, {} from "./collectRoutesFromFS.js";
|
|
5
4
|
import createRoutesFromMeta from "./createRoutesFromMeta.js";
|
|
6
5
|
import createViewConfigJson from "./createViewConfigJson.js";
|
|
7
6
|
async function generateRuntimeFile(url, data, forceWrite) {
|
|
@@ -24,7 +23,16 @@ async function generateRuntimeFile(url, data, forceWrite) {
|
|
|
24
23
|
return shouldWrite;
|
|
25
24
|
}
|
|
26
25
|
async function generateRuntimeFiles(viewsDir, urls, extensions, logger, debug) {
|
|
27
|
-
let routeMeta
|
|
26
|
+
let routeMeta;
|
|
27
|
+
try {
|
|
28
|
+
routeMeta = await collectRoutesFromFS(viewsDir, { extensions, logger });
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
|
|
31
|
+
routeMeta = [];
|
|
32
|
+
} else {
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
28
36
|
if (debug) {
|
|
29
37
|
logger.info("Collected file-based routes");
|
|
30
38
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/vite-plugin/generateRuntimeFiles.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport type { Logger } from 'vite';\nimport applyLayouts from './applyLayouts.js';\nimport collectRoutesFromFS, { type RouteMeta } from './collectRoutesFromFS.js';\nimport createRoutesFromMeta from './createRoutesFromMeta.js';\nimport createViewConfigJson from './createViewConfigJson.js';\n\n/**\n * The URLs of the files to generate.\n */\nexport type RuntimeFileUrls = Readonly<{\n /**\n * The URL of the JSON file with the leaf routes and their metadata. This file\n * will be processed by the server to provide the final route configuration.\n */\n json: URL;\n /**\n * The URL of the module with the routes tree in a framework-agnostic format.\n */\n code: URL;\n /**\n * The URL of the JSON file containing server layout path information.\n */\n layouts: URL;\n}>;\n\n/**\n * Generates a file conditionally. If the file already exists and its content is the same as the\n * given data, the file will not be overwritten. It is useful to avoid unnecessary server\n * reboot during development.\n *\n * @param url - The URL of the file to generate.\n * @param data - The data to write to the file.\n * @param forceWrite - true to force writing the file even if there are no changes\n * @returns true if the file was written, false otherwise.\n */\nasync function generateRuntimeFile(url: URL, data: string, forceWrite?: boolean): Promise<boolean> {\n await mkdir(new URL('./', url), { recursive: true });\n let shouldWrite = forceWrite ?? false;\n if (!forceWrite) {\n let contents: string | undefined;\n try {\n contents = await readFile(url, 'utf-8');\n } catch (e: unknown) {\n if (!(e != null && typeof e === 'object' && 'code' in e && e.code === 'ENOENT')) {\n throw e;\n }\n }\n shouldWrite = contents !== data;\n }\n if (shouldWrite) {\n await writeFile(url, data, 'utf-8');\n }\n\n return shouldWrite;\n}\n\n/**\n * Collects all file-based routes from the given directory, and based on them generates two files\n * described by {@link RuntimeFileUrls} type.\n * @param viewsDir - The directory that contains file-based routes (views).\n * @param urls - The URLs of the files to generate.\n * @param extensions - The list of extensions that will be collected as routes.\n * @param logger - The Vite logger instance.\n * @param debug - true to debug\n */\nexport async function generateRuntimeFiles(\n viewsDir: URL,\n urls: RuntimeFileUrls,\n extensions: readonly string[],\n logger: Logger,\n debug: boolean,\n): Promise<void> {\n let routeMeta: readonly RouteMeta[];\n try {\n routeMeta = await collectRoutesFromFS(viewsDir, { extensions, logger });\n } catch (e: unknown) {\n if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {\n routeMeta = [];\n } else {\n throw e;\n }\n }\n\n if (debug) {\n logger.info('Collected file-based routes');\n }\n routeMeta = await applyLayouts(routeMeta, urls.layouts);\n const runtimeRoutesCode = createRoutesFromMeta(routeMeta, urls);\n const viewConfigJson = await createViewConfigJson(routeMeta);\n\n const jsonWritten = await generateRuntimeFile(urls.json, viewConfigJson);\n if (debug) {\n logger.info(`Frontend route list is generated: ${String(urls.json)}`);\n }\n // If the metadata has changed, we need to write the TS file also to make Vite HMR updates work properly.\n // Even though the contents of the TS file does not change, the contents of the files imported in the TS\n // files changes and the routes must be re-applied to the React router\n await generateRuntimeFile(urls.code, runtimeRoutesCode, jsonWritten);\n if (debug) {\n logger.info(`File Route module is generated: ${String(urls.code)}`);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,UAAU,iBAAiB;AAE3C,OAAO,kBAAkB;AACzB,OAAO,6BAA6C;AACpD,OAAO,0BAA0B;AACjC,OAAO,0BAA0B;AA+BjC,eAAe,oBAAoB,KAAU,MAAc,YAAwC;AACjG,QAAM,MAAM,IAAI,IAAI,MAAM,GAAG,GAAG,EAAE,WAAW,KAAK,CAAC;AACnD,MAAI,cAAc,cAAc;AAChC,MAAI,CAAC,YAAY;AACf,QAAI;AACJ,QAAI;AACF,iBAAW,MAAM,SAAS,KAAK,OAAO;AAAA,IACxC,SAAS,GAAY;AACnB,UAAI,EAAE,KAAK,QAAQ,OAAO,MAAM,YAAY,UAAU,KAAK,EAAE,SAAS,WAAW;AAC/E,cAAM;AAAA,MACR;AAAA,IACF;AACA,kBAAc,aAAa;AAAA,EAC7B;AACA,MAAI,aAAa;AACf,UAAM,UAAU,KAAK,MAAM,OAAO;AAAA,EACpC;AAEA,SAAO;AACT;AAWA,eAAsB,qBACpB,UACA,MACA,YACA,QACA,OACe;AACf,MAAI;AACJ,MAAI;AACF,gBAAY,MAAM,oBAAoB,UAAU,EAAE,YAAY,OAAO,CAAC;AAAA,EACxE,SAAS,GAAY;AACnB,QAAI,aAAa,SAAS,UAAU,KAAK,EAAE,S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