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.
Files changed (124) hide show
  1. package/README.md +5 -0
  2. package/dist/commands.d.ts +4 -0
  3. package/dist/commands.d.ts.map +1 -0
  4. package/dist/commands.js +5 -0
  5. package/dist/commands.js.map +1 -0
  6. package/dist/lib/agent-config.d.ts +15 -0
  7. package/dist/lib/agent-config.d.ts.map +1 -0
  8. package/dist/lib/agent-config.js +22 -0
  9. package/dist/lib/agent-config.js.map +1 -0
  10. package/dist/lib/agent-config.spec.js +23 -0
  11. package/dist/lib/agent-config.spec.js.map +1 -0
  12. package/dist/lib/ast/package-json.d.ts +9 -0
  13. package/dist/lib/ast/package-json.d.ts.map +1 -1
  14. package/dist/lib/ast/package-json.js +34 -8
  15. package/dist/lib/ast/package-json.js.map +1 -1
  16. package/dist/lib/ast/package-json.spec.js +73 -1
  17. package/dist/lib/ast/package-json.spec.js.map +1 -1
  18. package/dist/lib/configure-payload-tsconfig.d.ts +5 -0
  19. package/dist/lib/configure-payload-tsconfig.d.ts.map +1 -0
  20. package/dist/lib/configure-payload-tsconfig.js +26 -0
  21. package/dist/lib/configure-payload-tsconfig.js.map +1 -0
  22. package/dist/lib/configure-payload-tsconfig.spec.js +135 -0
  23. package/dist/lib/configure-payload-tsconfig.spec.js.map +1 -0
  24. package/dist/lib/create-project.d.ts +1 -2
  25. package/dist/lib/create-project.d.ts.map +1 -1
  26. package/dist/lib/create-project.js +5 -21
  27. package/dist/lib/create-project.js.map +1 -1
  28. package/dist/lib/create-project.spec.js +9 -0
  29. package/dist/lib/create-project.spec.js.map +1 -1
  30. package/dist/lib/generate-secret.js +1 -1
  31. package/dist/lib/generate-secret.js.map +1 -1
  32. package/dist/lib/init-next.d.ts.map +1 -1
  33. package/dist/lib/init-next.js +5 -34
  34. package/dist/lib/init-next.js.map +1 -1
  35. package/dist/lib/init-tanstack-default-template.spec.js +121 -0
  36. package/dist/lib/init-tanstack-default-template.spec.js.map +1 -0
  37. package/dist/lib/init-tanstack.d.ts +18 -0
  38. package/dist/lib/init-tanstack.d.ts.map +1 -0
  39. package/dist/lib/init-tanstack.js +150 -0
  40. package/dist/lib/init-tanstack.js.map +1 -0
  41. package/dist/lib/init-tanstack.spec.js +394 -0
  42. package/dist/lib/init-tanstack.spec.js.map +1 -0
  43. package/dist/lib/tanstack/detect.d.ts +5 -0
  44. package/dist/lib/tanstack/detect.d.ts.map +1 -0
  45. package/dist/lib/tanstack/detect.js +131 -0
  46. package/dist/lib/tanstack/detect.js.map +1 -0
  47. package/dist/lib/tanstack/detect.spec.js +227 -0
  48. package/dist/lib/tanstack/detect.spec.js.map +1 -0
  49. package/dist/lib/tanstack/prepare.d.ts +23 -0
  50. package/dist/lib/tanstack/prepare.d.ts.map +1 -0
  51. package/dist/lib/tanstack/prepare.js +114 -0
  52. package/dist/lib/tanstack/prepare.js.map +1 -0
  53. package/dist/lib/tanstack/prepare.spec.js +288 -0
  54. package/dist/lib/tanstack/prepare.spec.js.map +1 -0
  55. package/dist/lib/tanstack/template-files.d.ts +50 -0
  56. package/dist/lib/tanstack/template-files.d.ts.map +1 -0
  57. package/dist/lib/tanstack/template-files.js +64 -0
  58. package/dist/lib/tanstack/template-files.js.map +1 -0
  59. package/dist/lib/tanstack/transform-root-route.d.ts +7 -0
  60. package/dist/lib/tanstack/transform-root-route.d.ts.map +1 -0
  61. package/dist/lib/tanstack/transform-root-route.js +747 -0
  62. package/dist/lib/tanstack/transform-root-route.js.map +1 -0
  63. package/dist/lib/tanstack/transform-root-route.spec.js +484 -0
  64. package/dist/lib/tanstack/transform-root-route.spec.js.map +1 -0
  65. package/dist/lib/tanstack/transform-router.d.ts +5 -0
  66. package/dist/lib/tanstack/transform-router.d.ts.map +1 -0
  67. package/dist/lib/tanstack/transform-router.js +301 -0
  68. package/dist/lib/tanstack/transform-router.js.map +1 -0
  69. package/dist/lib/tanstack/transform-router.spec.js +264 -0
  70. package/dist/lib/tanstack/transform-router.spec.js.map +1 -0
  71. package/dist/lib/tanstack/transform-vite-config.d.ts +14 -0
  72. package/dist/lib/tanstack/transform-vite-config.d.ts.map +1 -0
  73. package/dist/lib/tanstack/transform-vite-config.js +576 -0
  74. package/dist/lib/tanstack/transform-vite-config.js.map +1 -0
  75. package/dist/lib/tanstack/transform-vite-config.spec.js +456 -0
  76. package/dist/lib/tanstack/transform-vite-config.spec.js.map +1 -0
  77. package/dist/lib/templates.d.ts.map +1 -1
  78. package/dist/lib/templates.js +6 -0
  79. package/dist/lib/templates.js.map +1 -1
  80. package/dist/lib/update-payload-in-project.d.ts +18 -3
  81. package/dist/lib/update-payload-in-project.d.ts.map +1 -1
  82. package/dist/lib/update-payload-in-project.js +98 -18
  83. package/dist/lib/update-payload-in-project.js.map +1 -1
  84. package/dist/lib/update-payload-in-project.spec.js +262 -0
  85. package/dist/lib/update-payload-in-project.spec.js.map +1 -0
  86. package/dist/main.d.ts +20 -1
  87. package/dist/main.d.ts.map +1 -1
  88. package/dist/main.js +120 -29
  89. package/dist/main.js.map +1 -1
  90. package/dist/main.spec.js +102 -0
  91. package/dist/main.spec.js.map +1 -0
  92. package/dist/scripts/pack-template-files.js +18 -0
  93. package/dist/scripts/pack-template-files.js.map +1 -1
  94. package/dist/template/src/app/(frontend)/styles.css +1 -1
  95. package/dist/template/src/app/(payload)/layout.tsx +1 -1
  96. package/dist/template-tanstack/routes/_payload/admin.$.tsx +8 -0
  97. package/dist/template-tanstack/routes/_payload/admin.index.tsx +8 -0
  98. package/dist/template-tanstack/routes/_payload/api.$.ts +10 -0
  99. package/dist/template-tanstack/routes/_payload/importMap.js +32 -0
  100. package/dist/template-tanstack/routes/_payload/server.functions.ts +49 -0
  101. package/dist/template-tanstack/routes/_payload.tsx +30 -0
  102. package/dist/template-tanstack/src/collections/Folders.ts +16 -0
  103. package/dist/template-tanstack/src/collections/Media.ts +20 -0
  104. package/dist/template-tanstack/src/collections/Tags.ts +16 -0
  105. package/dist/template-tanstack/src/collections/Users.ts +14 -0
  106. package/dist/template-tanstack/src/payload.config.ts +40 -0
  107. package/dist/template-tanstack/src/payload.css +1 -0
  108. package/dist/types.d.ts +22 -3
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/types.js.map +1 -1
  111. package/dist/utils/messages.d.ts +1 -0
  112. package/dist/utils/messages.d.ts.map +1 -1
  113. package/dist/utils/messages.js +8 -6
  114. package/dist/utils/messages.js.map +1 -1
  115. package/package.json +4 -4
  116. package/dist/lib/download-skill.d.ts +0 -8
  117. package/dist/lib/download-skill.d.ts.map +0 -1
  118. package/dist/lib/download-skill.js +0 -35
  119. package/dist/lib/download-skill.js.map +0 -1
  120. package/dist/lib/select-agent.d.ts +0 -16
  121. package/dist/lib/select-agent.d.ts.map +0 -1
  122. package/dist/lib/select-agent.js +0 -67
  123. package/dist/lib/select-agent.js.map +0 -1
  124. /package/dist/template/src/app/(payload)/{custom.scss → custom.css} +0 -0
@@ -0,0 +1,131 @@
1
+ import fse from 'fs-extra';
2
+ import globby from 'globby';
3
+ import path from 'path';
4
+ const FILE_EXTENSIONS = 'js|jsx|ts|tsx|cjs|cts|mjs|mts';
5
+ export async function getTanStackAppDetails({ projectDir }) {
6
+ const absoluteProjectDir = path.resolve(projectDir);
7
+ const packageJson = await getPackageJson({
8
+ projectDir: absoluteProjectDir
9
+ });
10
+ const packages = {
11
+ ...packageJson.dependencies,
12
+ ...packageJson.devDependencies
13
+ };
14
+ const isSolidHost = Boolean(packages['@tanstack/solid-router'] || packages['@tanstack/solid-start']);
15
+ const hasReactRouter = Boolean(packages['@tanstack/react-router']);
16
+ const hasReactStart = Boolean(packages['@tanstack/react-start']);
17
+ const hasRouterPlugin = Boolean(packages['@tanstack/router-plugin']);
18
+ if (!isSolidHost && !hasReactRouter && !hasReactStart && !hasRouterPlugin) {
19
+ return {
20
+ detected: false
21
+ };
22
+ }
23
+ if (isSolidHost) {
24
+ return incompatible('TanStack Solid projects are not supported.');
25
+ }
26
+ if (hasReactStart && packages.next) {
27
+ return incompatible('TanStack Start and Next.js markers are both present.');
28
+ }
29
+ if (!hasReactRouter) {
30
+ return incompatible('Could not find @tanstack/react-router.');
31
+ }
32
+ const kind = hasReactStart ? 'start' : 'router-only';
33
+ const viteConfigPaths = await findFiles({
34
+ cwd: absoluteProjectDir,
35
+ pattern: `vite.config.@(${FILE_EXTENSIONS})`
36
+ });
37
+ if (viteConfigPaths.length > 1) {
38
+ return incompatible(getAmbiguousFilesReason({
39
+ filePaths: viteConfigPaths,
40
+ projectDir: absoluteProjectDir,
41
+ role: 'Vite config'
42
+ }));
43
+ }
44
+ const viteConfigPath = viteConfigPaths[0];
45
+ if (!viteConfigPath) {
46
+ return incompatible('Could not find a Vite config file.');
47
+ }
48
+ const viteConfig = await fse.readFile(viteConfigPath, 'utf8');
49
+ const pluginName = kind === 'start' ? 'tanstackStart' : 'tanstackRouter';
50
+ if (!new RegExp(`\\b${pluginName}\\s*\\(`).test(viteConfig)) {
51
+ return incompatible(`Could not find ${pluginName}() in ${viteConfigPath}.`);
52
+ }
53
+ const sourceDir = path.join(absoluteProjectDir, 'src');
54
+ const routesDir = path.join(sourceDir, 'routes');
55
+ const routerPaths = await findFiles({
56
+ cwd: sourceDir,
57
+ pattern: `router.@(${FILE_EXTENSIONS})`
58
+ });
59
+ if (routerPaths.length > 1) {
60
+ return incompatible(getAmbiguousFilesReason({
61
+ filePaths: routerPaths,
62
+ projectDir: absoluteProjectDir,
63
+ role: 'router'
64
+ }));
65
+ }
66
+ const routerPath = routerPaths[0];
67
+ if (!routerPath) {
68
+ return incompatible(`Could not find src/router.* in ${absoluteProjectDir}.`);
69
+ }
70
+ const router = await fse.readFile(routerPath, 'utf8');
71
+ if (!/\bgetRouter\b/.test(router)) {
72
+ return incompatible(`Could not find getRouter in ${routerPath}.`);
73
+ }
74
+ const rootRoutePaths = await findFiles({
75
+ cwd: routesDir,
76
+ pattern: `__root.@(${FILE_EXTENSIONS})`
77
+ });
78
+ if (rootRoutePaths.length > 1) {
79
+ return incompatible(getAmbiguousFilesReason({
80
+ filePaths: rootRoutePaths,
81
+ projectDir: absoluteProjectDir,
82
+ role: 'root route'
83
+ }));
84
+ }
85
+ const rootRoutePath = rootRoutePaths[0];
86
+ if (!rootRoutePath) {
87
+ return incompatible(`Could not find src/routes/__root.* in ${absoluteProjectDir}.`);
88
+ }
89
+ const details = {
90
+ isPayloadInstalled: Boolean(packages.payload),
91
+ kind,
92
+ projectDir: absoluteProjectDir,
93
+ rootRoutePath,
94
+ routerPath,
95
+ routesDir,
96
+ sourceDir,
97
+ viteConfigPath
98
+ };
99
+ return {
100
+ compatible: true,
101
+ details,
102
+ detected: true
103
+ };
104
+ }
105
+ function incompatible(reason) {
106
+ return {
107
+ compatible: false,
108
+ detected: true,
109
+ reason
110
+ };
111
+ }
112
+ function getAmbiguousFilesReason({ filePaths, projectDir, role }) {
113
+ const relativePaths = filePaths.map((filePath)=>path.relative(projectDir, filePath)).sort();
114
+ return `Found multiple supported ${role} files: ${relativePaths.join(', ')}.`;
115
+ }
116
+ async function findFiles({ cwd, pattern }) {
117
+ return globby(pattern, {
118
+ absolute: true,
119
+ cwd,
120
+ onlyFiles: true
121
+ });
122
+ }
123
+ async function getPackageJson({ projectDir }) {
124
+ const packageJsonPath = path.join(projectDir, 'package.json');
125
+ if (!await fse.pathExists(packageJsonPath)) {
126
+ return {};
127
+ }
128
+ return fse.readJson(packageJsonPath);
129
+ }
130
+
131
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/tanstack/detect.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport globby from 'globby'\nimport path from 'path'\n\nimport type { TanStackAppDetails, TanStackAppKind, TanStackDetectionResult } from '../../types.js'\n\ntype PackageJson = {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n}\n\nconst FILE_EXTENSIONS = 'js|jsx|ts|tsx|cjs|cts|mjs|mts'\n\nexport async function getTanStackAppDetails({\n projectDir,\n}: {\n projectDir: string\n}): Promise<TanStackDetectionResult> {\n const absoluteProjectDir = path.resolve(projectDir)\n const packageJson = await getPackageJson({ projectDir: absoluteProjectDir })\n const packages = { ...packageJson.dependencies, ...packageJson.devDependencies }\n const isSolidHost = Boolean(\n packages['@tanstack/solid-router'] || packages['@tanstack/solid-start'],\n )\n const hasReactRouter = Boolean(packages['@tanstack/react-router'])\n const hasReactStart = Boolean(packages['@tanstack/react-start'])\n const hasRouterPlugin = Boolean(packages['@tanstack/router-plugin'])\n\n if (!isSolidHost && !hasReactRouter && !hasReactStart && !hasRouterPlugin) {\n return { detected: false }\n }\n\n if (isSolidHost) {\n return incompatible('TanStack Solid projects are not supported.')\n }\n\n if (hasReactStart && packages.next) {\n return incompatible('TanStack Start and Next.js markers are both present.')\n }\n\n if (!hasReactRouter) {\n return incompatible('Could not find @tanstack/react-router.')\n }\n\n const kind: TanStackAppKind = hasReactStart ? 'start' : 'router-only'\n const viteConfigPaths = await findFiles({\n cwd: absoluteProjectDir,\n pattern: `vite.config.@(${FILE_EXTENSIONS})`,\n })\n if (viteConfigPaths.length > 1) {\n return incompatible(\n getAmbiguousFilesReason({\n filePaths: viteConfigPaths,\n projectDir: absoluteProjectDir,\n role: 'Vite config',\n }),\n )\n }\n\n const viteConfigPath = viteConfigPaths[0]\n if (!viteConfigPath) {\n return incompatible('Could not find a Vite config file.')\n }\n\n const viteConfig = await fse.readFile(viteConfigPath, 'utf8')\n const pluginName = kind === 'start' ? 'tanstackStart' : 'tanstackRouter'\n if (!new RegExp(`\\\\b${pluginName}\\\\s*\\\\(`).test(viteConfig)) {\n return incompatible(`Could not find ${pluginName}() in ${viteConfigPath}.`)\n }\n\n const sourceDir = path.join(absoluteProjectDir, 'src')\n const routesDir = path.join(sourceDir, 'routes')\n const routerPaths = await findFiles({\n cwd: sourceDir,\n pattern: `router.@(${FILE_EXTENSIONS})`,\n })\n if (routerPaths.length > 1) {\n return incompatible(\n getAmbiguousFilesReason({\n filePaths: routerPaths,\n projectDir: absoluteProjectDir,\n role: 'router',\n }),\n )\n }\n\n const routerPath = routerPaths[0]\n if (!routerPath) {\n return incompatible(`Could not find src/router.* in ${absoluteProjectDir}.`)\n }\n\n const router = await fse.readFile(routerPath, 'utf8')\n if (!/\\bgetRouter\\b/.test(router)) {\n return incompatible(`Could not find getRouter in ${routerPath}.`)\n }\n\n const rootRoutePaths = await findFiles({\n cwd: routesDir,\n pattern: `__root.@(${FILE_EXTENSIONS})`,\n })\n if (rootRoutePaths.length > 1) {\n return incompatible(\n getAmbiguousFilesReason({\n filePaths: rootRoutePaths,\n projectDir: absoluteProjectDir,\n role: 'root route',\n }),\n )\n }\n\n const rootRoutePath = rootRoutePaths[0]\n if (!rootRoutePath) {\n return incompatible(`Could not find src/routes/__root.* in ${absoluteProjectDir}.`)\n }\n\n const details: TanStackAppDetails = {\n isPayloadInstalled: Boolean(packages.payload),\n kind,\n projectDir: absoluteProjectDir,\n rootRoutePath,\n routerPath,\n routesDir,\n sourceDir,\n viteConfigPath,\n }\n\n return { compatible: true, details, detected: true }\n}\n\nfunction incompatible(reason: string): TanStackDetectionResult {\n return { compatible: false, detected: true, reason }\n}\n\nfunction getAmbiguousFilesReason({\n filePaths,\n projectDir,\n role,\n}: {\n filePaths: string[]\n projectDir: string\n role: string\n}): string {\n const relativePaths = filePaths.map((filePath) => path.relative(projectDir, filePath)).sort()\n\n return `Found multiple supported ${role} files: ${relativePaths.join(', ')}.`\n}\n\nasync function findFiles({ cwd, pattern }: { cwd: string; pattern: string }): Promise<string[]> {\n return globby(pattern, {\n absolute: true,\n cwd,\n onlyFiles: true,\n })\n}\n\nasync function getPackageJson({ projectDir }: { projectDir: string }): Promise<PackageJson> {\n const packageJsonPath = path.join(projectDir, 'package.json')\n\n if (!(await fse.pathExists(packageJsonPath))) {\n return {}\n }\n\n return fse.readJson(packageJsonPath) as Promise<PackageJson>\n}\n"],"names":["fse","globby","path","FILE_EXTENSIONS","getTanStackAppDetails","projectDir","absoluteProjectDir","resolve","packageJson","getPackageJson","packages","dependencies","devDependencies","isSolidHost","Boolean","hasReactRouter","hasReactStart","hasRouterPlugin","detected","incompatible","next","kind","viteConfigPaths","findFiles","cwd","pattern","length","getAmbiguousFilesReason","filePaths","role","viteConfigPath","viteConfig","readFile","pluginName","RegExp","test","sourceDir","join","routesDir","routerPaths","routerPath","router","rootRoutePaths","rootRoutePath","details","isPayloadInstalled","payload","compatible","reason","relativePaths","map","filePath","relative","sort","absolute","onlyFiles","packageJsonPath","pathExists","readJson"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AASvB,MAAMC,kBAAkB;AAExB,OAAO,eAAeC,sBAAsB,EAC1CC,UAAU,EAGX;IACC,MAAMC,qBAAqBJ,KAAKK,OAAO,CAACF;IACxC,MAAMG,cAAc,MAAMC,eAAe;QAAEJ,YAAYC;IAAmB;IAC1E,MAAMI,WAAW;QAAE,GAAGF,YAAYG,YAAY;QAAE,GAAGH,YAAYI,eAAe;IAAC;IAC/E,MAAMC,cAAcC,QAClBJ,QAAQ,CAAC,yBAAyB,IAAIA,QAAQ,CAAC,wBAAwB;IAEzE,MAAMK,iBAAiBD,QAAQJ,QAAQ,CAAC,yBAAyB;IACjE,MAAMM,gBAAgBF,QAAQJ,QAAQ,CAAC,wBAAwB;IAC/D,MAAMO,kBAAkBH,QAAQJ,QAAQ,CAAC,0BAA0B;IAEnE,IAAI,CAACG,eAAe,CAACE,kBAAkB,CAACC,iBAAiB,CAACC,iBAAiB;QACzE,OAAO;YAAEC,UAAU;QAAM;IAC3B;IAEA,IAAIL,aAAa;QACf,OAAOM,aAAa;IACtB;IAEA,IAAIH,iBAAiBN,SAASU,IAAI,EAAE;QAClC,OAAOD,aAAa;IACtB;IAEA,IAAI,CAACJ,gBAAgB;QACnB,OAAOI,aAAa;IACtB;IAEA,MAAME,OAAwBL,gBAAgB,UAAU;IAC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I0D,QAAQ,CAACF;AACtB"}
@@ -0,0 +1,227 @@
1
+ import fse from 'fs-extra';
2
+ import * as os from 'node:os';
3
+ import path from 'path';
4
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
5
+ import { getTanStackAppDetails } from './detect.js';
6
+ describe('getTanStackAppDetails', ()=>{
7
+ let projectDir;
8
+ beforeEach(()=>{
9
+ projectDir = fse.mkdtempSync(path.join(os.tmpdir(), 'create-payload-app-tanstack-'));
10
+ });
11
+ afterEach(()=>{
12
+ fse.removeSync(projectDir);
13
+ });
14
+ function writeFixture({ additionalFiles, dependencies, devDependencies, hasRootRoute = true, hasRouter = true, router = 'export function getRouter() {}', vite }) {
15
+ fse.writeJsonSync(path.join(projectDir, 'package.json'), {
16
+ dependencies,
17
+ devDependencies,
18
+ name: 'tanstack-fixture'
19
+ });
20
+ fse.ensureDirSync(path.join(projectDir, 'src/routes'));
21
+ if (hasRouter) {
22
+ fse.writeFileSync(path.join(projectDir, 'src/router.tsx'), router);
23
+ }
24
+ if (hasRootRoute) {
25
+ fse.writeFileSync(path.join(projectDir, 'src/routes/__root.tsx'), 'export {}');
26
+ }
27
+ if (vite) {
28
+ fse.writeFileSync(path.join(projectDir, 'vite.config.ts'), vite);
29
+ }
30
+ for (const [relativePath, content] of Object.entries(additionalFiles ?? {})){
31
+ fse.outputFileSync(path.join(projectDir, relativePath), content);
32
+ }
33
+ }
34
+ it('should detect a conventional TanStack Start project', async ()=>{
35
+ writeFixture({
36
+ dependencies: {
37
+ '@tanstack/react-router': 'latest',
38
+ '@tanstack/react-start': 'latest'
39
+ },
40
+ vite: `const config = defineConfig({ plugins: [tanstackStart(), viteReact()] })\nexport default config`
41
+ });
42
+ const result = await getTanStackAppDetails({
43
+ projectDir
44
+ });
45
+ expect(result).toMatchObject({
46
+ compatible: true,
47
+ detected: true,
48
+ details: {
49
+ isPayloadInstalled: false,
50
+ kind: 'start',
51
+ projectDir,
52
+ rootRoutePath: path.join(projectDir, 'src/routes/__root.tsx'),
53
+ routerPath: path.join(projectDir, 'src/router.tsx'),
54
+ routesDir: path.join(projectDir, 'src/routes'),
55
+ sourceDir: path.join(projectDir, 'src'),
56
+ viteConfigPath: path.join(projectDir, 'vite.config.ts')
57
+ }
58
+ });
59
+ });
60
+ it('should detect a conventional Router-only project', async ()=>{
61
+ writeFixture({
62
+ dependencies: {
63
+ '@tanstack/react-router': 'latest',
64
+ payload: 'latest'
65
+ },
66
+ devDependencies: {
67
+ '@tanstack/router-plugin': 'latest'
68
+ },
69
+ vite: `const config = defineConfig({ plugins: [tanstackRouter({ target: 'react' }), viteReact()] })\nexport default config`
70
+ });
71
+ expect(await getTanStackAppDetails({
72
+ projectDir
73
+ })).toMatchObject({
74
+ compatible: true,
75
+ detected: true,
76
+ details: {
77
+ isPayloadInstalled: true,
78
+ kind: 'router-only'
79
+ }
80
+ });
81
+ });
82
+ it('should detect a Router-only project that also depends on Next.js', async ()=>{
83
+ writeFixture({
84
+ dependencies: {
85
+ '@tanstack/react-router': 'latest',
86
+ next: 'latest'
87
+ },
88
+ devDependencies: {
89
+ '@tanstack/router-plugin': 'latest'
90
+ },
91
+ vite: `const config = defineConfig({ plugins: [tanstackRouter({ target: 'react' }), viteReact()] })\nexport default config`
92
+ });
93
+ await expect(getTanStackAppDetails({
94
+ projectDir
95
+ })).resolves.toMatchObject({
96
+ compatible: true,
97
+ detected: true,
98
+ details: {
99
+ kind: 'router-only'
100
+ }
101
+ });
102
+ });
103
+ it('should ignore projects that only use TanStack Query', async ()=>{
104
+ writeFixture({
105
+ dependencies: {
106
+ '@tanstack/react-query': 'latest'
107
+ }
108
+ });
109
+ await expect(getTanStackAppDetails({
110
+ projectDir
111
+ })).resolves.toEqual({
112
+ detected: false
113
+ });
114
+ });
115
+ it('should report a missing root route in a recognized host', async ()=>{
116
+ writeFixture({
117
+ dependencies: {
118
+ '@tanstack/react-router': 'latest'
119
+ },
120
+ devDependencies: {
121
+ '@tanstack/router-plugin': 'latest'
122
+ },
123
+ hasRootRoute: false,
124
+ vite: 'export default defineConfig({ plugins: [tanstackRouter()] })'
125
+ });
126
+ await expect(getTanStackAppDetails({
127
+ projectDir
128
+ })).resolves.toMatchObject({
129
+ compatible: false,
130
+ detected: true,
131
+ reason: expect.stringContaining('src/routes/__root')
132
+ });
133
+ });
134
+ it('should report a router without getRouter in a recognized host', async ()=>{
135
+ writeFixture({
136
+ dependencies: {
137
+ '@tanstack/react-router': 'latest'
138
+ },
139
+ devDependencies: {
140
+ '@tanstack/router-plugin': 'latest'
141
+ },
142
+ router: 'export const router = createRouter({})',
143
+ vite: 'export default defineConfig({ plugins: [tanstackRouter()] })'
144
+ });
145
+ await expect(getTanStackAppDetails({
146
+ projectDir
147
+ })).resolves.toMatchObject({
148
+ compatible: false,
149
+ detected: true,
150
+ reason: expect.stringContaining('getRouter')
151
+ });
152
+ });
153
+ it('should report unsupported Solid hosts', async ()=>{
154
+ writeFixture({
155
+ dependencies: {
156
+ '@tanstack/solid-router': 'latest',
157
+ '@tanstack/solid-start': 'latest'
158
+ },
159
+ vite: 'export default defineConfig({ plugins: [tanstackStart()] })'
160
+ });
161
+ await expect(getTanStackAppDetails({
162
+ projectDir
163
+ })).resolves.toMatchObject({
164
+ compatible: false,
165
+ detected: true,
166
+ reason: expect.stringContaining('Solid')
167
+ });
168
+ });
169
+ it('should report ambiguous TanStack Start and Next.js markers', async ()=>{
170
+ writeFixture({
171
+ dependencies: {
172
+ '@tanstack/react-router': 'latest',
173
+ '@tanstack/react-start': 'latest',
174
+ next: 'latest'
175
+ },
176
+ vite: 'export default defineConfig({ plugins: [tanstackStart()] })'
177
+ });
178
+ await expect(getTanStackAppDetails({
179
+ projectDir
180
+ })).resolves.toMatchObject({
181
+ compatible: false,
182
+ detected: true,
183
+ reason: expect.stringContaining('Next.js')
184
+ });
185
+ });
186
+ it.each([
187
+ {
188
+ additionalFiles: {
189
+ 'vite.config.mts': 'export default defineConfig({ plugins: [tanstackStart(), viteReact()] })'
190
+ },
191
+ reason: 'Found multiple supported Vite config files: vite.config.mts, vite.config.ts.',
192
+ role: 'Vite config'
193
+ },
194
+ {
195
+ additionalFiles: {
196
+ 'src/router.ts': 'export function getRouter() {}'
197
+ },
198
+ reason: 'Found multiple supported router files: src/router.ts, src/router.tsx.',
199
+ role: 'router'
200
+ },
201
+ {
202
+ additionalFiles: {
203
+ 'src/routes/__root.ts': 'export {}'
204
+ },
205
+ reason: 'Found multiple supported root route files: src/routes/__root.ts, src/routes/__root.tsx.',
206
+ role: 'root route'
207
+ }
208
+ ])('should reject multiple supported $role candidates', async ({ additionalFiles, reason })=>{
209
+ writeFixture({
210
+ additionalFiles,
211
+ dependencies: {
212
+ '@tanstack/react-router': 'latest',
213
+ '@tanstack/react-start': 'latest'
214
+ },
215
+ vite: 'export default defineConfig({ plugins: [tanstackStart(), viteReact()] })'
216
+ });
217
+ await expect(getTanStackAppDetails({
218
+ projectDir
219
+ })).resolves.toEqual({
220
+ compatible: false,
221
+ detected: true,
222
+ reason
223
+ });
224
+ });
225
+ });
226
+
227
+ //# sourceMappingURL=detect.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/tanstack/detect.spec.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport * as os from 'node:os'\nimport path from 'path'\nimport { afterEach, beforeEach, describe, expect, it } from 'vitest'\n\nimport { getTanStackAppDetails } from './detect.js'\n\ntype Fixture = {\n additionalFiles?: Record<string, string>\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n hasRootRoute?: boolean\n hasRouter?: boolean\n router?: string\n vite?: string\n}\n\ndescribe('getTanStackAppDetails', () => {\n let projectDir: string\n\n beforeEach(() => {\n projectDir = fse.mkdtempSync(path.join(os.tmpdir(), 'create-payload-app-tanstack-'))\n })\n\n afterEach(() => {\n fse.removeSync(projectDir)\n })\n\n function writeFixture({\n additionalFiles,\n dependencies,\n devDependencies,\n hasRootRoute = true,\n hasRouter = true,\n router = 'export function getRouter() {}',\n vite,\n }: Fixture) {\n fse.writeJsonSync(path.join(projectDir, 'package.json'), {\n dependencies,\n devDependencies,\n name: 'tanstack-fixture',\n })\n fse.ensureDirSync(path.join(projectDir, 'src/routes'))\n\n if (hasRouter) {\n fse.writeFileSync(path.join(projectDir, 'src/router.tsx'), router)\n }\n if (hasRootRoute) {\n fse.writeFileSync(path.join(projectDir, 'src/routes/__root.tsx'), 'export {}')\n }\n if (vite) {\n fse.writeFileSync(path.join(projectDir, 'vite.config.ts'), vite)\n }\n for (const [relativePath, content] of Object.entries(additionalFiles ?? {})) {\n fse.outputFileSync(path.join(projectDir, relativePath), content)\n }\n }\n\n it('should detect a conventional TanStack Start project', async () => {\n writeFixture({\n dependencies: { '@tanstack/react-router': 'latest', '@tanstack/react-start': 'latest' },\n vite: `const config = defineConfig({ plugins: [tanstackStart(), viteReact()] })\\nexport default config`,\n })\n\n const result = await getTanStackAppDetails({ projectDir })\n\n expect(result).toMatchObject({\n compatible: true,\n detected: true,\n details: {\n isPayloadInstalled: false,\n kind: 'start',\n projectDir,\n rootRoutePath: path.join(projectDir, 'src/routes/__root.tsx'),\n routerPath: path.join(projectDir, 'src/router.tsx'),\n routesDir: path.join(projectDir, 'src/routes'),\n sourceDir: path.join(projectDir, 'src'),\n viteConfigPath: path.join(projectDir, 'vite.config.ts'),\n },\n })\n })\n\n it('should detect a conventional Router-only project', async () => {\n writeFixture({\n dependencies: { '@tanstack/react-router': 'latest', payload: 'latest' },\n devDependencies: { '@tanstack/router-plugin': 'latest' },\n vite: `const config = defineConfig({ plugins: [tanstackRouter({ target: 'react' }), viteReact()] })\\nexport default config`,\n })\n\n expect(await getTanStackAppDetails({ projectDir })).toMatchObject({\n compatible: true,\n detected: true,\n details: { isPayloadInstalled: true, kind: 'router-only' },\n })\n })\n\n it('should detect a Router-only project that also depends on Next.js', async () => {\n writeFixture({\n dependencies: {\n '@tanstack/react-router': 'latest',\n next: 'latest',\n },\n devDependencies: { '@tanstack/router-plugin': 'latest' },\n vite: `const config = defineConfig({ plugins: [tanstackRouter({ target: 'react' }), viteReact()] })\\nexport default config`,\n })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toMatchObject({\n compatible: true,\n detected: true,\n details: { kind: 'router-only' },\n })\n })\n\n it('should ignore projects that only use TanStack Query', async () => {\n writeFixture({ dependencies: { '@tanstack/react-query': 'latest' } })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toEqual({ detected: false })\n })\n\n it('should report a missing root route in a recognized host', async () => {\n writeFixture({\n dependencies: { '@tanstack/react-router': 'latest' },\n devDependencies: { '@tanstack/router-plugin': 'latest' },\n hasRootRoute: false,\n vite: 'export default defineConfig({ plugins: [tanstackRouter()] })',\n })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toMatchObject({\n compatible: false,\n detected: true,\n reason: expect.stringContaining('src/routes/__root'),\n })\n })\n\n it('should report a router without getRouter in a recognized host', async () => {\n writeFixture({\n dependencies: { '@tanstack/react-router': 'latest' },\n devDependencies: { '@tanstack/router-plugin': 'latest' },\n router: 'export const router = createRouter({})',\n vite: 'export default defineConfig({ plugins: [tanstackRouter()] })',\n })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toMatchObject({\n compatible: false,\n detected: true,\n reason: expect.stringContaining('getRouter'),\n })\n })\n\n it('should report unsupported Solid hosts', async () => {\n writeFixture({\n dependencies: { '@tanstack/solid-router': 'latest', '@tanstack/solid-start': 'latest' },\n vite: 'export default defineConfig({ plugins: [tanstackStart()] })',\n })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toMatchObject({\n compatible: false,\n detected: true,\n reason: expect.stringContaining('Solid'),\n })\n })\n\n it('should report ambiguous TanStack Start and Next.js markers', async () => {\n writeFixture({\n dependencies: {\n '@tanstack/react-router': 'latest',\n '@tanstack/react-start': 'latest',\n next: 'latest',\n },\n vite: 'export default defineConfig({ plugins: [tanstackStart()] })',\n })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toMatchObject({\n compatible: false,\n detected: true,\n reason: expect.stringContaining('Next.js'),\n })\n })\n\n it.each([\n {\n additionalFiles: {\n 'vite.config.mts':\n 'export default defineConfig({ plugins: [tanstackStart(), viteReact()] })',\n },\n reason: 'Found multiple supported Vite config files: vite.config.mts, vite.config.ts.',\n role: 'Vite config',\n },\n {\n additionalFiles: { 'src/router.ts': 'export function getRouter() {}' },\n reason: 'Found multiple supported router files: src/router.ts, src/router.tsx.',\n role: 'router',\n },\n {\n additionalFiles: { 'src/routes/__root.ts': 'export {}' },\n reason:\n 'Found multiple supported root route files: src/routes/__root.ts, src/routes/__root.tsx.',\n role: 'root route',\n },\n ])('should reject multiple supported $role candidates', async ({ additionalFiles, reason }) => {\n writeFixture({\n additionalFiles,\n dependencies: {\n '@tanstack/react-router': 'latest',\n '@tanstack/react-start': 'latest',\n },\n vite: 'export default defineConfig({ plugins: [tanstackStart(), viteReact()] })',\n })\n\n await expect(getTanStackAppDetails({ projectDir })).resolves.toEqual({\n compatible: false,\n detected: true,\n reason,\n })\n })\n})\n"],"names":["fse","os","path","afterEach","beforeEach","describe","expect","it","getTanStackAppDetails","projectDir","mkdtempSync","join","tmpdir","removeSync","writeFixture","additionalFiles","dependencies","devDependencies","hasRootRoute","hasRouter","router","vite","writeJsonSync","name","ensureDirSync","writeFileSync","relativePath","content","Object","entries","outputFileSync","result","toMatchObject","compatible","detected","details","isPayloadInstalled","kind","rootRoutePath","routerPath","routesDir","sourceDir","viteConfigPath","payload","next","resolves","toEqual","reason","stringContaining","each","role"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,YAAYC,QAAQ,UAAS;AAC7B,OAAOC,UAAU,OAAM;AACvB,SAASC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAEpE,SAASC,qBAAqB,QAAQ,cAAa;AAYnDH,SAAS,yBAAyB;IAChC,IAAII;IAEJL,WAAW;QACTK,aAAaT,IAAIU,WAAW,CAACR,KAAKS,IAAI,CAACV,GAAGW,MAAM,IAAI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
@@ -0,0 +1,23 @@
1
+ import type { TanStackAppDetails } from '../../types.js';
2
+ export type PreparedWrite = {
3
+ /** Exact content to write after every preparation check succeeds. */
4
+ content: string;
5
+ /** Absolute destination path in the detected host project. */
6
+ filePath: string;
7
+ };
8
+ type PrepareResult = {
9
+ reason: string;
10
+ success: false;
11
+ } | {
12
+ success: true;
13
+ writes: PreparedWrite[];
14
+ };
15
+ export declare function prepareTanStackInit({ appDetails, templateRoot, }: {
16
+ appDetails: TanStackAppDetails;
17
+ templateRoot: string;
18
+ }): Promise<PrepareResult>;
19
+ export declare function applyPreparedWrites({ writes }: {
20
+ writes: PreparedWrite[];
21
+ }): Promise<void>;
22
+ export {};
23
+ //# sourceMappingURL=prepare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare.d.ts","sourceRoot":"","sources":["../../../src/lib/tanstack/prepare.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAQxD,MAAM,MAAM,aAAa,GAAG;IAC1B,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAA;IACf,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,aAAa,EAAE,CAAA;CAAE,CAAA;AAOpG,wBAAsB,mBAAmB,CAAC,EACxC,UAAU,EACV,YAAY,GACb,EAAE;IACD,UAAU,EAAE,kBAAkB,CAAA;IAC9B,YAAY,EAAE,MAAM,CAAA;CACrB,GAAG,OAAO,CAAC,aAAa,CAAC,CAoEzB;AAED,wBAAsB,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,aAAa,EAAE,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAKhG"}
@@ -0,0 +1,114 @@
1
+ import fse from 'fs-extra';
2
+ import path from 'node:path';
3
+ import { TANSTACK_TEMPLATE_FILES } from './template-files.js';
4
+ import { transformTanStackRootRoute } from './transform-root-route.js';
5
+ import { transformTanStackRouter } from './transform-router.js';
6
+ import { transformTanStackViteConfig } from './transform-vite-config.js';
7
+ export async function prepareTanStackInit({ appDetails, templateRoot }) {
8
+ try {
9
+ const templateFilesResult = await getTemplateFiles({
10
+ appDetails,
11
+ templateRoot
12
+ });
13
+ if (!templateFilesResult.success) {
14
+ return templateFilesResult;
15
+ }
16
+ const [viteConfigContent, routerContent, rootRouteContent, ...templateContents] = await Promise.all([
17
+ fse.readFile(appDetails.viteConfigPath, 'utf8'),
18
+ fse.readFile(appDetails.routerPath, 'utf8'),
19
+ fse.readFile(appDetails.rootRoutePath, 'utf8'),
20
+ ...templateFilesResult.files.map(({ templatePath })=>fse.readFile(templatePath, 'utf8'))
21
+ ]);
22
+ const transformedFiles = [
23
+ {
24
+ filePath: appDetails.viteConfigPath,
25
+ result: transformTanStackViteConfig({
26
+ appDetails,
27
+ content: viteConfigContent
28
+ })
29
+ },
30
+ {
31
+ filePath: appDetails.routerPath,
32
+ result: transformTanStackRouter({
33
+ content: routerContent
34
+ })
35
+ },
36
+ {
37
+ filePath: appDetails.rootRoutePath,
38
+ result: transformTanStackRootRoute({
39
+ content: rootRouteContent,
40
+ kind: appDetails.kind
41
+ })
42
+ }
43
+ ];
44
+ const failedTransform = transformedFiles.find(({ result })=>!result.success);
45
+ if (failedTransform && !failedTransform.result.success) {
46
+ return {
47
+ reason: `Could not transform ${failedTransform.filePath}: ${failedTransform.result.reason}`,
48
+ success: false
49
+ };
50
+ }
51
+ const writes = transformedFiles.flatMap(({ filePath, result })=>result.success && result.modified ? [
52
+ {
53
+ content: result.content,
54
+ filePath
55
+ }
56
+ ] : []);
57
+ for (const [index, templateFile] of templateFilesResult.files.entries()){
58
+ const content = templateContents[index];
59
+ const { filePath } = templateFile;
60
+ if (await fse.pathExists(filePath)) {
61
+ const existingContent = await fse.readFile(filePath, 'utf8');
62
+ if (existingContent !== content) {
63
+ return {
64
+ reason: `A different file already exists at ${filePath}.`,
65
+ success: false
66
+ };
67
+ }
68
+ continue;
69
+ }
70
+ writes.push({
71
+ content,
72
+ filePath
73
+ });
74
+ }
75
+ return {
76
+ success: true,
77
+ writes
78
+ };
79
+ } catch (error) {
80
+ return {
81
+ reason: error instanceof Error ? error.message : 'Could not prepare TanStack files.',
82
+ success: false
83
+ };
84
+ }
85
+ }
86
+ export async function applyPreparedWrites({ writes }) {
87
+ for (const { content, filePath } of writes){
88
+ await fse.ensureDir(path.dirname(filePath));
89
+ await fse.writeFile(filePath, content);
90
+ }
91
+ }
92
+ async function getTemplateFiles({ appDetails, templateRoot }) {
93
+ const files = [];
94
+ const hasPackedTemplateLayout = await fse.pathExists(path.join(templateRoot, 'routes'));
95
+ for (const { destination, relativePath, sourcePath } of TANSTACK_TEMPLATE_FILES){
96
+ const templatePath = hasPackedTemplateLayout ? path.join(templateRoot, destination, relativePath) : path.join(templateRoot, sourcePath);
97
+ if (!await fse.pathExists(templatePath)) {
98
+ return {
99
+ reason: `Required TanStack template file is missing: ${templatePath}.`,
100
+ success: false
101
+ };
102
+ }
103
+ files.push({
104
+ filePath: path.join(destination === 'src' ? appDetails.sourceDir : appDetails.routesDir, relativePath),
105
+ templatePath
106
+ });
107
+ }
108
+ return {
109
+ files,
110
+ success: true
111
+ };
112
+ }
113
+
114
+ //# sourceMappingURL=prepare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/tanstack/prepare.ts"],"sourcesContent":["import fse from 'fs-extra'\nimport path from 'node:path'\n\nimport type { TanStackAppDetails } from '../../types.js'\nimport type { TextTransformResult } from './transform-vite-config.js'\n\nimport { TANSTACK_TEMPLATE_FILES } from './template-files.js'\nimport { transformTanStackRootRoute } from './transform-root-route.js'\nimport { transformTanStackRouter } from './transform-router.js'\nimport { transformTanStackViteConfig } from './transform-vite-config.js'\n\nexport type PreparedWrite = {\n /** Exact content to write after every preparation check succeeds. */\n content: string\n /** Absolute destination path in the detected host project. */\n filePath: string\n}\n\ntype PrepareResult = { reason: string; success: false } | { success: true; writes: PreparedWrite[] }\n\ntype TemplateFile = {\n filePath: string\n templatePath: string\n}\n\nexport async function prepareTanStackInit({\n appDetails,\n templateRoot,\n}: {\n appDetails: TanStackAppDetails\n templateRoot: string\n}): Promise<PrepareResult> {\n try {\n const templateFilesResult = await getTemplateFiles({ appDetails, templateRoot })\n if (!templateFilesResult.success) {\n return templateFilesResult\n }\n\n const [viteConfigContent, routerContent, rootRouteContent, ...templateContents] =\n await Promise.all([\n fse.readFile(appDetails.viteConfigPath, 'utf8'),\n fse.readFile(appDetails.routerPath, 'utf8'),\n fse.readFile(appDetails.rootRoutePath, 'utf8'),\n ...templateFilesResult.files.map(({ templatePath }) => fse.readFile(templatePath, 'utf8')),\n ])\n\n const transformedFiles: Array<{\n filePath: string\n result: TextTransformResult\n }> = [\n {\n filePath: appDetails.viteConfigPath,\n result: transformTanStackViteConfig({ appDetails, content: viteConfigContent }),\n },\n {\n filePath: appDetails.routerPath,\n result: transformTanStackRouter({ content: routerContent }),\n },\n {\n filePath: appDetails.rootRoutePath,\n result: transformTanStackRootRoute({ content: rootRouteContent, kind: appDetails.kind }),\n },\n ]\n\n const failedTransform = transformedFiles.find(({ result }) => !result.success)\n if (failedTransform && !failedTransform.result.success) {\n return {\n reason: `Could not transform ${failedTransform.filePath}: ${failedTransform.result.reason}`,\n success: false,\n }\n }\n\n const writes: PreparedWrite[] = transformedFiles.flatMap(({ filePath, result }) =>\n result.success && result.modified ? [{ content: result.content, filePath }] : [],\n )\n\n for (const [index, templateFile] of templateFilesResult.files.entries()) {\n const content = templateContents[index]!\n const { filePath } = templateFile\n\n if (await fse.pathExists(filePath)) {\n const existingContent = await fse.readFile(filePath, 'utf8')\n if (existingContent !== content) {\n return { reason: `A different file already exists at ${filePath}.`, success: false }\n }\n\n continue\n }\n\n writes.push({ content, filePath })\n }\n\n return { success: true, writes }\n } catch (error) {\n return {\n reason: error instanceof Error ? error.message : 'Could not prepare TanStack files.',\n success: false,\n }\n }\n}\n\nexport async function applyPreparedWrites({ writes }: { writes: PreparedWrite[] }): Promise<void> {\n for (const { content, filePath } of writes) {\n await fse.ensureDir(path.dirname(filePath))\n await fse.writeFile(filePath, content)\n }\n}\n\nasync function getTemplateFiles({\n appDetails,\n templateRoot,\n}: {\n appDetails: TanStackAppDetails\n templateRoot: string\n}): Promise<{ files: TemplateFile[]; success: true } | { reason: string; success: false }> {\n const files: TemplateFile[] = []\n const hasPackedTemplateLayout = await fse.pathExists(path.join(templateRoot, 'routes'))\n\n for (const { destination, relativePath, sourcePath } of TANSTACK_TEMPLATE_FILES) {\n const templatePath = hasPackedTemplateLayout\n ? path.join(templateRoot, destination, relativePath)\n : path.join(templateRoot, sourcePath)\n if (!(await fse.pathExists(templatePath))) {\n return {\n reason: `Required TanStack template file is missing: ${templatePath}.`,\n success: false,\n }\n }\n\n files.push({\n filePath: path.join(\n destination === 'src' ? appDetails.sourceDir : appDetails.routesDir,\n relativePath,\n ),\n templatePath,\n })\n }\n\n return { files, success: true }\n}\n"],"names":["fse","path","TANSTACK_TEMPLATE_FILES","transformTanStackRootRoute","transformTanStackRouter","transformTanStackViteConfig","prepareTanStackInit","appDetails","templateRoot","templateFilesResult","getTemplateFiles","success","viteConfigContent","routerContent","rootRouteContent","templateContents","Promise","all","readFile","viteConfigPath","routerPath","rootRoutePath","files","map","templatePath","transformedFiles","filePath","result","content","kind","failedTransform","find","reason","writes","flatMap","modified","index","templateFile","entries","pathExists","existingContent","push","error","Error","message","applyPreparedWrites","ensureDir","dirname","writeFile","hasPackedTemplateLayout","join","destination","relativePath","sourcePath","sourceDir","routesDir"],"mappings":"AAAA,OAAOA,SAAS,WAAU;AAC1B,OAAOC,UAAU,YAAW;AAK5B,SAASC,uBAAuB,QAAQ,sBAAqB;AAC7D,SAASC,0BAA0B,QAAQ,4BA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