create-payload-app 4.0.0-internal.cd69eef → 4.0.0-internal.ce66a41

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 (132) 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 +12 -0
  7. package/dist/lib/agent-config.d.ts.map +1 -0
  8. package/dist/lib/agent-config.js +15 -0
  9. package/dist/lib/agent-config.js.map +1 -0
  10. package/dist/lib/ast/adapter-config.d.ts.map +1 -1
  11. package/dist/lib/ast/adapter-config.js +0 -10
  12. package/dist/lib/ast/adapter-config.js.map +1 -1
  13. package/dist/lib/ast/package-json.d.ts +9 -0
  14. package/dist/lib/ast/package-json.d.ts.map +1 -1
  15. package/dist/lib/ast/package-json.js +34 -8
  16. package/dist/lib/ast/package-json.js.map +1 -1
  17. package/dist/lib/ast/types.d.ts +1 -1
  18. package/dist/lib/ast/types.d.ts.map +1 -1
  19. package/dist/lib/ast/types.js +0 -1
  20. package/dist/lib/ast/types.js.map +1 -1
  21. package/dist/lib/configure-payload-tsconfig.d.ts +5 -0
  22. package/dist/lib/configure-payload-tsconfig.d.ts.map +1 -0
  23. package/dist/lib/configure-payload-tsconfig.js +26 -0
  24. package/dist/lib/configure-payload-tsconfig.js.map +1 -0
  25. package/dist/lib/create-project.d.ts +1 -2
  26. package/dist/lib/create-project.d.ts.map +1 -1
  27. package/dist/lib/create-project.js +56 -29
  28. package/dist/lib/create-project.js.map +1 -1
  29. package/dist/lib/generate-secret.js +1 -1
  30. package/dist/lib/generate-secret.js.map +1 -1
  31. package/dist/lib/get-package-manager.d.ts +9 -0
  32. package/dist/lib/get-package-manager.d.ts.map +1 -1
  33. package/dist/lib/get-package-manager.js +20 -0
  34. package/dist/lib/get-package-manager.js.map +1 -1
  35. package/dist/lib/init-next.d.ts.map +1 -1
  36. package/dist/lib/init-next.js +5 -34
  37. package/dist/lib/init-next.js.map +1 -1
  38. package/dist/lib/init-tanstack.d.ts +18 -0
  39. package/dist/lib/init-tanstack.d.ts.map +1 -0
  40. package/dist/lib/init-tanstack.js +149 -0
  41. package/dist/lib/init-tanstack.js.map +1 -0
  42. package/dist/lib/tanstack/detect.d.ts +5 -0
  43. package/dist/lib/tanstack/detect.d.ts.map +1 -0
  44. package/dist/lib/tanstack/detect.js +131 -0
  45. package/dist/lib/tanstack/detect.js.map +1 -0
  46. package/dist/lib/tanstack/prepare.d.ts +23 -0
  47. package/dist/lib/tanstack/prepare.d.ts.map +1 -0
  48. package/dist/lib/tanstack/prepare.js +114 -0
  49. package/dist/lib/tanstack/prepare.js.map +1 -0
  50. package/dist/lib/tanstack/template-files.d.ts +50 -0
  51. package/dist/lib/tanstack/template-files.d.ts.map +1 -0
  52. package/dist/lib/tanstack/template-files.js +64 -0
  53. package/dist/lib/tanstack/template-files.js.map +1 -0
  54. package/dist/lib/tanstack/transform-root-route.d.ts +7 -0
  55. package/dist/lib/tanstack/transform-root-route.d.ts.map +1 -0
  56. package/dist/lib/tanstack/transform-root-route.js +747 -0
  57. package/dist/lib/tanstack/transform-root-route.js.map +1 -0
  58. package/dist/lib/tanstack/transform-router.d.ts +5 -0
  59. package/dist/lib/tanstack/transform-router.d.ts.map +1 -0
  60. package/dist/lib/tanstack/transform-router.js +301 -0
  61. package/dist/lib/tanstack/transform-router.js.map +1 -0
  62. package/dist/lib/tanstack/transform-vite-config.d.ts +14 -0
  63. package/dist/lib/tanstack/transform-vite-config.d.ts.map +1 -0
  64. package/dist/lib/tanstack/transform-vite-config.js +576 -0
  65. package/dist/lib/tanstack/transform-vite-config.js.map +1 -0
  66. package/dist/lib/templates.d.ts.map +1 -1
  67. package/dist/lib/templates.js +6 -0
  68. package/dist/lib/templates.js.map +1 -1
  69. package/dist/lib/update-payload-in-project.d.ts +18 -3
  70. package/dist/lib/update-payload-in-project.d.ts.map +1 -1
  71. package/dist/lib/update-payload-in-project.js +98 -18
  72. package/dist/lib/update-payload-in-project.js.map +1 -1
  73. package/dist/main.d.ts +20 -1
  74. package/dist/main.d.ts.map +1 -1
  75. package/dist/main.js +120 -30
  76. package/dist/main.js.map +1 -1
  77. package/dist/scripts/pack-template-files.js +18 -0
  78. package/dist/scripts/pack-template-files.js.map +1 -1
  79. package/dist/template/src/app/(frontend)/styles.css +8 -1
  80. package/dist/template/src/app/(payload)/admin/[[...segments]]/not-found.tsx +1 -2
  81. package/dist/template/src/app/(payload)/admin/[[...segments]]/page.tsx +1 -2
  82. package/dist/template/src/app/(payload)/admin/importMap.js +15 -0
  83. package/dist/template/src/app/(payload)/api/[...slug]/route.ts +1 -2
  84. package/dist/template/src/app/(payload)/api/graphql/route.ts +1 -2
  85. package/dist/template/src/app/(payload)/api/graphql-playground/route.ts +1 -2
  86. package/dist/template/src/app/(payload)/layout.tsx +2 -3
  87. package/dist/template/src/payload.config.ts +4 -2
  88. package/dist/template-tanstack/routes/_payload/admin.$.tsx +9 -0
  89. package/dist/template-tanstack/routes/_payload/admin.index.tsx +9 -0
  90. package/dist/template-tanstack/routes/_payload/api.$.ts +11 -0
  91. package/dist/template-tanstack/routes/_payload/importMap.js +32 -0
  92. package/dist/template-tanstack/routes/_payload/server.functions.ts +50 -0
  93. package/dist/template-tanstack/routes/_payload.tsx +31 -0
  94. package/dist/template-tanstack/src/collections/Folders.ts +16 -0
  95. package/dist/template-tanstack/src/collections/Media.ts +20 -0
  96. package/dist/template-tanstack/src/collections/Tags.ts +16 -0
  97. package/dist/template-tanstack/src/collections/Users.ts +14 -0
  98. package/dist/template-tanstack/src/payload.config.ts +38 -0
  99. package/dist/template-tanstack/src/payload.css +1 -0
  100. package/dist/types.d.ts +22 -3
  101. package/dist/types.d.ts.map +1 -1
  102. package/dist/types.js.map +1 -1
  103. package/dist/utils/messages.d.ts +1 -0
  104. package/dist/utils/messages.d.ts.map +1 -1
  105. package/dist/utils/messages.js +8 -6
  106. package/dist/utils/messages.js.map +1 -1
  107. package/package.json +6 -6
  108. package/dist/ast-integration.spec.js +0 -132
  109. package/dist/ast-integration.spec.js.map +0 -1
  110. package/dist/lib/ast/package-json.spec.js +0 -67
  111. package/dist/lib/ast/package-json.spec.js.map +0 -1
  112. package/dist/lib/ast/payload-config.spec.js +0 -365
  113. package/dist/lib/ast/payload-config.spec.js.map +0 -1
  114. package/dist/lib/ast/utils.spec.js +0 -226
  115. package/dist/lib/ast/utils.spec.js.map +0 -1
  116. package/dist/lib/create-project.spec.js +0 -190
  117. package/dist/lib/create-project.spec.js.map +0 -1
  118. package/dist/lib/download-skill.d.ts +0 -8
  119. package/dist/lib/download-skill.d.ts.map +0 -1
  120. package/dist/lib/download-skill.js +0 -35
  121. package/dist/lib/download-skill.js.map +0 -1
  122. package/dist/lib/manage-env-files.spec.js +0 -118
  123. package/dist/lib/manage-env-files.spec.js.map +0 -1
  124. package/dist/lib/select-agent.d.ts +0 -16
  125. package/dist/lib/select-agent.d.ts.map +0 -1
  126. package/dist/lib/select-agent.js +0 -67
  127. package/dist/lib/select-agent.js.map +0 -1
  128. package/dist/lib/wrap-next-config.spec.js +0 -167
  129. package/dist/lib/wrap-next-config.spec.js.map +0 -1
  130. package/dist/utils/resolvePackageVersion.spec.js +0 -77
  131. package/dist/utils/resolvePackageVersion.spec.js.map +0 -1
  132. /package/dist/template/src/app/(payload)/{custom.scss → custom.css} +0 -0
@@ -0,0 +1,576 @@
1
+ import { Node, Project, QuoteKind, SyntaxKind } from 'ts-morph';
2
+ const PAYLOAD_CONFIG_PATH = "path.resolve(__dirname, 'src', 'payload.config.ts')";
3
+ export function transformTanStackViteConfig({ appDetails, content }) {
4
+ const project = new Project({
5
+ manipulationSettings: {
6
+ quoteKind: QuoteKind.Single
7
+ },
8
+ useInMemoryFileSystem: true
9
+ });
10
+ const sourceFile = project.createSourceFile('vite.config.ts', content);
11
+ const defineConfigCalls = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).filter((call)=>call.getExpression().getText() === 'defineConfig');
12
+ if (defineConfigCalls.length !== 1) {
13
+ return failure('Expected exactly one defineConfig() call.');
14
+ }
15
+ const defineConfigCall = defineConfigCalls[0];
16
+ if (defineConfigCall.getArguments().length !== 1) {
17
+ return failure('defineConfig() must receive exactly one argument.');
18
+ }
19
+ const configArgument = defineConfigCall.getArguments()[0];
20
+ if (Node.isCallExpression(configArgument) && configArgument.getExpression().getText() === 'withPayload') {
21
+ if (isCompatiblePayloadConfig({
22
+ sourceFile,
23
+ withPayloadCall: configArgument
24
+ })) {
25
+ return {
26
+ content,
27
+ modified: false,
28
+ success: true
29
+ };
30
+ }
31
+ return failure('The existing withPayload() call does not match the supported configuration.');
32
+ }
33
+ if (!Node.isObjectLiteralExpression(configArgument)) {
34
+ return failure('defineConfig() must receive an object literal.');
35
+ }
36
+ if (configArgument.getProperties().some(Node.isSpreadAssignment)) {
37
+ return failure('Config object spreads cannot be transformed safely.');
38
+ }
39
+ const pluginsProperties = configArgument.getProperties().filter(Node.isPropertyAssignment).filter((property)=>property.getName() === 'plugins');
40
+ const pluginsProperty = pluginsProperties[0];
41
+ if (pluginsProperties.length !== 1 || !pluginsProperty) {
42
+ return failure('The Vite config must contain a plugins array.');
43
+ }
44
+ const pluginsArray = pluginsProperty.getInitializer();
45
+ if (!Node.isArrayLiteralExpression(pluginsArray)) {
46
+ return failure('The Vite config must contain a plugins array.');
47
+ }
48
+ if (pluginsArray.getElements().some(Node.isSpreadElement)) {
49
+ return failure('Plugin array spreads cannot be transformed safely.');
50
+ }
51
+ const frameworkImport = getFrameworkImport({
52
+ appDetails,
53
+ sourceFile
54
+ });
55
+ if (!frameworkImport) {
56
+ return failure('Could not identify the TanStack framework plugin import.');
57
+ }
58
+ const reactPluginName = getDefaultImportLocalName({
59
+ moduleSpecifier: '@vitejs/plugin-react',
60
+ sourceFile
61
+ });
62
+ if (!reactPluginName) {
63
+ return failure('Could not identify the React plugin import.');
64
+ }
65
+ const pluginCalls = pluginsArray.getElements().map((element)=>Node.isCallExpression(element) ? {
66
+ name: element.getExpression().getText(),
67
+ element
68
+ } : {
69
+ name: undefined,
70
+ element
71
+ });
72
+ const frameworkCalls = pluginCalls.filter(({ name })=>name === frameworkImport.localName);
73
+ const reactCalls = pluginCalls.filter(({ name })=>name === reactPluginName);
74
+ if (frameworkCalls.length !== 1) {
75
+ return failure('Expected exactly one TanStack framework plugin call.');
76
+ }
77
+ if (reactCalls.length !== 1) {
78
+ return failure('Expected exactly one React plugin call.');
79
+ }
80
+ const frameworkIndex = pluginCalls.indexOf(frameworkCalls[0]);
81
+ const reactIndex = pluginCalls.indexOf(reactCalls[0]);
82
+ if (reactIndex !== frameworkIndex + 1) {
83
+ return failure('Framework and React plugin calls must be adjacent and ordered.');
84
+ }
85
+ const frameworkCall = frameworkCalls[0].element;
86
+ const reactCall = reactCalls[0].element;
87
+ if (!Node.isCallExpression(frameworkCall) || !Node.isCallExpression(reactCall) || frameworkCall.getArguments().length > 1 || reactCall.getArguments().length > 1) {
88
+ return failure('Framework and React plugin calls must receive at most one argument.');
89
+ }
90
+ const destinationValidation = validateDestinationBindings({
91
+ sourceFile
92
+ });
93
+ if (!destinationValidation.success) {
94
+ return destinationValidation;
95
+ }
96
+ replacePluginCalls({
97
+ frameworkCall,
98
+ frameworkIndex,
99
+ pluginsArray,
100
+ preserveFrameworkOptions: appDetails.kind === 'start',
101
+ reactCall,
102
+ reactIndex,
103
+ reactPluginName
104
+ });
105
+ const transformedConfig = configArgument.getText();
106
+ defineConfigCall.replaceWithText(`defineConfig(
107
+ withPayload(
108
+ ({ pluginOptions }) => (${transformedConfig}),
109
+ {
110
+ payloadConfigPath: ${PAYLOAD_CONFIG_PATH},
111
+ routesDirectory: 'routes',
112
+ },
113
+ ),
114
+ )`);
115
+ if (appDetails.kind === 'router-only') {
116
+ removeNamedImport({
117
+ declaration: frameworkImport.declaration,
118
+ importedName: 'tanstackRouter'
119
+ });
120
+ }
121
+ ensureNamedImport({
122
+ importedName: 'withPayload',
123
+ moduleSpecifier: '@payloadcms/tanstack-start',
124
+ sourceFile
125
+ });
126
+ ensureNamedImport({
127
+ importedName: 'tanstackStart',
128
+ moduleSpecifier: '@tanstack/react-start/plugin/vite',
129
+ sourceFile
130
+ });
131
+ ensureDefaultImport({
132
+ defaultImport: 'rsc',
133
+ moduleSpecifier: '@vitejs/plugin-rsc',
134
+ sourceFile
135
+ });
136
+ ensurePathImport(sourceFile);
137
+ if (destinationValidation.shouldAddDirname) {
138
+ ensureNamedImport({
139
+ importedName: 'fileURLToPath',
140
+ moduleSpecifier: 'node:url',
141
+ sourceFile
142
+ });
143
+ sourceFile.insertStatements(sourceFile.getImportDeclarations().length, `const __dirname = path.dirname(fileURLToPath(import.meta.url))`);
144
+ }
145
+ sourceFile.formatText({
146
+ indentSize: 2
147
+ });
148
+ return {
149
+ content: sourceFile.getFullText(),
150
+ modified: true,
151
+ success: true
152
+ };
153
+ }
154
+ function ensureDefaultImport({ defaultImport, moduleSpecifier, sourceFile }) {
155
+ const matchingImport = sourceFile.getImportDeclarations().find((declaration)=>declaration.getModuleSpecifierValue() === moduleSpecifier && declaration.getDefaultImport()?.getText() === defaultImport);
156
+ if (!matchingImport) {
157
+ sourceFile.addImportDeclaration({
158
+ defaultImport,
159
+ moduleSpecifier
160
+ });
161
+ }
162
+ }
163
+ function ensureNamedImport({ importedName, moduleSpecifier, sourceFile }) {
164
+ const imports = sourceFile.getImportDeclarations().filter((declaration)=>declaration.getModuleSpecifierValue() === moduleSpecifier);
165
+ const hasImport = imports.some((declaration)=>declaration.getNamedImports().some((namedImport)=>namedImport.getName() === importedName && !namedImport.getAliasNode()));
166
+ if (hasImport) {
167
+ return;
168
+ }
169
+ const extensibleImport = imports.find((declaration)=>!declaration.getNamespaceImport());
170
+ if (extensibleImport) {
171
+ extensibleImport.addNamedImport(importedName);
172
+ } else {
173
+ sourceFile.addImportDeclaration({
174
+ moduleSpecifier,
175
+ namedImports: [
176
+ importedName
177
+ ]
178
+ });
179
+ }
180
+ }
181
+ function ensurePathImport(sourceFile) {
182
+ const hasCompatibleImport = sourceFile.getImportDeclarations().some((declaration)=>{
183
+ if (declaration.getModuleSpecifierValue() !== 'node:path') {
184
+ return false;
185
+ }
186
+ return declaration.getDefaultImport()?.getText() === 'path' || declaration.getNamespaceImport()?.getText() === 'path';
187
+ });
188
+ if (!hasCompatibleImport) {
189
+ sourceFile.addImportDeclaration({
190
+ defaultImport: 'path',
191
+ moduleSpecifier: 'node:path'
192
+ });
193
+ }
194
+ }
195
+ function failure(reason) {
196
+ return {
197
+ reason,
198
+ success: false
199
+ };
200
+ }
201
+ function getLocalBindings({ localName, sourceFile }) {
202
+ const bindings = [];
203
+ for (const declaration of sourceFile.getImportDeclarations()){
204
+ const moduleSpecifier = declaration.getModuleSpecifierValue();
205
+ const defaultImport = declaration.getDefaultImport();
206
+ if (defaultImport?.getText() === localName) {
207
+ bindings.push({
208
+ declaration,
209
+ importKind: 'default',
210
+ isTypeOnly: declaration.isTypeOnly(),
211
+ kind: 'import',
212
+ moduleSpecifier
213
+ });
214
+ }
215
+ const namespaceImport = declaration.getNamespaceImport();
216
+ if (namespaceImport?.getText() === localName) {
217
+ bindings.push({
218
+ declaration,
219
+ importKind: 'namespace',
220
+ isTypeOnly: declaration.isTypeOnly(),
221
+ kind: 'import',
222
+ moduleSpecifier
223
+ });
224
+ }
225
+ for (const namedImport of declaration.getNamedImports()){
226
+ const namedImportLocalName = namedImport.getAliasNode()?.getText() ?? namedImport.getName();
227
+ if (namedImportLocalName === localName) {
228
+ bindings.push({
229
+ declaration,
230
+ importedName: namedImport.getName(),
231
+ importKind: 'named',
232
+ isTypeOnly: declaration.isTypeOnly() || namedImport.isTypeOnly(),
233
+ kind: 'import',
234
+ moduleSpecifier
235
+ });
236
+ }
237
+ }
238
+ }
239
+ for (const declaration of sourceFile.getVariableDeclarations()){
240
+ if (bindingNameIncludes({
241
+ localName,
242
+ node: declaration.getNameNode()
243
+ })) {
244
+ bindings.push({
245
+ kind: 'variable'
246
+ });
247
+ }
248
+ }
249
+ const hasOtherDeclaration = [
250
+ ...sourceFile.getClasses(),
251
+ ...sourceFile.getEnums(),
252
+ ...sourceFile.getFunctions(),
253
+ ...sourceFile.getModules()
254
+ ].some((declaration)=>declaration.getName() === localName);
255
+ if (hasOtherDeclaration) {
256
+ bindings.push({
257
+ kind: 'other'
258
+ });
259
+ }
260
+ return bindings;
261
+ }
262
+ function bindingNameIncludes({ localName, node }) {
263
+ if (Node.isIdentifier(node)) {
264
+ return node.getText() === localName;
265
+ }
266
+ if (Node.isArrayBindingPattern(node) || Node.isObjectBindingPattern(node)) {
267
+ return node.getElements().some((element)=>Node.isBindingElement(element) && bindingNameIncludes({
268
+ localName,
269
+ node: element.getNameNode()
270
+ }));
271
+ }
272
+ return false;
273
+ }
274
+ function getNamedPluginCalls({ elements, localName }) {
275
+ return elements.filter((element)=>Node.isCallExpression(element) && element.getExpression().getText() === localName);
276
+ }
277
+ function hasCompatibleDirnameBinding(sourceFile) {
278
+ const bindings = getLocalBindings({
279
+ localName: '__dirname',
280
+ sourceFile
281
+ });
282
+ return bindings.length === 1 && bindings[0]?.kind === 'variable';
283
+ }
284
+ function hasOnlyCompatibleBinding({ localName, predicate, sourceFile }) {
285
+ const bindings = getLocalBindings({
286
+ localName,
287
+ sourceFile
288
+ });
289
+ return bindings.length === 1 && predicate(bindings[0]);
290
+ }
291
+ function isCompatiblePathBinding(binding) {
292
+ return binding.kind === 'import' && !binding.isTypeOnly && binding.moduleSpecifier === 'node:path' && (binding.importKind === 'default' || binding.importKind === 'namespace');
293
+ }
294
+ function isExactPluginCall({ call, expectedArgument }) {
295
+ return call.getArguments().length === 1 && call.getArguments()[0]?.getText() === expectedArgument;
296
+ }
297
+ function isMergedPluginCall({ call, expectedArgument }) {
298
+ if (isExactPluginCall({
299
+ call,
300
+ expectedArgument
301
+ })) {
302
+ return true;
303
+ }
304
+ const argument = call.getArguments()[0];
305
+ if (call.getArguments().length !== 1 || !Node.isObjectLiteralExpression(argument)) {
306
+ return false;
307
+ }
308
+ const firstProperty = argument.getProperties()[0];
309
+ return Node.isSpreadAssignment(firstProperty) && firstProperty.getExpression().getText() === expectedArgument;
310
+ }
311
+ function isImportBinding({ binding, importedName, importKind, moduleSpecifier }) {
312
+ return binding.kind === 'import' && !binding.isTypeOnly && binding.importKind === importKind && binding.moduleSpecifier === moduleSpecifier && (importedName === undefined || binding.importedName === importedName);
313
+ }
314
+ function validateDestinationBindings({ sourceFile }) {
315
+ const destinations = [
316
+ {
317
+ localName: 'withPayload',
318
+ predicate: (binding)=>isImportBinding({
319
+ binding,
320
+ importedName: 'withPayload',
321
+ importKind: 'named',
322
+ moduleSpecifier: '@payloadcms/tanstack-start'
323
+ })
324
+ },
325
+ {
326
+ localName: 'tanstackStart',
327
+ predicate: (binding)=>isImportBinding({
328
+ binding,
329
+ importedName: 'tanstackStart',
330
+ importKind: 'named',
331
+ moduleSpecifier: '@tanstack/react-start/plugin/vite'
332
+ })
333
+ },
334
+ {
335
+ localName: 'rsc',
336
+ predicate: (binding)=>isImportBinding({
337
+ binding,
338
+ importKind: 'default',
339
+ moduleSpecifier: '@vitejs/plugin-rsc'
340
+ })
341
+ },
342
+ {
343
+ localName: 'path',
344
+ predicate: isCompatiblePathBinding
345
+ }
346
+ ];
347
+ for (const destination of destinations){
348
+ const bindings = getLocalBindings({
349
+ localName: destination.localName,
350
+ sourceFile
351
+ });
352
+ if (bindings.length > 0 && (bindings.length !== 1 || !destination.predicate(bindings[0]))) {
353
+ return {
354
+ reason: `Identifier "${destination.localName}" is already bound incompatibly.`,
355
+ success: false
356
+ };
357
+ }
358
+ }
359
+ const dirnameBindings = getLocalBindings({
360
+ localName: '__dirname',
361
+ sourceFile
362
+ });
363
+ if (dirnameBindings.length > 0 && (dirnameBindings.length !== 1 || dirnameBindings[0]?.kind !== 'variable')) {
364
+ return {
365
+ reason: 'Identifier "__dirname" is already bound incompatibly.',
366
+ success: false
367
+ };
368
+ }
369
+ const shouldAddDirname = dirnameBindings.length === 0;
370
+ if (shouldAddDirname) {
371
+ const fileURLToPathBindings = getLocalBindings({
372
+ localName: 'fileURLToPath',
373
+ sourceFile
374
+ });
375
+ if (fileURLToPathBindings.length > 0 && (fileURLToPathBindings.length !== 1 || !isImportBinding({
376
+ binding: fileURLToPathBindings[0],
377
+ importedName: 'fileURLToPath',
378
+ importKind: 'named',
379
+ moduleSpecifier: 'node:url'
380
+ }))) {
381
+ return {
382
+ reason: 'Identifier "fileURLToPath" is already bound incompatibly.',
383
+ success: false
384
+ };
385
+ }
386
+ }
387
+ return {
388
+ shouldAddDirname,
389
+ success: true
390
+ };
391
+ }
392
+ function getDefaultImportLocalName({ moduleSpecifier, sourceFile }) {
393
+ const imports = sourceFile.getImportDeclarations().filter((declaration)=>declaration.getModuleSpecifierValue() === moduleSpecifier).map((declaration)=>declaration.getDefaultImport()?.getText()).filter((name)=>Boolean(name));
394
+ if (imports.length !== 1) {
395
+ return undefined;
396
+ }
397
+ const localName = imports[0];
398
+ return hasOnlyCompatibleBinding({
399
+ localName,
400
+ predicate: (binding)=>isImportBinding({
401
+ binding,
402
+ importKind: 'default',
403
+ moduleSpecifier
404
+ }),
405
+ sourceFile
406
+ }) ? localName : undefined;
407
+ }
408
+ function getFrameworkImport({ appDetails, sourceFile }) {
409
+ const importedName = appDetails.kind === 'start' ? 'tanstackStart' : 'tanstackRouter';
410
+ const moduleSpecifier = appDetails.kind === 'start' ? '@tanstack/react-start/plugin/vite' : '@tanstack/router-plugin/vite';
411
+ for (const declaration of sourceFile.getImportDeclarations()){
412
+ if (declaration.getModuleSpecifierValue() !== moduleSpecifier) {
413
+ continue;
414
+ }
415
+ const namedImport = declaration.getNamedImports().find((specifier)=>specifier.getName() === importedName);
416
+ if (namedImport) {
417
+ return {
418
+ declaration,
419
+ localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName()
420
+ };
421
+ }
422
+ }
423
+ }
424
+ function isCompatiblePayloadConfig({ sourceFile, withPayloadCall }) {
425
+ if (withPayloadCall.getArguments().length !== 2 || !hasOnlyCompatibleBinding({
426
+ localName: 'withPayload',
427
+ predicate: (binding)=>isImportBinding({
428
+ binding,
429
+ importedName: 'withPayload',
430
+ importKind: 'named',
431
+ moduleSpecifier: '@payloadcms/tanstack-start'
432
+ }),
433
+ sourceFile
434
+ })) {
435
+ return false;
436
+ }
437
+ const [callback, options] = withPayloadCall.getArguments();
438
+ if (!Node.isArrowFunction(callback) || !Node.isObjectLiteralExpression(options)) {
439
+ return false;
440
+ }
441
+ const callbackParameters = callback.getParameters();
442
+ const callbackParameter = callbackParameters[0];
443
+ const callbackBinding = callbackParameter?.getNameNode();
444
+ if (callbackParameters.length !== 1 || !callbackParameter || !Node.isObjectBindingPattern(callbackBinding) || callbackBinding.getElements().length !== 1 || callbackBinding.getElements()[0]?.getName() !== 'pluginOptions' || callbackBinding.getElements()[0]?.getPropertyNameNode() || callbackBinding.getElements()[0]?.getInitializer() || callbackBinding.getElements()[0]?.getDotDotDotToken()) {
445
+ return false;
446
+ }
447
+ const callbackBody = callback.getBody();
448
+ const configObject = Node.isParenthesizedExpression(callbackBody) ? callbackBody.getExpression() : callbackBody;
449
+ if (!Node.isObjectLiteralExpression(configObject)) {
450
+ return false;
451
+ }
452
+ if (configObject.getProperties().some(Node.isSpreadAssignment)) {
453
+ return false;
454
+ }
455
+ const pluginsProperties = configObject.getProperties().filter(Node.isPropertyAssignment).filter((property)=>property.getName() === 'plugins');
456
+ const pluginsArray = pluginsProperties[0]?.getInitializer();
457
+ if (pluginsProperties.length !== 1 || !Node.isArrayLiteralExpression(pluginsArray) || pluginsArray.getElements().some(Node.isSpreadElement)) {
458
+ return false;
459
+ }
460
+ const reactPluginName = getDefaultImportLocalName({
461
+ moduleSpecifier: '@vitejs/plugin-react',
462
+ sourceFile
463
+ });
464
+ if (!reactPluginName || !hasOnlyCompatibleBinding({
465
+ localName: 'rsc',
466
+ predicate: (binding)=>isImportBinding({
467
+ binding,
468
+ importKind: 'default',
469
+ moduleSpecifier: '@vitejs/plugin-rsc'
470
+ }),
471
+ sourceFile
472
+ }) || !hasOnlyCompatibleBinding({
473
+ localName: 'tanstackStart',
474
+ predicate: (binding)=>isImportBinding({
475
+ binding,
476
+ importedName: 'tanstackStart',
477
+ importKind: 'named',
478
+ moduleSpecifier: '@tanstack/react-start/plugin/vite'
479
+ }),
480
+ sourceFile
481
+ }) || !hasOnlyCompatibleBinding({
482
+ localName: 'path',
483
+ predicate: isCompatiblePathBinding,
484
+ sourceFile
485
+ }) || !hasCompatibleDirnameBinding(sourceFile)) {
486
+ return false;
487
+ }
488
+ const dirnameInitializer = sourceFile.getVariableDeclaration('__dirname')?.getInitializer()?.getText();
489
+ if (dirnameInitializer === 'path.dirname(fileURLToPath(import.meta.url))' && !hasOnlyCompatibleBinding({
490
+ localName: 'fileURLToPath',
491
+ predicate: (binding)=>isImportBinding({
492
+ binding,
493
+ importedName: 'fileURLToPath',
494
+ importKind: 'named',
495
+ moduleSpecifier: 'node:url'
496
+ }),
497
+ sourceFile
498
+ })) {
499
+ return false;
500
+ }
501
+ const elements = pluginsArray.getElements();
502
+ const rscCalls = getNamedPluginCalls({
503
+ elements,
504
+ localName: 'rsc'
505
+ });
506
+ const frameworkCalls = getNamedPluginCalls({
507
+ elements,
508
+ localName: 'tanstackStart'
509
+ });
510
+ const reactCalls = getNamedPluginCalls({
511
+ elements,
512
+ localName: reactPluginName
513
+ });
514
+ if (rscCalls.length !== 1 || frameworkCalls.length !== 1 || reactCalls.length !== 1 || !isExactPluginCall({
515
+ call: rscCalls[0],
516
+ expectedArgument: 'pluginOptions.rsc'
517
+ }) || !isMergedPluginCall({
518
+ call: frameworkCalls[0],
519
+ expectedArgument: 'pluginOptions.tanstackStart'
520
+ }) || !isMergedPluginCall({
521
+ call: reactCalls[0],
522
+ expectedArgument: 'pluginOptions.react'
523
+ })) {
524
+ return false;
525
+ }
526
+ const rscIndex = elements.indexOf(rscCalls[0]);
527
+ const frameworkIndex = elements.indexOf(frameworkCalls[0]);
528
+ const reactIndex = elements.indexOf(reactCalls[0]);
529
+ if (frameworkIndex !== rscIndex + 1 || reactIndex !== frameworkIndex + 1) {
530
+ return false;
531
+ }
532
+ const optionProperties = options.getProperties().filter(Node.isPropertyAssignment);
533
+ if (optionProperties.length !== 2 || options.getProperties().length !== 2) {
534
+ return false;
535
+ }
536
+ const payloadConfigPath = optionProperties.find((property)=>property.getName() === 'payloadConfigPath');
537
+ const routesDirectory = optionProperties.find((property)=>property.getName() === 'routesDirectory');
538
+ const routesDirectoryInitializer = routesDirectory?.getInitializer();
539
+ return payloadConfigPath?.getInitializer()?.getText() === PAYLOAD_CONFIG_PATH && Node.isStringLiteral(routesDirectoryInitializer) && routesDirectoryInitializer.getLiteralValue() === 'routes';
540
+ }
541
+ function removeNamedImport({ declaration, importedName }) {
542
+ const namedImport = declaration.getNamedImports().find((specifier)=>specifier.getName() === importedName);
543
+ namedImport?.remove();
544
+ if (declaration.getNamedImports().length === 0 && !declaration.getDefaultImport() && !declaration.getNamespaceImport()) {
545
+ declaration.remove();
546
+ }
547
+ }
548
+ function replacePluginCalls({ frameworkCall, frameworkIndex, pluginsArray, preserveFrameworkOptions, reactCall, reactIndex, reactPluginName }) {
549
+ const retainedPlugins = pluginsArray.getElements().filter((_, index)=>index !== frameworkIndex && index !== reactIndex).map((element)=>element.getText());
550
+ const insertionIndex = Math.min(frameworkIndex, reactIndex);
551
+ retainedPlugins.splice(insertionIndex, 0, 'rsc(pluginOptions.rsc)', getPluginCallWithMergedOptions({
552
+ call: frameworkCall,
553
+ localName: 'tanstackStart',
554
+ pluginOptions: 'pluginOptions.tanstackStart',
555
+ shouldPreserveOptions: preserveFrameworkOptions
556
+ }), getPluginCallWithMergedOptions({
557
+ call: reactCall,
558
+ localName: reactPluginName,
559
+ pluginOptions: 'pluginOptions.react',
560
+ shouldPreserveOptions: true
561
+ }));
562
+ pluginsArray.replaceWithText(`[${retainedPlugins.join(', ')}]`);
563
+ }
564
+ function getPluginCallWithMergedOptions({ call, localName, pluginOptions, shouldPreserveOptions }) {
565
+ const existingOptions = shouldPreserveOptions ? call.getArguments()[0] : undefined;
566
+ if (!existingOptions) {
567
+ return `${localName}(${pluginOptions})`;
568
+ }
569
+ if (Node.isObjectLiteralExpression(existingOptions)) {
570
+ const properties = existingOptions.getText().slice(1, -1).trim();
571
+ return `${localName}({ ...${pluginOptions}${properties ? `, ${properties}` : ''} })`;
572
+ }
573
+ return `${localName}({ ...${pluginOptions}, ...(${existingOptions.getText()}) })`;
574
+ }
575
+
576
+ //# sourceMappingURL=transform-vite-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/tanstack/transform-vite-config.ts"],"sourcesContent":["import type {\n ArrayLiteralExpression,\n CallExpression,\n Expression,\n ImportDeclaration,\n Node as MorphNode,\n SourceFile,\n} from 'ts-morph'\n\nimport { Node, Project, QuoteKind, SyntaxKind } from 'ts-morph'\n\nimport type { TanStackAppDetails } from '../../types.js'\n\nexport type TextTransformResult =\n | { content: string; modified: boolean; success: true }\n | { reason: string; success: false }\n\ntype LocalBinding =\n | {\n declaration: ImportDeclaration\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n isTypeOnly: boolean\n kind: 'import'\n moduleSpecifier: string\n }\n | { kind: 'other' | 'variable' }\n\nconst PAYLOAD_CONFIG_PATH = \"path.resolve(__dirname, 'src', 'payload.config.ts')\"\n\nexport function transformTanStackViteConfig({\n appDetails,\n content,\n}: {\n appDetails: TanStackAppDetails\n content: string\n}): TextTransformResult {\n const project = new Project({\n manipulationSettings: { quoteKind: QuoteKind.Single },\n useInMemoryFileSystem: true,\n })\n const sourceFile = project.createSourceFile('vite.config.ts', content)\n const defineConfigCalls = sourceFile\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((call) => call.getExpression().getText() === 'defineConfig')\n\n if (defineConfigCalls.length !== 1) {\n return failure('Expected exactly one defineConfig() call.')\n }\n\n const defineConfigCall = defineConfigCalls[0]!\n if (defineConfigCall.getArguments().length !== 1) {\n return failure('defineConfig() must receive exactly one argument.')\n }\n\n const configArgument = defineConfigCall.getArguments()[0]\n\n if (\n Node.isCallExpression(configArgument) &&\n configArgument.getExpression().getText() === 'withPayload'\n ) {\n if (isCompatiblePayloadConfig({ sourceFile, withPayloadCall: configArgument })) {\n return { content, modified: false, success: true }\n }\n\n return failure('The existing withPayload() call does not match the supported configuration.')\n }\n\n if (!Node.isObjectLiteralExpression(configArgument)) {\n return failure('defineConfig() must receive an object literal.')\n }\n\n if (configArgument.getProperties().some(Node.isSpreadAssignment)) {\n return failure('Config object spreads cannot be transformed safely.')\n }\n\n const pluginsProperties = configArgument\n .getProperties()\n .filter(Node.isPropertyAssignment)\n .filter((property) => property.getName() === 'plugins')\n const pluginsProperty = pluginsProperties[0]\n if (pluginsProperties.length !== 1 || !pluginsProperty) {\n return failure('The Vite config must contain a plugins array.')\n }\n\n const pluginsArray = pluginsProperty.getInitializer()\n if (!Node.isArrayLiteralExpression(pluginsArray)) {\n return failure('The Vite config must contain a plugins array.')\n }\n\n if (pluginsArray.getElements().some(Node.isSpreadElement)) {\n return failure('Plugin array spreads cannot be transformed safely.')\n }\n\n const frameworkImport = getFrameworkImport({ appDetails, sourceFile })\n if (!frameworkImport) {\n return failure('Could not identify the TanStack framework plugin import.')\n }\n\n const reactPluginName = getDefaultImportLocalName({\n moduleSpecifier: '@vitejs/plugin-react',\n sourceFile,\n })\n\n if (!reactPluginName) {\n return failure('Could not identify the React plugin import.')\n }\n\n const pluginCalls = pluginsArray\n .getElements()\n .map((element) =>\n Node.isCallExpression(element)\n ? { name: element.getExpression().getText(), element }\n : { name: undefined, element },\n )\n const frameworkCalls = pluginCalls.filter(({ name }) => name === frameworkImport.localName)\n const reactCalls = pluginCalls.filter(({ name }) => name === reactPluginName)\n\n if (frameworkCalls.length !== 1) {\n return failure('Expected exactly one TanStack framework plugin call.')\n }\n\n if (reactCalls.length !== 1) {\n return failure('Expected exactly one React plugin call.')\n }\n\n const frameworkIndex = pluginCalls.indexOf(frameworkCalls[0]!)\n const reactIndex = pluginCalls.indexOf(reactCalls[0]!)\n\n if (reactIndex !== frameworkIndex + 1) {\n return failure('Framework and React plugin calls must be adjacent and ordered.')\n }\n\n const frameworkCall = frameworkCalls[0]!.element\n const reactCall = reactCalls[0]!.element\n if (\n !Node.isCallExpression(frameworkCall) ||\n !Node.isCallExpression(reactCall) ||\n frameworkCall.getArguments().length > 1 ||\n reactCall.getArguments().length > 1\n ) {\n return failure('Framework and React plugin calls must receive at most one argument.')\n }\n\n const destinationValidation = validateDestinationBindings({ sourceFile })\n if (!destinationValidation.success) {\n return destinationValidation\n }\n\n replacePluginCalls({\n frameworkCall,\n frameworkIndex,\n pluginsArray,\n preserveFrameworkOptions: appDetails.kind === 'start',\n reactCall,\n reactIndex,\n reactPluginName,\n })\n\n const transformedConfig = configArgument.getText()\n defineConfigCall.replaceWithText(`defineConfig(\n withPayload(\n ({ pluginOptions }) => (${transformedConfig}),\n {\n payloadConfigPath: ${PAYLOAD_CONFIG_PATH},\n routesDirectory: 'routes',\n },\n ),\n)`)\n\n if (appDetails.kind === 'router-only') {\n removeNamedImport({\n declaration: frameworkImport.declaration,\n importedName: 'tanstackRouter',\n })\n }\n\n ensureNamedImport({\n importedName: 'withPayload',\n moduleSpecifier: '@payloadcms/tanstack-start',\n sourceFile,\n })\n ensureNamedImport({\n importedName: 'tanstackStart',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n sourceFile,\n })\n ensureDefaultImport({\n defaultImport: 'rsc',\n moduleSpecifier: '@vitejs/plugin-rsc',\n sourceFile,\n })\n ensurePathImport(sourceFile)\n\n if (destinationValidation.shouldAddDirname) {\n ensureNamedImport({\n importedName: 'fileURLToPath',\n moduleSpecifier: 'node:url',\n sourceFile,\n })\n sourceFile.insertStatements(\n sourceFile.getImportDeclarations().length,\n `const __dirname = path.dirname(fileURLToPath(import.meta.url))`,\n )\n }\n\n sourceFile.formatText({ indentSize: 2 })\n\n return { content: sourceFile.getFullText(), modified: true, success: true }\n}\n\nfunction ensureDefaultImport({\n defaultImport,\n moduleSpecifier,\n sourceFile,\n}: {\n defaultImport: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const matchingImport = sourceFile\n .getImportDeclarations()\n .find(\n (declaration) =>\n declaration.getModuleSpecifierValue() === moduleSpecifier &&\n declaration.getDefaultImport()?.getText() === defaultImport,\n )\n\n if (!matchingImport) {\n sourceFile.addImportDeclaration({ defaultImport, moduleSpecifier })\n }\n}\n\nfunction ensureNamedImport({\n importedName,\n moduleSpecifier,\n sourceFile,\n}: {\n importedName: string\n moduleSpecifier: string\n sourceFile: SourceFile\n}) {\n const imports = sourceFile\n .getImportDeclarations()\n .filter((declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier)\n const hasImport = imports.some((declaration) =>\n declaration\n .getNamedImports()\n .some((namedImport) => namedImport.getName() === importedName && !namedImport.getAliasNode()),\n )\n\n if (hasImport) {\n return\n }\n\n const extensibleImport = imports.find((declaration) => !declaration.getNamespaceImport())\n if (extensibleImport) {\n extensibleImport.addNamedImport(importedName)\n } else {\n sourceFile.addImportDeclaration({ moduleSpecifier, namedImports: [importedName] })\n }\n}\n\nfunction ensurePathImport(sourceFile: SourceFile) {\n const hasCompatibleImport = sourceFile.getImportDeclarations().some((declaration) => {\n if (declaration.getModuleSpecifierValue() !== 'node:path') {\n return false\n }\n\n return (\n declaration.getDefaultImport()?.getText() === 'path' ||\n declaration.getNamespaceImport()?.getText() === 'path'\n )\n })\n\n if (!hasCompatibleImport) {\n sourceFile.addImportDeclaration({ defaultImport: 'path', moduleSpecifier: 'node:path' })\n }\n}\n\nfunction failure(reason: string): TextTransformResult {\n return { reason, success: false }\n}\n\nfunction getLocalBindings({\n localName,\n sourceFile,\n}: {\n localName: string\n sourceFile: SourceFile\n}): LocalBinding[] {\n const bindings: LocalBinding[] = []\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n const moduleSpecifier = declaration.getModuleSpecifierValue()\n const defaultImport = declaration.getDefaultImport()\n if (defaultImport?.getText() === localName) {\n bindings.push({\n declaration,\n importKind: 'default',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n const namespaceImport = declaration.getNamespaceImport()\n if (namespaceImport?.getText() === localName) {\n bindings.push({\n declaration,\n importKind: 'namespace',\n isTypeOnly: declaration.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n\n for (const namedImport of declaration.getNamedImports()) {\n const namedImportLocalName = namedImport.getAliasNode()?.getText() ?? namedImport.getName()\n if (namedImportLocalName === localName) {\n bindings.push({\n declaration,\n importedName: namedImport.getName(),\n importKind: 'named',\n isTypeOnly: declaration.isTypeOnly() || namedImport.isTypeOnly(),\n kind: 'import',\n moduleSpecifier,\n })\n }\n }\n }\n\n for (const declaration of sourceFile.getVariableDeclarations()) {\n if (bindingNameIncludes({ localName, node: declaration.getNameNode() })) {\n bindings.push({ kind: 'variable' })\n }\n }\n\n const hasOtherDeclaration = [\n ...sourceFile.getClasses(),\n ...sourceFile.getEnums(),\n ...sourceFile.getFunctions(),\n ...sourceFile.getModules(),\n ].some((declaration) => declaration.getName() === localName)\n\n if (hasOtherDeclaration) {\n bindings.push({ kind: 'other' })\n }\n\n return bindings\n}\n\nfunction bindingNameIncludes({ localName, node }: { localName: string; node: MorphNode }): boolean {\n if (Node.isIdentifier(node)) {\n return node.getText() === localName\n }\n\n if (Node.isArrayBindingPattern(node) || Node.isObjectBindingPattern(node)) {\n return node\n .getElements()\n .some(\n (element) =>\n Node.isBindingElement(element) &&\n bindingNameIncludes({ localName, node: element.getNameNode() }),\n )\n }\n\n return false\n}\n\nfunction getNamedPluginCalls({\n elements,\n localName,\n}: {\n elements: Expression[]\n localName: string\n}): CallExpression[] {\n return elements.filter(\n (element): element is CallExpression =>\n Node.isCallExpression(element) && element.getExpression().getText() === localName,\n )\n}\n\nfunction hasCompatibleDirnameBinding(sourceFile: SourceFile): boolean {\n const bindings = getLocalBindings({ localName: '__dirname', sourceFile })\n\n return bindings.length === 1 && bindings[0]?.kind === 'variable'\n}\n\nfunction hasOnlyCompatibleBinding({\n localName,\n predicate,\n sourceFile,\n}: {\n localName: string\n predicate: (binding: LocalBinding) => boolean\n sourceFile: SourceFile\n}): boolean {\n const bindings = getLocalBindings({ localName, sourceFile })\n\n return bindings.length === 1 && predicate(bindings[0]!)\n}\n\nfunction isCompatiblePathBinding(binding: LocalBinding): boolean {\n return (\n binding.kind === 'import' &&\n !binding.isTypeOnly &&\n binding.moduleSpecifier === 'node:path' &&\n (binding.importKind === 'default' || binding.importKind === 'namespace')\n )\n}\n\nfunction isExactPluginCall({\n call,\n expectedArgument,\n}: {\n call: CallExpression\n expectedArgument: string\n}): boolean {\n return call.getArguments().length === 1 && call.getArguments()[0]?.getText() === expectedArgument\n}\n\nfunction isMergedPluginCall({\n call,\n expectedArgument,\n}: {\n call: CallExpression\n expectedArgument: string\n}): boolean {\n if (isExactPluginCall({ call, expectedArgument })) {\n return true\n }\n\n const argument = call.getArguments()[0]\n if (call.getArguments().length !== 1 || !Node.isObjectLiteralExpression(argument)) {\n return false\n }\n\n const firstProperty = argument.getProperties()[0]\n return (\n Node.isSpreadAssignment(firstProperty) &&\n firstProperty.getExpression().getText() === expectedArgument\n )\n}\n\nfunction isImportBinding({\n binding,\n importedName,\n importKind,\n moduleSpecifier,\n}: {\n binding: LocalBinding\n importedName?: string\n importKind: 'default' | 'named' | 'namespace'\n moduleSpecifier: string\n}): boolean {\n return (\n binding.kind === 'import' &&\n !binding.isTypeOnly &&\n binding.importKind === importKind &&\n binding.moduleSpecifier === moduleSpecifier &&\n (importedName === undefined || binding.importedName === importedName)\n )\n}\n\nfunction validateDestinationBindings({\n sourceFile,\n}: {\n sourceFile: SourceFile\n}): { reason: string; success: false } | { shouldAddDirname: boolean; success: true } {\n const destinations: Array<{\n localName: string\n predicate: (binding: LocalBinding) => boolean\n }> = [\n {\n localName: 'withPayload',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'withPayload',\n importKind: 'named',\n moduleSpecifier: '@payloadcms/tanstack-start',\n }),\n },\n {\n localName: 'tanstackStart',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'tanstackStart',\n importKind: 'named',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n }),\n },\n {\n localName: 'rsc',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importKind: 'default',\n moduleSpecifier: '@vitejs/plugin-rsc',\n }),\n },\n { localName: 'path', predicate: isCompatiblePathBinding },\n ]\n\n for (const destination of destinations) {\n const bindings = getLocalBindings({ localName: destination.localName, sourceFile })\n if (bindings.length > 0 && (bindings.length !== 1 || !destination.predicate(bindings[0]!))) {\n return {\n reason: `Identifier \"${destination.localName}\" is already bound incompatibly.`,\n success: false,\n }\n }\n }\n\n const dirnameBindings = getLocalBindings({ localName: '__dirname', sourceFile })\n if (\n dirnameBindings.length > 0 &&\n (dirnameBindings.length !== 1 || dirnameBindings[0]?.kind !== 'variable')\n ) {\n return { reason: 'Identifier \"__dirname\" is already bound incompatibly.', success: false }\n }\n\n const shouldAddDirname = dirnameBindings.length === 0\n if (shouldAddDirname) {\n const fileURLToPathBindings = getLocalBindings({ localName: 'fileURLToPath', sourceFile })\n if (\n fileURLToPathBindings.length > 0 &&\n (fileURLToPathBindings.length !== 1 ||\n !isImportBinding({\n binding: fileURLToPathBindings[0]!,\n importedName: 'fileURLToPath',\n importKind: 'named',\n moduleSpecifier: 'node:url',\n }))\n ) {\n return {\n reason: 'Identifier \"fileURLToPath\" is already bound incompatibly.',\n success: false,\n }\n }\n }\n\n return { shouldAddDirname, success: true }\n}\n\nfunction getDefaultImportLocalName({\n moduleSpecifier,\n sourceFile,\n}: {\n moduleSpecifier: string\n sourceFile: SourceFile\n}): string | undefined {\n const imports = sourceFile\n .getImportDeclarations()\n .filter((declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier)\n .map((declaration) => declaration.getDefaultImport()?.getText())\n .filter((name): name is string => Boolean(name))\n\n if (imports.length !== 1) {\n return undefined\n }\n\n const localName = imports[0]!\n return hasOnlyCompatibleBinding({\n localName,\n predicate: (binding) => isImportBinding({ binding, importKind: 'default', moduleSpecifier }),\n sourceFile,\n })\n ? localName\n : undefined\n}\n\nfunction getFrameworkImport({\n appDetails,\n sourceFile,\n}: {\n appDetails: TanStackAppDetails\n sourceFile: SourceFile\n}): { declaration: ImportDeclaration; localName: string } | undefined {\n const importedName = appDetails.kind === 'start' ? 'tanstackStart' : 'tanstackRouter'\n const moduleSpecifier =\n appDetails.kind === 'start'\n ? '@tanstack/react-start/plugin/vite'\n : '@tanstack/router-plugin/vite'\n\n for (const declaration of sourceFile.getImportDeclarations()) {\n if (declaration.getModuleSpecifierValue() !== moduleSpecifier) {\n continue\n }\n\n const namedImport = declaration\n .getNamedImports()\n .find((specifier) => specifier.getName() === importedName)\n\n if (namedImport) {\n return {\n declaration,\n localName: namedImport.getAliasNode()?.getText() ?? namedImport.getName(),\n }\n }\n }\n}\n\nfunction isCompatiblePayloadConfig({\n sourceFile,\n withPayloadCall,\n}: {\n sourceFile: SourceFile\n withPayloadCall: CallExpression\n}): boolean {\n if (\n withPayloadCall.getArguments().length !== 2 ||\n !hasOnlyCompatibleBinding({\n localName: 'withPayload',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'withPayload',\n importKind: 'named',\n moduleSpecifier: '@payloadcms/tanstack-start',\n }),\n sourceFile,\n })\n ) {\n return false\n }\n\n const [callback, options] = withPayloadCall.getArguments()\n\n if (!Node.isArrowFunction(callback) || !Node.isObjectLiteralExpression(options)) {\n return false\n }\n\n const callbackParameters = callback.getParameters()\n const callbackParameter = callbackParameters[0]\n const callbackBinding = callbackParameter?.getNameNode()\n if (\n callbackParameters.length !== 1 ||\n !callbackParameter ||\n !Node.isObjectBindingPattern(callbackBinding) ||\n callbackBinding.getElements().length !== 1 ||\n callbackBinding.getElements()[0]?.getName() !== 'pluginOptions' ||\n callbackBinding.getElements()[0]?.getPropertyNameNode() ||\n callbackBinding.getElements()[0]?.getInitializer() ||\n callbackBinding.getElements()[0]?.getDotDotDotToken()\n ) {\n return false\n }\n\n const callbackBody = callback.getBody()\n const configObject = Node.isParenthesizedExpression(callbackBody)\n ? callbackBody.getExpression()\n : callbackBody\n\n if (!Node.isObjectLiteralExpression(configObject)) {\n return false\n }\n\n if (configObject.getProperties().some(Node.isSpreadAssignment)) {\n return false\n }\n\n const pluginsProperties = configObject\n .getProperties()\n .filter(Node.isPropertyAssignment)\n .filter((property) => property.getName() === 'plugins')\n const pluginsArray = pluginsProperties[0]?.getInitializer()\n\n if (\n pluginsProperties.length !== 1 ||\n !Node.isArrayLiteralExpression(pluginsArray) ||\n pluginsArray.getElements().some(Node.isSpreadElement)\n ) {\n return false\n }\n\n const reactPluginName = getDefaultImportLocalName({\n moduleSpecifier: '@vitejs/plugin-react',\n sourceFile,\n })\n if (\n !reactPluginName ||\n !hasOnlyCompatibleBinding({\n localName: 'rsc',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importKind: 'default',\n moduleSpecifier: '@vitejs/plugin-rsc',\n }),\n sourceFile,\n }) ||\n !hasOnlyCompatibleBinding({\n localName: 'tanstackStart',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'tanstackStart',\n importKind: 'named',\n moduleSpecifier: '@tanstack/react-start/plugin/vite',\n }),\n sourceFile,\n }) ||\n !hasOnlyCompatibleBinding({\n localName: 'path',\n predicate: isCompatiblePathBinding,\n sourceFile,\n }) ||\n !hasCompatibleDirnameBinding(sourceFile)\n ) {\n return false\n }\n\n const dirnameInitializer = sourceFile\n .getVariableDeclaration('__dirname')\n ?.getInitializer()\n ?.getText()\n if (\n dirnameInitializer === 'path.dirname(fileURLToPath(import.meta.url))' &&\n !hasOnlyCompatibleBinding({\n localName: 'fileURLToPath',\n predicate: (binding) =>\n isImportBinding({\n binding,\n importedName: 'fileURLToPath',\n importKind: 'named',\n moduleSpecifier: 'node:url',\n }),\n sourceFile,\n })\n ) {\n return false\n }\n\n const elements = pluginsArray.getElements()\n const rscCalls = getNamedPluginCalls({ elements, localName: 'rsc' })\n const frameworkCalls = getNamedPluginCalls({ elements, localName: 'tanstackStart' })\n const reactCalls = getNamedPluginCalls({ elements, localName: reactPluginName })\n\n if (\n rscCalls.length !== 1 ||\n frameworkCalls.length !== 1 ||\n reactCalls.length !== 1 ||\n !isExactPluginCall({ call: rscCalls[0]!, expectedArgument: 'pluginOptions.rsc' }) ||\n !isMergedPluginCall({\n call: frameworkCalls[0]!,\n expectedArgument: 'pluginOptions.tanstackStart',\n }) ||\n !isMergedPluginCall({ call: reactCalls[0]!, expectedArgument: 'pluginOptions.react' })\n ) {\n return false\n }\n\n const rscIndex = elements.indexOf(rscCalls[0]!)\n const frameworkIndex = elements.indexOf(frameworkCalls[0]!)\n const reactIndex = elements.indexOf(reactCalls[0]!)\n if (frameworkIndex !== rscIndex + 1 || reactIndex !== frameworkIndex + 1) {\n return false\n }\n\n const optionProperties = options.getProperties().filter(Node.isPropertyAssignment)\n if (optionProperties.length !== 2 || options.getProperties().length !== 2) {\n return false\n }\n\n const payloadConfigPath = optionProperties.find(\n (property) => property.getName() === 'payloadConfigPath',\n )\n const routesDirectory = optionProperties.find(\n (property) => property.getName() === 'routesDirectory',\n )\n const routesDirectoryInitializer = routesDirectory?.getInitializer()\n\n return (\n payloadConfigPath?.getInitializer()?.getText() === PAYLOAD_CONFIG_PATH &&\n Node.isStringLiteral(routesDirectoryInitializer) &&\n routesDirectoryInitializer.getLiteralValue() === 'routes'\n )\n}\n\nfunction removeNamedImport({\n declaration,\n importedName,\n}: {\n declaration: ImportDeclaration\n importedName: string\n}) {\n const namedImport = declaration\n .getNamedImports()\n .find((specifier) => specifier.getName() === importedName)\n\n namedImport?.remove()\n\n if (\n declaration.getNamedImports().length === 0 &&\n !declaration.getDefaultImport() &&\n !declaration.getNamespaceImport()\n ) {\n declaration.remove()\n }\n}\n\nfunction replacePluginCalls({\n frameworkCall,\n frameworkIndex,\n pluginsArray,\n preserveFrameworkOptions,\n reactCall,\n reactIndex,\n reactPluginName,\n}: {\n frameworkCall: CallExpression\n frameworkIndex: number\n pluginsArray: ArrayLiteralExpression\n preserveFrameworkOptions: boolean\n reactCall: CallExpression\n reactIndex: number\n reactPluginName: string\n}) {\n const retainedPlugins = pluginsArray\n .getElements()\n .filter((_, index) => index !== frameworkIndex && index !== reactIndex)\n .map((element) => element.getText())\n const insertionIndex = Math.min(frameworkIndex, reactIndex)\n\n retainedPlugins.splice(\n insertionIndex,\n 0,\n 'rsc(pluginOptions.rsc)',\n getPluginCallWithMergedOptions({\n call: frameworkCall,\n localName: 'tanstackStart',\n pluginOptions: 'pluginOptions.tanstackStart',\n shouldPreserveOptions: preserveFrameworkOptions,\n }),\n getPluginCallWithMergedOptions({\n call: reactCall,\n localName: reactPluginName,\n pluginOptions: 'pluginOptions.react',\n shouldPreserveOptions: true,\n }),\n )\n\n pluginsArray.replaceWithText(`[${retainedPlugins.join(', ')}]`)\n}\n\nfunction getPluginCallWithMergedOptions({\n call,\n localName,\n pluginOptions,\n shouldPreserveOptions,\n}: {\n call: CallExpression\n localName: string\n pluginOptions: string\n shouldPreserveOptions: boolean\n}): string {\n const existingOptions = shouldPreserveOptions ? call.getArguments()[0] : undefined\n if (!existingOptions) {\n return `${localName}(${pluginOptions})`\n }\n\n if (Node.isObjectLiteralExpression(existingOptions)) {\n const properties = existingOptions.getText().slice(1, -1).trim()\n return `${localName}({ ...${pluginOptions}${properties ? `, ${properties}` : ''} })`\n }\n\n return `${localName}({ ...${pluginOptions}, ...(${existingOptions.getText()}) })`\n}\n"],"names":["Node","Project","QuoteKind","SyntaxKind","PAYLOAD_CONFIG_PATH","transformTanStackViteConfig","appDetails","content","project","manipulationSettings","quoteKind","Single","useInMemoryFileSystem","sourceFile","createSourceFile","defineConfigCalls","getDescendantsOfKind","CallExpression","filter","call","getExpression","getText","length","failure","defineConfigCall","getArguments","configArgument","isCallExpression","isCompatiblePayloadConfig","withPayloadCall","modified","success","isObjectLiteralExpression","getProperties","some","isSpreadAssignment","pluginsProperties","isPropertyAssignment","property","getName","pluginsProperty","pluginsArray","getInitializer","isArrayLiteralExpression","getElements","isSpreadElement","frameworkImport","getFrameworkImport","reactPluginName","getDefaultImportLocalName","moduleSpecifier","pluginCalls","map","element","name","undefined","frameworkCalls","localName","reactCalls","frameworkIndex","indexOf","reactIndex","frameworkCall","reactCall","destinationValidation","validateDestinationBindings","replacePluginCalls","preserveFrameworkOptions","kind","transformedConfig","replaceWithText","removeNamedImport","declaration","importedName","ensureNamedImport","ensureDefaultImport","defaultImport","ensurePathImport","shouldAddDirname","insertStatements","getImportDeclarations","formatText","indentSize","getFullText","matchingImport","find","getModuleSpecifierValue","getDefaultImport","addImportDeclaration","imports","hasImport","getNamedImports","namedImport","getAliasNode","extensibleImport","getNamespaceImport","addNamedImport","namedImports","hasCompatibleImport","reason","getLocalBindings","bindings","push","importKind","isTypeOnly","namespaceImport","namedImportLocalName","getVariableDeclarations","bindingNameIncludes","node","getNameNode","hasOtherDeclaration","getClasses","getEnums","getFunctions","getModules","isIdentifier","isArrayBindingPattern","isObjectBindingPattern","isBindingElement","getNamedPluginCalls","elements","hasCompatibleDirnameBinding","hasOnlyCompatibleBinding","predicate","isCompatiblePathBinding","binding","isExactPluginCall","expectedArgument","isMergedPluginCall","argument","firstProperty","isImportBinding","destinations","destination","dirnameBindings","fileURLToPathBindings","Boolean","specifier","callback","options","isArrowFunction","callbackParameters","getParameters","callbackParameter","callbackBinding","getPropertyNameNode","getDotDotDotToken","callbackBody","getBody","configObject","isParenthesizedExpression","dirnameInitializer","getVariableDeclaration","rscCalls","rscIndex","optionProperties","payloadConfigPath","routesDirectory","routesDirectoryInitializer","isStringLiteral","getLiteralValue","remove","retainedPlugins","_","index","insertionIndex","Math","min","splice","getPluginCallWithMergedOptions","pluginOptions","shouldPreserveOptions","join","existingOptions","properties","slice","trim"],"mappings":"AASA,SAASA,IAAI,EAAEC,OAAO,EAAEC,SAAS,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