@tanstack/start-plugin-core 1.121.0-alpha.6 → 1.121.0-alpha.7

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.
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schema = require("./schema.cjs");
4
4
  const plugin = require("./plugin.cjs");
5
+ const utils = require("./utils.cjs");
5
6
  exports.createTanStackConfig = schema.createTanStackConfig;
6
7
  exports.createTanStackStartOptionsSchema = schema.createTanStackStartOptionsSchema;
7
8
  exports.pageSchema = schema.pageSchema;
8
9
  exports.TanStackStartVitePluginCore = plugin.TanStackStartVitePluginCore;
10
+ exports.resolveViteId = utils.resolveViteId;
9
11
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -1,2 +1,3 @@
1
1
  export { createTanStackConfig, createTanStackStartOptionsSchema, pageSchema, } from './schema.cjs';
2
2
  export { TanStackStartVitePluginCore } from './plugin.cjs';
3
+ export { resolveViteId } from './utils.cjs';
@@ -119,8 +119,8 @@ function TanStackStartVitePluginCore(opts, startConfig) {
119
119
  "@tanstack/start-router-manifest",
120
120
  "@tanstack/start-config",
121
121
  "@tanstack/server-functions-plugin",
122
- "tanstack:start-manifest",
123
- "tanstack:server-fn-manifest",
122
+ "tanstack-start-router-manifest:v",
123
+ "tanstack-start-server-fn-manifest:v",
124
124
  "nitropack",
125
125
  "@tanstack/**"
126
126
  ]
@@ -145,7 +145,7 @@ function TanStackStartVitePluginCore(opts, startConfig) {
145
145
  serverFunctionsPlugin.TanStackServerFnPluginEnv({
146
146
  // This is the ID that will be available to look up and import
147
147
  // our server function manifest and resolve its module
148
- manifestVirtualImportId: "tanstack:server-fn-manifest",
148
+ manifestVirtualImportId: "tanstack-start-server-fn-manifest:v",
149
149
  client: {
150
150
  getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
151
151
  replacer: (d) => `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config-client',\n async config() {\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n )\n\n return entry\n }\n\n return {\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack:start-manifest',\n 'tanstack:server-fn-manifest',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n /* prettier-ignore */\n define: {\n ...injectDefineEnv('TSS_PUBLIC_BASE', startConfig.public.base),\n ...injectDefineEnv('TSS_CLIENT_BASE', startConfig.client.base),\n ...injectDefineEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...injectDefineEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...injectDefineEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n TanStackStartCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack:server-fn-manifest',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n startManifestPlugin(startConfig),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction injectDefineEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["createTanStackStartOptionsSchema","createTanStackConfig","tanstackRouter","createNitro","nitroOutputPublicDir","startConfig","vite","VITE_ENVIRONMENT_NAMES","TanStackStartCompilerPlugin","TanStackServerFnPluginEnv","startManifestPlugin","nitroPlugin","TanStackStartServerRoutesVite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBmCA,OAAiC,iCAAA;AAK9CC,OAAqB,qBAAA;AASpC,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAM5B,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACLC,oBAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,SAAS;AACP,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAMC,sBAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKC,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEG,cAAA,qBAAqB,CAACC,iBAA2C;AAK/D,gBAAA,QAAQA,aAAY,gBAAgB;AAAA,YACxC;AAAA,UAAA,IAEEA,aAAY,kBACZC,gBAAK;AAAA,YACH,KA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AAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,gBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;;;;"}
1
+ {"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config-client',\n async config() {\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n )\n\n return entry\n }\n\n return {\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n /* prettier-ignore */\n define: {\n ...injectDefineEnv('TSS_PUBLIC_BASE', startConfig.public.base),\n ...injectDefineEnv('TSS_CLIENT_BASE', startConfig.client.base),\n ...injectDefineEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...injectDefineEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...injectDefineEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n TanStackStartCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n startManifestPlugin(startConfig),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction injectDefineEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["createTanStackStartOptionsSchema","createTanStackConfig","tanstackRouter","createNitro","nitroOutputPublicDir","startConfig","vite","VITE_ENVIRONMENT_NAMES","TanStackStartCompilerPlugin","TanStackServerFnPluginEnv","startManifestPlugin","nitroPlugin","TanStackStartServerRoutesVite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBmCA,OAAiC,iCAAA;AAK9CC,OAAqB,qBAAA;AASpC,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAM5B,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACLC,oBAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,SAAS;AACP,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAMC,sBAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKC,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEG,cAAA,qBAAqB,CAACC,iBAA2C;AAK/D,gBAAA,QAAQA,aAAY,gBAAgB;AAAA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,qCAA8B;AAAA,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,gBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;;;;"}
@@ -4,8 +4,11 @@ const fs = require("node:fs");
4
4
  const path = require("node:path");
5
5
  const ufo = require("ufo");
6
6
  const routerCore = require("@tanstack/router-core");
7
+ const utils = require("./utils.cjs");
7
8
  function startManifestPlugin(opts) {
8
9
  let config;
10
+ const moduleId = "tanstack-start-router-manifest:v";
11
+ const resolvedModuleId = utils.resolveViteId(moduleId);
9
12
  return {
10
13
  name: "tsr-routes-manifest",
11
14
  enforce: "pre",
@@ -16,14 +19,14 @@ function startManifestPlugin(opts) {
16
19
  // config = envConfig.
17
20
  // },
18
21
  resolveId(id) {
19
- if (id === "tanstack:start-manifest") {
20
- return id;
22
+ if (id === moduleId) {
23
+ return resolvedModuleId;
21
24
  }
22
25
  return;
23
26
  },
24
27
  load(id) {
25
28
  var _a, _b;
26
- if (id === "tanstack:start-manifest") {
29
+ if (id === resolvedModuleId) {
27
30
  if (this.environment.config.consumer !== "server") {
28
31
  return `export default {}`;
29
32
  }
@@ -1 +1 @@
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 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 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 === 'tanstack:start-manifest') {\n return id\n }\n return\n },\n load(id) {\n if (id === 'tanstack:start-manifest') {\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":["readFileSync","joinURL","rootRouteId","_a"],"mappings":";;;;;;AAaO,SAAS,oBACd,MACc;AACV,MAAA;AAEG,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,eAAe,gBAAgB;AACpB,eAAA;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAIA,UAAU,IAAI;AACZ,UAAI,OAAO,2BAA2B;AAC7B,eAAA;AAAA,MAAA;AAET;AAAA,IACF;AAAA,IACA,KAAK,IAAI;;AACP,UAAI,OAAO,2BAA2B;AACpC,YAAI,KAAK,YAAY,OAAO,aAAa,UAAU;AAG1C,iBAAA;AAAA,QAAA;AAIL,YAAA,OAAO,YAAY,SAAS;AACvB,iBAAA;AAAA,uBACM,QAAQ,IAAI,eAAe;AAAA;AAAA;AAAA,QAAA;AAK1C,cAAM,yBAAyB,KAAK;AAAA,UAClC,KAAK;AAAA,UACL;AAAA,QACF;AAEI,YAAA;AACA,YAAA;AACF,yBAAe,KAAK;AAAA,YAClBA,GAAA,aAAa,wBAAwB,OAAO;AAAA,UAC9C;AAAA,iBACO,KAAK;AACZ,kBAAQ,MAAM,GAAG;AACjB,gBAAM,IAAI;AAAA,YACR,0DAA0D,sBAAsB;AAAA,UAClF;AAAA,QAAA;AAGF,cAAM,gBAAgB,KAAK,QAAQ,KAAK,IAAI,kBAAkB;AAE1D,YAAA;AACA,YAAA;AACiB,6BAAAA,GAAAA,aAAa,eAAe,OAAO;AAAA,iBAC/C,KAAK;AACZ,kBAAQ,MAAM,GAAG;AACjB,gBAAM,IAAI;AAAA,YACR,+CAA+C,aAAa;AAAA,UAC9D;AAAA,QAAA;AAMF,cAAM,iBAAiB,KAAK;AAAA,YAC1B,sBAAiB;AAAA,YACf;AAAA,UACF,MAFA,mBAEI,OAAM;AAAA,QACZ;AAEA,cAAM,SAAS,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AA;AAAA,EAEJ;AACF;;"}
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":";;;;;;;AAcO,SAAS,oBACd,MACc;AACV,MAAA;AAEJ,QAAM,WAAW;AACX,QAAA,mBAAmBA,oBAAc,QAAQ;AAExC,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,eAAe,gBAAgB;AACpB,eAAA;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAIA,UAAU,IAAI;AACZ,UAAI,OAAO,UAAU;AACZ,eAAA;AAAA,MAAA;AAET;AAAA,IACF;AAAA,IACA,KAAK,IAAI;;AACP,UAAI,OAAO,kBAAkB;AAC3B,YAAI,KAAK,YAAY,OAAO,aAAa,UAAU;AAG1C,iBAAA;AAAA,QAAA;AAIL,YAAA,OAAO,YAAY,SAAS;AACvB,iBAAA;AAAA,uBACM,QAAQ,IAAI,eAAe;AAAA;AAAA;AAAA,QAAA;AAK1C,cAAM,yBAAyB,KAAK;AAAA,UAClC,KAAK;AAAA,UACL;AAAA,QACF;AAEI,YAAA;AACA,YAAA;AACF,yBAAe,KAAK;AAAA,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Z;;AACH,gBAAM,YAAWE,MAAA,MAAM,aAAN,gBAAAA,IAAgB,OAAO,CAAC,YAAY;AAC/C,gBAAA,aAAa,OAAO,GAAG;AAClB,qBAAA;AAAA,YAAA;AAET,yBAAa,OAAO,IAAI;AACjB,mBAAA;AAAA,UAAA;AAGT,cAAI,MAAM,UAAU;AACZ,kBAAA,SAAS,QAAQ,CAAC,UAAU;AAC1B,oBAAA,aAAa,OAAO,KAAK;AAC/B,2BAAa,YAAY,EAAE,GAAG,cAAc;AAAA,YAAA,CAC7C;AAAA,UAAA;AAAA,QAEL;AAGa,qBAAA,OAAOD,WAAAA,WAAW,CAAC;AAEhC,cAAM,iBAAiB;AAAA,UACrB;AAAA,QACF;AAEA,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAEjF;AAAA,IAAA;AAAA,EAEJ;AACF;;"}
@@ -13,6 +13,7 @@ const setLock = (bool) => {
13
13
  };
14
14
  function TanStackStartServerRoutesVite(config) {
15
15
  let ROOT = process.cwd();
16
+ const moduleId = "tanstack-start-server-routes-manifest:v";
16
17
  const getRoutesDirectoryPath = () => {
17
18
  return path.isAbsolute(config.routesDirectory) ? config.routesDirectory : path.join(ROOT, config.routesDirectory);
18
19
  };
@@ -52,7 +53,7 @@ function TanStackStartServerRoutesVite(config) {
52
53
  },
53
54
  sharedDuringBuild: true,
54
55
  resolveId(id) {
55
- if (id === "tanstack:server-routes") {
56
+ if (id === moduleId) {
56
57
  const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT);
57
58
  return generatedRouteTreePath;
58
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs","sources":["../../../src/start-server-routes-plugin/plugin.ts"],"sourcesContent":["import path, { isAbsolute, join, normalize } from 'node:path'\nimport fs from 'node:fs'\nimport fsp from 'node:fs/promises'\nimport {\n format,\n logging,\n multiSortBy,\n physicalGetRouteNodes,\n removeExt,\n removeUnderscores,\n replaceBackslash,\n resetRegex,\n rootPathId,\n routePathToVariable,\n trimPathLeft,\n virtualGetRouteNodes,\n writeIfDifferent,\n} from '@tanstack/router-generator'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport type { GetRouteNodesResult, RouteNode } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type { Plugin } from 'vite'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nexport function TanStackStartServerRoutesVite(config: Config): Plugin {\n let ROOT: string = process.cwd()\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(config.routesDirectory)\n ? config.routesDirectory\n : join(ROOT, config.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(config, ROOT)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (file: string) => {\n const filePath = normalize(file)\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'tanstack-start-server-routes-plugin',\n configureServer(server) {\n server.watcher.on('all', (event, path) => {\n handleFile(path)\n })\n },\n configResolved(config) {\n ROOT = config.root\n },\n async buildStart() {\n await generate()\n // if (this.environment.name === 'server') {\n // }\n },\n sharedDuringBuild: true,\n resolveId(id) {\n if (id === 'tanstack:server-routes') {\n const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT)\n return generatedRouteTreePath\n }\n return null\n },\n }\n}\n\n// Maybe import this from `@tanstack/router-core` in the future???\nlet latestTask = 0\nconst routeGroupPatternRegex = /\\(.+\\)/g\nconst possiblyNestedRouteGroupPatternRegex = /\\([^/]+\\)\\/?/g\n\nlet isFirst = false\nlet skipMessage = false\n\nfunction getGeneratedRouteTreePath(root: string) {\n return path.resolve(root, '.tanstack-start/server-routes/routeTree.gen.ts')\n}\n\nasync function generator(config: Config, root: string) {\n const generatedServerRouteTreePath = getGeneratedRouteTreePath(root)\n const ROUTE_TEMPLATE = getTargetTemplate(config.target)\n const logger = logging({ disabled: config.disableLogging })\n\n if (!isFirst) {\n // logger.log('♻️ Generating server routes...')\n isFirst = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n // logger.log('♻️ Regenerating server routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(config, root)\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(config, root)\n }\n\n const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.tsx\" file to your routes directory.\\nAdd the file in: \"${config.routesDirectory}/${rootPathId}.tsx\"`\n }\n throw new Error(errorMessage)\n }\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.indexToken}[.]`)) ? 1 : -1,\n (d) =>\n d.filePath.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.routeToken}[.]`)) ? -1 : 1,\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: Array<RouteNode> = []\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n const routeNodes: Array<RouteNode> = []\n\n // the handleRootNode function is not being collapsed into the handleNode function\n // because it requires only a subset of the logic that the handleNode function requires\n // and it's easier to read and maintain this way\n const handleRootNode = async (node?: RouteNode) => {\n if (!node) {\n // currently this is not being handled, but it could be in the future\n // for example to handle a virtual root route\n return\n }\n\n // from here on, we are only handling the root node that's present in the file system\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n if (!routeCode) {\n const _rootTemplate = ROUTE_TEMPLATE.rootRoute\n const replaced = await fillTemplate(config, _rootTemplate.template(), {\n tsrImports: _rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: _rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: _rootTemplate.imports.tsrExportEnd(),\n })\n\n await writeIfDifferent(\n node.fullPath,\n '', // Empty string because the file doesn't exist yet\n replaced,\n {\n beforeWrite: () => {\n // logger.log(`🟡 Creating ${node.fullPath}`)\n },\n },\n )\n }\n }\n\n await handleRootNode(rootRouteNode)\n\n const handleNode = async (node: RouteNode) => {\n // Do not remove this as we need to set the lastIndex to 0 as it\n // is necessary to reset the regex's index when using the global flag\n // otherwise it might not match the next time it's used\n resetRegex(routeGroupPatternRegex)\n\n let parentRoute = hasParentRoute(routeNodes, node, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n\n node.isNonPath =\n lastRouteSegment.startsWith('_') ||\n routeGroupPatternRegex.test(lastRouteSegment)\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n const routeCode = node.fullPath\n ? fs.readFileSync(node.fullPath, 'utf-8')\n : ''\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes and virtual routes\n if (!node.isVirtualParentRoute && !node.isVirtual) {\n // const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n // let replaced = routeCode\n // await writeIfDifferent(node.fullPath, routeCode, replaced, {\n // beforeWrite: () => {\n // // logger.log(`🟡 Updating ${node.fullPath}`)\n // },\n // })\n }\n\n const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0\n const nonPathRoute =\n node._fsRouteType === 'pathless_layout' && node.isNonPath\n\n node.isVirtualParentRequired =\n node._fsRouteType === 'pathless_layout' || nonPathRoute\n ? !cleanedPathIsEmpty\n : false\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n const parentVariableName = routePathToVariable(parentRoutePath)\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode: RouteNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: parentVariableName,\n isVirtual: true,\n _fsRouteType: 'layout', // layout since this route will wrap other routes\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n if (node._fsRouteType === 'pathless_layout') {\n // since `node.path` is used as the `id` on the route definition, we need to update it\n node.path = determineNodePath(node)\n }\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (\n !routeCode\n .split('\\n')\n .some((line) => line.trim().startsWith('export const ServerRoute'))\n ) {\n return\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n for (const node of preRouteNodes) {\n await handleNode(node)\n }\n\n // This is run against the `routeNodes` array since it\n // has the accumulated (intended) Server Route nodes\n // Since TSR allows multiple way of defining a route,\n // we need to ensure that a user hasn't defined the\n // same route in multiple ways (i.e. `flat`, `nested`, `virtual`)\n checkRouteFullPathUniqueness(routeNodes, config)\n\n function buildRouteTreeConfig(nodes: Array<RouteNode>, depth = 1): string {\n const children = nodes.map((node) => {\n if (node._fsRouteType === '__root') {\n return\n }\n\n if (node._fsRouteType === 'pathless_layout' && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = buildRouteTreeConfig(node.children, depth + 1)\n\n const childrenDeclaration = `interface ${route}Children {\n ${node.children.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const children = `const ${route}Children: ${route}Children = {\n ${node.children.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const routeWithChildren = `const ${route}WithChildren = ${route}._addFileChildren(${route}Children)`\n\n return [\n childConfigs,\n childrenDeclaration,\n children,\n routeWithChildren,\n ].join('\\n\\n')\n }\n\n return undefined\n })\n\n return children.filter(Boolean).join('\\n\\n')\n }\n\n const routeConfigChildrenText = buildRouteTreeConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(config.indexToken) ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n function getImportPath(node: RouteNode) {\n return replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(generatedServerRouteTreePath),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )\n }\n\n const rootRouteExists = fs.existsSync(rootRouteNode.fullPath)\n const rootRouteCode = rootRouteExists\n ? fs.readFileSync(rootRouteNode.fullPath, 'utf-8')\n : ''\n const hasServerRootRoute =\n rootRouteExists && rootRouteCode.includes('export const ServerRoute')\n\n const routeImports = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n imports.length\n ? `import { ${imports.join(', ')} } from '${ROUTE_TEMPLATE.fullPkg}'\\n`\n : '',\n '// Import Routes',\n [\n `import type { FileRoutesByPath, CreateServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n `import { createServerRoute, createServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n hasServerRootRoute\n ? `import { ServerRoute as rootRouteImport } from './${getImportPath(rootRouteNode)}'`\n : '',\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { ServerRoute as ${\n node.variableName\n }RouteImport } from './${getImportPath(node)}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }RouteImport = createFileRoute('${node.routePath}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n !hasServerRootRoute\n ? `\n const rootRoute = createServerRoute()\n `\n : '',\n sortedRouteNodes\n .map((node) => {\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ? `path: '${node.cleanedPath}'` : undefined,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n } as any)`,\n ].join(''),\n ].join('\\n\\n')\n })\n .join('\\n\\n'),\n '',\n\n '// Populate the FileRoutesByPath interface',\n `declare module '${ROUTE_TEMPLATE.fullPkg}' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n const filePathId = routeNode.routePath\n\n return `'${filePathId}': {\n id: '${filePathId}'\n path: '${inferPath(routeNode)}'\n fullPath: '${inferFullPath(routeNode)}'\n preLoaderRoute: typeof ${routeNode.variableName}RouteImport\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent.variableName}RouteImport`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n `// Add type-safety to the createFileRoute function across the route tree`,\n routeNodes\n .map((routeNode) => {\n return `declare module './${getImportPath(routeNode)}' {\nconst createServerFileRoute: CreateServerFileRoute<\nFileRoutesByPath['${routeNode.routePath}']['parentRoute'],\nFileRoutesByPath['${routeNode.routePath}']['id'],\nFileRoutesByPath['${routeNode.routePath}']['path'],\nFileRoutesByPath['${routeNode.routePath}']['fullPath'],\n${routeNode.children?.length ? `${routeNode.variableName}RouteChildren` : 'unknown'}\n>\n}`\n })\n .join('\\n'),\n '// Create and export the route tree',\n routeConfigChildrenText,\n `export interface FileRoutesByFullPath {\n ${[...createRouteNodesByFullPath(routeNodes).entries()].map(\n ([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n },\n )}\n}`,\n `export interface FileRoutesByTo {\n ${[...createRouteNodesByTo(routeNodes).entries()].map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n '${rootRouteId}': typeof rootRoute,\n ${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRouteTypes {\n fileRoutesByFullPath: FileRoutesByFullPath\n fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join('|') : 'never'}\n fileRoutesByTo: FileRoutesByTo\n to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join('|') : 'never'}\n id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join('|')}\n fileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n ${routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `const rootRouteChildren: RootRouteChildren = {\n ${routeTree.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileTypes<FileRouteTypes>()`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const createRouteManifest = () => {\n const routesManifest = {\n [rootRouteId]: {\n filePath: rootRouteNode.filePath,\n children: routeTree.map((d) => d.routePath),\n },\n ...Object.fromEntries(\n routeNodes.map((d) => {\n const filePathId = d.routePath\n\n return [\n filePathId,\n {\n filePath: d.filePath,\n parent: d.parent?.routePath ? d.parent.routePath : undefined,\n children: d.children?.map((childRoute) => childRoute.routePath),\n },\n ]\n }),\n ),\n }\n\n return JSON.stringify(\n {\n routes: routesManifest,\n },\n null,\n 2,\n )\n }\n\n const includeManifest = ['react', 'solid']\n const routeConfigFileContent = !includeManifest.includes(config.target)\n ? routeImports\n : [\n routeImports,\n '\\n',\n '/* ROUTE_MANIFEST_START',\n createRouteManifest(),\n 'ROUTE_MANIFEST_END */',\n ].join('\\n')\n\n if (!checkLatest()) return\n\n const existingRouteTreeContent = await fsp\n .readFile(path.resolve(generatedServerRouteTreePath), 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n\n throw err\n })\n\n if (!checkLatest()) return\n\n // Ensure the directory exists\n await fsp.mkdir(path.dirname(path.resolve(generatedServerRouteTreePath)), {\n recursive: true,\n })\n\n if (!checkLatest()) return\n\n // Write the route tree file, if it has changed\n const routeTreeWriteResult = await writeIfDifferent(\n path.resolve(generatedServerRouteTreePath),\n await format(existingRouteTreeContent, config),\n await format(routeConfigFileContent, config),\n {\n beforeWrite: () => {\n // logger.log(`🟡 Updating ${generatedRouteTreePath}`)\n },\n },\n )\n\n // Write declaration file\n const startDeclarationFilePath = path.join(\n path.resolve(root, config.srcDirectory),\n 'tanstack-start.d.ts',\n )\n const serverRoutesRelativePath = removeExt(\n path.relative(\n path.dirname(startDeclarationFilePath),\n generatedServerRouteTreePath,\n ),\n )\n const startDeclarationFileContent = buildStartDeclarationFile({\n serverRoutesRelativePath,\n })\n if (!fs.existsSync(startDeclarationFilePath)) {\n await writeIfDifferent(\n startDeclarationFilePath,\n '',\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Creating tanstack-start.d.ts`)\n },\n },\n )\n } else {\n const existingDeclarationFileContent = await fsp\n .readFile(startDeclarationFilePath, 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n throw err\n })\n await writeIfDifferent(\n startDeclarationFilePath,\n existingDeclarationFileContent,\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Updating tanstack-start.d.ts`)\n },\n },\n )\n }\n\n if (routeTreeWriteResult && !checkLatest()) {\n return\n }\n\n // logger.log(\n // `✅ Processed ${routeNodes.length === 1 ? 'server route' : 'server routes'} in ${\n // Date.now() - start\n // }ms`,\n // )\n}\n\nfunction buildStartDeclarationFile({\n serverRoutesRelativePath,\n}: {\n serverRoutesRelativePath: string\n}) {\n const serverRoutesPath = replaceBackslash(serverRoutesRelativePath)\n return (\n [\n '/// <reference types=\"vite/client\" />',\n `import '${serverRoutesPath}'`,\n ].join('\\n') + '\\n'\n )\n}\n\nfunction removeGroups(s: string) {\n return s.replace(possiblyNestedRouteGroupPatternRegex, '')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nfunction determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nfunction removeLastSegmentFromPath(routePath: string = '/'): string {\n const segments = routePath.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} routePath - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(routePath: string = '/'): string {\n const segments = routePath.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nfunction hasParentRoute(\n routes: Array<RouteNode>,\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, node, parentRoutePath)\n}\n\n/**\n * Gets the final variable name for a route\n */\nconst getResolvedRouteNodeVariableName = (routeNode: RouteNode): string => {\n return routeNode.children?.length\n ? `${routeNode.variableName}RouteWithChildren`\n : `${routeNode.variableName}Route`\n}\n\n/**\n * Creates a map from fullPath to routeNode\n */\nconst createRouteNodesByFullPath = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode]),\n )\n}\n\n/**\n * Create a map from 'to' to a routeNode\n */\nconst createRouteNodesByTo = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [\n inferTo(routeNode),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'id' to a routeNode\n */\nconst createRouteNodesById = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => {\n const id = routeNode.routePath ?? ''\n return [id, routeNode]\n }),\n )\n}\n\n/**\n * Infers the full path for use by TS\n */\nconst inferFullPath = (routeNode: RouteNode): string => {\n const fullPath = removeGroups(\n removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? '',\n )\n\n return routeNode.cleanedPath === '/' ? fullPath : fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Infers the path for use by TS\n */\nconst inferPath = (routeNode: RouteNode): string => {\n return routeNode.cleanedPath === '/'\n ? routeNode.cleanedPath\n : (routeNode.cleanedPath?.replace(/\\/$/, '') ?? '')\n}\n\n/**\n * Infers to path\n */\nconst inferTo = (routeNode: RouteNode): string => {\n const fullPath = inferFullPath(routeNode)\n\n if (fullPath === '/') return fullPath\n\n return fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Dedupes branches and index routes\n */\nconst dedupeBranchesAndIndexRoutes = (\n routes: Array<RouteNode>,\n): Array<RouteNode> => {\n return routes.filter((route) => {\n if (route.children?.find((child) => child.cleanedPath === '/')) return false\n return true\n })\n}\n\nfunction checkUnique<TElement>(routes: Array<TElement>, key: keyof TElement) {\n // Check no two routes have the same `key`\n // if they do, throw an error with the conflicting filePaths\n const keys = routes.map((d) => d[key])\n const uniqueKeys = new Set(keys)\n if (keys.length !== uniqueKeys.size) {\n const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i)\n const conflictingFiles = routes.filter((d) =>\n duplicateKeys.includes(d[key]),\n )\n return conflictingFiles\n }\n return undefined\n}\n\nfunction checkRouteFullPathUniqueness(\n _routes: Array<RouteNode>,\n config: Config,\n) {\n const routes = _routes.map((d) => {\n const inferredFullPath = inferFullPath(d)\n return { ...d, inferredFullPath }\n })\n\n const conflictingFiles = checkUnique(routes, 'inferredFullPath')\n\n if (conflictingFiles !== undefined) {\n const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles\n .map((p) => `\"${p.inferredFullPath}\"`)\n .join(', ')}.\nPlease ensure each Server Route has a unique full path.\nConflicting files: \\n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\\n ')}\\n`\n console.error(errorMessage)\n process.exit(1)\n }\n}\n"],"names":["isAbsolute","join","normalize","path","config","getTargetTemplate","logging","virtualGetRouteNodes","physicalGetRouteNodes","rootPathId","multiSortBy","fillTemplate","writeIfDifferent","resetRegex","trimPathLeft","removeUnderscores","routePathToVariable","children","replaceBackslash","removeExt","rootRouteId","format"],"mappings":";;;;;;;;AAwBA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEO,SAAS,8BAA8B,QAAwB;AAChE,MAAA,OAAe,QAAQ,IAAI;AAE/B,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,KAAA,WAAW,OAAO,eAAe,IACpC,OAAO,kBACPC,UAAK,MAAM,OAAO,eAAe;AAAA,EACvC;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ,IAAI;AAER,QAAA;AACI,YAAA,UAAU,QAAQ,IAAI;AAAA,aACrB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,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ugin/plugin.ts"],"sourcesContent":["import path, { isAbsolute, join, normalize } from 'node:path'\nimport fs from 'node:fs'\nimport fsp from 'node:fs/promises'\nimport {\n format,\n logging,\n multiSortBy,\n physicalGetRouteNodes,\n removeExt,\n removeUnderscores,\n replaceBackslash,\n resetRegex,\n rootPathId,\n routePathToVariable,\n trimPathLeft,\n virtualGetRouteNodes,\n writeIfDifferent,\n} from '@tanstack/router-generator'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport type { GetRouteNodesResult, RouteNode } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type { Plugin } from 'vite'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nexport function TanStackStartServerRoutesVite(config: Config): Plugin {\n let ROOT: string = process.cwd()\n const moduleId = 'tanstack-start-server-routes-manifest:v'\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(config.routesDirectory)\n ? config.routesDirectory\n : join(ROOT, config.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(config, ROOT)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (file: string) => {\n const filePath = normalize(file)\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'tanstack-start-server-routes-plugin',\n configureServer(server) {\n server.watcher.on('all', (event, path) => {\n handleFile(path)\n })\n },\n configResolved(config) {\n ROOT = config.root\n },\n async buildStart() {\n await generate()\n // if (this.environment.name === 'server') {\n // }\n },\n sharedDuringBuild: true,\n resolveId(id) {\n if (id === moduleId) {\n const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT)\n return generatedRouteTreePath\n }\n return null\n },\n }\n}\n\n// Maybe import this from `@tanstack/router-core` in the future???\nlet latestTask = 0\nconst routeGroupPatternRegex = /\\(.+\\)/g\nconst possiblyNestedRouteGroupPatternRegex = /\\([^/]+\\)\\/?/g\n\nlet isFirst = false\nlet skipMessage = false\n\nfunction getGeneratedRouteTreePath(root: string) {\n return path.resolve(root, '.tanstack-start/server-routes/routeTree.gen.ts')\n}\n\nasync function generator(config: Config, root: string) {\n const generatedServerRouteTreePath = getGeneratedRouteTreePath(root)\n const ROUTE_TEMPLATE = getTargetTemplate(config.target)\n const logger = logging({ disabled: config.disableLogging })\n\n if (!isFirst) {\n // logger.log('♻️ Generating server routes...')\n isFirst = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n // logger.log('♻️ Regenerating server routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(config, root)\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(config, root)\n }\n\n const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.tsx\" file to your routes directory.\\nAdd the file in: \"${config.routesDirectory}/${rootPathId}.tsx\"`\n }\n throw new Error(errorMessage)\n }\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.indexToken}[.]`)) ? 1 : -1,\n (d) =>\n d.filePath.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.routeToken}[.]`)) ? -1 : 1,\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: Array<RouteNode> = []\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n const routeNodes: Array<RouteNode> = []\n\n // the handleRootNode function is not being collapsed into the handleNode function\n // because it requires only a subset of the logic that the handleNode function requires\n // and it's easier to read and maintain this way\n const handleRootNode = async (node?: RouteNode) => {\n if (!node) {\n // currently this is not being handled, but it could be in the future\n // for example to handle a virtual root route\n return\n }\n\n // from here on, we are only handling the root node that's present in the file system\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n if (!routeCode) {\n const _rootTemplate = ROUTE_TEMPLATE.rootRoute\n const replaced = await fillTemplate(config, _rootTemplate.template(), {\n tsrImports: _rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: _rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: _rootTemplate.imports.tsrExportEnd(),\n })\n\n await writeIfDifferent(\n node.fullPath,\n '', // Empty string because the file doesn't exist yet\n replaced,\n {\n beforeWrite: () => {\n // logger.log(`🟡 Creating ${node.fullPath}`)\n },\n },\n )\n }\n }\n\n await handleRootNode(rootRouteNode)\n\n const handleNode = async (node: RouteNode) => {\n // Do not remove this as we need to set the lastIndex to 0 as it\n // is necessary to reset the regex's index when using the global flag\n // otherwise it might not match the next time it's used\n resetRegex(routeGroupPatternRegex)\n\n let parentRoute = hasParentRoute(routeNodes, node, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n\n node.isNonPath =\n lastRouteSegment.startsWith('_') ||\n routeGroupPatternRegex.test(lastRouteSegment)\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n const routeCode = node.fullPath\n ? fs.readFileSync(node.fullPath, 'utf-8')\n : ''\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes and virtual routes\n if (!node.isVirtualParentRoute && !node.isVirtual) {\n // const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n // let replaced = routeCode\n // await writeIfDifferent(node.fullPath, routeCode, replaced, {\n // beforeWrite: () => {\n // // logger.log(`🟡 Updating ${node.fullPath}`)\n // },\n // })\n }\n\n const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0\n const nonPathRoute =\n node._fsRouteType === 'pathless_layout' && node.isNonPath\n\n node.isVirtualParentRequired =\n node._fsRouteType === 'pathless_layout' || nonPathRoute\n ? !cleanedPathIsEmpty\n : false\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n const parentVariableName = routePathToVariable(parentRoutePath)\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode: RouteNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: parentVariableName,\n isVirtual: true,\n _fsRouteType: 'layout', // layout since this route will wrap other routes\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n if (node._fsRouteType === 'pathless_layout') {\n // since `node.path` is used as the `id` on the route definition, we need to update it\n node.path = determineNodePath(node)\n }\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (\n !routeCode\n .split('\\n')\n .some((line) => line.trim().startsWith('export const ServerRoute'))\n ) {\n return\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n for (const node of preRouteNodes) {\n await handleNode(node)\n }\n\n // This is run against the `routeNodes` array since it\n // has the accumulated (intended) Server Route nodes\n // Since TSR allows multiple way of defining a route,\n // we need to ensure that a user hasn't defined the\n // same route in multiple ways (i.e. `flat`, `nested`, `virtual`)\n checkRouteFullPathUniqueness(routeNodes, config)\n\n function buildRouteTreeConfig(nodes: Array<RouteNode>, depth = 1): string {\n const children = nodes.map((node) => {\n if (node._fsRouteType === '__root') {\n return\n }\n\n if (node._fsRouteType === 'pathless_layout' && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = buildRouteTreeConfig(node.children, depth + 1)\n\n const childrenDeclaration = `interface ${route}Children {\n ${node.children.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const children = `const ${route}Children: ${route}Children = {\n ${node.children.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const routeWithChildren = `const ${route}WithChildren = ${route}._addFileChildren(${route}Children)`\n\n return [\n childConfigs,\n childrenDeclaration,\n children,\n routeWithChildren,\n ].join('\\n\\n')\n }\n\n return undefined\n })\n\n return children.filter(Boolean).join('\\n\\n')\n }\n\n const routeConfigChildrenText = buildRouteTreeConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(config.indexToken) ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n function getImportPath(node: RouteNode) {\n return replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(generatedServerRouteTreePath),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )\n }\n\n const rootRouteExists = fs.existsSync(rootRouteNode.fullPath)\n const rootRouteCode = rootRouteExists\n ? fs.readFileSync(rootRouteNode.fullPath, 'utf-8')\n : ''\n const hasServerRootRoute =\n rootRouteExists && rootRouteCode.includes('export const ServerRoute')\n\n const routeImports = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n imports.length\n ? `import { ${imports.join(', ')} } from '${ROUTE_TEMPLATE.fullPkg}'\\n`\n : '',\n '// Import Routes',\n [\n `import type { FileRoutesByPath, CreateServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n `import { createServerRoute, createServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n hasServerRootRoute\n ? `import { ServerRoute as rootRouteImport } from './${getImportPath(rootRouteNode)}'`\n : '',\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { ServerRoute as ${\n node.variableName\n }RouteImport } from './${getImportPath(node)}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }RouteImport = createFileRoute('${node.routePath}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n !hasServerRootRoute\n ? `\n const rootRoute = createServerRoute()\n `\n : '',\n sortedRouteNodes\n .map((node) => {\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ? `path: '${node.cleanedPath}'` : undefined,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n } as any)`,\n ].join(''),\n ].join('\\n\\n')\n })\n .join('\\n\\n'),\n '',\n\n '// Populate the FileRoutesByPath interface',\n `declare module '${ROUTE_TEMPLATE.fullPkg}' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n const filePathId = routeNode.routePath\n\n return `'${filePathId}': {\n id: '${filePathId}'\n path: '${inferPath(routeNode)}'\n fullPath: '${inferFullPath(routeNode)}'\n preLoaderRoute: typeof ${routeNode.variableName}RouteImport\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent.variableName}RouteImport`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n `// Add type-safety to the createFileRoute function across the route tree`,\n routeNodes\n .map((routeNode) => {\n return `declare module './${getImportPath(routeNode)}' {\nconst createServerFileRoute: CreateServerFileRoute<\nFileRoutesByPath['${routeNode.routePath}']['parentRoute'],\nFileRoutesByPath['${routeNode.routePath}']['id'],\nFileRoutesByPath['${routeNode.routePath}']['path'],\nFileRoutesByPath['${routeNode.routePath}']['fullPath'],\n${routeNode.children?.length ? `${routeNode.variableName}RouteChildren` : 'unknown'}\n>\n}`\n })\n .join('\\n'),\n '// Create and export the route tree',\n routeConfigChildrenText,\n `export interface FileRoutesByFullPath {\n ${[...createRouteNodesByFullPath(routeNodes).entries()].map(\n ([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n },\n )}\n}`,\n `export interface FileRoutesByTo {\n ${[...createRouteNodesByTo(routeNodes).entries()].map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n '${rootRouteId}': typeof rootRoute,\n ${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRouteTypes {\n fileRoutesByFullPath: FileRoutesByFullPath\n fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join('|') : 'never'}\n fileRoutesByTo: FileRoutesByTo\n to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join('|') : 'never'}\n id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join('|')}\n fileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n ${routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `const rootRouteChildren: RootRouteChildren = {\n ${routeTree.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileTypes<FileRouteTypes>()`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const createRouteManifest = () => {\n const routesManifest = {\n [rootRouteId]: {\n filePath: rootRouteNode.filePath,\n children: routeTree.map((d) => d.routePath),\n },\n ...Object.fromEntries(\n routeNodes.map((d) => {\n const filePathId = d.routePath\n\n return [\n filePathId,\n {\n filePath: d.filePath,\n parent: d.parent?.routePath ? d.parent.routePath : undefined,\n children: d.children?.map((childRoute) => childRoute.routePath),\n },\n ]\n }),\n ),\n }\n\n return JSON.stringify(\n {\n routes: routesManifest,\n },\n null,\n 2,\n )\n }\n\n const includeManifest = ['react', 'solid']\n const routeConfigFileContent = !includeManifest.includes(config.target)\n ? routeImports\n : [\n routeImports,\n '\\n',\n '/* ROUTE_MANIFEST_START',\n createRouteManifest(),\n 'ROUTE_MANIFEST_END */',\n ].join('\\n')\n\n if (!checkLatest()) return\n\n const existingRouteTreeContent = await fsp\n .readFile(path.resolve(generatedServerRouteTreePath), 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n\n throw err\n })\n\n if (!checkLatest()) return\n\n // Ensure the directory exists\n await fsp.mkdir(path.dirname(path.resolve(generatedServerRouteTreePath)), {\n recursive: true,\n })\n\n if (!checkLatest()) return\n\n // Write the route tree file, if it has changed\n const routeTreeWriteResult = await writeIfDifferent(\n path.resolve(generatedServerRouteTreePath),\n await format(existingRouteTreeContent, config),\n await format(routeConfigFileContent, config),\n {\n beforeWrite: () => {\n // logger.log(`🟡 Updating ${generatedRouteTreePath}`)\n },\n },\n )\n\n // Write declaration file\n const startDeclarationFilePath = path.join(\n path.resolve(root, config.srcDirectory),\n 'tanstack-start.d.ts',\n )\n const serverRoutesRelativePath = removeExt(\n path.relative(\n path.dirname(startDeclarationFilePath),\n generatedServerRouteTreePath,\n ),\n )\n const startDeclarationFileContent = buildStartDeclarationFile({\n serverRoutesRelativePath,\n })\n if (!fs.existsSync(startDeclarationFilePath)) {\n await writeIfDifferent(\n startDeclarationFilePath,\n '',\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Creating tanstack-start.d.ts`)\n },\n },\n )\n } else {\n const existingDeclarationFileContent = await fsp\n .readFile(startDeclarationFilePath, 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n throw err\n })\n await writeIfDifferent(\n startDeclarationFilePath,\n existingDeclarationFileContent,\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Updating tanstack-start.d.ts`)\n },\n },\n )\n }\n\n if (routeTreeWriteResult && !checkLatest()) {\n return\n }\n\n // logger.log(\n // `✅ Processed ${routeNodes.length === 1 ? 'server route' : 'server routes'} in ${\n // Date.now() - start\n // }ms`,\n // )\n}\n\nfunction buildStartDeclarationFile({\n serverRoutesRelativePath,\n}: {\n serverRoutesRelativePath: string\n}) {\n const serverRoutesPath = replaceBackslash(serverRoutesRelativePath)\n return (\n [\n '/// <reference types=\"vite/client\" />',\n `import '${serverRoutesPath}'`,\n ].join('\\n') + '\\n'\n )\n}\n\nfunction removeGroups(s: string) {\n return s.replace(possiblyNestedRouteGroupPatternRegex, '')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nfunction determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nfunction removeLastSegmentFromPath(routePath: string = '/'): string {\n const segments = routePath.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} routePath - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(routePath: string = '/'): string {\n const segments = routePath.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nfunction hasParentRoute(\n routes: Array<RouteNode>,\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, node, parentRoutePath)\n}\n\n/**\n * Gets the final variable name for a route\n */\nconst getResolvedRouteNodeVariableName = (routeNode: RouteNode): string => {\n return routeNode.children?.length\n ? `${routeNode.variableName}RouteWithChildren`\n : `${routeNode.variableName}Route`\n}\n\n/**\n * Creates a map from fullPath to routeNode\n */\nconst createRouteNodesByFullPath = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode]),\n )\n}\n\n/**\n * Create a map from 'to' to a routeNode\n */\nconst createRouteNodesByTo = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [\n inferTo(routeNode),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'id' to a routeNode\n */\nconst createRouteNodesById = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => {\n const id = routeNode.routePath ?? ''\n return [id, routeNode]\n }),\n )\n}\n\n/**\n * Infers the full path for use by TS\n */\nconst inferFullPath = (routeNode: RouteNode): string => {\n const fullPath = removeGroups(\n removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? '',\n )\n\n return routeNode.cleanedPath === '/' ? fullPath : fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Infers the path for use by TS\n */\nconst inferPath = (routeNode: RouteNode): string => {\n return routeNode.cleanedPath === '/'\n ? routeNode.cleanedPath\n : (routeNode.cleanedPath?.replace(/\\/$/, '') ?? '')\n}\n\n/**\n * Infers to path\n */\nconst inferTo = (routeNode: RouteNode): string => {\n const fullPath = inferFullPath(routeNode)\n\n if (fullPath === '/') return fullPath\n\n return fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Dedupes branches and index routes\n */\nconst dedupeBranchesAndIndexRoutes = (\n routes: Array<RouteNode>,\n): Array<RouteNode> => {\n return routes.filter((route) => {\n if (route.children?.find((child) => child.cleanedPath === '/')) return false\n return true\n })\n}\n\nfunction checkUnique<TElement>(routes: Array<TElement>, key: keyof TElement) {\n // Check no two routes have the same `key`\n // if they do, throw an error with the conflicting filePaths\n const keys = routes.map((d) => d[key])\n const uniqueKeys = new Set(keys)\n if (keys.length !== uniqueKeys.size) {\n const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i)\n const conflictingFiles = routes.filter((d) =>\n duplicateKeys.includes(d[key]),\n )\n return conflictingFiles\n }\n return undefined\n}\n\nfunction checkRouteFullPathUniqueness(\n _routes: Array<RouteNode>,\n config: Config,\n) {\n const routes = _routes.map((d) => {\n const inferredFullPath = inferFullPath(d)\n return { ...d, inferredFullPath }\n })\n\n const conflictingFiles = checkUnique(routes, 'inferredFullPath')\n\n if (conflictingFiles !== undefined) {\n const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles\n .map((p) => `\"${p.inferredFullPath}\"`)\n .join(', ')}.\nPlease ensure each Server Route has a unique full path.\nConflicting files: \\n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\\n ')}\\n`\n console.error(errorMessage)\n process.exit(1)\n }\n}\n"],"names":["isAbsolute","join","normalize","path","config","getTargetTemplate","logging","virtualGetRouteNodes","physicalGetRouteNodes","rootPathId","multiSortBy","fillTemplate","writeIfDifferent","resetRegex","trimPathLeft","removeUnderscores","routePathToVariable","children","replaceBackslash","removeExt","rootRouteId","format"],"mappings":";;;;;;;;AAwBA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEO,SAAS,8BAA8B,QAAwB;AAChE,MAAA,OAAe,QAAQ,IAAI;AAC/B,QAAM,WAAW;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAAA,KAAA,WAAW,OAAO,eAAe,IACpC,OAAO,kBACPC,UAAK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AEO,iBAAiB,IAAI,CAAC,MAAM,KAAK,QAAQ,OAAO,iBAAiB,EAAE,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA;AAC7G,YAAQ,MAAM,YAAY;AAC1B,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function resolveViteId(id) {
4
+ return `\0${id}`;
5
+ }
6
+ exports.resolveViteId = resolveViteId;
7
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sources":["../../src/utils.ts"],"sourcesContent":["export function resolveViteId(id: string) {\n return `\\0${id}`\n}\n"],"names":[],"mappings":";;AAAO,SAAS,cAAc,IAAY;AACxC,SAAO,KAAK,EAAE;AAChB;;"}
@@ -0,0 +1 @@
1
+ export declare function resolveViteId(id: string): string;
@@ -1,2 +1,3 @@
1
1
  export { createTanStackConfig, createTanStackStartOptionsSchema, pageSchema, } from './schema.js';
2
2
  export { TanStackStartVitePluginCore } from './plugin.js';
3
+ export { resolveViteId } from './utils.js';
package/dist/esm/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { createTanStackConfig, createTanStackStartOptionsSchema, pageSchema } from "./schema.js";
2
2
  import { TanStackStartVitePluginCore } from "./plugin.js";
3
+ import { resolveViteId } from "./utils.js";
3
4
  export {
4
5
  TanStackStartVitePluginCore,
5
6
  createTanStackConfig,
6
7
  createTanStackStartOptionsSchema,
7
- pageSchema
8
+ pageSchema,
9
+ resolveViteId
8
10
  };
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -100,8 +100,8 @@ function TanStackStartVitePluginCore(opts, startConfig) {
100
100
  "@tanstack/start-router-manifest",
101
101
  "@tanstack/start-config",
102
102
  "@tanstack/server-functions-plugin",
103
- "tanstack:start-manifest",
104
- "tanstack:server-fn-manifest",
103
+ "tanstack-start-router-manifest:v",
104
+ "tanstack-start-server-fn-manifest:v",
105
105
  "nitropack",
106
106
  "@tanstack/**"
107
107
  ]
@@ -126,7 +126,7 @@ function TanStackStartVitePluginCore(opts, startConfig) {
126
126
  TanStackServerFnPluginEnv({
127
127
  // This is the ID that will be available to look up and import
128
128
  // our server function manifest and resolve its module
129
- manifestVirtualImportId: "tanstack:server-fn-manifest",
129
+ manifestVirtualImportId: "tanstack-start-server-fn-manifest:v",
130
130
  client: {
131
131
  getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
132
132
  replacer: (d) => `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config-client',\n async config() {\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n )\n\n return entry\n }\n\n return {\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack:start-manifest',\n 'tanstack:server-fn-manifest',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n /* prettier-ignore */\n define: {\n ...injectDefineEnv('TSS_PUBLIC_BASE', startConfig.public.base),\n ...injectDefineEnv('TSS_CLIENT_BASE', startConfig.client.base),\n ...injectDefineEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...injectDefineEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...injectDefineEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n TanStackStartCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack:server-fn-manifest',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n startManifestPlugin(startConfig),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction injectDefineEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["nitroOutputPublicDir","startConfig"],"mappings":";;;;;;;;;;;AAkBmC,iCAAiC;AAK9C,qBAAqB;AASpC,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAM5B,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACL,eAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,SAAS;AACP,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAM,YAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKA,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEn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AY,aAAa,MAAM,SAAS;AAAA,IACxC,8BAA8B;AAAA,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,gBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;"}
1
+ {"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config-client',\n async config() {\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n const getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n )\n\n return entry\n }\n\n return {\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n /* prettier-ignore */\n define: {\n ...injectDefineEnv('TSS_PUBLIC_BASE', startConfig.public.base),\n ...injectDefineEnv('TSS_CLIENT_BASE', startConfig.client.base),\n ...injectDefineEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...injectDefineEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...injectDefineEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n TanStackStartCompilerPlugin(opts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n startManifestPlugin(startConfig),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction injectDefineEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["nitroOutputPublicDir","startConfig"],"mappings":";;;;;;;;;;;AAkBmC,iCAAiC;AAK9C,qBAAqB;AASpC,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAM5B,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACL,eAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,SAAS;AACP,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAM,YAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKA,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEG,cAAA,qBAAqB,CAACC,iBAA2C;AAK/D,gBAAA,QAAQA,aAAY,gBAAgB;AAAA,YACxC;AAAA,UAAA,IAEEA,aAAY,kBACZ,KAAK;AAAA,YACH,KAAK,QAAQA,aAAY,MAAMA,aAAY,eAAe;AAAA,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AAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;"}
@@ -2,8 +2,11 @@ import { readFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { joinURL } from "ufo";
4
4
  import { rootRouteId } from "@tanstack/router-core";
5
+ import { resolveViteId } from "./utils.js";
5
6
  function startManifestPlugin(opts) {
6
7
  let config;
8
+ const moduleId = "tanstack-start-router-manifest:v";
9
+ const resolvedModuleId = resolveViteId(moduleId);
7
10
  return {
8
11
  name: "tsr-routes-manifest",
9
12
  enforce: "pre",
@@ -14,14 +17,14 @@ function startManifestPlugin(opts) {
14
17
  // config = envConfig.
15
18
  // },
16
19
  resolveId(id) {
17
- if (id === "tanstack:start-manifest") {
18
- return id;
20
+ if (id === moduleId) {
21
+ return resolvedModuleId;
19
22
  }
20
23
  return;
21
24
  },
22
25
  load(id) {
23
26
  var _a, _b;
24
- if (id === "tanstack:start-manifest") {
27
+ if (id === resolvedModuleId) {
25
28
  if (this.environment.config.consumer !== "server") {
26
29
  return `export default {}`;
27
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"routesManifestPlugin.js","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 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 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 === 'tanstack:start-manifest') {\n return id\n }\n return\n },\n load(id) {\n if (id === 'tanstack:start-manifest') {\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":["_a"],"mappings":";;;;AAaO,SAAS,oBACd,MACc;AACV,MAAA;AAEG,SAAA;AA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AAC,aAAa;AAAA,cACZ,KAAK;AAAA,cACL,OAAO;AAAA,gBACL,KAAK;AAAA,gBACL,MAAM,QAAQ,KAAK,OAAO;AAAA,gBAC1B,MAAM;AAAA,cAAA;AAAA,YAEV;AAAA,UACF;AAEO,iBAAA,WAAW,EAAG,SAAS;AAAA,YAC5B,GAAI,OAAO,WAAW,EAAG,UAAU,CAAC;AAAA,YACpC,GAAG;AAAA,YACH;AAAA,cACE,KAAK;AAAA,cACL,OAAO;AAAA,gBACL,KAAK,QAAQ,KAAK,UAAU,IAAI;AAAA,gBAChC,MAAM;AAAA,cAAA;AAAA,YACR;AAAA,UAEJ;AAAA,QAAA;AAGF,cAAM,eAAe,CACnB,OAIA,eAAe,CAAA,MACZ;;AACH,gBAAM,YAAWA,MAAA,MAAM,aAAN,gBAAAA,IAAgB,OAAO,CAAC,YAAY;AAC/C,gBAAA,aAAa,OAAO,GAAG;AAClB,qBAAA;AAAA,YAAA;AAET,yBAAa,OAAO,IAAI;AACjB,mBAAA;AAAA,UAAA;AAGT,cAAI,MAAM,UAAU;AACZ,kBAAA,SAAS,QAAQ,CAAC,UAAU;AAC1B,oBAAA,aAAa,OAAO,KAAK;AAC/B,2BAAa,YAAY,EAAE,GAAG,cAAc;AAAA,YAAA,CAC7C;AAAA,UAAA;AAAA,QAEL;AAGa,qBAAA,OAAO,WAAW,CAAC;AAEhC,cAAM,iBAAiB;AAAA,UACrB;AAAA,QACF;AAEA,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAEjF;AAAA,IAAA;AAAA,EAEJ;AACF;"}
1
+ {"version":3,"file":"routesManifestPlugin.js","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":["_a"],"mappings":";;;;;AAcO,SAAS,oBACd,MACc;AACV,MAAA;AAEJ,QAAM,WAAW;AACX,QAAA,mBAAmB,cAAc,QAAQ;AAExC,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,eAAe,gBAAgB;AACpB,eAAA;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAIA,UAAU,IAAI;AACZ,UAAI,OAAO,UAAU;AACZ,eAAA;AAAA,MAAA;AAET;AAAA,IACF;AAAA,IACA,KAAK,IAAI;;AACP,UAAI,OAAO,kBAAkB;AAC3B,YAAI,KAAK,YAAY,OAAO,aAAa,UAAU;AAG1C,iBAAA;AAAA,QAAA;AAIL,YAAA,OAAO,YAAY,SAAS;AACvB,iBAAA;AAAA,uBACM,QAAQ,IAAI,eAAe;AAAA;AAAA;AAAA,QAAA;AAK1C,cAAM,yBAAyB,KAAK;AAAA,UAClC,KAAK;AAAA,UACL;AAAA,QACF;AAEI,YAAA;AACA,YAAA;AACF,yBAAe,KAAK;AAAA,YAClB,aAAa,wBAAwB,OAAO;AAAA,UAC9C;AAAA,iBACO,KAAK;AACZ,kBAAQ,MAAM,GAAG;AACjB,gBAAM,IAAI;AAAA,YACR,0DAA0D,sBAAsB;AAAA,UAClF;AAAA,QAAA;AAGF,cAAM,gBAAgB,KAAK,QAAQ,KAAK,IAAI,kBAAkB;AAE1D,YAAA;AACA,YAAA;AACiB,6BAAA,aAAa,eAAe,OAAO;AAAA,iBAC/C,KAAK;AACZ,kBAAQ,MAAM,GA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OAAO,WAAW,CAAC;AAEhC,cAAM,iBAAiB;AAAA,UACrB;AAAA,QACF;AAEA,eAAO,0CAA0C,KAAK,UAAU,cAAc,CAAC;AAAA,MAAA;AAEjF;AAAA,IAAA;AAAA,EAEJ;AACF;"}
@@ -11,6 +11,7 @@ const setLock = (bool) => {
11
11
  };
12
12
  function TanStackStartServerRoutesVite(config) {
13
13
  let ROOT = process.cwd();
14
+ const moduleId = "tanstack-start-server-routes-manifest:v";
14
15
  const getRoutesDirectoryPath = () => {
15
16
  return isAbsolute(config.routesDirectory) ? config.routesDirectory : join(ROOT, config.routesDirectory);
16
17
  };
@@ -50,7 +51,7 @@ function TanStackStartServerRoutesVite(config) {
50
51
  },
51
52
  sharedDuringBuild: true,
52
53
  resolveId(id) {
53
- if (id === "tanstack:server-routes") {
54
+ if (id === moduleId) {
54
55
  const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT);
55
56
  return generatedRouteTreePath;
56
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../../../src/start-server-routes-plugin/plugin.ts"],"sourcesContent":["import path, { isAbsolute, join, normalize } from 'node:path'\nimport fs from 'node:fs'\nimport fsp from 'node:fs/promises'\nimport {\n format,\n logging,\n multiSortBy,\n physicalGetRouteNodes,\n removeExt,\n removeUnderscores,\n replaceBackslash,\n resetRegex,\n rootPathId,\n routePathToVariable,\n trimPathLeft,\n virtualGetRouteNodes,\n writeIfDifferent,\n} from '@tanstack/router-generator'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport type { GetRouteNodesResult, RouteNode } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type { Plugin } from 'vite'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nexport function TanStackStartServerRoutesVite(config: Config): Plugin {\n let ROOT: string = process.cwd()\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(config.routesDirectory)\n ? config.routesDirectory\n : join(ROOT, config.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(config, ROOT)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (file: string) => {\n const filePath = normalize(file)\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'tanstack-start-server-routes-plugin',\n configureServer(server) {\n server.watcher.on('all', (event, path) => {\n handleFile(path)\n })\n },\n configResolved(config) {\n ROOT = config.root\n },\n async buildStart() {\n await generate()\n // if (this.environment.name === 'server') {\n // }\n },\n sharedDuringBuild: true,\n resolveId(id) {\n if (id === 'tanstack:server-routes') {\n const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT)\n return generatedRouteTreePath\n }\n return null\n },\n }\n}\n\n// Maybe import this from `@tanstack/router-core` in the future???\nlet latestTask = 0\nconst routeGroupPatternRegex = /\\(.+\\)/g\nconst possiblyNestedRouteGroupPatternRegex = /\\([^/]+\\)\\/?/g\n\nlet isFirst = false\nlet skipMessage = false\n\nfunction getGeneratedRouteTreePath(root: string) {\n return path.resolve(root, '.tanstack-start/server-routes/routeTree.gen.ts')\n}\n\nasync function generator(config: Config, root: string) {\n const generatedServerRouteTreePath = getGeneratedRouteTreePath(root)\n const ROUTE_TEMPLATE = getTargetTemplate(config.target)\n const logger = logging({ disabled: config.disableLogging })\n\n if (!isFirst) {\n // logger.log('♻️ Generating server routes...')\n isFirst = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n // logger.log('♻️ Regenerating server routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(config, root)\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(config, root)\n }\n\n const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.tsx\" file to your routes directory.\\nAdd the file in: \"${config.routesDirectory}/${rootPathId}.tsx\"`\n }\n throw new Error(errorMessage)\n }\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.indexToken}[.]`)) ? 1 : -1,\n (d) =>\n d.filePath.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.routeToken}[.]`)) ? -1 : 1,\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: Array<RouteNode> = []\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n const routeNodes: Array<RouteNode> = []\n\n // the handleRootNode function is not being collapsed into the handleNode function\n // because it requires only a subset of the logic that the handleNode function requires\n // and it's easier to read and maintain this way\n const handleRootNode = async (node?: RouteNode) => {\n if (!node) {\n // currently this is not being handled, but it could be in the future\n // for example to handle a virtual root route\n return\n }\n\n // from here on, we are only handling the root node that's present in the file system\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n if (!routeCode) {\n const _rootTemplate = ROUTE_TEMPLATE.rootRoute\n const replaced = await fillTemplate(config, _rootTemplate.template(), {\n tsrImports: _rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: _rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: _rootTemplate.imports.tsrExportEnd(),\n })\n\n await writeIfDifferent(\n node.fullPath,\n '', // Empty string because the file doesn't exist yet\n replaced,\n {\n beforeWrite: () => {\n // logger.log(`🟡 Creating ${node.fullPath}`)\n },\n },\n )\n }\n }\n\n await handleRootNode(rootRouteNode)\n\n const handleNode = async (node: RouteNode) => {\n // Do not remove this as we need to set the lastIndex to 0 as it\n // is necessary to reset the regex's index when using the global flag\n // otherwise it might not match the next time it's used\n resetRegex(routeGroupPatternRegex)\n\n let parentRoute = hasParentRoute(routeNodes, node, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n\n node.isNonPath =\n lastRouteSegment.startsWith('_') ||\n routeGroupPatternRegex.test(lastRouteSegment)\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n const routeCode = node.fullPath\n ? fs.readFileSync(node.fullPath, 'utf-8')\n : ''\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes and virtual routes\n if (!node.isVirtualParentRoute && !node.isVirtual) {\n // const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n // let replaced = routeCode\n // await writeIfDifferent(node.fullPath, routeCode, replaced, {\n // beforeWrite: () => {\n // // logger.log(`🟡 Updating ${node.fullPath}`)\n // },\n // })\n }\n\n const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0\n const nonPathRoute =\n node._fsRouteType === 'pathless_layout' && node.isNonPath\n\n node.isVirtualParentRequired =\n node._fsRouteType === 'pathless_layout' || nonPathRoute\n ? !cleanedPathIsEmpty\n : false\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n const parentVariableName = routePathToVariable(parentRoutePath)\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode: RouteNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: parentVariableName,\n isVirtual: true,\n _fsRouteType: 'layout', // layout since this route will wrap other routes\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n if (node._fsRouteType === 'pathless_layout') {\n // since `node.path` is used as the `id` on the route definition, we need to update it\n node.path = determineNodePath(node)\n }\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (\n !routeCode\n .split('\\n')\n .some((line) => line.trim().startsWith('export const ServerRoute'))\n ) {\n return\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n for (const node of preRouteNodes) {\n await handleNode(node)\n }\n\n // This is run against the `routeNodes` array since it\n // has the accumulated (intended) Server Route nodes\n // Since TSR allows multiple way of defining a route,\n // we need to ensure that a user hasn't defined the\n // same route in multiple ways (i.e. `flat`, `nested`, `virtual`)\n checkRouteFullPathUniqueness(routeNodes, config)\n\n function buildRouteTreeConfig(nodes: Array<RouteNode>, depth = 1): string {\n const children = nodes.map((node) => {\n if (node._fsRouteType === '__root') {\n return\n }\n\n if (node._fsRouteType === 'pathless_layout' && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = buildRouteTreeConfig(node.children, depth + 1)\n\n const childrenDeclaration = `interface ${route}Children {\n ${node.children.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const children = `const ${route}Children: ${route}Children = {\n ${node.children.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const routeWithChildren = `const ${route}WithChildren = ${route}._addFileChildren(${route}Children)`\n\n return [\n childConfigs,\n childrenDeclaration,\n children,\n routeWithChildren,\n ].join('\\n\\n')\n }\n\n return undefined\n })\n\n return children.filter(Boolean).join('\\n\\n')\n }\n\n const routeConfigChildrenText = buildRouteTreeConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(config.indexToken) ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n function getImportPath(node: RouteNode) {\n return replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(generatedServerRouteTreePath),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )\n }\n\n const rootRouteExists = fs.existsSync(rootRouteNode.fullPath)\n const rootRouteCode = rootRouteExists\n ? fs.readFileSync(rootRouteNode.fullPath, 'utf-8')\n : ''\n const hasServerRootRoute =\n rootRouteExists && rootRouteCode.includes('export const ServerRoute')\n\n const routeImports = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n imports.length\n ? `import { ${imports.join(', ')} } from '${ROUTE_TEMPLATE.fullPkg}'\\n`\n : '',\n '// Import Routes',\n [\n `import type { FileRoutesByPath, CreateServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n `import { createServerRoute, createServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n hasServerRootRoute\n ? `import { ServerRoute as rootRouteImport } from './${getImportPath(rootRouteNode)}'`\n : '',\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { ServerRoute as ${\n node.variableName\n }RouteImport } from './${getImportPath(node)}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }RouteImport = createFileRoute('${node.routePath}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n !hasServerRootRoute\n ? `\n const rootRoute = createServerRoute()\n `\n : '',\n sortedRouteNodes\n .map((node) => {\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ? `path: '${node.cleanedPath}'` : undefined,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n } as any)`,\n ].join(''),\n ].join('\\n\\n')\n })\n .join('\\n\\n'),\n '',\n\n '// Populate the FileRoutesByPath interface',\n `declare module '${ROUTE_TEMPLATE.fullPkg}' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n const filePathId = routeNode.routePath\n\n return `'${filePathId}': {\n id: '${filePathId}'\n path: '${inferPath(routeNode)}'\n fullPath: '${inferFullPath(routeNode)}'\n preLoaderRoute: typeof ${routeNode.variableName}RouteImport\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent.variableName}RouteImport`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n `// Add type-safety to the createFileRoute function across the route tree`,\n routeNodes\n .map((routeNode) => {\n return `declare module './${getImportPath(routeNode)}' {\nconst createServerFileRoute: CreateServerFileRoute<\nFileRoutesByPath['${routeNode.routePath}']['parentRoute'],\nFileRoutesByPath['${routeNode.routePath}']['id'],\nFileRoutesByPath['${routeNode.routePath}']['path'],\nFileRoutesByPath['${routeNode.routePath}']['fullPath'],\n${routeNode.children?.length ? `${routeNode.variableName}RouteChildren` : 'unknown'}\n>\n}`\n })\n .join('\\n'),\n '// Create and export the route tree',\n routeConfigChildrenText,\n `export interface FileRoutesByFullPath {\n ${[...createRouteNodesByFullPath(routeNodes).entries()].map(\n ([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n },\n )}\n}`,\n `export interface FileRoutesByTo {\n ${[...createRouteNodesByTo(routeNodes).entries()].map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n '${rootRouteId}': typeof rootRoute,\n ${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRouteTypes {\n fileRoutesByFullPath: FileRoutesByFullPath\n fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join('|') : 'never'}\n fileRoutesByTo: FileRoutesByTo\n to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join('|') : 'never'}\n id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join('|')}\n fileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n ${routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `const rootRouteChildren: RootRouteChildren = {\n ${routeTree.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileTypes<FileRouteTypes>()`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const createRouteManifest = () => {\n const routesManifest = {\n [rootRouteId]: {\n filePath: rootRouteNode.filePath,\n children: routeTree.map((d) => d.routePath),\n },\n ...Object.fromEntries(\n routeNodes.map((d) => {\n const filePathId = d.routePath\n\n return [\n filePathId,\n {\n filePath: d.filePath,\n parent: d.parent?.routePath ? d.parent.routePath : undefined,\n children: d.children?.map((childRoute) => childRoute.routePath),\n },\n ]\n }),\n ),\n }\n\n return JSON.stringify(\n {\n routes: routesManifest,\n },\n null,\n 2,\n )\n }\n\n const includeManifest = ['react', 'solid']\n const routeConfigFileContent = !includeManifest.includes(config.target)\n ? routeImports\n : [\n routeImports,\n '\\n',\n '/* ROUTE_MANIFEST_START',\n createRouteManifest(),\n 'ROUTE_MANIFEST_END */',\n ].join('\\n')\n\n if (!checkLatest()) return\n\n const existingRouteTreeContent = await fsp\n .readFile(path.resolve(generatedServerRouteTreePath), 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n\n throw err\n })\n\n if (!checkLatest()) return\n\n // Ensure the directory exists\n await fsp.mkdir(path.dirname(path.resolve(generatedServerRouteTreePath)), {\n recursive: true,\n })\n\n if (!checkLatest()) return\n\n // Write the route tree file, if it has changed\n const routeTreeWriteResult = await writeIfDifferent(\n path.resolve(generatedServerRouteTreePath),\n await format(existingRouteTreeContent, config),\n await format(routeConfigFileContent, config),\n {\n beforeWrite: () => {\n // logger.log(`🟡 Updating ${generatedRouteTreePath}`)\n },\n },\n )\n\n // Write declaration file\n const startDeclarationFilePath = path.join(\n path.resolve(root, config.srcDirectory),\n 'tanstack-start.d.ts',\n )\n const serverRoutesRelativePath = removeExt(\n path.relative(\n path.dirname(startDeclarationFilePath),\n generatedServerRouteTreePath,\n ),\n )\n const startDeclarationFileContent = buildStartDeclarationFile({\n serverRoutesRelativePath,\n })\n if (!fs.existsSync(startDeclarationFilePath)) {\n await writeIfDifferent(\n startDeclarationFilePath,\n '',\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Creating tanstack-start.d.ts`)\n },\n },\n )\n } else {\n const existingDeclarationFileContent = await fsp\n .readFile(startDeclarationFilePath, 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n throw err\n })\n await writeIfDifferent(\n startDeclarationFilePath,\n existingDeclarationFileContent,\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Updating tanstack-start.d.ts`)\n },\n },\n )\n }\n\n if (routeTreeWriteResult && !checkLatest()) {\n return\n }\n\n // logger.log(\n // `✅ Processed ${routeNodes.length === 1 ? 'server route' : 'server routes'} in ${\n // Date.now() - start\n // }ms`,\n // )\n}\n\nfunction buildStartDeclarationFile({\n serverRoutesRelativePath,\n}: {\n serverRoutesRelativePath: string\n}) {\n const serverRoutesPath = replaceBackslash(serverRoutesRelativePath)\n return (\n [\n '/// <reference types=\"vite/client\" />',\n `import '${serverRoutesPath}'`,\n ].join('\\n') + '\\n'\n )\n}\n\nfunction removeGroups(s: string) {\n return s.replace(possiblyNestedRouteGroupPatternRegex, '')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nfunction determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nfunction removeLastSegmentFromPath(routePath: string = '/'): string {\n const segments = routePath.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} routePath - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(routePath: string = '/'): string {\n const segments = routePath.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nfunction hasParentRoute(\n routes: Array<RouteNode>,\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, node, parentRoutePath)\n}\n\n/**\n * Gets the final variable name for a route\n */\nconst getResolvedRouteNodeVariableName = (routeNode: RouteNode): string => {\n return routeNode.children?.length\n ? `${routeNode.variableName}RouteWithChildren`\n : `${routeNode.variableName}Route`\n}\n\n/**\n * Creates a map from fullPath to routeNode\n */\nconst createRouteNodesByFullPath = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode]),\n )\n}\n\n/**\n * Create a map from 'to' to a routeNode\n */\nconst createRouteNodesByTo = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [\n inferTo(routeNode),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'id' to a routeNode\n */\nconst createRouteNodesById = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => {\n const id = routeNode.routePath ?? ''\n return [id, routeNode]\n }),\n )\n}\n\n/**\n * Infers the full path for use by TS\n */\nconst inferFullPath = (routeNode: RouteNode): string => {\n const fullPath = removeGroups(\n removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? '',\n )\n\n return routeNode.cleanedPath === '/' ? fullPath : fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Infers the path for use by TS\n */\nconst inferPath = (routeNode: RouteNode): string => {\n return routeNode.cleanedPath === '/'\n ? routeNode.cleanedPath\n : (routeNode.cleanedPath?.replace(/\\/$/, '') ?? '')\n}\n\n/**\n * Infers to path\n */\nconst inferTo = (routeNode: RouteNode): string => {\n const fullPath = inferFullPath(routeNode)\n\n if (fullPath === '/') return fullPath\n\n return fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Dedupes branches and index routes\n */\nconst dedupeBranchesAndIndexRoutes = (\n routes: Array<RouteNode>,\n): Array<RouteNode> => {\n return routes.filter((route) => {\n if (route.children?.find((child) => child.cleanedPath === '/')) return false\n return true\n })\n}\n\nfunction checkUnique<TElement>(routes: Array<TElement>, key: keyof TElement) {\n // Check no two routes have the same `key`\n // if they do, throw an error with the conflicting filePaths\n const keys = routes.map((d) => d[key])\n const uniqueKeys = new Set(keys)\n if (keys.length !== uniqueKeys.size) {\n const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i)\n const conflictingFiles = routes.filter((d) =>\n duplicateKeys.includes(d[key]),\n )\n return conflictingFiles\n }\n return undefined\n}\n\nfunction checkRouteFullPathUniqueness(\n _routes: Array<RouteNode>,\n config: Config,\n) {\n const routes = _routes.map((d) => {\n const inferredFullPath = inferFullPath(d)\n return { ...d, inferredFullPath }\n })\n\n const conflictingFiles = checkUnique(routes, 'inferredFullPath')\n\n if (conflictingFiles !== undefined) {\n const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles\n .map((p) => `\"${p.inferredFullPath}\"`)\n .join(', ')}.\nPlease ensure each Server Route has a unique full path.\nConflicting files: \\n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\\n ')}\\n`\n console.error(errorMessage)\n process.exit(1)\n }\n}\n"],"names":["path","config","children"],"mappings":";;;;;;AAwBA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEO,SAAS,8BAA8B,QAAwB;AAChE,MAAA,OAAe,QAAQ,IAAI;AAE/B,QAAM,yBAAyB,MAAM;AAC5B,WAAA,WAAW,OAAO,eAAe,IACpC,OAAO,kBACP,KAAK,MAAM,OAAO,eAAe;AAAA,EACvC;AAEA,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IAAA;AAGF,YAAQ,IAAI;AAER,QAAA;AACI,YAAA,UAAU,QAAQ,IAAI;AAAA,aACrB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IAAA;AAAA,EAEjB;AAEM,QAAA,aAAa,OAAO,SAAiB;AACnC,UAAA,WAAW,UAAU,IAAI;AAE/B,UAAM,sBAAsB,uBAAuB;AAC/C,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IAAA;AAAA,EAEnB;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,gBAAgB,QAAQ;AACtB,aAAO,QAAQ,GAAG,OAAO,CAAC,OAAOA,UAAS;AACxC,mBAAWA,KAAI;AAAA,MAAA,CAChB;AAAA,IACH;AAAA,IACA,eAAeC,SAAQ;AACrB,aAAOA,QAAO;AAAA,IAChB;AAAA,IACA,MAAM,aAAa;AACjB,YAAM,SAAS;AAAA,IAGjB;AAAA,IACA,mBAAmB;AAAA,IACnB,UAAU,IAAI;AACZ,UAAI,OAAO,0BAA0B;AAC7B,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,CACjC;AAEK,QAAA,mBAAmB,YAAY,QAAQ,kBAAkB;AAE/D,MAAI,qBAAqB,QAAW;AAClC,UAAM,eAAe,qEAAqE,iBAAiB,SAAS,IAAI,MAAM,EAAE,KAAK,iBAClI,IAAI,CAAC,MAAM,IAAI,EAAE,gBAAgB,GAAG,EACpC,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA,GAEO,iBAAiB,IAAI,CAAC,MAAM,KAAK,QAAQ,OAAO,iBAAiB,EAAE,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA;AAC7G,YAAQ,MAAM,YAAY;AAC1B,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;"}
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/start-server-routes-plugin/plugin.ts"],"sourcesContent":["import path, { isAbsolute, join, normalize } from 'node:path'\nimport fs from 'node:fs'\nimport fsp from 'node:fs/promises'\nimport {\n format,\n logging,\n multiSortBy,\n physicalGetRouteNodes,\n removeExt,\n removeUnderscores,\n replaceBackslash,\n resetRegex,\n rootPathId,\n routePathToVariable,\n trimPathLeft,\n virtualGetRouteNodes,\n writeIfDifferent,\n} from '@tanstack/router-generator'\nimport { rootRouteId } from '@tanstack/router-core'\nimport { fillTemplate, getTargetTemplate } from './template'\nimport type { GetRouteNodesResult, RouteNode } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type { Plugin } from 'vite'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nexport function TanStackStartServerRoutesVite(config: Config): Plugin {\n let ROOT: string = process.cwd()\n const moduleId = 'tanstack-start-server-routes-manifest:v'\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(config.routesDirectory)\n ? config.routesDirectory\n : join(ROOT, config.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(config, ROOT)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (file: string) => {\n const filePath = normalize(file)\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n return {\n name: 'tanstack-start-server-routes-plugin',\n configureServer(server) {\n server.watcher.on('all', (event, path) => {\n handleFile(path)\n })\n },\n configResolved(config) {\n ROOT = config.root\n },\n async buildStart() {\n await generate()\n // if (this.environment.name === 'server') {\n // }\n },\n sharedDuringBuild: true,\n resolveId(id) {\n if (id === moduleId) {\n const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT)\n return generatedRouteTreePath\n }\n return null\n },\n }\n}\n\n// Maybe import this from `@tanstack/router-core` in the future???\nlet latestTask = 0\nconst routeGroupPatternRegex = /\\(.+\\)/g\nconst possiblyNestedRouteGroupPatternRegex = /\\([^/]+\\)\\/?/g\n\nlet isFirst = false\nlet skipMessage = false\n\nfunction getGeneratedRouteTreePath(root: string) {\n return path.resolve(root, '.tanstack-start/server-routes/routeTree.gen.ts')\n}\n\nasync function generator(config: Config, root: string) {\n const generatedServerRouteTreePath = getGeneratedRouteTreePath(root)\n const ROUTE_TEMPLATE = getTargetTemplate(config.target)\n const logger = logging({ disabled: config.disableLogging })\n\n if (!isFirst) {\n // logger.log('♻️ Generating server routes...')\n isFirst = true\n } else if (skipMessage) {\n skipMessage = false\n } else {\n // logger.log('♻️ Regenerating server routes...')\n }\n\n const taskId = latestTask + 1\n latestTask = taskId\n\n const checkLatest = () => {\n if (latestTask !== taskId) {\n skipMessage = true\n return false\n }\n\n return true\n }\n\n const start = Date.now()\n\n let getRouteNodesResult: GetRouteNodesResult\n\n if (config.virtualRouteConfig) {\n getRouteNodesResult = await virtualGetRouteNodes(config, root)\n } else {\n getRouteNodesResult = await physicalGetRouteNodes(config, root)\n }\n\n const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult\n if (rootRouteNode === undefined) {\n let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`\n if (!config.virtualRouteConfig) {\n errorMessage += `\\nMake sure that you add a \"${rootPathId}.tsx\" file to your routes directory.\\nAdd the file in: \"${config.routesDirectory}/${rootPathId}.tsx\"`\n }\n throw new Error(errorMessage)\n }\n\n const preRouteNodes = multiSortBy(beforeRouteNodes, [\n (d) => (d.routePath === '/' ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.indexToken}[.]`)) ? 1 : -1,\n (d) =>\n d.filePath.match(\n /[./](component|errorComponent|pendingComponent|loader|lazy)[.]/,\n )\n ? 1\n : -1,\n (d) =>\n d.filePath.match(new RegExp(`[./]${config.routeToken}[.]`)) ? -1 : 1,\n (d) => (d.routePath?.endsWith('/') ? -1 : 1),\n (d) => d.routePath,\n ]).filter((d) => ![`/${rootPathId}`].includes(d.routePath || ''))\n\n const routeTree: Array<RouteNode> = []\n\n // Loop over the flat list of routeNodes and\n // build up a tree based on the routeNodes' routePath\n const routeNodes: Array<RouteNode> = []\n\n // the handleRootNode function is not being collapsed into the handleNode function\n // because it requires only a subset of the logic that the handleNode function requires\n // and it's easier to read and maintain this way\n const handleRootNode = async (node?: RouteNode) => {\n if (!node) {\n // currently this is not being handled, but it could be in the future\n // for example to handle a virtual root route\n return\n }\n\n // from here on, we are only handling the root node that's present in the file system\n const routeCode = fs.readFileSync(node.fullPath, 'utf-8')\n\n if (!routeCode) {\n const _rootTemplate = ROUTE_TEMPLATE.rootRoute\n const replaced = await fillTemplate(config, _rootTemplate.template(), {\n tsrImports: _rootTemplate.imports.tsrImports(),\n tsrPath: rootPathId,\n tsrExportStart: _rootTemplate.imports.tsrExportStart(),\n tsrExportEnd: _rootTemplate.imports.tsrExportEnd(),\n })\n\n await writeIfDifferent(\n node.fullPath,\n '', // Empty string because the file doesn't exist yet\n replaced,\n {\n beforeWrite: () => {\n // logger.log(`🟡 Creating ${node.fullPath}`)\n },\n },\n )\n }\n }\n\n await handleRootNode(rootRouteNode)\n\n const handleNode = async (node: RouteNode) => {\n // Do not remove this as we need to set the lastIndex to 0 as it\n // is necessary to reset the regex's index when using the global flag\n // otherwise it might not match the next time it's used\n resetRegex(routeGroupPatternRegex)\n\n let parentRoute = hasParentRoute(routeNodes, node, node.routePath)\n\n // if the parent route is a virtual parent route, we need to find the real parent route\n if (parentRoute?.isVirtualParentRoute && parentRoute.children?.length) {\n // only if this sub-parent route returns a valid parent route, we use it, if not leave it as it\n const possibleParentRoute = hasParentRoute(\n parentRoute.children,\n node,\n node.routePath,\n )\n if (possibleParentRoute) {\n parentRoute = possibleParentRoute\n }\n }\n\n if (parentRoute) node.parent = parentRoute\n\n node.path = determineNodePath(node)\n\n const trimmedPath = trimPathLeft(node.path ?? '')\n\n const split = trimmedPath.split('/')\n const lastRouteSegment = split[split.length - 1] ?? trimmedPath\n\n node.isNonPath =\n lastRouteSegment.startsWith('_') ||\n routeGroupPatternRegex.test(lastRouteSegment)\n\n node.cleanedPath = removeGroups(\n removeUnderscores(removeLayoutSegments(node.path)) ?? '',\n )\n\n const routeCode = node.fullPath\n ? fs.readFileSync(node.fullPath, 'utf-8')\n : ''\n\n // Ensure the boilerplate for the route exists, which can be skipped for virtual parent routes and virtual routes\n if (!node.isVirtualParentRoute && !node.isVirtual) {\n // const escapedRoutePath = node.routePath?.replaceAll('$', '$$') ?? ''\n // let replaced = routeCode\n // await writeIfDifferent(node.fullPath, routeCode, replaced, {\n // beforeWrite: () => {\n // // logger.log(`🟡 Updating ${node.fullPath}`)\n // },\n // })\n }\n\n const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0\n const nonPathRoute =\n node._fsRouteType === 'pathless_layout' && node.isNonPath\n\n node.isVirtualParentRequired =\n node._fsRouteType === 'pathless_layout' || nonPathRoute\n ? !cleanedPathIsEmpty\n : false\n\n if (!node.isVirtual && node.isVirtualParentRequired) {\n const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'\n const parentVariableName = routePathToVariable(parentRoutePath)\n\n const anchorRoute = routeNodes.find(\n (d) => d.routePath === parentRoutePath,\n )\n\n if (!anchorRoute) {\n const parentNode: RouteNode = {\n ...node,\n path: removeLastSegmentFromPath(node.path) || '/',\n filePath: removeLastSegmentFromPath(node.filePath) || '/',\n fullPath: removeLastSegmentFromPath(node.fullPath) || '/',\n routePath: parentRoutePath,\n variableName: parentVariableName,\n isVirtual: true,\n _fsRouteType: 'layout', // layout since this route will wrap other routes\n isVirtualParentRoute: true,\n isVirtualParentRequired: false,\n }\n\n parentNode.children = parentNode.children ?? []\n parentNode.children.push(node)\n\n node.parent = parentNode\n\n if (node._fsRouteType === 'pathless_layout') {\n // since `node.path` is used as the `id` on the route definition, we need to update it\n node.path = determineNodePath(node)\n }\n\n await handleNode(parentNode)\n } else {\n anchorRoute.children = anchorRoute.children ?? []\n anchorRoute.children.push(node)\n\n node.parent = anchorRoute\n }\n }\n\n if (\n !routeCode\n .split('\\n')\n .some((line) => line.trim().startsWith('export const ServerRoute'))\n ) {\n return\n }\n\n if (node.parent) {\n if (!node.isVirtualParentRequired) {\n node.parent.children = node.parent.children ?? []\n node.parent.children.push(node)\n }\n } else {\n routeTree.push(node)\n }\n\n routeNodes.push(node)\n }\n\n for (const node of preRouteNodes) {\n await handleNode(node)\n }\n\n // This is run against the `routeNodes` array since it\n // has the accumulated (intended) Server Route nodes\n // Since TSR allows multiple way of defining a route,\n // we need to ensure that a user hasn't defined the\n // same route in multiple ways (i.e. `flat`, `nested`, `virtual`)\n checkRouteFullPathUniqueness(routeNodes, config)\n\n function buildRouteTreeConfig(nodes: Array<RouteNode>, depth = 1): string {\n const children = nodes.map((node) => {\n if (node._fsRouteType === '__root') {\n return\n }\n\n if (node._fsRouteType === 'pathless_layout' && !node.children?.length) {\n return\n }\n\n const route = `${node.variableName}Route`\n\n if (node.children?.length) {\n const childConfigs = buildRouteTreeConfig(node.children, depth + 1)\n\n const childrenDeclaration = `interface ${route}Children {\n ${node.children.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const children = `const ${route}Children: ${route}Children = {\n ${node.children.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`\n\n const routeWithChildren = `const ${route}WithChildren = ${route}._addFileChildren(${route}Children)`\n\n return [\n childConfigs,\n childrenDeclaration,\n children,\n routeWithChildren,\n ].join('\\n\\n')\n }\n\n return undefined\n })\n\n return children.filter(Boolean).join('\\n\\n')\n }\n\n const routeConfigChildrenText = buildRouteTreeConfig(routeTree)\n\n const sortedRouteNodes = multiSortBy(routeNodes, [\n (d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),\n (d) => d.routePath?.split('/').length,\n (d) => (d.routePath?.endsWith(config.indexToken) ? -1 : 1),\n (d) => d,\n ])\n\n const imports = Object.entries({\n createFileRoute: sortedRouteNodes.some((d) => d.isVirtual),\n })\n .filter((d) => d[1])\n .map((d) => d[0])\n\n const virtualRouteNodes = sortedRouteNodes.filter((d) => d.isVirtual)\n\n function getImportPath(node: RouteNode) {\n return replaceBackslash(\n removeExt(\n path.relative(\n path.dirname(generatedServerRouteTreePath),\n path.resolve(config.routesDirectory, node.filePath),\n ),\n ),\n )\n }\n\n const rootRouteExists = fs.existsSync(rootRouteNode.fullPath)\n const rootRouteCode = rootRouteExists\n ? fs.readFileSync(rootRouteNode.fullPath, 'utf-8')\n : ''\n const hasServerRootRoute =\n rootRouteExists && rootRouteCode.includes('export const ServerRoute')\n\n const routeImports = [\n ...config.routeTreeFileHeader,\n `// This file was automatically generated by TanStack Router.\n// You should NOT make any changes in this file as it will be overwritten.\n// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.`,\n imports.length\n ? `import { ${imports.join(', ')} } from '${ROUTE_TEMPLATE.fullPkg}'\\n`\n : '',\n '// Import Routes',\n [\n `import type { FileRoutesByPath, CreateServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n `import { createServerRoute, createServerFileRoute } from '${ROUTE_TEMPLATE.fullPkg}'`,\n hasServerRootRoute\n ? `import { ServerRoute as rootRouteImport } from './${getImportPath(rootRouteNode)}'`\n : '',\n ...sortedRouteNodes\n .filter((d) => !d.isVirtual)\n .map((node) => {\n return `import { ServerRoute as ${\n node.variableName\n }RouteImport } from './${getImportPath(node)}'`\n }),\n ].join('\\n'),\n virtualRouteNodes.length ? '// Create Virtual Routes' : '',\n virtualRouteNodes\n .map((node) => {\n return `const ${\n node.variableName\n }RouteImport = createFileRoute('${node.routePath}')()`\n })\n .join('\\n'),\n '// Create/Update Routes',\n !hasServerRootRoute\n ? `\n const rootRoute = createServerRoute()\n `\n : '',\n sortedRouteNodes\n .map((node) => {\n return [\n [\n `const ${node.variableName}Route = ${node.variableName}RouteImport.update({\n ${[\n `id: '${node.path}'`,\n !node.isNonPath ? `path: '${node.cleanedPath}'` : undefined,\n `getParentRoute: () => ${node.parent?.variableName ?? 'root'}Route`,\n ]\n .filter(Boolean)\n .join(',')}\n } as any)`,\n ].join(''),\n ].join('\\n\\n')\n })\n .join('\\n\\n'),\n '',\n\n '// Populate the FileRoutesByPath interface',\n `declare module '${ROUTE_TEMPLATE.fullPkg}' {\n interface FileRoutesByPath {\n ${routeNodes\n .map((routeNode) => {\n const filePathId = routeNode.routePath\n\n return `'${filePathId}': {\n id: '${filePathId}'\n path: '${inferPath(routeNode)}'\n fullPath: '${inferFullPath(routeNode)}'\n preLoaderRoute: typeof ${routeNode.variableName}RouteImport\n parentRoute: typeof ${\n routeNode.isVirtualParentRequired\n ? `${routeNode.parent?.variableName}Route`\n : routeNode.parent?.variableName\n ? `${routeNode.parent.variableName}RouteImport`\n : 'rootRoute'\n }\n }`\n })\n .join('\\n')}\n }\n}`,\n `// Add type-safety to the createFileRoute function across the route tree`,\n routeNodes\n .map((routeNode) => {\n return `declare module './${getImportPath(routeNode)}' {\nconst createServerFileRoute: CreateServerFileRoute<\nFileRoutesByPath['${routeNode.routePath}']['parentRoute'],\nFileRoutesByPath['${routeNode.routePath}']['id'],\nFileRoutesByPath['${routeNode.routePath}']['path'],\nFileRoutesByPath['${routeNode.routePath}']['fullPath'],\n${routeNode.children?.length ? `${routeNode.variableName}RouteChildren` : 'unknown'}\n>\n}`\n })\n .join('\\n'),\n '// Create and export the route tree',\n routeConfigChildrenText,\n `export interface FileRoutesByFullPath {\n ${[...createRouteNodesByFullPath(routeNodes).entries()].map(\n ([fullPath, routeNode]) => {\n return `'${fullPath}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n },\n )}\n}`,\n `export interface FileRoutesByTo {\n ${[...createRouteNodesByTo(routeNodes).entries()].map(([to, routeNode]) => {\n return `'${to}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRoutesById {\n '${rootRouteId}': typeof rootRoute,\n ${[...createRouteNodesById(routeNodes).entries()].map(([id, routeNode]) => {\n return `'${id}': typeof ${getResolvedRouteNodeVariableName(routeNode)}`\n })}\n}`,\n `export interface FileRouteTypes {\n fileRoutesByFullPath: FileRoutesByFullPath\n fullPaths: ${routeNodes.length > 0 ? [...createRouteNodesByFullPath(routeNodes).keys()].map((fullPath) => `'${fullPath}'`).join('|') : 'never'}\n fileRoutesByTo: FileRoutesByTo\n to: ${routeNodes.length > 0 ? [...createRouteNodesByTo(routeNodes).keys()].map((to) => `'${to}'`).join('|') : 'never'}\n id: ${[`'${rootRouteId}'`, ...[...createRouteNodesById(routeNodes).keys()].map((id) => `'${id}'`)].join('|')}\n fileRoutesById: FileRoutesById\n}`,\n `export interface RootRouteChildren {\n ${routeTree.map((child) => `${child.variableName}Route: typeof ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `const rootRouteChildren: RootRouteChildren = {\n ${routeTree.map((child) => `${child.variableName}Route: ${getResolvedRouteNodeVariableName(child)}`).join(',')}\n}`,\n `export const routeTree = rootRoute._addFileChildren(rootRouteChildren)._addFileTypes<FileRouteTypes>()`,\n ]\n .filter(Boolean)\n .join('\\n\\n')\n\n const createRouteManifest = () => {\n const routesManifest = {\n [rootRouteId]: {\n filePath: rootRouteNode.filePath,\n children: routeTree.map((d) => d.routePath),\n },\n ...Object.fromEntries(\n routeNodes.map((d) => {\n const filePathId = d.routePath\n\n return [\n filePathId,\n {\n filePath: d.filePath,\n parent: d.parent?.routePath ? d.parent.routePath : undefined,\n children: d.children?.map((childRoute) => childRoute.routePath),\n },\n ]\n }),\n ),\n }\n\n return JSON.stringify(\n {\n routes: routesManifest,\n },\n null,\n 2,\n )\n }\n\n const includeManifest = ['react', 'solid']\n const routeConfigFileContent = !includeManifest.includes(config.target)\n ? routeImports\n : [\n routeImports,\n '\\n',\n '/* ROUTE_MANIFEST_START',\n createRouteManifest(),\n 'ROUTE_MANIFEST_END */',\n ].join('\\n')\n\n if (!checkLatest()) return\n\n const existingRouteTreeContent = await fsp\n .readFile(path.resolve(generatedServerRouteTreePath), 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n\n throw err\n })\n\n if (!checkLatest()) return\n\n // Ensure the directory exists\n await fsp.mkdir(path.dirname(path.resolve(generatedServerRouteTreePath)), {\n recursive: true,\n })\n\n if (!checkLatest()) return\n\n // Write the route tree file, if it has changed\n const routeTreeWriteResult = await writeIfDifferent(\n path.resolve(generatedServerRouteTreePath),\n await format(existingRouteTreeContent, config),\n await format(routeConfigFileContent, config),\n {\n beforeWrite: () => {\n // logger.log(`🟡 Updating ${generatedRouteTreePath}`)\n },\n },\n )\n\n // Write declaration file\n const startDeclarationFilePath = path.join(\n path.resolve(root, config.srcDirectory),\n 'tanstack-start.d.ts',\n )\n const serverRoutesRelativePath = removeExt(\n path.relative(\n path.dirname(startDeclarationFilePath),\n generatedServerRouteTreePath,\n ),\n )\n const startDeclarationFileContent = buildStartDeclarationFile({\n serverRoutesRelativePath,\n })\n if (!fs.existsSync(startDeclarationFilePath)) {\n await writeIfDifferent(\n startDeclarationFilePath,\n '',\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Creating tanstack-start.d.ts`)\n },\n },\n )\n } else {\n const existingDeclarationFileContent = await fsp\n .readFile(startDeclarationFilePath, 'utf-8')\n .catch((err) => {\n if (err.code === 'ENOENT') {\n return ''\n }\n throw err\n })\n await writeIfDifferent(\n startDeclarationFilePath,\n existingDeclarationFileContent,\n startDeclarationFileContent,\n {\n beforeWrite: () => {\n logger.log(`🟡 Updating tanstack-start.d.ts`)\n },\n },\n )\n }\n\n if (routeTreeWriteResult && !checkLatest()) {\n return\n }\n\n // logger.log(\n // `✅ Processed ${routeNodes.length === 1 ? 'server route' : 'server routes'} in ${\n // Date.now() - start\n // }ms`,\n // )\n}\n\nfunction buildStartDeclarationFile({\n serverRoutesRelativePath,\n}: {\n serverRoutesRelativePath: string\n}) {\n const serverRoutesPath = replaceBackslash(serverRoutesRelativePath)\n return (\n [\n '/// <reference types=\"vite/client\" />',\n `import '${serverRoutesPath}'`,\n ].join('\\n') + '\\n'\n )\n}\n\nfunction removeGroups(s: string) {\n return s.replace(possiblyNestedRouteGroupPatternRegex, '')\n}\n\n/**\n * The `node.path` is used as the `id` in the route definition.\n * This function checks if the given node has a parent and if so, it determines the correct path for the given node.\n * @param node - The node to determine the path for.\n * @returns The correct path for the given node.\n */\nfunction determineNodePath(node: RouteNode) {\n return (node.path = node.parent\n ? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'\n : node.routePath)\n}\n\n/**\n * Removes the last segment from a given path. Segments are considered to be separated by a '/'.\n *\n * @param {string} routePath - The path from which to remove the last segment. Defaults to '/'.\n * @returns {string} The path with the last segment removed.\n * @example\n * removeLastSegmentFromPath('/workspace/_auth/foo') // '/workspace/_auth'\n */\nfunction removeLastSegmentFromPath(routePath: string = '/'): string {\n const segments = routePath.split('/')\n segments.pop() // Remove the last segment\n return segments.join('/')\n}\n\n/**\n * Removes all segments from a given path that start with an underscore ('_').\n *\n * @param {string} routePath - The path from which to remove segments. Defaults to '/'.\n * @returns {string} The path with all underscore-prefixed segments removed.\n * @example\n * removeLayoutSegments('/workspace/_auth/foo') // '/workspace/foo'\n */\nfunction removeLayoutSegments(routePath: string = '/'): string {\n const segments = routePath.split('/')\n const newSegments = segments.filter((segment) => !segment.startsWith('_'))\n return newSegments.join('/')\n}\n\nfunction hasParentRoute(\n routes: Array<RouteNode>,\n node: RouteNode,\n routePathToCheck: string | undefined,\n): RouteNode | null {\n if (!routePathToCheck || routePathToCheck === '/') {\n return null\n }\n\n const sortedNodes = multiSortBy(routes, [\n (d) => d.routePath!.length * -1,\n (d) => d.variableName,\n ]).filter((d) => d.routePath !== `/${rootPathId}`)\n\n for (const route of sortedNodes) {\n if (route.routePath === '/') continue\n\n if (\n routePathToCheck.startsWith(`${route.routePath}/`) &&\n route.routePath !== routePathToCheck\n ) {\n return route\n }\n }\n\n const segments = routePathToCheck.split('/')\n segments.pop() // Remove the last segment\n const parentRoutePath = segments.join('/')\n\n return hasParentRoute(routes, node, parentRoutePath)\n}\n\n/**\n * Gets the final variable name for a route\n */\nconst getResolvedRouteNodeVariableName = (routeNode: RouteNode): string => {\n return routeNode.children?.length\n ? `${routeNode.variableName}RouteWithChildren`\n : `${routeNode.variableName}Route`\n}\n\n/**\n * Creates a map from fullPath to routeNode\n */\nconst createRouteNodesByFullPath = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => [inferFullPath(routeNode), routeNode]),\n )\n}\n\n/**\n * Create a map from 'to' to a routeNode\n */\nconst createRouteNodesByTo = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n dedupeBranchesAndIndexRoutes(routeNodes).map((routeNode) => [\n inferTo(routeNode),\n routeNode,\n ]),\n )\n}\n\n/**\n * Create a map from 'id' to a routeNode\n */\nconst createRouteNodesById = (\n routeNodes: Array<RouteNode>,\n): Map<string, RouteNode> => {\n return new Map(\n routeNodes.map((routeNode) => {\n const id = routeNode.routePath ?? ''\n return [id, routeNode]\n }),\n )\n}\n\n/**\n * Infers the full path for use by TS\n */\nconst inferFullPath = (routeNode: RouteNode): string => {\n const fullPath = removeGroups(\n removeUnderscores(removeLayoutSegments(routeNode.routePath)) ?? '',\n )\n\n return routeNode.cleanedPath === '/' ? fullPath : fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Infers the path for use by TS\n */\nconst inferPath = (routeNode: RouteNode): string => {\n return routeNode.cleanedPath === '/'\n ? routeNode.cleanedPath\n : (routeNode.cleanedPath?.replace(/\\/$/, '') ?? '')\n}\n\n/**\n * Infers to path\n */\nconst inferTo = (routeNode: RouteNode): string => {\n const fullPath = inferFullPath(routeNode)\n\n if (fullPath === '/') return fullPath\n\n return fullPath.replace(/\\/$/, '')\n}\n\n/**\n * Dedupes branches and index routes\n */\nconst dedupeBranchesAndIndexRoutes = (\n routes: Array<RouteNode>,\n): Array<RouteNode> => {\n return routes.filter((route) => {\n if (route.children?.find((child) => child.cleanedPath === '/')) return false\n return true\n })\n}\n\nfunction checkUnique<TElement>(routes: Array<TElement>, key: keyof TElement) {\n // Check no two routes have the same `key`\n // if they do, throw an error with the conflicting filePaths\n const keys = routes.map((d) => d[key])\n const uniqueKeys = new Set(keys)\n if (keys.length !== uniqueKeys.size) {\n const duplicateKeys = keys.filter((d, i) => keys.indexOf(d) !== i)\n const conflictingFiles = routes.filter((d) =>\n duplicateKeys.includes(d[key]),\n )\n return conflictingFiles\n }\n return undefined\n}\n\nfunction checkRouteFullPathUniqueness(\n _routes: Array<RouteNode>,\n config: Config,\n) {\n const routes = _routes.map((d) => {\n const inferredFullPath = inferFullPath(d)\n return { ...d, inferredFullPath }\n })\n\n const conflictingFiles = checkUnique(routes, 'inferredFullPath')\n\n if (conflictingFiles !== undefined) {\n const errorMessage = `Conflicting configuration paths were found for the following route${conflictingFiles.length > 1 ? 's' : ''}: ${conflictingFiles\n .map((p) => `\"${p.inferredFullPath}\"`)\n .join(', ')}.\nPlease ensure each Server Route has a unique full path.\nConflicting files: \\n ${conflictingFiles.map((d) => path.resolve(config.routesDirectory, d.filePath)).join('\\n ')}\\n`\n console.error(errorMessage)\n process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I,IAAI,CAAC,MAAM,IAAI,EAAE,gBAAgB,GAAG,EACpC,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA,GAEO,iBAAiB,IAAI,CAAC,MAAM,KAAK,QAAQ,OAAO,iBAAiB,EAAE,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA;AAC7G,YAAQ,MAAM,YAAY;AAC1B,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;"}
@@ -0,0 +1 @@
1
+ export declare function resolveViteId(id: string): string;
@@ -0,0 +1,7 @@
1
+ function resolveViteId(id) {
2
+ return `\0${id}`;
3
+ }
4
+ export {
5
+ resolveViteId
6
+ };
7
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function resolveViteId(id: string) {\n return `\\0${id}`\n}\n"],"names":[],"mappings":"AAAO,SAAS,cAAc,IAAY;AACxC,SAAO,KAAK,EAAE;AAChB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.121.0-alpha.6",
3
+ "version": "1.121.0-alpha.7",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -63,11 +63,11 @@
63
63
  "ufo": "^1.5.4",
64
64
  "xmlbuilder2": "^3.1.1",
65
65
  "zod": "^3.24.2",
66
- "@tanstack/router-generator": "^1.121.0-alpha.5",
66
+ "@tanstack/router-core": "^1.121.0-alpha.5",
67
67
  "@tanstack/router-plugin": "^1.121.0-alpha.5",
68
68
  "@tanstack/router-utils": "^1.121.0-alpha.2",
69
- "@tanstack/server-functions-plugin": "^1.121.0-alpha.2",
70
- "@tanstack/router-core": "^1.121.0-alpha.5"
69
+ "@tanstack/server-functions-plugin": "^1.121.0-alpha.7",
70
+ "@tanstack/router-generator": "^1.121.0-alpha.5"
71
71
  },
72
72
  "devDependencies": {
73
73
  "vite": "^6.0.0"
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@ export {
5
5
  } from './schema'
6
6
 
7
7
  export { TanStackStartVitePluginCore } from './plugin'
8
+ export { resolveViteId } from './utils'
package/src/plugin.ts CHANGED
@@ -141,8 +141,8 @@ export function TanStackStartVitePluginCore(
141
141
  '@tanstack/start-router-manifest',
142
142
  '@tanstack/start-config',
143
143
  '@tanstack/server-functions-plugin',
144
- 'tanstack:start-manifest',
145
- 'tanstack:server-fn-manifest',
144
+ 'tanstack-start-router-manifest:v',
145
+ 'tanstack-start-server-fn-manifest:v',
146
146
  'nitropack',
147
147
  '@tanstack/**',
148
148
  ],
@@ -166,7 +166,7 @@ export function TanStackStartVitePluginCore(
166
166
  TanStackServerFnPluginEnv({
167
167
  // This is the ID that will be available to look up and import
168
168
  // our server function manifest and resolve its module
169
- manifestVirtualImportId: 'tanstack:server-fn-manifest',
169
+ manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',
170
170
  client: {
171
171
  getRuntimeCode: () =>
172
172
  `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
@@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { joinURL } from 'ufo'
4
4
  import { rootRouteId } from '@tanstack/router-core'
5
+ import { resolveViteId } from './utils'
5
6
  import type {
6
7
  PluginOption,
7
8
  ResolvedConfig,
@@ -16,6 +17,9 @@ export function startManifestPlugin(
16
17
  ): PluginOption {
17
18
  let config: ResolvedConfig
18
19
 
20
+ const moduleId = 'tanstack-start-router-manifest:v'
21
+ const resolvedModuleId = resolveViteId(moduleId)
22
+
19
23
  return {
20
24
  name: 'tsr-routes-manifest',
21
25
  enforce: 'pre',
@@ -27,13 +31,13 @@ export function startManifestPlugin(
27
31
  // config = envConfig.
28
32
  // },
29
33
  resolveId(id) {
30
- if (id === 'tanstack:start-manifest') {
31
- return id
34
+ if (id === moduleId) {
35
+ return resolvedModuleId
32
36
  }
33
37
  return
34
38
  },
35
39
  load(id) {
36
- if (id === 'tanstack:start-manifest') {
40
+ if (id === resolvedModuleId) {
37
41
  if (this.environment.config.consumer !== 'server') {
38
42
  // this will ultimately fail the build if the plugin is used outside the server environment
39
43
  // TODO: do we need special handling for `serve`?
@@ -30,6 +30,7 @@ const setLock = (bool: boolean) => {
30
30
 
31
31
  export function TanStackStartServerRoutesVite(config: Config): Plugin {
32
32
  let ROOT: string = process.cwd()
33
+ const moduleId = 'tanstack-start-server-routes-manifest:v'
33
34
 
34
35
  const getRoutesDirectoryPath = () => {
35
36
  return isAbsolute(config.routesDirectory)
@@ -80,7 +81,7 @@ export function TanStackStartServerRoutesVite(config: Config): Plugin {
80
81
  },
81
82
  sharedDuringBuild: true,
82
83
  resolveId(id) {
83
- if (id === 'tanstack:server-routes') {
84
+ if (id === moduleId) {
84
85
  const generatedRouteTreePath = getGeneratedRouteTreePath(ROOT)
85
86
  return generatedRouteTreePath
86
87
  }
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function resolveViteId(id: string) {
2
+ return `\0${id}`
3
+ }