{"version":3,"file":"config.cjs","names":[],"sources":["../../../src/core/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n  configSchema as generatorConfigSchema,\n  getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport type {\n  CreateFileRoute,\n  RegisteredRouter,\n  RouteIds,\n} from '@tanstack/router-core'\nimport type { CodeSplitGroupings } from './constants'\n\nexport const splitGroupingsSchema = z\n  .array(\n    z.array(\n      z.union([\n        z.literal('loader'),\n        z.literal('component'),\n        z.literal('pendingComponent'),\n        z.literal('errorComponent'),\n        z.literal('notFoundComponent'),\n      ]),\n    ),\n    {\n      message:\n        \"  Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]\",\n    },\n  )\n  .superRefine((val, ctx) => {\n    const flattened = val.flat()\n    const unique = [...new Set(flattened)]\n\n    // Elements must be unique,\n    // ie. this shouldn't be allows [['component'], ['component', 'loader']]\n    if (unique.length !== flattened.length) {\n      ctx.addIssue({\n        code: 'custom',\n        message:\n          \"  Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\" +\n          `\\n  You input was: ${JSON.stringify(val)}.`,\n      })\n    }\n  })\n\nexport type CodeSplittingOptions = {\n  /**\n   * Use this function to programmatically control the code splitting behavior\n   * based on the `routeId` for each route.\n   *\n   * If you just need to change the default behavior, you can use the `defaultBehavior` option.\n   * @param params\n   */\n  splitBehavior?: (params: {\n    routeId: RouteIds<RegisteredRouter['routeTree']>\n  }) => CodeSplitGroupings | undefined | void\n\n  /**\n   * The default/global configuration to control your code splitting behavior per route.\n   * @default [['component'],['pendingComponent'],['errorComponent'],['notFoundComponent']]\n   */\n  defaultBehavior?: CodeSplitGroupings\n\n  /**\n   * The nodes that shall be deleted from the route.\n   * @default undefined\n   */\n  deleteNodes?: Array<DeletableNodes>\n\n  /**\n   * @default true\n   */\n  addHmr?: boolean\n}\n\nexport type HmrOptions = {\n  hotExpression?: string\n}\n\nconst codeSplittingOptionsSchema = z.object({\n  splitBehavior: z.function().optional(),\n  defaultBehavior: splitGroupingsSchema.optional(),\n  deleteNodes: z.array(z.string()).optional(),\n  addHmr: z.boolean().optional().default(true),\n})\n\ntype FileRouteKeys = keyof (Parameters<\n  CreateFileRoute<any, any, any, any, any>\n>[0] & {})\nexport type DeletableNodes = FileRouteKeys | (string & {})\n\nexport const configSchema = generatorConfigSchema.extend({\n  enableRouteGeneration: z.boolean().optional(),\n  codeSplittingOptions: z\n    .custom<CodeSplittingOptions>((v) => {\n      return codeSplittingOptionsSchema.parse(v)\n    })\n    .optional(),\n  plugin: z\n    .object({\n      hmr: z\n        .object({\n          hotExpression: z.string().optional(),\n        })\n        .optional(),\n      vite: z\n        .object({\n          environmentName: z.string().optional(),\n        })\n        .optional(),\n    })\n    .optional(),\n})\n\nexport const getConfig = (inlineConfig: Partial<Config>, root: string) => {\n  const config = getGeneratorConfig(inlineConfig, root)\n\n  return configSchema.parse({ ...inlineConfig, ...config })\n}\n\nexport type Config = z.infer<typeof configSchema>\nexport type ConfigInput = z.input<typeof configSchema>\nexport type ConfigOutput = z.output<typeof configSchema>\n"],"mappings":";;;;AAYA,IAAa,uBAAuB,IAAA,EACjC,MACC,IAAA,EAAE,MACA,IAAA,EAAE,MAAM;CACN,IAAA,EAAE,QAAQ,SAAS;CACnB,IAAA,EAAE,QAAQ,YAAY;CACtB,IAAA,EAAE,QAAQ,mBAAmB;CAC7B,IAAA,EAAE,QAAQ,iBAAiB;CAC3B,IAAA,EAAE,QAAQ,oBAAoB;CAC/B,CAAC,CACH,EACD,EACE,SACE,oJACH,CACF,CACA,aAAa,KAAK,QAAQ;CACzB,MAAM,YAAY,IAAI,MAAM;AAK5B,KAJe,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,CAI3B,WAAW,UAAU,OAC9B,KAAI,SAAS;EACX,MAAM;EACN,SACE,kKACsB,KAAK,UAAU,IAAI,CAAC;EAC7C,CAAC;EAEJ;AAoC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