@payloadcms/figma 0.0.1-alpha.4 → 0.0.1-alpha.40

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 (269) hide show
  1. package/dist/api/control-plane.d.ts +22 -1
  2. package/dist/api/control-plane.d.ts.map +1 -1
  3. package/dist/api/control-plane.js +55 -22
  4. package/dist/api/control-plane.js.map +1 -1
  5. package/dist/api/figma-api.d.ts.map +1 -1
  6. package/dist/api/figma-api.js +45 -26
  7. package/dist/api/figma-api.js.map +1 -1
  8. package/dist/auth/callback-server.d.ts.map +1 -1
  9. package/dist/auth/callback-server.js +2 -1
  10. package/dist/auth/callback-server.js.map +1 -1
  11. package/dist/auth/crypto-utils.d.ts.map +1 -1
  12. package/dist/auth/crypto-utils.js +5 -5
  13. package/dist/auth/crypto-utils.js.map +1 -1
  14. package/dist/auth/jwt-validator.d.ts +2 -1
  15. package/dist/auth/jwt-validator.d.ts.map +1 -1
  16. package/dist/auth/jwt-validator.js +2 -2
  17. package/dist/auth/jwt-validator.js.map +1 -1
  18. package/dist/auth/oauth-flow.d.ts +1 -1
  19. package/dist/auth/oauth-flow.d.ts.map +1 -1
  20. package/dist/auth/oauth-flow.js +9 -8
  21. package/dist/auth/oauth-flow.js.map +1 -1
  22. package/dist/auth/project-token.d.ts.map +1 -1
  23. package/dist/auth/project-token.js +9 -4
  24. package/dist/auth/project-token.js.map +1 -1
  25. package/dist/auth/refresh.d.ts.map +1 -1
  26. package/dist/auth/refresh.js +14 -9
  27. package/dist/auth/refresh.js.map +1 -1
  28. package/dist/auth/token-store.d.ts +10 -0
  29. package/dist/auth/token-store.d.ts.map +1 -1
  30. package/dist/auth/token-store.js +20 -0
  31. package/dist/auth/token-store.js.map +1 -1
  32. package/dist/cli.d.ts.map +1 -1
  33. package/dist/cli.js +31 -0
  34. package/dist/cli.js.map +1 -1
  35. package/dist/commands/build-lambda-zip.d.ts +5 -0
  36. package/dist/commands/build-lambda-zip.d.ts.map +1 -0
  37. package/dist/commands/build-lambda-zip.js +19 -0
  38. package/dist/commands/build-lambda-zip.js.map +1 -0
  39. package/dist/commands/deploy.d.ts +4 -0
  40. package/dist/commands/deploy.d.ts.map +1 -1
  41. package/dist/commands/deploy.js +71 -129
  42. package/dist/commands/deploy.js.map +1 -1
  43. package/dist/commands/init.d.ts +1 -5
  44. package/dist/commands/init.d.ts.map +1 -1
  45. package/dist/commands/init.js +94 -85
  46. package/dist/commands/init.js.map +1 -1
  47. package/dist/commands/list-tokens.d.ts.map +1 -1
  48. package/dist/commands/list-tokens.js +6 -3
  49. package/dist/commands/list-tokens.js.map +1 -1
  50. package/dist/commands/login.d.ts +8 -1
  51. package/dist/commands/login.d.ts.map +1 -1
  52. package/dist/commands/login.js +21 -11
  53. package/dist/commands/login.js.map +1 -1
  54. package/dist/commands/logout.js +2 -2
  55. package/dist/commands/logout.js.map +1 -1
  56. package/dist/config/oauth.d.ts +4 -14
  57. package/dist/config/oauth.d.ts.map +1 -1
  58. package/dist/config/oauth.js +19 -40
  59. package/dist/config/oauth.js.map +1 -1
  60. package/dist/constants.d.ts +26 -18
  61. package/dist/constants.d.ts.map +1 -1
  62. package/dist/constants.js +34 -20
  63. package/dist/constants.js.map +1 -1
  64. package/dist/db-content-api/README.md +98 -0
  65. package/dist/db-content-api/generated/content-api-types.d.ts +3848 -0
  66. package/dist/db-content-api/generated/content-api-types.d.ts.map +1 -0
  67. package/dist/db-content-api/generated/content-api-types.js +7 -0
  68. package/dist/db-content-api/generated/content-api-types.js.map +1 -0
  69. package/dist/db-content-api/index.d.ts +18 -0
  70. package/dist/db-content-api/index.d.ts.map +1 -0
  71. package/dist/db-content-api/index.js +571 -0
  72. package/dist/db-content-api/index.js.map +1 -0
  73. package/dist/db-content-api/temp-utilities/pagination.d.ts +13 -0
  74. package/dist/db-content-api/temp-utilities/pagination.d.ts.map +1 -0
  75. package/dist/db-content-api/temp-utilities/pagination.js +45 -0
  76. package/dist/db-content-api/temp-utilities/pagination.js.map +1 -0
  77. package/dist/db-content-api/temp-utilities/slug.d.ts +2 -0
  78. package/dist/db-content-api/temp-utilities/slug.d.ts.map +1 -0
  79. package/dist/db-content-api/temp-utilities/slug.js +3 -0
  80. package/dist/db-content-api/temp-utilities/slug.js.map +1 -0
  81. package/dist/db-content-api/temp-utilities/sorting.d.ts +3 -0
  82. package/dist/db-content-api/temp-utilities/sorting.d.ts.map +1 -0
  83. package/dist/db-content-api/temp-utilities/sorting.js +32 -0
  84. package/dist/db-content-api/temp-utilities/sorting.js.map +1 -0
  85. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts +4 -0
  86. package/dist/db-content-api/temp-utilities/unwrapDocument.d.ts.map +1 -0
  87. package/dist/db-content-api/temp-utilities/unwrapDocument.js +53 -0
  88. package/dist/db-content-api/temp-utilities/unwrapDocument.js.map +1 -0
  89. package/dist/db-content-api/utilities/auth.d.ts +30 -0
  90. package/dist/db-content-api/utilities/auth.d.ts.map +1 -0
  91. package/dist/db-content-api/utilities/auth.js +81 -0
  92. package/dist/db-content-api/utilities/auth.js.map +1 -0
  93. package/dist/db-content-api/utilities/data/applyDefaults.d.ts +7 -0
  94. package/dist/db-content-api/utilities/data/applyDefaults.d.ts.map +1 -0
  95. package/dist/db-content-api/utilities/data/applyDefaults.js +59 -0
  96. package/dist/db-content-api/utilities/data/applyDefaults.js.map +1 -0
  97. package/dist/db-content-api/utilities/data/castFieldValue.d.ts +11 -0
  98. package/dist/db-content-api/utilities/data/castFieldValue.d.ts.map +1 -0
  99. package/dist/db-content-api/utilities/data/castFieldValue.js +66 -0
  100. package/dist/db-content-api/utilities/data/castFieldValue.js.map +1 -0
  101. package/dist/db-content-api/utilities/data/index.d.ts +30 -0
  102. package/dist/db-content-api/utilities/data/index.d.ts.map +1 -0
  103. package/dist/db-content-api/utilities/data/index.js +173 -0
  104. package/dist/db-content-api/utilities/data/index.js.map +1 -0
  105. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +12 -0
  106. package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts.map +1 -0
  107. package/dist/db-content-api/utilities/data/removeVirtualFields.js +54 -0
  108. package/dist/db-content-api/utilities/data/removeVirtualFields.js.map +1 -0
  109. package/dist/db-content-api/utilities/data/stripFields.d.ts +48 -0
  110. package/dist/db-content-api/utilities/data/stripFields.d.ts.map +1 -0
  111. package/dist/db-content-api/utilities/data/stripFields.js +195 -0
  112. package/dist/db-content-api/utilities/data/stripFields.js.map +1 -0
  113. package/dist/db-content-api/utilities/joins.d.ts +55 -0
  114. package/dist/db-content-api/utilities/joins.d.ts.map +1 -0
  115. package/dist/db-content-api/utilities/joins.js +136 -0
  116. package/dist/db-content-api/utilities/joins.js.map +1 -0
  117. package/dist/db-content-api/utilities/where.d.ts +12 -0
  118. package/dist/db-content-api/utilities/where.d.ts.map +1 -0
  119. package/dist/db-content-api/utilities/where.js +107 -0
  120. package/dist/db-content-api/utilities/where.js.map +1 -0
  121. package/dist/endpoints/health.d.ts +3 -0
  122. package/dist/endpoints/health.d.ts.map +1 -0
  123. package/dist/endpoints/health.js +11 -0
  124. package/dist/endpoints/health.js.map +1 -0
  125. package/dist/exports/client.d.ts +4 -0
  126. package/dist/exports/client.d.ts.map +1 -0
  127. package/dist/exports/client.js +5 -0
  128. package/dist/exports/client.js.map +1 -0
  129. package/dist/index.d.ts +2 -1
  130. package/dist/index.d.ts.map +1 -1
  131. package/dist/index.js +3 -1
  132. package/dist/index.js.map +1 -1
  133. package/dist/oauth/components/LoginButton/index.d.ts.map +1 -1
  134. package/dist/oauth/components/LoginButton/index.js +50 -6
  135. package/dist/oauth/components/LoginButton/index.js.map +1 -1
  136. package/dist/oauth/components/LoginButton/index.scss +50 -3
  137. package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -1
  138. package/dist/oauth/components/LogoutButton/index.js +0 -1
  139. package/dist/oauth/components/LogoutButton/index.js.map +1 -1
  140. package/dist/oauth/defaults.d.ts.map +1 -1
  141. package/dist/oauth/defaults.js +29 -5
  142. package/dist/oauth/defaults.js.map +1 -1
  143. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -1
  144. package/dist/oauth/endpoints/getLoginEndpoint.js +4 -4
  145. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -1
  146. package/dist/oauth/index.d.ts.map +1 -1
  147. package/dist/oauth/index.js +42 -7
  148. package/dist/oauth/index.js.map +1 -1
  149. package/dist/oauth/strategy/index.d.ts +0 -2
  150. package/dist/oauth/strategy/index.d.ts.map +1 -1
  151. package/dist/oauth/strategy/index.js +38 -15
  152. package/dist/oauth/strategy/index.js.map +1 -1
  153. package/dist/oauth/types.d.ts +6 -6
  154. package/dist/oauth/types.d.ts.map +1 -1
  155. package/dist/oauth/types.js.map +1 -1
  156. package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -1
  157. package/dist/oauth/utilities/createCookieOptions.js.map +1 -1
  158. package/dist/oauth/utilities/isDuplicateKeyError.d.ts +7 -0
  159. package/dist/oauth/utilities/isDuplicateKeyError.d.ts.map +1 -0
  160. package/dist/oauth/utilities/isDuplicateKeyError.js +14 -0
  161. package/dist/oauth/utilities/isDuplicateKeyError.js.map +1 -0
  162. package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -1
  163. package/dist/oauth/utilities/refreshTokens.js +1 -1
  164. package/dist/oauth/utilities/refreshTokens.js.map +1 -1
  165. package/dist/plugin/build-config.d.ts +21 -4
  166. package/dist/plugin/build-config.d.ts.map +1 -1
  167. package/dist/plugin/build-config.js +114 -8
  168. package/dist/plugin/build-config.js.map +1 -1
  169. package/dist/storage-content-api/api-types.d.ts +161 -0
  170. package/dist/storage-content-api/api-types.d.ts.map +1 -0
  171. package/dist/storage-content-api/api-types.js +6 -0
  172. package/dist/storage-content-api/api-types.js.map +1 -0
  173. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts +9 -0
  174. package/dist/storage-content-api/client-uploads/ClientUploadHandler.d.ts.map +1 -0
  175. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js +42 -0
  176. package/dist/storage-content-api/client-uploads/ClientUploadHandler.js.map +1 -0
  177. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts +13 -0
  178. package/dist/storage-content-api/client-uploads/generateSignedURL.d.ts.map +1 -0
  179. package/dist/storage-content-api/client-uploads/generateSignedURL.js +31 -0
  180. package/dist/storage-content-api/client-uploads/generateSignedURL.js.map +1 -0
  181. package/dist/storage-content-api/client.d.ts +6 -0
  182. package/dist/storage-content-api/client.d.ts.map +1 -0
  183. package/dist/storage-content-api/client.js +36 -0
  184. package/dist/storage-content-api/client.js.map +1 -0
  185. package/dist/storage-content-api/generateURL.d.ts +7 -0
  186. package/dist/storage-content-api/generateURL.d.ts.map +1 -0
  187. package/dist/storage-content-api/generateURL.js +7 -0
  188. package/dist/storage-content-api/generateURL.js.map +1 -0
  189. package/dist/storage-content-api/handleDelete.d.ts +8 -0
  190. package/dist/storage-content-api/handleDelete.d.ts.map +1 -0
  191. package/dist/storage-content-api/handleDelete.js +15 -0
  192. package/dist/storage-content-api/handleDelete.js.map +1 -0
  193. package/dist/storage-content-api/handleUpload.d.ts +11 -0
  194. package/dist/storage-content-api/handleUpload.d.ts.map +1 -0
  195. package/dist/storage-content-api/handleUpload.js +136 -0
  196. package/dist/storage-content-api/handleUpload.js.map +1 -0
  197. package/dist/storage-content-api/index.d.ts +5 -0
  198. package/dist/storage-content-api/index.d.ts.map +1 -0
  199. package/dist/storage-content-api/index.js +31 -0
  200. package/dist/storage-content-api/index.js.map +1 -0
  201. package/dist/storage-content-api/staticHandler.d.ts +10 -0
  202. package/dist/storage-content-api/staticHandler.d.ts.map +1 -0
  203. package/dist/storage-content-api/staticHandler.js +55 -0
  204. package/dist/storage-content-api/staticHandler.js.map +1 -0
  205. package/dist/storage-content-api/types.d.ts +10 -0
  206. package/dist/storage-content-api/types.d.ts.map +1 -0
  207. package/dist/storage-content-api/types.js +3 -0
  208. package/dist/storage-content-api/types.js.map +1 -0
  209. package/dist/templates/README.md +19 -0
  210. package/dist/types.d.ts +1 -0
  211. package/dist/types.d.ts.map +1 -1
  212. package/dist/types.js.map +1 -1
  213. package/dist/utils/asset-collection.d.ts +3 -6
  214. package/dist/utils/asset-collection.d.ts.map +1 -1
  215. package/dist/utils/asset-collection.js +10 -34
  216. package/dist/utils/asset-collection.js.map +1 -1
  217. package/dist/utils/build-lambda-zip.d.ts +14 -0
  218. package/dist/utils/build-lambda-zip.d.ts.map +1 -0
  219. package/dist/utils/build-lambda-zip.js +81 -0
  220. package/dist/utils/build-lambda-zip.js.map +1 -0
  221. package/dist/utils/config.js +1 -1
  222. package/dist/utils/config.js.map +1 -1
  223. package/dist/utils/env-management.d.ts +9 -8
  224. package/dist/utils/env-management.d.ts.map +1 -1
  225. package/dist/utils/env-management.js +73 -74
  226. package/dist/utils/env-management.js.map +1 -1
  227. package/dist/utils/formatter.d.ts.map +1 -1
  228. package/dist/utils/formatter.js +3 -5
  229. package/dist/utils/formatter.js.map +1 -1
  230. package/dist/utils/lambda-config.d.ts +3 -1
  231. package/dist/utils/lambda-config.d.ts.map +1 -1
  232. package/dist/utils/lambda-config.js +13 -21
  233. package/dist/utils/lambda-config.js.map +1 -1
  234. package/dist/utils/messages.d.ts.map +1 -1
  235. package/dist/utils/messages.js +8 -7
  236. package/dist/utils/messages.js.map +1 -1
  237. package/dist/utils/payload-config-ast.d.ts +22 -3
  238. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  239. package/dist/utils/payload-config-ast.js +89 -31
  240. package/dist/utils/payload-config-ast.js.map +1 -1
  241. package/dist/utils/payload-config-finder.d.ts +2 -2
  242. package/dist/utils/payload-config-finder.d.ts.map +1 -1
  243. package/dist/utils/payload-config-finder.js +48 -9
  244. package/dist/utils/payload-config-finder.js.map +1 -1
  245. package/dist/utils/payload-config-modifier.d.ts.map +1 -1
  246. package/dist/utils/payload-config-modifier.js +54 -6
  247. package/dist/utils/payload-config-modifier.js.map +1 -1
  248. package/dist/utils/payload-package-check.d.ts +12 -1
  249. package/dist/utils/payload-package-check.d.ts.map +1 -1
  250. package/dist/utils/payload-package-check.js +63 -5
  251. package/dist/utils/payload-package-check.js.map +1 -1
  252. package/dist/utils/project.d.ts.map +1 -1
  253. package/dist/utils/project.js +8 -5
  254. package/dist/utils/project.js.map +1 -1
  255. package/dist/utils/s3-upload.d.ts +0 -1
  256. package/dist/utils/s3-upload.d.ts.map +1 -1
  257. package/dist/utils/s3-upload.js +10 -3
  258. package/dist/utils/s3-upload.js.map +1 -1
  259. package/dist/utils/token-display.d.ts.map +1 -1
  260. package/dist/utils/token-display.js +11 -5
  261. package/dist/utils/token-display.js.map +1 -1
  262. package/dist/utils/typescript-validator.d.ts.map +1 -1
  263. package/dist/utils/typescript-validator.js +4 -6
  264. package/dist/utils/typescript-validator.js.map +1 -1
  265. package/dist/utils/version-check.d.ts +3 -0
  266. package/dist/utils/version-check.d.ts.map +1 -0
  267. package/dist/utils/version-check.js +38 -0
  268. package/dist/utils/version-check.js.map +1 -0
  269. package/package.json +31 -7
@@ -20,15 +20,18 @@ import * as log from './log.js';
20
20
  log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`);
21
21
  const moduleSpecifier = payloadImport.getModuleSpecifierValue();
22
22
  const namedImports = payloadImport.getNamedImports();
23
- // Check if buildConfig is imported
24
- const buildConfigImport = namedImports.find((ni)=>ni.getName() === 'buildConfig');
23
+ // Determine which function name to look for based on the import source
24
+ // - From 'payload': look for buildConfig (needs migration)
25
+ // - From '@payloadcms/figma': look for buildFigmaConfig (already migrated)
26
+ const expectedFunctionName = moduleSpecifier === 'payload' ? 'buildConfig' : 'buildFigmaConfig';
27
+ const buildConfigImport = namedImports.find((ni)=>ni.getName() === expectedFunctionName);
25
28
  if (!buildConfigImport) {
26
29
  result.hasBuildConfig = false;
27
30
  return result;
28
31
  }
29
32
  // Check for alias and get the actual name used in code
30
33
  const aliasNode = buildConfigImport.getAliasNode();
31
- const buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig';
34
+ const buildConfigName = aliasNode ? aliasNode.getText() : expectedFunctionName;
32
35
  if (aliasNode) {
33
36
  result.hasAlias = true;
34
37
  }
@@ -109,6 +112,15 @@ import * as log from './log.js';
109
112
  }
110
113
  }
111
114
  }
115
+ // Check for sharp property
116
+ const sharpProperty = configArg.getProperty('sharp');
117
+ if (sharpProperty) {
118
+ // Find the import source for sharp
119
+ const sharpImport = imports.find((imp)=>imp.getModuleSpecifierValue() === 'sharp' || imp.getNamedImports().some((ni)=>ni.getName() === 'sharp'));
120
+ result.sharpProperty = {
121
+ importSource: sharpImport?.getModuleSpecifierValue() || 'sharp'
122
+ };
123
+ }
112
124
  // Check for figma property
113
125
  const figmaProperty = configArg.getProperty('figma');
114
126
  if (figmaProperty) {
@@ -240,7 +252,16 @@ import * as log from './log.js';
240
252
  modified = true;
241
253
  }
242
254
  }
243
- // 4. Update buildConfig import
255
+ // 4. Remove sharp property
256
+ if (detection.sharpProperty) {
257
+ const sharpProperty = configArg.getProperty('sharp');
258
+ if (sharpProperty) {
259
+ sharpProperty.remove();
260
+ changes.push('Removed sharp property');
261
+ modified = true;
262
+ }
263
+ }
264
+ // 5. Update buildConfig import
244
265
  if (detection.needsImportChange) {
245
266
  if (payloadImport) {
246
267
  if (detection.hasOtherPayloadImports) {
@@ -258,19 +279,31 @@ import * as log from './log.js';
258
279
  sourceFile.addImportDeclaration({
259
280
  moduleSpecifier: '@payloadcms/figma',
260
281
  namedImports: [
261
- 'buildConfig'
282
+ 'buildFigmaConfig'
262
283
  ]
263
284
  });
264
285
  changes.push('Split buildConfig import to @payloadcms/figma');
265
286
  } else {
266
- // Replace entire import
287
+ // Replace entire import: change module specifier and rename all references
288
+ const buildConfigImport = payloadImport.getNamedImports().find((ni)=>ni.getName() === 'buildConfig');
289
+ if (buildConfigImport) {
290
+ // Change the import name
291
+ buildConfigImport.setName('buildFigmaConfig');
292
+ // Find and rename all usages of 'buildConfig' in the file
293
+ const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier);
294
+ identifiers.forEach((identifier)=>{
295
+ if (identifier.getText() === 'buildConfig') {
296
+ identifier.replaceWithText('buildFigmaConfig');
297
+ }
298
+ });
299
+ }
267
300
  payloadImport.setModuleSpecifier('@payloadcms/figma');
268
301
  changes.push('Changed buildConfig import to @payloadcms/figma');
269
302
  }
270
303
  modified = true;
271
304
  }
272
305
  }
273
- // 5. Remove orphaned imports
306
+ // 6. Remove orphaned imports
274
307
  // Re-fetch imports after each removal to avoid stale references
275
308
  if (detection.dbProperty) {
276
309
  const currentImports = sourceFile.getImportDeclarations();
@@ -290,6 +323,15 @@ import * as log from './log.js';
290
323
  modified = true;
291
324
  }
292
325
  }
326
+ if (detection.sharpProperty) {
327
+ const currentImports = sourceFile.getImportDeclarations();
328
+ const sharpImport = currentImports.find((imp)=>imp.getModuleSpecifierValue() === 'sharp');
329
+ if (sharpImport) {
330
+ sharpImport.remove();
331
+ changes.push('Removed sharp import');
332
+ modified = true;
333
+ }
334
+ }
293
335
  return {
294
336
  changes,
295
337
  modified
@@ -301,15 +343,15 @@ import * as log from './log.js';
301
343
  */ export function addFigmaProperty(sourceFile, config) {
302
344
  const changes = [];
303
345
  let modified = false;
304
- // Find buildConfig call
346
+ // Find buildFigmaConfig call (this function is only used with Figma configs)
305
347
  const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
306
348
  const buildConfigCall = callExpressions.find((ce)=>{
307
349
  const expr = ce.getExpression();
308
350
  const text = expr.getText();
309
- return text === 'buildConfig' || text.endsWith('.buildConfig');
351
+ return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig');
310
352
  });
311
353
  if (!buildConfigCall) {
312
- log.debug('No buildConfig call found');
354
+ log.debug('No buildFigmaConfig call found');
313
355
  return {
314
356
  changes: [],
315
357
  modified: false
@@ -336,15 +378,19 @@ import * as log from './log.js';
336
378
  };
337
379
  }
338
380
  // Add figma property
381
+ // Note: useContentSystem is optional and defaults to true, so we don't generate it during init
382
+ // contentSystemId is stored in .env file and referenced via process.env with non-null assertion
383
+ const figmaObj = config.useContentSystem === false ? `{
384
+ contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,
385
+ useContentSystem: false,
386
+ }` : `{
387
+ contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,
388
+ }`;
339
389
  configArg.addPropertyAssignment({
340
390
  name: 'figma',
341
- initializer: `{
342
- region: '${config.region}',
343
- tenantId: '${config.tenantId}',
344
- useContentSystem: ${config.useContentSystem},
345
- }`
391
+ initializer: figmaObj
346
392
  });
347
- changes.push(`Added figma property (region: ${config.region}, tenantId: ${config.tenantId}, useContentSystem: ${config.useContentSystem})`);
393
+ changes.push(`Added figma property (contentSystemId: ${config.contentSystemId})`);
348
394
  modified = true;
349
395
  return {
350
396
  changes,
@@ -355,15 +401,15 @@ import * as log from './log.js';
355
401
  * Read figma configuration from payload.config.ts
356
402
  * Returns the figma object if it exists, null otherwise
357
403
  */ export function readFigmaConfig(sourceFile) {
358
- // Find buildConfig call
404
+ // Find buildFigmaConfig call (this function is only used with Figma configs)
359
405
  const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression);
360
406
  const buildConfigCall = callExpressions.find((ce)=>{
361
407
  const expr = ce.getExpression();
362
408
  const text = expr.getText();
363
- return text === 'buildConfig' || text.endsWith('.buildConfig');
409
+ return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig');
364
410
  });
365
411
  if (!buildConfigCall) {
366
- log.debug('No buildConfig call found');
412
+ log.debug('No buildFigmaConfig call found');
367
413
  return null;
368
414
  }
369
415
  // Get config object argument
@@ -385,25 +431,37 @@ import * as log from './log.js';
385
431
  return null;
386
432
  }
387
433
  // Extract values
388
- const regionProp = initializer.getProperty('region');
389
- const tenantIdProp = initializer.getProperty('tenantId');
434
+ const contentSystemIdProp = initializer.getProperty('contentSystemId');
390
435
  const useContentSystemProp = initializer.getProperty('useContentSystem');
391
- if (!regionProp || !tenantIdProp) {
392
- log.debug('Missing required figma properties (region or tenantId)');
436
+ if (!contentSystemIdProp) {
437
+ log.debug('Missing required figma property: contentSystemId');
393
438
  return null;
394
439
  }
395
- // Extract string values (remove quotes)
396
- const region = Node.isPropertyAssignment(regionProp) ? regionProp.getInitializer()?.getText().replace(/['"]/g, '') : undefined;
397
- const tenantId = Node.isPropertyAssignment(tenantIdProp) ? tenantIdProp.getInitializer()?.getText().replace(/['"]/g, '') : undefined;
398
- const useContentSystem = Node.isPropertyAssignment(useContentSystemProp) ? useContentSystemProp.getInitializer()?.getText() === 'true' : true // Default to true if not specified
440
+ // Extract contentSystemId - support both literal strings and env var references
441
+ let contentSystemId;
442
+ if (Node.isPropertyAssignment(contentSystemIdProp)) {
443
+ const initializer = contentSystemIdProp.getInitializer();
444
+ const text = initializer?.getText() || '';
445
+ // Support both patterns:
446
+ // 1. Literal string: 'cms_abc123' or "cms_abc123"
447
+ // 2. Environment variable: process.env.FIGMA_CONTENT_SYSTEM_ID
448
+ if (text.includes('process.env.FIGMA_CONTENT_SYSTEM_ID')) {
449
+ // For env var reference, return a marker that indicates it's from env
450
+ // The actual value will be read at runtime
451
+ contentSystemId = 'process.env.FIGMA_CONTENT_SYSTEM_ID';
452
+ } else {
453
+ // Remove quotes for literal strings
454
+ contentSystemId = text.replace(/['"]/g, '');
455
+ }
456
+ }
457
+ const useContentSystem = Node.isPropertyAssignment(useContentSystemProp) ? useContentSystemProp.getInitializer()?.getText() === 'true' : undefined // Optional: undefined if not specified
399
458
  ;
400
- if (!region || !tenantId) {
401
- log.debug('Could not extract region or tenantId values');
459
+ if (!contentSystemId) {
460
+ log.debug('Could not extract contentSystemId value');
402
461
  return null;
403
462
  }
404
463
  return {
405
- region,
406
- tenantId,
464
+ contentSystemId,
407
465
  useContentSystem
408
466
  };
409
467
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/payload-config-ast.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph'\n\nimport { Node, SyntaxKind } from 'ts-morph'\n\nimport * as log from './log.js'\n\nexport type DetectionResult = {\n dbProperty?: {\n adapter: string\n importSource: string\n }\n editorProperty?: {\n importSource: string\n isDefault: boolean\n }\n figmaObjectExists: boolean\n hasAlias: boolean\n hasBuildConfig?: boolean\n hasOtherPayloadImports: boolean\n needsImportChange: boolean\n secretProperty?: boolean\n}\n\n/**\n * Detect what changes are needed in the payload config file\n */\nexport function detectRequiredChanges(sourceFile: SourceFile): DetectionResult {\n const result: DetectionResult = {\n figmaObjectExists: false,\n hasAlias: false,\n hasOtherPayloadImports: false,\n needsImportChange: false,\n }\n\n // Find buildConfig import\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'payload' ||\n imp.getModuleSpecifierValue() === '@payloadcms/figma',\n )\n\n if (!payloadImport) {\n log.debug('No payload or @payloadcms/figma import found')\n result.hasBuildConfig = false\n return result\n }\n\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n\n const moduleSpecifier = payloadImport.getModuleSpecifierValue()\n const namedImports = payloadImport.getNamedImports()\n\n // Check if buildConfig is imported\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n\n if (!buildConfigImport) {\n result.hasBuildConfig = false\n return result\n }\n\n // Check for alias and get the actual name used in code\n const aliasNode = buildConfigImport.getAliasNode()\n const buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n if (aliasNode) {\n result.hasAlias = true\n }\n\n // Check if import needs change\n if (moduleSpecifier === 'payload') {\n result.needsImportChange = true\n\n // Check if there are other imports from payload\n if (namedImports.length > 1) {\n result.hasOtherPayloadImports = true\n }\n }\n\n // Find buildConfig call in export default\n // First try to find export default with the buildConfig call\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n // Look for buildConfig call in the export default\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n result.hasBuildConfig = false\n return result\n }\n\n // Get config object\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return result\n }\n\n // Check for db property\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n const dbValue = dbProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (dbValue) {\n const adapterName = dbValue.getExpression().getText()\n\n // Find the import source for this adapter\n const adapterImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === adapterName),\n )\n\n if (adapterImport) {\n result.dbProperty = {\n adapter: adapterName,\n importSource: adapterImport.getModuleSpecifierValue(),\n }\n }\n }\n }\n\n // Check for secret property\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n result.secretProperty = true\n }\n\n // Check for editor property\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n const editorValue = editorProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (editorValue) {\n const editorName = editorValue.getExpression().getText()\n\n // Find the import source\n const editorImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === editorName),\n )\n\n if (editorImport && editorName === 'lexicalEditor') {\n // Check if it has arguments\n const args = editorValue.getArguments()\n const isDefault = args.length === 0\n\n result.editorProperty = {\n importSource: editorImport.getModuleSpecifierValue(),\n isDefault,\n }\n }\n }\n }\n\n // Check for figma property\n const figmaProperty = configArg.getProperty('figma')\n if (figmaProperty) {\n result.figmaObjectExists = true\n }\n\n return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\n}\n\n/**\n * Remove all comments\n * @returns true if any comments were removed\n */\nfunction removeAllComments(sourceFile: SourceFile): boolean {\n const ranges: Array<[number, number]> = []\n\n // Recursively collect comments from node and ALL children (including tokens)\n const collectComments = (node: Node) => {\n node.getLeadingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n node.getTrailingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n\n // Process ALL children including token nodes (commas, braces, etc.)\n node.getChildren().forEach(collectComments)\n }\n\n collectComments(sourceFile)\n\n if (ranges.length === 0) {\n return false\n }\n\n // Remove duplicates and sort in reverse order to avoid position shifts\n const uniqueRanges = Array.from(new Set(ranges.map((r) => JSON.stringify(r)))).map(\n (r) => JSON.parse(r) as [number, number],\n )\n uniqueRanges.sort((a, b) => b[0] - a[0])\n\n // Remove each comment range\n for (const [pos, end] of uniqueRanges) {\n sourceFile.removeText(pos, end)\n }\n\n return true\n}\n\n/**\n * Apply modifications to the source file based on detection result\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function applyModifications(\n sourceFile: SourceFile,\n detection: DetectionResult,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n if (detection.hasBuildConfig === false || detection.hasAlias) {\n log.debug(\n `Skipping modifications: hasBuildConfig=${detection.hasBuildConfig}, hasAlias=${detection.hasAlias}`,\n )\n return { changes: [], modified: false }\n }\n\n // 1. Remove all comments FIRST (before AST modifications that might shift positions)\n const hadComments = removeAllComments(sourceFile)\n if (hadComments) {\n changes.push('Removed comments')\n modified = true\n }\n\n // Find the import declarations\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find((imp) => imp.getModuleSpecifierValue() === 'payload')\n\n // Get the buildConfig name (could be aliased)\n let buildConfigName = 'buildConfig'\n if (payloadImport) {\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n const aliasNode = buildConfigImport.getAliasNode()\n buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n }\n }\n\n // Find buildConfig call in export default (prefer export default)\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n return { changes: [], modified: false }\n }\n\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return { changes: [], modified: false }\n }\n\n // 1. Remove db property\n if (detection.dbProperty) {\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n dbProperty.remove()\n changes.push('Removed db property')\n modified = true\n }\n }\n\n // 2. Remove secret property\n if (detection.secretProperty) {\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n secretProperty.remove()\n changes.push('Removed secret property')\n modified = true\n }\n }\n\n // 3. Remove editor if default\n if (detection.editorProperty?.isDefault) {\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n editorProperty.remove()\n changes.push('Removed default editor property')\n modified = true\n }\n }\n\n // 4. Update buildConfig import\n if (detection.needsImportChange) {\n if (payloadImport) {\n if (detection.hasOtherPayloadImports) {\n // Remove buildConfig from payload import, add new figma import\n const namedImports = payloadImport.getNamedImports()\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n buildConfigImport.remove()\n\n // If payload import is now empty, remove it\n if (payloadImport.getNamedImports().length === 0) {\n payloadImport.remove()\n }\n }\n\n // Add new import at the top\n sourceFile.addImportDeclaration({\n moduleSpecifier: '@payloadcms/figma',\n namedImports: ['buildConfig'],\n })\n\n changes.push('Split buildConfig import to @payloadcms/figma')\n } else {\n // Replace entire import\n payloadImport.setModuleSpecifier('@payloadcms/figma')\n changes.push('Changed buildConfig import to @payloadcms/figma')\n }\n modified = true\n }\n }\n\n // 5. Remove orphaned imports\n // Re-fetch imports after each removal to avoid stale references\n if (detection.dbProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const dbImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.dbProperty?.importSource,\n )\n if (dbImport) {\n dbImport.remove()\n changes.push(`Removed ${detection.dbProperty.adapter} import`)\n modified = true\n }\n }\n\n if (detection.editorProperty?.isDefault) {\n const currentImports = sourceFile.getImportDeclarations()\n const editorImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.editorProperty?.importSource,\n )\n if (editorImport) {\n editorImport.remove()\n changes.push('Removed lexicalEditor import')\n modified = true\n }\n }\n\n return { changes, modified }\n}\n\nexport type FigmaPropertyConfig = {\n region: string\n tenantId: string\n useContentSystem: boolean\n}\n\n/**\n * Add figma property to buildConfig if it doesn't exist\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function addFigmaProperty(\n sourceFile: SourceFile,\n config: FigmaPropertyConfig,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n // Find buildConfig call\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildConfig' || text.endsWith('.buildConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildConfig call found')\n return { changes: [], modified: false }\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return { changes: [], modified: false }\n }\n\n // Check if figma property already exists\n const existingFigmaProperty = configArg.getProperty('figma')\n if (existingFigmaProperty) {\n log.debug('figma property already exists, skipping')\n return { changes: ['Skipped: figma property already exists'], modified: false }\n }\n\n // Add figma property\n configArg.addPropertyAssignment({\n name: 'figma',\n initializer: `{\n region: '${config.region}',\n tenantId: '${config.tenantId}',\n useContentSystem: ${config.useContentSystem},\n }`,\n })\n\n changes.push(\n `Added figma property (region: ${config.region}, tenantId: ${config.tenantId}, useContentSystem: ${config.useContentSystem})`,\n )\n modified = true\n\n return { changes, modified }\n}\n\n/**\n * Read figma configuration from payload.config.ts\n * Returns the figma object if it exists, null otherwise\n */\nexport function readFigmaConfig(sourceFile: SourceFile): FigmaPropertyConfig | null {\n // Find buildConfig call\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildConfig' || text.endsWith('.buildConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildConfig call found')\n return null\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return null\n }\n\n // Find figma property\n const figmaProperty = configArg.getProperty('figma')\n if (!figmaProperty || !Node.isPropertyAssignment(figmaProperty)) {\n log.debug('No figma property found in buildConfig')\n return null\n }\n\n // Get initializer (the object value)\n const initializer = figmaProperty.getInitializer()\n if (!initializer || !Node.isObjectLiteralExpression(initializer)) {\n log.debug('figma property is not an object literal')\n return null\n }\n\n // Extract values\n const regionProp = initializer.getProperty('region')\n const tenantIdProp = initializer.getProperty('tenantId')\n const useContentSystemProp = initializer.getProperty('useContentSystem')\n\n if (!regionProp || !tenantIdProp) {\n log.debug('Missing required figma properties (region or tenantId)')\n return null\n }\n\n // Extract string values (remove quotes)\n const region = Node.isPropertyAssignment(regionProp)\n ? regionProp\n .getInitializer()\n ?.getText()\n .replace(/['\"]/g, '')\n : undefined\n\n const tenantId = Node.isPropertyAssignment(tenantIdProp)\n ? tenantIdProp\n .getInitializer()\n ?.getText()\n .replace(/['\"]/g, '')\n : undefined\n\n const useContentSystem = Node.isPropertyAssignment(useContentSystemProp)\n ? useContentSystemProp.getInitializer()?.getText() === 'true'\n : true // Default to true if not specified\n\n if (!region || !tenantId) {\n log.debug('Could not extract region or tenantId values')\n return null\n }\n\n return {\n region,\n tenantId,\n useContentSystem,\n }\n}\n"],"names":["Node","SyntaxKind","log","detectRequiredChanges","sourceFile","result","figmaObjectExists","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","hasBuildConfig","moduleSpecifier","namedImports","getNamedImports","buildConfigImport","ni","getName","aliasNode","getAliasNode","buildConfigName","getText","length","exportAssignment","getFirstDescendantByKind","ExportAssignment","buildConfigCall","callExpressions","getDescendantsOfKind","CallExpression","ce","expr","getExpression","configArg","getArguments","isObjectLiteralExpression","dbProperty","getProperty","dbValue","getChildrenOfKind","adapterName","adapterImport","some","adapter","importSource","secretProperty","editorProperty","editorValue","editorName","editorImport","args","isDefault","figmaProperty","removeAllComments","ranges","collectComments","node","getLeadingCommentRanges","forEach","range","push","getPos","getEnd","getTrailingCommentRanges","getChildren","uniqueRanges","Array","from","Set","map","r","JSON","stringify","parse","sort","a","b","pos","end","removeText","applyModifications","detection","changes","modified","hadComments","remove","addImportDeclaration","setModuleSpecifier","currentImports","dbImport","addFigmaProperty","config","text","endsWith","existingFigmaProperty","addPropertyAssignment","name","initializer","region","tenantId","useContentSystem","readFigmaConfig","isPropertyAssignment","getInitializer","regionProp","tenantIdProp","useContentSystemProp","replace","undefined"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAE3C,YAAYC,SAAS,WAAU;AAmB/B;;CAEC,GACD,OAAO,SAASC,sBAAsBC,UAAsB;IAC1D,MAAMC,SAA0B;QAC9BC,mBAAmB;QACnBC,UAAU;QACVC,wBAAwB;QACxBC,mBAAmB;IACrB;IAEA,0BAA0B;IAC1B,MAAMC,UAAUN,WAAWO,qBAAqB;IAChD,MAAMC,gBAAgBF,QAAQG,IAAI,CA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,MAAMT,WAAWzG,KAAK4G,oBAAoB,CAACG,gBACvCA,aACGF,cAAc,IACblF,UACDsF,QAAQ,SAAS,MACpBC;IAEJ,MAAMR,mBAAmB1G,KAAK4G,oBAAoB,CAACI,wBAC/CA,qBAAqBH,cAAc,IAAIlF,cAAc,SACrD,KAAK,mCAAmC;;IAE5C,IAAI,CAAC6E,UAAU,CAACC,UAAU;QACxBvG,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACLwF;QACAC;QACAC;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/utils/payload-config-ast.ts"],"sourcesContent":["import type { SourceFile } from 'ts-morph'\n\nimport { Node, SyntaxKind } from 'ts-morph'\n\nimport * as log from './log.js'\n\n/**\n * Result of detecting what changes are needed in a payload config file\n */\nexport type DetectionResult = {\n /** Database adapter configuration if present */\n dbProperty?: {\n /** Name of the adapter function (e.g., 'mongooseAdapter', 'postgresAdapter') */\n adapter: string\n /** NPM package the adapter is imported from (e.g., '@payloadcms/db-mongodb') */\n importSource: string\n }\n /** Editor configuration if present */\n editorProperty?: {\n /** NPM package the editor is imported from (e.g., '@payloadcms/richtext-lexical') */\n importSource: string\n /** Whether this is a default editor with no custom configuration */\n isDefault: boolean\n }\n /** Whether the config already has a `figma` property */\n figmaObjectExists: boolean\n /** Whether buildConfig/buildFigmaConfig uses an import alias (e.g., 'buildConfig as createConfig') */\n hasAlias: boolean\n /** Whether a buildConfig or buildFigmaConfig call was found (undefined if not checked) */\n hasBuildConfig?: boolean\n /** Whether there are other imports from 'payload' besides buildConfig (e.g., types) */\n hasOtherPayloadImports: boolean\n /** Whether the import needs to be changed from 'payload' to '@payloadcms/figma' */\n needsImportChange: boolean\n /** Whether a `secret` property exists in the config */\n secretProperty?: boolean\n /** Sharp configuration if present */\n sharpProperty?: {\n /** NPM package sharp is imported from (always 'sharp') */\n importSource: string\n }\n}\n\n/**\n * Detect what changes are needed in the payload config file\n */\nexport function detectRequiredChanges(sourceFile: SourceFile): DetectionResult {\n const result: DetectionResult = {\n figmaObjectExists: false,\n hasAlias: false,\n hasOtherPayloadImports: false,\n needsImportChange: false,\n }\n\n // Find buildConfig import\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'payload' ||\n imp.getModuleSpecifierValue() === '@payloadcms/figma',\n )\n\n if (!payloadImport) {\n log.debug('No payload or @payloadcms/figma import found')\n result.hasBuildConfig = false\n return result\n }\n\n log.debug(`Found import from: ${payloadImport.getModuleSpecifierValue()}`)\n\n const moduleSpecifier = payloadImport.getModuleSpecifierValue()\n const namedImports = payloadImport.getNamedImports()\n\n // Determine which function name to look for based on the import source\n // - From 'payload': look for buildConfig (needs migration)\n // - From '@payloadcms/figma': look for buildFigmaConfig (already migrated)\n const expectedFunctionName = moduleSpecifier === 'payload' ? 'buildConfig' : 'buildFigmaConfig'\n\n const buildConfigImport = namedImports.find((ni) => ni.getName() === expectedFunctionName)\n\n if (!buildConfigImport) {\n result.hasBuildConfig = false\n return result\n }\n\n // Check for alias and get the actual name used in code\n const aliasNode = buildConfigImport.getAliasNode()\n const buildConfigName = aliasNode ? aliasNode.getText() : expectedFunctionName\n if (aliasNode) {\n result.hasAlias = true\n }\n\n // Check if import needs change\n if (moduleSpecifier === 'payload') {\n result.needsImportChange = true\n\n // Check if there are other imports from payload\n if (namedImports.length > 1) {\n result.hasOtherPayloadImports = true\n }\n }\n\n // Find buildConfig call in export default\n // First try to find export default with the buildConfig call\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n // Look for buildConfig call in the export default\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n result.hasBuildConfig = false\n return result\n }\n\n // Get config object\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return result\n }\n\n // Check for db property\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n const dbValue = dbProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (dbValue) {\n const adapterName = dbValue.getExpression().getText()\n\n // Find the import source for this adapter\n const adapterImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === adapterName),\n )\n\n if (adapterImport) {\n result.dbProperty = {\n adapter: adapterName,\n importSource: adapterImport.getModuleSpecifierValue(),\n }\n }\n }\n }\n\n // Check for secret property\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n result.secretProperty = true\n }\n\n // Check for editor property\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n const editorValue = editorProperty.getChildrenOfKind(SyntaxKind.CallExpression)[0]\n if (editorValue) {\n const editorName = editorValue.getExpression().getText()\n\n // Find the import source\n const editorImport = imports.find((imp) =>\n imp.getNamedImports().some((ni) => ni.getName() === editorName),\n )\n\n if (editorImport && editorName === 'lexicalEditor') {\n // Check if it has arguments\n const args = editorValue.getArguments()\n const isDefault = args.length === 0\n\n result.editorProperty = {\n importSource: editorImport.getModuleSpecifierValue(),\n isDefault,\n }\n }\n }\n }\n\n // Check for sharp property\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n // Find the import source for sharp\n const sharpImport = imports.find(\n (imp) =>\n imp.getModuleSpecifierValue() === 'sharp' ||\n imp.getNamedImports().some((ni) => ni.getName() === 'sharp'),\n )\n\n result.sharpProperty = {\n importSource: sharpImport?.getModuleSpecifierValue() || 'sharp',\n }\n }\n\n // Check for figma property\n const figmaProperty = configArg.getProperty('figma')\n if (figmaProperty) {\n result.figmaObjectExists = true\n }\n\n return result\n}\n\nexport type ASTModificationResult = {\n changes: string[]\n modified: boolean\n}\n\n/**\n * Remove all comments\n * @returns true if any comments were removed\n */\nfunction removeAllComments(sourceFile: SourceFile): boolean {\n const ranges: Array<[number, number]> = []\n\n // Recursively collect comments from node and ALL children (including tokens)\n const collectComments = (node: Node) => {\n node.getLeadingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n node.getTrailingCommentRanges().forEach((range) => {\n ranges.push([range.getPos(), range.getEnd()])\n })\n\n // Process ALL children including token nodes (commas, braces, etc.)\n node.getChildren().forEach(collectComments)\n }\n\n collectComments(sourceFile)\n\n if (ranges.length === 0) {\n return false\n }\n\n // Remove duplicates and sort in reverse order to avoid position shifts\n const uniqueRanges = Array.from(new Set(ranges.map((r) => JSON.stringify(r)))).map(\n (r) => JSON.parse(r) as [number, number],\n )\n uniqueRanges.sort((a, b) => b[0] - a[0])\n\n // Remove each comment range\n for (const [pos, end] of uniqueRanges) {\n sourceFile.removeText(pos, end)\n }\n\n return true\n}\n\n/**\n * Apply modifications to the source file based on detection result\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function applyModifications(\n sourceFile: SourceFile,\n detection: DetectionResult,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n if (detection.hasBuildConfig === false || detection.hasAlias) {\n log.debug(\n `Skipping modifications: hasBuildConfig=${detection.hasBuildConfig}, hasAlias=${detection.hasAlias}`,\n )\n return { changes: [], modified: false }\n }\n\n // 1. Remove all comments FIRST (before AST modifications that might shift positions)\n const hadComments = removeAllComments(sourceFile)\n if (hadComments) {\n changes.push('Removed comments')\n modified = true\n }\n\n // Find the import declarations\n const imports = sourceFile.getImportDeclarations()\n const payloadImport = imports.find((imp) => imp.getModuleSpecifierValue() === 'payload')\n\n // Get the buildConfig name (could be aliased)\n let buildConfigName = 'buildConfig'\n if (payloadImport) {\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n const aliasNode = buildConfigImport.getAliasNode()\n buildConfigName = aliasNode ? aliasNode.getText() : 'buildConfig'\n }\n }\n\n // Find buildConfig call in export default (prefer export default)\n const exportAssignment = sourceFile.getFirstDescendantByKind(SyntaxKind.ExportAssignment)\n let buildConfigCall = null\n\n if (exportAssignment) {\n const callExpressions = exportAssignment.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n // If not found in export default, search all call expressions\n if (!buildConfigCall) {\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n return expr.getText() === buildConfigName\n })\n }\n\n if (!buildConfigCall) {\n return { changes: [], modified: false }\n }\n\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n return { changes: [], modified: false }\n }\n\n // 1. Remove db property\n if (detection.dbProperty) {\n const dbProperty = configArg.getProperty('db')\n if (dbProperty) {\n dbProperty.remove()\n changes.push('Removed db property')\n modified = true\n }\n }\n\n // 2. Remove secret property\n if (detection.secretProperty) {\n const secretProperty = configArg.getProperty('secret')\n if (secretProperty) {\n secretProperty.remove()\n changes.push('Removed secret property')\n modified = true\n }\n }\n\n // 3. Remove editor if default\n if (detection.editorProperty?.isDefault) {\n const editorProperty = configArg.getProperty('editor')\n if (editorProperty) {\n editorProperty.remove()\n changes.push('Removed default editor property')\n modified = true\n }\n }\n\n // 4. Remove sharp property\n if (detection.sharpProperty) {\n const sharpProperty = configArg.getProperty('sharp')\n if (sharpProperty) {\n sharpProperty.remove()\n changes.push('Removed sharp property')\n modified = true\n }\n }\n\n // 5. Update buildConfig import\n if (detection.needsImportChange) {\n if (payloadImport) {\n if (detection.hasOtherPayloadImports) {\n // Remove buildConfig from payload import, add new figma import\n const namedImports = payloadImport.getNamedImports()\n const buildConfigImport = namedImports.find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n buildConfigImport.remove()\n\n // If payload import is now empty, remove it\n if (payloadImport.getNamedImports().length === 0) {\n payloadImport.remove()\n }\n }\n\n // Add new import at the top\n sourceFile.addImportDeclaration({\n moduleSpecifier: '@payloadcms/figma',\n namedImports: ['buildFigmaConfig'],\n })\n\n changes.push('Split buildConfig import to @payloadcms/figma')\n } else {\n // Replace entire import: change module specifier and rename all references\n const buildConfigImport = payloadImport\n .getNamedImports()\n .find((ni) => ni.getName() === 'buildConfig')\n if (buildConfigImport) {\n // Change the import name\n buildConfigImport.setName('buildFigmaConfig')\n\n // Find and rename all usages of 'buildConfig' in the file\n const identifiers = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)\n identifiers.forEach((identifier) => {\n if (identifier.getText() === 'buildConfig') {\n identifier.replaceWithText('buildFigmaConfig')\n }\n })\n }\n payloadImport.setModuleSpecifier('@payloadcms/figma')\n changes.push('Changed buildConfig import to @payloadcms/figma')\n }\n modified = true\n }\n }\n\n // 6. Remove orphaned imports\n // Re-fetch imports after each removal to avoid stale references\n if (detection.dbProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const dbImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.dbProperty?.importSource,\n )\n if (dbImport) {\n dbImport.remove()\n changes.push(`Removed ${detection.dbProperty.adapter} import`)\n modified = true\n }\n }\n\n if (detection.editorProperty?.isDefault) {\n const currentImports = sourceFile.getImportDeclarations()\n const editorImport = currentImports.find(\n (imp) => imp.getModuleSpecifierValue() === detection.editorProperty?.importSource,\n )\n if (editorImport) {\n editorImport.remove()\n changes.push('Removed lexicalEditor import')\n modified = true\n }\n }\n\n if (detection.sharpProperty) {\n const currentImports = sourceFile.getImportDeclarations()\n const sharpImport = currentImports.find((imp) => imp.getModuleSpecifierValue() === 'sharp')\n if (sharpImport) {\n sharpImport.remove()\n changes.push('Removed sharp import')\n modified = true\n }\n }\n\n return { changes, modified }\n}\n\nexport type FigmaPropertyConfig = {\n contentSystemId: string\n useContentSystem?: boolean\n}\n\n/**\n * Add figma property to buildConfig if it doesn't exist\n * Modifies the AST in memory - caller must call sourceFile.save()\n */\nexport function addFigmaProperty(\n sourceFile: SourceFile,\n config: FigmaPropertyConfig,\n): ASTModificationResult {\n const changes: string[] = []\n let modified = false\n\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return { changes: [], modified: false }\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return { changes: [], modified: false }\n }\n\n // Check if figma property already exists\n const existingFigmaProperty = configArg.getProperty('figma')\n if (existingFigmaProperty) {\n log.debug('figma property already exists, skipping')\n return { changes: ['Skipped: figma property already exists'], modified: false }\n }\n\n // Add figma property\n // Note: useContentSystem is optional and defaults to true, so we don't generate it during init\n // contentSystemId is stored in .env file and referenced via process.env with non-null assertion\n const figmaObj =\n config.useContentSystem === false\n ? `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n useContentSystem: false,\n }`\n : `{\n contentSystemId: process.env.FIGMA_CONTENT_SYSTEM_ID!,\n }`\n\n configArg.addPropertyAssignment({\n name: 'figma',\n initializer: figmaObj,\n })\n\n changes.push(`Added figma property (contentSystemId: ${config.contentSystemId})`)\n modified = true\n\n return { changes, modified }\n}\n\n/**\n * Read figma configuration from payload.config.ts\n * Returns the figma object if it exists, null otherwise\n */\nexport function readFigmaConfig(sourceFile: SourceFile): FigmaPropertyConfig | null {\n // Find buildFigmaConfig call (this function is only used with Figma configs)\n const callExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression)\n const buildConfigCall = callExpressions.find((ce) => {\n const expr = ce.getExpression()\n const text = expr.getText()\n return text === 'buildFigmaConfig' || text.endsWith('.buildFigmaConfig')\n })\n\n if (!buildConfigCall) {\n log.debug('No buildFigmaConfig call found')\n return null\n }\n\n // Get config object argument\n const configArg = buildConfigCall.getArguments()[0]\n if (!configArg || !Node.isObjectLiteralExpression(configArg)) {\n log.debug('buildConfig argument is not an object literal')\n return null\n }\n\n // Find figma property\n const figmaProperty = configArg.getProperty('figma')\n if (!figmaProperty || !Node.isPropertyAssignment(figmaProperty)) {\n log.debug('No figma property found in buildConfig')\n return null\n }\n\n // Get initializer (the object value)\n const initializer = figmaProperty.getInitializer()\n if (!initializer || !Node.isObjectLiteralExpression(initializer)) {\n log.debug('figma property is not an object literal')\n return null\n }\n\n // Extract values\n const contentSystemIdProp = initializer.getProperty('contentSystemId')\n const useContentSystemProp = initializer.getProperty('useContentSystem')\n\n if (!contentSystemIdProp) {\n log.debug('Missing required figma property: contentSystemId')\n return null\n }\n\n // Extract contentSystemId - support both literal strings and env var references\n let contentSystemId: string | undefined\n if (Node.isPropertyAssignment(contentSystemIdProp)) {\n const initializer = contentSystemIdProp.getInitializer()\n const text = initializer?.getText() || ''\n\n // Support both patterns:\n // 1. Literal string: 'cms_abc123' or \"cms_abc123\"\n // 2. Environment variable: process.env.FIGMA_CONTENT_SYSTEM_ID\n if (text.includes('process.env.FIGMA_CONTENT_SYSTEM_ID')) {\n // For env var reference, return a marker that indicates it's from env\n // The actual value will be read at runtime\n contentSystemId = 'process.env.FIGMA_CONTENT_SYSTEM_ID'\n } else {\n // Remove quotes for literal strings\n contentSystemId = text.replace(/['\"]/g, '')\n }\n }\n\n const useContentSystem = Node.isPropertyAssignment(useContentSystemProp)\n ? useContentSystemProp.getInitializer()?.getText() === 'true'\n : undefined // Optional: undefined if not specified\n\n if (!contentSystemId) {\n log.debug('Could not extract contentSystemId value')\n return null\n }\n\n return {\n contentSystemId,\n useContentSystem,\n }\n}\n"],"names":["Node","SyntaxKind","log","detectRequiredChanges","sourceFile","result","figmaObjectExists","hasAlias","hasOtherPayloadImports","needsImportChange","imports","getImportDeclarations","payloadImport","find","imp","getModuleSpecifierValue","debug","hasBuildConfig","moduleSpecifier","namedImports","getNamedImports","expectedFunctionName","buildConfigImport","ni","getName","aliasNode","getAliasNode","buildConfigName","getText","length","exportAssignment","getFirstDescendantByKind","ExportAssignment","buildConfigCall","callExpressions","getDescendantsOfKind","CallExpression","ce","expr","getExpression","configArg","getArguments","isObjectLiteralExpression","dbProperty","getProperty","dbValue","getChildrenOfKind","adapterName","adapterImport","some","adapter","importSource","secretProperty","editorProperty","editorValue","editorName","editorImport","args","isDefault","sharpProperty","sharpImport","figmaProperty","removeAllComments","ranges","collectComments","node","getLeadingCommentRanges","forEach","range","push","getPos","getEnd","getTrailingCommentRanges","getChildren","uniqueRanges","Array","from","Set","map","r","JSON","stringify","parse","sort","a","b","pos","end","removeText","applyModifications","detection","changes","modified","hadComments","remove","addImportDeclaration","setName","identifiers","Identifier","identifier","replaceWithText","setModuleSpecifier","currentImports","dbImport","addFigmaProperty","config","text","endsWith","existingFigmaProperty","figmaObj","useContentSystem","addPropertyAssignment","name","initializer","contentSystemId","readFigmaConfig","isPropertyAssignment","getInitializer","contentSystemIdProp","useContentSystemProp","includes","replace","undefined"],"mappings":"AAEA,SAASA,IAAI,EAAEC,UAAU,QAAQ,WAAU;AAE3C,YAAYC,SAAS,WAAU;AAuC/B;;CAEC,GACD,OAAO,SAASC,sBAAsBC,UAAsB;IAC1D,MAAMC,SAA0B;QAC9BC,mBAAmB;QACnBC,UAAU;QACVC,wBAAwB;QACxBC,mBAAmB;IACrB;IAEA,0BAA0B;IAC1B,MAAMC,UAAUN,WAAWO,qBAAqB;IAChD,MAAMC,gBAAgBF,QAAQG,IAAI,CAChC,CAACC,MACCA,IAAIC,uBAAuB,OAAO,aAClCD,IAAIC,uBAAuB,OAAO;IAGtC,IAAI,CAACH,eA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C1C;IACF;IAEA,MAAMX,mBAAmB9G,KAAKoH,oBAAoB,CAACG,wBAC/CA,qBAAqBF,cAAc,IAAIzF,cAAc,SACrD8F,UAAU,uCAAuC;;IAErD,IAAI,CAACR,iBAAiB;QACpBhH,IAAIc,KAAK,CAAC;QACV,OAAO;IACT;IAEA,OAAO;QACLkG;QACAJ;IACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Find the Payload config file using Payload's built-in finder
3
- * Changes to project directory temporarily and restores afterward
2
+ * Find the Payload config file using Payload's built-in finder when available,
3
+ * with fallback to simple file search for npx environments where payload isn't installed.
4
4
  *
5
5
  * @param projectPath - Absolute path to project directory
6
6
  * @returns Absolute path to config file, or null if not found
@@ -1 +1 @@
1
- {"version":3,"file":"payload-config-finder.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-finder.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAmBnF"}
1
+ {"version":3,"file":"payload-config-finder.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-finder.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,CAWnF"}
@@ -1,26 +1,65 @@
1
- import { findConfig } from 'payload/node';
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import * as log from './log.js';
4
+ // Standard Payload config file names in priority order
5
+ const CONFIG_FILES = [
6
+ 'payload.config.ts',
7
+ 'payload.config.js',
8
+ 'src/payload.config.ts',
9
+ 'src/payload.config.js'
10
+ ];
2
11
  /**
3
- * Find the Payload config file using Payload's built-in finder
4
- * Changes to project directory temporarily and restores afterward
12
+ * Find the Payload config file using Payload's built-in finder when available,
13
+ * with fallback to simple file search for npx environments where payload isn't installed.
5
14
  *
6
15
  * @param projectPath - Absolute path to project directory
7
16
  * @returns Absolute path to config file, or null if not found
8
17
  */ export async function findPayloadConfig(projectPath) {
18
+ // First, try using Payload's official config finder (if payload is installed)
19
+ const configFromPayload = await findConfigWithPayload(projectPath);
20
+ if (configFromPayload) {
21
+ return configFromPayload;
22
+ }
23
+ // Fallback: Simple file search for standard config locations
24
+ // This works when running via npx before payload is installed
25
+ log.debug('Payload not available, using fallback config finder');
26
+ return findConfigFallback(projectPath);
27
+ }
28
+ /**
29
+ * Try to find config using Payload's findConfig function.
30
+ * Returns null if payload is not installed (dynamic import fails).
31
+ */ async function findConfigWithPayload(projectPath) {
9
32
  const originalCwd = process.cwd();
10
33
  try {
34
+ // Dynamic import - will fail gracefully if payload is not installed
35
+ const { findConfig } = await import('payload/node');
11
36
  // findConfig requires being in the project directory
12
37
  process.chdir(projectPath);
13
- // Use Payload's official config finder
14
38
  const configPath = findConfig();
15
- // Wrap in Promise.resolve to satisfy async requirement
16
- return await Promise.resolve(configPath || null);
17
- } catch {
18
- // Config not found or error occurred
39
+ return configPath || null;
40
+ } catch (error) {
41
+ // payload not installed or other error - return null to use fallback
42
+ log.debug(`Could not use Payload findConfig: ${error instanceof Error ? error.message : 'unknown'}`);
19
43
  return null;
20
44
  } finally{
21
- // Always restore original working directory
22
45
  process.chdir(originalCwd);
23
46
  }
24
47
  }
48
+ /**
49
+ * Fallback config finder that checks standard locations.
50
+ * Used when payload is not installed (e.g., running via npx).
51
+ */ async function findConfigFallback(projectPath) {
52
+ for (const configFile of CONFIG_FILES){
53
+ const fullPath = path.join(projectPath, configFile);
54
+ try {
55
+ await fs.access(fullPath);
56
+ log.debug(`Found config at: ${fullPath}`);
57
+ return fullPath;
58
+ } catch {
59
+ // File doesn't exist, try next
60
+ }
61
+ }
62
+ return null;
63
+ }
25
64
 
26
65
  //# sourceMappingURL=payload-config-finder.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/payload-config-finder.ts"],"sourcesContent":["import { findConfig } from 'payload/node'\n\n/**\n * Find the Payload config file using Payload's built-in finder\n * Changes to project directory temporarily and restores afterward\n *\n * @param projectPath - Absolute path to project directory\n * @returns Absolute path to config file, or null if not found\n */\nexport async function findPayloadConfig(projectPath: string): Promise<null | string> {\n const originalCwd = process.cwd()\n\n try {\n // findConfig requires being in the project directory\n process.chdir(projectPath)\n\n // Use Payload's official config finder\n const configPath = findConfig()\n\n // Wrap in Promise.resolve to satisfy async requirement\n return await Promise.resolve(configPath || null)\n } catch {\n // Config not found or error occurred\n return null\n } finally {\n // Always restore original working directory\n process.chdir(originalCwd)\n }\n}\n"],"names":["findConfig","findPayloadConfig","projectPath","originalCwd","process","cwd","chdir","configPath","Promise","resolve"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAc;AAEzC;;;;;;CAMC,GACD,OAAO,eAAeC,kBAAkBC,WAAmB;IACzD,MAAMC,cAAcC,QAAQC,GAAG;IAE/B,IAAI;QACF,qDAAqD;QACrDD,QAAQE,KAAK,CAACJ;QAEd,uCAAuC;QACvC,MAAMK,aAAaP;QAEnB,uDAAuD;QACvD,OAAO,MAAMQ,QAAQC,OAAO,CAACF,cAAc;IAC7C,EAAE,OAAM;QACN,qCAAqC;QACrC,OAAO;IACT,SAAU;QACR,4CAA4C;QAC5CH,QAAQE,KAAK,CAACH;IAChB;AACF"}
1
+ {"version":3,"sources":["../../src/utils/payload-config-finder.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\nimport * as log from './log.js'\n\n// Standard Payload config file names in priority order\nconst CONFIG_FILES = [\n 'payload.config.ts',\n 'payload.config.js',\n 'src/payload.config.ts',\n 'src/payload.config.js',\n]\n\n/**\n * Find the Payload config file using Payload's built-in finder when available,\n * with fallback to simple file search for npx environments where payload isn't installed.\n *\n * @param projectPath - Absolute path to project directory\n * @returns Absolute path to config file, or null if not found\n */\nexport async function findPayloadConfig(projectPath: string): Promise<null | string> {\n // First, try using Payload's official config finder (if payload is installed)\n const configFromPayload = await findConfigWithPayload(projectPath)\n if (configFromPayload) {\n return configFromPayload\n }\n\n // Fallback: Simple file search for standard config locations\n // This works when running via npx before payload is installed\n log.debug('Payload not available, using fallback config finder')\n return findConfigFallback(projectPath)\n}\n\n/**\n * Try to find config using Payload's findConfig function.\n * Returns null if payload is not installed (dynamic import fails).\n */\nasync function findConfigWithPayload(projectPath: string): Promise<null | string> {\n const originalCwd = process.cwd()\n\n try {\n // Dynamic import - will fail gracefully if payload is not installed\n const { findConfig } = await import('payload/node')\n\n // findConfig requires being in the project directory\n process.chdir(projectPath)\n const configPath = findConfig()\n return configPath || null\n } catch (error) {\n // payload not installed or other error - return null to use fallback\n log.debug(\n `Could not use Payload findConfig: ${error instanceof Error ? error.message : 'unknown'}`,\n )\n return null\n } finally {\n process.chdir(originalCwd)\n }\n}\n\n/**\n * Fallback config finder that checks standard locations.\n * Used when payload is not installed (e.g., running via npx).\n */\nasync function findConfigFallback(projectPath: string): Promise<null | string> {\n for (const configFile of CONFIG_FILES) {\n const fullPath = path.join(projectPath, configFile)\n try {\n await fs.access(fullPath)\n log.debug(`Found config at: ${fullPath}`)\n return fullPath\n } catch {\n // File doesn't exist, try next\n }\n }\n\n return null\n}\n"],"names":["fs","path","log","CONFIG_FILES","findPayloadConfig","projectPath","configFromPayload","findConfigWithPayload","debug","findConfigFallback","originalCwd","process","cwd","findConfig","chdir","configPath","error","Error","message","configFile","fullPath","join","access"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB,YAAYC,SAAS,WAAU;AAE/B,uDAAuD;AACvD,MAAMC,eAAe;IACnB;IACA;IACA;IACA;CACD;AAED;;;;;;CAMC,GACD,OAAO,eAAeC,kBAAkBC,WAAmB;IACzD,8EAA8E;IAC9E,MAAMC,oBAAoB,MAAMC,sBAAsBF;IACtD,IAAIC,mBAAmB;QACrB,OAAOA;IACT;IAEA,6DAA6D;IAC7D,8DAA8D;IAC9DJ,IAAIM,KAAK,CAAC;IACV,OAAOC,mBAAmBJ;AAC5B;AAEA;;;CAGC,GACD,eAAeE,sBAAsBF,WAAmB;IACtD,MAAMK,cAAcC,QAAQC,GAAG;IAE/B,IAAI;QACF,oEAAoE;QACpE,MAAM,EAAEC,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC;QAEpC,qDAAqD;QACrDF,QAAQG,KAAK,CAACT;QACd,MAAMU,aAAaF;QACnB,OAAOE,cAAc;IACvB,EAAE,OAAOC,OAAO;QACd,qEAAqE;QACrEd,IAAIM,KAAK,CACP,CAAC,kCAAkC,EAAEQ,iBAAiBC,QAAQD,MAAME,OAAO,GAAG,WAAW;QAE3F,OAAO;IACT,SAAU;QACRP,QAAQG,KAAK,CAACJ;IAChB;AACF;AAEA;;;CAGC,GACD,eAAeD,mBAAmBJ,WAAmB;IACnD,KAAK,MAAMc,cAAchB,aAAc;QACrC,MAAMiB,WAAWnB,KAAKoB,IAAI,CAAChB,aAAac;QACxC,IAAI;YACF,MAAMnB,GAAGsB,MAAM,CAACF;YAChBlB,IAAIM,KAAK,CAAC,CAAC,iBAAiB,EAAEY,UAAU;YACxC,OAAOA;QACT,EAAE,OAAM;QACN,+BAA+B;QACjC;IACF;IAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;AAKhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,mBAAmB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAqL7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwC9D"}
1
+ {"version":3,"file":"payload-config-modifier.d.ts","sourceRoot":"","sources":["../../src/utils/payload-config-modifier.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAI1D,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAA;AAUhC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,EAAE,mBAAmB,GAChC,OAAO,CAAC,kBAAkB,CAAC,CAkQ7B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAwC9D"}
@@ -4,7 +4,7 @@ import { formatFile } from './formatter.js';
4
4
  import * as log from './log.js';
5
5
  import { addFigmaProperty, applyModifications, detectRequiredChanges } from './payload-config-ast.js';
6
6
  import { findPayloadConfig } from './payload-config-finder.js';
7
- import { checkPackageInstalled, installPackage, uninstallPackage } from './payload-package-check.js';
7
+ import { checkPackageInstalled, getPayloadVersion, installPackage, uninstallPackage } from './payload-package-check.js';
8
8
  import { runTypeScriptCheck } from './typescript-validator.js';
9
9
  /**
10
10
  * Main orchestrator for payload config modification
@@ -27,6 +27,9 @@ import { runTypeScriptCheck } from './typescript-validator.js';
27
27
  };
28
28
  }
29
29
  log.debug(`Found config file: ${configPath}`);
30
+ // Get payload version to pin @payloadcms/* dependencies
31
+ const payloadVersion = await getPayloadVersion(projectPath);
32
+ log.debug(`Detected payload version: ${payloadVersion || 'unknown'}`);
30
33
  // 2. Check/install @payloadcms/figma package
31
34
  const isInstalled = await checkPackageInstalled(projectPath, '@payloadcms/figma');
32
35
  if (!isInstalled) {
@@ -103,13 +106,58 @@ import { runTypeScriptCheck } from './typescript-validator.js';
103
106
  if (modified) {
104
107
  await sourceFile.save();
105
108
  log.debug('Config file saved');
106
- // 7. Uninstall orphaned packages
109
+ // 7. Handle package management
107
110
  const packagesToUninstall = [];
111
+ // Uninstall db adapter (buildFigmaConfig provides its own)
108
112
  if (detection.dbProperty) {
109
113
  packagesToUninstall.push(detection.dbProperty.importSource);
110
114
  }
111
- if (detection.editorProperty?.isDefault) {
112
- packagesToUninstall.push(detection.editorProperty.importSource);
115
+ // Uninstall sharp (Figma infrastructure handles image processing)
116
+ if (detection.sharpProperty) {
117
+ packagesToUninstall.push('sharp');
118
+ }
119
+ // Ensure lexical is installed if user doesn't have a custom editor
120
+ // (buildFigmaConfig uses lexicalEditor() as default)
121
+ if (!detection.editorProperty) {
122
+ log.debug('No editor property detected - will ensure lexical is installed for default editor');
123
+ } else if (detection.editorProperty.isDefault) {
124
+ log.debug('Default lexicalEditor() detected - will ensure lexical is installed');
125
+ } else {
126
+ log.debug(`Custom editor detected (${detection.editorProperty.importSource}) - skipping lexical installation`);
127
+ }
128
+ if (!detection.editorProperty || detection.editorProperty.isDefault) {
129
+ log.debug('Checking if @payloadcms/richtext-lexical is installed...');
130
+ const hasLexical = await checkPackageInstalled(projectPath, '@payloadcms/richtext-lexical');
131
+ if (!hasLexical) {
132
+ log.debug('@payloadcms/richtext-lexical not found, installing...');
133
+ try {
134
+ await installPackage(projectPath, '@payloadcms/richtext-lexical', packageManager, payloadVersion);
135
+ changes.push('Installed @payloadcms/richtext-lexical (default editor)');
136
+ log.debug('Successfully installed @payloadcms/richtext-lexical');
137
+ } catch (error) {
138
+ log.debug(`Failed to install @payloadcms/richtext-lexical: ${error instanceof Error ? error.message : 'Unknown error'}`);
139
+ // Don't fail on install error - user can install manually if needed
140
+ warnings.push('Could not install @payloadcms/richtext-lexical - you may need to install it manually');
141
+ }
142
+ } else {
143
+ log.debug('@payloadcms/richtext-lexical already installed, skipping');
144
+ }
145
+ }
146
+ // Ensure cloud-storage is installed (required peer dependency for buildFigmaConfig)
147
+ log.debug('Checking if @payloadcms/plugin-cloud-storage is installed...');
148
+ const hasCloudStorage = await checkPackageInstalled(projectPath, '@payloadcms/plugin-cloud-storage');
149
+ if (!hasCloudStorage) {
150
+ log.debug('@payloadcms/plugin-cloud-storage not found, installing...');
151
+ try {
152
+ await installPackage(projectPath, '@payloadcms/plugin-cloud-storage', packageManager, payloadVersion);
153
+ changes.push('Installed @payloadcms/plugin-cloud-storage');
154
+ log.debug('Successfully installed @payloadcms/plugin-cloud-storage');
155
+ } catch (error) {
156
+ log.debug(`Failed to install @payloadcms/plugin-cloud-storage: ${error instanceof Error ? error.message : 'Unknown error'}`);
157
+ warnings.push('Could not install @payloadcms/plugin-cloud-storage - you may need to install it manually');
158
+ }
159
+ } else {
160
+ log.debug('@payloadcms/plugin-cloud-storage already installed, skipping');
113
161
  }
114
162
  if (packagesToUninstall.length > 0) {
115
163
  log.debug(`Uninstalling ${packagesToUninstall.length} orphaned packages...`);
@@ -166,7 +214,7 @@ import { runTypeScriptCheck } from './typescript-validator.js';
166
214
  */ export function displayManualInstructions(reason) {
167
215
  const leftLineWrap = (message)=>{
168
216
  // Add '┌ ' prefix to first line, '│ ' to subsequent lines, and '└ ' to last line
169
- return message.split('\n').map((line, index, arr)=>{
217
+ return message.split(/\r?\n/).map((line, index, arr)=>{
170
218
  if (index === 0) {
171
219
  return `${pc.dim('┌ ')}${line}`;
172
220
  } else if (index === arr.length - 1) {
@@ -185,7 +233,7 @@ ${pc.bold('Required changes:')}
185
233
 
186
234
  1. Replace buildConfig import:
187
235
  ${pc.dim('- FROM: ')}${pc.cyan("import { buildConfig } from 'payload'")}
188
- ${pc.dim('- TO: ')}${pc.cyan("import { buildConfig } from '@payloadcms/figma'")}
236
+ ${pc.dim('- TO: ')}${pc.cyan("import { buildFigmaConfig } from '@payloadcms/figma'")}
189
237
 
190
238
  2. Remove these properties from buildConfig():
191
239
  • db