@tanstack/start-plugin-core 1.121.0-alpha.8 → 1.121.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/compilers.cjs +24 -10
- package/dist/cjs/compilers.cjs.map +1 -1
- package/dist/cjs/constants.cjs +10 -0
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/constants.d.cts +2 -0
- package/dist/cjs/debug.cjs +5 -0
- package/dist/cjs/debug.cjs.map +1 -0
- package/dist/cjs/debug.d.cts +1 -0
- package/dist/cjs/{extractHtmlScripts.cjs → dev-server-plugin/extract-html-scripts.cjs} +1 -1
- package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +1 -0
- package/dist/cjs/{nitro/dev-server-plugin.cjs → dev-server-plugin/plugin.cjs} +2 -2
- package/dist/cjs/dev-server-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.cjs +34 -0
- package/dist/cjs/load-env-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.d.cts +3 -0
- package/dist/cjs/{build-sitemap.cjs → nitro-plugin/build-sitemap.cjs} +12 -10
- package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +1 -0
- package/dist/cjs/{build-sitemap.d.cts → nitro-plugin/build-sitemap.d.cts} +2 -2
- package/dist/cjs/{nitro/nitro-plugin.cjs → nitro-plugin/plugin.cjs} +79 -65
- package/dist/cjs/nitro-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/{prerender.cjs → nitro-plugin/prerender.cjs} +18 -14
- package/dist/cjs/nitro-plugin/prerender.cjs.map +1 -0
- package/dist/cjs/{prerender.d.cts → nitro-plugin/prerender.d.cts} +1 -1
- package/dist/cjs/nitro-plugin/queue.cjs.map +1 -0
- package/dist/cjs/plugin.cjs +50 -38
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +14 -2657
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +66 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +3 -0
- package/dist/cjs/schema.cjs +5 -5
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +32 -16
- package/dist/cjs/start-compiler-plugin.cjs +21 -19
- package/dist/cjs/start-compiler-plugin.cjs.map +1 -1
- package/dist/cjs/start-compiler-plugin.d.cts +1 -1
- package/dist/cjs/start-manifest-plugin/plugin.cjs +182 -0
- package/dist/cjs/start-manifest-plugin/plugin.cjs.map +1 -0
- package/dist/{esm/routesManifestPlugin.d.ts → cjs/start-manifest-plugin/plugin.d.cts} +1 -1
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +39 -0
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +6 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +121 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +2 -0
- package/dist/cjs/start-router-plugin/plugin.cjs +21 -0
- package/dist/cjs/start-router-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/plugin.d.cts +3 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +72 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +6 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +30 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +4 -0
- package/dist/cjs/utils.cjs +11 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +7 -0
- package/dist/esm/compilers.js +24 -10
- package/dist/esm/compilers.js.map +1 -1
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/debug.d.ts +1 -0
- package/dist/esm/debug.js +5 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/{extractHtmlScripts.js → dev-server-plugin/extract-html-scripts.js} +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -0
- package/dist/esm/{nitro/dev-server-plugin.js → dev-server-plugin/plugin.js} +2 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -0
- package/dist/esm/load-env-plugin/plugin.d.ts +3 -0
- package/dist/esm/load-env-plugin/plugin.js +17 -0
- package/dist/esm/load-env-plugin/plugin.js.map +1 -0
- package/dist/esm/{build-sitemap.d.ts → nitro-plugin/build-sitemap.d.ts} +2 -2
- package/dist/esm/{build-sitemap.js → nitro-plugin/build-sitemap.js} +9 -7
- package/dist/esm/nitro-plugin/build-sitemap.js.map +1 -0
- package/dist/esm/nitro-plugin/plugin.js +181 -0
- package/dist/esm/nitro-plugin/plugin.js.map +1 -0
- package/dist/esm/{prerender.d.ts → nitro-plugin/prerender.d.ts} +1 -1
- package/dist/esm/{prerender.js → nitro-plugin/prerender.js} +15 -11
- package/dist/esm/nitro-plugin/prerender.js.map +1 -0
- package/dist/esm/nitro-plugin/queue.js.map +1 -0
- package/dist/esm/plugin.d.ts +14 -2657
- package/dist/esm/plugin.js +51 -39
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +3 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js +49 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +1 -0
- package/dist/esm/schema.d.ts +32 -16
- package/dist/esm/start-compiler-plugin.d.ts +1 -1
- package/dist/esm/start-compiler-plugin.js +21 -19
- package/dist/esm/start-compiler-plugin.js.map +1 -1
- package/dist/{cjs/routesManifestPlugin.d.cts → esm/start-manifest-plugin/plugin.d.ts} +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +182 -0
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +39 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +2 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +121 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/plugin.d.ts +3 -0
- package/dist/esm/start-router-plugin/plugin.js +21 -0
- package/dist/esm/start-router-plugin/plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +6 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +55 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +4 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +30 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -0
- package/dist/esm/utils.d.ts +7 -0
- package/dist/esm/utils.js +11 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/compilers.ts +31 -131
- package/src/constants.ts +10 -0
- package/src/debug.ts +3 -0
- package/src/{nitro/dev-server-plugin.ts → dev-server-plugin/plugin.ts} +11 -1
- package/src/global.d.ts +8 -0
- package/src/load-env-plugin/plugin.ts +17 -0
- package/src/{build-sitemap.ts → nitro-plugin/build-sitemap.ts} +11 -8
- package/src/nitro-plugin/plugin.ts +244 -0
- package/src/{prerender.ts → nitro-plugin/prerender.ts} +17 -13
- package/src/plugin.ts +63 -41
- package/src/resolve-virtual-entries-plugin/plugin.ts +63 -0
- package/src/start-compiler-plugin.ts +25 -25
- package/src/start-manifest-plugin/plugin.ts +249 -0
- package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +43 -0
- package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +138 -0
- package/src/start-router-plugin/plugin.ts +35 -0
- package/src/start-router-plugin/route-tree-client-plugin.ts +76 -0
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +30 -0
- package/src/utils.ts +11 -0
- package/dist/cjs/build-sitemap.cjs.map +0 -1
- package/dist/cjs/extractHtmlScripts.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.cjs +0 -18
- package/dist/cjs/nitro/build-nitro.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.d.cts +0 -2
- package/dist/cjs/nitro/dev-server-plugin.cjs.map +0 -1
- package/dist/cjs/nitro/nitro-plugin.cjs.map +0 -1
- package/dist/cjs/prerender.cjs.map +0 -1
- package/dist/cjs/queue.cjs.map +0 -1
- package/dist/cjs/routesManifestPlugin.cjs +0 -168
- package/dist/cjs/routesManifestPlugin.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/config.d.cts +0 -49
- package/dist/cjs/start-server-routes-plugin/plugin.cjs +0 -613
- package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/plugin.d.cts +0 -3
- package/dist/cjs/start-server-routes-plugin/template.cjs +0 -111
- package/dist/cjs/start-server-routes-plugin/template.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/template.d.cts +0 -34
- package/dist/esm/build-sitemap.js.map +0 -1
- package/dist/esm/extractHtmlScripts.js.map +0 -1
- package/dist/esm/nitro/build-nitro.d.ts +0 -2
- package/dist/esm/nitro/build-nitro.js +0 -18
- package/dist/esm/nitro/build-nitro.js.map +0 -1
- package/dist/esm/nitro/dev-server-plugin.js.map +0 -1
- package/dist/esm/nitro/nitro-plugin.js +0 -167
- package/dist/esm/nitro/nitro-plugin.js.map +0 -1
- package/dist/esm/prerender.js.map +0 -1
- package/dist/esm/queue.js.map +0 -1
- package/dist/esm/routesManifestPlugin.js +0 -168
- package/dist/esm/routesManifestPlugin.js.map +0 -1
- package/dist/esm/start-server-routes-plugin/config.d.ts +0 -49
- package/dist/esm/start-server-routes-plugin/plugin.d.ts +0 -3
- package/dist/esm/start-server-routes-plugin/plugin.js +0 -613
- package/dist/esm/start-server-routes-plugin/plugin.js.map +0 -1
- package/dist/esm/start-server-routes-plugin/template.d.ts +0 -34
- package/dist/esm/start-server-routes-plugin/template.js +0 -111
- package/dist/esm/start-server-routes-plugin/template.js.map +0 -1
- package/src/nitro/build-nitro.ts +0 -27
- package/src/nitro/nitro-plugin.ts +0 -195
- package/src/routesManifestPlugin.ts +0 -220
- package/src/start-server-routes-plugin/config.ts +0 -8
- package/src/start-server-routes-plugin/plugin.ts +0 -899
- package/src/start-server-routes-plugin/template.ts +0 -164
- /package/dist/cjs/{extractHtmlScripts.d.cts → dev-server-plugin/extract-html-scripts.d.cts} +0 -0
- /package/dist/cjs/{nitro/dev-server-plugin.d.cts → dev-server-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{nitro/nitro-plugin.d.cts → nitro-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{queue.cjs → nitro-plugin/queue.cjs} +0 -0
- /package/dist/cjs/{queue.d.cts → nitro-plugin/queue.d.cts} +0 -0
- /package/dist/esm/{extractHtmlScripts.d.ts → dev-server-plugin/extract-html-scripts.d.ts} +0 -0
- /package/dist/esm/{nitro/dev-server-plugin.d.ts → dev-server-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{nitro/nitro-plugin.d.ts → nitro-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{queue.d.ts → nitro-plugin/queue.d.ts} +0 -0
- /package/dist/esm/{queue.js → nitro-plugin/queue.js} +0 -0
- /package/src/{extractHtmlScripts.ts → dev-server-plugin/extract-html-scripts.ts} +0 -0
- /package/src/{queue.ts → nitro-plugin/queue.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routesManifestPlugin.cjs","sources":["../../src/routesManifestPlugin.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { joinURL } from 'ufo'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { resolveViteId } from './utils'\nimport type {\n PluginOption,\n ResolvedConfig,\n Manifest as ViteManifest,\n ManifestChunk as ViteManifestChunk,\n} from 'vite'\nimport type { Manifest, RouterManagedTag } from '@tanstack/router-core'\nimport type { TanStackStartOutputConfig } from './plugin'\n\nexport function startManifestPlugin(\n opts: TanStackStartOutputConfig,\n): PluginOption {\n let config: ResolvedConfig\n\n const moduleId = 'tanstack-start-router-manifest:v'\n const resolvedModuleId = resolveViteId(moduleId)\n\n return {\n name: 'tsr-routes-manifest',\n enforce: 'pre',\n\n configResolved(resolvedConfig) {\n config = resolvedConfig\n },\n // configEnvironment(env, envConfig) {\n // config = envConfig.\n // },\n resolveId(id) {\n if (id === moduleId) {\n return resolvedModuleId\n }\n return\n },\n load(id) {\n if (id === resolvedModuleId) {\n if (this.environment.config.consumer !== 'server') {\n // this will ultimately fail the build if the plugin is used outside the server environment\n // TODO: do we need special handling for `serve`?\n return `export default {}`\n }\n // If we're in development, return a dummy manifest\n\n if (config.command === 'serve') {\n return `export const tsrStartManifest = () => ({\n entry: \"$${process.env.TSS_CLIENT_BASE}/\",\n routes: {}\n })`\n }\n\n const clientViteManifestPath = path.resolve(\n opts.root,\n '.tanstack-start/build/client-dist/.vite/manifest.json',\n )\n\n let viteManifest: ViteManifest\n try {\n viteManifest = JSON.parse(\n readFileSync(clientViteManifestPath, 'utf-8'),\n )\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,\n )\n }\n\n const routeTreePath = path.resolve(opts.tsr.generatedRouteTree)\n\n let routeTreeContent: string\n try {\n routeTreeContent = readFileSync(routeTreePath, 'utf-8')\n } catch (err) {\n console.error(err)\n throw new Error(\n `Could not find the generated route tree at '${routeTreePath}'!`,\n )\n }\n\n // Extract the routesManifest JSON from the route tree file.\n // It's located between the /* ROUTE_MANIFEST_START and ROUTE_MANIFEST_END */ comment block.\n\n const routerManifest = JSON.parse(\n routeTreeContent.match(\n /\\/\\* ROUTE_MANIFEST_START([\\s\\S]*?)ROUTE_MANIFEST_END \\*\\//,\n )?.[1] || '{ routes: {} }',\n ) as Manifest\n\n const routes = routerManifest.routes\n\n let entryFile: ViteManifestChunk | undefined\n\n const filesByRouteFilePath: ViteManifest = Object.fromEntries(\n Object.entries(viteManifest).map(([k, v]) => {\n if (v.isEntry) {\n entryFile = v\n }\n\n const rPath = k.split('?')[0]\n\n return [rPath, v]\n }, {}),\n )\n\n const routesDirectoryFromRoot = path.relative(\n opts.root,\n opts.tsr.routesDirectory,\n )\n\n // Add preloads to the routes from the vite manifest\n Object.entries(routes).forEach(([k, v]) => {\n const file =\n filesByRouteFilePath[\n path.join(routesDirectoryFromRoot, v.filePath as string)\n ]\n\n if (file) {\n const preloads = (file.imports ?? []).map((d) =>\n path.join('/', viteManifest[d]!.file),\n )\n\n if (file.file) {\n preloads.unshift(path.join('/', file.file))\n }\n\n const cssFiles = file.css ?? []\n const cssAssetsList: Array<RouterManagedTag> = cssFiles.map(\n (cssFile) => ({\n tag: 'link',\n attrs: {\n rel: 'stylesheet',\n href: joinURL('/', cssFile),\n type: 'text/css',\n },\n }),\n )\n\n routes[k] = {\n ...v,\n assets: [...(v.assets || []), ...cssAssetsList],\n preloads,\n }\n }\n })\n\n if (entryFile) {\n routes[rootRouteId]!.preloads = [\n path.join('/', entryFile.file),\n ...(entryFile.imports?.map((d) =>\n path.join('/', viteManifest[d]!.file),\n ) || []),\n ]\n\n // Gather all the CSS files from the entry file in\n // the `css` key and add them to the root route\n const entryCssFiles = entryFile.css ?? []\n const entryCssAssetsList: Array<RouterManagedTag> = entryCssFiles.map(\n (cssFile) => ({\n tag: 'link',\n attrs: {\n rel: 'stylesheet',\n href: joinURL('/', cssFile),\n type: 'text/css',\n },\n }),\n )\n\n routes[rootRouteId]!.assets = [\n ...(routes[rootRouteId]!.assets || []),\n ...entryCssAssetsList,\n {\n tag: 'script',\n attrs: {\n src: joinURL('/', entryFile.file),\n type: 'module',\n },\n },\n ]\n }\n\n const recurseRoute = (\n route: {\n preloads?: Array<string>\n children?: Array<any>\n },\n seenPreloads = {} as Record<string, true>,\n ) => {\n route.preloads = route.preloads?.filter((preload) => {\n if (seenPreloads[preload]) {\n return false\n }\n seenPreloads[preload] = true\n return true\n })\n\n if (route.children) {\n route.children.forEach((child) => {\n const childRoute = routes[child]!\n recurseRoute(childRoute, { ...seenPreloads })\n })\n }\n }\n\n // @ts-expect-error\n recurseRoute(routes[rootRouteId])\n\n const routesManifest = {\n routes,\n }\n\n return `export const tsrStartManifest = () => (${JSON.stringify(routesManifest)})`\n }\n return\n },\n }\n}\n"],"names":["resolveViteId","readFileSync","joinURL","rootRouteId","_a"],"mappings":"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"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const configSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
3
|
-
target: z.ZodDefault<z.ZodOptional<z.ZodEnum<["react", "solid"]>>>;
|
|
4
|
-
virtualRouteConfig: z.ZodOptional<z.ZodUnion<[z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, z.ZodTypeDef, import('@tanstack/virtual-file-routes').VirtualRootRoute>, z.ZodString]>>;
|
|
5
|
-
routeFilePrefix: z.ZodOptional<z.ZodString>;
|
|
6
|
-
routeFileIgnorePrefix: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
7
|
-
routeFileIgnorePattern: z.ZodOptional<z.ZodString>;
|
|
8
|
-
routesDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
-
quoteStyle: z.ZodDefault<z.ZodOptional<z.ZodEnum<["single", "double"]>>>;
|
|
10
|
-
semicolons: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
11
|
-
disableLogging: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
12
|
-
routeTreeFileHeader: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
13
|
-
indexToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
14
|
-
routeToken: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
|
-
pathParamsAllowedCharacters: z.ZodOptional<z.ZodArray<z.ZodEnum<[";", ":", "@", "&", "=", "+", "$", ","]>, "many">>;
|
|
16
|
-
}, {
|
|
17
|
-
srcDirectory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
|
-
}>, "strip", z.ZodTypeAny, {
|
|
19
|
-
target: "react" | "solid";
|
|
20
|
-
routeFileIgnorePrefix: string;
|
|
21
|
-
routesDirectory: string;
|
|
22
|
-
quoteStyle: "single" | "double";
|
|
23
|
-
semicolons: boolean;
|
|
24
|
-
disableLogging: boolean;
|
|
25
|
-
routeTreeFileHeader: string[];
|
|
26
|
-
indexToken: string;
|
|
27
|
-
routeToken: string;
|
|
28
|
-
srcDirectory: string;
|
|
29
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
30
|
-
routeFilePrefix?: string | undefined;
|
|
31
|
-
routeFileIgnorePattern?: string | undefined;
|
|
32
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
target?: "react" | "solid" | undefined;
|
|
35
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
36
|
-
routeFilePrefix?: string | undefined;
|
|
37
|
-
routeFileIgnorePrefix?: string | undefined;
|
|
38
|
-
routeFileIgnorePattern?: string | undefined;
|
|
39
|
-
routesDirectory?: string | undefined;
|
|
40
|
-
quoteStyle?: "single" | "double" | undefined;
|
|
41
|
-
semicolons?: boolean | undefined;
|
|
42
|
-
disableLogging?: boolean | undefined;
|
|
43
|
-
routeTreeFileHeader?: string[] | undefined;
|
|
44
|
-
indexToken?: string | undefined;
|
|
45
|
-
routeToken?: string | undefined;
|
|
46
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
srcDirectory?: string | undefined;
|
|
48
|
-
}>;
|
|
49
|
-
export type Config = z.infer<typeof configSchema>;
|
|
@@ -1,613 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const path = require("node:path");
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const fsp = require("node:fs/promises");
|
|
6
|
-
const routerGenerator = require("@tanstack/router-generator");
|
|
7
|
-
const routerCore = require("@tanstack/router-core");
|
|
8
|
-
const template = require("./template.cjs");
|
|
9
|
-
let lock = false;
|
|
10
|
-
const checkLock = () => lock;
|
|
11
|
-
const setLock = (bool) => {
|
|
12
|
-
lock = bool;
|
|
13
|
-
};
|
|
14
|
-
function TanStackStartServerRoutesVite(config) {
|
|
15
|
-
let ROOT = process.cwd();
|
|
16
|
-
const moduleId = "tanstack-start-server-routes-manifest:v";
|
|
17
|
-
const getRoutesDirectoryPath = () => {
|
|
18
|
-
return path.isAbsolute(config.routesDirectory) ? config.routesDirectory : path.join(ROOT, config.routesDirectory);
|
|
19
|
-
};
|
|
20
|
-
const generate = async () => {
|
|
21
|
-
if (checkLock()) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
setLock(true);
|
|
25
|
-
try {
|
|
26
|
-
await generator(config, ROOT);
|
|
27
|
-
} catch (err) {
|
|
28
|
-
console.error(err);
|
|
29
|
-
console.info();
|
|
30
|
-
} finally {
|
|
31
|
-
setLock(false);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
const handleFile = async (file) => {
|
|
35
|
-
const filePath = path.normalize(file);
|
|
36
|
-
const routesDirectoryPath = getRoutesDirectoryPath();
|
|
37
|
-
if (filePath.startsWith(routesDirectoryPath)) {
|
|
38
|
-
await generate();
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
name: "tanstack-start-server-routes-plugin",
|
|
43
|
-
configureServer(server) {
|
|
44
|
-
server.watcher.on("all", (event, path2) => {
|
|
45
|
-
handleFile(path2);
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
configResolved(config2) {
|
|
49
|
-
ROOT = config2.root;
|
|
50
|
-
},
|
|
51
|
-
async buildStart() {
|
|
52
|
-
await generate();
|
|
53
|
-
},
|
|
54
|
-
sharedDuringBuild: true,
|
|
55
|
-
resolveId(id) {
|
|
56
|
-
if (id === moduleId) {
|
|
57
|
-
const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT);
|
|
58
|
-
return generatedRouteTreePath;
|
|
59
|
-
}
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
let latestTask = 0;
|
|
65
|
-
const routeGroupPatternRegex = /\(.+\)/g;
|
|
66
|
-
const possiblyNestedRouteGroupPatternRegex = /\([^/]+\)\/?/g;
|
|
67
|
-
function getGeneratedRouteTreePath(root) {
|
|
68
|
-
return path.resolve(root, ".tanstack-start/server-routes/routeTree.gen.ts");
|
|
69
|
-
}
|
|
70
|
-
async function generator(config, root) {
|
|
71
|
-
const generatedServerRouteTreePath = getGeneratedRouteTreePath(root);
|
|
72
|
-
const ROUTE_TEMPLATE = template.getTargetTemplate(config.target);
|
|
73
|
-
const logger = routerGenerator.logging({ disabled: config.disableLogging });
|
|
74
|
-
const taskId = latestTask + 1;
|
|
75
|
-
latestTask = taskId;
|
|
76
|
-
const checkLatest = () => {
|
|
77
|
-
if (latestTask !== taskId) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
};
|
|
82
|
-
let getRouteNodesResult;
|
|
83
|
-
if (config.virtualRouteConfig) {
|
|
84
|
-
getRouteNodesResult = await routerGenerator.virtualGetRouteNodes(config, root);
|
|
85
|
-
} else {
|
|
86
|
-
getRouteNodesResult = await routerGenerator.physicalGetRouteNodes(config, root);
|
|
87
|
-
}
|
|
88
|
-
const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult;
|
|
89
|
-
if (rootRouteNode === void 0) {
|
|
90
|
-
let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`;
|
|
91
|
-
if (!config.virtualRouteConfig) {
|
|
92
|
-
errorMessage += `
|
|
93
|
-
Make sure that you add a "${routerGenerator.rootPathId}.tsx" file to your routes directory.
|
|
94
|
-
Add the file in: "${config.routesDirectory}/${routerGenerator.rootPathId}.tsx"`;
|
|
95
|
-
}
|
|
96
|
-
throw new Error(errorMessage);
|
|
97
|
-
}
|
|
98
|
-
const preRouteNodes = routerGenerator.multiSortBy(beforeRouteNodes, [
|
|
99
|
-
(d) => d.routePath === "/" ? -1 : 1,
|
|
100
|
-
(d) => {
|
|
101
|
-
var _a;
|
|
102
|
-
return (_a = d.routePath) == null ? void 0 : _a.split("/").length;
|
|
103
|
-
},
|
|
104
|
-
(d) => d.filePath.match(new RegExp(`[./]${config.indexToken}[.]`)) ? 1 : -1,
|
|
105
|
-
(d) => d.filePath.match(
|
|
106
|
-
/[./](component|errorComponent|pendingComponent|loader|lazy)[.]/
|
|
107
|
-
) ? 1 : -1,
|
|
108
|
-
(d) => d.filePath.match(new RegExp(`[./]${config.routeToken}[.]`)) ? -1 : 1,
|
|
109
|
-
(d) => {
|
|
110
|
-
var _a;
|
|
111
|
-
return ((_a = d.routePath) == null ? void 0 : _a.endsWith("/")) ? -1 : 1;
|
|
112
|
-
},
|
|
113
|
-
(d) => d.routePath
|
|
114
|
-
]).filter((d) => ![`/${routerGenerator.rootPathId}`].includes(d.routePath || ""));
|
|
115
|
-
const routeTree = [];
|
|
116
|
-
const routeNodes = [];
|
|
117
|
-
const handleRootNode = async (node) => {
|
|
118
|
-
if (!node) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const routeCode = fs.readFileSync(node.fullPath, "utf-8");
|
|
122
|
-
if (!routeCode) {
|
|
123
|
-
const _rootTemplate = ROUTE_TEMPLATE.rootRoute;
|
|
124
|
-
const replaced = await template.fillTemplate(config, _rootTemplate.template(), {
|
|
125
|
-
tsrImports: _rootTemplate.imports.tsrImports(),
|
|
126
|
-
tsrPath: routerGenerator.rootPathId,
|
|
127
|
-
tsrExportStart: _rootTemplate.imports.tsrExportStart(),
|
|
128
|
-
tsrExportEnd: _rootTemplate.imports.tsrExportEnd()
|
|
129
|
-
});
|
|
130
|
-
await routerGenerator.writeIfDifferent(
|
|
131
|
-
node.fullPath,
|
|
132
|
-
"",
|
|
133
|
-
// Empty string because the file doesn't exist yet
|
|
134
|
-
replaced,
|
|
135
|
-
{
|
|
136
|
-
beforeWrite: () => {
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
await handleRootNode(rootRouteNode);
|
|
143
|
-
const handleNode = async (node) => {
|
|
144
|
-
var _a;
|
|
145
|
-
routerGenerator.resetRegex(routeGroupPatternRegex);
|
|
146
|
-
let parentRoute = hasParentRoute(routeNodes, node, node.routePath);
|
|
147
|
-
if ((parentRoute == null ? void 0 : parentRoute.isVirtualParentRoute) && ((_a = parentRoute.children) == null ? void 0 : _a.length)) {
|
|
148
|
-
const possibleParentRoute = hasParentRoute(
|
|
149
|
-
parentRoute.children,
|
|
150
|
-
node,
|
|
151
|
-
node.routePath
|
|
152
|
-
);
|
|
153
|
-
if (possibleParentRoute) {
|
|
154
|
-
parentRoute = possibleParentRoute;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (parentRoute) node.parent = parentRoute;
|
|
158
|
-
node.path = determineNodePath(node);
|
|
159
|
-
const trimmedPath = routerGenerator.trimPathLeft(node.path ?? "");
|
|
160
|
-
const split = trimmedPath.split("/");
|
|
161
|
-
const lastRouteSegment = split[split.length - 1] ?? trimmedPath;
|
|
162
|
-
node.isNonPath = lastRouteSegment.startsWith("_") || routeGroupPatternRegex.test(lastRouteSegment);
|
|
163
|
-
node.cleanedPath = removeGroups(
|
|
164
|
-
routerGenerator.removeUnderscores(removeLayoutSegments(node.path)) ?? ""
|
|
165
|
-
);
|
|
166
|
-
const routeCode = node.fullPath ? fs.readFileSync(node.fullPath, "utf-8") : "";
|
|
167
|
-
if (!node.isVirtualParentRoute && !node.isVirtual) ;
|
|
168
|
-
const cleanedPathIsEmpty = (node.cleanedPath || "").length === 0;
|
|
169
|
-
const nonPathRoute = node._fsRouteType === "pathless_layout" && node.isNonPath;
|
|
170
|
-
node.isVirtualParentRequired = node._fsRouteType === "pathless_layout" || nonPathRoute ? !cleanedPathIsEmpty : false;
|
|
171
|
-
if (!node.isVirtual && node.isVirtualParentRequired) {
|
|
172
|
-
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || "/";
|
|
173
|
-
const parentVariableName = routerGenerator.routePathToVariable(parentRoutePath);
|
|
174
|
-
const anchorRoute = routeNodes.find(
|
|
175
|
-
(d) => d.routePath === parentRoutePath
|
|
176
|
-
);
|
|
177
|
-
if (!anchorRoute) {
|
|
178
|
-
const parentNode = {
|
|
179
|
-
...node,
|
|
180
|
-
path: removeLastSegmentFromPath(node.path) || "/",
|
|
181
|
-
filePath: removeLastSegmentFromPath(node.filePath) || "/",
|
|
182
|
-
fullPath: removeLastSegmentFromPath(node.fullPath) || "/",
|
|
183
|
-
routePath: parentRoutePath,
|
|
184
|
-
variableName: parentVariableName,
|
|
185
|
-
isVirtual: true,
|
|
186
|
-
_fsRouteType: "layout",
|
|
187
|
-
// layout since this route will wrap other routes
|
|
188
|
-
isVirtualParentRoute: true,
|
|
189
|
-
isVirtualParentRequired: false
|
|
190
|
-
};
|
|
191
|
-
parentNode.children = parentNode.children ?? [];
|
|
192
|
-
parentNode.children.push(node);
|
|
193
|
-
node.parent = parentNode;
|
|
194
|
-
if (node._fsRouteType === "pathless_layout") {
|
|
195
|
-
node.path = determineNodePath(node);
|
|
196
|
-
}
|
|
197
|
-
await handleNode(parentNode);
|
|
198
|
-
} else {
|
|
199
|
-
anchorRoute.children = anchorRoute.children ?? [];
|
|
200
|
-
anchorRoute.children.push(node);
|
|
201
|
-
node.parent = anchorRoute;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (!routeCode.split("\n").some((line) => line.trim().startsWith("export const ServerRoute"))) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (node.parent) {
|
|
208
|
-
if (!node.isVirtualParentRequired) {
|
|
209
|
-
node.parent.children = node.parent.children ?? [];
|
|
210
|
-
node.parent.children.push(node);
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
routeTree.push(node);
|
|
214
|
-
}
|
|
215
|
-
routeNodes.push(node);
|
|
216
|
-
};
|
|
217
|
-
for (const node of preRouteNodes) {
|
|
218
|
-
await handleNode(node);
|
|
219
|
-
}
|
|
220
|
-
checkRouteFullPathUniqueness(routeNodes, config);
|
|
221
|
-
function buildRouteTreeConfig(nodes, depth = 1) {
|
|
222
|
-
const children = nodes.map((node) => {
|
|
223
|
-
var _a, _b;
|
|
224
|
-
if (node._fsRouteType === "__root") {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (node._fsRouteType === "pathless_layout" && !((_a = node.children) == null ? void 0 : _a.length)) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
const route = `${node.variableName}Route`;
|
|
231
|
-
if ((_b = node.children) == null ? void 0 : _b.length) {
|
|
232
|
-
const childConfigs = buildRouteTreeConfig(node.children, depth + 1);
|
|
233
|
-
const childrenDeclaration = `interface ${route}Children {
|
|
234
|
-
${node.children.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(",")}
|
|
235
|
-
}`;
|
|
236
|
-
const children2 = `const ${route}Children: ${route}Children = {
|
|
237
|
-
${node.children.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(",")}
|
|
238
|
-
}`;
|
|
239
|
-
const routeWithChildren = `const ${route}WithChildren = ${route}._addFileChildren(${route}Children)`;
|
|
240
|
-
return [
|
|
241
|
-
childConfigs,
|
|
242
|
-
childrenDeclaration,
|
|
243
|
-
children2,
|
|
244
|
-
routeWithChildren
|
|
245
|
-
].join("\n\n");
|
|
246
|
-
}
|
|
247
|
-
return void 0;
|
|
248
|
-
});
|
|
249
|
-
return children.filter(Boolean).join("\n\n");
|
|
250
|
-
}
|
|
251
|
-
const routeConfigChildrenText = buildRouteTreeConfig(routeTree);
|
|
252
|
-
const sortedRouteNodes = routerGenerator.multiSortBy(routeNodes, [
|
|
253
|
-
(d) => {
|
|
254
|
-
var _a;
|
|
255
|
-
return ((_a = d.routePath) == null ? void 0 : _a.includes(`/${routerGenerator.rootPathId}`)) ? -1 : 1;
|
|
256
|
-
},
|
|
257
|
-
(d) => {
|
|
258
|
-
var _a;
|
|
259
|
-
return (_a = d.routePath) == null ? void 0 : _a.split("/").length;
|
|
260
|
-
},
|
|
261
|
-
(d) => {
|
|
262
|
-
var _a;
|
|
263
|
-
return ((_a = d.routePath) == null ? void 0 : _a.endsWith(config.indexToken)) ? -1 : 1;
|
|
264
|
-
},
|
|
265
|
-
(d) => d
|
|
266
|
-
]);
|
|
267
|
-
const imports = Object.entries({
|
|
268
|
-
createFileRoute: sortedRouteNodes.some((d) => d.isVirtual)
|
|
269
|
-
}).filter((d) => d[1]).map((d) => d[0]);
|
|
270
|
-
const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual);
|
|
271
|
-
function getImportPath(node) {
|
|
272
|
-
return routerGenerator.replaceBackslash(
|
|
273
|
-
routerGenerator.removeExt(
|
|
274
|
-
path.relative(
|
|
275
|
-
path.dirname(generatedServerRouteTreePath),
|
|
276
|
-
path.resolve(config.routesDirectory, node.filePath)
|
|
277
|
-
)
|
|
278
|
-
)
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
const rootRouteExists = fs.existsSync(rootRouteNode.fullPath);
|
|
282
|
-
const rootRouteCode = rootRouteExists ? fs.readFileSync(rootRouteNode.fullPath, "utf-8") : "";
|
|
283
|
-
const hasServerRootRoute = rootRouteExists && rootRouteCode.includes("export const ServerRoute");
|
|
284
|
-
const routeImports = [
|
|
285
|
-
...config.routeTreeFileHeader,
|
|
286
|
-
`// This file was automatically generated by TanStack Router.
|
|
287
|
-
// You should NOT make any changes in this file as it will be overwritten.
|
|
288
|
-
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,
|
|
289
|
-
imports.length ? `import { ${imports.join(", ")} } from '${ROUTE_TEMPLATE.fullPkg}'
|
|
290
|
-
` : "",
|
|
291
|
-
"// Import Routes",
|
|
292
|
-
[
|
|
293
|
-
`import type { FileRoutesByPath, CreateServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,
|
|
294
|
-
`import { createServerRoute, createServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,
|
|
295
|
-
hasServerRootRoute ? `import { ServerRoute as rootRouteImport } from './${getImportPath(rootRouteNode)}'` : "",
|
|
296
|
-
...sortedRouteNodes.filter((d) => !d.isVirtual).map((node) => {
|
|
297
|
-
return `import { ServerRoute as ${node.variableName}RouteImport } from './${getImportPath(node)}'`;
|
|
298
|
-
})
|
|
299
|
-
].join("\n"),
|
|
300
|
-
virtualRouteNodes.length ? "// Create Virtual Routes" : "",
|
|
301
|
-
virtualRouteNodes.map((node) => {
|
|
302
|
-
return `const ${node.variableName}RouteImport = createFileRoute('${node.routePath}')()`;
|
|
303
|
-
}).join("\n"),
|
|
304
|
-
"// Create/Update Routes",
|
|
305
|
-
!hasServerRootRoute ? `
|
|
306
|
-
const rootRoute = createServerRoute()
|
|
307
|
-
` : "",
|
|
308
|
-
sortedRouteNodes.map((node) => {
|
|
309
|
-
var _a;
|
|
310
|
-
return [
|
|
311
|
-
[
|
|
312
|
-
`const ${node.variableName}Route = ${node.variableName}RouteImport.update({
|
|
313
|
-
${[
|
|
314
|
-
`id: '${node.path}'`,
|
|
315
|
-
!node.isNonPath ? `path: '${node.cleanedPath}'` : void 0,
|
|
316
|
-
`getParentRoute: () => ${((_a = node.parent) == null ? void 0 : _a.variableName) ?? "root"}Route`
|
|
317
|
-
].filter(Boolean).join(",")}
|
|
318
|
-
} as any)`
|
|
319
|
-
].join("")
|
|
320
|
-
].join("\n\n");
|
|
321
|
-
}).join("\n\n"),
|
|
322
|
-
"",
|
|
323
|
-
"// Populate the FileRoutesByPath interface",
|
|
324
|
-
`declare module '${ROUTE_TEMPLATE.fullPkg}' {
|
|
325
|
-
interface FileRoutesByPath {
|
|
326
|
-
${routeNodes.map((routeNode) => {
|
|
327
|
-
var _a, _b;
|
|
328
|
-
const filePathId = routeNode.routePath;
|
|
329
|
-
return `'${filePathId}': {
|
|
330
|
-
id: '${filePathId}'
|
|
331
|
-
path: '${inferPath(routeNode)}'
|
|
332
|
-
fullPath: '${inferFullPath(routeNode)}'
|
|
333
|
-
preLoaderRoute: typeof ${routeNode.variableName}RouteImport
|
|
334
|
-
parentRoute: typeof ${routeNode.isVirtualParentRequired ? `${(_a = routeNode.parent) == null ? void 0 : _a.variableName}Route` : ((_b = routeNode.parent) == null ? void 0 : _b.variableName) ? `${routeNode.parent.variableName}RouteImport` : "rootRoute"}
|
|
335
|
-
}`;
|
|
336
|
-
}).join("\n")}
|
|
337
|
-
}
|
|
338
|
-
}`,
|
|
339
|
-
`// Add type-safety to the createFileRoute function across the route tree`,
|
|
340
|
-
routeNodes.map((routeNode) => {
|
|
341
|
-
var _a;
|
|
342
|
-
return `declare module './${getImportPath(routeNode)}' {
|
|
343
|
-
const createServerFileRoute: CreateServerFileRoute<
|
|
344
|
-
FileRoutesByPath['${routeNode.routePath}']['parentRoute'],
|
|
345
|
-
FileRoutesByPath['${routeNode.routePath}']['id'],
|
|
346
|
-
FileRoutesByPath['${routeNode.routePath}']['path'],
|
|
347
|
-
FileRoutesByPath['${routeNode.routePath}']['fullPath'],
|
|
348
|
-
${((_a = routeNode.children) == null ? void 0 : _a.length) ? `${routeNode.variableName}RouteChildren` : "unknown"}
|
|
349
|
-
>
|
|
350
|
-
}`;
|
|
351
|
-
}).join("\n"),
|
|
352
|
-
"// Create and export the route tree",
|
|
353
|
-
routeConfigChildrenText,
|
|
354
|
-
`export interface FileRoutesByFullPath {
|
|
355
|
-
${[...createRouteNodesByFullPath(routeNodes).entries()].map(
|
|
356
|
-
([fullPath, routeNode]) => {
|
|
357
|
-
return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
358
|
-
}
|
|
359
|
-
)}
|
|
360
|
-
}`,
|
|
361
|
-
`export interface FileRoutesByTo {
|
|
362
|
-
${[...createRouteNodesByTo(routeNodes).entries()].map(([to, routeNode]) => {
|
|
363
|
-
return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
364
|
-
})}
|
|
365
|
-
}`,
|
|
366
|
-
`export interface FileRoutesById {
|
|
367
|
-
'${routerCore.rootRouteId}': typeof rootRoute,
|
|
368
|
-
${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {
|
|
369
|
-
return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`;
|
|
370
|
-
})}
|
|
371
|
-
}`,
|
|
372
|
-
`export interface FileRouteTypes {
|
|
373
|
-
fileRoutesByFullPath: FileRoutesByFullPath
|
|
374
|
-
fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join("|") : "never"}
|
|
375
|
-
fileRoutesByTo: FileRoutesByTo
|
|
376
|
-
to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join("|") : "never"}
|
|
377
|
-
id: ${[`'${routerCore.rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join("|")}
|
|
378
|
-
fileRoutesById: FileRoutesById
|
|
379
|
-
}`,
|
|
380
|
-
`export interface RootRouteChildren {
|
|
381
|
-
${routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(",")}
|
|
382
|
-
}`,
|
|
383
|
-
`const rootRouteChildren: RootRouteChildren = {
|
|
384
|
-
${routeTree.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(",")}
|
|
385
|
-
}`,
|
|
386
|
-
`export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileTypes<FileRouteTypes>()`
|
|
387
|
-
].filter(Boolean).join("\n\n");
|
|
388
|
-
const createRouteManifest = () => {
|
|
389
|
-
const routesManifest = {
|
|
390
|
-
[routerCore.rootRouteId]: {
|
|
391
|
-
filePath: rootRouteNode.filePath,
|
|
392
|
-
children: routeTree.map((d) => d.routePath)
|
|
393
|
-
},
|
|
394
|
-
...Object.fromEntries(
|
|
395
|
-
routeNodes.map((d) => {
|
|
396
|
-
var _a, _b;
|
|
397
|
-
const filePathId = d.routePath;
|
|
398
|
-
return [
|
|
399
|
-
filePathId,
|
|
400
|
-
{
|
|
401
|
-
filePath: d.filePath,
|
|
402
|
-
parent: ((_a = d.parent) == null ? void 0 : _a.routePath) ? d.parent.routePath : void 0,
|
|
403
|
-
children: (_b = d.children) == null ? void 0 : _b.map((childRoute) => childRoute.routePath)
|
|
404
|
-
}
|
|
405
|
-
];
|
|
406
|
-
})
|
|
407
|
-
)
|
|
408
|
-
};
|
|
409
|
-
return JSON.stringify(
|
|
410
|
-
{
|
|
411
|
-
routes: routesManifest
|
|
412
|
-
},
|
|
413
|
-
null,
|
|
414
|
-
2
|
|
415
|
-
);
|
|
416
|
-
};
|
|
417
|
-
const includeManifest = ["react", "solid"];
|
|
418
|
-
const routeConfigFileContent = !includeManifest.includes(config.target) ? routeImports : [
|
|
419
|
-
routeImports,
|
|
420
|
-
"\n",
|
|
421
|
-
"/* ROUTE_MANIFEST_START",
|
|
422
|
-
createRouteManifest(),
|
|
423
|
-
"ROUTE_MANIFEST_END */"
|
|
424
|
-
].join("\n");
|
|
425
|
-
if (!checkLatest()) return;
|
|
426
|
-
const existingRouteTreeContent = await fsp.readFile(path.resolve(generatedServerRouteTreePath), "utf-8").catch((err) => {
|
|
427
|
-
if (err.code === "ENOENT") {
|
|
428
|
-
return "";
|
|
429
|
-
}
|
|
430
|
-
throw err;
|
|
431
|
-
});
|
|
432
|
-
if (!checkLatest()) return;
|
|
433
|
-
await fsp.mkdir(path.dirname(path.resolve(generatedServerRouteTreePath)), {
|
|
434
|
-
recursive: true
|
|
435
|
-
});
|
|
436
|
-
if (!checkLatest()) return;
|
|
437
|
-
const routeTreeWriteResult = await routerGenerator.writeIfDifferent(
|
|
438
|
-
path.resolve(generatedServerRouteTreePath),
|
|
439
|
-
await routerGenerator.format(existingRouteTreeContent, config),
|
|
440
|
-
await routerGenerator.format(routeConfigFileContent, config),
|
|
441
|
-
{
|
|
442
|
-
beforeWrite: () => {
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
);
|
|
446
|
-
const startDeclarationFilePath = path.join(
|
|
447
|
-
path.resolve(root, config.srcDirectory),
|
|
448
|
-
"tanstack-start.d.ts"
|
|
449
|
-
);
|
|
450
|
-
const serverRoutesRelativePath = routerGenerator.removeExt(
|
|
451
|
-
path.relative(
|
|
452
|
-
path.dirname(startDeclarationFilePath),
|
|
453
|
-
generatedServerRouteTreePath
|
|
454
|
-
)
|
|
455
|
-
);
|
|
456
|
-
const startDeclarationFileContent = buildStartDeclarationFile({
|
|
457
|
-
serverRoutesRelativePath
|
|
458
|
-
});
|
|
459
|
-
if (!fs.existsSync(startDeclarationFilePath)) {
|
|
460
|
-
await routerGenerator.writeIfDifferent(
|
|
461
|
-
startDeclarationFilePath,
|
|
462
|
-
"",
|
|
463
|
-
startDeclarationFileContent,
|
|
464
|
-
{
|
|
465
|
-
beforeWrite: () => {
|
|
466
|
-
logger.log(`🟡 Creating tanstack-start.d.ts`);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
);
|
|
470
|
-
} else {
|
|
471
|
-
const existingDeclarationFileContent = await fsp.readFile(startDeclarationFilePath, "utf-8").catch((err) => {
|
|
472
|
-
if (err.code === "ENOENT") {
|
|
473
|
-
return "";
|
|
474
|
-
}
|
|
475
|
-
throw err;
|
|
476
|
-
});
|
|
477
|
-
await routerGenerator.writeIfDifferent(
|
|
478
|
-
startDeclarationFilePath,
|
|
479
|
-
existingDeclarationFileContent,
|
|
480
|
-
startDeclarationFileContent,
|
|
481
|
-
{
|
|
482
|
-
beforeWrite: () => {
|
|
483
|
-
logger.log(`🟡 Updating tanstack-start.d.ts`);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
if (routeTreeWriteResult && !checkLatest()) {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function buildStartDeclarationFile({
|
|
493
|
-
serverRoutesRelativePath
|
|
494
|
-
}) {
|
|
495
|
-
const serverRoutesPath = routerGenerator.replaceBackslash(serverRoutesRelativePath);
|
|
496
|
-
return [
|
|
497
|
-
'/// <reference types="vite/client" />',
|
|
498
|
-
`import '${serverRoutesPath}'`
|
|
499
|
-
].join("\n") + "\n";
|
|
500
|
-
}
|
|
501
|
-
function removeGroups(s) {
|
|
502
|
-
return s.replace(possiblyNestedRouteGroupPatternRegex, "");
|
|
503
|
-
}
|
|
504
|
-
function determineNodePath(node) {
|
|
505
|
-
var _a;
|
|
506
|
-
return node.path = node.parent ? ((_a = node.routePath) == null ? void 0 : _a.replace(node.parent.routePath ?? "", "")) || "/" : node.routePath;
|
|
507
|
-
}
|
|
508
|
-
function removeLastSegmentFromPath(routePath = "/") {
|
|
509
|
-
const segments = routePath.split("/");
|
|
510
|
-
segments.pop();
|
|
511
|
-
return segments.join("/");
|
|
512
|
-
}
|
|
513
|
-
function removeLayoutSegments(routePath = "/") {
|
|
514
|
-
const segments = routePath.split("/");
|
|
515
|
-
const newSegments = segments.filter((segment) => !segment.startsWith("_"));
|
|
516
|
-
return newSegments.join("/");
|
|
517
|
-
}
|
|
518
|
-
function hasParentRoute(routes, node, routePathToCheck) {
|
|
519
|
-
if (!routePathToCheck || routePathToCheck === "/") {
|
|
520
|
-
return null;
|
|
521
|
-
}
|
|
522
|
-
const sortedNodes = routerGenerator.multiSortBy(routes, [
|
|
523
|
-
(d) => d.routePath.length * -1,
|
|
524
|
-
(d) => d.variableName
|
|
525
|
-
]).filter((d) => d.routePath !== `/${routerGenerator.rootPathId}`);
|
|
526
|
-
for (const route of sortedNodes) {
|
|
527
|
-
if (route.routePath === "/") continue;
|
|
528
|
-
if (routePathToCheck.startsWith(`${route.routePath}/`) && route.routePath !== routePathToCheck) {
|
|
529
|
-
return route;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
const segments = routePathToCheck.split("/");
|
|
533
|
-
segments.pop();
|
|
534
|
-
const parentRoutePath = segments.join("/");
|
|
535
|
-
return hasParentRoute(routes, node, parentRoutePath);
|
|
536
|
-
}
|
|
537
|
-
const getResolvedRouteNodeVariableName = (routeNode) => {
|
|
538
|
-
var _a;
|
|
539
|
-
return ((_a = routeNode.children) == null ? void 0 : _a.length) ? `${routeNode.variableName}RouteWithChildren` : `${routeNode.variableName}Route`;
|
|
540
|
-
};
|
|
541
|
-
const createRouteNodesByFullPath = (routeNodes) => {
|
|
542
|
-
return new Map(
|
|
543
|
-
routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode])
|
|
544
|
-
);
|
|
545
|
-
};
|
|
546
|
-
const createRouteNodesByTo = (routeNodes) => {
|
|
547
|
-
return new Map(
|
|
548
|
-
dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [
|
|
549
|
-
inferTo(routeNode),
|
|
550
|
-
routeNode
|
|
551
|
-
])
|
|
552
|
-
);
|
|
553
|
-
};
|
|
554
|
-
const createRouteNodesById = (routeNodes) => {
|
|
555
|
-
return new Map(
|
|
556
|
-
routeNodes.map((routeNode) => {
|
|
557
|
-
const id = routeNode.routePath ?? "";
|
|
558
|
-
return [id, routeNode];
|
|
559
|
-
})
|
|
560
|
-
);
|
|
561
|
-
};
|
|
562
|
-
const inferFullPath = (routeNode) => {
|
|
563
|
-
const fullPath = removeGroups(
|
|
564
|
-
routerGenerator.removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? ""
|
|
565
|
-
);
|
|
566
|
-
return routeNode.cleanedPath === "/" ? fullPath : fullPath.replace(/\/$/, "");
|
|
567
|
-
};
|
|
568
|
-
const inferPath = (routeNode) => {
|
|
569
|
-
var _a;
|
|
570
|
-
return routeNode.cleanedPath === "/" ? routeNode.cleanedPath : ((_a = routeNode.cleanedPath) == null ? void 0 : _a.replace(/\/$/, "")) ?? "";
|
|
571
|
-
};
|
|
572
|
-
const inferTo = (routeNode) => {
|
|
573
|
-
const fullPath = inferFullPath(routeNode);
|
|
574
|
-
if (fullPath === "/") return fullPath;
|
|
575
|
-
return fullPath.replace(/\/$/, "");
|
|
576
|
-
};
|
|
577
|
-
const dedupeBranchesAndIndexRoutes = (routes) => {
|
|
578
|
-
return routes.filter((route) => {
|
|
579
|
-
var _a;
|
|
580
|
-
if ((_a = route.children) == null ? void 0 : _a.find((child) => child.cleanedPath === "/")) return false;
|
|
581
|
-
return true;
|
|
582
|
-
});
|
|
583
|
-
};
|
|
584
|
-
function checkUnique(routes, key) {
|
|
585
|
-
const keys = routes.map((d) => d[key]);
|
|
586
|
-
const uniqueKeys = new Set(keys);
|
|
587
|
-
if (keys.length !== uniqueKeys.size) {
|
|
588
|
-
const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i);
|
|
589
|
-
const conflictingFiles = routes.filter(
|
|
590
|
-
(d) => duplicateKeys.includes(d[key])
|
|
591
|
-
);
|
|
592
|
-
return conflictingFiles;
|
|
593
|
-
}
|
|
594
|
-
return void 0;
|
|
595
|
-
}
|
|
596
|
-
function checkRouteFullPathUniqueness(_routes, config) {
|
|
597
|
-
const routes = _routes.map((d) => {
|
|
598
|
-
const inferredFullPath = inferFullPath(d);
|
|
599
|
-
return { ...d, inferredFullPath };
|
|
600
|
-
});
|
|
601
|
-
const conflictingFiles = checkUnique(routes, "inferredFullPath");
|
|
602
|
-
if (conflictingFiles !== void 0) {
|
|
603
|
-
const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? "s" : ""}: ${conflictingFiles.map((p) => `"${p.inferredFullPath}"`).join(", ")}.
|
|
604
|
-
Please ensure each Server Route has a unique full path.
|
|
605
|
-
Conflicting files:
|
|
606
|
-
${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join("\n ")}
|
|
607
|
-
`;
|
|
608
|
-
console.error(errorMessage);
|
|
609
|
-
process.exit(1);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
exports.TanStackStartServerRoutesVite = TanStackStartServerRoutesVite;
|
|
613
|
-
//# sourceMappingURL=plugin.cjs.map
|