create-payload-app 4.0.0-internal.f11981a → 4.0.0-internal.f2a04f7

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.
Files changed (115) hide show
  1. package/dist/lib/agent-config.d.ts +12 -0
  2. package/dist/lib/agent-config.d.ts.map +1 -0
  3. package/dist/lib/agent-config.js +15 -0
  4. package/dist/lib/agent-config.js.map +1 -0
  5. package/dist/lib/ast/payload-config.js +13 -13
  6. package/dist/lib/ast/payload-config.js.map +1 -1
  7. package/dist/lib/ast/types.d.ts +1 -1
  8. package/dist/lib/ast/types.d.ts.map +1 -1
  9. package/dist/lib/ast/types.js.map +1 -1
  10. package/dist/lib/configure-payload-config.js +1 -1
  11. package/dist/lib/configure-payload-config.js.map +1 -1
  12. package/dist/lib/create-project.d.ts +1 -2
  13. package/dist/lib/create-project.d.ts.map +1 -1
  14. package/dist/lib/create-project.js +56 -29
  15. package/dist/lib/create-project.js.map +1 -1
  16. package/dist/lib/generate-secret.js +1 -1
  17. package/dist/lib/generate-secret.js.map +1 -1
  18. package/dist/lib/get-package-manager.d.ts +9 -0
  19. package/dist/lib/get-package-manager.d.ts.map +1 -1
  20. package/dist/lib/get-package-manager.js +20 -0
  21. package/dist/lib/get-package-manager.js.map +1 -1
  22. package/dist/lib/init-next.d.ts +5 -0
  23. package/dist/lib/init-next.d.ts.map +1 -1
  24. package/dist/lib/init-next.js +14 -3
  25. package/dist/lib/init-next.js.map +1 -1
  26. package/dist/lib/init-tanstack.js +2 -3
  27. package/dist/lib/init-tanstack.js.map +1 -1
  28. package/dist/lib/tanstack/template-files.d.ts +4 -4
  29. package/dist/lib/tanstack/template-files.d.ts.map +1 -1
  30. package/dist/lib/tanstack/template-files.js +5 -5
  31. package/dist/lib/tanstack/template-files.js.map +1 -1
  32. package/dist/lib/tanstack/transform-root-route.d.ts.map +1 -1
  33. package/dist/lib/tanstack/transform-root-route.js +51 -1
  34. package/dist/lib/tanstack/transform-root-route.js.map +1 -1
  35. package/dist/lib/tanstack/transform-vite-config.d.ts.map +1 -1
  36. package/dist/lib/tanstack/transform-vite-config.js +47 -4
  37. package/dist/lib/tanstack/transform-vite-config.js.map +1 -1
  38. package/dist/lib/update-payload-in-project.d.ts.map +1 -1
  39. package/dist/lib/update-payload-in-project.js +7 -2
  40. package/dist/lib/update-payload-in-project.js.map +1 -1
  41. package/dist/main.d.ts.map +1 -1
  42. package/dist/main.js +2 -17
  43. package/dist/main.js.map +1 -1
  44. package/dist/template/src/app/(frontend)/styles.css +7 -0
  45. package/dist/template/src/app/(payload)/admin/[[...segments]]/not-found.tsx +1 -2
  46. package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +1 -2
  47. package/dist/template/src/app/(payload)/admin/importMap.js +15 -0
  48. package/dist/template/src/app/(payload)/api/[...slug]/route.ts +1 -2
  49. package/dist/template/src/app/(payload)/api/graphql/route.ts +1 -2
  50. package/dist/template/src/app/(payload)/api/graphql-playground/route.ts +1 -2
  51. package/dist/template/src/app/(payload)/layout.tsx +1 -2
  52. package/dist/template/src/payload.config.ts +5 -3
  53. package/dist/template-tanstack/routes/_payload/admin.$.tsx +20 -3
  54. package/dist/template-tanstack/routes/_payload/admin.index.tsx +20 -3
  55. package/dist/template-tanstack/routes/_payload/api.$.ts +1 -0
  56. package/dist/template-tanstack/routes/_payload/custom.css +0 -0
  57. package/dist/template-tanstack/routes/_payload/server.functions.ts +1 -0
  58. package/dist/template-tanstack/routes/_payload.tsx +21 -5
  59. package/dist/template-tanstack/src/payload.config.ts +1 -3
  60. package/dist/types.d.ts +0 -3
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/types.js.map +1 -1
  63. package/dist/utils/messages.d.ts.map +1 -1
  64. package/dist/utils/messages.js +3 -6
  65. package/dist/utils/messages.js.map +1 -1
  66. package/dist/utils/resolvePackageVersion.d.ts +10 -4
  67. package/dist/utils/resolvePackageVersion.d.ts.map +1 -1
  68. package/dist/utils/resolvePackageVersion.js +24 -3
  69. package/dist/utils/resolvePackageVersion.js.map +1 -1
  70. package/package.json +18 -18
  71. package/dist/ast-integration.spec.js +0 -132
  72. package/dist/ast-integration.spec.js.map +0 -1
  73. package/dist/lib/ast/package-json.spec.js +0 -139
  74. package/dist/lib/ast/package-json.spec.js.map +0 -1
  75. package/dist/lib/ast/payload-config.spec.js +0 -365
  76. package/dist/lib/ast/payload-config.spec.js.map +0 -1
  77. package/dist/lib/ast/utils.spec.js +0 -226
  78. package/dist/lib/ast/utils.spec.js.map +0 -1
  79. package/dist/lib/configure-payload-tsconfig.spec.js +0 -135
  80. package/dist/lib/configure-payload-tsconfig.spec.js.map +0 -1
  81. package/dist/lib/create-project.spec.js +0 -199
  82. package/dist/lib/create-project.spec.js.map +0 -1
  83. package/dist/lib/download-skill.d.ts +0 -8
  84. package/dist/lib/download-skill.d.ts.map +0 -1
  85. package/dist/lib/download-skill.js +0 -35
  86. package/dist/lib/download-skill.js.map +0 -1
  87. package/dist/lib/init-tanstack-default-template.spec.js +0 -119
  88. package/dist/lib/init-tanstack-default-template.spec.js.map +0 -1
  89. package/dist/lib/init-tanstack.spec.js +0 -394
  90. package/dist/lib/init-tanstack.spec.js.map +0 -1
  91. package/dist/lib/manage-env-files.spec.js +0 -118
  92. package/dist/lib/manage-env-files.spec.js.map +0 -1
  93. package/dist/lib/select-agent.d.ts +0 -16
  94. package/dist/lib/select-agent.d.ts.map +0 -1
  95. package/dist/lib/select-agent.js +0 -67
  96. package/dist/lib/select-agent.js.map +0 -1
  97. package/dist/lib/tanstack/detect.spec.js +0 -227
  98. package/dist/lib/tanstack/detect.spec.js.map +0 -1
  99. package/dist/lib/tanstack/prepare.spec.js +0 -288
  100. package/dist/lib/tanstack/prepare.spec.js.map +0 -1
  101. package/dist/lib/tanstack/transform-root-route.spec.js +0 -448
  102. package/dist/lib/tanstack/transform-root-route.spec.js.map +0 -1
  103. package/dist/lib/tanstack/transform-router.spec.js +0 -264
  104. package/dist/lib/tanstack/transform-router.spec.js.map +0 -1
  105. package/dist/lib/tanstack/transform-vite-config.spec.js +0 -450
  106. package/dist/lib/tanstack/transform-vite-config.spec.js.map +0 -1
  107. package/dist/lib/update-payload-in-project.spec.js +0 -258
  108. package/dist/lib/update-payload-in-project.spec.js.map +0 -1
  109. package/dist/lib/wrap-next-config.spec.js +0 -167
  110. package/dist/lib/wrap-next-config.spec.js.map +0 -1
  111. package/dist/main.spec.js +0 -102
  112. package/dist/main.spec.js.map +0 -1
  113. package/dist/template-tanstack/src/payload-foundation.css +0 -10
  114. package/dist/utils/resolvePackageVersion.spec.js +0 -77
  115. package/dist/utils/resolvePackageVersion.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/tanstack/transform-root-route.ts"],"sourcesContent":["import type {\n ArrayLiteralExpression,\n FunctionDeclaration,\n ImportDeclaration,\n JsxSelfClosingElement,\n Node as MorphNode,\n ObjectLiteralExpression,\n PropertyAssignment,\n SourceFile,\n} from 'ts-morph'\n\nimport { Node, Project, QuoteKind, SyntaxKind } from 'ts-morph'\n\nimport type { TanStackAppDetails } from '../../types.js'\nimport type { TextTransformResult } from './transform-vite-config.js'\n\ntype LocalBinding =\n | {\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n isTypeOnly: boolean\n kind: 'import'\n moduleSpecifier: string\n }\n | { kind: 'other' | 'variable' }\n\ntype NamedImport = { declaration: ImportDeclaration; localName: string }\n\nconst PAYLOAD_CLIENT_MODULE = '@payloadcms/tanstack-start/client'\nconst ROUTER_MODULE = '@tanstack/react-router'\n\nexport function transformTanStackRootRoute({\n content,\n kind,\n}: {\n content: string\n kind: TanStackAppDetails['kind']\n}): TextTransformResult {\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n useInMemoryFileSystem: true,\n })\n const sourceFile = project.createSourceFile('__root.tsx', content)\n const createRootRouteImport = getNamedImport({\n importedName: 'createRootRoute',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n\n if (!createRootRouteImport) {\n return failure('Could not identify the createRootRoute import.')\n }\n\n const createRootRouteCalls = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((call) => call.getExpression().getText() === createRootRouteImport.localName)\n\n if (createRootRouteCalls.length !== 1) {\n return failure('Expected exactly one createRootRoute() call.')\n }\n\n const createRootRouteCall = createRootRouteCalls[0]!\n if (createRootRouteCall.getArguments().length !== 1) {\n return failure('createRootRoute() must receive exactly one argument.')\n }\n\n const rootObject = createRootRouteCall.getArguments()[0]\n if (!Node.isObjectLiteralExpression(rootObject)) {\n return failure('createRootRoute() must receive an object literal.')\n }\n\n if (rootObject.getProperties().some(Node.isSpreadAssignment)) {\n return failure('Root route object spreads cannot be transformed safely.')\n }\n\n return kind === 'start'\n ? transformStartRoot({ content, rootObject, sourceFile })\n : transformRouterOnlyRoot({ content, rootObject, sourceFile })\n}\n\nfunction bindingNameIncludes({ localName, node }: { localName: string; node: MorphNode }): boolean {\n if (Node.isIdentifier(node)) {\n return node.getText() === localName\n }\n\n if (Node.isArrayBindingPattern(node) || Node.isObjectBindingPattern(node)) {\n return node\n .getElements()\n .some(\n (element) =>\n Node.isBindingElement(element) &&\n bindingNameIncludes({ localName, node: element.getNameNode() }),\n )\n }\n\n return false\n}\n\nfunction ensureNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const declaration = sourceFile\n .getImportDeclarations()\n .find(\n (candidate) =>\n candidate.getModuleSpecifierValue() === moduleSpecifier &&\n !candidate.isTypeOnly() &&\n !candidate.getNamespaceImport(),\n )\n\n if (\n declaration\n ?.getNamedImports()\n .some((namedImport) => namedImport.getName() === importedName && !namedImport.getAliasNode())\n ) {\n return\n }\n\n if (declaration) {\n declaration.addNamedImport(importedName)\n } else {\n sourceFile.addImportDeclaration({ moduleSpecifier, namedImports: [importedName] })\n }\n}\n\nfunction failure(reason: string): TextTransformResult {\n return { reason, success: false }\n}\n\nfunction getAppStylesheetImport({\n requireSideEffect,\n sourceFile,\n}: {\n requireSideEffect: boolean\n sourceFile: SourceFile\n}): { declaration: ImportDeclaration; localName?: string; moduleSpecifier: string } | undefined {\n const imports = sourceFile.getImportDeclarations().filter((declaration) => {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const isStylesheet = requireSideEffect\n ? /\\.css$/.test(moduleSpecifier)\n : /\\.css\\?url$/.test(moduleSpecifier)\n\n if (!isStylesheet) {\n return false\n }\n\n const hasNamedOrNamespaceImport =\n declaration.getNamedImports().length > 0 || Boolean(declaration.getNamespaceImport())\n return requireSideEffect\n ? !declaration.getDefaultImport() && !hasNamedOrNamespaceImport\n : Boolean(declaration.getDefaultImport()) && !hasNamedOrNamespaceImport\n })\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const declaration = imports[0]!\n return {\n declaration,\n localName: declaration.getDefaultImport()?.getText(),\n moduleSpecifier: declaration.getModuleSpecifierValue(),\n }\n}\n\nfunction getFunction({\n functionName,\n sourceFile,\n}: {\n functionName: string\n sourceFile: SourceFile\n}): FunctionDeclaration | undefined {\n const functions = sourceFile\n .getFunctions()\n .filter((declaration) => declaration.getName() === functionName)\n\n return functions.length === 1 ? functions[0] : undefined\n}\n\nfunction getHeadContentNode({\n functionDeclaration,\n localName,\n}: {\n functionDeclaration: FunctionDeclaration\n localName: string\n}): JsxSelfClosingElement | undefined {\n const matches = functionDeclaration\n .getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n .filter((element) => element.getTagNameNode().getText() === localName)\n\n return matches.length === 1 ? matches[0] : undefined\n}\n\nfunction getLocalBindings({\n localName,\n sourceFile,\n}: {\n localName: string\n sourceFile: SourceFile\n}): LocalBinding[] {\n const bindings: LocalBinding[] = []\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const defaultImport = declaration.getDefaultImport()\n if (defaultImport?.getText() === localName) {\n bindings.push({\n importKind: 'default',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n const namespaceImport = declaration.getNamespaceImport()\n if (namespaceImport?.getText() === localName) {\n bindings.push({\n importKind: 'namespace',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n const namedImportLocalName = namedImport.getAliasNode()?.getText() ?? namedImport.getName()\n if (namedImportLocalName === localName) {\n bindings.push({\n importedName: namedImport.getName(),\n importKind: 'named',\n isTypeOnly: declaration.isTypeOnly() || namedImport.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n }\n }\n\n for (const declaration of sourceFile.getVariableDeclarations()) {\n if (bindingNameIncludes({ localName, node: declaration.getNameNode() })) {\n bindings.push({ kind: 'variable' })\n }\n }\n\n const hasOtherDeclaration = [\n ...sourceFile.getClasses(),\n ...sourceFile.getEnums(),\n ...sourceFile.getFunctions(),\n ...sourceFile.getModules(),\n ].some((declaration) => declaration.getName() === localName)\n\n if (hasOtherDeclaration) {\n bindings.push({ kind: 'other' })\n }\n\n return bindings\n}\n\nfunction getNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}): NamedImport | undefined {\n const imports = sourceFile.getImportDeclarations().flatMap((declaration) =>\n declaration.getModuleSpecifierValue() === moduleSpecifier\n ? declaration\n .getNamedImports()\n .filter((namedImport) => namedImport.getName() === importedName)\n .map((namedImport) => ({\n declaration,\n localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName(),\n }))\n : [],\n )\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const imported = imports[0]!\n const bindings = getLocalBindings({ localName: imported.localName, sourceFile })\n const binding = bindings[0]\n\n if (\n bindings.length !== 1 ||\n binding?.kind !== 'import' ||\n binding.importKind !== 'named' ||\n binding.importedName !== importedName ||\n binding.isTypeOnly ||\n binding.moduleSpecifier !== moduleSpecifier\n ) {\n return undefined\n }\n\n return imported\n}\n\nfunction resolveRouterNamedImport({\n importedName,\n sourceFile,\n}: {\n importedName: 'HeadContent' | 'Scripts'\n sourceFile: SourceFile\n}):\n | { importedName: string; isPresent: boolean; localName: string; success: true }\n | { reason: string; success: false } {\n const matchingImports = sourceFile.getImportDeclarations().flatMap((declaration) =>\n declaration.getModuleSpecifierValue() === ROUTER_MODULE && !declaration.isTypeOnly()\n ? declaration\n .getNamedImports()\n .filter(\n (namedImport) => namedImport.getName() === importedName && !namedImport.isTypeOnly(),\n )\n .map((namedImport) => namedImport.getAliasNode()?.getText() ?? namedImport.getName())\n : [],\n )\n\n if (matchingImports.length > 1) {\n return {\n reason: `The TanStack router module imports ${importedName} more than once.`,\n success: false,\n }\n }\n\n const localName = matchingImports[0] ?? importedName\n const bindings = getLocalBindings({ localName, sourceFile })\n const binding = bindings[0]\n const isCompatible =\n binding?.kind === 'import' &&\n binding.importKind === 'named' &&\n binding.importedName === importedName &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === ROUTER_MODULE\n\n if (bindings.length > 0 && (bindings.length !== 1 || !isCompatible)) {\n return {\n reason: `Identifier \"${localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n\n return { importedName, isPresent: matchingImports.length === 1, localName, success: true }\n}\n\nfunction getSideEffectStylesheetImports(sourceFile: SourceFile): ImportDeclaration[] {\n return sourceFile\n .getImportDeclarations()\n .filter(\n (declaration) =>\n /\\.css$/.test(declaration.getModuleSpecifierValue()) &&\n !declaration.getDefaultImport() &&\n !declaration.getNamespaceImport() &&\n declaration.getNamedImports().length === 0,\n )\n}\n\nfunction getPropertyName(node: MorphNode): string | undefined {\n if (\n Node.isPropertyAssignment(node) ||\n Node.isShorthandPropertyAssignment(node) ||\n Node.isMethodDeclaration(node) ||\n Node.isGetAccessorDeclaration(node) ||\n Node.isSetAccessorDeclaration(node)\n ) {\n return node.getName()\n }\n}\n\nfunction getPropertyAssignment({\n object,\n propertyName,\n}: {\n object: ObjectLiteralExpression\n propertyName: string\n}) {\n const properties = object\n .getProperties()\n .filter((property) => getPropertyName(property) === propertyName)\n\n return properties.length === 1 && Node.isPropertyAssignment(properties[0])\n ? properties[0]\n : undefined\n}\n\nfunction getRootHeadLinks(\n rootObject: ObjectLiteralExpression,\n): { links: ArrayLiteralExpression; success: true } | { reason: string; success: false } {\n const headProperty = getPropertyAssignment({ object: rootObject, propertyName: 'head' })\n const headInitializer = headProperty?.getInitializer()\n if (!headInitializer || !Node.isArrowFunction(headInitializer)) {\n return { reason: 'The root head declaration cannot be transformed safely.', success: false }\n }\n\n const body = headInitializer.getBody()\n const headObject = Node.isParenthesizedExpression(body) ? body.getExpression() : body\n if (!Node.isObjectLiteralExpression(headObject)) {\n return { reason: 'The root head declaration cannot be transformed safely.', success: false }\n }\n\n const linksProperty = getPropertyAssignment({ object: headObject, propertyName: 'links' })\n const links = linksProperty?.getInitializer()\n if (\n !links ||\n !Node.isArrayLiteralExpression(links) ||\n links.getElements().some(Node.isSpreadElement)\n ) {\n return { reason: 'The root head links cannot be transformed safely.', success: false }\n }\n\n return { links, success: true }\n}\n\nfunction getShellState({\n expectedComponent,\n rootObject,\n withPayloadRootLocalName,\n}: {\n expectedComponent?: string\n rootObject: ObjectLiteralExpression\n withPayloadRootLocalName: string\n}):\n | { componentName: string; isWrapped: boolean; property?: PropertyAssignment; success: true }\n | { reason: string; success: false } {\n const properties = rootObject\n .getProperties()\n .filter((property) => getPropertyName(property) === 'shellComponent')\n\n if (properties.length === 0) {\n if (!expectedComponent) {\n return { componentName: 'RootDocument', isWrapped: false, success: true }\n }\n\n return {\n reason: 'The existing shellComponent cannot be transformed safely.',\n success: false,\n }\n }\n\n const property = properties[0]\n if (properties.length !== 1 || !property || !Node.isPropertyAssignment(property)) {\n return {\n reason: 'The existing shellComponent cannot be transformed safely.',\n success: false,\n }\n }\n\n const initializer = property.getInitializer()\n if (\n Node.isIdentifier(initializer) &&\n (!expectedComponent || initializer.getText() === expectedComponent)\n ) {\n return {\n componentName: initializer.getText(),\n isWrapped: false,\n property,\n success: true,\n }\n }\n\n if (\n Node.isCallExpression(initializer) &&\n initializer.getExpression().getText() === withPayloadRootLocalName &&\n initializer.getArguments().length === 1 &&\n Node.isIdentifier(initializer.getArguments()[0]) &&\n (!expectedComponent || initializer.getArguments()[0]!.getText() === expectedComponent)\n ) {\n return {\n componentName: initializer.getArguments()[0]!.getText(),\n isWrapped: true,\n property,\n success: true,\n }\n }\n\n return {\n reason: 'The existing shellComponent cannot be transformed safely.',\n success: false,\n }\n}\n\nfunction getStylesheetAttribute({\n name,\n element,\n}: {\n element: JsxSelfClosingElement\n name: string\n}): string | undefined {\n const attribute = element\n .getAttributes()\n .find(\n (candidate) => Node.isJsxAttribute(candidate) && candidate.getNameNode().getText() === name,\n )\n\n if (!attribute || !Node.isJsxAttribute(attribute)) {\n return undefined\n }\n\n const initializer = attribute.getInitializer()\n if (Node.isStringLiteral(initializer)) {\n return initializer.getLiteralValue()\n }\n\n if (Node.isJsxExpression(initializer)) {\n return initializer.getExpression()?.getText()\n }\n}\n\nfunction transformRouterOnlyRoot({\n content,\n rootObject,\n sourceFile,\n}: {\n content: string\n rootObject: ObjectLiteralExpression\n sourceFile: SourceFile\n}): TextTransformResult {\n const withPayloadRootImport = getNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n const withPayloadRootLocalName = withPayloadRootImport?.localName ?? 'withPayloadRoot'\n const shellState = getShellState({ rootObject, withPayloadRootLocalName })\n if (!shellState.success) {\n return shellState\n }\n\n if (shellState.property && !shellState.isWrapped) {\n return failure('The existing shellComponent cannot be transformed safely.')\n }\n\n if (shellState.isWrapped && getSideEffectStylesheetImports(sourceFile).length > 0) {\n return failure('Side-effect stylesheet imports cannot be isolated from admin.')\n }\n\n const headContentImport = resolveRouterNamedImport({\n importedName: 'HeadContent',\n sourceFile,\n })\n if (!headContentImport.success) {\n return headContentImport\n }\n\n const scriptsImport = resolveRouterNamedImport({ importedName: 'Scripts', sourceFile })\n if (!scriptsImport.success) {\n return scriptsImport\n }\n\n const destinationValidation = validateRouterOnlyDestinations({\n isAlreadyWrapped: shellState.isWrapped,\n sourceFile,\n withPayloadRootLocalName,\n })\n if (!destinationValidation.success) {\n return destinationValidation\n }\n\n if (shellState.isWrapped) {\n const stylesheetImport = getAppStylesheetImport({ requireSideEffect: false, sourceFile })\n const rootDocument = getFunction({ functionName: 'RootDocument', sourceFile })\n if (\n !stylesheetImport ||\n stylesheetImport.localName !== 'appCss' ||\n !rootDocument ||\n !hasValidAppStylesheetLink({\n functionDeclaration: rootDocument,\n headContentLocalName: headContentImport.localName,\n localName: 'appCss',\n })\n ) {\n return failure('The existing Payload root shell does not match the supported configuration.')\n }\n\n const hasWithPayloadImport = Boolean(withPayloadRootImport)\n const hasAllRequiredImports =\n hasWithPayloadImport && headContentImport.isPresent && scriptsImport.isPresent\n\n if (!hasAllRequiredImports) {\n if (!hasWithPayloadImport) {\n ensureNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n }\n if (!headContentImport.isPresent) {\n ensureNamedImport({\n importedName: 'HeadContent',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n }\n if (!scriptsImport.isPresent) {\n ensureNamedImport({\n importedName: 'Scripts',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n }\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n }\n\n return { content, modified: false, success: true }\n }\n\n const sideEffectStylesheets = getSideEffectStylesheetImports(sourceFile)\n\n if (sideEffectStylesheets.length !== 1) {\n return failure('Expected exactly one side-effect stylesheet import.')\n }\n\n const stylesheetImport = sideEffectStylesheets[0]!\n const componentProperties = rootObject\n .getProperties()\n .filter((property) => getPropertyName(property) === 'component')\n if (componentProperties.length !== 1) {\n return failure('The Router-only root must contain exactly one component option.')\n }\n\n stylesheetImport.setDefaultImport('appCss')\n stylesheetImport.setModuleSpecifier(`${stylesheetImport.getModuleSpecifierValue()}?url`)\n rootObject.addPropertyAssignment({\n name: 'shellComponent',\n initializer: `${withPayloadRootLocalName}(RootDocument)`,\n })\n if (!withPayloadRootImport) {\n ensureNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n }\n if (!headContentImport.isPresent) {\n ensureNamedImport({ importedName: 'HeadContent', moduleSpecifier: ROUTER_MODULE, sourceFile })\n }\n if (!scriptsImport.isPresent) {\n ensureNamedImport({ importedName: 'Scripts', moduleSpecifier: ROUTER_MODULE, sourceFile })\n }\n sourceFile.addStatements(`\nfunction RootDocument({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\" suppressHydrationWarning>\n <head>\n <link href={appCss} rel=\"stylesheet\" />\n <${headContentImport.localName} />\n </head>\n <body>\n {children}\n <${scriptsImport.localName} />\n </body>\n </html>\n )\n}`)\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction transformStartRoot({\n content,\n rootObject,\n sourceFile,\n}: {\n content: string\n rootObject: ObjectLiteralExpression\n sourceFile: SourceFile\n}): TextTransformResult {\n if (getSideEffectStylesheetImports(sourceFile).length > 0) {\n return failure('Side-effect stylesheet imports cannot be isolated from admin.')\n }\n\n const withPayloadRootImport = getNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n const withPayloadRootLocalName = withPayloadRootImport?.localName ?? 'withPayloadRoot'\n const shellState = getShellState({\n expectedComponent: undefined,\n rootObject,\n withPayloadRootLocalName,\n })\n if (!shellState.success || !shellState.property) {\n return shellState.success\n ? failure('The existing shellComponent cannot be transformed safely.')\n : shellState\n }\n\n const withPayloadValidation = validateNamedDestination({\n importedName: 'withPayloadRoot',\n localName: withPayloadRootLocalName,\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n if (!withPayloadValidation.success) {\n return withPayloadValidation\n }\n const hasWithPayloadImport = Boolean(withPayloadRootImport)\n\n const headContentImport = getNamedImport({\n importedName: 'HeadContent',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n const scriptsImport = getNamedImport({\n importedName: 'Scripts',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n if (!headContentImport || !scriptsImport) {\n return failure('Could not identify the Start document imports.')\n }\n\n const stylesheetImport = getAppStylesheetImport({ requireSideEffect: false, sourceFile })\n if (!stylesheetImport?.localName) {\n return failure('Could not identify the app stylesheet import.')\n }\n\n const stylesheetBindings = getLocalBindings({ localName: stylesheetImport.localName, sourceFile })\n const stylesheetBinding = stylesheetBindings[0]\n if (\n stylesheetBindings.length !== 1 ||\n stylesheetBinding?.kind !== 'import' ||\n stylesheetBinding.importKind !== 'default' ||\n stylesheetBinding.isTypeOnly ||\n stylesheetBinding.moduleSpecifier !== stylesheetImport.moduleSpecifier\n ) {\n return failure(`Identifier \"${stylesheetImport.localName}\" is already bound incompatibly.`)\n }\n\n const rootDocument = getFunction({ functionName: shellState.componentName, sourceFile })\n if (!rootDocument) {\n return failure('Could not identify the Start root document component.')\n }\n\n const headContentNode = getHeadContentNode({\n functionDeclaration: rootDocument,\n localName: headContentImport.localName,\n })\n if (!headContentNode) {\n return failure('Could not identify HeadContent in the Start root document.')\n }\n\n const headLinks = getRootHeadLinks(rootObject)\n if (!headLinks.success) {\n return headLinks\n }\n\n let stylesheetIndex = -1\n for (const [index, element] of headLinks.links.getElements().entries()) {\n if (!Node.isObjectLiteralExpression(element)) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n if (element.getProperties().some(Node.isSpreadAssignment)) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n const rel = getStaticObjectPropertyValue({ object: element, propertyName: 'rel' })\n if (rel !== 'stylesheet') {\n continue\n }\n\n const hrefProperty = getPropertyAssignment({ object: element, propertyName: 'href' })\n if (\n hrefProperty?.getInitializer()?.getText() !== stylesheetImport.localName ||\n stylesheetIndex !== -1\n ) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n stylesheetIndex = index\n }\n\n const hasStylesheetLink = hasValidAppStylesheetLink({\n functionDeclaration: rootDocument,\n headContentLocalName: headContentImport.localName,\n localName: stylesheetImport.localName,\n })\n if (stylesheetIndex === -1 && !hasStylesheetLink) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n if (shellState.isWrapped && stylesheetIndex === -1 && hasStylesheetLink && hasWithPayloadImport) {\n return { content, modified: false, success: true }\n }\n\n if (stylesheetIndex !== -1) {\n headLinks.links.removeElement(stylesheetIndex)\n }\n if (!hasStylesheetLink) {\n headContentNode.replaceWithText(\n `<link href={${stylesheetImport.localName}} rel=\"stylesheet\" />\\n<${headContentImport.localName} />`,\n )\n }\n if (!shellState.isWrapped) {\n shellState.property.setInitializer(`${withPayloadRootLocalName}(${shellState.componentName})`)\n }\n if (!withPayloadRootImport) {\n ensureNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n }\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction getStaticObjectPropertyValue({\n object,\n propertyName,\n}: {\n object: ObjectLiteralExpression\n propertyName: string\n}): string | undefined {\n const property = getPropertyAssignment({ object, propertyName })\n const initializer = property?.getInitializer()\n\n return Node.isStringLiteral(initializer) ? initializer.getLiteralValue() : undefined\n}\n\nfunction hasValidAppStylesheetLink({\n functionDeclaration,\n headContentLocalName,\n localName,\n}: {\n functionDeclaration: FunctionDeclaration\n headContentLocalName: string\n localName: string\n}): boolean {\n const links = functionDeclaration\n .getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n .filter(\n (element) =>\n element.getTagNameNode().getText() === 'link' &&\n getStylesheetAttribute({ name: 'href', element }) === localName &&\n getStylesheetAttribute({ name: 'rel', element }) === 'stylesheet',\n )\n\n const headContentElements = functionDeclaration\n .getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n .filter((element) => element.getTagNameNode().getText() === headContentLocalName)\n\n if (links.length !== 1 || headContentElements.length !== 1) {\n return false\n }\n\n const link = links[0]!\n const headContent = headContentElements[0]!\n const linkParent = link.getFirstAncestorByKind(SyntaxKind.JsxElement)\n const headContentParent = headContent.getFirstAncestorByKind(SyntaxKind.JsxElement)\n\n return (\n linkParent?.getStart() === headContentParent?.getStart() &&\n linkParent?.getOpeningElement().getTagNameNode().getText() === 'head' &&\n link.getStart() < headContent.getStart()\n )\n}\n\nfunction validateNamedDestination({\n importedName,\n localName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n localName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}): { reason: string; success: false } | { success: true } {\n const bindings = getLocalBindings({ localName, sourceFile })\n const binding = bindings[0]\n const isCompatible =\n binding?.kind === 'import' &&\n binding.importKind === 'named' &&\n binding.importedName === importedName &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === moduleSpecifier\n\n if (bindings.length > 0 && (bindings.length !== 1 || !isCompatible)) {\n return {\n reason: `Identifier \"${localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n\n return { success: true }\n}\n\nfunction validateRouterOnlyDestinations({\n isAlreadyWrapped,\n sourceFile,\n withPayloadRootLocalName,\n}: {\n isAlreadyWrapped: boolean\n sourceFile: SourceFile\n withPayloadRootLocalName: string\n}): { reason: string; success: false } | { success: true } {\n const destinations = [\n {\n importedName: 'withPayloadRoot',\n localName: withPayloadRootLocalName,\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n },\n ]\n\n for (const destination of destinations) {\n const validation = validateNamedDestination({ ...destination, sourceFile })\n if (!validation.success) {\n return validation\n }\n }\n\n for (const localName of ['appCss', 'RootDocument']) {\n const bindings = getLocalBindings({ localName, sourceFile })\n if (bindings.length === 0) {\n continue\n }\n\n const binding = bindings[0]\n const isCompatible =\n isAlreadyWrapped &&\n bindings.length === 1 &&\n (localName === 'RootDocument'\n ? binding?.kind === 'other'\n : binding?.kind === 'import' &&\n binding.importKind === 'default' &&\n !binding.isTypeOnly &&\n /\\.css\\?url$/.test(binding.moduleSpecifier))\n\n if (!isCompatible) {\n return {\n reason: `Identifier \"${localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n }\n\n return { success: true }\n}\n"],"names":["Node","Project","QuoteKind","SyntaxKind","PAYLOAD_CLIENT_MODULE","ROUTER_MODULE","transformTanStackRootRoute","content","kind","project","manipulationSettings","quoteKind","Single","useInMemoryFileSystem","sourceFile","createSourceFile","createRootRouteImport","getNamedImport","importedName","moduleSpecifier","failure","createRootRouteCalls","getDescendantsOfKind","CallExpression","filter","call","getExpression","getText","localName","length","createRootRouteCall","getArguments","rootObject","isObjectLiteralExpression","getProperties","some","isSpreadAssignment","transformStartRoot","transformRouterOnlyRoot","bindingNameIncludes","node","isIdentifier","isArrayBindingPattern","isObjectBindingPattern","getElements","element","isBindingElement","getNameNode","ensureNamedImport","declaration","getImportDeclarations","find","candidate","getModuleSpecifierValue","isTypeOnly","getNamespaceImport","getNamedImports","namedImport","getName","getAliasNode","addNamedImport","addImportDeclaration","namedImports","reason","success","getAppStylesheetImport","requireSideEffect","imports","isStylesheet","test","hasNamedOrNamespaceImport","Boolean","getDefaultImport","undefined","getFunction","functionName","functions","getFunctions","getHeadContentNode","functionDeclaration","matches","JsxSelfClosingElement","getTagNameNode","getLocalBindings","bindings","defaultImport","push","importKind","namespaceImport","namedImportLocalName","getVariableDeclarations","hasOtherDeclaration","getClasses","getEnums","getModules","flatMap","map","imported","binding","resolveRouterNamedImport","matchingImports","isCompatible","isPresent","getSideEffectStylesheetImports","getPropertyName","isPropertyAssignment","isShorthandPropertyAssignment","isMethodDeclaration","isGetAccessorDeclaration","isSetAccessorDeclaration","getPropertyAssignment","object","propertyName","properties","property","getRootHeadLinks","headProperty","headInitializer","getInitializer","isArrowFunction","body","getBody","headObject","isParenthesizedExpression","linksProperty","links","isArrayLiteralExpression","isSpreadElement","getShellState","expectedComponent","withPayloadRootLocalName","componentName","isWrapped","initializer","isCallExpression","getStylesheetAttribute","name","attribute","getAttributes","isJsxAttribute","isStringLiteral","getLiteralValue","isJsxExpression","withPayloadRootImport","shellState","headContentImport","scriptsImport","destinationValidation","validateRouterOnlyDestinations","isAlreadyWrapped","stylesheetImport","rootDocument","hasValidAppStylesheetLink","headContentLocalName","hasWithPayloadImport","hasAllRequiredImports","formatText","indentSize","getFullText","modified","sideEffectStylesheets","componentProperties","setDefaultImport","setModuleSpecifier","addPropertyAssignment","addStatements","withPayloadValidation","validateNamedDestination","stylesheetBindings","stylesheetBinding","headContentNode","headLinks","stylesheetIndex","index","entries","rel","getStaticObjectPropertyValue","hrefProperty","hasStylesheetLink","removeElement","replaceWithText","setInitializer","headContentElements","link","headContent","linkParent","getFirstAncestorByKind","JsxElement","headContentParent","getStart","getOpeningElement","destinations","destination","validation"],"mappings":"AAWA,SAASA,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,UAAU,QAAQ,WAAU;AAiB/D,MAAMC,wBAAwB;AAC9B,MAAMC,gBAAgB;AAEtB,OAAO,SAASC,2BAA2B,EACzCC,OAAO,EACPC,IAAI,EAIL;IACC,MAAMC,UAAU,IAAIR,QAAQ;QAC1BS,sBAAsB;YAAEC,WAAWT,UAAUU,MAAM;QAAC;QACpDC,uBAAuB;IACzB;IACA,MAAMC,aAAaL,QAAQM,gBAAgB,CAAC,cAAcR;IAC1D,MAAMS,wBAAwBC,eAAe;QAC3CC,cAAc;QACdC,iBAAiBd;QACjBS;IACF;IAEA,IAAI,CAACE,uBAAuB;QAC1B,OAAOI,QAAQ;IACjB;IAEA,MAAMC,uBAAuBP,WAC1BQ,oBAAoB,CAACnB,WAAWoB,cAAc,EAC9CC,MAAM,CAAC,CAACC,OAASA,KAAKC,aAAa,GAAGC,OAAO,OAAOX,sBAAsBY,SAAS;IAEtF,IAAIP,qBAAqBQ,MAAM,KAA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AAiB;YAAEvD;YAAWd;QAAW;QAC1D,IAAIsE,SAASvD,MAAM,KAAK,GAAG;YACzB;QACF;QAEA,MAAMqE,UAAUd,QAAQ,CAAC,EAAE;QAC3B,MAAMiB,eACJgD,oBACAjE,SAASvD,MAAM,KAAK,KACnBD,CAAAA,cAAc,iBACXsE,SAAS1F,SAAS,UAClB0F,SAAS1F,SAAS,YAClB0F,QAAQX,UAAU,KAAK,aACvB,CAACW,QAAQ5C,UAAU,IACnB,cAAce,IAAI,CAAC6B,QAAQ/E,eAAe,CAAA;QAEhD,IAAI,CAACkF,cAAc;YACjB,OAAO;gBACLtC,QAAQ,CAAC,YAAY,EAAEnC,UAAU,gCAAgC,CAAC;gBAClEoC,SAAS;YACX;QACF;IACF;IAEA,OAAO;QAAEA,SAAS;IAAK;AACzB"}
1
+ {"version":3,"sources":["../../../src/lib/tanstack/transform-root-route.ts"],"sourcesContent":["import type {\n ArrayLiteralExpression,\n ArrowFunction,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n ImportDeclaration,\n JsxSelfClosingElement,\n Node as MorphNode,\n ObjectLiteralExpression,\n PropertyAssignment,\n SourceFile,\n} from 'ts-morph'\n\nimport { Node, Project, QuoteKind, SyntaxKind } from 'ts-morph'\n\nimport type { TanStackAppDetails } from '../../types.js'\nimport type { TextTransformResult } from './transform-vite-config.js'\n\ntype LocalBinding =\n | {\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n isTypeOnly: boolean\n kind: 'import'\n moduleSpecifier: string\n }\n | { kind: 'other' | 'variable' }\n\ntype NamedImport = { declaration: ImportDeclaration; localName: string }\ntype RouteComponentFunction = ArrowFunction | FunctionDeclaration | FunctionExpression\n\nconst PAYLOAD_CLIENT_MODULE = '@payloadcms/tanstack-start/client'\nconst ROUTER_MODULE = '@tanstack/react-router'\n\nexport function transformTanStackRootRoute({\n content,\n kind,\n}: {\n content: string\n kind: TanStackAppDetails['kind']\n}): TextTransformResult {\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n useInMemoryFileSystem: true,\n })\n const sourceFile = project.createSourceFile('__root.tsx', content)\n const createRootRouteImport = getNamedImport({\n importedName: 'createRootRoute',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n\n if (!createRootRouteImport) {\n return failure('Could not identify the createRootRoute import.')\n }\n\n const createRootRouteCalls = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((call) => call.getExpression().getText() === createRootRouteImport.localName)\n\n if (createRootRouteCalls.length !== 1) {\n return failure('Expected exactly one createRootRoute() call.')\n }\n\n const createRootRouteCall = createRootRouteCalls[0]!\n if (createRootRouteCall.getArguments().length !== 1) {\n return failure('createRootRoute() must receive exactly one argument.')\n }\n\n const rootObject = createRootRouteCall.getArguments()[0]\n if (!Node.isObjectLiteralExpression(rootObject)) {\n return failure('createRootRoute() must receive an object literal.')\n }\n\n if (rootObject.getProperties().some(Node.isSpreadAssignment)) {\n return failure('Root route object spreads cannot be transformed safely.')\n }\n\n return kind === 'start'\n ? transformStartRoot({ content, rootObject, sourceFile })\n : transformRouterOnlyRoot({ content, rootObject, sourceFile })\n}\n\nfunction bindingNameIncludes({ localName, node }: { localName: string; node: MorphNode }): boolean {\n if (Node.isIdentifier(node)) {\n return node.getText() === localName\n }\n\n if (Node.isArrayBindingPattern(node) || Node.isObjectBindingPattern(node)) {\n return node\n .getElements()\n .some(\n (element) =>\n Node.isBindingElement(element) &&\n bindingNameIncludes({ localName, node: element.getNameNode() }),\n )\n }\n\n return false\n}\n\nfunction ensureNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const declaration = sourceFile\n .getImportDeclarations()\n .find(\n (candidate) =>\n candidate.getModuleSpecifierValue() === moduleSpecifier &&\n !candidate.isTypeOnly() &&\n !candidate.getNamespaceImport(),\n )\n\n if (\n declaration\n ?.getNamedImports()\n .some((namedImport) => namedImport.getName() === importedName && !namedImport.getAliasNode())\n ) {\n return\n }\n\n if (declaration) {\n declaration.addNamedImport(importedName)\n } else {\n sourceFile.addImportDeclaration({ moduleSpecifier, namedImports: [importedName] })\n }\n}\n\nfunction failure(reason: string): TextTransformResult {\n return { reason, success: false }\n}\n\nfunction getAppStylesheetImport({\n requireSideEffect,\n sourceFile,\n}: {\n requireSideEffect: boolean\n sourceFile: SourceFile\n}): { declaration: ImportDeclaration; localName?: string; moduleSpecifier: string } | undefined {\n const imports = sourceFile.getImportDeclarations().filter((declaration) => {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const isStylesheet = requireSideEffect\n ? /\\.css$/.test(moduleSpecifier)\n : /\\.css\\?url$/.test(moduleSpecifier)\n\n if (!isStylesheet) {\n return false\n }\n\n const hasNamedOrNamespaceImport =\n declaration.getNamedImports().length > 0 || Boolean(declaration.getNamespaceImport())\n return requireSideEffect\n ? !declaration.getDefaultImport() && !hasNamedOrNamespaceImport\n : Boolean(declaration.getDefaultImport()) && !hasNamedOrNamespaceImport\n })\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const declaration = imports[0]!\n return {\n declaration,\n localName: declaration.getDefaultImport()?.getText(),\n moduleSpecifier: declaration.getModuleSpecifierValue(),\n }\n}\n\nfunction getFunction({\n functionName,\n sourceFile,\n}: {\n functionName: string\n sourceFile: SourceFile\n}): FunctionDeclaration | undefined {\n const functions = sourceFile\n .getFunctions()\n .filter((declaration) => declaration.getName() === functionName)\n\n return functions.length === 1 ? functions[0] : undefined\n}\n\nfunction getRouteComponentFunction({\n component,\n sourceFile,\n}: {\n component: Expression\n sourceFile: SourceFile\n}): RouteComponentFunction | undefined {\n if (Node.isArrowFunction(component) || Node.isFunctionExpression(component)) {\n return component\n }\n\n if (!Node.isIdentifier(component)) {\n return undefined\n }\n\n const functions: RouteComponentFunction[] = sourceFile\n .getFunctions()\n .filter((declaration) => declaration.getName() === component.getText())\n const variableFunctions = sourceFile\n .getVariableDeclarations()\n .filter((declaration) => declaration.getName() === component.getText())\n .map((declaration) => declaration.getInitializer())\n .filter(\n (initializer): initializer is ArrowFunction | FunctionExpression =>\n Node.isArrowFunction(initializer) || Node.isFunctionExpression(initializer),\n )\n\n functions.push(...variableFunctions)\n\n return functions.length === 1 ? functions[0] : undefined\n}\n\nfunction isDocumentShellExpression(expression: Expression | undefined): boolean {\n if (!expression) {\n return false\n }\n\n const openingElements = expression.getDescendantsOfKind(SyntaxKind.JsxOpeningElement)\n const selfClosingElements = expression.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n\n return [...openingElements, ...selfClosingElements].some(\n (element) => element.getTagNameNode().getText() === 'html',\n )\n}\n\nfunction routeComponentRendersDocumentShell({\n component,\n sourceFile,\n}: {\n component: Expression\n sourceFile: SourceFile\n}): boolean {\n const componentFunction = getRouteComponentFunction({ component, sourceFile })\n if (!componentFunction) {\n return false\n }\n\n const body = componentFunction.getBody()\n if (!body) {\n return false\n }\n\n if (Node.isExpression(body) && isDocumentShellExpression(body)) {\n return true\n }\n\n return body\n .getDescendantsOfKind(SyntaxKind.ReturnStatement)\n .filter((returnStatement) => {\n const containingFunction = returnStatement.getFirstAncestor(\n (ancestor) =>\n Node.isArrowFunction(ancestor) ||\n Node.isFunctionDeclaration(ancestor) ||\n Node.isFunctionExpression(ancestor),\n )\n\n return containingFunction?.getStart() === componentFunction.getStart()\n })\n .some((returnStatement) => isDocumentShellExpression(returnStatement.getExpression()))\n}\n\nfunction getHeadContentNode({\n functionDeclaration,\n localName,\n}: {\n functionDeclaration: FunctionDeclaration\n localName: string\n}): JsxSelfClosingElement | undefined {\n const matches = functionDeclaration\n .getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n .filter((element) => element.getTagNameNode().getText() === localName)\n\n return matches.length === 1 ? matches[0] : undefined\n}\n\nfunction getLocalBindings({\n localName,\n sourceFile,\n}: {\n localName: string\n sourceFile: SourceFile\n}): LocalBinding[] {\n const bindings: LocalBinding[] = []\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const defaultImport = declaration.getDefaultImport()\n if (defaultImport?.getText() === localName) {\n bindings.push({\n importKind: 'default',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n const namespaceImport = declaration.getNamespaceImport()\n if (namespaceImport?.getText() === localName) {\n bindings.push({\n importKind: 'namespace',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n const namedImportLocalName = namedImport.getAliasNode()?.getText() ?? namedImport.getName()\n if (namedImportLocalName === localName) {\n bindings.push({\n importedName: namedImport.getName(),\n importKind: 'named',\n isTypeOnly: declaration.isTypeOnly() || namedImport.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n }\n }\n\n for (const declaration of sourceFile.getVariableDeclarations()) {\n if (bindingNameIncludes({ localName, node: declaration.getNameNode() })) {\n bindings.push({ kind: 'variable' })\n }\n }\n\n const hasOtherDeclaration = [\n ...sourceFile.getClasses(),\n ...sourceFile.getEnums(),\n ...sourceFile.getFunctions(),\n ...sourceFile.getModules(),\n ].some((declaration) => declaration.getName() === localName)\n\n if (hasOtherDeclaration) {\n bindings.push({ kind: 'other' })\n }\n\n return bindings\n}\n\nfunction getNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}): NamedImport | undefined {\n const imports = sourceFile.getImportDeclarations().flatMap((declaration) =>\n declaration.getModuleSpecifierValue() === moduleSpecifier\n ? declaration\n .getNamedImports()\n .filter((namedImport) => namedImport.getName() === importedName)\n .map((namedImport) => ({\n declaration,\n localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName(),\n }))\n : [],\n )\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const imported = imports[0]!\n const bindings = getLocalBindings({ localName: imported.localName, sourceFile })\n const binding = bindings[0]\n\n if (\n bindings.length !== 1 ||\n binding?.kind !== 'import' ||\n binding.importKind !== 'named' ||\n binding.importedName !== importedName ||\n binding.isTypeOnly ||\n binding.moduleSpecifier !== moduleSpecifier\n ) {\n return undefined\n }\n\n return imported\n}\n\nfunction resolveRouterNamedImport({\n importedName,\n sourceFile,\n}: {\n importedName: 'HeadContent' | 'Scripts'\n sourceFile: SourceFile\n}):\n | { importedName: string; isPresent: boolean; localName: string; success: true }\n | { reason: string; success: false } {\n const matchingImports = sourceFile.getImportDeclarations().flatMap((declaration) =>\n declaration.getModuleSpecifierValue() === ROUTER_MODULE && !declaration.isTypeOnly()\n ? declaration\n .getNamedImports()\n .filter(\n (namedImport) => namedImport.getName() === importedName && !namedImport.isTypeOnly(),\n )\n .map((namedImport) => namedImport.getAliasNode()?.getText() ?? namedImport.getName())\n : [],\n )\n\n if (matchingImports.length > 1) {\n return {\n reason: `The TanStack router module imports ${importedName} more than once.`,\n success: false,\n }\n }\n\n const localName = matchingImports[0] ?? importedName\n const bindings = getLocalBindings({ localName, sourceFile })\n const binding = bindings[0]\n const isCompatible =\n binding?.kind === 'import' &&\n binding.importKind === 'named' &&\n binding.importedName === importedName &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === ROUTER_MODULE\n\n if (bindings.length > 0 && (bindings.length !== 1 || !isCompatible)) {\n return {\n reason: `Identifier \"${localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n\n return { importedName, isPresent: matchingImports.length === 1, localName, success: true }\n}\n\nfunction getSideEffectStylesheetImports(sourceFile: SourceFile): ImportDeclaration[] {\n return sourceFile\n .getImportDeclarations()\n .filter(\n (declaration) =>\n /\\.css$/.test(declaration.getModuleSpecifierValue()) &&\n !declaration.getDefaultImport() &&\n !declaration.getNamespaceImport() &&\n declaration.getNamedImports().length === 0,\n )\n}\n\nfunction getPropertyName(node: MorphNode): string | undefined {\n if (\n Node.isPropertyAssignment(node) ||\n Node.isShorthandPropertyAssignment(node) ||\n Node.isMethodDeclaration(node) ||\n Node.isGetAccessorDeclaration(node) ||\n Node.isSetAccessorDeclaration(node)\n ) {\n return node.getName()\n }\n}\n\nfunction getPropertyAssignment({\n object,\n propertyName,\n}: {\n object: ObjectLiteralExpression\n propertyName: string\n}) {\n const properties = object\n .getProperties()\n .filter((property) => getPropertyName(property) === propertyName)\n\n return properties.length === 1 && Node.isPropertyAssignment(properties[0])\n ? properties[0]\n : undefined\n}\n\nfunction getRootHeadLinks(\n rootObject: ObjectLiteralExpression,\n): { links: ArrayLiteralExpression; success: true } | { reason: string; success: false } {\n const headProperty = getPropertyAssignment({ object: rootObject, propertyName: 'head' })\n const headInitializer = headProperty?.getInitializer()\n if (!headInitializer || !Node.isArrowFunction(headInitializer)) {\n return { reason: 'The root head declaration cannot be transformed safely.', success: false }\n }\n\n const body = headInitializer.getBody()\n const headObject = Node.isParenthesizedExpression(body) ? body.getExpression() : body\n if (!Node.isObjectLiteralExpression(headObject)) {\n return { reason: 'The root head declaration cannot be transformed safely.', success: false }\n }\n\n const linksProperty = getPropertyAssignment({ object: headObject, propertyName: 'links' })\n const links = linksProperty?.getInitializer()\n if (\n !links ||\n !Node.isArrayLiteralExpression(links) ||\n links.getElements().some(Node.isSpreadElement)\n ) {\n return { reason: 'The root head links cannot be transformed safely.', success: false }\n }\n\n return { links, success: true }\n}\n\nfunction getShellState({\n expectedComponent,\n rootObject,\n withPayloadRootLocalName,\n}: {\n expectedComponent?: string\n rootObject: ObjectLiteralExpression\n withPayloadRootLocalName: string\n}):\n | { componentName: string; isWrapped: boolean; property?: PropertyAssignment; success: true }\n | { reason: string; success: false } {\n const properties = rootObject\n .getProperties()\n .filter((property) => getPropertyName(property) === 'shellComponent')\n\n if (properties.length === 0) {\n if (!expectedComponent) {\n return { componentName: 'RootDocument', isWrapped: false, success: true }\n }\n\n return {\n reason: 'The existing shellComponent cannot be transformed safely.',\n success: false,\n }\n }\n\n const property = properties[0]\n if (properties.length !== 1 || !property || !Node.isPropertyAssignment(property)) {\n return {\n reason: 'The existing shellComponent cannot be transformed safely.',\n success: false,\n }\n }\n\n const initializer = property.getInitializer()\n if (\n Node.isIdentifier(initializer) &&\n (!expectedComponent || initializer.getText() === expectedComponent)\n ) {\n return {\n componentName: initializer.getText(),\n isWrapped: false,\n property,\n success: true,\n }\n }\n\n if (\n Node.isCallExpression(initializer) &&\n initializer.getExpression().getText() === withPayloadRootLocalName &&\n initializer.getArguments().length === 1 &&\n Node.isIdentifier(initializer.getArguments()[0]) &&\n (!expectedComponent || initializer.getArguments()[0]!.getText() === expectedComponent)\n ) {\n return {\n componentName: initializer.getArguments()[0]!.getText(),\n isWrapped: true,\n property,\n success: true,\n }\n }\n\n return {\n reason: 'The existing shellComponent cannot be transformed safely.',\n success: false,\n }\n}\n\nfunction getStylesheetAttribute({\n name,\n element,\n}: {\n element: JsxSelfClosingElement\n name: string\n}): string | undefined {\n const attribute = element\n .getAttributes()\n .find(\n (candidate) => Node.isJsxAttribute(candidate) && candidate.getNameNode().getText() === name,\n )\n\n if (!attribute || !Node.isJsxAttribute(attribute)) {\n return undefined\n }\n\n const initializer = attribute.getInitializer()\n if (Node.isStringLiteral(initializer)) {\n return initializer.getLiteralValue()\n }\n\n if (Node.isJsxExpression(initializer)) {\n return initializer.getExpression()?.getText()\n }\n}\n\nfunction transformRouterOnlyRoot({\n content,\n rootObject,\n sourceFile,\n}: {\n content: string\n rootObject: ObjectLiteralExpression\n sourceFile: SourceFile\n}): TextTransformResult {\n const withPayloadRootImport = getNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n const withPayloadRootLocalName = withPayloadRootImport?.localName ?? 'withPayloadRoot'\n const shellState = getShellState({ rootObject, withPayloadRootLocalName })\n if (!shellState.success) {\n return shellState\n }\n\n if (shellState.property && !shellState.isWrapped) {\n return failure('The existing shellComponent cannot be transformed safely.')\n }\n\n if (shellState.isWrapped && getSideEffectStylesheetImports(sourceFile).length > 0) {\n return failure('Side-effect stylesheet imports cannot be isolated from admin.')\n }\n\n const headContentImport = resolveRouterNamedImport({\n importedName: 'HeadContent',\n sourceFile,\n })\n if (!headContentImport.success) {\n return headContentImport\n }\n\n const scriptsImport = resolveRouterNamedImport({ importedName: 'Scripts', sourceFile })\n if (!scriptsImport.success) {\n return scriptsImport\n }\n\n const destinationValidation = validateRouterOnlyDestinations({\n isAlreadyWrapped: shellState.isWrapped,\n sourceFile,\n withPayloadRootLocalName,\n })\n if (!destinationValidation.success) {\n return destinationValidation\n }\n\n if (shellState.isWrapped) {\n const stylesheetImport = getAppStylesheetImport({ requireSideEffect: false, sourceFile })\n const rootDocument = getFunction({ functionName: 'RootDocument', sourceFile })\n if (\n !stylesheetImport ||\n stylesheetImport.localName !== 'appCss' ||\n !rootDocument ||\n !hasValidAppStylesheetLink({\n functionDeclaration: rootDocument,\n headContentLocalName: headContentImport.localName,\n localName: 'appCss',\n })\n ) {\n return failure('The existing Payload root shell does not match the supported configuration.')\n }\n\n const hasWithPayloadImport = Boolean(withPayloadRootImport)\n const hasAllRequiredImports =\n hasWithPayloadImport && headContentImport.isPresent && scriptsImport.isPresent\n\n if (!hasAllRequiredImports) {\n if (!hasWithPayloadImport) {\n ensureNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n }\n if (!headContentImport.isPresent) {\n ensureNamedImport({\n importedName: 'HeadContent',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n }\n if (!scriptsImport.isPresent) {\n ensureNamedImport({\n importedName: 'Scripts',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n }\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n }\n\n return { content, modified: false, success: true }\n }\n\n const sideEffectStylesheets = getSideEffectStylesheetImports(sourceFile)\n\n if (sideEffectStylesheets.length !== 1) {\n return failure('Expected exactly one side-effect stylesheet import.')\n }\n\n const stylesheetImport = sideEffectStylesheets[0]!\n const componentProperties = rootObject\n .getProperties()\n .filter((property) => getPropertyName(property) === 'component')\n const componentProperty = componentProperties[0]\n if (\n componentProperties.length !== 1 ||\n !Node.isPropertyAssignment(componentProperty) ||\n !componentProperty.getInitializer()\n ) {\n return failure('The Router-only root must contain exactly one component option.')\n }\n\n if (\n routeComponentRendersDocumentShell({\n component: componentProperty.getInitializer()!,\n sourceFile,\n })\n ) {\n return failure('The Router-only route component cannot render the document shell.')\n }\n\n stylesheetImport.setDefaultImport('appCss')\n stylesheetImport.setModuleSpecifier(`${stylesheetImport.getModuleSpecifierValue()}?url`)\n rootObject.addPropertyAssignment({\n name: 'shellComponent',\n initializer: `${withPayloadRootLocalName}(RootDocument)`,\n })\n if (!withPayloadRootImport) {\n ensureNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n }\n if (!headContentImport.isPresent) {\n ensureNamedImport({ importedName: 'HeadContent', moduleSpecifier: ROUTER_MODULE, sourceFile })\n }\n if (!scriptsImport.isPresent) {\n ensureNamedImport({ importedName: 'Scripts', moduleSpecifier: ROUTER_MODULE, sourceFile })\n }\n sourceFile.addStatements(`\nfunction RootDocument({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\" suppressHydrationWarning>\n <head>\n <link href={appCss} rel=\"stylesheet\" />\n <${headContentImport.localName} />\n </head>\n <body>\n {children}\n <${scriptsImport.localName} />\n </body>\n </html>\n )\n}`)\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction transformStartRoot({\n content,\n rootObject,\n sourceFile,\n}: {\n content: string\n rootObject: ObjectLiteralExpression\n sourceFile: SourceFile\n}): TextTransformResult {\n if (getSideEffectStylesheetImports(sourceFile).length > 0) {\n return failure('Side-effect stylesheet imports cannot be isolated from admin.')\n }\n\n const withPayloadRootImport = getNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n const withPayloadRootLocalName = withPayloadRootImport?.localName ?? 'withPayloadRoot'\n const shellState = getShellState({\n expectedComponent: undefined,\n rootObject,\n withPayloadRootLocalName,\n })\n if (!shellState.success || !shellState.property) {\n return shellState.success\n ? failure('The existing shellComponent cannot be transformed safely.')\n : shellState\n }\n\n const withPayloadValidation = validateNamedDestination({\n importedName: 'withPayloadRoot',\n localName: withPayloadRootLocalName,\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n if (!withPayloadValidation.success) {\n return withPayloadValidation\n }\n const hasWithPayloadImport = Boolean(withPayloadRootImport)\n\n const headContentImport = getNamedImport({\n importedName: 'HeadContent',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n const scriptsImport = getNamedImport({\n importedName: 'Scripts',\n moduleSpecifier: ROUTER_MODULE,\n sourceFile,\n })\n if (!headContentImport || !scriptsImport) {\n return failure('Could not identify the Start document imports.')\n }\n\n const stylesheetImport = getAppStylesheetImport({ requireSideEffect: false, sourceFile })\n if (!stylesheetImport?.localName) {\n return failure('Could not identify the app stylesheet import.')\n }\n\n const stylesheetBindings = getLocalBindings({ localName: stylesheetImport.localName, sourceFile })\n const stylesheetBinding = stylesheetBindings[0]\n if (\n stylesheetBindings.length !== 1 ||\n stylesheetBinding?.kind !== 'import' ||\n stylesheetBinding.importKind !== 'default' ||\n stylesheetBinding.isTypeOnly ||\n stylesheetBinding.moduleSpecifier !== stylesheetImport.moduleSpecifier\n ) {\n return failure(`Identifier \"${stylesheetImport.localName}\" is already bound incompatibly.`)\n }\n\n const rootDocument = getFunction({ functionName: shellState.componentName, sourceFile })\n if (!rootDocument) {\n return failure('Could not identify the Start root document component.')\n }\n\n const headContentNode = getHeadContentNode({\n functionDeclaration: rootDocument,\n localName: headContentImport.localName,\n })\n if (!headContentNode) {\n return failure('Could not identify HeadContent in the Start root document.')\n }\n\n const headLinks = getRootHeadLinks(rootObject)\n if (!headLinks.success) {\n return headLinks\n }\n\n let stylesheetIndex = -1\n for (const [index, element] of headLinks.links.getElements().entries()) {\n if (!Node.isObjectLiteralExpression(element)) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n if (element.getProperties().some(Node.isSpreadAssignment)) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n const rel = getStaticObjectPropertyValue({ object: element, propertyName: 'rel' })\n if (rel !== 'stylesheet') {\n continue\n }\n\n const hrefProperty = getPropertyAssignment({ object: element, propertyName: 'href' })\n if (\n hrefProperty?.getInitializer()?.getText() !== stylesheetImport.localName ||\n stylesheetIndex !== -1\n ) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n stylesheetIndex = index\n }\n\n const hasStylesheetLink = hasValidAppStylesheetLink({\n functionDeclaration: rootDocument,\n headContentLocalName: headContentImport.localName,\n localName: stylesheetImport.localName,\n })\n if (stylesheetIndex === -1 && !hasStylesheetLink) {\n return failure('The app stylesheet link cannot be relocated safely.')\n }\n\n if (shellState.isWrapped && stylesheetIndex === -1 && hasStylesheetLink && hasWithPayloadImport) {\n return { content, modified: false, success: true }\n }\n\n if (stylesheetIndex !== -1) {\n headLinks.links.removeElement(stylesheetIndex)\n }\n if (!hasStylesheetLink) {\n headContentNode.replaceWithText(\n `<link href={${stylesheetImport.localName}} rel=\"stylesheet\" />\\n<${headContentImport.localName} />`,\n )\n }\n if (!shellState.isWrapped) {\n shellState.property.setInitializer(`${withPayloadRootLocalName}(${shellState.componentName})`)\n }\n if (!withPayloadRootImport) {\n ensureNamedImport({\n importedName: 'withPayloadRoot',\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n sourceFile,\n })\n }\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction getStaticObjectPropertyValue({\n object,\n propertyName,\n}: {\n object: ObjectLiteralExpression\n propertyName: string\n}): string | undefined {\n const property = getPropertyAssignment({ object, propertyName })\n const initializer = property?.getInitializer()\n\n return Node.isStringLiteral(initializer) ? initializer.getLiteralValue() : undefined\n}\n\nfunction hasValidAppStylesheetLink({\n functionDeclaration,\n headContentLocalName,\n localName,\n}: {\n functionDeclaration: FunctionDeclaration\n headContentLocalName: string\n localName: string\n}): boolean {\n const links = functionDeclaration\n .getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n .filter(\n (element) =>\n element.getTagNameNode().getText() === 'link' &&\n getStylesheetAttribute({ name: 'href', element }) === localName &&\n getStylesheetAttribute({ name: 'rel', element }) === 'stylesheet',\n )\n\n const headContentElements = functionDeclaration\n .getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n .filter((element) => element.getTagNameNode().getText() === headContentLocalName)\n\n if (links.length !== 1 || headContentElements.length !== 1) {\n return false\n }\n\n const link = links[0]!\n const headContent = headContentElements[0]!\n const linkParent = link.getFirstAncestorByKind(SyntaxKind.JsxElement)\n const headContentParent = headContent.getFirstAncestorByKind(SyntaxKind.JsxElement)\n\n return (\n linkParent?.getStart() === headContentParent?.getStart() &&\n linkParent?.getOpeningElement().getTagNameNode().getText() === 'head' &&\n link.getStart() < headContent.getStart()\n )\n}\n\nfunction validateNamedDestination({\n importedName,\n localName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n localName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}): { reason: string; success: false } | { success: true } {\n const bindings = getLocalBindings({ localName, sourceFile })\n const binding = bindings[0]\n const isCompatible =\n binding?.kind === 'import' &&\n binding.importKind === 'named' &&\n binding.importedName === importedName &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === moduleSpecifier\n\n if (bindings.length > 0 && (bindings.length !== 1 || !isCompatible)) {\n return {\n reason: `Identifier \"${localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n\n return { success: true }\n}\n\nfunction validateRouterOnlyDestinations({\n isAlreadyWrapped,\n sourceFile,\n withPayloadRootLocalName,\n}: {\n isAlreadyWrapped: boolean\n sourceFile: SourceFile\n withPayloadRootLocalName: string\n}): { reason: string; success: false } | { success: true } {\n const destinations = [\n {\n importedName: 'withPayloadRoot',\n localName: withPayloadRootLocalName,\n moduleSpecifier: PAYLOAD_CLIENT_MODULE,\n },\n ]\n\n for (const destination of destinations) {\n const validation = validateNamedDestination({ ...destination, sourceFile })\n if (!validation.success) {\n return validation\n }\n }\n\n for (const localName of ['appCss', 'RootDocument']) {\n const bindings = getLocalBindings({ localName, sourceFile })\n if (bindings.length === 0) {\n continue\n }\n\n const binding = bindings[0]\n const isCompatible =\n isAlreadyWrapped &&\n bindings.length === 1 &&\n (localName === 'RootDocument'\n ? binding?.kind === 'other'\n : binding?.kind === 'import' &&\n binding.importKind === 'default' &&\n !binding.isTypeOnly &&\n /\\.css\\?url$/.test(binding.moduleSpecifier))\n\n if (!isCompatible) {\n return {\n reason: `Identifier \"${localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n }\n\n return { success: true }\n}\n"],"names":["Node","Project","QuoteKind","SyntaxKind","PAYLOAD_CLIENT_MODULE","ROUTER_MODULE","transformTanStackRootRoute","content","kind","project","manipulationSettings","quoteKind","Single","useInMemoryFileSystem","sourceFile","createSourceFile","createRootRouteImport","getNamedImport","importedName","moduleSpecifier","failure","createRootRouteCalls","getDescendantsOfKind","CallExpression","filter","call","getExpression","getText","localName","length","createRootRouteCall","getArguments","rootObject","isObjectLiteralExpression","getProperties","some","isSpreadAssignment","transformStartRoot","transformRouterOnlyRoot","bindingNameIncludes","node","isIdentifier","isArrayBindingPattern","isObjectBindingPattern","getElements","element","isBindingElement","getNameNode","ensureNamedImport","declaration","getImportDeclarations","find","candidate","getModuleSpecifierValue","isTypeOnly","getNamespaceImport","getNamedImports","namedImport","getName","getAliasNode","addNamedImport","addImportDeclaration","namedImports","reason","success","getAppStylesheetImport","requireSideEffect","imports","isStylesheet","test","hasNamedOrNamespaceImport","Boolean","getDefaultImport","undefined","getFunction","functionName","functions","getFunctions","getRouteComponentFunction","component","isArrowFunction","isFunctionExpression","variableFunctions","getVariableDeclarations","map","getInitializer","initializer","push","isDocumentShellExpression","expression","openingElements","JsxOpeningElement","selfClosingElements","JsxSelfClosingElement","getTagNameNode","routeComponentRendersDocumentShell","componentFunction","body","getBody","isExpression","ReturnStatement","returnStatement","containingFunction","getFirstAncestor","ancestor","isFunctionDeclaration","getStart","getHeadContentNode","functionDeclaration","matches","getLocalBindings","bindings","defaultImport","importKind","namespaceImport","namedImportLocalName","hasOtherDeclaration","getClasses","getEnums","getModules","flatMap","imported","binding","resolveRouterNamedImport","matchingImports","isCompatible","isPresent","getSideEffectStylesheetImports","getPropertyName","isPropertyAssignment","isShorthandPropertyAssignment","isMethodDeclaration","isGetAccessorDeclaration","isSetAccessorDeclaration","getPropertyAssignment","object","propertyName","properties","property","getRootHeadLinks","headProperty","headInitializer","headObject","isParenthesizedExpression","linksProperty","links","isArrayLiteralExpression","isSpreadElement","getShellState","expectedComponent","withPayloadRootLocalName","componentName","isWrapped","isCallExpression","getStylesheetAttribute","name","attribute","getAttributes","isJsxAttribute","isStringLiteral","getLiteralValue","isJsxExpression","withPayloadRootImport","shellState","headContentImport","scriptsImport","destinationValidation","validateRouterOnlyDestinations","isAlreadyWrapped","stylesheetImport","rootDocument","hasValidAppStylesheetLink","headContentLocalName","hasWithPayloadImport","hasAllRequiredImports","formatText","indentSize","getFullText","modified","sideEffectStylesheets","componentProperties","componentProperty","setDefaultImport","setModuleSpecifier","addPropertyAssignment","addStatements","withPayloadValidation","validateNamedDestination","stylesheetBindings","stylesheetBinding","headContentNode","headLinks","stylesheetIndex","index","entries","rel","getStaticObjectPropertyValue","hrefProperty","hasStylesheetLink","removeElement","replaceWithText","setInitializer","headContentElements","link","headContent","linkParent","getFirstAncestorByKind","JsxElement","headContentParent","getOpeningElement","destinations","destination","validation"],"mappings":"AAcA,SAASA,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,UAAU,QAAQ,WAAU;AAkB/D,MAAMC,wBAAwB;AAC9B,MAAMC,gBAAgB;AAEtB,OAAO,SAASC,2BAA2B,EACzCC,OAAO,EACPC,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M6F,UAAUX,QAAQ,CAAC,EAAE;QAC3B,MAAMc,eACJ2C,oBACAzD,SAASlF,MAAM,KAAK,KACnBD,CAAAA,cAAc,iBACX8F,SAASlH,SAAS,UAClBkH,SAASlH,SAAS,YAClBkH,QAAQT,UAAU,KAAK,aACvB,CAACS,QAAQpE,UAAU,IACnB,cAAce,IAAI,CAACqD,QAAQvG,eAAe,CAAA;QAEhD,IAAI,CAAC0G,cAAc;YACjB,OAAO;gBACL9D,QAAQ,CAAC,YAAY,EAAEnC,UAAU,gCAAgC,CAAC;gBAClEoC,SAAS;YACX;QACF;IACF;IAEA,OAAO;QAAEA,SAAS;IAAK;AACzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"transform-vite-config.d.ts","sourceRoot":"","sources":["../../../src/lib/tanstack/transform-vite-config.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GACrD;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAA;AAetC,wBAAgB,2BAA2B,CAAC,EAC1C,UAAU,EACV,OAAO,GACR,EAAE;IACD,UAAU,EAAE,kBAAkB,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,mBAAmB,CA+JtB"}
1
+ {"version":3,"file":"transform-vite-config.d.ts","sourceRoot":"","sources":["../../../src/lib/tanstack/transform-vite-config.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GACrD;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAA;AAetC,wBAAgB,2BAA2B,CAAC,EAC1C,UAAU,EACV,OAAO,GACR,EAAE;IACD,UAAU,EAAE,kBAAkB,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,mBAAmB,CA6KtB"}
@@ -82,6 +82,11 @@ export function transformTanStackViteConfig({ appDetails, content }) {
82
82
  if (reactIndex !== frameworkIndex + 1) {
83
83
  return failure('Framework and React plugin calls must be adjacent and ordered.');
84
84
  }
85
+ const frameworkCall = frameworkCalls[0].element;
86
+ const reactCall = reactCalls[0].element;
87
+ if (!Node.isCallExpression(frameworkCall) || !Node.isCallExpression(reactCall) || frameworkCall.getArguments().length > 1 || reactCall.getArguments().length > 1) {
88
+ return failure('Framework and React plugin calls must receive at most one argument.');
89
+ }
85
90
  const destinationValidation = validateDestinationBindings({
86
91
  sourceFile
87
92
  });
@@ -89,8 +94,11 @@ export function transformTanStackViteConfig({ appDetails, content }) {
89
94
  return destinationValidation;
90
95
  }
91
96
  replacePluginCalls({
97
+ frameworkCall,
92
98
  frameworkIndex,
93
99
  pluginsArray,
100
+ preserveFrameworkOptions: appDetails.kind === 'start',
101
+ reactCall,
94
102
  reactIndex,
95
103
  reactPluginName
96
104
  });
@@ -286,6 +294,20 @@ function isCompatiblePathBinding(binding) {
286
294
  function isExactPluginCall({ call, expectedArgument }) {
287
295
  return call.getArguments().length === 1 && call.getArguments()[0]?.getText() === expectedArgument;
288
296
  }
297
+ function isMergedPluginCall({ call, expectedArgument }) {
298
+ if (isExactPluginCall({
299
+ call,
300
+ expectedArgument
301
+ })) {
302
+ return true;
303
+ }
304
+ const argument = call.getArguments()[0];
305
+ if (call.getArguments().length !== 1 || !Node.isObjectLiteralExpression(argument)) {
306
+ return false;
307
+ }
308
+ const firstProperty = argument.getProperties()[0];
309
+ return Node.isSpreadAssignment(firstProperty) && firstProperty.getExpression().getText() === expectedArgument;
310
+ }
289
311
  function isImportBinding({ binding, importedName, importKind, moduleSpecifier }) {
290
312
  return binding.kind === 'import' && !binding.isTypeOnly && binding.importKind === importKind && binding.moduleSpecifier === moduleSpecifier && (importedName === undefined || binding.importedName === importedName);
291
313
  }
@@ -492,10 +514,10 @@ function isCompatiblePayloadConfig({ sourceFile, withPayloadCall }) {
492
514
  if (rscCalls.length !== 1 || frameworkCalls.length !== 1 || reactCalls.length !== 1 || !isExactPluginCall({
493
515
  call: rscCalls[0],
494
516
  expectedArgument: 'pluginOptions.rsc'
495
- }) || !isExactPluginCall({
517
+ }) || !isMergedPluginCall({
496
518
  call: frameworkCalls[0],
497
519
  expectedArgument: 'pluginOptions.tanstackStart'
498
- }) || !isExactPluginCall({
520
+ }) || !isMergedPluginCall({
499
521
  call: reactCalls[0],
500
522
  expectedArgument: 'pluginOptions.react'
501
523
  })) {
@@ -523,11 +545,32 @@ function removeNamedImport({ declaration, importedName }) {
523
545
  declaration.remove();
524
546
  }
525
547
  }
526
- function replacePluginCalls({ frameworkIndex, pluginsArray, reactIndex, reactPluginName }) {
548
+ function replacePluginCalls({ frameworkCall, frameworkIndex, pluginsArray, preserveFrameworkOptions, reactCall, reactIndex, reactPluginName }) {
527
549
  const retainedPlugins = pluginsArray.getElements().filter((_, index)=>index !== frameworkIndex && index !== reactIndex).map((element)=>element.getText());
528
550
  const insertionIndex = Math.min(frameworkIndex, reactIndex);
529
- retainedPlugins.splice(insertionIndex, 0, 'rsc(pluginOptions.rsc)', 'tanstackStart(pluginOptions.tanstackStart)', `${reactPluginName}(pluginOptions.react)`);
551
+ retainedPlugins.splice(insertionIndex, 0, 'rsc(pluginOptions.rsc)', getPluginCallWithMergedOptions({
552
+ call: frameworkCall,
553
+ localName: 'tanstackStart',
554
+ pluginOptions: 'pluginOptions.tanstackStart',
555
+ shouldPreserveOptions: preserveFrameworkOptions
556
+ }), getPluginCallWithMergedOptions({
557
+ call: reactCall,
558
+ localName: reactPluginName,
559
+ pluginOptions: 'pluginOptions.react',
560
+ shouldPreserveOptions: true
561
+ }));
530
562
  pluginsArray.replaceWithText(`[${retainedPlugins.join(', ')}]`);
531
563
  }
564
+ function getPluginCallWithMergedOptions({ call, localName, pluginOptions, shouldPreserveOptions }) {
565
+ const existingOptions = shouldPreserveOptions ? call.getArguments()[0] : undefined;
566
+ if (!existingOptions) {
567
+ return `${localName}(${pluginOptions})`;
568
+ }
569
+ if (Node.isObjectLiteralExpression(existingOptions)) {
570
+ const properties = existingOptions.getText().slice(1, -1).trim();
571
+ return `${localName}({ ...${pluginOptions}${properties ? `, ${properties}` : ''} })`;
572
+ }
573
+ return `${localName}({ ...${pluginOptions}, ...(${existingOptions.getText()}) })`;
574
+ }
532
575
 
533
576
  //# sourceMappingURL=transform-vite-config.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/tanstack/transform-vite-config.ts"],"sourcesContent":["import type {\n ArrayLiteralExpression,\n CallExpression,\n Expression,\n ImportDeclaration,\n Node as MorphNode,\n SourceFile,\n} from 'ts-morph'\n\nimport { Node, Project, QuoteKind, SyntaxKind } from 'ts-morph'\n\nimport type { TanStackAppDetails } from '../../types.js'\n\nexport type TextTransformResult =\n | { content: string; modified: boolean; success: true }\n | { reason: string; success: false }\n\ntype LocalBinding =\n | {\n declaration: ImportDeclaration\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n isTypeOnly: boolean\n kind: 'import'\n moduleSpecifier: string\n }\n | { kind: 'other' | 'variable' }\n\nconst PAYLOAD_CONFIG_PATH = \"path.resolve(__dirname, 'src', 'payload.config.ts')\"\n\nexport function transformTanStackViteConfig({\n appDetails,\n content,\n}: {\n appDetails: TanStackAppDetails\n content: string\n}): TextTransformResult {\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n useInMemoryFileSystem: true,\n })\n const sourceFile = project.createSourceFile('vite.config.ts', content)\n const defineConfigCalls = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((call) => call.getExpression().getText() === 'defineConfig')\n\n if (defineConfigCalls.length !== 1) {\n return failure('Expected exactly one defineConfig() call.')\n }\n\n const defineConfigCall = defineConfigCalls[0]!\n if (defineConfigCall.getArguments().length !== 1) {\n return failure('defineConfig() must receive exactly one argument.')\n }\n\n const configArgument = defineConfigCall.getArguments()[0]\n\n if (\n Node.isCallExpression(configArgument) &&\n configArgument.getExpression().getText() === 'withPayload'\n ) {\n if (isCompatiblePayloadConfig({ sourceFile, withPayloadCall: configArgument })) {\n return { content, modified: false, success: true }\n }\n\n return failure('The existing withPayload() call does not match the supported configuration.')\n }\n\n if (!Node.isObjectLiteralExpression(configArgument)) {\n return failure('defineConfig() must receive an object literal.')\n }\n\n if (configArgument.getProperties().some(Node.isSpreadAssignment)) {\n return failure('Config object spreads cannot be transformed safely.')\n }\n\n const pluginsProperties = configArgument\n .getProperties()\n .filter(Node.isPropertyAssignment)\n .filter((property) => property.getName() === 'plugins')\n const pluginsProperty = pluginsProperties[0]\n if (pluginsProperties.length !== 1 || !pluginsProperty) {\n return failure('The Vite config must contain a plugins array.')\n }\n\n const pluginsArray = pluginsProperty.getInitializer()\n if (!Node.isArrayLiteralExpression(pluginsArray)) {\n return failure('The Vite config must contain a plugins array.')\n }\n\n if (pluginsArray.getElements().some(Node.isSpreadElement)) {\n return failure('Plugin array spreads cannot be transformed safely.')\n }\n\n const frameworkImport = getFrameworkImport({ appDetails, sourceFile })\n if (!frameworkImport) {\n return failure('Could not identify the TanStack framework plugin import.')\n }\n\n const reactPluginName = getDefaultImportLocalName({\n moduleSpecifier: '@vitejs/plugin-react',\n sourceFile,\n })\n\n if (!reactPluginName) {\n return failure('Could not identify the React plugin import.')\n }\n\n const pluginCalls = pluginsArray\n .getElements()\n .map((element) =>\n Node.isCallExpression(element)\n ? { name: element.getExpression().getText(), element }\n : { name: undefined, element },\n )\n const frameworkCalls = pluginCalls.filter(({ name }) => name === frameworkImport.localName)\n const reactCalls = pluginCalls.filter(({ name }) => name === reactPluginName)\n\n if (frameworkCalls.length !== 1) {\n return failure('Expected exactly one TanStack framework plugin call.')\n }\n\n if (reactCalls.length !== 1) {\n return failure('Expected exactly one React plugin call.')\n }\n\n const frameworkIndex = pluginCalls.indexOf(frameworkCalls[0]!)\n const reactIndex = pluginCalls.indexOf(reactCalls[0]!)\n\n if (reactIndex !== frameworkIndex + 1) {\n return failure('Framework and React plugin calls must be adjacent and ordered.')\n }\n\n const destinationValidation = validateDestinationBindings({ sourceFile })\n if (!destinationValidation.success) {\n return destinationValidation\n }\n\n replacePluginCalls({\n frameworkIndex,\n pluginsArray,\n reactIndex,\n reactPluginName,\n })\n\n const transformedConfig = configArgument.getText()\n defineConfigCall.replaceWithText(`defineConfig(\n withPayload(\n ({ pluginOptions }) => (${transformedConfig}),\n {\n payloadConfigPath: ${PAYLOAD_CONFIG_PATH},\n routesDirectory: 'routes',\n },\n ),\n)`)\n\n if (appDetails.kind === 'router-only') {\n removeNamedImport({\n declaration: frameworkImport.declaration,\n importedName: 'tanstackRouter',\n })\n }\n\n ensureNamedImport({\n importedName: 'withPayload',\n moduleSpecifier: '@payloadcms/tanstack-start',\n sourceFile,\n })\n ensureNamedImport({\n importedName: 'tanstackStart',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n sourceFile,\n })\n ensureDefaultImport({\n defaultImport: 'rsc',\n moduleSpecifier: '@vitejs/plugin-rsc',\n sourceFile,\n })\n ensurePathImport(sourceFile)\n\n if (destinationValidation.shouldAddDirname) {\n ensureNamedImport({\n importedName: 'fileURLToPath',\n moduleSpecifier: 'node:url',\n sourceFile,\n })\n sourceFile.insertStatements(\n sourceFile.getImportDeclarations().length,\n `const __dirname = path.dirname(fileURLToPath(import.meta.url))`,\n )\n }\n\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction ensureDefaultImport({\n defaultImport,\n moduleSpecifier,\n sourceFile,\n}: {\n defaultImport: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const matchingImport = sourceFile\n .getImportDeclarations()\n .find(\n (declaration) =>\n declaration.getModuleSpecifierValue() === moduleSpecifier &&\n declaration.getDefaultImport()?.getText() === defaultImport,\n )\n\n if (!matchingImport) {\n sourceFile.addImportDeclaration({ defaultImport, moduleSpecifier })\n }\n}\n\nfunction ensureNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const imports = sourceFile\n .getImportDeclarations()\n .filter((declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier)\n const hasImport = imports.some((declaration) =>\n declaration\n .getNamedImports()\n .some((namedImport) => namedImport.getName() === importedName && !namedImport.getAliasNode()),\n )\n\n if (hasImport) {\n return\n }\n\n const extensibleImport = imports.find((declaration) => !declaration.getNamespaceImport())\n if (extensibleImport) {\n extensibleImport.addNamedImport(importedName)\n } else {\n sourceFile.addImportDeclaration({ moduleSpecifier, namedImports: [importedName] })\n }\n}\n\nfunction ensurePathImport(sourceFile: SourceFile) {\n const hasCompatibleImport = sourceFile.getImportDeclarations().some((declaration) => {\n if (declaration.getModuleSpecifierValue() !== 'node:path') {\n return false\n }\n\n return (\n declaration.getDefaultImport()?.getText() === 'path' ||\n declaration.getNamespaceImport()?.getText() === 'path'\n )\n })\n\n if (!hasCompatibleImport) {\n sourceFile.addImportDeclaration({ defaultImport: 'path', moduleSpecifier: 'node:path' })\n }\n}\n\nfunction failure(reason: string): TextTransformResult {\n return { reason, success: false }\n}\n\nfunction getLocalBindings({\n localName,\n sourceFile,\n}: {\n localName: string\n sourceFile: SourceFile\n}): LocalBinding[] {\n const bindings: LocalBinding[] = []\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const defaultImport = declaration.getDefaultImport()\n if (defaultImport?.getText() === localName) {\n bindings.push({\n declaration,\n importKind: 'default',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n const namespaceImport = declaration.getNamespaceImport()\n if (namespaceImport?.getText() === localName) {\n bindings.push({\n declaration,\n importKind: 'namespace',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n const namedImportLocalName = namedImport.getAliasNode()?.getText() ?? namedImport.getName()\n if (namedImportLocalName === localName) {\n bindings.push({\n declaration,\n importedName: namedImport.getName(),\n importKind: 'named',\n isTypeOnly: declaration.isTypeOnly() || namedImport.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n }\n }\n\n for (const declaration of sourceFile.getVariableDeclarations()) {\n if (bindingNameIncludes({ localName, node: declaration.getNameNode() })) {\n bindings.push({ kind: 'variable' })\n }\n }\n\n const hasOtherDeclaration = [\n ...sourceFile.getClasses(),\n ...sourceFile.getEnums(),\n ...sourceFile.getFunctions(),\n ...sourceFile.getModules(),\n ].some((declaration) => declaration.getName() === localName)\n\n if (hasOtherDeclaration) {\n bindings.push({ kind: 'other' })\n }\n\n return bindings\n}\n\nfunction bindingNameIncludes({ localName, node }: { localName: string; node: MorphNode }): boolean {\n if (Node.isIdentifier(node)) {\n return node.getText() === localName\n }\n\n if (Node.isArrayBindingPattern(node) || Node.isObjectBindingPattern(node)) {\n return node\n .getElements()\n .some(\n (element) =>\n Node.isBindingElement(element) &&\n bindingNameIncludes({ localName, node: element.getNameNode() }),\n )\n }\n\n return false\n}\n\nfunction getNamedPluginCalls({\n elements,\n localName,\n}: {\n elements: Expression[]\n localName: string\n}): CallExpression[] {\n return elements.filter(\n (element): element is CallExpression =>\n Node.isCallExpression(element) && element.getExpression().getText() === localName,\n )\n}\n\nfunction hasCompatibleDirnameBinding(sourceFile: SourceFile): boolean {\n const bindings = getLocalBindings({ localName: '__dirname', sourceFile })\n\n return bindings.length === 1 && bindings[0]?.kind === 'variable'\n}\n\nfunction hasOnlyCompatibleBinding({\n localName,\n predicate,\n sourceFile,\n}: {\n localName: string\n predicate: (binding: LocalBinding) => boolean\n sourceFile: SourceFile\n}): boolean {\n const bindings = getLocalBindings({ localName, sourceFile })\n\n return bindings.length === 1 && predicate(bindings[0]!)\n}\n\nfunction isCompatiblePathBinding(binding: LocalBinding): boolean {\n return (\n binding.kind === 'import' &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === 'node:path' &&\n (binding.importKind === 'default' || binding.importKind === 'namespace')\n )\n}\n\nfunction isExactPluginCall({\n call,\n expectedArgument,\n}: {\n call: CallExpression\n expectedArgument: string\n}): boolean {\n return call.getArguments().length === 1 && call.getArguments()[0]?.getText() === expectedArgument\n}\n\nfunction isImportBinding({\n binding,\n importedName,\n importKind,\n moduleSpecifier,\n}: {\n binding: LocalBinding\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n moduleSpecifier: string\n}): boolean {\n return (\n binding.kind === 'import' &&\n !binding.isTypeOnly &&\n binding.importKind === importKind &&\n binding.moduleSpecifier === moduleSpecifier &&\n (importedName === undefined || binding.importedName === importedName)\n )\n}\n\nfunction validateDestinationBindings({\n sourceFile,\n}: {\n sourceFile: SourceFile\n}): { reason: string; success: false } | { shouldAddDirname: boolean; success: true } {\n const destinations: Array<{\n localName: string\n predicate: (binding: LocalBinding) => boolean\n }> = [\n {\n localName: 'withPayload',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'withPayload',\n importKind: 'named',\n moduleSpecifier: '@payloadcms/tanstack-start',\n }),\n },\n {\n localName: 'tanstackStart',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'tanstackStart',\n importKind: 'named',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n }),\n },\n {\n localName: 'rsc',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importKind: 'default',\n moduleSpecifier: '@vitejs/plugin-rsc',\n }),\n },\n { localName: 'path', predicate: isCompatiblePathBinding },\n ]\n\n for (const destination of destinations) {\n const bindings = getLocalBindings({ localName: destination.localName, sourceFile })\n if (bindings.length > 0 && (bindings.length !== 1 || !destination.predicate(bindings[0]!))) {\n return {\n reason: `Identifier \"${destination.localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n }\n\n const dirnameBindings = getLocalBindings({ localName: '__dirname', sourceFile })\n if (\n dirnameBindings.length > 0 &&\n (dirnameBindings.length !== 1 || dirnameBindings[0]?.kind !== 'variable')\n ) {\n return { reason: 'Identifier \"__dirname\" is already bound incompatibly.', success: false }\n }\n\n const shouldAddDirname = dirnameBindings.length === 0\n if (shouldAddDirname) {\n const fileURLToPathBindings = getLocalBindings({ localName: 'fileURLToPath', sourceFile })\n if (\n fileURLToPathBindings.length > 0 &&\n (fileURLToPathBindings.length !== 1 ||\n !isImportBinding({\n binding: fileURLToPathBindings[0]!,\n importedName: 'fileURLToPath',\n importKind: 'named',\n moduleSpecifier: 'node:url',\n }))\n ) {\n return {\n reason: 'Identifier \"fileURLToPath\" is already bound incompatibly.',\n success: false,\n }\n }\n }\n\n return { shouldAddDirname, success: true }\n}\n\nfunction getDefaultImportLocalName({\n moduleSpecifier,\n sourceFile,\n}: {\n moduleSpecifier: string\n sourceFile: SourceFile\n}): string | undefined {\n const imports = sourceFile\n .getImportDeclarations()\n .filter((declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier)\n .map((declaration) => declaration.getDefaultImport()?.getText())\n .filter((name): name is string => Boolean(name))\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const localName = imports[0]!\n return hasOnlyCompatibleBinding({\n localName,\n predicate: (binding) => isImportBinding({ binding, importKind: 'default', moduleSpecifier }),\n sourceFile,\n })\n ? localName\n : undefined\n}\n\nfunction getFrameworkImport({\n appDetails,\n sourceFile,\n}: {\n appDetails: TanStackAppDetails\n sourceFile: SourceFile\n}): { declaration: ImportDeclaration; localName: string } | undefined {\n const importedName = appDetails.kind === 'start' ? 'tanstackStart' : 'tanstackRouter'\n const moduleSpecifier =\n appDetails.kind === 'start'\n ? '@tanstack/react-start/plugin/vite'\n : '@tanstack/router-plugin/vite'\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n if (declaration.getModuleSpecifierValue() !== moduleSpecifier) {\n continue\n }\n\n const namedImport = declaration\n .getNamedImports()\n .find((specifier) => specifier.getName() === importedName)\n\n if (namedImport) {\n return {\n declaration,\n localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName(),\n }\n }\n }\n}\n\nfunction isCompatiblePayloadConfig({\n sourceFile,\n withPayloadCall,\n}: {\n sourceFile: SourceFile\n withPayloadCall: CallExpression\n}): boolean {\n if (\n withPayloadCall.getArguments().length !== 2 ||\n !hasOnlyCompatibleBinding({\n localName: 'withPayload',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'withPayload',\n importKind: 'named',\n moduleSpecifier: '@payloadcms/tanstack-start',\n }),\n sourceFile,\n })\n ) {\n return false\n }\n\n const [callback, options] = withPayloadCall.getArguments()\n\n if (!Node.isArrowFunction(callback) || !Node.isObjectLiteralExpression(options)) {\n return false\n }\n\n const callbackParameters = callback.getParameters()\n const callbackParameter = callbackParameters[0]\n const callbackBinding = callbackParameter?.getNameNode()\n if (\n callbackParameters.length !== 1 ||\n !callbackParameter ||\n !Node.isObjectBindingPattern(callbackBinding) ||\n callbackBinding.getElements().length !== 1 ||\n callbackBinding.getElements()[0]?.getName() !== 'pluginOptions' ||\n callbackBinding.getElements()[0]?.getPropertyNameNode() ||\n callbackBinding.getElements()[0]?.getInitializer() ||\n callbackBinding.getElements()[0]?.getDotDotDotToken()\n ) {\n return false\n }\n\n const callbackBody = callback.getBody()\n const configObject = Node.isParenthesizedExpression(callbackBody)\n ? callbackBody.getExpression()\n : callbackBody\n\n if (!Node.isObjectLiteralExpression(configObject)) {\n return false\n }\n\n if (configObject.getProperties().some(Node.isSpreadAssignment)) {\n return false\n }\n\n const pluginsProperties = configObject\n .getProperties()\n .filter(Node.isPropertyAssignment)\n .filter((property) => property.getName() === 'plugins')\n const pluginsArray = pluginsProperties[0]?.getInitializer()\n\n if (\n pluginsProperties.length !== 1 ||\n !Node.isArrayLiteralExpression(pluginsArray) ||\n pluginsArray.getElements().some(Node.isSpreadElement)\n ) {\n return false\n }\n\n const reactPluginName = getDefaultImportLocalName({\n moduleSpecifier: '@vitejs/plugin-react',\n sourceFile,\n })\n if (\n !reactPluginName ||\n !hasOnlyCompatibleBinding({\n localName: 'rsc',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importKind: 'default',\n moduleSpecifier: '@vitejs/plugin-rsc',\n }),\n sourceFile,\n }) ||\n !hasOnlyCompatibleBinding({\n localName: 'tanstackStart',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'tanstackStart',\n importKind: 'named',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n }),\n sourceFile,\n }) ||\n !hasOnlyCompatibleBinding({\n localName: 'path',\n predicate: isCompatiblePathBinding,\n sourceFile,\n }) ||\n !hasCompatibleDirnameBinding(sourceFile)\n ) {\n return false\n }\n\n const dirnameInitializer = sourceFile\n .getVariableDeclaration('__dirname')\n ?.getInitializer()\n ?.getText()\n if (\n dirnameInitializer === 'path.dirname(fileURLToPath(import.meta.url))' &&\n !hasOnlyCompatibleBinding({\n localName: 'fileURLToPath',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'fileURLToPath',\n importKind: 'named',\n moduleSpecifier: 'node:url',\n }),\n sourceFile,\n })\n ) {\n return false\n }\n\n const elements = pluginsArray.getElements()\n const rscCalls = getNamedPluginCalls({ elements, localName: 'rsc' })\n const frameworkCalls = getNamedPluginCalls({ elements, localName: 'tanstackStart' })\n const reactCalls = getNamedPluginCalls({ elements, localName: reactPluginName })\n\n if (\n rscCalls.length !== 1 ||\n frameworkCalls.length !== 1 ||\n reactCalls.length !== 1 ||\n !isExactPluginCall({ call: rscCalls[0]!, expectedArgument: 'pluginOptions.rsc' }) ||\n !isExactPluginCall({\n call: frameworkCalls[0]!,\n expectedArgument: 'pluginOptions.tanstackStart',\n }) ||\n !isExactPluginCall({ call: reactCalls[0]!, expectedArgument: 'pluginOptions.react' })\n ) {\n return false\n }\n\n const rscIndex = elements.indexOf(rscCalls[0]!)\n const frameworkIndex = elements.indexOf(frameworkCalls[0]!)\n const reactIndex = elements.indexOf(reactCalls[0]!)\n if (frameworkIndex !== rscIndex + 1 || reactIndex !== frameworkIndex + 1) {\n return false\n }\n\n const optionProperties = options.getProperties().filter(Node.isPropertyAssignment)\n if (optionProperties.length !== 2 || options.getProperties().length !== 2) {\n return false\n }\n\n const payloadConfigPath = optionProperties.find(\n (property) => property.getName() === 'payloadConfigPath',\n )\n const routesDirectory = optionProperties.find(\n (property) => property.getName() === 'routesDirectory',\n )\n const routesDirectoryInitializer = routesDirectory?.getInitializer()\n\n return (\n payloadConfigPath?.getInitializer()?.getText() === PAYLOAD_CONFIG_PATH &&\n Node.isStringLiteral(routesDirectoryInitializer) &&\n routesDirectoryInitializer.getLiteralValue() === 'routes'\n )\n}\n\nfunction removeNamedImport({\n declaration,\n importedName,\n}: {\n declaration: ImportDeclaration\n importedName: string\n}) {\n const namedImport = declaration\n .getNamedImports()\n .find((specifier) => specifier.getName() === importedName)\n\n namedImport?.remove()\n\n if (\n declaration.getNamedImports().length === 0 &&\n !declaration.getDefaultImport() &&\n !declaration.getNamespaceImport()\n ) {\n declaration.remove()\n }\n}\n\nfunction replacePluginCalls({\n frameworkIndex,\n pluginsArray,\n reactIndex,\n reactPluginName,\n}: {\n frameworkIndex: number\n pluginsArray: ArrayLiteralExpression\n reactIndex: number\n reactPluginName: string\n}) {\n const retainedPlugins = pluginsArray\n .getElements()\n .filter((_, index) => index !== frameworkIndex && index !== reactIndex)\n .map((element) => element.getText())\n const insertionIndex = Math.min(frameworkIndex, reactIndex)\n\n retainedPlugins.splice(\n insertionIndex,\n 0,\n 'rsc(pluginOptions.rsc)',\n 'tanstackStart(pluginOptions.tanstackStart)',\n `${reactPluginName}(pluginOptions.react)`,\n )\n\n pluginsArray.replaceWithText(`[${retainedPlugins.join(', ')}]`)\n}\n"],"names":["Node","Project","QuoteKind","SyntaxKind","PAYLOAD_CONFIG_PATH","transformTanStackViteConfig","appDetails","content","project","manipulationSettings","quoteKind","Single","useInMemoryFileSystem","sourceFile","createSourceFile","defineConfigCalls","getDescendantsOfKind","CallExpression","filter","call","getExpression","getText","length","failure","defineConfigCall","getArguments","configArgument","isCallExpression","isCompatiblePayloadConfig","withPayloadCall","modified","success","isObjectLiteralExpression","getProperties","some","isSpreadAssignment","pluginsProperties","isPropertyAssignment","property","getName","pluginsProperty","pluginsArray","getInitializer","isArrayLiteralExpression","getElements","isSpreadElement","frameworkImport","getFrameworkImport","reactPluginName","getDefaultImportLocalName","moduleSpecifier","pluginCalls","map","element","name","undefined","frameworkCalls","localName","reactCalls","frameworkIndex","indexOf","reactIndex","destinationValidation","validateDestinationBindings","replacePluginCalls","transformedConfig","replaceWithText","kind","removeNamedImport","declaration","importedName","ensureNamedImport","ensureDefaultImport","defaultImport","ensurePathImport","shouldAddDirname","insertStatements","getImportDeclarations","formatText","indentSize","getFullText","matchingImport","find","getModuleSpecifierValue","getDefaultImport","addImportDeclaration","imports","hasImport","getNamedImports","namedImport","getAliasNode","extensibleImport","getNamespaceImport","addNamedImport","namedImports","hasCompatibleImport","reason","getLocalBindings","bindings","push","importKind","isTypeOnly","namespaceImport","namedImportLocalName","getVariableDeclarations","bindingNameIncludes","node","getNameNode","hasOtherDeclaration","getClasses","getEnums","getFunctions","getModules","isIdentifier","isArrayBindingPattern","isObjectBindingPattern","isBindingElement","getNamedPluginCalls","elements","hasCompatibleDirnameBinding","hasOnlyCompatibleBinding","predicate","isCompatiblePathBinding","binding","isExactPluginCall","expectedArgument","isImportBinding","destinations","destination","dirnameBindings","fileURLToPathBindings","Boolean","specifier","callback","options","isArrowFunction","callbackParameters","getParameters","callbackParameter","callbackBinding","getPropertyNameNode","getDotDotDotToken","callbackBody","getBody","configObject","isParenthesizedExpression","dirnameInitializer","getVariableDeclaration","rscCalls","rscIndex","optionProperties","payloadConfigPath","routesDirectory","routesDirectoryInitializer","isStringLiteral","getLiteralValue","remove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9G;IAEpD,OACE6G,mBAAmB7G,kBAAkBrB,cAAcjB,uBACnDJ,KAAK0J,eAAe,CAACD,+BACrBA,2BAA2BE,eAAe,OAAO;AAErD;AAEA,SAASvF,kBAAkB,EACzBC,WAAW,EACXC,YAAY,EAIb;IACC,MAAMmB,cAAcpB,YACjBmB,eAAe,GACfN,IAAI,CAAC,CAACkD,YAAcA,UAAU7F,OAAO,OAAO+B;IAE/CmB,aAAamE;IAEb,IACEvF,YAAYmB,eAAe,GAAGlE,MAAM,KAAK,KACzC,CAAC+C,YAAYe,gBAAgB,MAC7B,CAACf,YAAYuB,kBAAkB,IAC/B;QACAvB,YAAYuF,MAAM;IACpB;AACF;AAEA,SAAS5F,mBAAmB,EAC1BL,cAAc,EACdlB,YAAY,EACZoB,UAAU,EACVb,eAAe,EAMhB;IACC,MAAM6G,kBAAkBpH,aACrBG,WAAW,GACX1B,MAAM,CAAC,CAAC4I,GAAGC,QAAUA,UAAUpG,kBAAkBoG,UAAUlG,YAC3DT,GAAG,CAAC,CAACC,UAAYA,QAAQhC,OAAO;IACnC,MAAM2I,iBAAiBC,KAAKC,GAAG,CAACvG,gBAAgBE;IAEhDgG,gBAAgBM,MAAM,CACpBH,gBACA,GACA,0BACA,8CACA,GAAGhH,gBAAgB,qBAAqB,CAAC;IAG3CP,aAAayB,eAAe,CAAC,CAAC,CAAC,EAAE2F,gBAAgBO,IAAI,CAAC,MAAM,CAAC,CAAC;AAChE"}
1
+ {"version":3,"sources":["../../../src/lib/tanstack/transform-vite-config.ts"],"sourcesContent":["import type {\n ArrayLiteralExpression,\n CallExpression,\n Expression,\n ImportDeclaration,\n Node as MorphNode,\n SourceFile,\n} from 'ts-morph'\n\nimport { Node, Project, QuoteKind, SyntaxKind } from 'ts-morph'\n\nimport type { TanStackAppDetails } from '../../types.js'\n\nexport type TextTransformResult =\n | { content: string; modified: boolean; success: true }\n | { reason: string; success: false }\n\ntype LocalBinding =\n | {\n declaration: ImportDeclaration\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n isTypeOnly: boolean\n kind: 'import'\n moduleSpecifier: string\n }\n | { kind: 'other' | 'variable' }\n\nconst PAYLOAD_CONFIG_PATH = \"path.resolve(__dirname, 'src', 'payload.config.ts')\"\n\nexport function transformTanStackViteConfig({\n appDetails,\n content,\n}: {\n appDetails: TanStackAppDetails\n content: string\n}): TextTransformResult {\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n useInMemoryFileSystem: true,\n })\n const sourceFile = project.createSourceFile('vite.config.ts', content)\n const defineConfigCalls = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((call) => call.getExpression().getText() === 'defineConfig')\n\n if (defineConfigCalls.length !== 1) {\n return failure('Expected exactly one defineConfig() call.')\n }\n\n const defineConfigCall = defineConfigCalls[0]!\n if (defineConfigCall.getArguments().length !== 1) {\n return failure('defineConfig() must receive exactly one argument.')\n }\n\n const configArgument = defineConfigCall.getArguments()[0]\n\n if (\n Node.isCallExpression(configArgument) &&\n configArgument.getExpression().getText() === 'withPayload'\n ) {\n if (isCompatiblePayloadConfig({ sourceFile, withPayloadCall: configArgument })) {\n return { content, modified: false, success: true }\n }\n\n return failure('The existing withPayload() call does not match the supported configuration.')\n }\n\n if (!Node.isObjectLiteralExpression(configArgument)) {\n return failure('defineConfig() must receive an object literal.')\n }\n\n if (configArgument.getProperties().some(Node.isSpreadAssignment)) {\n return failure('Config object spreads cannot be transformed safely.')\n }\n\n const pluginsProperties = configArgument\n .getProperties()\n .filter(Node.isPropertyAssignment)\n .filter((property) => property.getName() === 'plugins')\n const pluginsProperty = pluginsProperties[0]\n if (pluginsProperties.length !== 1 || !pluginsProperty) {\n return failure('The Vite config must contain a plugins array.')\n }\n\n const pluginsArray = pluginsProperty.getInitializer()\n if (!Node.isArrayLiteralExpression(pluginsArray)) {\n return failure('The Vite config must contain a plugins array.')\n }\n\n if (pluginsArray.getElements().some(Node.isSpreadElement)) {\n return failure('Plugin array spreads cannot be transformed safely.')\n }\n\n const frameworkImport = getFrameworkImport({ appDetails, sourceFile })\n if (!frameworkImport) {\n return failure('Could not identify the TanStack framework plugin import.')\n }\n\n const reactPluginName = getDefaultImportLocalName({\n moduleSpecifier: '@vitejs/plugin-react',\n sourceFile,\n })\n\n if (!reactPluginName) {\n return failure('Could not identify the React plugin import.')\n }\n\n const pluginCalls = pluginsArray\n .getElements()\n .map((element) =>\n Node.isCallExpression(element)\n ? { name: element.getExpression().getText(), element }\n : { name: undefined, element },\n )\n const frameworkCalls = pluginCalls.filter(({ name }) => name === frameworkImport.localName)\n const reactCalls = pluginCalls.filter(({ name }) => name === reactPluginName)\n\n if (frameworkCalls.length !== 1) {\n return failure('Expected exactly one TanStack framework plugin call.')\n }\n\n if (reactCalls.length !== 1) {\n return failure('Expected exactly one React plugin call.')\n }\n\n const frameworkIndex = pluginCalls.indexOf(frameworkCalls[0]!)\n const reactIndex = pluginCalls.indexOf(reactCalls[0]!)\n\n if (reactIndex !== frameworkIndex + 1) {\n return failure('Framework and React plugin calls must be adjacent and ordered.')\n }\n\n const frameworkCall = frameworkCalls[0]!.element\n const reactCall = reactCalls[0]!.element\n if (\n !Node.isCallExpression(frameworkCall) ||\n !Node.isCallExpression(reactCall) ||\n frameworkCall.getArguments().length > 1 ||\n reactCall.getArguments().length > 1\n ) {\n return failure('Framework and React plugin calls must receive at most one argument.')\n }\n\n const destinationValidation = validateDestinationBindings({ sourceFile })\n if (!destinationValidation.success) {\n return destinationValidation\n }\n\n replacePluginCalls({\n frameworkCall,\n frameworkIndex,\n pluginsArray,\n preserveFrameworkOptions: appDetails.kind === 'start',\n reactCall,\n reactIndex,\n reactPluginName,\n })\n\n const transformedConfig = configArgument.getText()\n defineConfigCall.replaceWithText(`defineConfig(\n withPayload(\n ({ pluginOptions }) => (${transformedConfig}),\n {\n payloadConfigPath: ${PAYLOAD_CONFIG_PATH},\n routesDirectory: 'routes',\n },\n ),\n)`)\n\n if (appDetails.kind === 'router-only') {\n removeNamedImport({\n declaration: frameworkImport.declaration,\n importedName: 'tanstackRouter',\n })\n }\n\n ensureNamedImport({\n importedName: 'withPayload',\n moduleSpecifier: '@payloadcms/tanstack-start',\n sourceFile,\n })\n ensureNamedImport({\n importedName: 'tanstackStart',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n sourceFile,\n })\n ensureDefaultImport({\n defaultImport: 'rsc',\n moduleSpecifier: '@vitejs/plugin-rsc',\n sourceFile,\n })\n ensurePathImport(sourceFile)\n\n if (destinationValidation.shouldAddDirname) {\n ensureNamedImport({\n importedName: 'fileURLToPath',\n moduleSpecifier: 'node:url',\n sourceFile,\n })\n sourceFile.insertStatements(\n sourceFile.getImportDeclarations().length,\n `const __dirname = path.dirname(fileURLToPath(import.meta.url))`,\n )\n }\n\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction ensureDefaultImport({\n defaultImport,\n moduleSpecifier,\n sourceFile,\n}: {\n defaultImport: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const matchingImport = sourceFile\n .getImportDeclarations()\n .find(\n (declaration) =>\n declaration.getModuleSpecifierValue() === moduleSpecifier &&\n declaration.getDefaultImport()?.getText() === defaultImport,\n )\n\n if (!matchingImport) {\n sourceFile.addImportDeclaration({ defaultImport, moduleSpecifier })\n }\n}\n\nfunction ensureNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const imports = sourceFile\n .getImportDeclarations()\n .filter((declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier)\n const hasImport = imports.some((declaration) =>\n declaration\n .getNamedImports()\n .some((namedImport) => namedImport.getName() === importedName && !namedImport.getAliasNode()),\n )\n\n if (hasImport) {\n return\n }\n\n const extensibleImport = imports.find((declaration) => !declaration.getNamespaceImport())\n if (extensibleImport) {\n extensibleImport.addNamedImport(importedName)\n } else {\n sourceFile.addImportDeclaration({ moduleSpecifier, namedImports: [importedName] })\n }\n}\n\nfunction ensurePathImport(sourceFile: SourceFile) {\n const hasCompatibleImport = sourceFile.getImportDeclarations().some((declaration) => {\n if (declaration.getModuleSpecifierValue() !== 'node:path') {\n return false\n }\n\n return (\n declaration.getDefaultImport()?.getText() === 'path' ||\n declaration.getNamespaceImport()?.getText() === 'path'\n )\n })\n\n if (!hasCompatibleImport) {\n sourceFile.addImportDeclaration({ defaultImport: 'path', moduleSpecifier: 'node:path' })\n }\n}\n\nfunction failure(reason: string): TextTransformResult {\n return { reason, success: false }\n}\n\nfunction getLocalBindings({\n localName,\n sourceFile,\n}: {\n localName: string\n sourceFile: SourceFile\n}): LocalBinding[] {\n const bindings: LocalBinding[] = []\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const defaultImport = declaration.getDefaultImport()\n if (defaultImport?.getText() === localName) {\n bindings.push({\n declaration,\n importKind: 'default',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n const namespaceImport = declaration.getNamespaceImport()\n if (namespaceImport?.getText() === localName) {\n bindings.push({\n declaration,\n importKind: 'namespace',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n const namedImportLocalName = namedImport.getAliasNode()?.getText() ?? namedImport.getName()\n if (namedImportLocalName === localName) {\n bindings.push({\n declaration,\n importedName: namedImport.getName(),\n importKind: 'named',\n isTypeOnly: declaration.isTypeOnly() || namedImport.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n }\n }\n\n for (const declaration of sourceFile.getVariableDeclarations()) {\n if (bindingNameIncludes({ localName, node: declaration.getNameNode() })) {\n bindings.push({ kind: 'variable' })\n }\n }\n\n const hasOtherDeclaration = [\n ...sourceFile.getClasses(),\n ...sourceFile.getEnums(),\n ...sourceFile.getFunctions(),\n ...sourceFile.getModules(),\n ].some((declaration) => declaration.getName() === localName)\n\n if (hasOtherDeclaration) {\n bindings.push({ kind: 'other' })\n }\n\n return bindings\n}\n\nfunction bindingNameIncludes({ localName, node }: { localName: string; node: MorphNode }): boolean {\n if (Node.isIdentifier(node)) {\n return node.getText() === localName\n }\n\n if (Node.isArrayBindingPattern(node) || Node.isObjectBindingPattern(node)) {\n return node\n .getElements()\n .some(\n (element) =>\n Node.isBindingElement(element) &&\n bindingNameIncludes({ localName, node: element.getNameNode() }),\n )\n }\n\n return false\n}\n\nfunction getNamedPluginCalls({\n elements,\n localName,\n}: {\n elements: Expression[]\n localName: string\n}): CallExpression[] {\n return elements.filter(\n (element): element is CallExpression =>\n Node.isCallExpression(element) && element.getExpression().getText() === localName,\n )\n}\n\nfunction hasCompatibleDirnameBinding(sourceFile: SourceFile): boolean {\n const bindings = getLocalBindings({ localName: '__dirname', sourceFile })\n\n return bindings.length === 1 && bindings[0]?.kind === 'variable'\n}\n\nfunction hasOnlyCompatibleBinding({\n localName,\n predicate,\n sourceFile,\n}: {\n localName: string\n predicate: (binding: LocalBinding) => boolean\n sourceFile: SourceFile\n}): boolean {\n const bindings = getLocalBindings({ localName, sourceFile })\n\n return bindings.length === 1 && predicate(bindings[0]!)\n}\n\nfunction isCompatiblePathBinding(binding: LocalBinding): boolean {\n return (\n binding.kind === 'import' &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === 'node:path' &&\n (binding.importKind === 'default' || binding.importKind === 'namespace')\n )\n}\n\nfunction isExactPluginCall({\n call,\n expectedArgument,\n}: {\n call: CallExpression\n expectedArgument: string\n}): boolean {\n return call.getArguments().length === 1 && call.getArguments()[0]?.getText() === expectedArgument\n}\n\nfunction isMergedPluginCall({\n call,\n expectedArgument,\n}: {\n call: CallExpression\n expectedArgument: string\n}): boolean {\n if (isExactPluginCall({ call, expectedArgument })) {\n return true\n }\n\n const argument = call.getArguments()[0]\n if (call.getArguments().length !== 1 || !Node.isObjectLiteralExpression(argument)) {\n return false\n }\n\n const firstProperty = argument.getProperties()[0]\n return (\n Node.isSpreadAssignment(firstProperty) &&\n firstProperty.getExpression().getText() === expectedArgument\n )\n}\n\nfunction isImportBinding({\n binding,\n importedName,\n importKind,\n moduleSpecifier,\n}: {\n binding: LocalBinding\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n moduleSpecifier: string\n}): boolean {\n return (\n binding.kind === 'import' &&\n !binding.isTypeOnly &&\n binding.importKind === importKind &&\n binding.moduleSpecifier === moduleSpecifier &&\n (importedName === undefined || binding.importedName === importedName)\n )\n}\n\nfunction validateDestinationBindings({\n sourceFile,\n}: {\n sourceFile: SourceFile\n}): { reason: string; success: false } | { shouldAddDirname: boolean; success: true } {\n const destinations: Array<{\n localName: string\n predicate: (binding: LocalBinding) => boolean\n }> = [\n {\n localName: 'withPayload',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'withPayload',\n importKind: 'named',\n moduleSpecifier: '@payloadcms/tanstack-start',\n }),\n },\n {\n localName: 'tanstackStart',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'tanstackStart',\n importKind: 'named',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n }),\n },\n {\n localName: 'rsc',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importKind: 'default',\n moduleSpecifier: '@vitejs/plugin-rsc',\n }),\n },\n { localName: 'path', predicate: isCompatiblePathBinding },\n ]\n\n for (const destination of destinations) {\n const bindings = getLocalBindings({ localName: destination.localName, sourceFile })\n if (bindings.length > 0 && (bindings.length !== 1 || !destination.predicate(bindings[0]!))) {\n return {\n reason: `Identifier \"${destination.localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n }\n\n const dirnameBindings = getLocalBindings({ localName: '__dirname', sourceFile })\n if (\n dirnameBindings.length > 0 &&\n (dirnameBindings.length !== 1 || dirnameBindings[0]?.kind !== 'variable')\n ) {\n return { reason: 'Identifier \"__dirname\" is already bound incompatibly.', success: false }\n }\n\n const shouldAddDirname = dirnameBindings.length === 0\n if (shouldAddDirname) {\n const fileURLToPathBindings = getLocalBindings({ localName: 'fileURLToPath', sourceFile })\n if (\n fileURLToPathBindings.length > 0 &&\n (fileURLToPathBindings.length !== 1 ||\n !isImportBinding({\n binding: fileURLToPathBindings[0]!,\n importedName: 'fileURLToPath',\n importKind: 'named',\n moduleSpecifier: 'node:url',\n }))\n ) {\n return {\n reason: 'Identifier \"fileURLToPath\" is already bound incompatibly.',\n success: false,\n }\n }\n }\n\n return { shouldAddDirname, success: true }\n}\n\nfunction getDefaultImportLocalName({\n moduleSpecifier,\n sourceFile,\n}: {\n moduleSpecifier: string\n sourceFile: SourceFile\n}): string | undefined {\n const imports = sourceFile\n .getImportDeclarations()\n .filter((declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier)\n .map((declaration) => declaration.getDefaultImport()?.getText())\n .filter((name): name is string => Boolean(name))\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const localName = imports[0]!\n return hasOnlyCompatibleBinding({\n localName,\n predicate: (binding) => isImportBinding({ binding, importKind: 'default', moduleSpecifier }),\n sourceFile,\n })\n ? localName\n : undefined\n}\n\nfunction getFrameworkImport({\n appDetails,\n sourceFile,\n}: {\n appDetails: TanStackAppDetails\n sourceFile: SourceFile\n}): { declaration: ImportDeclaration; localName: string } | undefined {\n const importedName = appDetails.kind === 'start' ? 'tanstackStart' : 'tanstackRouter'\n const moduleSpecifier =\n appDetails.kind === 'start'\n ? '@tanstack/react-start/plugin/vite'\n : '@tanstack/router-plugin/vite'\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n if (declaration.getModuleSpecifierValue() !== moduleSpecifier) {\n continue\n }\n\n const namedImport = declaration\n .getNamedImports()\n .find((specifier) => specifier.getName() === importedName)\n\n if (namedImport) {\n return {\n declaration,\n localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName(),\n }\n }\n }\n}\n\nfunction isCompatiblePayloadConfig({\n sourceFile,\n withPayloadCall,\n}: {\n sourceFile: SourceFile\n withPayloadCall: CallExpression\n}): boolean {\n if (\n withPayloadCall.getArguments().length !== 2 ||\n !hasOnlyCompatibleBinding({\n localName: 'withPayload',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'withPayload',\n importKind: 'named',\n moduleSpecifier: '@payloadcms/tanstack-start',\n }),\n sourceFile,\n })\n ) {\n return false\n }\n\n const [callback, options] = withPayloadCall.getArguments()\n\n if (!Node.isArrowFunction(callback) || !Node.isObjectLiteralExpression(options)) {\n return false\n }\n\n const callbackParameters = callback.getParameters()\n const callbackParameter = callbackParameters[0]\n const callbackBinding = callbackParameter?.getNameNode()\n if (\n callbackParameters.length !== 1 ||\n !callbackParameter ||\n !Node.isObjectBindingPattern(callbackBinding) ||\n callbackBinding.getElements().length !== 1 ||\n callbackBinding.getElements()[0]?.getName() !== 'pluginOptions' ||\n callbackBinding.getElements()[0]?.getPropertyNameNode() ||\n callbackBinding.getElements()[0]?.getInitializer() ||\n callbackBinding.getElements()[0]?.getDotDotDotToken()\n ) {\n return false\n }\n\n const callbackBody = callback.getBody()\n const configObject = Node.isParenthesizedExpression(callbackBody)\n ? callbackBody.getExpression()\n : callbackBody\n\n if (!Node.isObjectLiteralExpression(configObject)) {\n return false\n }\n\n if (configObject.getProperties().some(Node.isSpreadAssignment)) {\n return false\n }\n\n const pluginsProperties = configObject\n .getProperties()\n .filter(Node.isPropertyAssignment)\n .filter((property) => property.getName() === 'plugins')\n const pluginsArray = pluginsProperties[0]?.getInitializer()\n\n if (\n pluginsProperties.length !== 1 ||\n !Node.isArrayLiteralExpression(pluginsArray) ||\n pluginsArray.getElements().some(Node.isSpreadElement)\n ) {\n return false\n }\n\n const reactPluginName = getDefaultImportLocalName({\n moduleSpecifier: '@vitejs/plugin-react',\n sourceFile,\n })\n if (\n !reactPluginName ||\n !hasOnlyCompatibleBinding({\n localName: 'rsc',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importKind: 'default',\n moduleSpecifier: '@vitejs/plugin-rsc',\n }),\n sourceFile,\n }) ||\n !hasOnlyCompatibleBinding({\n localName: 'tanstackStart',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'tanstackStart',\n importKind: 'named',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n }),\n sourceFile,\n }) ||\n !hasOnlyCompatibleBinding({\n localName: 'path',\n predicate: isCompatiblePathBinding,\n sourceFile,\n }) ||\n !hasCompatibleDirnameBinding(sourceFile)\n ) {\n return false\n }\n\n const dirnameInitializer = sourceFile\n .getVariableDeclaration('__dirname')\n ?.getInitializer()\n ?.getText()\n if (\n dirnameInitializer === 'path.dirname(fileURLToPath(import.meta.url))' &&\n !hasOnlyCompatibleBinding({\n localName: 'fileURLToPath',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'fileURLToPath',\n importKind: 'named',\n moduleSpecifier: 'node:url',\n }),\n sourceFile,\n })\n ) {\n return false\n }\n\n const elements = pluginsArray.getElements()\n const rscCalls = getNamedPluginCalls({ elements, localName: 'rsc' })\n const frameworkCalls = getNamedPluginCalls({ elements, localName: 'tanstackStart' })\n const reactCalls = getNamedPluginCalls({ elements, localName: reactPluginName })\n\n if (\n rscCalls.length !== 1 ||\n frameworkCalls.length !== 1 ||\n reactCalls.length !== 1 ||\n !isExactPluginCall({ call: rscCalls[0]!, expectedArgument: 'pluginOptions.rsc' }) ||\n !isMergedPluginCall({\n call: frameworkCalls[0]!,\n expectedArgument: 'pluginOptions.tanstackStart',\n }) ||\n !isMergedPluginCall({ call: reactCalls[0]!, expectedArgument: 'pluginOptions.react' })\n ) {\n return false\n }\n\n const rscIndex = elements.indexOf(rscCalls[0]!)\n const frameworkIndex = elements.indexOf(frameworkCalls[0]!)\n const reactIndex = elements.indexOf(reactCalls[0]!)\n if (frameworkIndex !== rscIndex + 1 || reactIndex !== frameworkIndex + 1) {\n return false\n }\n\n const optionProperties = options.getProperties().filter(Node.isPropertyAssignment)\n if (optionProperties.length !== 2 || options.getProperties().length !== 2) {\n return false\n }\n\n const payloadConfigPath = optionProperties.find(\n (property) => property.getName() === 'payloadConfigPath',\n )\n const routesDirectory = optionProperties.find(\n (property) => property.getName() === 'routesDirectory',\n )\n const routesDirectoryInitializer = routesDirectory?.getInitializer()\n\n return (\n payloadConfigPath?.getInitializer()?.getText() === PAYLOAD_CONFIG_PATH &&\n Node.isStringLiteral(routesDirectoryInitializer) &&\n routesDirectoryInitializer.getLiteralValue() === 'routes'\n )\n}\n\nfunction removeNamedImport({\n declaration,\n importedName,\n}: {\n declaration: ImportDeclaration\n importedName: string\n}) {\n const namedImport = declaration\n .getNamedImports()\n .find((specifier) => specifier.getName() === importedName)\n\n namedImport?.remove()\n\n if (\n declaration.getNamedImports().length === 0 &&\n !declaration.getDefaultImport() &&\n !declaration.getNamespaceImport()\n ) {\n declaration.remove()\n }\n}\n\nfunction replacePluginCalls({\n frameworkCall,\n frameworkIndex,\n pluginsArray,\n preserveFrameworkOptions,\n reactCall,\n reactIndex,\n reactPluginName,\n}: {\n frameworkCall: CallExpression\n frameworkIndex: number\n pluginsArray: ArrayLiteralExpression\n preserveFrameworkOptions: boolean\n reactCall: CallExpression\n reactIndex: number\n reactPluginName: string\n}) {\n const retainedPlugins = pluginsArray\n .getElements()\n .filter((_, index) => index !== frameworkIndex && index !== reactIndex)\n .map((element) => element.getText())\n const insertionIndex = Math.min(frameworkIndex, reactIndex)\n\n retainedPlugins.splice(\n insertionIndex,\n 0,\n 'rsc(pluginOptions.rsc)',\n getPluginCallWithMergedOptions({\n call: frameworkCall,\n localName: 'tanstackStart',\n pluginOptions: 'pluginOptions.tanstackStart',\n shouldPreserveOptions: preserveFrameworkOptions,\n }),\n getPluginCallWithMergedOptions({\n call: reactCall,\n localName: reactPluginName,\n pluginOptions: 'pluginOptions.react',\n shouldPreserveOptions: true,\n }),\n )\n\n pluginsArray.replaceWithText(`[${retainedPlugins.join(', ')}]`)\n}\n\nfunction getPluginCallWithMergedOptions({\n call,\n localName,\n pluginOptions,\n shouldPreserveOptions,\n}: {\n call: CallExpression\n localName: string\n pluginOptions: string\n shouldPreserveOptions: boolean\n}): string {\n const existingOptions = shouldPreserveOptions ? call.getArguments()[0] : undefined\n if (!existingOptions) {\n return `${localName}(${pluginOptions})`\n }\n\n if (Node.isObjectLiteralExpression(existingOptions)) {\n const properties = existingOptions.getText().slice(1, -1).trim()\n return `${localName}({ ...${pluginOptions}${properties ? `, ${properties}` : ''} })`\n }\n\n return `${localName}({ ...${pluginOptions}, ...(${existingOptions.getText()}) })`\n}\n"],"names":["Node","Project","QuoteKind","SyntaxKind","PAYLOAD_CONFIG_PATH","transformTanStackViteConfig","appDetails","content","project","manipulationSettings","quoteKind","Single","useInMemoryFileSystem","sourceFile","createSourceFile","defineConfigCalls","getDescendantsOfKind","CallExpression","filter","call","getExpression","getText","length","failure","defineConfigCall","getArguments","configArgument","isCallExpression","isCompatiblePayloadConfig","withPayloadCall","modified","success","isObjectLiteralExpression","getProperties","some","isSpreadAssignment","pluginsProperties","isPropertyAssignment","property","getName","pluginsProperty","pluginsArray","getInitializer","isArrayLiteralExpression","getElements","isSpreadElement","frameworkImport","getFrameworkImport","reactPluginName","getDefaultImportLocalName","moduleSpecifier","pluginCalls","map","element","name","undefined","frameworkCalls","localName","reactCalls","frameworkIndex","indexOf","reactIndex","frameworkCall","reactCall","destinationValidation","validateDestinationBindings","replacePluginCalls","preserveFrameworkOptions","kind","transformedConfig","replaceWithText","removeNamedImport","declaration","importedName","ensureNamedImport","ensureDefaultImport","defaultImport","ensurePathImport","shouldAddDirname","insertStatements","getImportDeclarations","formatText","indentSize","getFullText","matchingImport","find","getModuleSpecifierValue","getDefaultImport","addImportDeclaration","imports","hasImport","getNamedImports","namedImport","getAliasNode","extensibleImport","getNamespaceImport","addNamedImport","namedImports","hasCompatibleImport","reason","getLocalBindings","bindings","push","importKind","isTypeOnly","namespaceImport","namedImportLocalName","getVariableDeclarations","bindingNameIncludes","node","getNameNode","hasOtherDeclaration","getClasses","getEnums","getFunctions","getModules","isIdentifier","isArrayBindingPattern","isObjectBindingPattern","isBindingElement","getNamedPluginCalls","elements","hasCompatibleDirnameBinding","hasOnlyCompatibleBinding","predicate","isCompatiblePathBinding","binding","isExactPluginCall","expectedArgument","isMergedPluginCall","argument","firstProperty","isImportBinding","destinations","destination","dirnameBindings","fileURLToPathBindings","Boolean","specifier","callback","options","isArrowFunction","callbackParameters","getParameters","callbackParameter","callbackBinding","getPropertyNameNode","getDotDotDotToken","callbackBody","getBody","configObject","isParenthesizedExpression","dirnameInitializer","getVariableDeclaration","rscCalls","rscIndex","optionProperties","payloadConfigPath","routesDirectory","routesDirectoryInitializer","isStringLiteral","getLiteralValue","remove","retainedPlugins","_","index","insertionIndex","Math","min","splice","getPluginCallWithMergedOptions","pluginOptions","shouldPreserveOptions","join","existingOptions","properties","slice","trim"],"mappings":"AASA,SAASA,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,UAAU,QAAQ,WAAU;AAmB/D,MAAMC,sBAAsB;AAE5B,OAAO,SAASC,4BAA4B,EAC1CC,UAAU,EACVC,OAAO,EAIR;IACC,MAAMC,UAAU,IAAIP,QAAQ;QAC1BQ,sBAAsB;YAAEC,WAAWR,UAAUS,MAAM;QAAC;QACpDC,uBAAuB;IACzB;IACA,MAAMC,aAAaL,QAAQM,gBAAgB,CAAC,kBAAkBP;IAC9D,MAAMQ,oBAAoBF,WACvBG,oBAAoB,CAACb,WAAWc,cAAc,EAC9CC,MAAM,CAAC,CAACC,OAASA,KAAKC,aAAa,GAAGC,OAAO,OAAO;IAEvD,IAAIN,kBAAkBO,MAAM,KAAK,GAAG;QAClC,OAAOC,QAAQ;IACjB;IAEA,MAAMC,mBAAmBT,iBAAiB,CAAC,EAAE;IAC7C,IAAIS,iBAAiBC,YAAY,GAAGH,MAAM,KAAK,GAAG;QAChD,OAAOC,QAAQ;IACjB;IAEA,MAAMG,iBAAiBF,iBAAiBC,YAAY,EAAE,CAAC,EAAE;IAEzD,IACEzB,KAAK2B,gBAAgB,CAACD,mBACtBA,eAAeN,aAAa,GAAGC,OAAO,OA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,CAACuH,iBAAiB;QACpB,OAAO,GAAGrH,UAAU,CAAC,EAAEkH,cAAc,CAAC,CAAC;IACzC;IAEA,IAAI3K,KAAKgC,yBAAyB,CAAC8I,kBAAkB;QACnD,MAAMC,aAAaD,gBAAgBzJ,OAAO,GAAG2J,KAAK,CAAC,GAAG,CAAC,GAAGC,IAAI;QAC9D,OAAO,GAAGxH,UAAU,MAAM,EAAEkH,gBAAgBI,aAAa,CAAC,EAAE,EAAEA,YAAY,GAAG,GAAG,GAAG,CAAC;IACtF;IAEA,OAAO,GAAGtH,UAAU,MAAM,EAAEkH,cAAc,MAAM,EAAEG,gBAAgBzJ,OAAO,GAAG,IAAI,CAAC;AACnF"}
@@ -1 +1 @@
1
- {"version":3,"file":"update-payload-in-project.d.ts","sourceRoot":"","sources":["../../src/lib/update-payload-in-project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAYrE,KAAK,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAA;AAIzD,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,EACV,YAAY,GACb,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,YAAY,CAAC,CAIxB;AAED,wBAAsB,0BAA0B,CAAC,EAC/C,UAAU,EACV,YAAY,GACb,EAAE;IACD,UAAU,EAAE,cAAc,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuCxB;AAED,wBAAsB,8BAA8B,CAAC,EACnD,UAAU,EACV,YAA4C,EAC5C,YAAY,GACb,EAAE;IACD,UAAU,EAAE,kBAAkB,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,YAAY,CAAC,CA2BxB;AAED,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,cAAc,EAC1B,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,YAAY,CAAC,CAEvB"}
1
+ {"version":3,"file":"update-payload-in-project.d.ts","sourceRoot":"","sources":["../../src/lib/update-payload-in-project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAYrE,KAAK,YAAY,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAA;AAIzD,wBAAsB,qBAAqB,CAAC,EAC1C,UAAU,EACV,YAAY,GACb,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,YAAY,CAAC,CAIxB;AAED,wBAAsB,0BAA0B,CAAC,EAC/C,UAAU,EACV,YAAY,GACb,EAAE;IACD,UAAU,EAAE,cAAc,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuCxB;AAED,wBAAsB,8BAA8B,CAAC,EACnD,UAAU,EACV,YAA4C,EAC5C,YAAY,GACb,EAAE;IACD,UAAU,EAAE,kBAAkB,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,GAAG,OAAO,CAAC,YAAY,CAAC,CAqCxB;AAED,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,cAAc,EAC1B,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,YAAY,CAAC,CAEvB"}
@@ -69,10 +69,15 @@ export async function updatePayloadInTanStackProject({ appDetails, templateRoot
69
69
  info(`Updating Payload TanStack files...`);
70
70
  const hasPackedTemplateLayout = fse.existsSync(path.join(templateRoot, 'routes'));
71
71
  for (const { destination, relativePath, sourcePath } of TANSTACK_TEMPLATE_FILES){
72
- if (destination !== 'routes' || !relativePath.startsWith('_payload')) {
72
+ const isPayloadRoute = destination === 'routes' && relativePath.startsWith('_payload');
73
+ const isCustomStyles = destination === 'routes' && relativePath === '_payload/custom.css';
74
+ if (!isPayloadRoute) {
75
+ continue;
76
+ }
77
+ const destinationPath = path.join(destination === 'routes' ? appDetails.routesDir : appDetails.sourceDir, relativePath);
78
+ if (isCustomStyles && fse.existsSync(destinationPath)) {
73
79
  continue;
74
80
  }
75
- const destinationPath = path.join(appDetails.routesDir, relativePath);
76
81
  const templatePath = hasPackedTemplateLayout ? path.join(templateRoot, destination, relativePath) : path.join(templateRoot, sourcePath);
77
82
  fse.ensureDirSync(path.dirname(destinationPath));
78
83
  fse.copyFileSync(templatePath, destinationPath);