@aws/nx-plugin 1.0.0-rc.53 → 1.0.0-rc.55

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 (271) hide show
  1. package/migrations.json +50 -0
  2. package/package.json +1 -1
  3. package/src/agentcore-gateway/gateway-connection/generator.js +3 -1
  4. package/src/agentcore-gateway/gateway-connection/generator.js.map +1 -1
  5. package/src/agentcore-gateway/generator.d.ts +49 -1
  6. package/src/agentcore-gateway/generator.js +55 -22
  7. package/src/agentcore-gateway/generator.js.map +1 -1
  8. package/src/agentcore-gateway/mcp-connection/generator.js +3 -1
  9. package/src/agentcore-gateway/mcp-connection/generator.js.map +1 -1
  10. package/src/infra/app/__snapshots__/generator.spec.ts.snap +2 -0
  11. package/src/infra/app/generator.d.ts +43 -0
  12. package/src/infra/app/generator.js +47 -18
  13. package/src/infra/app/generator.js.map +1 -1
  14. package/src/init/generator.d.ts +13 -0
  15. package/src/init/generator.js +14 -3
  16. package/src/init/generator.js.map +1 -1
  17. package/src/migrations/latest/backfill-generator-metadata/migration.d.ts +96 -0
  18. package/src/migrations/latest/backfill-generator-metadata/migration.js +670 -0
  19. package/src/migrations/latest/backfill-generator-metadata/migration.js.map +1 -0
  20. package/src/migrations/latest/order-access-log-delivery-after-bucket-policy/migration.d.ts +6 -0
  21. package/src/migrations/latest/order-access-log-delivery-after-bucket-policy/migration.js +94 -0
  22. package/src/migrations/latest/order-access-log-delivery-after-bucket-policy/migration.js.map +1 -0
  23. package/src/preset/generator.d.ts +13 -0
  24. package/src/preset/generator.js +12 -3
  25. package/src/preset/generator.js.map +1 -1
  26. package/src/py/agent/a2a-connection/generator.d.ts +24 -0
  27. package/src/py/agent/a2a-connection/generator.js +49 -20
  28. package/src/py/agent/a2a-connection/generator.js.map +1 -1
  29. package/src/py/agent/gateway-connection/generator.d.ts +23 -0
  30. package/src/py/agent/gateway-connection/generator.js +45 -11
  31. package/src/py/agent/gateway-connection/generator.js.map +1 -1
  32. package/src/py/agent/generator.d.ts +146 -1
  33. package/src/py/agent/generator.js +173 -76
  34. package/src/py/agent/generator.js.map +1 -1
  35. package/src/py/agent/mcp-connection/generator.d.ts +23 -0
  36. package/src/py/agent/mcp-connection/generator.js +45 -11
  37. package/src/py/agent/mcp-connection/generator.js.map +1 -1
  38. package/src/py/agent/react-connection/generator.d.ts +146 -0
  39. package/src/py/agent/react-connection/generator.js +27 -4
  40. package/src/py/agent/react-connection/generator.js.map +1 -1
  41. package/src/py/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +18 -0
  42. package/src/py/dynamodb/agent-connection/generator.js +7 -1
  43. package/src/py/dynamodb/agent-connection/generator.js.map +1 -1
  44. package/src/py/dynamodb/fast-api-connection/__snapshots__/generator.spec.ts.snap +9 -0
  45. package/src/py/dynamodb/fast-api-connection/generator.js +3 -1
  46. package/src/py/dynamodb/fast-api-connection/generator.js.map +1 -1
  47. package/src/py/dynamodb/generator.d.ts +29 -0
  48. package/src/py/dynamodb/generator.js +32 -12
  49. package/src/py/dynamodb/generator.js.map +1 -1
  50. package/src/py/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
  51. package/src/py/dynamodb/mcp-server-connection/generator.js +7 -1
  52. package/src/py/dynamodb/mcp-server-connection/generator.js.map +1 -1
  53. package/src/py/fast-api/generator.d.ts +63 -0
  54. package/src/py/fast-api/generator.js +58 -23
  55. package/src/py/fast-api/generator.js.map +1 -1
  56. package/src/py/fast-api/react/generator.d.ts +16 -1
  57. package/src/py/fast-api/react/generator.js +15 -3
  58. package/src/py/fast-api/react/generator.js.map +1 -1
  59. package/src/py/lambda-function/generator.d.ts +21 -0
  60. package/src/py/lambda-function/generator.js +29 -10
  61. package/src/py/lambda-function/generator.js.map +1 -1
  62. package/src/py/mcp-server/generator.d.ts +60 -0
  63. package/src/py/mcp-server/generator.js +62 -25
  64. package/src/py/mcp-server/generator.js.map +1 -1
  65. package/src/py/project/generator.d.ts +13 -0
  66. package/src/py/project/generator.js +29 -10
  67. package/src/py/project/generator.js.map +1 -1
  68. package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +19 -0
  69. package/src/py/rdb/agent-connection/generator.js +7 -1
  70. package/src/py/rdb/agent-connection/generator.js.map +1 -1
  71. package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +7 -0
  72. package/src/py/rdb/fast-api-connection/generator.js +3 -1
  73. package/src/py/rdb/fast-api-connection/generator.js.map +1 -1
  74. package/src/py/rdb/generator.d.ts +89 -0
  75. package/src/py/rdb/generator.js +88 -40
  76. package/src/py/rdb/generator.js.map +1 -1
  77. package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
  78. package/src/py/rdb/mcp-server-connection/generator.js +7 -1
  79. package/src/py/rdb/mcp-server-connection/generator.js.map +1 -1
  80. package/src/smithy/project/generator.d.ts +7 -0
  81. package/src/smithy/project/generator.js +8 -2
  82. package/src/smithy/project/generator.js.map +1 -1
  83. package/src/smithy/react-connection/generator.d.ts +15 -0
  84. package/src/smithy/react-connection/generator.js +17 -3
  85. package/src/smithy/react-connection/generator.js.map +1 -1
  86. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +1 -0
  87. package/src/smithy/ts/api/generator.d.ts +79 -0
  88. package/src/smithy/ts/api/generator.js +77 -33
  89. package/src/smithy/ts/api/generator.js.map +1 -1
  90. package/src/terraform/project/generator.d.ts +50 -0
  91. package/src/terraform/project/generator.js +63 -17
  92. package/src/terraform/project/generator.js.map +1 -1
  93. package/src/trpc/backend/generator.d.ts +84 -0
  94. package/src/trpc/backend/generator.js +98 -38
  95. package/src/trpc/backend/generator.js.map +1 -1
  96. package/src/trpc/react/generator.d.ts +37 -0
  97. package/src/trpc/react/generator.js +63 -26
  98. package/src/trpc/react/generator.js.map +1 -1
  99. package/src/ts/agent/a2a-connection/generator.d.ts +46 -0
  100. package/src/ts/agent/a2a-connection/generator.js +53 -16
  101. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  102. package/src/ts/agent/gateway-connection/generator.d.ts +37 -0
  103. package/src/ts/agent/gateway-connection/generator.js +41 -14
  104. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  105. package/src/ts/agent/generator.d.ts +162 -0
  106. package/src/ts/agent/generator.js +166 -75
  107. package/src/ts/agent/generator.js.map +1 -1
  108. package/src/ts/agent/mcp-connection/generator.d.ts +37 -0
  109. package/src/ts/agent/mcp-connection/generator.js +41 -14
  110. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  111. package/src/ts/agent/react-connection/generator.d.ts +186 -0
  112. package/src/ts/agent/react-connection/generator.js +70 -21
  113. package/src/ts/agent/react-connection/generator.js.map +1 -1
  114. package/src/ts/astro-docs/generator.d.ts +38 -0
  115. package/src/ts/astro-docs/generator.js +58 -19
  116. package/src/ts/astro-docs/generator.js.map +1 -1
  117. package/src/ts/dcr-proxy/generator.d.ts +24 -0
  118. package/src/ts/dcr-proxy/generator.js +31 -14
  119. package/src/ts/dcr-proxy/generator.js.map +1 -1
  120. package/src/ts/dynamodb/agent-connection/__snapshots__/generator.spec.ts.snap +18 -0
  121. package/src/ts/dynamodb/agent-connection/generator.js +7 -1
  122. package/src/ts/dynamodb/agent-connection/generator.js.map +1 -1
  123. package/src/ts/dynamodb/generator.d.ts +41 -0
  124. package/src/ts/dynamodb/generator.js +47 -20
  125. package/src/ts/dynamodb/generator.js.map +1 -1
  126. package/src/ts/dynamodb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +18 -0
  127. package/src/ts/dynamodb/mcp-server-connection/generator.js +7 -1
  128. package/src/ts/dynamodb/mcp-server-connection/generator.js.map +1 -1
  129. package/src/ts/dynamodb/smithy-connection/__snapshots__/generator.spec.ts.snap +9 -0
  130. package/src/ts/dynamodb/smithy-connection/generator.js +3 -1
  131. package/src/ts/dynamodb/smithy-connection/generator.js.map +1 -1
  132. package/src/ts/dynamodb/trpc-connection/__snapshots__/generator.spec.ts.snap +9 -0
  133. package/src/ts/dynamodb/trpc-connection/generator.js +3 -1
  134. package/src/ts/dynamodb/trpc-connection/generator.js.map +1 -1
  135. package/src/ts/lambda-function/generator.d.ts +38 -0
  136. package/src/ts/lambda-function/generator.js +49 -20
  137. package/src/ts/lambda-function/generator.js.map +1 -1
  138. package/src/ts/lib/generator.d.ts +7 -0
  139. package/src/ts/lib/generator.js +8 -1
  140. package/src/ts/lib/generator.js.map +1 -1
  141. package/src/ts/lib/ts-project-utils.d.ts +3 -1
  142. package/src/ts/lib/ts-project-utils.js +3 -2
  143. package/src/ts/lib/ts-project-utils.js.map +1 -1
  144. package/src/ts/lib/vitest.d.ts +10 -1
  145. package/src/ts/lib/vitest.js +14 -2
  146. package/src/ts/lib/vitest.js.map +1 -1
  147. package/src/ts/mcp-server/generator.d.ts +71 -0
  148. package/src/ts/mcp-server/generator.js +73 -36
  149. package/src/ts/mcp-server/generator.js.map +1 -1
  150. package/src/ts/nx-generator/generator.d.ts +3 -0
  151. package/src/ts/nx-generator/generator.js +8 -2
  152. package/src/ts/nx-generator/generator.js.map +1 -1
  153. package/src/ts/nx-migration/generator.d.ts +3 -0
  154. package/src/ts/nx-migration/generator.js +8 -2
  155. package/src/ts/nx-migration/generator.js.map +1 -1
  156. package/src/ts/nx-plugin/generator.d.ts +3 -0
  157. package/src/ts/nx-plugin/generator.js +8 -2
  158. package/src/ts/nx-plugin/generator.js.map +1 -1
  159. package/src/ts/nx-plugin/utils.d.ts +7 -2
  160. package/src/ts/nx-plugin/utils.js +10 -4
  161. package/src/ts/nx-plugin/utils.js.map +1 -1
  162. package/src/ts/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +10 -0
  163. package/src/ts/rdb/agent-connection/generator.js +8 -1
  164. package/src/ts/rdb/agent-connection/generator.js.map +1 -1
  165. package/src/ts/rdb/generator.d.ts +101 -0
  166. package/src/ts/rdb/generator.js +93 -41
  167. package/src/ts/rdb/generator.js.map +1 -1
  168. package/src/ts/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +10 -0
  169. package/src/ts/rdb/mcp-server-connection/generator.js +8 -1
  170. package/src/ts/rdb/mcp-server-connection/generator.js.map +1 -1
  171. package/src/ts/rdb/smithy-connection/__snapshots__/generator.spec.ts.snap +9 -0
  172. package/src/ts/rdb/smithy-connection/generator.js +4 -1
  173. package/src/ts/rdb/smithy-connection/generator.js.map +1 -1
  174. package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +9 -0
  175. package/src/ts/rdb/trpc-connection/generator.js +3 -1
  176. package/src/ts/rdb/trpc-connection/generator.js.map +1 -1
  177. package/src/ts/react-website/agui/generator.d.ts +86 -0
  178. package/src/ts/react-website/agui/generator.js +63 -28
  179. package/src/ts/react-website/agui/generator.js.map +1 -1
  180. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +20 -2
  181. package/src/ts/react-website/app/generator.d.ts +136 -1
  182. package/src/ts/react-website/app/generator.js +109 -40
  183. package/src/ts/react-website/app/generator.js.map +1 -1
  184. package/src/ts/react-website/cognito-auth/generator.d.ts +19 -0
  185. package/src/ts/react-website/cognito-auth/generator.js +21 -9
  186. package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
  187. package/src/utils/add-dependencies.d.ts +38 -0
  188. package/src/utils/add-dependencies.js +83 -0
  189. package/src/utils/add-dependencies.js.map +1 -0
  190. package/src/utils/agent-connection/agent-connection.d.ts +27 -6
  191. package/src/utils/agent-connection/agent-connection.js +47 -18
  192. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  193. package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +19 -1
  194. package/src/utils/agent-core-constructs/agent-core-constructs.js +26 -6
  195. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  196. package/src/utils/api-constructs/api-constructs.d.ts +21 -2
  197. package/src/utils/api-constructs/api-constructs.js +26 -5
  198. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  199. package/src/utils/bundle/bundle.d.ts +6 -1
  200. package/src/utils/bundle/bundle.js +8 -2
  201. package/src/utils/bundle/bundle.js.map +1 -1
  202. package/src/utils/commands.d.ts +5 -4
  203. package/src/utils/commands.js +2 -6
  204. package/src/utils/commands.js.map +1 -1
  205. package/src/utils/connection/open-api/react.d.ts +18 -1
  206. package/src/utils/connection/open-api/react.js +27 -3
  207. package/src/utils/connection/open-api/react.js.map +1 -1
  208. package/src/utils/declared-dependencies.d.ts +140 -0
  209. package/src/utils/declared-dependencies.js +64 -0
  210. package/src/utils/declared-dependencies.js.map +1 -0
  211. package/src/utils/docker.d.ts +10 -1
  212. package/src/utils/docker.js +7 -3
  213. package/src/utils/docker.js.map +1 -1
  214. package/src/utils/fs.d.ts +15 -4
  215. package/src/utils/fs.js +26 -13
  216. package/src/utils/fs.js.map +1 -1
  217. package/src/utils/init.d.ts +14 -1
  218. package/src/utils/init.js +25 -7
  219. package/src/utils/init.js.map +1 -1
  220. package/src/utils/migration-versions.d.ts +15 -1
  221. package/src/utils/migration-versions.js +53 -7
  222. package/src/utils/migration-versions.js.map +1 -1
  223. package/src/utils/nx.d.ts +18 -0
  224. package/src/utils/nx.js +4 -0
  225. package/src/utils/nx.js.map +1 -1
  226. package/src/utils/py.d.ts +3 -2
  227. package/src/utils/py.js +10 -10
  228. package/src/utils/py.js.map +1 -1
  229. package/src/utils/shared-constructs-constants.d.ts +39 -4
  230. package/src/utils/shared-constructs-constants.js +29 -0
  231. package/src/utils/shared-constructs-constants.js.map +1 -1
  232. package/src/utils/shared-constructs.d.ts +4 -1
  233. package/src/utils/shared-constructs.js +5 -4
  234. package/src/utils/shared-constructs.js.map +1 -1
  235. package/src/utils/shared-dynamodb-scripts.d.ts +8 -1
  236. package/src/utils/shared-dynamodb-scripts.js +11 -3
  237. package/src/utils/shared-dynamodb-scripts.js.map +1 -1
  238. package/src/utils/shared-infra-scripts.d.ts +16 -1
  239. package/src/utils/shared-infra-scripts.js +18 -3
  240. package/src/utils/shared-infra-scripts.js.map +1 -1
  241. package/src/utils/shared-rdb-scripts.d.ts +12 -1
  242. package/src/utils/shared-rdb-scripts.js +17 -3
  243. package/src/utils/shared-rdb-scripts.js.map +1 -1
  244. package/src/utils/shared-shadcn.d.ts +26 -1
  245. package/src/utils/shared-shadcn.js +31 -14
  246. package/src/utils/shared-shadcn.js.map +1 -1
  247. package/src/utils/version-upgrade-migration/migration.d.ts +14 -0
  248. package/src/utils/version-upgrade-migration/migration.js +16 -0
  249. package/src/utils/version-upgrade-migration/migration.js.map +1 -0
  250. package/src/utils/version-upgrade-migration/nx-package-updates.d.ts +35 -0
  251. package/src/utils/version-upgrade-migration/nx-package-updates.js +42 -0
  252. package/src/utils/version-upgrade-migration/nx-package-updates.js.map +1 -0
  253. package/src/utils/version-upgrade-migration/owned-dependencies.d.ts +50 -0
  254. package/src/utils/version-upgrade-migration/owned-dependencies.js +98 -0
  255. package/src/utils/version-upgrade-migration/owned-dependencies.js.map +1 -0
  256. package/src/utils/version-upgrade-migration/register.d.ts +18 -0
  257. package/src/utils/version-upgrade-migration/register.js +33 -0
  258. package/src/utils/version-upgrade-migration/register.js.map +1 -0
  259. package/src/utils/version-upgrade-migration/sync-metrics-version.d.ts +13 -0
  260. package/src/utils/version-upgrade-migration/sync-metrics-version.js +33 -0
  261. package/src/utils/version-upgrade-migration/sync-metrics-version.js.map +1 -0
  262. package/src/utils/version-upgrade-migration/sync-vended-versions.d.ts +10 -0
  263. package/src/utils/version-upgrade-migration/sync-vended-versions.js +504 -0
  264. package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -0
  265. package/src/utils/version-upgrade-migration/vended-upgrade.d.ts +14 -0
  266. package/src/utils/version-upgrade-migration/vended-upgrade.js +40 -0
  267. package/src/utils/version-upgrade-migration/vended-upgrade.js.map +1 -0
  268. package/src/utils/versions.d.ts +25 -5
  269. package/src/utils/versions.js +46 -4
  270. package/src/utils/versions.js.map +1 -1
  271. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +4 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/lambda-function/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { addLambdaFunctionInfra } from '../../utils/function-constructs/function-constructs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport {\n toClassName,\n toDotNotation,\n toKebabCase,\n toSnakeCase,\n} from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { toProjectRelativePath } from '../../utils/paths';\nimport { addDependenciesToPyProjectToml } from '../../utils/py';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport type { PyLambdaFunctionGeneratorSchema } from './schema';\n\nexport const LAMBDA_FUNCTION_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport interface LambdaFunctionDetails {\n /**\n * The normalized name of the lambda handler project\n */\n readonly normalizedFunctionName: string;\n /**\n * The full package name of the lambda handler construct\n */\n readonly fullyQualifiedFunctionName: string;\n /**\n * The normalized python path to the lambda handler file in dot notation (e.g. `app.lambda_functions.lambda_handler`)\n */\n readonly normalizedFunctionPath: string;\n}\n\nconst getLambdaFunctionDetails = (\n tree: Tree,\n schema: { moduleName: string; name: string; functionPath?: string },\n): LambdaFunctionDetails => {\n const scope = toSnakeCase(getNpmScope(tree));\n const normalizedFunctionName = toSnakeCase(schema.name);\n const fullyQualifiedFunctionName = `${scope}.${normalizedFunctionName}`;\n const normalizedFunctionPath = `${schema.moduleName}.${schema.functionPath ? `${toDotNotation(schema.functionPath)}.` : ''}${normalizedFunctionName}.lambda_handler`;\n\n return {\n fullyQualifiedFunctionName,\n normalizedFunctionName,\n normalizedFunctionPath,\n };\n};\n\n/**\n * Generates a Python Lambda Function to add to a python project\n */\nexport const pyLambdaFunctionGenerator = async (\n tree: Tree,\n schema: PyLambdaFunctionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n schema.project,\n );\n\n const pyProjectPath = joinPathFragments(projectConfig.root, 'pyproject.toml');\n\n // Check if the project has a pyproject.toml file\n if (!pyProjectPath) {\n throw new Error(\n `This generator does not support selected project ${schema.project}`,\n );\n }\n\n if (!projectConfig.sourceRoot) {\n throw new Error(\n `This project does not have a source root. Please add a source root to the project configuration before running this generator.`,\n );\n }\n\n const dir = projectConfig.root;\n const projectNameWithOutScope = projectConfig.name.split('.').pop();\n const normalizedProjectName = toSnakeCase(projectNameWithOutScope);\n\n // Module name is the last part of the source root,\n const sourceParts = projectConfig.sourceRoot.split('/');\n const moduleName = sourceParts[sourceParts.length - 1];\n\n const { normalizedFunctionName, normalizedFunctionPath } =\n getLambdaFunctionDetails(tree, {\n moduleName,\n name: schema.name,\n functionPath: schema.functionPath,\n });\n\n const constructFunctionName = `${normalizedProjectName}_${normalizedFunctionName}`;\n const constructFunctionClassName = toClassName(constructFunctionName);\n const constructFunctionKebabCase = toKebabCase(constructFunctionName);\n const lambdaFunctionClassName = toClassName(schema.name);\n const lambdaFunctionKebabCase = toKebabCase(schema.name);\n\n const functionPath = joinPathFragments(\n projectConfig.sourceRoot,\n schema.functionPath ?? '',\n `${normalizedFunctionName}.py`,\n );\n\n const infra = schema.infra ?? 'lambda';\n const handlerAlreadyExists = tree.exists(functionPath);\n\n if (handlerAlreadyExists && infra === 'none') {\n throw new Error(\n `This project already has a lambda function with the name ${normalizedFunctionName}. Please remove the lambda function before running this generator or use a different name.`,\n );\n }\n\n // Check if the project has a bundle target and if not add it\n const { bundleOutputDir } = addPythonBundleTarget(projectConfig);\n\n if (infra !== 'none') {\n const iac = await resolveIac(tree, schema.iac);\n\n await sharedConstructsGenerator(tree, {\n iac,\n });\n\n await addLambdaFunctionInfra(tree, {\n functionProjectName: projectConfig.name,\n nameClassName: constructFunctionClassName,\n nameKebabCase: constructFunctionKebabCase,\n handler: normalizedFunctionPath,\n bundlePathFromRoot: bundleOutputDir,\n runtime: 'python',\n iac,\n });\n }\n\n const enhancedOptions = {\n ...schema,\n dir,\n lambdaFunctionClassName,\n lambdaFunctionSnakeCase: normalizedFunctionName,\n };\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n // Generate the lambda handler file\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files', 'handler'), // path to the file templates\n joinPathFragments(projectConfig.sourceRoot, schema.functionPath ?? ''),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate the lambda handler test file\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'tests'),\n joinPathFragments(dir, 'tests'),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addDependenciesToPyProjectToml(tree, dir, [\n 'aws-lambda-powertools',\n 'aws-lambda-powertools[tracer]',\n 'aws-lambda-powertools[parser]',\n ]);\n\n addComponentGeneratorMetadata(\n tree,\n projectConfig.name,\n LAMBDA_FUNCTION_GENERATOR_INFO,\n toProjectRelativePath(projectConfig, functionPath),\n lambdaFunctionKebabCase,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [LAMBDA_FUNCTION_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\nexport default pyLambdaFunctionGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addPythonBundleTarget","formatFilesInSubtree","addLambdaFunctionInfra","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toDotNotation","toKebabCase","toSnakeCase","getNpmScope","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","toProjectRelativePath","addDependenciesToPyProjectToml","sharedConstructsGenerator","LAMBDA_FUNCTION_GENERATOR_INFO","filename","getLambdaFunctionDetails","tree","schema","scope","normalizedFunctionName","name","fullyQualifiedFunctionName","normalizedFunctionPath","moduleName","functionPath","pyLambdaFunctionGenerator","projectConfig","project","pyProjectPath","root","Error","sourceRoot","dir","projectNameWithOutScope","split","pop","normalizedProjectName","sourceParts","length","constructFunctionName","constructFunctionClassName","constructFunctionKebabCase","lambdaFunctionClassName","lambdaFunctionKebabCase","infra","handlerAlreadyExists","exists","bundleOutputDir","iac","functionProjectName","nameClassName","nameKebabCase","handler","bundlePathFromRoot","runtime","enhancedOptions","lambdaFunctionSnakeCase","targets","dirname","overwriteStrategy","KeepExisting","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,sBAAsB,QAAQ,yDAAsD;AAC7F,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SACEC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,WAAW,QACN,uBAAoB;AAC3B,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,6BAA6B,EAC7BC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,qBAAqB,QAAQ,uBAAoB;AAC1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A;QAAEI,mBAAmBlE,kBAAkBmE,YAAY;IAAC;IAGtD,wCAAwC;IACxCrE,cACEyB,MACAxB,kBAAkB,YAAYkE,OAAO,EAAE,SAAS,UAChDlE,kBAAkBwC,KAAK,UACvBuB,iBACA;QAAEI,mBAAmBlE,kBAAkBmE,YAAY;IAAC;IAGtDjD,+BAA+BK,MAAMgB,KAAK;QACxC;QACA;QACA;KACD;IAED1B,8BACEU,MACAU,cAAcN,IAAI,EAClBP,gCACAH,sBAAsBgB,eAAeF,eACrCmB;IAGF,MAAM3C,gCAAgCgB,MAAM;QAACH;KAA+B;IAE5E,MAAMjB,qBAAqBoB;IAE3B,OAAO,IACLjB,oBAAoBiB,MAAMC,OAAO4C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AACF,eAAerC,0BAA0B"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/lambda-function/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addPyDependencies } from '../../utils/add-dependencies';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { addLambdaFunctionInfra } from '../../utils/function-constructs/function-constructs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport {\n toClassName,\n toDotNotation,\n toKebabCase,\n toSnakeCase,\n} from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { toProjectRelativePath } from '../../utils/paths';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport type { PyLambdaFunctionGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES)],\n py: [\n { name: 'aws-lambda-powertools' },\n { name: 'aws-lambda-powertools[tracer]' },\n { name: 'aws-lambda-powertools[parser]' },\n ],\n});\n\nexport const LAMBDA_FUNCTION_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport interface LambdaFunctionDetails {\n /**\n * The normalized name of the lambda handler project\n */\n readonly normalizedFunctionName: string;\n /**\n * The full package name of the lambda handler construct\n */\n readonly fullyQualifiedFunctionName: string;\n /**\n * The normalized python path to the lambda handler file in dot notation (e.g. `app.lambda_functions.lambda_handler`)\n */\n readonly normalizedFunctionPath: string;\n}\n\nconst getLambdaFunctionDetails = (\n tree: Tree,\n schema: { moduleName: string; name: string; functionPath?: string },\n): LambdaFunctionDetails => {\n const scope = toSnakeCase(getNpmScope(tree));\n const normalizedFunctionName = toSnakeCase(schema.name);\n const fullyQualifiedFunctionName = `${scope}.${normalizedFunctionName}`;\n const normalizedFunctionPath = `${schema.moduleName}.${schema.functionPath ? `${toDotNotation(schema.functionPath)}.` : ''}${normalizedFunctionName}.lambda_handler`;\n\n return {\n fullyQualifiedFunctionName,\n normalizedFunctionName,\n normalizedFunctionPath,\n };\n};\n\n/**\n * Generates a Python Lambda Function to add to a python project\n */\nexport const pyLambdaFunctionGenerator = async (\n tree: Tree,\n schema: PyLambdaFunctionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n schema.project,\n );\n\n const pyProjectPath = joinPathFragments(projectConfig.root, 'pyproject.toml');\n\n // Check if the project has a pyproject.toml file\n if (!pyProjectPath) {\n throw new Error(\n `This generator does not support selected project ${schema.project}`,\n );\n }\n\n if (!projectConfig.sourceRoot) {\n throw new Error(\n `This project does not have a source root. Please add a source root to the project configuration before running this generator.`,\n );\n }\n\n const dir = projectConfig.root;\n const projectNameWithOutScope = projectConfig.name.split('.').pop();\n const normalizedProjectName = toSnakeCase(projectNameWithOutScope);\n\n // Module name is the last part of the source root,\n const sourceParts = projectConfig.sourceRoot.split('/');\n const moduleName = sourceParts[sourceParts.length - 1];\n\n const { normalizedFunctionName, normalizedFunctionPath } =\n getLambdaFunctionDetails(tree, {\n moduleName,\n name: schema.name,\n functionPath: schema.functionPath,\n });\n\n const constructFunctionName = `${normalizedProjectName}_${normalizedFunctionName}`;\n const constructFunctionClassName = toClassName(constructFunctionName);\n const constructFunctionKebabCase = toKebabCase(constructFunctionName);\n const lambdaFunctionClassName = toClassName(schema.name);\n const lambdaFunctionKebabCase = toKebabCase(schema.name);\n\n const functionPath = joinPathFragments(\n projectConfig.sourceRoot,\n schema.functionPath ?? '',\n `${normalizedFunctionName}.py`,\n );\n\n const infra = schema.infra ?? 'lambda';\n const handlerAlreadyExists = tree.exists(functionPath);\n\n if (handlerAlreadyExists && infra === 'none') {\n throw new Error(\n `This project already has a lambda function with the name ${normalizedFunctionName}. Please remove the lambda function before running this generator or use a different name.`,\n );\n }\n\n // Check if the project has a bundle target and if not add it\n const { bundleOutputDir } = addPythonBundleTarget(projectConfig);\n\n // Recorded below so the version sync can tell a CDK project from a\n // Terraform one; undefined when no infrastructure was generated.\n const iac = infra !== 'none' ? await resolveIac(tree, schema.iac) : undefined;\n\n if (infra !== 'none') {\n await sharedConstructsGenerator(\n tree,\n {\n iac,\n },\n DEPENDENCIES,\n );\n\n await addLambdaFunctionInfra(tree, {\n functionProjectName: projectConfig.name,\n nameClassName: constructFunctionClassName,\n nameKebabCase: constructFunctionKebabCase,\n handler: normalizedFunctionPath,\n bundlePathFromRoot: bundleOutputDir,\n runtime: 'python',\n iac,\n });\n }\n\n const enhancedOptions = {\n ...schema,\n dir,\n lambdaFunctionClassName,\n lambdaFunctionSnakeCase: normalizedFunctionName,\n };\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n // Generate the lambda handler file\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, 'files', 'handler'), // path to the file templates\n joinPathFragments(projectConfig.sourceRoot, schema.functionPath ?? ''),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate the lambda handler test file\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'tests'),\n joinPathFragments(dir, 'tests'),\n enhancedOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addPyDependencies(tree, DEPENDENCIES, { projectRoot: dir });\n\n addComponentGeneratorMetadata(\n tree,\n projectConfig.name,\n LAMBDA_FUNCTION_GENERATOR_INFO,\n toProjectRelativePath(projectConfig, functionPath),\n lambdaFunctionKebabCase,\n iac ? { iac } : {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [LAMBDA_FUNCTION_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\nexport default pyLambdaFunctionGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addPyDependencies","addPythonBundleTarget","declareDependencies","ownedElsewhere","formatFilesInSubtree","addLambdaFunctionInfra","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toDotNotation","toKebabCase","toSnakeCase","getNpmScope","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","toProjectRelativePath","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","py","name","LAMBDA_FUNCTION_GENERATOR_INFO","filename","getLambdaFunctionDetails","tree","schema","scope","normalizedFunctionName","fullyQualifiedFunctionName","normalizedFunctionPath","moduleName","functionPath","pyLambdaFunctionGenerator","projectConfig","project","pyProjectPath","root","Error","sourceRoot","dir","projectNameWithOutScope","split","pop","normalizedProjectName","sourceParts","length","constructFunctionName","constructFunctionClassName","constructFunctionKebabCase","lambdaFunctionClassName","lambdaFunctionKebabCase","infra","handlerAlreadyExists","exists","bundleOutputDir","iac","undefined","functionProjectName","nameClassName","nameKebabCase","handler","bundlePathFromRoot","runtime","enhancedOptions","lambdaFunctionSnakeCase","targets","dirname","overwriteStrategy","KeepExisting","projectRoot","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAA+B;AACjE,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,sBAAsB,QAAQ,yDAAsD;AAC7F,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SACEC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,WAAW,QACN,uBAAoB;AAC3B,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,6BAA6B,EAC7BC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,qBAAqB,QAAQ,uBAAoB;AAC1D,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAgC;AAGvC,OAAO,MAAMC,eAAenB,sBAAsB;IAChDoB,IAAI;WAAInB,eAAegB;KAAgC;IACvDI,IAAI;QACF;YAAEC,MAAM;QAAwB;QAChC;YAAEA,MAAM;QAAgC;QACxC;YA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b,OAAOM,YAAY,IAAI,KACnEgC,iBACA;QAAEI,mBAAmBzE,kBAAkB0E,YAAY;IAAC;IAGtD,wCAAwC;IACxC5E,cACEgC,MACA/B,kBAAkB,YAAYyE,OAAO,EAAE,SAAS,UAChDzE,kBAAkB8C,KAAK,UACvBwB,iBACA;QAAEI,mBAAmBzE,kBAAkB0E,YAAY;IAAC;IAGtDxE,kBAAkB4B,MAAMP,cAAc;QAAEoD,aAAa9B;IAAI;IAEzD7B,8BACEc,MACAS,cAAcb,IAAI,EAClBC,gCACAP,sBAAsBmB,eAAeF,eACrCmB,yBACAK,MAAM;QAAEA;IAAI,IAAI,CAAC;IAGnB,MAAMnD,gCAAgCoB,MAAM;QAACH;KAA+B;IAE5E,MAAMrB,qBAAqBwB;IAE3B,OAAO,IACLrB,oBAAoBqB,MAAMC,OAAO6C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AACF,eAAevC,0BAA0B"}
@@ -4,7 +4,67 @@
4
4
  */
5
5
  import { type GeneratorCallback, type Tree } from '@nx/devkit';
6
6
  import { type NxGeneratorInfo } from '../../utils/nx';
7
+ import type { IacMetadata } from '../../utils/shared-constructs-constants';
7
8
  import type { PyMcpServerGeneratorSchema } from './schema';
9
+ /** The metadata this generator records, which its predicates read. */
10
+ export interface PyMcpServerMetadata extends IacMetadata {
11
+ readonly port: number;
12
+ readonly rc: string;
13
+ readonly auth: string;
14
+ }
15
+ export declare const DEPENDENCIES: import("../../utils/declared-dependencies").DependencyDeclaration<readonly [{
16
+ readonly name: "@modelcontextprotocol/inspector";
17
+ readonly dev: true;
18
+ readonly root: true;
19
+ }, {
20
+ readonly name: "ncp";
21
+ } & {
22
+ versionOnly: true;
23
+ }, {
24
+ readonly name: "rimraf";
25
+ } & {
26
+ versionOnly: true;
27
+ }, {
28
+ readonly name: "make-dir-cli";
29
+ } & {
30
+ versionOnly: true;
31
+ }, {
32
+ readonly name: "ncp";
33
+ } & {
34
+ versionOnly: true;
35
+ }, {
36
+ readonly name: "rimraf";
37
+ } & {
38
+ versionOnly: true;
39
+ }, {
40
+ readonly name: "make-dir-cli";
41
+ } & {
42
+ versionOnly: true;
43
+ }, {
44
+ readonly name: "constructs";
45
+ readonly when: (m: IacMetadata) => boolean;
46
+ } & {
47
+ versionOnly: true;
48
+ }, {
49
+ readonly name: "aws-cdk-lib";
50
+ readonly when: (m: IacMetadata) => boolean;
51
+ } & {
52
+ versionOnly: true;
53
+ }, {
54
+ readonly name: "@types/node";
55
+ } & {
56
+ versionOnly: true;
57
+ }], readonly [{
58
+ readonly name: "aws-lambda-powertools";
59
+ }, {
60
+ readonly name: "mcp";
61
+ }, {
62
+ readonly name: "uvicorn";
63
+ }, {
64
+ readonly name: "boto3";
65
+ }, {
66
+ readonly name: "aws-opentelemetry-distro";
67
+ }]>;
8
68
  export declare const PY_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo;
9
69
  export declare const pyMcpServerGenerator: (tree: Tree, options: PyMcpServerGeneratorSchema) => Promise<GeneratorCallback>;
10
70
  export default pyMcpServerGenerator;
@@ -4,13 +4,14 @@
4
4
  */ import { generateFiles, joinPathFragments, OverwriteStrategy, updateProjectConfiguration } from "@nx/devkit";
5
5
  import { ensureLicenseExceptions } from "../../license/config.js";
6
6
  import { MCP_INSPECTOR_EXCEPTIONS } from "../../license/known-exceptions.js";
7
+ import { addPyDependencies, addTsDependencies } from "../../utils/add-dependencies.js";
7
8
  import { addMcpServerInfra } from "../../utils/agent-core-constructs/agent-core-constructs.js";
8
9
  import { addPythonBundleTarget } from "../../utils/bundle/bundle.js";
9
10
  import { resolveContainers } from "../../utils/containers.js";
10
- import { addDependenciesToPackageJson } from "../../utils/dependencies.js";
11
- import { addDockerScanTarget } from "../../utils/docker.js";
11
+ import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
12
+ import { addDockerScanTarget, DOCKER_DEPENDENCIES } from "../../utils/docker.js";
12
13
  import { formatFilesInSubtree } from "../../utils/format.js";
13
- import { FsCommands } from "../../utils/fs.js";
14
+ import { FS_DEPENDENCIES, FsCommands } from "../../utils/fs.js";
14
15
  import { resolveIac } from "../../utils/iac.js";
15
16
  import { installDependencies } from "../../utils/install.js";
16
17
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
@@ -19,9 +20,39 @@ import { getNpmScope } from "../../utils/npm-scope.js";
19
20
  import { addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
20
21
  import { toProjectRelativePath } from "../../utils/paths.js";
21
22
  import { assignPort } from "../../utils/port.js";
22
- import { addDependenciesToPyProjectToml } from "../../utils/py.js";
23
- import { sharedConstructsGenerator } from "../../utils/shared-constructs.js";
24
- import { BASE_IMAGES, withVersions } from "../../utils/versions.js";
23
+ import { SHARED_CONSTRUCTS_DEPENDENCIES, sharedConstructsGenerator } from "../../utils/shared-constructs.js";
24
+ import { BASE_IMAGES } from "../../utils/versions.js";
25
+ export const DEPENDENCIES = declareDependencies()({
26
+ ts: [
27
+ // The MCP inspector is shared tooling.
28
+ {
29
+ name: '@modelcontextprotocol/inspector',
30
+ dev: true,
31
+ root: true
32
+ },
33
+ // Added by the helpers that own the projects they belong to.
34
+ ...ownedElsewhere(FS_DEPENDENCIES),
35
+ ...ownedElsewhere(DOCKER_DEPENDENCIES),
36
+ ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES)
37
+ ],
38
+ py: [
39
+ {
40
+ name: 'aws-lambda-powertools'
41
+ },
42
+ {
43
+ name: 'mcp'
44
+ },
45
+ {
46
+ name: 'uvicorn'
47
+ },
48
+ {
49
+ name: 'boto3'
50
+ },
51
+ {
52
+ name: 'aws-opentelemetry-distro'
53
+ }
54
+ ]
55
+ });
25
56
  export const PY_MCP_SERVER_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
26
57
  export const pyMcpServerGenerator = async (tree, options)=>{
27
58
  const project = readProjectConfigurationUnqualified(tree, options.project);
@@ -42,6 +73,10 @@ export const pyMcpServerGenerator = async (tree, options)=>{
42
73
  const mcpServerNameClassName = toClassName(name);
43
74
  const targetSourceDir = joinPathFragments(project.sourceRoot, mcpServerNameSnakeCase);
44
75
  const infra = options.infra ?? 'agentcore';
76
+ // Recorded in the metadata below so the version sync can tell a CDK
77
+ // project from a Terraform one; undefined when no infrastructure was
78
+ // generated, in which case neither provider's packages were added.
79
+ const iac = infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;
45
80
  if (infra === 'none' && options.auth && options.auth !== 'iam') {
46
81
  console.warn('Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)');
47
82
  }
@@ -55,13 +90,6 @@ export const pyMcpServerGenerator = async (tree, options)=>{
55
90
  }, {
56
91
  overwriteStrategy: OverwriteStrategy.KeepExisting
57
92
  });
58
- addDependenciesToPyProjectToml(tree, project.root, [
59
- 'aws-lambda-powertools',
60
- 'mcp',
61
- 'uvicorn',
62
- 'boto3',
63
- 'aws-opentelemetry-distro'
64
- ]);
65
93
  if (infra === 'agentcore') {
66
94
  const containers = await resolveContainers(tree, 'inherit');
67
95
  const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;
@@ -80,7 +108,7 @@ export const pyMcpServerGenerator = async (tree, options)=>{
80
108
  const dockerOutputDir = joinPathFragments('dist', project.root, 'docker', name);
81
109
  const dockerTargetName = `${mcpTargetPrefix}-docker`;
82
110
  // Add a docker target that prepares the docker context and builds the image
83
- const fs = new FsCommands(tree);
111
+ const fs = new FsCommands(tree, DEPENDENCIES);
84
112
  project.targets[dockerTargetName] = {
85
113
  cache: true,
86
114
  executor: 'nx:run-commands',
@@ -108,12 +136,11 @@ export const pyMcpServerGenerator = async (tree, options)=>{
108
136
  imageTags: [
109
137
  dockerImageTag
110
138
  ]
111
- });
139
+ }, DEPENDENCIES);
112
140
  // Add shared constructs
113
- const iac = await resolveIac(tree, options.iac);
114
141
  await sharedConstructsGenerator(tree, {
115
142
  iac
116
- });
143
+ }, DEPENDENCIES);
117
144
  // Add the construct to deploy the mcp server
118
145
  await addMcpServerInfra(tree, {
119
146
  mcpServerNameKebabCase: name,
@@ -132,6 +159,23 @@ export const pyMcpServerGenerator = async (tree, options)=>{
132
159
  name: mcpTargetPrefix
133
160
  }
134
161
  });
162
+ // Recorded below and read by the declaration's predicates, so the packages
163
+ // added here are exactly the ones the version sync will own.
164
+ const metadata = {
165
+ port: localDevPort,
166
+ rc: mcpServerNameClassName,
167
+ auth,
168
+ ...iac ? {
169
+ iac
170
+ } : {}
171
+ };
172
+ addPyDependencies(tree, DEPENDENCIES, {
173
+ metadata,
174
+ projectRoot: project.root
175
+ });
176
+ addTsDependencies(tree, DEPENDENCIES, {
177
+ metadata
178
+ });
135
179
  const mcpTargets = {
136
180
  ...project.targets,
137
181
  // Add targets for running the MCP server
@@ -205,14 +249,7 @@ export const pyMcpServerGenerator = async (tree, options)=>{
205
249
  ...project,
206
250
  targets: mcpTargets
207
251
  });
208
- addDependenciesToPackageJson(tree, {}, withVersions([
209
- '@modelcontextprotocol/inspector'
210
- ]));
211
- addComponentGeneratorMetadata(tree, project.name, PY_MCP_SERVER_GENERATOR_INFO, toProjectRelativePath(project, targetSourceDir), mcpTargetPrefix, {
212
- port: localDevPort,
213
- rc: mcpServerNameClassName,
214
- auth
215
- });
252
+ addComponentGeneratorMetadata(tree, project.name, PY_MCP_SERVER_GENERATOR_INFO, toProjectRelativePath(project, targetSourceDir), mcpTargetPrefix, metadata);
216
253
  await addGeneratorMetricsIfApplicable(tree, [
217
254
  PY_MCP_SERVER_GENERATOR_INFO
218
255
  ]);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport { addMcpServerInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies';\nimport { addDockerScanTarget } from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName, toSnakeCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { toProjectRelativePath } from '../../utils/paths';\nimport { assignPort } from '../../utils/port';\nimport { addDependenciesToPyProjectToml } from '../../utils/py';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { BASE_IMAGES, withVersions } from '../../utils/versions';\nimport type { PyMcpServerGeneratorSchema } from './schema';\n\nexport const PY_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const pyMcpServerGenerator = async (\n tree: Tree,\n options: PyMcpServerGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n const pyProjectPath = joinPathFragments(project.root, 'pyproject.toml');\n\n // Check if the project has a pyproject.toml file\n if (!pyProjectPath) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a Python project (with a pyproject.toml)`,\n );\n }\n\n if (!project.sourceRoot) {\n throw new Error(\n `This project does not have a source root. Please add a source root to the project configuration before running this generator.`,\n );\n }\n\n // Module name is the last part of the source root,\n const sourceParts = project.sourceRoot.split('/');\n const moduleName = sourceParts[sourceParts.length - 1];\n\n const name = kebabCase(\n options.name || `${kebabCase(project.name.split('.').pop())}-mcp-server`,\n );\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n\n const mcpServerNameSnakeCase = toSnakeCase(options.name || 'mcp-server');\n const mcpServerNameClassName = toClassName(name);\n\n const targetSourceDir = joinPathFragments(\n project.sourceRoot,\n mcpServerNameSnakeCase,\n );\n\n const infra = options.infra ?? 'agentcore';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'app'),\n targetSourceDir,\n {\n name,\n mcpServerNameSnakeCase,\n mcpServerNameClassName,\n moduleName,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addDependenciesToPyProjectToml(tree, project.root, [\n 'aws-lambda-powertools',\n 'mcp',\n 'uvicorn',\n 'boto3',\n 'aws-opentelemetry-distro',\n ]);\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n const { bundleTargetName, bundleOutputDir } = addPythonBundleTarget(\n project,\n {\n pythonPlatform: 'aarch64-manylinux_2_28',\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n mcpServerNameSnakeCase,\n moduleName,\n bundleOutputDir,\n pythonBaseImage: BASE_IMAGES.python,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'docker',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n // Add a docker target that prepares the docker context and builds the image\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(dockerOutputDir),\n fs.mkdir(dockerOutputDir),\n fs.cp(bundleOutputDir, dockerOutputDir),\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: [bundleTargetName],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n addDockerScanTarget(tree, {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n });\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: PY_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`uv run -m ${moduleName}.${mcpServerNameSnakeCase}.stdio`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `uv run uvicorn --reload ${moduleName}.${mcpServerNameSnakeCase}.http:app --host 0.0.0.0 --port ${localDevPort}`,\n ],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `uv run uvicorn --reload ${moduleName}.${mcpServerNameSnakeCase}.http:app --host 0.0.0.0 --port ${localDevPort}`,\n ],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- uv run -m ${moduleName}.${mcpServerNameSnakeCase}.stdio`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n targets: mcpTargets,\n });\n\n addDependenciesToPackageJson(\n tree,\n {},\n withVersions(['@modelcontextprotocol/inspector']),\n );\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n PY_MCP_SERVER_GENERATOR_INFO,\n toProjectRelativePath(project, targetSourceDir),\n mcpTargetPrefix,\n {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [PY_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\n\nexport default pyMcpServerGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addMcpServerInfra","addPythonBundleTarget","resolveContainers","addDependenciesToPackageJson","addDockerScanTarget","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","toSnakeCase","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","toProjectRelativePath","assignPort","addDependenciesToPyProjectToml","sharedConstructsGenerator","BASE_IMAGES","withVersions","PY_MCP_SERVER_GENERATOR_INFO","filename","pyMcpServerGenerator","tree","options","project","pyProjectPath","root","Error","sourceRoot","sourceParts","split","moduleName","length","name","pop","mcpTargetPrefix","mcpServerNameSnakeCase","mcpServerNameClassName","targetSourceDir","infra","auth","console","warn","dirname","overwriteStrategy","KeepExisting","containers","dockerImageTag","bundleTargetName","bundleOutputDir","pythonPlatform","pythonBaseImage","python","dockerOutputDir","dockerTargetName","fs","targets","cache","executor","commands","rm","mkdir","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","iac","mcpServerNameKebabCase","projectName","localDevPort","component","info","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,wBAAwB,QAAQ,oCAAiC;AAC1E,SAASC,iBAAiB,QAAQ,6DAA0D;AAC5F,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,4BAA4B,QAAQ,8BAA2B;AACxE,SAASC,mBAAmB,QAAQ,wBAAqB;AACzD,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,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F;IAGF,MAAMrC,gCAAgCmB,MAAM;QAACH;KAA6B;IAE1E,MAAM3B,wBAAwB8B,MAAM7B;IAEpC,MAAMM,qBAAqBuB;IAC3B,OAAO,IACLpB,oBAAoBoB,MAAMC,QAAQ2D,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AAEF,eAAe9D,qBAAqB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport {\n addPyDependencies,\n addTsDependencies,\n} from '../../utils/add-dependencies';\nimport { addMcpServerInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addPythonBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies';\nimport { addDockerScanTarget, DOCKER_DEPENDENCIES } from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName, toSnakeCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { toProjectRelativePath } from '../../utils/paths';\nimport { assignPort } from '../../utils/port';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants';\nimport { BASE_IMAGES } from '../../utils/versions';\nimport type { PyMcpServerGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface PyMcpServerMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n}\n\nexport const DEPENDENCIES = declareDependencies<PyMcpServerMetadata>()({\n ts: [\n // The MCP inspector is shared tooling.\n { name: '@modelcontextprotocol/inspector', dev: true, root: true },\n // Added by the helpers that own the projects they belong to.\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n py: [\n { name: 'aws-lambda-powertools' },\n { name: 'mcp' },\n { name: 'uvicorn' },\n { name: 'boto3' },\n { name: 'aws-opentelemetry-distro' },\n ],\n});\n\nexport const PY_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const pyMcpServerGenerator = async (\n tree: Tree,\n options: PyMcpServerGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n const pyProjectPath = joinPathFragments(project.root, 'pyproject.toml');\n\n // Check if the project has a pyproject.toml file\n if (!pyProjectPath) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a Python project (with a pyproject.toml)`,\n );\n }\n\n if (!project.sourceRoot) {\n throw new Error(\n `This project does not have a source root. Please add a source root to the project configuration before running this generator.`,\n );\n }\n\n // Module name is the last part of the source root,\n const sourceParts = project.sourceRoot.split('/');\n const moduleName = sourceParts[sourceParts.length - 1];\n\n const name = kebabCase(\n options.name || `${kebabCase(project.name.split('.').pop())}-mcp-server`,\n );\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n\n const mcpServerNameSnakeCase = toSnakeCase(options.name || 'mcp-server');\n const mcpServerNameClassName = toClassName(name);\n\n const targetSourceDir = joinPathFragments(\n project.sourceRoot,\n mcpServerNameSnakeCase,\n );\n\n const infra = options.infra ?? 'agentcore';\n\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'app'),\n targetSourceDir,\n {\n name,\n mcpServerNameSnakeCase,\n mcpServerNameClassName,\n moduleName,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n const { bundleTargetName, bundleOutputDir } = addPythonBundleTarget(\n project,\n {\n pythonPlatform: 'aarch64-manylinux_2_28',\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n mcpServerNameSnakeCase,\n moduleName,\n bundleOutputDir,\n pythonBaseImage: BASE_IMAGES.python,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'docker',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n // Add a docker target that prepares the docker context and builds the image\n const fs = new FsCommands(tree, DEPENDENCIES);\n project.targets[dockerTargetName] = {\n cache: true,\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.rm(dockerOutputDir),\n fs.mkdir(dockerOutputDir),\n fs.cp(bundleOutputDir, dockerOutputDir),\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: [bundleTargetName],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: PY_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: PyMcpServerMetadata = {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n ...(iac ? { iac } : {}),\n };\n\n addPyDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\n });\n addTsDependencies(tree, DEPENDENCIES, { metadata });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`uv run -m ${moduleName}.${mcpServerNameSnakeCase}.stdio`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `uv run uvicorn --reload ${moduleName}.${mcpServerNameSnakeCase}.http:app --host 0.0.0.0 --port ${localDevPort}`,\n ],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `uv run uvicorn --reload ${moduleName}.${mcpServerNameSnakeCase}.http:app --host 0.0.0.0 --port ${localDevPort}`,\n ],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- uv run -m ${moduleName}.${mcpServerNameSnakeCase}.stdio`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n targets: mcpTargets,\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n PY_MCP_SERVER_GENERATOR_INFO,\n toProjectRelativePath(project, targetSourceDir),\n mcpTargetPrefix,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [PY_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\n\nexport default pyMcpServerGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addPyDependencies","addTsDependencies","addMcpServerInfra","addPythonBundleTarget","resolveContainers","declareDependencies","ownedElsewhere","addDockerScanTarget","DOCKER_DEPENDENCIES","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","toSnakeCase","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","toProjectRelativePath","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","DEPENDENCIES","ts","name","dev","root","py","PY_MCP_SERVER_GENERATOR_INFO","filename","pyMcpServerGenerator","tree","options","project","pyProjectPath","Error","sourceRoot","sourceParts","split","moduleName","length","pop","mcpTargetPrefix","mcpServerNameSnakeCase","mcpServerNameClassName","targetSourceDir","infra","iac","undefined","auth","console","warn","dirname","overwriteStrategy","KeepExisting","containers","dockerImageTag","bundleTargetName","bundleOutputDir","pythonPlatform","pythonBaseImage","python","dockerOutputDir","dockerTargetName","fs","targets","cache","executor","commands","rm","mkdir","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","mcpServerNameKebabCase","projectName","localDevPort","component","info","metadata","port","rc","projectRoot","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,wBAAwB,QAAQ,oCAAiC;AAC1E,SACEC,iBAAiB,EACjBC,iBAAiB,QACZ,kCAA+B;AACtC,SAASC,iBAAiB,QAAQ,6DAA0D;AAC5F,SAASC,qBAAqB,QAAQ,+BAA4B;AAClE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAoC;AAC3C,SAASC,mBAAmB,EAAEC,m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C,EAAE;YAC9ByB,UAAU;YACVoB,YAAY;YACZ,uEAAuE;YACvE,wEAAwE;YACxE,aAAa;YACbd,WAAW;gBAAC,GAAG/B,gBAAgB,IAAI,CAAC;aAAC;YACrCV,SAAS;gBACPoC,UAAU;oBACR,CAAC,6DAA6D,EAAEW,aAAa,IAAI,CAAC;iBACnF;gBACDS,KAAK;YACP;QACF;QACA,CAAC,GAAG9C,gBAAgB,cAAc,CAAC,CAAC,EAAE;YACpCyB,UAAU;YACVoB,YAAY;YACZvD,SAAS;gBACPoC,UAAU;oBACR,CAAC,2BAA2B,EAAE7B,WAAW,CAAC,EAAEI,uBAAuB,MAAM,CAAC;iBAC3E;gBACD6C,KAAK;YACP;QACF;IACF;IAEA,8DAA8D;IAC9D5E,sBAAsB0E,YAAY,GAAG5C,gBAAgB,IAAI,CAAC;IAE1DpD,2BAA2ByC,MAAME,QAAQT,IAAI,EAAE;QAC7C,GAAGS,OAAO;QACVgC,SAASqB;IACX;IAEAzE,8BACEkB,MACAE,QAAQT,IAAI,EACZI,8BACAX,sBAAsBgB,SAASY,kBAC/BH,iBACAwC;IAGF,MAAM3E,gCAAgCwB,MAAM;QAACH;KAA6B;IAE1E,MAAMrC,wBAAwBwC,MAAMvC;IAEpC,MAAMU,qBAAqB6B;IAC3B,OAAO,IACLzB,oBAAoByB,MAAMC,QAAQ4D,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AAEF,eAAe/D,qBAAqB"}
@@ -5,6 +5,19 @@
5
5
  import { type GeneratorCallback, type Tree } from '@nx/devkit';
6
6
  import { type NxGeneratorInfo } from '../../utils/nx';
7
7
  import type { PyProjectGeneratorSchema } from './schema';
8
+ export declare const DEPENDENCIES: import("../../utils/declared-dependencies").DependencyDeclaration<readonly [{
9
+ readonly name: "@nxlv/python";
10
+ readonly dev: true;
11
+ readonly root: true;
12
+ }], readonly [{
13
+ readonly name: "ruff";
14
+ readonly group: "dev";
15
+ readonly root: true;
16
+ }, {
17
+ readonly name: "ty";
18
+ readonly group: "dev";
19
+ readonly root: true;
20
+ }]>;
8
21
  export declare const PY_PROJECT_GENERATOR_INFO: NxGeneratorInfo;
9
22
  export interface PyProjectDetails {
10
23
  /**
@@ -3,7 +3,8 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */ import { ensurePackage, joinPathFragments, readNxJson, readProjectConfiguration, updateNxJson, updateProjectConfiguration } from "@nx/devkit";
5
5
  import { addLicenseCheckToLintTarget, ensurePythonLicenseCollector } from "../../license/config.js";
6
- import { addDependenciesToPackageJson } from "../../utils/dependencies.js";
6
+ import { addPyDependencies, addTsDependencies } from "../../utils/add-dependencies.js";
7
+ import { declareDependencies } from "../../utils/declared-dependencies.js";
7
8
  import { updateGitIgnore } from "../../utils/git.js";
8
9
  import { installDependencies } from "../../utils/install.js";
9
10
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
@@ -12,9 +13,32 @@ import { getNpmScope } from "../../utils/npm-scope.js";
12
13
  import { addDependencyToTargetIfNotPresent, addGeneratorMetadata, getGeneratorInfo, projectExists } from "../../utils/nx.js";
13
14
  import { migrateToSharedVenvGenerator, uvProjectGenerator } from "../../utils/nxlv-python.js";
14
15
  import { sortObjectKeys } from "../../utils/object.js";
15
- import { addDependenciesToDependencyGroupInPyProjectToml } from "../../utils/py.js";
16
16
  import { updateToml } from "../../utils/toml.js";
17
17
  import { withVersions } from "../../utils/versions.js";
18
+ export const DEPENDENCIES = declareDependencies()({
19
+ ts: [
20
+ {
21
+ name: '@nxlv/python',
22
+ dev: true,
23
+ root: true
24
+ }
25
+ ],
26
+ py: [
27
+ // The linting and type checking tools live in the workspace root pyproject.
28
+ // Pinned to the version generation-time formatting uses, so generated files
29
+ // stay `ruff format --check`-clean across ruff releases.
30
+ {
31
+ name: 'ruff',
32
+ group: 'dev',
33
+ root: true
34
+ },
35
+ {
36
+ name: 'ty',
37
+ group: 'dev',
38
+ root: true
39
+ }
40
+ ]
41
+ });
18
42
  export const PY_PROJECT_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
19
43
  // Transient artifacts that pytest, coverage and ruff create and remove while
20
44
  // the test, typecheck and compile targets run concurrently. `.coverage.*` are
@@ -53,10 +77,10 @@ const PYTHON_TRANSIENT_ARTIFACTS = [
53
77
  * Generates a Python project
54
78
  */ export const pyProjectGenerator = async (tree, schema)=>{
55
79
  const { dir, normalizedModuleName, fullyQualifiedName, distributionName } = getPyProjectDetails(tree, schema);
56
- const pythonPlugin = withVersions([
80
+ addTsDependencies(tree, DEPENDENCIES);
81
+ const pythonPlugin = withVersions(DEPENDENCIES, [
57
82
  '@nxlv/python'
58
83
  ]);
59
- addDependenciesToPackageJson(tree, {}, pythonPlugin);
60
84
  Object.entries(pythonPlugin).forEach(([name, version])=>ensurePackage(name, version));
61
85
  const nxJson = readNxJson(tree);
62
86
  // Only rewrite nx.json when the plugin needs adding, so re-running does not
@@ -192,12 +216,7 @@ const PYTHON_TRANSIENT_ARTIFACTS = [
192
216
  }
193
217
  return pyProjectToml;
194
218
  });
195
- // Pin ruff to the version generation-time formatting uses (PY_VERSIONS), so
196
- // generated files stay `ruff format --check`-clean across ruff releases.
197
- addDependenciesToDependencyGroupInPyProjectToml(tree, '.', 'dev', [
198
- 'ruff',
199
- 'ty'
200
- ]);
219
+ addPyDependencies(tree, DEPENDENCIES);
201
220
  // Base format target checks rather than writes (so build/lint don't rewrite
202
221
  // source); `fix` writes, and `skip-lint` writes without failing so it stays
203
222
  // a no-op when propagated through the lint -> format dependency.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n ensurePackage,\n type GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n type Tree,\n updateNxJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n addLicenseCheckToLintTarget,\n ensurePythonLicenseCollector,\n} from '../../license/config';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies';\nimport { updateGitIgnore } from '../../utils/git';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { normalizeDistributionName, toSnakeCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport type { UVPyprojectToml } from '../../utils/nxlv-python';\nimport {\n migrateToSharedVenvGenerator,\n uvProjectGenerator,\n} from '../../utils/nxlv-python';\nimport { sortObjectKeys } from '../../utils/object';\nimport { addDependenciesToDependencyGroupInPyProjectToml } from '../../utils/py';\nimport { updateToml } from '../../utils/toml';\nimport { withVersions } from '../../utils/versions';\nimport type { PyProjectGeneratorSchema } from './schema';\n\nexport const PY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n// Transient artifacts that pytest, coverage and ruff create and remove while\n// the test, typecheck and compile targets run concurrently. `.coverage.*` are\n// the per-process data files pytest-cov writes (`.coverage.<host>.<pid>.<rand>`)\n// before combining them. Both `ty` (which respects .gitignore) and the\n// `@nxlv/python:build` copy (which respects `ignorePaths`) would otherwise fail\n// when they read one of these mid-deletion.\nconst PYTHON_TRANSIENT_ARTIFACTS = [\n '__pycache__',\n '.coverage',\n '.coverage.*',\n '.pytest_cache',\n 'pytest-cache-files-*',\n '.ruff_cache',\n];\n\nexport interface PyProjectDetails {\n /**\n * Fully qualified Nx project id including scope, in dot notation (eg foo.bar).\n * This is the identifier Nx uses (readProjectConfiguration, the project\n * graph, target references) and is intentionally kept dotted.\n */\n readonly fullyQualifiedName: string;\n /**\n * PEP 503 normalised Python distribution name (eg foo-bar). This is the name\n * written to the project's `[project].name`, the root `[tool.uv.sources]`\n * key, and any inter-project dependency string. It is hyphenated (not dotted)\n * so `uv` and `@nxlv/python` can match it: uv writes `uv.lock` keyed by the\n * PEP 503 hyphenated name, and `@nxlv/python`'s dependency inference splits a\n * dotted name on `.` and so would otherwise drop the edge entirely. Keeping\n * the distribution name decoupled from `fullyQualifiedName` is what lets the\n * workspace dependency edge appear in the Nx project graph.\n */\n readonly distributionName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n /**\n * Module name for the project\n */\n readonly normalizedModuleName: string;\n}\n\n/**\n * Returns details about the Python project to be created\n */\nexport const getPyProjectDetails = (\n tree: Tree,\n schema: {\n name: string;\n directory?: string;\n subDirectory?: string;\n moduleName?: string;\n },\n): PyProjectDetails => {\n const scope = toSnakeCase(getNpmScope(tree));\n const normalizedName = toSnakeCase(schema.name);\n const normalizedModuleName = toSnakeCase(\n schema.moduleName ?? `${scope}_${normalizedName}`,\n );\n const fullyQualifiedName = `${scope}.${normalizedName}`;\n // The Python distribution name is the PEP 503 normalised form of the\n // fully qualified name: hyphenated, never dotted. See PyProjectDetails.\n const distributionName = normalizeDistributionName(fullyQualifiedName);\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName, distributionName, normalizedModuleName };\n};\n\n/**\n * Generates a Python project\n */\nexport const pyProjectGenerator = async (\n tree: Tree,\n schema: PyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { dir, normalizedModuleName, fullyQualifiedName, distributionName } =\n getPyProjectDetails(tree, schema);\n\n const pythonPlugin = withVersions(['@nxlv/python']);\n addDependenciesToPackageJson(tree, {}, pythonPlugin);\n\n Object.entries(pythonPlugin).forEach(([name, version]) =>\n ensurePackage(name, version),\n );\n\n const nxJson = readNxJson(tree);\n\n // Only rewrite nx.json when the plugin needs adding, so re-running does not\n // reserialize (and reformat) the file when nothing has changed.\n if (\n !nxJson.plugins?.find((p) =>\n typeof p === 'string'\n ? p === '@nxlv/python'\n : p.plugin === '@nxlv/python',\n )\n ) {\n nxJson.plugins = [\n ...(nxJson.plugins ?? []),\n {\n plugin: '@nxlv/python',\n options: {\n packageManager: 'uv',\n },\n },\n ];\n updateNxJson(tree, nxJson);\n }\n\n // Only scaffold the project when it does not already exist so re-running with\n // the same name does not throw. The rest of the generator still runs to apply\n // any changed options to the existing project.\n if (!projectExists(tree, fullyQualifiedName)) {\n if (!tree.exists('uv.lock')) {\n await migrateToSharedVenvGenerator(tree, {\n autoActivate: true,\n packageManager: 'uv',\n moveDevDependencies: false,\n pyenvPythonVersion: '3.14.0',\n pyprojectPythonDependency: '>=3.14',\n });\n }\n\n await uvProjectGenerator(tree, {\n // The Nx project id (and `uv.workspace.members` etc.) keys off `name`, so\n // keep it dotted. `packageName` is the separate PEP 503 distribution name\n // written to `[project].name` and the root `[tool.uv.sources]` key; it is\n // hyphenated so `@nxlv/python` infers the workspace dependency edge (it\n // splits a dotted name on `.` and would otherwise drop it). This split is\n // the whole fix (see PyProjectDetails.distributionName).\n name: fullyQualifiedName,\n packageName: distributionName,\n publishable: false,\n buildLockedVersions: true,\n buildBundleLocalDependencies: true,\n linter: 'ruff',\n rootPyprojectDependencyGroup: 'main',\n pyenvPythonVersion: '3.14.0',\n pyprojectPythonDependency: '>=3.14',\n projectType: schema.type,\n projectNameAndRootFormat: 'as-provided',\n moduleName: normalizedModuleName,\n directory: dir,\n unitTestRunner: 'pytest',\n codeCoverage: true,\n codeCoverageHtmlReport: true,\n codeCoverageXmlReport: true,\n unitTestHtmlReport: true,\n unitTestJUnitReport: true,\n buildSystem: 'hatch',\n srcDir: false,\n });\n\n // Remove generated hello.py and test_hello.py as they are not needed\n [\n joinPathFragments(dir, normalizedModuleName, 'hello.py'),\n joinPathFragments(dir, 'tests', 'test_hello.py'),\n ].forEach((f) => tree.delete(f));\n\n // Add a placeholder test so pytest doesn't fail with \"no tests collected\"\n tree.write(\n joinPathFragments(dir, 'tests', 'test_noop.py'),\n 'def test_noop():\\n pass\\n',\n );\n }\n\n const outputPath = '{workspaceRoot}/dist/{projectRoot}';\n const buildOutputPath = joinPathFragments(outputPath, 'build');\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n projectConfiguration.name = fullyQualifiedName;\n // Derive the compile target from the uv build target, and rewrite build to\n // orchestrate the other targets. This only runs on first creation: on re-run\n // build has already been transformed, so re-deriving would corrupt compile\n // and duplicate the build dependencies.\n if (!projectConfiguration.targets.compile) {\n const buildTarget = projectConfiguration.targets.build;\n projectConfiguration.targets.compile = {\n ...buildTarget,\n inputs: ['default', '^production'],\n outputs: [buildOutputPath],\n options: {\n ...buildTarget.options,\n outputPath: buildOutputPath,\n // The build executor copies the project to a temp folder; exclude the\n // executor defaults plus transient artifacts so the copy does not race\n // a concurrent test/typecheck target deleting a file mid-copy.\n ignorePaths: ['.venv', '.tox', 'tests', ...PYTHON_TRANSIENT_ARTIFACTS],\n },\n };\n projectConfiguration.targets.build = {\n inputs: ['default', '^production'],\n dependsOn: [\n 'lint',\n 'compile',\n 'test',\n 'typecheck',\n ...(buildTarget.dependsOn ?? []),\n ],\n options: {\n outputPath,\n },\n };\n }\n projectConfiguration.targets.typecheck = {\n cache: true,\n inputs: ['default', '^production'],\n executor: '@nxlv/python:run-commands',\n options: {\n command: 'uv run ty check',\n cwd: '{projectRoot}',\n },\n };\n\n // Set the default line length to 120, as 88 is a little too strict\n updateToml(\n tree,\n joinPathFragments(dir, 'pyproject.toml'),\n (pyProjectToml: UVPyprojectToml) => {\n if ((pyProjectToml.tool as any)?.ruff) {\n (pyProjectToml.tool as any).ruff['line-length'] = 120;\n }\n return pyProjectToml;\n },\n );\n\n // Pin ruff to the version generation-time formatting uses (PY_VERSIONS), so\n // generated files stay `ruff format --check`-clean across ruff releases.\n addDependenciesToDependencyGroupInPyProjectToml(tree, '.', 'dev', [\n 'ruff',\n 'ty',\n ]);\n\n // Base format target checks rather than writes (so build/lint don't rewrite\n // source); `fix` writes, and `skip-lint` writes without failing so it stays\n // a no-op when propagated through the lint -> format dependency.\n projectConfiguration.targets.format = {\n ...projectConfiguration.targets.format,\n cache: true,\n inputs: ['default', '^production'],\n options: {\n ...projectConfiguration.targets.format?.options,\n check: true,\n },\n configurations: {\n ...projectConfiguration.targets.format?.configurations,\n fix: {\n check: false,\n },\n 'skip-lint': {\n check: false,\n },\n },\n };\n\n // Add a dependency on the format target for lint in order to reduce the number of\n // fixable lint errors (eg line too long)\n projectConfiguration.targets.lint = {\n ...projectConfiguration.targets.lint,\n cache: true,\n inputs: ['default', '^production'],\n configurations: {\n ...projectConfiguration.targets.lint?.configurations,\n fix: {\n fix: true,\n },\n 'skip-lint': {\n exitZero: true,\n },\n },\n };\n // Append `format` without moving an existing entry, so re-running does not\n // reorder lint dependencies (e.g. relative to a later-added license-check).\n addDependencyToTargetIfNotPresent(projectConfiguration, 'lint', 'format');\n\n projectConfiguration.targets = sortObjectKeys(projectConfiguration.targets);\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, PY_PROJECT_GENERATOR_INFO);\n\n // Update root .gitignore\n updateGitIgnore(tree, '.', (patterns) => [...patterns, '/reports']);\n\n // Update project level .gitignore. The cache directories are also kept out\n // of type checking: `ty` respects .gitignore, and pytest creates and removes\n // transient `pytest-cache-files-*` directories while the test and typecheck\n // targets run concurrently, which would otherwise make `ty` fail with an I/O\n // error when it scans one mid-deletion.\n updateGitIgnore(tree, dir, (patterns) => [\n ...patterns,\n '**/__pycache__',\n ...PYTHON_TRANSIENT_ARTIFACTS.filter((p) => p !== '__pycache__'),\n ]);\n\n await addGeneratorMetricsIfApplicable(tree, [PY_PROJECT_GENERATOR_INFO]);\n\n await ensurePythonLicenseCollector(tree);\n\n // If license checking is configured, make this project's lint target depend\n // on the root license-check target. No-op if license checking isn't set up;\n // the license generator wires up existing projects itself, so the dependency\n // is added regardless of which generator runs first.\n addLicenseCheckToLintTarget(tree, fullyQualifiedName);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\nexport default pyProjectGenerator;\n"],"names":["ensurePackage","joinPathFragments","readNxJson","readProjectConfiguration","updateNxJson","updateProjectConfiguration","addLicenseCheckToLintTarget","ensurePythonLicenseCollector","addDependenciesToPackageJson","updateGitIgnore","installDependencies","addGeneratorMetricsIfApplicable","normalizeDistributionName","toSnakeCase","getNpmScope","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","projectExists","migrateToSharedVenvGenerator","uvProjectGenerator","sortObjectKeys","addDependenciesToDependencyGroupInPyProjectToml","updateToml","withVersions","PY_PROJECT_GENERATOR_INFO","filename","PYTHON_TRANSIENT_ARTIFACTS","getPyProjectDetails","tree","schema","scope","normalizedName","name","normalizedModuleName","moduleName","fullyQualifiedName","distributionName","dir","directory","subDirectory","pyProjectGenerator","pythonPlugin","Object","entries","forEach","version","nxJson","plugins","find","p","plugin","options","packageManager","exists","autoActivate","moveDevDependencies","pyenvPythonVersion","pyprojectPythonDependency","packageName","publishable","buildLockedVersions","buildBundleLocalDependencies","linter","rootPyprojectDependencyGroup","projectType","type","projectNameAndRootFormat","unitTestRunner","codeCoverage","codeCoverageHtmlReport","codeCoverageXmlReport","unitTestHtmlReport","unitTestJUnitReport","buildSystem","srcDir","f","delete","write","outputPath","buildOutputPath","projectConfiguration","targets","compile","buildTarget","build","inputs","outputs","ignorePaths","dependsOn","typecheck","cache","executor","command","cwd","pyProjectToml","tool","ruff","format","check","configurations","fix","lint","exitZero","patterns","filter","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EAEbC,iBAAiB,EACjBC,UAAU,EACVC,wBAAwB,EAExBC,YAAY,EACZC,0BAA0B,QACrB,aAAa;AACpB,SACEC,2BAA2B,EAC3BC,4BAA4B,QACvB,0BAAuB;AAC9B,SAASC,4BAA4B,QAAQ,8BAA2B;AACxE,SAASC,eAAe,QAAQ,qBAAkB;AAClD,SAASC,mBAAmB,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A6E;IAC7E,4EAA4E;IAC5E,6EAA6E;IAC7E,wCAAwC;IACxC/F,gBAAgBoB,MAAMS,KAAK,CAACkE,WAAa;eACpCA;YACH;eACG7E,2BAA2B8E,MAAM,CAAC,CAACvD,IAAMA,MAAM;SACnD;IAED,MAAMvC,gCAAgCkB,MAAM;QAACJ;KAA0B;IAEvE,MAAMlB,6BAA6BsB;IAEnC,4EAA4E;IAC5E,4EAA4E;IAC5E,6EAA6E;IAC7E,qDAAqD;IACrDvB,4BAA4BuB,MAAMO;IAElC,OAAO,IACL1B,oBAAoBmB,MAAMC,OAAO4E,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AACF,eAAelE,mBAAmB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/py/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n ensurePackage,\n type GeneratorCallback,\n joinPathFragments,\n readNxJson,\n readProjectConfiguration,\n type Tree,\n updateNxJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n addLicenseCheckToLintTarget,\n ensurePythonLicenseCollector,\n} from '../../license/config';\nimport {\n addPyDependencies,\n addTsDependencies,\n} from '../../utils/add-dependencies';\nimport { declareDependencies } from '../../utils/declared-dependencies';\nimport { updateGitIgnore } from '../../utils/git';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { normalizeDistributionName, toSnakeCase } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport type { UVPyprojectToml } from '../../utils/nxlv-python';\nimport {\n migrateToSharedVenvGenerator,\n uvProjectGenerator,\n} from '../../utils/nxlv-python';\nimport { sortObjectKeys } from '../../utils/object';\nimport { updateToml } from '../../utils/toml';\nimport { withVersions } from '../../utils/versions';\nimport type { PyProjectGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [{ name: '@nxlv/python', dev: true, root: true }],\n py: [\n // The linting and type checking tools live in the workspace root pyproject.\n // Pinned to the version generation-time formatting uses, so generated files\n // stay `ruff format --check`-clean across ruff releases.\n { name: 'ruff', group: 'dev', root: true },\n { name: 'ty', group: 'dev', root: true },\n ],\n});\n\nexport const PY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n// Transient artifacts that pytest, coverage and ruff create and remove while\n// the test, typecheck and compile targets run concurrently. `.coverage.*` are\n// the per-process data files pytest-cov writes (`.coverage.<host>.<pid>.<rand>`)\n// before combining them. Both `ty` (which respects .gitignore) and the\n// `@nxlv/python:build` copy (which respects `ignorePaths`) would otherwise fail\n// when they read one of these mid-deletion.\nconst PYTHON_TRANSIENT_ARTIFACTS = [\n '__pycache__',\n '.coverage',\n '.coverage.*',\n '.pytest_cache',\n 'pytest-cache-files-*',\n '.ruff_cache',\n];\n\nexport interface PyProjectDetails {\n /**\n * Fully qualified Nx project id including scope, in dot notation (eg foo.bar).\n * This is the identifier Nx uses (readProjectConfiguration, the project\n * graph, target references) and is intentionally kept dotted.\n */\n readonly fullyQualifiedName: string;\n /**\n * PEP 503 normalised Python distribution name (eg foo-bar). This is the name\n * written to the project's `[project].name`, the root `[tool.uv.sources]`\n * key, and any inter-project dependency string. It is hyphenated (not dotted)\n * so `uv` and `@nxlv/python` can match it: uv writes `uv.lock` keyed by the\n * PEP 503 hyphenated name, and `@nxlv/python`'s dependency inference splits a\n * dotted name on `.` and so would otherwise drop the edge entirely. Keeping\n * the distribution name decoupled from `fullyQualifiedName` is what lets the\n * workspace dependency edge appear in the Nx project graph.\n */\n readonly distributionName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n /**\n * Module name for the project\n */\n readonly normalizedModuleName: string;\n}\n\n/**\n * Returns details about the Python project to be created\n */\nexport const getPyProjectDetails = (\n tree: Tree,\n schema: {\n name: string;\n directory?: string;\n subDirectory?: string;\n moduleName?: string;\n },\n): PyProjectDetails => {\n const scope = toSnakeCase(getNpmScope(tree));\n const normalizedName = toSnakeCase(schema.name);\n const normalizedModuleName = toSnakeCase(\n schema.moduleName ?? `${scope}_${normalizedName}`,\n );\n const fullyQualifiedName = `${scope}.${normalizedName}`;\n // The Python distribution name is the PEP 503 normalised form of the\n // fully qualified name: hyphenated, never dotted. See PyProjectDetails.\n const distributionName = normalizeDistributionName(fullyQualifiedName);\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName, distributionName, normalizedModuleName };\n};\n\n/**\n * Generates a Python project\n */\nexport const pyProjectGenerator = async (\n tree: Tree,\n schema: PyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { dir, normalizedModuleName, fullyQualifiedName, distributionName } =\n getPyProjectDetails(tree, schema);\n\n addTsDependencies(tree, DEPENDENCIES);\n\n const pythonPlugin = withVersions(DEPENDENCIES, ['@nxlv/python']);\n Object.entries(pythonPlugin).forEach(([name, version]) =>\n ensurePackage(name, version),\n );\n\n const nxJson = readNxJson(tree);\n\n // Only rewrite nx.json when the plugin needs adding, so re-running does not\n // reserialize (and reformat) the file when nothing has changed.\n if (\n !nxJson.plugins?.find((p) =>\n typeof p === 'string'\n ? p === '@nxlv/python'\n : p.plugin === '@nxlv/python',\n )\n ) {\n nxJson.plugins = [\n ...(nxJson.plugins ?? []),\n {\n plugin: '@nxlv/python',\n options: {\n packageManager: 'uv',\n },\n },\n ];\n updateNxJson(tree, nxJson);\n }\n\n // Only scaffold the project when it does not already exist so re-running with\n // the same name does not throw. The rest of the generator still runs to apply\n // any changed options to the existing project.\n if (!projectExists(tree, fullyQualifiedName)) {\n if (!tree.exists('uv.lock')) {\n await migrateToSharedVenvGenerator(tree, {\n autoActivate: true,\n packageManager: 'uv',\n moveDevDependencies: false,\n pyenvPythonVersion: '3.14.0',\n pyprojectPythonDependency: '>=3.14',\n });\n }\n\n await uvProjectGenerator(tree, {\n // The Nx project id (and `uv.workspace.members` etc.) keys off `name`, so\n // keep it dotted. `packageName` is the separate PEP 503 distribution name\n // written to `[project].name` and the root `[tool.uv.sources]` key; it is\n // hyphenated so `@nxlv/python` infers the workspace dependency edge (it\n // splits a dotted name on `.` and would otherwise drop it). This split is\n // the whole fix (see PyProjectDetails.distributionName).\n name: fullyQualifiedName,\n packageName: distributionName,\n publishable: false,\n buildLockedVersions: true,\n buildBundleLocalDependencies: true,\n linter: 'ruff',\n rootPyprojectDependencyGroup: 'main',\n pyenvPythonVersion: '3.14.0',\n pyprojectPythonDependency: '>=3.14',\n projectType: schema.type,\n projectNameAndRootFormat: 'as-provided',\n moduleName: normalizedModuleName,\n directory: dir,\n unitTestRunner: 'pytest',\n codeCoverage: true,\n codeCoverageHtmlReport: true,\n codeCoverageXmlReport: true,\n unitTestHtmlReport: true,\n unitTestJUnitReport: true,\n buildSystem: 'hatch',\n srcDir: false,\n });\n\n // Remove generated hello.py and test_hello.py as they are not needed\n [\n joinPathFragments(dir, normalizedModuleName, 'hello.py'),\n joinPathFragments(dir, 'tests', 'test_hello.py'),\n ].forEach((f) => tree.delete(f));\n\n // Add a placeholder test so pytest doesn't fail with \"no tests collected\"\n tree.write(\n joinPathFragments(dir, 'tests', 'test_noop.py'),\n 'def test_noop():\\n pass\\n',\n );\n }\n\n const outputPath = '{workspaceRoot}/dist/{projectRoot}';\n const buildOutputPath = joinPathFragments(outputPath, 'build');\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n projectConfiguration.name = fullyQualifiedName;\n // Derive the compile target from the uv build target, and rewrite build to\n // orchestrate the other targets. This only runs on first creation: on re-run\n // build has already been transformed, so re-deriving would corrupt compile\n // and duplicate the build dependencies.\n if (!projectConfiguration.targets.compile) {\n const buildTarget = projectConfiguration.targets.build;\n projectConfiguration.targets.compile = {\n ...buildTarget,\n inputs: ['default', '^production'],\n outputs: [buildOutputPath],\n options: {\n ...buildTarget.options,\n outputPath: buildOutputPath,\n // The build executor copies the project to a temp folder; exclude the\n // executor defaults plus transient artifacts so the copy does not race\n // a concurrent test/typecheck target deleting a file mid-copy.\n ignorePaths: ['.venv', '.tox', 'tests', ...PYTHON_TRANSIENT_ARTIFACTS],\n },\n };\n projectConfiguration.targets.build = {\n inputs: ['default', '^production'],\n dependsOn: [\n 'lint',\n 'compile',\n 'test',\n 'typecheck',\n ...(buildTarget.dependsOn ?? []),\n ],\n options: {\n outputPath,\n },\n };\n }\n projectConfiguration.targets.typecheck = {\n cache: true,\n inputs: ['default', '^production'],\n executor: '@nxlv/python:run-commands',\n options: {\n command: 'uv run ty check',\n cwd: '{projectRoot}',\n },\n };\n\n // Set the default line length to 120, as 88 is a little too strict\n updateToml(\n tree,\n joinPathFragments(dir, 'pyproject.toml'),\n (pyProjectToml: UVPyprojectToml) => {\n if ((pyProjectToml.tool as any)?.ruff) {\n (pyProjectToml.tool as any).ruff['line-length'] = 120;\n }\n return pyProjectToml;\n },\n );\n\n addPyDependencies(tree, DEPENDENCIES);\n\n // Base format target checks rather than writes (so build/lint don't rewrite\n // source); `fix` writes, and `skip-lint` writes without failing so it stays\n // a no-op when propagated through the lint -> format dependency.\n projectConfiguration.targets.format = {\n ...projectConfiguration.targets.format,\n cache: true,\n inputs: ['default', '^production'],\n options: {\n ...projectConfiguration.targets.format?.options,\n check: true,\n },\n configurations: {\n ...projectConfiguration.targets.format?.configurations,\n fix: {\n check: false,\n },\n 'skip-lint': {\n check: false,\n },\n },\n };\n\n // Add a dependency on the format target for lint in order to reduce the number of\n // fixable lint errors (eg line too long)\n projectConfiguration.targets.lint = {\n ...projectConfiguration.targets.lint,\n cache: true,\n inputs: ['default', '^production'],\n configurations: {\n ...projectConfiguration.targets.lint?.configurations,\n fix: {\n fix: true,\n },\n 'skip-lint': {\n exitZero: true,\n },\n },\n };\n // Append `format` without moving an existing entry, so re-running does not\n // reorder lint dependencies (e.g. relative to a later-added license-check).\n addDependencyToTargetIfNotPresent(projectConfiguration, 'lint', 'format');\n\n projectConfiguration.targets = sortObjectKeys(projectConfiguration.targets);\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, PY_PROJECT_GENERATOR_INFO);\n\n // Update root .gitignore\n updateGitIgnore(tree, '.', (patterns) => [...patterns, '/reports']);\n\n // Update project level .gitignore. The cache directories are also kept out\n // of type checking: `ty` respects .gitignore, and pytest creates and removes\n // transient `pytest-cache-files-*` directories while the test and typecheck\n // targets run concurrently, which would otherwise make `ty` fail with an I/O\n // error when it scans one mid-deletion.\n updateGitIgnore(tree, dir, (patterns) => [\n ...patterns,\n '**/__pycache__',\n ...PYTHON_TRANSIENT_ARTIFACTS.filter((p) => p !== '__pycache__'),\n ]);\n\n await addGeneratorMetricsIfApplicable(tree, [PY_PROJECT_GENERATOR_INFO]);\n\n await ensurePythonLicenseCollector(tree);\n\n // If license checking is configured, make this project's lint target depend\n // on the root license-check target. No-op if license checking isn't set up;\n // the license generator wires up existing projects itself, so the dependency\n // is added regardless of which generator runs first.\n addLicenseCheckToLintTarget(tree, fullyQualifiedName);\n\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript', 'python'],\n });\n};\nexport default pyProjectGenerator;\n"],"names":["ensurePackage","joinPathFragments","readNxJson","readProjectConfiguration","updateNxJson","updateProjectConfiguration","addLicenseCheckToLintTarget","ensurePythonLicenseCollector","addPyDependencies","addTsDependencies","declareDependencies","updateGitIgnore","installDependencies","addGeneratorMetricsIfApplicable","normalizeDistributionName","toSnakeCase","getNpmScope","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","projectExists","migrateToSharedVenvGenerator","uvProjectGenerator","sortObjectKeys","updateToml","withVersions","DEPENDENCIES","ts","name","dev","root","py","group","PY_PROJECT_GENERATOR_INFO","filename","PYTHON_TRANSIENT_ARTIFACTS","getPyProjectDetails","tree","schema","scope","normalizedName","normalizedModuleName","moduleName","fullyQualifiedName","distributionName","dir","directory","subDirectory","pyProjectGenerator","pythonPlugin","Object","entries","forEach","version","nxJson","plugins","find","p","plugin","options","packageManager","exists","autoActivate","moveDevDependencies","pyenvPythonVersion","pyprojectPythonDependency","packageName","publishable","buildLockedVersions","buildBundleLocalDependencies","linter","rootPyprojectDependencyGroup","projectType","type","projectNameAndRootFormat","unitTestRunner","codeCoverage","codeCoverageHtmlReport","codeCoverageXmlReport","unitTestHtmlReport","unitTestJUnitReport","buildSystem","srcDir","f","delete","write","outputPath","buildOutputPath","projectConfiguration","targets","compile","buildTarget","build","inputs","outputs","ignorePaths","dependsOn","typecheck","cache","executor","command","cwd","pyProjectToml","tool","ruff","format","check","configurations","fix","lint","exitZero","patterns","filter","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EAEbC,iBAAiB,EACjBC,UAAU,EACVC,wBAAwB,EAExBC,YAAY,EACZC,0BAA0B,QACrB,aAAa;AACpB,SACEC,2BAA2B,EAC3BC,4BAA4B,QACvB,0BAAuB;AAC9B,SACEC,iBAAiB,EACjBC,iBAAiB,QACZ,kCAA+B;AACtC,SAASC,mBAAmB,QAAQ,uCAAoC;AACxE,SAASC,eAAe,QAAQ,qBAAkB;AAClD,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,yBAAyB,EAAEC,WAAW,QAAQ,uBAAoB;AAC3E,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AAExB,SACEC,4BAA4B,EAC5BC,kBAAkB,QACb,6BAA0B;AACjC,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,UAAU,QAAQ,sBAA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,CAAC,CAACvD,IAAMA,MAAM;SACnD;IAED,MAAM5C,gCAAgCwB,MAAM;QAACJ;KAA0B;IAEvE,MAAM1B,6BAA6B8B;IAEnC,4EAA4E;IAC5E,4EAA4E;IAC5E,6EAA6E;IAC7E,qDAAqD;IACrD/B,4BAA4B+B,MAAMM;IAElC,OAAO,IACL/B,oBAAoByB,MAAMC,OAAO2E,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;gBAAc;aAAS;QACrC;AACJ,EAAE;AACF,eAAelE,mBAAmB"}
@@ -41,6 +41,15 @@ CMD ["python", "-m", "proj_my_agent.custom_agent.main"]
41
41
  exports[`py#rdb agent-connection generator > should add rdb dev dependency to agent dev 1`] = `
42
42
  {
43
43
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
44
+ "metadata": {
45
+ "components": [
46
+ {
47
+ "generator": "py#rdb#agent-connection",
48
+ "name": "agent-db",
49
+ "path": "packages/db",
50
+ },
51
+ ],
52
+ },
44
53
  "name": "my-agent",
45
54
  "root": "packages/my-agent",
46
55
  "sourceRoot": "packages/my-agent/src/proj_my_agent",
@@ -83,6 +92,16 @@ CMD ["python", "-m", "proj_my_agent.agent.main"]
83
92
  exports[`py#rdb agent-connection generator > should use sourceComponent name when provided 1`] = `
84
93
  {
85
94
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
95
+ "metadata": {
96
+ "components": [
97
+ {
98
+ "generator": "py#rdb#agent-connection",
99
+ "name": "custom-agent-db",
100
+ "path": "packages/db",
101
+ "sourcePath": "src/proj_my_agent/custom_agent",
102
+ },
103
+ ],
104
+ },
86
105
  "name": "my-agent",
87
106
  "root": "packages/my-agent",
88
107
  "sourceRoot": "packages/my-agent/src/proj_my_agent",
@@ -6,7 +6,7 @@ import { formatFilesInSubtree } from "../../../utils/format.js";
6
6
  import { installDependencies } from "../../../utils/install.js";
7
7
  import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
8
8
  import { toSnakeCase } from "../../../utils/names.js";
9
- import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
9
+ import { addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
10
10
  import { addWorkspaceDependencyToPyProject } from "../../../utils/py.js";
11
11
  import { injectRdsCaBundleIntoDockerfile } from "../utils.js";
12
12
  export const PY_RDB_AGENT_CONNECTION_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
@@ -30,6 +30,12 @@ export const pyRdbAgentConnectionGenerator = async (tree, options)=>{
30
30
  });
31
31
  updateProjectConfiguration(tree, sourceProject.name, sourceProject);
32
32
  }
33
+ // Recorded so the version sync can identify this connection.
34
+ addComponentGeneratorMetadata(tree, sourceProject.name, PY_RDB_AGENT_CONNECTION_GENERATOR_INFO, targetProject.root, `${agentName}-${targetProject.name}`, // The source component this connection is made from, so the pair is
35
+ // identifiable rather than just the two projects.
36
+ {
37
+ sourcePath: options.sourceComponent?.path
38
+ });
33
39
  await addGeneratorMetricsIfApplicable(tree, [
34
40
  PY_RDB_AGENT_CONNECTION_GENERATOR_INFO
35
41
  ]);