@vaadin/hilla-file-router 25.2.0-alpha6 → 25.2.0-alpha8
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/hilla-file-router",
|
|
3
|
-
"version": "25.2.0-
|
|
3
|
+
"version": "25.2.0-alpha8",
|
|
4
4
|
"description": "Hilla file-based router",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -62,10 +62,9 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@ungap/with-resolvers": "0.1.0",
|
|
65
|
-
"@vaadin/hilla-generator-utils": "25.2.0-
|
|
66
|
-
"@vaadin/hilla-react-auth": "25.2.0-
|
|
67
|
-
"@vaadin/hilla-react-signals": "25.2.0-
|
|
68
|
-
"tsc-template": "0.2.3",
|
|
65
|
+
"@vaadin/hilla-generator-utils": "25.2.0-alpha8",
|
|
66
|
+
"@vaadin/hilla-react-auth": "25.2.0-alpha8",
|
|
67
|
+
"@vaadin/hilla-react-signals": "25.2.0-alpha8",
|
|
69
68
|
"typescript": "6.0.3"
|
|
70
69
|
}
|
|
71
70
|
}
|
|
@@ -19,7 +19,7 @@ export function createMenuItems() {
|
|
|
19
19
|
vaadinObj.registrations ??= [];
|
|
20
20
|
vaadinObj.registrations.push({
|
|
21
21
|
is: feature ? `@vaadin/hilla-file-router/${feature}` : "@vaadin/hilla-file-router",
|
|
22
|
-
version: "25.2.0-
|
|
22
|
+
version: "25.2.0-alpha8"
|
|
23
23
|
});
|
|
24
24
|
})("createMenuItems", window.Vaadin);
|
|
25
25
|
const collator = new Intl.Collator("en-US");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,SAAsB,2CAA4C;AAIlE,OAAO,MAAMA,cAAkF,OAC5F,OAAwB,QAAQ,MAClC;AAED,SAAS,WAA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C;AACH","names":["viewsSignal: Signal<Readonly<Record<string, Readonly<ViewConfig>>> | undefined>","value: ViewConfig","path: string","e: unknown"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/file-router/src/runtime/createMenuItems.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\nimport { type Signal, signal } from '@vaadin/hilla-react-signals';\nimport type { VaadinWindow } from '../shared/internal.js';\nimport type { MenuItem, ViewConfig } from '../types.js';\n\nexport const viewsSignal: Signal<Readonly<Record<string, Readonly<ViewConfig>>> | undefined> = signal(\n (window as VaadinWindow).Vaadin?.views,\n);\n\nfunction isExcluded(value: ViewConfig): boolean {\n return !!value.menu?.exclude;\n}\n\nfunction hasVariablePathSegment(path: string): boolean {\n return path.split('/').some((segment) => segment.startsWith(':'));\n}\n\n/**\n * Creates menu items from the views provided by the server. The views are sorted according to the\n * {@link ViewConfig.menu.order}, filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.\n * Note that views with no order are put below views with an order. Ties are resolved based on the path string\n * comparison.\n *\n * @returns A list of menu items.\n */\nexport function createMenuItems<T = unknown>(): ReadonlyArray<MenuItem<T>> {\n // @ts-expect-error: esbuild injection\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n ((feature, vaadinObj = (globalThis.Vaadin ??= {})) => {\n vaadinObj.registrations ??= [];\n vaadinObj.registrations.push({\n is: feature ? `@vaadin/hilla-file-router/${feature}` : '@vaadin/hilla-file-router',\n version: '25.2.0-
|
|
1
|
+
{"mappings":"AACA,SAAsB,2CAA4C;AAIlE,OAAO,MAAMA,cAAkF,OAC5F,OAAwB,QAAQ,MAClC;AAED,SAAS,WAAWC,OAA4B;AAC9C,UAAS,MAAM,MAAM;AACtB;AAED,SAAS,uBAAuBC,MAAuB;AACrD,QAAO,KAAK,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,QAAQ,WAAW,IAAI,CAAC;AAClE;;;;;;;;;AAUD,OAAO,SAAS,kBAA2D;AAGzE,EAAC,CAAC,SAAS,YAAa,WAAW,WAAW,CAAE,MAAM;AACtD,YAAU,kBAAkB,CAAE;AAC9B,YAAU,cAAc,KAAK;GAC3B,IAAI,WAAW,4BAA4B,QAAQ,IAAI;GACvD,SAAS;EACV,EAAC;CACH,GAAE,mBAAoB,OAAwB,OAAO;CACpD,MAAM,WAAW,IAAI,KAAK,SAAS;AACnC,MAAK,YAAY,OAAO;AACtB,SAAO,CAAE;CACV;CAED,MAAM,QAAQ,OAAO,QAAQ,YAAY,MAAM;AAE/C,QACE,MAEG,OAAO,CAAC,CAAC,MAAM,MAAM,MAAM,WAAW,MAAM,KAAK,uBAAuB,KAAK,CAAC,CAE9E,IAAI,CAAC,CAAC,MAAM,OAAO,MAAM;EACxB,IAAI;EACJ,MAAM,OAAO,MAAM;EACnB,OAAO,OAAO,MAAM,SAAS,OAAO;EACpC,OAAO,OAAO,MAAM;EACpB,QAAQ,OAAO;CAChB,GAAE,CAEF,KAAK,CAAC,OAAO,UAAU;EACtB,MAAM,cAAc,MAAM,SAAS,OAAO,cAAc,MAAM,SAAS,OAAO;AAC9E,SAAO,eAAe,IAAI,aAAa,SAAS,QAAQ,MAAM,IAAI,MAAM,GAAG;CAC5E,EAAC;AAEP;AAED,IAAI,OAAO,KAAK,KAAK;AACnB,QAAO,KAAK,IAAI,GAAG,mBAAmB,MAAM;AAC1C,QAAM,iBAAiB,CACpB,KAAK,OAAO,SAAS,KAAK,MAAM,CAAC,CACjC,KAAK,CAAC,SAAS;AACd,eAAY,QAAQ;EACrB,EAAC,CACD,MAAM,CAACC,MAAe;AACrB,WAAQ,MAAM,8BAA8B,EAAE;EAC/C,EAAC;CACL,EAAC;AACH","names":["viewsSignal: Signal<Readonly<Record<string, Readonly<ViewConfig>>> | undefined>","value: ViewConfig","path: string","e: unknown"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/file-router/src/runtime/createMenuItems.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\nimport { type Signal, signal } from '@vaadin/hilla-react-signals';\nimport type { VaadinWindow } from '../shared/internal.js';\nimport type { MenuItem, ViewConfig } from '../types.js';\n\nexport const viewsSignal: Signal<Readonly<Record<string, Readonly<ViewConfig>>> | undefined> = signal(\n (window as VaadinWindow).Vaadin?.views,\n);\n\nfunction isExcluded(value: ViewConfig): boolean {\n return !!value.menu?.exclude;\n}\n\nfunction hasVariablePathSegment(path: string): boolean {\n return path.split('/').some((segment) => segment.startsWith(':'));\n}\n\n/**\n * Creates menu items from the views provided by the server. The views are sorted according to the\n * {@link ViewConfig.menu.order}, filtered out if they are explicitly excluded via {@link ViewConfig.menu.exclude}.\n * Note that views with no order are put below views with an order. Ties are resolved based on the path string\n * comparison.\n *\n * @returns A list of menu items.\n */\nexport function createMenuItems<T = unknown>(): ReadonlyArray<MenuItem<T>> {\n // @ts-expect-error: esbuild injection\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n ((feature, vaadinObj = (globalThis.Vaadin ??= {})) => {\n vaadinObj.registrations ??= [];\n vaadinObj.registrations.push({\n is: feature ? `@vaadin/hilla-file-router/${feature}` : '@vaadin/hilla-file-router',\n version: '25.2.0-alpha8',\n });\n})('createMenuItems', (window as VaadinWindow).Vaadin);\n const collator = new Intl.Collator('en-US');\n if (!viewsSignal.value) {\n return [];\n }\n\n const views = Object.entries(viewsSignal.value);\n\n return (\n views\n // Filter out the views that are explicitly excluded from the menu.\n .filter(([path, value]) => !isExcluded(value) && !hasVariablePathSegment(path))\n // Map the views to menu items.\n .map(([path, config]) => ({\n to: path,\n icon: config.menu?.icon,\n title: config.menu?.title ?? config.title,\n order: config.menu?.order,\n detail: config.detail as T | undefined,\n }))\n // Sort views according to the order specified in the view configuration.\n .sort((menuA, menuB) => {\n const ordersDiff = (menuA.order ?? Number.MAX_VALUE) - (menuB.order ?? Number.MAX_VALUE);\n return ordersDiff !== 0 ? ordersDiff : collator.compare(menuA.to, menuB.to);\n })\n );\n}\n\nif (import.meta.hot) {\n import.meta.hot.on('fs-route-update', () => {\n fetch('?v-r=routeinfo')\n .then(async (resp) => resp.json())\n .then((json) => {\n viewsSignal.value = json;\n })\n .catch((e: unknown) => {\n console.error('Failed to fetch route info', e);\n });\n });\n}\n"],"version":3}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import createSourceFile from "@vaadin/hilla-generator-utils/createSourceFile.js";
|
|
2
2
|
import DependencyManager from "@vaadin/hilla-generator-utils/dependencies/DependencyManager.js";
|
|
3
3
|
import PathManager from "@vaadin/hilla-generator-utils/dependencies/PathManager.js";
|
|
4
|
-
import ast from "tsc-template";
|
|
4
|
+
import ast from "@vaadin/hilla-generator-utils/tsc-template.js";
|
|
5
5
|
import { createPrinter, factory, NewLineKind } from "typescript";
|
|
6
6
|
import { transformTree } from "../shared/transformTree.js";
|
|
7
7
|
import { convertFSRouteSegmentToURLPatternFormat } from "./utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,OAAO,yEAA0E;AACjF,OAAO,wFAAyF;AAChG,OAAO,4EAA6E;AACpF,OAAO,uBAAwB;AAC/B,SAEE,eACA,SAEA,+BAGkB;AAEpB,SAAS,iDAAkD;AAG3D,SAAS,2DAA4D;AAErE,MAAM,UAAU,cAAc,EAAE,SAAS,YAAY,SAAU,EAAC;AAEhE,MAAM,iBAAiB;CAAC;CAAO;CAAQ;CAAO;AAAO;AAErD,MAAM,oBAAoB;AAC1B,MAAM,6BAA6B,EAAE,kBAAkB;AACvD,MAAM,2BAA2B,EAAE,kBAAkB;AAcrD,SAAS,aAAaA,KAAgE;AACpF,UAAS,OAAO,UAAU;AAC3B;AAED,SAAS,YAAYC,aAAgCC,MAAcC,QAA6C;AAC9G,KAAI,OAAO,SAAS,WAAW;AAC7B,SAAO,OAAO;CACf;CAGD,MAAM,eAAe,YAAY,KAAK,QAAQ;CAC9C,MAAM,eAAe,gBAAgB,SAAS,MAAM,SAAS;AAC7D,SAAQ;AACT;AAED,MAAM,uBAAuB;CAC3B,AAASC;CACT,AAASC;CACT,AAASC;CAET,YACEC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AAW,GAAG;EAC5E,WAAU,QAAQ;AACjB,eAAY,OAAO;AACnB,YAAS,OAAO,aACX,IAAI,oBAAoB,OAAO,SAAS,gBAAgB,OAAO,WAAW,UAAU,CAAC,OACnF,OACH,OAAO;EACZ;EAED,MAAM,YAAY,WAAW,QAAQ,6BAA6B,UAAU,KAAK,GAAG;AASpF,SAAO,IAAI,EAAE,cAAc,IAAI,KAAK,KAAK,aAAa,GAAG,IAAI,UAAU,GAAG,IAAI,UAAU,GAAG;CAC5F;AACF;AAED,eAAe,SAAS,qBACtBV,OACAC,aACAU,MACQ;AACR,QAAO,IAAI,uBAAuB,OAAO,aAAa,MAAM,SAAS;AACtE","names":["mod: LazyModule | RegularModule | undefined","pathContext: readonly string[]","path: string","config: Readonly<ServerViewConfig>","#manager","#views","#configs","views: readonly RouteMeta[]","viewConfigs: readonly ServerViewConfig[]","errors: string[]","_children: readonly CallExpression[] | undefined","module: LazyModule | RegularModule | undefined","relativePath: string | undefined","fileName: string | undefined","#createRouteData","children: readonly CallExpression[] | undefined","component: PropertyAccessExpression | CallExpression | undefined","config: PropertyAccessExpression | ObjectLiteralExpression | string | undefined","urls: RuntimeFileUrls"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/file-router/src/vite-plugin/createRoutesFromMeta.ts"],"sourcesContent":["import 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 ast from 'tsc-template';\nimport {\n type CallExpression,\n createPrinter,\n factory,\n type Identifier,\n NewLineKind,\n type ObjectLiteralExpression,\n type PropertyAccessExpression,\n} from 'typescript';\nimport type { ServerViewConfig } from '../shared/internal.js';\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 = createPrinter({ newLine: NewLineKind.LineFeed });\n\nconst fileExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n\nconst HILLA_FILE_ROUTER = '@vaadin/hilla-file-router';\nconst HILLA_FILE_ROUTER_RUNTIME = `${HILLA_FILE_ROUTER}/runtime.js`;\nconst HILLA_FILE_ROUTER_TYPES = `${HILLA_FILE_ROUTER}/types.js`;\n\ntype LazyModule = Readonly<{\n path: string;\n config: ServerViewConfig;\n lazyId: Identifier;\n}>;\n\ntype RegularModule = Readonly<{\n componentId: PropertyAccessExpression;\n configId: PropertyAccessExpression;\n flowLayout?: boolean;\n}>;\n\nfunction isLazyModule(mod: LazyModule | RegularModule | undefined): mod is LazyModule {\n return !!mod && 'path' in mod;\n}\n\nfunction isLazyRoute(pathContext: readonly string[], path: string, config: Readonly<ServerViewConfig>): boolean {\n if (config.lazy !== undefined) {\n return config.lazy;\n }\n\n // \"/\" and \"/login\" are eager by default\n const rootContext = !pathContext.some(Boolean);\n const eagerDefault = rootContext && (path === '' || path === 'login');\n return !eagerDefault;\n}\n\nclass RouteFromMetaProcessor {\n readonly #manager: DependencyManager;\n readonly #views: readonly RouteMeta[];\n readonly #configs: readonly ServerViewConfig[];\n\n constructor(\n views: readonly RouteMeta[],\n viewConfigs: readonly ServerViewConfig[],\n { code: codeFile }: RuntimeFileUrls,\n ) {\n this.#views = views;\n this.#configs = viewConfigs;\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 process(): string {\n const {\n paths,\n imports: { namespace, named },\n } = this.#manager;\n const errors: string[] = [];\n\n const routes = transformTree<\n [pathContext: readonly string[], metas: readonly RouteMeta[], configs: readonly ServerViewConfig[]],\n readonly CallExpression[]\n >([[], this.#views, this.#configs], null, ([pathContext, metas, configs], 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 }, index) => {\n const config = configs[index]!;\n let _children: readonly CallExpression[] | undefined;\n\n if (children) {\n // Assuming that if we have `children` in the route, we also have\n // `children` in the config.\n _children = next([[...pathContext, path], children, config.children!]);\n }\n\n let module: LazyModule | RegularModule | undefined;\n\n let relativePath: string | undefined;\n let fileName: string | undefined;\n\n if (file) {\n const fileExt = fileExtensions.find((ext) => file.pathname.endsWith(ext));\n relativePath = paths.createRelativePath(file, fileExt);\n fileName = 'Page';\n } else if (layout) {\n const fileExt = fileExtensions.find((ext) => layout.pathname.endsWith(ext));\n relativePath = paths.createRelativePath(layout, fileExt);\n fileName = 'Layout';\n }\n\n if (relativePath && fileName) {\n if (isLazyRoute(pathContext, path, config)) {\n module = {\n path: relativePath,\n config,\n lazyId: named.getIdentifier('react', 'lazy') ?? named.add('react', 'lazy'),\n } satisfies LazyModule;\n } else {\n const mod = namespace.add(relativePath, fileName);\n const reactModuleType =\n named.getIdentifier(HILLA_FILE_ROUTER_TYPES, 'RouteModule') ??\n named.add(HILLA_FILE_ROUTER_TYPES, 'RouteModule', true);\n\n module = {\n componentId: ast`${mod}.default`.node as PropertyAccessExpression,\n configId: ast`(${mod} as ${reactModuleType}).config`.node as PropertyAccessExpression,\n flowLayout: config.flowLayout,\n } satisfies RegularModule;\n }\n }\n\n return this.#createRouteData(convertFSRouteSegmentToURLPatternFormat(path), module, _children);\n });\n });\n\n const agnosticRouteId =\n named.getIdentifier(HILLA_FILE_ROUTER_TYPES, 'AgnosticRoute') ??\n named.add(HILLA_FILE_ROUTER_TYPES, 'AgnosticRoute', true);\n const routeDeclaration = [\n ...this.#manager.imports.toCode(),\n ...ast`${errors.join('\\n')}\nconst routes: readonly ${agnosticRouteId}[] = ${factory.createArrayLiteralExpression(routes, true)};\nexport default routes;`.source.statements,\n ];\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 module - The module to build route from.\n * @param children - The list of child route call expressions.\n */\n #createRouteData(\n path: string,\n module: LazyModule | RegularModule | undefined,\n children: readonly CallExpression[] | undefined,\n ): CallExpression {\n const { named } = this.#manager.imports;\n\n const createRouteId =\n named.getIdentifier(HILLA_FILE_ROUTER_RUNTIME, 'createRoute') ??\n named.add(HILLA_FILE_ROUTER_RUNTIME, 'createRoute');\n\n let component: PropertyAccessExpression | CallExpression | undefined;\n let config: PropertyAccessExpression | ObjectLiteralExpression | string | undefined;\n\n if (isLazyModule(module)) {\n const { children: _c, params: _p, ...viewConfig } = module.config;\n\n component = ast`${module.lazyId}(() => import('${module.path}')`.node as CallExpression;\n config = Object.keys(viewConfig).length > 0 ? JSON.stringify(viewConfig) : '';\n } else if (module) {\n component = module.componentId;\n config = module.flowLayout\n ? (ast`const a = %{ { ...${module.configId}, flowLayout: ${module.flowLayout.toString()} } }%`\n .node as ObjectLiteralExpression)\n : module.configId;\n }\n\n const _children = children ? factory.createArrayLiteralExpression(children, true) : '';\n\n // ```ts\n // createRoute(\"grandparent\", {...grandparentConfig, flowLayout: true}, [\n // createRoute(\"parent\", ParentPage, parentConfig, [\n // createRoute(\"child\", lazy(() => import('../ChildPage.js')), { title: 'Child Page' }),\n // ]),\n // ]),\n // ```\n return ast`${createRouteId}(\"${path}\", ${component ?? ''}, ${config ?? ''}, ${_children})`.node as CallExpression;\n }\n}\n\nexport default function createRoutesFromMeta(\n views: readonly RouteMeta[],\n viewConfigs: readonly ServerViewConfig[],\n urls: RuntimeFileUrls,\n): string {\n return new RouteFromMetaProcessor(views, viewConfigs, urls).process();\n}\n"],"version":3}
|
|
1
|
+
{"mappings":"AAAA,OAAO,yEAA0E;AACjF,OAAO,wFAAyF;AAChG,OAAO,4EAA6E;AACpF,OAAO,wDAAyD;AAChE,SAEE,eACA,SAEA,+BAGkB;AAEpB,SAAS,i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Q,6BAA6B,QAAQ,KAAK,CAAC;wBAC3E,OAAO,UAC1B;EAED,MAAM,OAAO,iBAAiB,kBAAkB,iBAAiB;AACjE,SAAO,QAAQ,UAAU,KAAK;CAC/B;;;;;;;;;CAUD,iBACEF,MACAS,QACAI,UACgB;EAChB,MAAM,EAAE,OAAO,GAAG,KAAKX,SAAS;EAEhC,MAAM,gBACJ,MAAM,cAAc,2BAA2B,cAAc,IAC7D,MAAM,IAAI,2BAA2B,cAAc;EAErD,IAAIY;EACJ,IAAIC;AAEJ,MAAI,aAAa,OAAO,EAAE;GACxB,MAAM,EAAE,UAAU,IAAI,QAAQ,GAAI,GAAG,YAAY,GAAG,OAAO;AAE3D,eAAY,IAAI,EAAE,OAAO,OAAO,iBAAiB,OAAO,KAAK,IAAI;AACjE,YAAS,OAAO,KAAK,WAAW,CAAC,SAAS,IAAI,KAAK,UAAU,WAAW,GAAG;EAC5E,WAAU,QAAQ;AACjB,eAAY,OAAO;AACnB,YAAS,OAAO,aACX,IAAI,oBAAoB,OAAO,SAAS,gBAAgB,OAAO,WAAW,UAAU,CAAC,OACnF,OACH,OAAO;EACZ;EAED,MAAM,YAAY,WAAW,QAAQ,6BAA6B,UAAU,KAAK,GAAG;AASpF,SAAO,IAAI,EAAE,cAAc,IAAI,KAAK,KAAK,aAAa,GAAG,IAAI,UAAU,GAAG,IAAI,UAAU,GAAG;CAC5F;AACF;AAED,eAAe,SAAS,qBACtBV,OACAC,aACAU,MACQ;AACR,QAAO,IAAI,uBAAuB,OAAO,aAAa,MAAM,SAAS;AACtE","names":["mod: LazyModule | RegularModule | undefined","pathContext: readonly string[]","path: string","config: Readonly<ServerViewConfig>","#manager","#views","#configs","views: readonly RouteMeta[]","viewConfigs: readonly ServerViewConfig[]","errors: string[]","_children: readonly CallExpression[] | undefined","module: LazyModule | RegularModule | undefined","relativePath: string | undefined","fileName: string | undefined","#createRouteData","children: readonly CallExpression[] | undefined","component: PropertyAccessExpression | CallExpression | undefined","config: PropertyAccessExpression | ObjectLiteralExpression | string | undefined","urls: RuntimeFileUrls"],"sources":["/opt/agent/work/649c11185a3798db/packages/ts/file-router/src/vite-plugin/createRoutesFromMeta.ts"],"sourcesContent":["import 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 ast from '@vaadin/hilla-generator-utils/tsc-template.js';\nimport {\n type CallExpression,\n createPrinter,\n factory,\n type Identifier,\n NewLineKind,\n type ObjectLiteralExpression,\n type PropertyAccessExpression,\n} from 'typescript';\nimport type { ServerViewConfig } from '../shared/internal.js';\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 = createPrinter({ newLine: NewLineKind.LineFeed });\n\nconst fileExtensions = ['.ts', '.tsx', '.js', '.jsx'];\n\nconst HILLA_FILE_ROUTER = '@vaadin/hilla-file-router';\nconst HILLA_FILE_ROUTER_RUNTIME = `${HILLA_FILE_ROUTER}/runtime.js`;\nconst HILLA_FILE_ROUTER_TYPES = `${HILLA_FILE_ROUTER}/types.js`;\n\ntype LazyModule = Readonly<{\n path: string;\n config: ServerViewConfig;\n lazyId: Identifier;\n}>;\n\ntype RegularModule = Readonly<{\n componentId: PropertyAccessExpression;\n configId: PropertyAccessExpression;\n flowLayout?: boolean;\n}>;\n\nfunction isLazyModule(mod: LazyModule | RegularModule | undefined): mod is LazyModule {\n return !!mod && 'path' in mod;\n}\n\nfunction isLazyRoute(pathContext: readonly string[], path: string, config: Readonly<ServerViewConfig>): boolean {\n if (config.lazy !== undefined) {\n return config.lazy;\n }\n\n // \"/\" and \"/login\" are eager by default\n const rootContext = !pathContext.some(Boolean);\n const eagerDefault = rootContext && (path === '' || path === 'login');\n return !eagerDefault;\n}\n\nclass RouteFromMetaProcessor {\n readonly #manager: DependencyManager;\n readonly #views: readonly RouteMeta[];\n readonly #configs: readonly ServerViewConfig[];\n\n constructor(\n views: readonly RouteMeta[],\n viewConfigs: readonly ServerViewConfig[],\n { code: codeFile }: RuntimeFileUrls,\n ) {\n this.#views = views;\n this.#configs = viewConfigs;\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 process(): string {\n const {\n paths,\n imports: { namespace, named },\n } = this.#manager;\n const errors: string[] = [];\n\n const routes = transformTree<\n [pathContext: readonly string[], metas: readonly RouteMeta[], configs: readonly ServerViewConfig[]],\n readonly CallExpression[]\n >([[], this.#views, this.#configs], null, ([pathContext, metas, configs], 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 }, index) => {\n const config = configs[index]!;\n let _children: readonly CallExpression[] | undefined;\n\n if (children) {\n // Assuming that if we have `children` in the route, we also have\n // `children` in the config.\n _children = next([[...pathContext, path], children, config.children!]);\n }\n\n let module: LazyModule | RegularModule | undefined;\n\n let relativePath: string | undefined;\n let fileName: string | undefined;\n\n if (file) {\n const fileExt = fileExtensions.find((ext) => file.pathname.endsWith(ext));\n relativePath = paths.createRelativePath(file, fileExt);\n fileName = 'Page';\n } else if (layout) {\n const fileExt = fileExtensions.find((ext) => layout.pathname.endsWith(ext));\n relativePath = paths.createRelativePath(layout, fileExt);\n fileName = 'Layout';\n }\n\n if (relativePath && fileName) {\n if (isLazyRoute(pathContext, path, config)) {\n module = {\n path: relativePath,\n config,\n lazyId: named.getIdentifier('react', 'lazy') ?? named.add('react', 'lazy'),\n } satisfies LazyModule;\n } else {\n const mod = namespace.add(relativePath, fileName);\n const reactModuleType =\n named.getIdentifier(HILLA_FILE_ROUTER_TYPES, 'RouteModule') ??\n named.add(HILLA_FILE_ROUTER_TYPES, 'RouteModule', true);\n\n module = {\n componentId: ast`${mod}.default`.node as PropertyAccessExpression,\n configId: ast`(${mod} as ${reactModuleType}).config`.node as PropertyAccessExpression,\n flowLayout: config.flowLayout,\n } satisfies RegularModule;\n }\n }\n\n return this.#createRouteData(convertFSRouteSegmentToURLPatternFormat(path), module, _children);\n });\n });\n\n const agnosticRouteId =\n named.getIdentifier(HILLA_FILE_ROUTER_TYPES, 'AgnosticRoute') ??\n named.add(HILLA_FILE_ROUTER_TYPES, 'AgnosticRoute', true);\n const routeDeclaration = [\n ...this.#manager.imports.toCode(),\n ...ast`${errors.join('\\n')}\nconst routes: readonly ${agnosticRouteId}[] = ${factory.createArrayLiteralExpression(routes, true)};\nexport default routes;`.source.statements,\n ];\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 module - The module to build route from.\n * @param children - The list of child route call expressions.\n */\n #createRouteData(\n path: string,\n module: LazyModule | RegularModule | undefined,\n children: readonly CallExpression[] | undefined,\n ): CallExpression {\n const { named } = this.#manager.imports;\n\n const createRouteId =\n named.getIdentifier(HILLA_FILE_ROUTER_RUNTIME, 'createRoute') ??\n named.add(HILLA_FILE_ROUTER_RUNTIME, 'createRoute');\n\n let component: PropertyAccessExpression | CallExpression | undefined;\n let config: PropertyAccessExpression | ObjectLiteralExpression | string | undefined;\n\n if (isLazyModule(module)) {\n const { children: _c, params: _p, ...viewConfig } = module.config;\n\n component = ast`${module.lazyId}(() => import('${module.path}')`.node as CallExpression;\n config = Object.keys(viewConfig).length > 0 ? JSON.stringify(viewConfig) : '';\n } else if (module) {\n component = module.componentId;\n config = module.flowLayout\n ? (ast`const a = %{ { ...${module.configId}, flowLayout: ${module.flowLayout.toString()} } }%`\n .node as ObjectLiteralExpression)\n : module.configId;\n }\n\n const _children = children ? factory.createArrayLiteralExpression(children, true) : '';\n\n // ```ts\n // createRoute(\"grandparent\", {...grandparentConfig, flowLayout: true}, [\n // createRoute(\"parent\", ParentPage, parentConfig, [\n // createRoute(\"child\", lazy(() => import('../ChildPage.js')), { title: 'Child Page' }),\n // ]),\n // ]),\n // ```\n return ast`${createRouteId}(\"${path}\", ${component ?? ''}, ${config ?? ''}, ${_children})`.node as CallExpression;\n }\n}\n\nexport default function createRoutesFromMeta(\n views: readonly RouteMeta[],\n viewConfigs: readonly ServerViewConfig[],\n urls: RuntimeFileUrls,\n): string {\n return new RouteFromMetaProcessor(views, viewConfigs, urls).process();\n}\n"],"version":3}
|