create-payload-app 4.0.0-internal.fa183d3 → 4.0.0-internal.fec2230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/commands.d.ts +4 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +5 -0
- package/dist/commands.js.map +1 -0
- package/dist/lib/agent-config.d.ts +15 -0
- package/dist/lib/agent-config.d.ts.map +1 -0
- package/dist/lib/agent-config.js +22 -0
- package/dist/lib/agent-config.js.map +1 -0
- package/dist/lib/agent-config.spec.js +23 -0
- package/dist/lib/agent-config.spec.js.map +1 -0
- package/dist/lib/ast/package-json.d.ts +9 -0
- package/dist/lib/ast/package-json.d.ts.map +1 -1
- package/dist/lib/ast/package-json.js +34 -8
- package/dist/lib/ast/package-json.js.map +1 -1
- package/dist/lib/ast/package-json.spec.js +73 -1
- package/dist/lib/ast/package-json.spec.js.map +1 -1
- package/dist/lib/configure-payload-tsconfig.d.ts +5 -0
- package/dist/lib/configure-payload-tsconfig.d.ts.map +1 -0
- package/dist/lib/configure-payload-tsconfig.js +26 -0
- package/dist/lib/configure-payload-tsconfig.js.map +1 -0
- package/dist/lib/configure-payload-tsconfig.spec.js +135 -0
- package/dist/lib/configure-payload-tsconfig.spec.js.map +1 -0
- package/dist/lib/create-project.d.ts +1 -2
- package/dist/lib/create-project.d.ts.map +1 -1
- package/dist/lib/create-project.js +5 -21
- package/dist/lib/create-project.js.map +1 -1
- package/dist/lib/create-project.spec.js +9 -0
- package/dist/lib/create-project.spec.js.map +1 -1
- package/dist/lib/generate-secret.js +1 -1
- package/dist/lib/generate-secret.js.map +1 -1
- package/dist/lib/init-next.d.ts.map +1 -1
- package/dist/lib/init-next.js +5 -34
- package/dist/lib/init-next.js.map +1 -1
- package/dist/lib/init-tanstack-default-template.spec.js +121 -0
- package/dist/lib/init-tanstack-default-template.spec.js.map +1 -0
- package/dist/lib/init-tanstack.d.ts +18 -0
- package/dist/lib/init-tanstack.d.ts.map +1 -0
- package/dist/lib/init-tanstack.js +150 -0
- package/dist/lib/init-tanstack.js.map +1 -0
- package/dist/lib/init-tanstack.spec.js +394 -0
- package/dist/lib/init-tanstack.spec.js.map +1 -0
- package/dist/lib/tanstack/detect.d.ts +5 -0
- package/dist/lib/tanstack/detect.d.ts.map +1 -0
- package/dist/lib/tanstack/detect.js +131 -0
- package/dist/lib/tanstack/detect.js.map +1 -0
- package/dist/lib/tanstack/detect.spec.js +227 -0
- package/dist/lib/tanstack/detect.spec.js.map +1 -0
- package/dist/lib/tanstack/prepare.d.ts +23 -0
- package/dist/lib/tanstack/prepare.d.ts.map +1 -0
- package/dist/lib/tanstack/prepare.js +114 -0
- package/dist/lib/tanstack/prepare.js.map +1 -0
- package/dist/lib/tanstack/prepare.spec.js +288 -0
- package/dist/lib/tanstack/prepare.spec.js.map +1 -0
- package/dist/lib/tanstack/template-files.d.ts +50 -0
- package/dist/lib/tanstack/template-files.d.ts.map +1 -0
- package/dist/lib/tanstack/template-files.js +64 -0
- package/dist/lib/tanstack/template-files.js.map +1 -0
- package/dist/lib/tanstack/transform-root-route.d.ts +7 -0
- package/dist/lib/tanstack/transform-root-route.d.ts.map +1 -0
- package/dist/lib/tanstack/transform-root-route.js +747 -0
- package/dist/lib/tanstack/transform-root-route.js.map +1 -0
- package/dist/lib/tanstack/transform-root-route.spec.js +484 -0
- package/dist/lib/tanstack/transform-root-route.spec.js.map +1 -0
- package/dist/lib/tanstack/transform-router.d.ts +5 -0
- package/dist/lib/tanstack/transform-router.d.ts.map +1 -0
- package/dist/lib/tanstack/transform-router.js +301 -0
- package/dist/lib/tanstack/transform-router.js.map +1 -0
- package/dist/lib/tanstack/transform-router.spec.js +264 -0
- package/dist/lib/tanstack/transform-router.spec.js.map +1 -0
- package/dist/lib/tanstack/transform-vite-config.d.ts +14 -0
- package/dist/lib/tanstack/transform-vite-config.d.ts.map +1 -0
- package/dist/lib/tanstack/transform-vite-config.js +576 -0
- package/dist/lib/tanstack/transform-vite-config.js.map +1 -0
- package/dist/lib/tanstack/transform-vite-config.spec.js +456 -0
- package/dist/lib/tanstack/transform-vite-config.spec.js.map +1 -0
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +6 -0
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/update-payload-in-project.d.ts +18 -3
- package/dist/lib/update-payload-in-project.d.ts.map +1 -1
- package/dist/lib/update-payload-in-project.js +98 -18
- package/dist/lib/update-payload-in-project.js.map +1 -1
- package/dist/lib/update-payload-in-project.spec.js +262 -0
- package/dist/lib/update-payload-in-project.spec.js.map +1 -0
- package/dist/main.d.ts +20 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +120 -29
- package/dist/main.js.map +1 -1
- package/dist/main.spec.js +102 -0
- package/dist/main.spec.js.map +1 -0
- package/dist/scripts/pack-template-files.js +18 -0
- package/dist/scripts/pack-template-files.js.map +1 -1
- package/dist/template/src/app/(frontend)/styles.css +1 -1
- package/dist/template/src/app/(payload)/layout.tsx +1 -1
- package/dist/template-tanstack/routes/_payload/admin.$.tsx +8 -0
- package/dist/template-tanstack/routes/_payload/admin.index.tsx +8 -0
- package/dist/template-tanstack/routes/_payload/api.$.ts +10 -0
- package/dist/template-tanstack/routes/_payload/importMap.js +32 -0
- package/dist/template-tanstack/routes/_payload/server.functions.ts +49 -0
- package/dist/template-tanstack/routes/_payload.tsx +30 -0
- package/dist/template-tanstack/src/collections/Folders.ts +16 -0
- package/dist/template-tanstack/src/collections/Media.ts +20 -0
- package/dist/template-tanstack/src/collections/Tags.ts +16 -0
- package/dist/template-tanstack/src/collections/Users.ts +14 -0
- package/dist/template-tanstack/src/payload.config.ts +40 -0
- package/dist/template-tanstack/src/payload.css +1 -0
- package/dist/types.d.ts +22 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/messages.d.ts +1 -0
- package/dist/utils/messages.d.ts.map +1 -1
- package/dist/utils/messages.js +8 -6
- package/dist/utils/messages.js.map +1 -1
- package/package.json +4 -4
- package/dist/lib/download-skill.d.ts +0 -8
- package/dist/lib/download-skill.d.ts.map +0 -1
- package/dist/lib/download-skill.js +0 -35
- package/dist/lib/download-skill.js.map +0 -1
- package/dist/lib/select-agent.d.ts +0 -16
- package/dist/lib/select-agent.d.ts.map +0 -1
- package/dist/lib/select-agent.js +0 -67
- package/dist/lib/select-agent.js.map +0 -1
- /package/dist/template/src/app/(payload)/{custom.scss → custom.css} +0 -0
|
@@ -0,0 +1 @@
|
|
|
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,IAAI,EAIL;IACC,MAAMC,UAAU,IAAIR,QAAQ;QAC1BS,sBAAsB;YAAEC,WAAWT,UAAUU,MAAM;QAAC;QACpDC,uBAAuB;IACzB;IACA,MAAMC,aAAaL,QAAQM,gBAAgB,CAAC,cAAcR;IAC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AAK,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"}
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import { Project } from 'ts-morph';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { transformTanStackRootRoute } from './transform-root-route.js';
|
|
4
|
+
function expectSuccessfulTransform(result) {
|
|
5
|
+
expect(result.success).toBe(true);
|
|
6
|
+
if (!result.success) {
|
|
7
|
+
throw new Error(result.reason);
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
function getStartRoot({ appCssHref = 'appCss', extraImports = '', shellComponent = 'RootDocument' } = {}) {
|
|
12
|
+
return `import { createRootRoute as createAppRoot, HeadContent, Scripts } from '@tanstack/react-router'
|
|
13
|
+
import appCss from '../styles.css?url'
|
|
14
|
+
import { ThemeProvider } from './theme-provider'
|
|
15
|
+
${extraImports}
|
|
16
|
+
|
|
17
|
+
export const Route = createAppRoot({
|
|
18
|
+
head: () => ({
|
|
19
|
+
meta: [
|
|
20
|
+
{ charSet: 'utf-8' },
|
|
21
|
+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
22
|
+
{ title: 'Custom title' },
|
|
23
|
+
],
|
|
24
|
+
links: [
|
|
25
|
+
{ rel: 'stylesheet', href: ${appCssHref} },
|
|
26
|
+
{ rel: 'preconnect', href: 'https://fonts.googleapis.com' },
|
|
27
|
+
],
|
|
28
|
+
}),
|
|
29
|
+
notFoundComponent: NotFound,
|
|
30
|
+
shellComponent: ${shellComponent},
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
function RootDocument({ children }: { children: React.ReactNode }) {
|
|
34
|
+
return (
|
|
35
|
+
<html lang="en">
|
|
36
|
+
<head>
|
|
37
|
+
<meta name="theme-color" content="black" />
|
|
38
|
+
<HeadContent />
|
|
39
|
+
</head>
|
|
40
|
+
<body>
|
|
41
|
+
<ThemeProvider>{children}</ThemeProvider>
|
|
42
|
+
<Scripts />
|
|
43
|
+
</body>
|
|
44
|
+
</html>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
function getRouterOnlyRoot({ extraImports = '', stylesheetImport = `import '../styles.css'` } = {}) {
|
|
50
|
+
return `import { createRootRoute as createAppRoot, Outlet } from '@tanstack/react-router'
|
|
51
|
+
import { AuthProvider } from './auth-provider'
|
|
52
|
+
${stylesheetImport}
|
|
53
|
+
${extraImports}
|
|
54
|
+
|
|
55
|
+
export const Route = createAppRoot({
|
|
56
|
+
component: RootComponent,
|
|
57
|
+
head: () => ({
|
|
58
|
+
meta: [{ title: 'Router app' }],
|
|
59
|
+
links: [{ rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
|
|
60
|
+
}),
|
|
61
|
+
notFoundComponent: NotFound,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
function RootComponent() {
|
|
65
|
+
return (
|
|
66
|
+
<AuthProvider>
|
|
67
|
+
<main data-layout="custom">
|
|
68
|
+
<Outlet />
|
|
69
|
+
</main>
|
|
70
|
+
</AuthProvider>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
function getRouterOnlyDocumentRoot(returnExpression) {
|
|
76
|
+
return `import { Outlet, createRootRoute } from '@tanstack/react-router'
|
|
77
|
+
|
|
78
|
+
import '../styles.css'
|
|
79
|
+
|
|
80
|
+
export const Route = createRootRoute({
|
|
81
|
+
component: RootComponent,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
function RootComponent() {
|
|
85
|
+
return (${returnExpression})
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
function getRouterNamedImports(content, importedNames) {
|
|
90
|
+
const project = new Project({
|
|
91
|
+
useInMemoryFileSystem: true
|
|
92
|
+
});
|
|
93
|
+
const sourceFile = project.createSourceFile('__root.tsx', content);
|
|
94
|
+
return sourceFile.getImportDeclarations().filter((declaration)=>declaration.getModuleSpecifierValue() === '@tanstack/react-router').flatMap((declaration)=>declaration.getNamedImports().filter((namedImport)=>importedNames.includes(namedImport.getName())).map((namedImport)=>({
|
|
95
|
+
importedName: namedImport.getName(),
|
|
96
|
+
localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName()
|
|
97
|
+
})));
|
|
98
|
+
}
|
|
99
|
+
describe('transformTanStackRootRoute', ()=>{
|
|
100
|
+
it('should wrap the official Start shell and isolate its app stylesheet from admin', ()=>{
|
|
101
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
102
|
+
content: getStartRoot(),
|
|
103
|
+
kind: 'start'
|
|
104
|
+
}));
|
|
105
|
+
expect(result.modified).toBe(true);
|
|
106
|
+
expect(result.content).toContain("import { withPayloadRoot } from '@payloadcms/tanstack-start/client'");
|
|
107
|
+
expect(result.content).toContain('shellComponent: withPayloadRoot(RootDocument)');
|
|
108
|
+
expect(result.content).not.toContain("{ rel: 'stylesheet', href: appCss }");
|
|
109
|
+
expect(result.content).toContain('<link href={appCss} rel="stylesheet" />');
|
|
110
|
+
expect(result.content.indexOf('<link href={appCss}')).toBeLessThan(result.content.indexOf('<HeadContent />'));
|
|
111
|
+
});
|
|
112
|
+
it('should preserve Start metadata, non-stylesheet links, components, and providers', ()=>{
|
|
113
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
114
|
+
content: getStartRoot(),
|
|
115
|
+
kind: 'start'
|
|
116
|
+
}));
|
|
117
|
+
expect(result.content).toContain("{ charSet: 'utf-8' }");
|
|
118
|
+
expect(result.content).toContain("{ name: 'viewport', content: 'width=device-width, initial-scale=1' }");
|
|
119
|
+
expect(result.content).toContain("{ title: 'Custom title' }");
|
|
120
|
+
expect(result.content).toContain("{ rel: 'preconnect', href: 'https://fonts.googleapis.com' }");
|
|
121
|
+
expect(result.content).toContain('notFoundComponent: NotFound');
|
|
122
|
+
expect(result.content).toContain('<meta name="theme-color" content="black" />');
|
|
123
|
+
expect(result.content).toContain('<ThemeProvider>{children}</ThemeProvider>');
|
|
124
|
+
});
|
|
125
|
+
it('should convert the official Router-only root without replacing its route component', ()=>{
|
|
126
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
127
|
+
content: getRouterOnlyRoot(),
|
|
128
|
+
kind: 'router-only'
|
|
129
|
+
}));
|
|
130
|
+
expect(result.modified).toBe(true);
|
|
131
|
+
expect(result.content).toContain("import appCss from '../styles.css?url'");
|
|
132
|
+
expect(result.content).not.toContain("import '../styles.css'");
|
|
133
|
+
expect(result.content).toContain('component: RootComponent');
|
|
134
|
+
expect(result.content).toContain('shellComponent: withPayloadRoot(RootDocument)');
|
|
135
|
+
expect(result.content).toContain('function RootComponent()');
|
|
136
|
+
expect(result.content).toContain('<AuthProvider>');
|
|
137
|
+
expect(result.content).toContain('<Outlet />');
|
|
138
|
+
expect(result.content).toContain('function RootDocument({ children }: { children: React.ReactNode })');
|
|
139
|
+
expect(result.content).toContain('<html lang="en" suppressHydrationWarning>');
|
|
140
|
+
expect(result.content).toContain('<link href={appCss} rel="stylesheet" />');
|
|
141
|
+
expect(result.content).toContain('<HeadContent />');
|
|
142
|
+
expect(result.content).toContain('{children}');
|
|
143
|
+
expect(result.content).toContain('<Scripts />');
|
|
144
|
+
});
|
|
145
|
+
it('should preserve Router-only metadata, non-stylesheet links, and route options', ()=>{
|
|
146
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
147
|
+
content: getRouterOnlyRoot(),
|
|
148
|
+
kind: 'router-only'
|
|
149
|
+
}));
|
|
150
|
+
expect(result.content).toContain("meta: [{ title: 'Router app' }]");
|
|
151
|
+
expect(result.content).toContain("links: [{ rel: 'preconnect', href: 'https://fonts.googleapis.com' }]");
|
|
152
|
+
expect(result.content).toContain('notFoundComponent: NotFound');
|
|
153
|
+
expect(result.content).toContain('<main data-layout="custom">');
|
|
154
|
+
});
|
|
155
|
+
it.each([
|
|
156
|
+
[
|
|
157
|
+
'direct',
|
|
158
|
+
`<html lang="fr"><head><title>My Router App</title></head><body><Outlet /></body></html>`
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
'fragment-wrapped',
|
|
162
|
+
`<><html lang="fr"><head /><body><Outlet /></body></html></>`
|
|
163
|
+
],
|
|
164
|
+
[
|
|
165
|
+
'conditional',
|
|
166
|
+
`isReady ? <html lang="fr"><head /><body><Outlet /></body></html> : null`
|
|
167
|
+
]
|
|
168
|
+
])('should reject a Router-only root whose %s route component renders the document shell', (_shape, returnExpression)=>{
|
|
169
|
+
const content = getRouterOnlyDocumentRoot(returnExpression);
|
|
170
|
+
expect(transformTanStackRootRoute({
|
|
171
|
+
content,
|
|
172
|
+
kind: 'router-only'
|
|
173
|
+
})).toEqual({
|
|
174
|
+
reason: 'The Router-only route component cannot render the document shell.',
|
|
175
|
+
success: false
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
it('should reuse aliased HeadContent and Scripts imports from split declarations', ()=>{
|
|
179
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
180
|
+
content: getRouterOnlyRoot({
|
|
181
|
+
extraImports: `import { HeadContent as RouterHeadContent } from '@tanstack/react-router'
|
|
182
|
+
import { Scripts as RouterScripts } from '@tanstack/react-router'`
|
|
183
|
+
}),
|
|
184
|
+
kind: 'router-only'
|
|
185
|
+
}));
|
|
186
|
+
expect(result.content).toContain('<RouterHeadContent />');
|
|
187
|
+
expect(result.content).toContain('<RouterScripts />');
|
|
188
|
+
expect(getRouterNamedImports(result.content, [
|
|
189
|
+
'HeadContent',
|
|
190
|
+
'Scripts'
|
|
191
|
+
])).toEqual([
|
|
192
|
+
{
|
|
193
|
+
importedName: 'HeadContent',
|
|
194
|
+
localName: 'RouterHeadContent'
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
importedName: 'Scripts',
|
|
198
|
+
localName: 'RouterScripts'
|
|
199
|
+
}
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
it('should preserve split HeadContent and Scripts imports without duplicating bindings', ()=>{
|
|
203
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
204
|
+
content: getRouterOnlyRoot({
|
|
205
|
+
extraImports: `import { HeadContent } from '@tanstack/react-router'
|
|
206
|
+
import { Scripts } from '@tanstack/react-router'`
|
|
207
|
+
}),
|
|
208
|
+
kind: 'router-only'
|
|
209
|
+
}));
|
|
210
|
+
expect(getRouterNamedImports(result.content, [
|
|
211
|
+
'HeadContent',
|
|
212
|
+
'Scripts'
|
|
213
|
+
])).toEqual([
|
|
214
|
+
{
|
|
215
|
+
importedName: 'HeadContent',
|
|
216
|
+
localName: 'HeadContent'
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
importedName: 'Scripts',
|
|
220
|
+
localName: 'Scripts'
|
|
221
|
+
}
|
|
222
|
+
]);
|
|
223
|
+
});
|
|
224
|
+
it('should not add withPayloadRoot to an unrelated type-only client import', ()=>{
|
|
225
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
226
|
+
content: getRouterOnlyRoot({
|
|
227
|
+
extraImports: `import type { ClientOptions } from '@payloadcms/tanstack-start/client'`
|
|
228
|
+
}),
|
|
229
|
+
kind: 'router-only'
|
|
230
|
+
}));
|
|
231
|
+
expect(result.content).toContain("import { withPayloadRoot } from '@payloadcms/tanstack-start/client'");
|
|
232
|
+
expect(result.content).toContain("import type { ClientOptions } from '@payloadcms/tanstack-start/client'");
|
|
233
|
+
});
|
|
234
|
+
it.each([
|
|
235
|
+
[
|
|
236
|
+
'start',
|
|
237
|
+
getStartRoot()
|
|
238
|
+
],
|
|
239
|
+
[
|
|
240
|
+
'router-only',
|
|
241
|
+
getRouterOnlyRoot()
|
|
242
|
+
]
|
|
243
|
+
])('should report an already transformed %s root as unmodified', (kind, content)=>{
|
|
244
|
+
const firstResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
245
|
+
content,
|
|
246
|
+
kind
|
|
247
|
+
}));
|
|
248
|
+
const secondResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
249
|
+
content: firstResult.content,
|
|
250
|
+
kind
|
|
251
|
+
}));
|
|
252
|
+
expect(secondResult).toEqual({
|
|
253
|
+
content: firstResult.content,
|
|
254
|
+
modified: false,
|
|
255
|
+
success: true
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
it.each([
|
|
259
|
+
[
|
|
260
|
+
'start',
|
|
261
|
+
getStartRoot()
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
'router-only',
|
|
265
|
+
getRouterOnlyRoot()
|
|
266
|
+
]
|
|
267
|
+
])('should restore a missing withPayloadRoot import in a transformed %s root', (kind, content)=>{
|
|
268
|
+
const firstResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
269
|
+
content,
|
|
270
|
+
kind
|
|
271
|
+
}));
|
|
272
|
+
const contentWithoutPayloadImport = firstResult.content.replace(/import \{ withPayloadRoot \} from '@payloadcms\/tanstack-start\/client';?\n/, '');
|
|
273
|
+
const result = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
274
|
+
content: contentWithoutPayloadImport,
|
|
275
|
+
kind
|
|
276
|
+
}));
|
|
277
|
+
expect(result.modified).toBe(true);
|
|
278
|
+
expect(result.content).toContain("import { withPayloadRoot } from '@payloadcms/tanstack-start/client'");
|
|
279
|
+
});
|
|
280
|
+
it.each([
|
|
281
|
+
[
|
|
282
|
+
'start',
|
|
283
|
+
getStartRoot()
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
'router-only',
|
|
287
|
+
getRouterOnlyRoot()
|
|
288
|
+
]
|
|
289
|
+
])('should validate an aliased wrapper call against its local import in a transformed %s root', (kind, content)=>{
|
|
290
|
+
const firstResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
291
|
+
content,
|
|
292
|
+
kind
|
|
293
|
+
}));
|
|
294
|
+
const aliasedContent = firstResult.content.replace("import { withPayloadRoot } from '@payloadcms/tanstack-start/client'", "import { withPayloadRoot as payloadRoot } from '@payloadcms/tanstack-start/client'").replace('withPayloadRoot(RootDocument)', 'payloadRoot(RootDocument)');
|
|
295
|
+
const result = transformTanStackRootRoute({
|
|
296
|
+
content: aliasedContent,
|
|
297
|
+
kind
|
|
298
|
+
});
|
|
299
|
+
expect(result).toEqual({
|
|
300
|
+
content: aliasedContent,
|
|
301
|
+
modified: false,
|
|
302
|
+
success: true
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
it.each([
|
|
306
|
+
[
|
|
307
|
+
'start',
|
|
308
|
+
getStartRoot()
|
|
309
|
+
],
|
|
310
|
+
[
|
|
311
|
+
'router-only',
|
|
312
|
+
getRouterOnlyRoot()
|
|
313
|
+
]
|
|
314
|
+
])('should reject a transformed %s root whose canonical wrapper call has only an aliased import', (kind, content)=>{
|
|
315
|
+
const firstResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
316
|
+
content,
|
|
317
|
+
kind
|
|
318
|
+
}));
|
|
319
|
+
const malformedContent = firstResult.content.replace("import { withPayloadRoot } from '@payloadcms/tanstack-start/client'", "import { withPayloadRoot as payloadRoot } from '@payloadcms/tanstack-start/client'");
|
|
320
|
+
const result = transformTanStackRootRoute({
|
|
321
|
+
content: malformedContent,
|
|
322
|
+
kind
|
|
323
|
+
});
|
|
324
|
+
expect(result).toEqual({
|
|
325
|
+
reason: 'The existing shellComponent cannot be transformed safely.',
|
|
326
|
+
success: false
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
it.each([
|
|
330
|
+
[
|
|
331
|
+
'start',
|
|
332
|
+
getStartRoot()
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
'router-only',
|
|
336
|
+
getRouterOnlyRoot()
|
|
337
|
+
]
|
|
338
|
+
])('should reject a transformed %s root with the stylesheet after HeadContent', (kind, content)=>{
|
|
339
|
+
const firstResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
340
|
+
content,
|
|
341
|
+
kind
|
|
342
|
+
}));
|
|
343
|
+
const reorderedContent = firstResult.content.replace('<link href={appCss} rel="stylesheet" />\n <HeadContent />', '<HeadContent />\n <link href={appCss} rel="stylesheet" />');
|
|
344
|
+
const result = transformTanStackRootRoute({
|
|
345
|
+
content: reorderedContent,
|
|
346
|
+
kind
|
|
347
|
+
});
|
|
348
|
+
expect(result.success).toBe(false);
|
|
349
|
+
});
|
|
350
|
+
it('should reject an unrecognized Start shell expression', ()=>{
|
|
351
|
+
const result = transformTanStackRootRoute({
|
|
352
|
+
content: getStartRoot({
|
|
353
|
+
shellComponent: 'createShell(RootDocument)'
|
|
354
|
+
}),
|
|
355
|
+
kind: 'start'
|
|
356
|
+
});
|
|
357
|
+
expect(result).toEqual({
|
|
358
|
+
reason: 'The existing shellComponent cannot be transformed safely.',
|
|
359
|
+
success: false
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
it('should reject an existing Router-only shell component', ()=>{
|
|
363
|
+
const content = getRouterOnlyRoot().replace('component: RootComponent,', 'component: RootComponent,\n shellComponent: CustomShell,');
|
|
364
|
+
const result = transformTanStackRootRoute({
|
|
365
|
+
content,
|
|
366
|
+
kind: 'router-only'
|
|
367
|
+
});
|
|
368
|
+
expect(result).toEqual({
|
|
369
|
+
reason: 'The existing shellComponent cannot be transformed safely.',
|
|
370
|
+
success: false
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
it('should reject multiple root route declarations', ()=>{
|
|
374
|
+
const content = `${getStartRoot()}
|
|
375
|
+
export const OtherRoute = createAppRoot({ shellComponent: RootDocument })
|
|
376
|
+
`;
|
|
377
|
+
const result = transformTanStackRootRoute({
|
|
378
|
+
content,
|
|
379
|
+
kind: 'start'
|
|
380
|
+
});
|
|
381
|
+
expect(result).toEqual({
|
|
382
|
+
reason: 'Expected exactly one createRootRoute() call.',
|
|
383
|
+
success: false
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
it('should reject a Start stylesheet expression that cannot be relocated', ()=>{
|
|
387
|
+
const result = transformTanStackRootRoute({
|
|
388
|
+
content: getStartRoot({
|
|
389
|
+
appCssHref: 'getStylesheetUrl()'
|
|
390
|
+
}),
|
|
391
|
+
kind: 'start'
|
|
392
|
+
});
|
|
393
|
+
expect(result).toEqual({
|
|
394
|
+
reason: 'The app stylesheet link cannot be relocated safely.',
|
|
395
|
+
success: false
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
it('should reject a Start root with an additional side-effect stylesheet import', ()=>{
|
|
399
|
+
const result = transformTanStackRootRoute({
|
|
400
|
+
content: getStartRoot({
|
|
401
|
+
extraImports: `import '../legacy.css'`
|
|
402
|
+
}),
|
|
403
|
+
kind: 'start'
|
|
404
|
+
});
|
|
405
|
+
expect(result).toEqual({
|
|
406
|
+
reason: 'Side-effect stylesheet imports cannot be isolated from admin.',
|
|
407
|
+
success: false
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
it('should reject a transformed Router-only root retaining side-effect CSS', ()=>{
|
|
411
|
+
const firstResult = expectSuccessfulTransform(transformTanStackRootRoute({
|
|
412
|
+
content: getRouterOnlyRoot(),
|
|
413
|
+
kind: 'router-only'
|
|
414
|
+
}));
|
|
415
|
+
const content = `${firstResult.content}\nimport '../legacy.css'\n`;
|
|
416
|
+
const result = transformTanStackRootRoute({
|
|
417
|
+
content,
|
|
418
|
+
kind: 'router-only'
|
|
419
|
+
});
|
|
420
|
+
expect(result).toEqual({
|
|
421
|
+
reason: 'Side-effect stylesheet imports cannot be isolated from admin.',
|
|
422
|
+
success: false
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
it('should reject multiple Router-only side-effect stylesheet imports', ()=>{
|
|
426
|
+
const result = transformTanStackRootRoute({
|
|
427
|
+
content: getRouterOnlyRoot({
|
|
428
|
+
stylesheetImport: `import '../base.css'\nimport '../styles.css'`
|
|
429
|
+
}),
|
|
430
|
+
kind: 'router-only'
|
|
431
|
+
});
|
|
432
|
+
expect(result).toEqual({
|
|
433
|
+
reason: 'Expected exactly one side-effect stylesheet import.',
|
|
434
|
+
success: false
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
it.each([
|
|
438
|
+
[
|
|
439
|
+
'withPayloadRoot',
|
|
440
|
+
`const withPayloadRoot = (component: unknown) => component`
|
|
441
|
+
],
|
|
442
|
+
[
|
|
443
|
+
'appCss',
|
|
444
|
+
`const appCss = '/custom.css'`
|
|
445
|
+
],
|
|
446
|
+
[
|
|
447
|
+
'RootDocument',
|
|
448
|
+
`function RootDocument() { return null }`
|
|
449
|
+
],
|
|
450
|
+
[
|
|
451
|
+
'HeadContent',
|
|
452
|
+
`const HeadContent = CustomHead`
|
|
453
|
+
],
|
|
454
|
+
[
|
|
455
|
+
'Scripts',
|
|
456
|
+
`const Scripts = CustomScripts`
|
|
457
|
+
]
|
|
458
|
+
])('should reject an incompatible Router-only %s destination binding', (name, binding)=>{
|
|
459
|
+
const result = transformTanStackRootRoute({
|
|
460
|
+
content: getRouterOnlyRoot({
|
|
461
|
+
extraImports: binding
|
|
462
|
+
}),
|
|
463
|
+
kind: 'router-only'
|
|
464
|
+
});
|
|
465
|
+
expect(result).toEqual({
|
|
466
|
+
reason: `Identifier "${name}" is already bound incompatibly.`,
|
|
467
|
+
success: false
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
it('should reject a withPayloadRoot import with the wrong provenance', ()=>{
|
|
471
|
+
const result = transformTanStackRootRoute({
|
|
472
|
+
content: getStartRoot({
|
|
473
|
+
extraImports: `import { withPayloadRoot } from 'custom-shell'`
|
|
474
|
+
}),
|
|
475
|
+
kind: 'start'
|
|
476
|
+
});
|
|
477
|
+
expect(result).toEqual({
|
|
478
|
+
reason: 'Identifier "withPayloadRoot" is already bound incompatibly.',
|
|
479
|
+
success: false
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
//# sourceMappingURL=transform-root-route.spec.js.map
|