@aws/nx-plugin 1.0.0-rc.32 → 1.0.0-rc.34

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 (277) hide show
  1. package/LICENSE-THIRD-PARTY +75 -86
  2. package/generators.json +27 -0
  3. package/package.json +10 -10
  4. package/src/connection/generator.js +12 -1
  5. package/src/connection/generator.js.map +1 -1
  6. package/src/connection/supported-connections.d.ts +10 -1
  7. package/src/connection/supported-connections.js +13 -0
  8. package/src/connection/supported-connections.js.map +1 -1
  9. package/src/infra/app/__snapshots__/generator.spec.ts.snap +21 -21
  10. package/src/infra/app/files/app/src/main.ts.template +1 -1
  11. package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
  12. package/src/infra/app/generator.js +3 -1
  13. package/src/infra/app/generator.js.map +1 -1
  14. package/src/open-api/ts-client/__snapshots__/generator.complex-types.spec.ts.snap +12 -12
  15. package/src/open-api/ts-client/__snapshots__/generator.composite-types.spec.ts.snap +74 -10
  16. package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +22 -4
  17. package/src/open-api/ts-client/__snapshots__/generator.duplicate-types.spec.ts.snap +53 -8
  18. package/src/open-api/ts-client/__snapshots__/generator.edge-cases.spec.ts.snap +32 -4
  19. package/src/open-api/ts-client/__snapshots__/generator.fast-api-gaps.spec.ts.snap +736 -0
  20. package/src/open-api/ts-client/__snapshots__/generator.fast-api.spec.ts.snap +86 -11
  21. package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +21 -3
  22. package/src/open-api/ts-client/__snapshots__/generator.primitive-types.spec.ts.snap +2 -2
  23. package/src/open-api/ts-client/__snapshots__/generator.request.spec.ts.snap +6 -6
  24. package/src/open-api/ts-client/__snapshots__/generator.reserved-keywords.spec.ts.snap +2 -2
  25. package/src/open-api/ts-client/__snapshots__/generator.spec-compliance.spec.ts.snap +1883 -0
  26. package/src/open-api/ts-client/__snapshots__/generator.tags.spec.ts.snap +4 -4
  27. package/src/open-api/ts-client/files/client.gen.ts.template +196 -13
  28. package/src/open-api/ts-client/files/types.gen.ts.template +2 -0
  29. package/src/open-api/ts-client/generator.js +27 -2
  30. package/src/open-api/ts-client/generator.js.map +1 -1
  31. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
  32. package/src/open-api/ts-hooks/generator.js +5 -1
  33. package/src/open-api/ts-hooks/generator.js.map +1 -1
  34. package/src/open-api/utils/codegen-data/languages.js +6 -0
  35. package/src/open-api/utils/codegen-data/languages.js.map +1 -1
  36. package/src/open-api/utils/codegen-data/types.d.ts +16 -1
  37. package/src/open-api/utils/codegen-data/types.js.map +1 -1
  38. package/src/open-api/utils/codegen-data.js +71 -0
  39. package/src/open-api/utils/codegen-data.js.map +1 -1
  40. package/src/open-api/utils/normalise.js +53 -8
  41. package/src/open-api/utils/normalise.js.map +1 -1
  42. package/src/open-api/utils/parser.js +48 -15
  43. package/src/open-api/utils/parser.js.map +1 -1
  44. package/src/preset/__snapshots__/generator.spec.ts.snap +5 -3
  45. package/src/preset/generator.d.ts +1 -1
  46. package/src/preset/generator.js +5 -2
  47. package/src/preset/generator.js.map +1 -1
  48. package/src/preset/schema.d.js.map +1 -1
  49. package/src/preset/schema.d.ts +2 -0
  50. package/src/preset/schema.json +6 -0
  51. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
  52. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
  53. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
  54. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  55. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
  56. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  57. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
  58. package/src/py/rdb/__snapshots__/generator.spec.ts.snap +2038 -0
  59. package/src/py/rdb/agent-connection/__snapshots__/generator.spec.ts.snap +104 -0
  60. package/src/py/rdb/agent-connection/generator.d.ts +10 -0
  61. package/src/py/rdb/agent-connection/generator.js +46 -0
  62. package/src/py/rdb/agent-connection/generator.js.map +1 -0
  63. package/src/py/rdb/agent-connection/schema.d.js +8 -0
  64. package/src/py/rdb/agent-connection/schema.d.js.map +1 -0
  65. package/src/py/rdb/agent-connection/schema.d.ts +15 -0
  66. package/src/py/rdb/agent-connection/schema.json +27 -0
  67. package/src/py/rdb/fast-api-connection/__snapshots__/generator.spec.ts.snap +44 -0
  68. package/src/py/rdb/fast-api-connection/files/__apiModuleName__/dependencies/__rdbNameSnake__.py.template +14 -0
  69. package/src/py/rdb/fast-api-connection/generator.d.ts +10 -0
  70. package/src/py/rdb/fast-api-connection/generator.js +54 -0
  71. package/src/py/rdb/fast-api-connection/generator.js.map +1 -0
  72. package/src/py/rdb/fast-api-connection/schema.d.js +8 -0
  73. package/src/py/rdb/fast-api-connection/schema.d.js.map +1 -0
  74. package/src/py/rdb/fast-api-connection/schema.d.ts +13 -0
  75. package/src/py/rdb/fast-api-connection/schema.json +23 -0
  76. package/src/py/rdb/files/Dockerfile.create-db-user.template +10 -0
  77. package/src/py/rdb/files/Dockerfile.migration.template +10 -0
  78. package/src/py/rdb/files/__name__/__init__.py.template +3 -0
  79. package/src/py/rdb/files/__name__/connection.py.template +55 -0
  80. package/src/py/rdb/files/__name__/create_db_user_handler.py.template +97 -0
  81. package/src/py/rdb/files/__name__/migration_handler.py.template +36 -0
  82. package/src/py/rdb/files/__name__/models/__init__.py.template +3 -0
  83. package/src/py/rdb/files/__name__/models/example.py.template +8 -0
  84. package/src/py/rdb/files/__name__/utils.py.template +104 -0
  85. package/src/py/rdb/files/alembic.ini.template +38 -0
  86. package/src/py/rdb/files/config.json.template +14 -0
  87. package/src/py/rdb/files/migrations/env.py.template +80 -0
  88. package/src/py/rdb/files/migrations/script.py.mako.template +28 -0
  89. package/src/py/rdb/generator.d.ts +6 -0
  90. package/src/py/rdb/generator.js +263 -0
  91. package/src/py/rdb/generator.js.map +1 -0
  92. package/src/py/rdb/mcp-server-connection/__snapshots__/generator.spec.ts.snap +101 -0
  93. package/src/py/rdb/mcp-server-connection/generator.d.ts +10 -0
  94. package/src/py/rdb/mcp-server-connection/generator.js +46 -0
  95. package/src/py/rdb/mcp-server-connection/generator.js.map +1 -0
  96. package/src/py/rdb/mcp-server-connection/schema.d.js +8 -0
  97. package/src/py/rdb/mcp-server-connection/schema.d.js.map +1 -0
  98. package/src/py/rdb/mcp-server-connection/schema.d.ts +15 -0
  99. package/src/py/rdb/mcp-server-connection/schema.json +27 -0
  100. package/src/py/rdb/schema.d.js +6 -0
  101. package/src/py/rdb/schema.d.js.map +1 -0
  102. package/src/py/rdb/schema.d.ts +16 -0
  103. package/src/py/rdb/schema.json +77 -0
  104. package/src/py/rdb/utils.d.ts +6 -0
  105. package/src/py/rdb/utils.js +16 -0
  106. package/src/py/rdb/utils.js.map +1 -0
  107. package/src/sdk/py.d.ts +2 -0
  108. package/src/sdk/py.js +1 -0
  109. package/src/sdk/py.js.map +1 -1
  110. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
  111. package/src/smithy/ts/api/files/handler.ts.template +2 -2
  112. package/src/smithy/ts/api/files/local-server.ts.template +2 -2
  113. package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
  114. package/src/smithy/ts/api/files/service.ts.template +3 -3
  115. package/src/smithy/ts/api/generator.js +3 -1
  116. package/src/smithy/ts/api/generator.js.map +1 -1
  117. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
  118. package/src/trpc/backend/files/src/client/index.ts.template +1 -1
  119. package/src/trpc/backend/files/src/handler.ts.template +1 -1
  120. package/src/trpc/backend/files/src/index.ts.template +5 -5
  121. package/src/trpc/backend/files/src/init.ts.template +1 -1
  122. package/src/trpc/backend/files/src/local-server.ts.template +1 -1
  123. package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
  124. package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
  125. package/src/trpc/backend/files/src/router.ts.template +2 -2
  126. package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
  127. package/src/trpc/backend/generator.js +3 -1
  128. package/src/trpc/backend/generator.js.map +1 -1
  129. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
  130. package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
  131. package/src/ts/agent/a2a-connection/generator.js +3 -1
  132. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  133. package/src/ts/agent/files/a2a/index.ts.template +1 -1
  134. package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
  135. package/src/ts/agent/files/http/client.ts.template +2 -2
  136. package/src/ts/agent/files/http/index.ts.template +2 -2
  137. package/src/ts/agent/files/http/router.ts.template +3 -3
  138. package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
  139. package/src/ts/agent/gateway-connection/generator.js +3 -1
  140. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  141. package/src/ts/agent/generator.js +5 -2
  142. package/src/ts/agent/generator.js.map +1 -1
  143. package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
  144. package/src/ts/agent/mcp-connection/generator.js +3 -1
  145. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  146. package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
  147. package/src/ts/astro-docs/generator.js +2 -0
  148. package/src/ts/astro-docs/generator.js.map +1 -1
  149. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  150. package/src/ts/dynamodb/files/src/client.ts.template +5 -2
  151. package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
  152. package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
  153. package/src/ts/dynamodb/files/src/index.ts.template +2 -2
  154. package/src/ts/dynamodb/generator.js +3 -1
  155. package/src/ts/dynamodb/generator.js.map +1 -1
  156. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  157. package/src/ts/lib/generator.js +7 -1
  158. package/src/ts/lib/generator.js.map +1 -1
  159. package/src/ts/lib/ts-project-utils.js +19 -4
  160. package/src/ts/lib/ts-project-utils.js.map +1 -1
  161. package/src/ts/lib/types.d.ts +6 -0
  162. package/src/ts/lib/types.js.map +1 -1
  163. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -8
  164. package/src/ts/mcp-server/generator.js +3 -2
  165. package/src/ts/mcp-server/generator.js.map +1 -1
  166. package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
  167. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
  168. package/src/ts/nx-generator/generator.js +5 -2
  169. package/src/ts/nx-generator/generator.js.map +1 -1
  170. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
  171. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
  172. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
  173. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
  174. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
  175. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
  176. package/src/ts/nx-plugin/generator.js +3 -1
  177. package/src/ts/nx-plugin/generator.js.map +1 -1
  178. package/src/ts/nx-plugin/utils.js +7 -4
  179. package/src/ts/nx-plugin/utils.js.map +1 -1
  180. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +149 -177
  181. package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
  182. package/src/ts/rdb/files/src/index.ts.template +1 -1
  183. package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
  184. package/src/ts/rdb/files/src/prisma.ts.template +7 -4
  185. package/src/ts/rdb/generator.js +7 -4
  186. package/src/ts/rdb/generator.js.map +1 -1
  187. package/src/ts/rdb/schema.json +1 -1
  188. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +45 -45
  189. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
  190. package/src/utils/agent-chat/agent-chat.js +3 -1
  191. package/src/utils/agent-chat/agent-chat.js.map +1 -1
  192. package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
  193. package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
  194. package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
  195. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  196. package/src/utils/agent-connection/agent-connection.js +4 -1
  197. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  198. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
  199. package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
  200. package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
  201. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
  202. package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
  203. package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
  204. package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
  205. package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
  206. package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
  207. package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
  208. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  209. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
  210. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
  211. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
  212. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
  213. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
  214. package/src/utils/api-constructs/api-constructs.js +8 -2
  215. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  216. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
  217. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
  218. package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
  219. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
  220. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
  221. package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
  222. package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
  223. package/src/utils/ast.js +16 -0
  224. package/src/utils/ast.js.map +1 -1
  225. package/src/utils/commands.d.ts +1 -1
  226. package/src/utils/commands.js +4 -1
  227. package/src/utils/commands.js.map +1 -1
  228. package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
  229. package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
  230. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
  231. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
  232. package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
  233. package/src/utils/files/common/constructs/src/index.ts.template +2 -2
  234. package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
  235. package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
  236. package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
  237. package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
  238. package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
  239. package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
  240. package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
  241. package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
  242. package/src/utils/function-constructs/function-constructs.js +3 -1
  243. package/src/utils/function-constructs/function-constructs.js.map +1 -1
  244. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
  245. package/src/utils/identity-constructs/identity-constructs.js +5 -1
  246. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  247. package/src/utils/module-format.d.ts +28 -0
  248. package/src/utils/module-format.js +28 -0
  249. package/src/utils/module-format.js.map +1 -0
  250. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +61 -17
  251. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +68 -78
  252. package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +88 -8
  253. package/src/utils/rdb-constructs/files/terraform/core/rdb/aurora/aurora.tf.template +5 -32
  254. package/src/utils/rdb-constructs/rdb-constructs.d.ts +11 -1
  255. package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
  256. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  257. package/src/utils/shared-constructs.js +12 -22
  258. package/src/utils/shared-constructs.js.map +1 -1
  259. package/src/utils/shared-infra-config.js +3 -1
  260. package/src/utils/shared-infra-config.js.map +1 -1
  261. package/src/utils/shared-infra-scripts.js +3 -1
  262. package/src/utils/shared-infra-scripts.js.map +1 -1
  263. package/src/utils/shared-rdb-scripts.js +5 -1
  264. package/src/utils/shared-rdb-scripts.js.map +1 -1
  265. package/src/utils/shared-shadcn.js +3 -1
  266. package/src/utils/shared-shadcn.js.map +1 -1
  267. package/src/utils/test.d.ts +2 -0
  268. package/src/utils/test.js +7 -1
  269. package/src/utils/test.js.map +1 -1
  270. package/src/utils/versions.d.ts +73 -69
  271. package/src/utils/versions.js +71 -67
  272. package/src/utils/versions.js.map +1 -1
  273. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
  274. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
  275. package/src/utils/website-constructs/website-constructs.js +9 -2
  276. package/src/utils/website-constructs/website-constructs.js.map +1 -1
  277. package/src/utils/files/terraform/scripts/reset-runtime-config.ts.template +0 -25
@@ -3,6 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */ import { generateFiles, joinPathFragments, OverwriteStrategy, updateJson } from "@nx/devkit";
5
5
  import { addStarExport } from "../ast.js";
6
+ import { esmVars } from "../module-format.js";
6
7
  import { addDependencyToTargetIfNotPresent } from "../nx.js";
7
8
  import { PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, SHARED_TERRAFORM_DIR } from "../shared-constructs-constants.js";
8
9
  import { PY_VERSIONS, terraformProviderVersions } from "../versions.js";
@@ -23,7 +24,9 @@ export const addApiGatewayInfra = async (tree, options)=>{
23
24
  * Add an API CDK construct, and update the Runtime Config type to export its url
24
25
  */ const addApiGatewayCdkConstructs = async (tree, options)=>{
25
26
  const generateCoreApiFile = (name)=>{
26
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'core', 'api', name), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core', 'api'), {}, {
27
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'core', 'api', name), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core', 'api'), {
28
+ ...esmVars(tree)
29
+ }, {
27
30
  overwriteStrategy: OverwriteStrategy.KeepExisting
28
31
  });
29
32
  };
@@ -34,7 +37,10 @@ export const addApiGatewayInfra = async (tree, options)=>{
34
37
  generateCoreApiFile('trpc');
35
38
  }
36
39
  // Generate app specific CDK construct
37
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'apis', options.constructType), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'app', 'apis'), options, {
40
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'apis', options.constructType), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'app', 'apis'), {
41
+ ...options,
42
+ ...esmVars(tree)
43
+ }, {
38
44
  overwriteStrategy: OverwriteStrategy.KeepExisting
39
45
  });
40
46
  // Export app specific CDK construct
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/api-constructs/api-constructs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { addStarExport } from '../ast';\nimport type { Iac } from '../iac';\nimport { addDependencyToTargetIfNotPresent } from '../nx';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants';\nimport { PY_VERSIONS, terraformProviderVersions } from '../versions';\n\ninterface BackendOptions {\n type: 'trpc' | 'fastapi' | 'smithy';\n integrationPattern: 'isolated' | 'shared';\n}\n\nexport interface TrpcBackendOptions extends BackendOptions {\n type: 'trpc';\n projectAlias: string;\n bundleOutputDir: string;\n authorizerBundleOutputDir?: string;\n}\n\nexport interface FastApiBackendOptions extends BackendOptions {\n type: 'fastapi';\n moduleName: string;\n bundleOutputDir: string;\n}\n\nexport interface SmithyBackendOptions extends BackendOptions {\n type: 'smithy';\n bundleOutputDir: string;\n authorizerBundleOutputDir?: string;\n}\n\nexport interface AddApiGatewayConstructOptions {\n apiProjectName: string;\n apiNameClassName: string;\n apiNameKebabCase: string;\n constructType: 'http' | 'rest';\n backend: TrpcBackendOptions | FastApiBackendOptions | SmithyBackendOptions;\n auth: 'iam' | 'cognito' | 'custom';\n}\n\nexport const addApiGatewayInfra = async (\n tree: Tree,\n options: AddApiGatewayConstructOptions & { iac: Iac },\n) => {\n if (options.iac === 'cdk') {\n await addApiGatewayCdkConstructs(tree, options);\n } else if (options.iac === 'terraform') {\n addApiGatewayTerraformModules(tree, options);\n } else {\n throw new Error(`Unsupported iac ${options.iac}`);\n }\n\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.apiProjectName}:build`,\n );\n return config;\n },\n );\n};\n\n/**\n * Add an API CDK construct, and update the Runtime Config type to export its url\n */\nconst addApiGatewayCdkConstructs = async (\n tree: Tree,\n options: AddApiGatewayConstructOptions,\n) => {\n const generateCoreApiFile = (name: string) => {\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'core',\n 'api',\n name,\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'api',\n ),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n };\n\n // Generate relevant core CDK construct and utilities\n generateCoreApiFile(options.constructType);\n generateCoreApiFile('utils');\n if (options.backend.type === 'trpc') {\n generateCoreApiFile('trpc');\n }\n\n // Generate app specific CDK construct\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'app',\n 'apis',\n options.constructType,\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'apis',\n ),\n options,\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Export app specific CDK construct\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'apis',\n 'index.ts',\n ),\n `./${options.apiNameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n './apis/index.js',\n );\n};\n\n/**\n * Add an API terraform module, and update the Runtime Config type to export its url\n */\nconst addApiGatewayTerraformModules = (\n tree: Tree,\n options: AddApiGatewayConstructOptions,\n) => {\n // Generate core terraform module\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'core',\n 'api',\n options.constructType,\n ),\n joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'core', 'api'),\n { boto3Version: PY_VERSIONS.boto3, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Generate app specific terraform module\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'apis',\n options.constructType,\n ),\n joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'app', 'apis'),\n { ...options, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","addStarExport","addDependencyToTargetIfNotPresent","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","PY_VERSIONS","terraformProviderVersions","addApiGatewayInfra","tree","options","iac","addApiGatewayCdkConstructs","addApiGatewayTerraformModules","Error","config","apiProjectName","generateCoreApiFile","name","dirname","overwriteStrategy","KeepExisting","constructType","backend","type","apiNameKebabCase","boto3Version","boto3"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,UAAU,QACL,aAAa;A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BACEK,cACAC,uBACA,OACA,OACA,QACA,aAEF,CAAC,EAAE,EAAEM,QAAQe,gBAAgB,CAAC,GAAG,CAAC;IAEpC,MAAMxB,cACJQ,MACAX,kBACEK,cACAC,uBACA,OACA,OACA,aAEF;AAEJ;AAEA;;CAEC,GACD,MAAMS,gCAAgC,CACpCJ,MACAC;IAEA,iCAAiC;IACjCb,cACEY,MACAX,kBACE,YAAYqB,OAAO,EACnB,SACA,aACA,QACA,OACAT,QAAQY,aAAa,GAEvBxB,kBAAkBK,cAAcE,sBAAsB,OAAO,QAAQ,QACrE;QAAEqB,cAAcpB,YAAYqB,KAAK;QAAE,GAAGpB,2BAA2B;IAAC,GAClE;QACEa,mBAAmBrB,kBAAkBsB,YAAY;IACnD;IAGF,yCAAyC;IACzCxB,cACEY,MACAX,kBACE,YAAYqB,OAAO,EACnB,SACA,aACA,OACA,QACAT,QAAQY,aAAa,GAEvBxB,kBAAkBK,cAAcE,sBAAsB,OAAO,OAAO,SACpE;QAAE,GAAGK,OAAO;QAAE,GAAGH,2BAA2B;IAAC,GAC7C;QACEa,mBAAmBrB,kBAAkBsB,YAAY;IACnD;AAEJ"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/api-constructs/api-constructs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { addStarExport } from '../ast';\nimport type { Iac } from '../iac';\nimport { esmVars } from '../module-format';\nimport { addDependencyToTargetIfNotPresent } from '../nx';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants';\nimport { PY_VERSIONS, terraformProviderVersions } from '../versions';\n\ninterface BackendOptions {\n type: 'trpc' | 'fastapi' | 'smithy';\n integrationPattern: 'isolated' | 'shared';\n}\n\nexport interface TrpcBackendOptions extends BackendOptions {\n type: 'trpc';\n projectAlias: string;\n bundleOutputDir: string;\n authorizerBundleOutputDir?: string;\n}\n\nexport interface FastApiBackendOptions extends BackendOptions {\n type: 'fastapi';\n moduleName: string;\n bundleOutputDir: string;\n}\n\nexport interface SmithyBackendOptions extends BackendOptions {\n type: 'smithy';\n bundleOutputDir: string;\n authorizerBundleOutputDir?: string;\n}\n\nexport interface AddApiGatewayConstructOptions {\n apiProjectName: string;\n apiNameClassName: string;\n apiNameKebabCase: string;\n constructType: 'http' | 'rest';\n backend: TrpcBackendOptions | FastApiBackendOptions | SmithyBackendOptions;\n auth: 'iam' | 'cognito' | 'custom';\n}\n\nexport const addApiGatewayInfra = async (\n tree: Tree,\n options: AddApiGatewayConstructOptions & { iac: Iac },\n) => {\n if (options.iac === 'cdk') {\n await addApiGatewayCdkConstructs(tree, options);\n } else if (options.iac === 'terraform') {\n addApiGatewayTerraformModules(tree, options);\n } else {\n throw new Error(`Unsupported iac ${options.iac}`);\n }\n\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.apiProjectName}:build`,\n );\n return config;\n },\n );\n};\n\n/**\n * Add an API CDK construct, and update the Runtime Config type to export its url\n */\nconst addApiGatewayCdkConstructs = async (\n tree: Tree,\n options: AddApiGatewayConstructOptions,\n) => {\n const generateCoreApiFile = (name: string) => {\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'core',\n 'api',\n name,\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'api',\n ),\n { ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n };\n\n // Generate relevant core CDK construct and utilities\n generateCoreApiFile(options.constructType);\n generateCoreApiFile('utils');\n if (options.backend.type === 'trpc') {\n generateCoreApiFile('trpc');\n }\n\n // Generate app specific CDK construct\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'app',\n 'apis',\n options.constructType,\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'apis',\n ),\n { ...options, ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Export app specific CDK construct\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'apis',\n 'index.ts',\n ),\n `./${options.apiNameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n './apis/index.js',\n );\n};\n\n/**\n * Add an API terraform module, and update the Runtime Config type to export its url\n */\nconst addApiGatewayTerraformModules = (\n tree: Tree,\n options: AddApiGatewayConstructOptions,\n) => {\n // Generate core terraform module\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'core',\n 'api',\n options.constructType,\n ),\n joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'core', 'api'),\n { boto3Version: PY_VERSIONS.boto3, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Generate app specific terraform module\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'apis',\n options.constructType,\n ),\n joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'app', 'apis'),\n { ...options, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","addStarExport","esmVars","addDependencyToTargetIfNotPresent","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","PY_VERSIONS","terraformProviderVersions","addApiGatewayInfra","tree","options","iac","addApiGatewayCdkConstructs","addApiGatewayTerraformModules","Error","config","apiProjectName","generateCoreApiFile","name","dirname","overwriteStrategy","KeepExisting","constructType","backend","type","apiNameKebabCase","boto3Version","boto3"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,UAAU,QACL,aAAa;AACpB,SAASC,aAAa,QAAQ,YAAS;AAEvC,SAASC,OAAO,QAAQ,sBAAmB;AAC3C,SAASC,iCAAiC,QAAQ,WAAQ;AAC1D,SACEC,YAAY,EACZC,qBAAqB,EACrBC,oBAAoB,QACf,oCAAiC;AACxC,SAASC,WAAW,EAAEC,yBAAyB,QAAQ,iBAAc;AAmCrE,OAAO,MAAMC,qBAAqB,OAChCC,MACAC;IAEA,IAAIA,QAAQC,GAAG,KAAK,OAAO;QACzB,MAAMC,2BAA2BH,MAAMC;IACzC,OAAO,IAAIA,QAAQC,GAAG,KAAK,aAAa;QACtCE,8BAA8BJ,MAAMC;IACtC,OAAO;QACL,MAAM,IAAII,MAAM,CAAC,gBAAgB,EAAEJ,QAAQC,GAAG,EAAE;IAClD;IAEAZ,WACEU,MACAZ,kBACEM,cACAO,QAAQC,GAAG,KAAK,QAAQP,wBAAwBC,sBAChD,iBAEF,CAACU;QACCb,kCACEa,QACA,SACA,GAAGL,QAAQM,cAAc,CAAC,MAAM,CAAC;QAEnC,OAAOD;IACT;AAEJ,EAAE;AAEF;;CAEC,GACD,MAAMH,6BAA6B,OACjCH,MACAC;IAEA,MAAMO,sBAAsB,CAACC;QAC3BtB,cACEa,MACAZ,kBACE,YAAYsB,OAAO,EACnB,SACA,OACA,QACA,OACAD,OAEFrB,kBACEM,cACAC,uBACA,OACA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"}
@@ -13,7 +13,7 @@ import {
13
13
  <%_ } _%>
14
14
  } from 'aws-cdk-lib/aws-lambda';
15
15
  import { Duration<%_ if (backend.type === 'fastapi') { _%>, Stack<%_ } _%> } from 'aws-cdk-lib';
16
- import { RuntimeConfig } from '../../core/runtime-config.js';
16
+ import { RuntimeConfig } from '../../core/runtime-config<% if (esm) { %>.js<% } %>';
17
17
  import {
18
18
  CorsHttpMethod,
19
19
  CfnApi,
@@ -41,10 +41,10 @@ import {
41
41
  ApiIntegrations,
42
42
  HttpApiIntegration,
43
43
  IntegrationBuilder,
44
- } from '../../core/api/utils.js';
45
- import { HttpApi } from '../../core/api/http-api.js';
44
+ } from '../../core/api/utils<% if (esm) { %>.js<% } %>';
45
+ import { HttpApi } from '../../core/api/http-api<% if (esm) { %>.js<% } %>';
46
46
  <%_ if (backend.type === 'trpc') { _%>
47
- import { Procedures, routerToOperations } from '../../core/api/trpc-utils.js';
47
+ import { Procedures, routerToOperations } from '../../core/api/trpc-utils<% if (esm) { %>.js<% } %>';
48
48
  import { AppRouter, appRouter } from '<%= backend.projectAlias %>';
49
49
 
50
50
  // String union type for all API operation names
@@ -116,7 +116,7 @@ export class <%= apiNameClassName %><
116
116
  url.fileURLToPath(
117
117
  new URL(
118
118
  '../../../../../../<%- backend.bundleOutputDir %>',
119
- import.meta.url,
119
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
120
120
  ),
121
121
  ),
122
122
  ),
@@ -127,7 +127,7 @@ export class <%= apiNameClassName %><
127
127
  url.fileURLToPath(
128
128
  new URL(
129
129
  '../../../../../../<%- backend.bundleOutputDir %>',
130
- import.meta.url,
130
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
131
131
  ),
132
132
  ),
133
133
  ),
@@ -184,7 +184,7 @@ export class <%= apiNameClassName %><
184
184
  url.fileURLToPath(
185
185
  new URL(
186
186
  '../../../../../../<%- backend.authorizerBundleOutputDir %>',
187
- import.meta.url,
187
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
188
188
  ),
189
189
  ),
190
190
  ),
@@ -195,7 +195,7 @@ export class <%= apiNameClassName %><
195
195
  url.fileURLToPath(
196
196
  new URL(
197
197
  '../../../../../../<%- backend.bundleOutputDir %>',
198
- import.meta.url,
198
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
199
199
  ),
200
200
  ),
201
201
  ),
@@ -12,7 +12,7 @@ import {
12
12
  SnapStartConf,
13
13
  <%_ } _%>
14
14
  } from 'aws-cdk-lib/aws-lambda';
15
- import { RuntimeConfig } from '../../core/runtime-config.js';
15
+ import { RuntimeConfig } from '../../core/runtime-config<% if (esm) { %>.js<% } %>';
16
16
  import {
17
17
  AuthorizationType,
18
18
  LambdaIntegration,
@@ -44,10 +44,10 @@ import {
44
44
  ApiIntegrations,
45
45
  IntegrationBuilder,
46
46
  RestApiIntegration,
47
- } from '../../core/api/utils.js';
48
- import { AddCorsPreflightAspect, RestApi } from '../../core/api/rest-api.js';
47
+ } from '../../core/api/utils<% if (esm) { %>.js<% } %>';
48
+ import { AddCorsPreflightAspect, RestApi } from '../../core/api/rest-api<% if (esm) { %>.js<% } %>';
49
49
  <%_ if (backend.type === 'trpc') { _%>
50
- import { Procedures, routerToOperations } from '../../core/api/trpc-utils.js';
50
+ import { Procedures, routerToOperations } from '../../core/api/trpc-utils<% if (esm) { %>.js<% } %>';
51
51
  import { AppRouter, appRouter } from '<%= backend.projectAlias %>';
52
52
 
53
53
  // String union type for all API operation names
@@ -126,7 +126,7 @@ export class <%= apiNameClassName %><
126
126
  url.fileURLToPath(
127
127
  new URL(
128
128
  '../../../../../../<%- backend.bundleOutputDir %>',
129
- import.meta.url,
129
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
130
130
  ),
131
131
  ),
132
132
  ),
@@ -137,7 +137,7 @@ export class <%= apiNameClassName %><
137
137
  url.fileURLToPath(
138
138
  new URL(
139
139
  '../../../../../../<%- backend.bundleOutputDir %>',
140
- import.meta.url,
140
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
141
141
  ),
142
142
  ),
143
143
  ),
@@ -204,7 +204,7 @@ export class <%= apiNameClassName %><
204
204
  url.fileURLToPath(
205
205
  new URL(
206
206
  '../../../../../../<%- backend.authorizerBundleOutputDir %>',
207
- import.meta.url,
207
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
208
208
  ),
209
209
  ),
210
210
  ),
@@ -215,7 +215,7 @@ export class <%= apiNameClassName %><
215
215
  url.fileURLToPath(
216
216
  new URL(
217
217
  '../../../../../../<%- backend.bundleOutputDir %>',
218
- import.meta.url,
218
+ <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>,
219
219
  ),
220
220
  ),
221
221
  ),
@@ -1,10 +1,10 @@
1
1
  import { Construct } from 'constructs';
2
- import { RuntimeConfig } from '../runtime-config.js';
2
+ import { RuntimeConfig } from '../runtime-config<% if (esm) { %>.js<% } %>';
3
3
  import {
4
4
  ApiIntegrations,
5
5
  HttpApiIntegration,
6
6
  OperationDetails,
7
- } from './utils.js';
7
+ } from './utils<% if (esm) { %>.js<% } %>';
8
8
  import { CfnOutput, Stack } from 'aws-cdk-lib';
9
9
  import {
10
10
  HttpApi as _HttpApi,
@@ -17,7 +17,7 @@ import {
17
17
  import { LogGroup } from 'aws-cdk-lib/aws-logs';
18
18
  import { Key } from 'aws-cdk-lib/aws-kms';
19
19
  import { ServicePrincipal } from 'aws-cdk-lib/aws-iam';
20
- import { suppressRules } from '../checkov.js';
20
+ import { suppressRules } from '../checkov<% if (esm) { %>.js<% } %>';
21
21
 
22
22
  /**
23
23
  * Properties for creating an HttpApi construct.
@@ -16,32 +16,23 @@ const iam = new IAMClient();
16
16
 
17
17
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
18
18
 
19
- const hasLiveRole = async () => {
20
- const { cloudwatchRoleArn } = await apigw.send(new GetAccountCommand({}));
21
- if (!cloudwatchRoleArn) return false;
22
- try {
23
- await iam.send(
24
- new GetRoleCommand({ RoleName: cloudwatchRoleArn.split('/').pop() }),
25
- );
26
- return true;
27
- } catch (e) {
28
- if (e.name === 'NoSuchEntityException') return false;
29
- throw e;
30
- }
31
- };
32
-
33
19
  const RETRYABLE = ['BadRequestException', 'TooManyRequestsException'];
34
20
 
35
- const setRole = async (value) => {
36
- const command = new UpdateAccountCommand({
37
- patchOperations: [{ op: 'replace', path: '/cloudwatchRoleArn', value }],
38
- });
39
- // Retry while the freshly created role propagates through IAM, and on throttling
21
+ // Throttling may surface as a bare 429 with no modeled error code, so check
22
+ // response metadata as well as error names
23
+ const isRetryable = (e) =>
24
+ RETRYABLE.includes(e.name) ||
25
+ e.$metadata?.httpStatusCode === 429 ||
26
+ e.$retryable?.throttling === true;
27
+
28
+ // Retry while the freshly created role propagates through IAM, and on
29
+ // throttling of the account-level API (shared across concurrent deployments)
30
+ const send = async (command) => {
40
31
  for (let attempt = 0; ; attempt++) {
41
32
  try {
42
33
  return await apigw.send(command);
43
34
  } catch (e) {
44
- if (RETRYABLE.includes(e.name) && attempt < 11) {
35
+ if (isRetryable(e) && attempt < 11) {
45
36
  await sleep(5000);
46
37
  } else {
47
38
  throw e;
@@ -50,6 +41,27 @@ const setRole = async (value) => {
50
41
  }
51
42
  };
52
43
 
44
+ const hasLiveRole = async () => {
45
+ const { cloudwatchRoleArn } = await send(new GetAccountCommand({}));
46
+ if (!cloudwatchRoleArn) return false;
47
+ try {
48
+ await iam.send(
49
+ new GetRoleCommand({ RoleName: cloudwatchRoleArn.split('/').pop() }),
50
+ );
51
+ return true;
52
+ } catch (e) {
53
+ if (e.name === 'NoSuchEntityException') return false;
54
+ throw e;
55
+ }
56
+ };
57
+
58
+ const setRole = (value) =>
59
+ send(
60
+ new UpdateAccountCommand({
61
+ patchOperations: [{ op: 'replace', path: '/cloudwatchRoleArn', value }],
62
+ }),
63
+ );
64
+
53
65
  exports.handler = async (event) => {
54
66
  if (event.RequestType !== 'Delete' && !(await hasLiveRole())) {
55
67
  await setRole(event.ResourceProperties.CloudWatchRoleArn);
@@ -50,7 +50,7 @@ export class ApiGatewayAccount extends Construct {
50
50
  handler: 'index.handler',
51
51
  timeout: Duration.minutes(2),
52
52
  code: Code.fromAsset(
53
- url.fileURLToPath(new URL('./api-gateway-account', import.meta.url)),
53
+ url.fileURLToPath(new URL('./api-gateway-account', <% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>)),
54
54
  ),
55
55
  });
56
56
  const { region } = Stack.of(this);
@@ -19,14 +19,14 @@ import {
19
19
  import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
20
20
  import { Key } from 'aws-cdk-lib/aws-kms';
21
21
  import { ServicePrincipal } from 'aws-cdk-lib/aws-iam';
22
- import { RuntimeConfig } from '../runtime-config.js';
23
- import { ApiGatewayAccount } from './api-gateway-account.js';
22
+ import { RuntimeConfig } from '../runtime-config<% if (esm) { %>.js<% } %>';
23
+ import { ApiGatewayAccount } from './api-gateway-account<% if (esm) { %>.js<% } %>';
24
24
  import {
25
25
  ApiIntegrations,
26
26
  OperationDetails,
27
27
  RestApiIntegration,
28
- } from './utils.js';
29
- import { suppressRules } from '../checkov.js';
28
+ } from './utils<% if (esm) { %>.js<% } %>';
29
+ import { suppressRules } from '../checkov<% if (esm) { %>.js<% } %>';
30
30
 
31
31
  /**
32
32
  * Properties for creating a RestApi construct.
@@ -1,5 +1,5 @@
1
1
  import { TRPCRouterRecord, AnyTRPCRouter } from '@trpc/server';
2
- import { OperationDetails } from './utils.js';
2
+ import { OperationDetails } from './utils<% if (esm) { %>.js<% } %>';
3
3
  import { HttpMethod } from 'aws-cdk-lib/aws-apigatewayv2';
4
4
 
5
5
  /**
package/src/utils/ast.js CHANGED
@@ -4,7 +4,20 @@
4
4
  */ import { QueryBuilder } from "@getgrit/gritql";
5
5
  import * as path from "path";
6
6
  import { updateGitIgnore } from "./git.js";
7
+ import { isEsmWorkspace } from "./module-format.js";
7
8
  const GRIT_DIR = '.grit';
9
+ /**
10
+ * Normalize a relative module specifier for the workspace's module format.
11
+ * ESM (`nodenext`) requires an explicit `.js` extension on relative imports;
12
+ * CommonJS (`node16`) resolves them extensionless. Callers always pass the ESM
13
+ * form (with `.js`); this strips the extension for CommonJS workspaces.
14
+ */ const normalizeModuleSpecifier = (tree, from)=>{
15
+ if (isEsmWorkspace(tree)) {
16
+ return from;
17
+ }
18
+ const isRelative = from.startsWith('./') || from.startsWith('../');
19
+ return isRelative && from.endsWith('.js') ? from.slice(0, -'.js'.length) : from;
20
+ };
8
21
  // Pin the gritql native library's "global" stdlib directory to <workspace>/.grit so it doesn't try to write to /usr/local/.grit (or wherever node's grandparent resolves to).
9
22
  const ensureGritDir = (tree)=>{
10
23
  process.env.GRIT_GLOBAL_DIR ??= path.join(tree.root, GRIT_DIR);
@@ -20,6 +33,7 @@ const assertFilePath = (tree, filePath)=>{
20
33
  };
21
34
  export const addDestructuredImport = async (tree, filePath, variableNames, from)=>{
22
35
  assertFilePath(tree, filePath);
36
+ from = normalizeModuleSpecifier(tree, from);
23
37
  // Check if there's an existing import from this module
24
38
  const hasExistingImport = await matchGritQL(tree, filePath, `\`import { $_ } from '${from}'\``);
25
39
  if (hasExistingImport) {
@@ -89,6 +103,7 @@ export const addDestructuredImport = async (tree, filePath, variableNames, from)
89
103
  * if it doesn't already exist
90
104
  */ export const addSingleImport = async (tree, filePath, variableName, from)=>{
91
105
  assertFilePath(tree, filePath);
106
+ from = normalizeModuleSpecifier(tree, from);
92
107
  // Check if default import already exists using GritQL
93
108
  const alreadyImported = await matchGritQL(tree, filePath, `\`import ${variableName} from '${from}'\``);
94
109
  if (alreadyImported) {
@@ -102,6 +117,7 @@ export const addDestructuredImport = async (tree, filePath, variableNames, from)
102
117
  * Adds an `export * from '<from>'; statement to the given TypeScript file.
103
118
  * Note that this will create the file if it does not exist in the tree.
104
119
  */ export const addStarExport = async (tree, filePath, from)=>{
120
+ from = normalizeModuleSpecifier(tree, from);
105
121
  const contents = tree.read(filePath)?.toString() ?? '';
106
122
  // For empty/non-existent files, just write the export
107
123
  if (!contents.trim()) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/ast.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { QueryBuilder } from '@getgrit/gritql';\nimport type { Tree } from '@nx/devkit';\nimport * as path from 'path';\nimport { updateGitIgnore } from './git';\n\nconst GRIT_DIR = '.grit';\n\n// Pin the gritql native library's \"global\" stdlib directory to <workspace>/.grit so it doesn't try to write to /usr/local/.grit (or wherever node's grandparent resolves to).\nconst ensureGritDir = (tree: Tree) => {\n process.env.GRIT_GLOBAL_DIR ??= path.join(tree.root, GRIT_DIR);\n updateGitIgnore(tree, '.', (patterns) => [...patterns, GRIT_DIR]);\n};\n\nconst assertFilePath = (tree: Tree, filePath: string) => {\n if (!tree.exists(filePath)) {\n throw new Error(`No file located at ${filePath}`);\n }\n};\n\nexport const addDestructuredImport = async (\n tree: Tree,\n filePath: string,\n variableNames: string[],\n from: string,\n) => {\n assertFilePath(tree, filePath);\n\n // Check if there's an existing import from this module\n const hasExistingImport = await matchGritQL(\n tree,\n filePath,\n `\\`import { $_ } from '${from}'\\``,\n );\n\n if (hasExistingImport) {\n // For each new variable, use GritQL rewrite to add it if not already present\n for (const variableName of variableNames) {\n const localName = variableName.includes(' as ')\n ? variableName.split(' as ')[1]\n : variableName;\n // Use rewrite (=>) which correctly handles comma-separated import specifier lists\n await applyGritQL(\n tree,\n filePath,\n `\\`import { $imports } from '${from}'\\` => \\`import { $imports, ${variableName} } from '${from}'\\` where { $imports <: not contains \\`${localName}\\` }`,\n );\n }\n } else {\n // No existing import — prepend a new one (after shebang if present)\n const specifiers = variableNames.join(', ');\n const contents = tree.read(filePath)!.toString();\n const newImport = `import { ${specifiers} } from '${from}';\\n`;\n if (contents.startsWith('#!')) {\n const newlineIndex = contents.indexOf('\\n');\n tree.write(\n filePath,\n `${contents.substring(0, newlineIndex + 1)}${newImport}${contents.substring(newlineIndex + 1)}`,\n );\n } else {\n tree.write(filePath, `${newImport}${contents}`);\n }\n }\n};\n\n/**\n * Ensure a Python `from <module> import <name1>, <name2>, ...` statement\n * exists in the given file. If the module already has a `from <module> import`\n * line, any missing names are appended; otherwise a fresh import statement is\n * prepended to the file (ruff's import sorter will reorder it into place on\n * the next format pass).\n *\n * We try to append first (which only succeeds if an import-from for the\n * module already exists AND the name isn't yet in the list). If nothing\n * was rewritten after trying every requested name, we fall back to checking\n * whether the module is imported at all; if not, we prepend a fresh\n * `from <module> import ...` line.\n */\nexport const addPythonDestructuredImport = async (\n tree: Tree,\n filePath: string,\n variableNames: string[],\n from: string,\n) => {\n assertFilePath(tree, filePath);\n\n // Determine whether there's any `from <module> import ...` line in the file.\n // We detect this by attempting a no-op transformation — the file is unchanged,\n // but a successful match tells us the line exists.\n const beforeContents = tree.read(filePath)!.toString();\n let moduleAlreadyImported = false;\n for (const variableName of variableNames) {\n // Appends the name if the import-from exists and the name isn't already there.\n const appended = await applyGritQL(\n tree,\n filePath,\n `language python\\n\\`from ${from} import $names\\` where { $names <: not contains \\`${variableName}\\`, $names += \\`, ${variableName}\\` }`,\n );\n if (appended) {\n moduleAlreadyImported = true;\n }\n }\n\n // If the append succeeded for at least one name, we know the module line\n // exists; we're done. If nothing was appended we need to distinguish\n // between \"module not imported\" (need to add a new line) and \"module\n // imported but all names already present\" (no-op).\n if (moduleAlreadyImported) {\n return;\n }\n\n const allAlreadyPresent = await matchGritQL(\n tree,\n filePath,\n `language python\\n\\`from ${from} import $names\\` where { ${variableNames\n .map((n) => `$names <: contains \\`${n}\\``)\n .join(', ')} }`,\n );\n if (allAlreadyPresent) {\n return;\n }\n\n // No existing `from <module> import` line — prepend one. Ruff's import\n // sorter will place it in the right group on the next formatter pass.\n const specifiers = variableNames.join(', ');\n tree.write(filePath, `from ${from} import ${specifiers}\\n${beforeContents}`);\n};\n\n/**\n * Adds an `import <variableName> from '<from>'; statement to the beginning of the file,\n * if it doesn't already exist\n */\nexport const addSingleImport = async (\n tree: Tree,\n filePath: string,\n variableName: string,\n from: string,\n) => {\n assertFilePath(tree, filePath);\n\n // Check if default import already exists using GritQL\n const alreadyImported = await matchGritQL(\n tree,\n filePath,\n `\\`import ${variableName} from '${from}'\\``,\n );\n if (alreadyImported) {\n return;\n }\n\n // Prepend new import to file\n const contents = tree.read(filePath)!.toString();\n tree.write(filePath, `import ${variableName} from '${from}';\\n${contents}`);\n};\n\n/**\n * Adds an `export * from '<from>'; statement to the given TypeScript file.\n * Note that this will create the file if it does not exist in the tree.\n */\nexport const addStarExport = async (\n tree: Tree,\n filePath: string,\n from: string,\n) => {\n const contents = tree.read(filePath)?.toString() ?? '';\n\n // For empty/non-existent files, just write the export\n if (!contents.trim()) {\n tree.write(filePath, `export * from '${from}';\\n`);\n return;\n }\n\n // Check if already exported using GritQL\n const alreadyExported = await matchGritQL(\n tree,\n filePath,\n `\\`export * from '${from}'\\``,\n );\n if (alreadyExported) {\n return;\n }\n\n // Prepend new export to file\n tree.write(filePath, `export * from '${from}';\\n${contents}`);\n};\n\n/**\n * Return whether or not the given identifier is exported in the source file.\n * Checks for both `export { Identifier }` and `export type Identifier = ...`.\n */\nexport const hasExportDeclaration = async (\n tree: Tree,\n source: string,\n identifierName: string,\n): Promise<boolean> => {\n ensureGritDir(tree);\n const patterns = [\n `\\`export type ${identifierName} = $_\\``,\n `\\`export { ${identifierName} }\\``,\n `\\`export type { ${identifierName} } from $_\\``,\n ];\n\n for (const pattern of patterns) {\n try {\n const q = new QueryBuilder(`$p => $p where { $p <: ${pattern} }`);\n const result = await q.applyToFile({\n path: 'check.ts',\n content: source,\n });\n if (result !== null) return true;\n } catch {\n // Pattern didn't match, try next\n }\n }\n\n return false;\n};\n\n/**\n * Apply a GritQL pattern to a file in the Nx tree.\n */\nexport const applyGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<boolean> => {\n if (!tree.exists(filePath)) throw new Error(`No file at ${filePath}`);\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n const query = new QueryBuilder(pattern);\n const result = await query.applyToFile({ path: filePath, content: source });\n if (result && result.content !== source) {\n tree.write(filePath, result.content);\n return true;\n }\n return false;\n};\n\n/**\n * Check whether a GritQL pattern matches anywhere in a file.\n * Returns true if the pattern matches at least once.\n *\n * Accepts raw GritQL, including patterns that start with a `language <name>`\n * header (e.g. `language python\\n\\`print($_)\\``) — the pattern is passed\n * straight through to QueryBuilder without any wrapping rewrite.\n */\nexport const matchGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<boolean> => {\n if (!tree.exists(filePath)) return false;\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n let matched = false;\n try {\n const query = new QueryBuilder(pattern);\n query.filter(() => {\n matched = true;\n return true;\n });\n await query.applyToFile({ path: filePath, content: source });\n } catch {\n return false;\n }\n return matched;\n};\n\n/**\n * Capture the source text of the first match of a GritQL pattern.\n *\n * For example `` `dependencyCheck: $_` `` returns the whole\n * `dependencyCheck: { ... }` property text. Returns undefined if nothing\n * matches. The file is not modified.\n */\nexport const captureGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<string | undefined> => {\n if (!tree.exists(filePath)) return undefined;\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n let captured: string | undefined;\n try {\n const query = new QueryBuilder(pattern);\n query.filter((node) => {\n captured ??= node.text();\n return true;\n });\n await query.applyToFile({ path: filePath, content: source });\n } catch {\n return undefined;\n }\n return captured;\n};\n\n/**\n * Return the text of every node matching the GritQL pattern, in document order.\n */\nexport const captureAllGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<string[]> => {\n if (!tree.exists(filePath)) return [];\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n const captured: string[] = [];\n try {\n const query = new QueryBuilder(pattern);\n query.filter((node) => {\n captured.push(node.text());\n return true;\n });\n await query.applyToFile({ path: filePath, content: source });\n } catch {\n return [];\n }\n return captured;\n};\n\n/**\n * A unique token that is a valid identifier, so it can stand in for an array\n * element or object property inside a GritQL rewrite.\n */\nexport const GRIT_INSERT_PLACEHOLDER = '__GRIT_INSERT_PLACEHOLDER__';\n\n/**\n * Apply a GritQL rewrite that inserts {@link GRIT_INSERT_PLACEHOLDER}, then\n * replace the placeholder with `text`. Routing user-provided text through a\n * placeholder keeps it out of the GritQL pattern, where quotes, backticks or\n * `${...}` would otherwise break parsing.\n *\n * Any separator (e.g. a leading `, ` when appending to an array) must be part\n * of the GritQL pattern, not `text`. The one adjustment made here: if the\n * placeholder lands after a trailing line comment (`// ...`) — which would\n * comment out the text — the text is moved to its own line.\n *\n * The caller formats afterwards. Returns true if the pattern matched and the\n * file changed.\n */\nexport const insertViaGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n text: string,\n): Promise<boolean> => {\n if (!(await applyGritQL(tree, filePath, pattern))) return false;\n const content = tree.read(filePath)!.toString();\n const at = content.indexOf(GRIT_INSERT_PLACEHOLDER);\n const lineSoFar = content.slice(content.lastIndexOf('\\n', at) + 1, at);\n const replacement = lineSoFar.includes('//') ? `\\n${text}` : text;\n\n // Function replacer so `$` in `text` isn't treated as a replacement pattern.\n tree.write(\n filePath,\n content.replace(GRIT_INSERT_PLACEHOLDER, () => replacement),\n );\n return true;\n};\n"],"names":["QueryBuilder","path","updateGitIgnore","GRIT_DIR","ensureGritDir","tree","process","env","GRIT_GLOBAL_DIR","join","root","patterns","assertFilePath","filePath","exists","Error","addDestructuredImport","variableNames","from","hasExistingImport","matchGritQL","variableName","localName","includes","split","applyGritQL","specifiers","contents","read","toString","newImport","startsWith","newlineIndex","indexOf","write","substring","addPythonDestructuredImport","beforeContents","moduleAlreadyImported","appended","allAlreadyPresent","map","n","addSingleImport","alreadyImported","addStarExport","trim","alreadyExported","hasExportDeclaration","source","identifierName","pattern","q","result","applyToFile","content","query","matched","filter","captureGritQL","undefined","captured","node","text","captureAllGritQL","push","GRIT_INSERT_PLACEHOLDER","insertViaGritQL","at","lineSoFar","slice","lastIndexOf","replacement","replace"],"mappings":"AAAA;;;CAGC,GAED,SAASA,YAAY,QAAQ,kBAAkB;AAE/C,YAAYC,UAAU,OAAO;AAC7B,SAASC,eAAe,QAAQ,WAAQ;AAExC,MAAMC,WAAW;AAEjB,8KAA8K;AAC9K,MAAMC,gBAAgB,CAACC;IACrBC,QAAQC,GAAG,CAACC,eAAe,KAAKP,KAAKQ,IAAI,CAACJ,KAAKK,IAAI,EAAEP;IACrDD,gBAAgBG,MAAM,KAAK,CAACM,WAAa;eAAIA;YAAUR;SAAS;AAClE;AAEA,MAAMS,iBAAiB,CAACP,MAAYQ;IAClC,IAAI,CAACR,KAAKS,MAAM,CAACD,WAAW;QAC1B,MAAM,IAAIE,MAAM,CAAC,mBAAmB,EAAEF,UAAU;IAClD;AACF;AAEA,OAAO,MAAMG,wBAAwB,OACnCX,MACAQ,UACAI,eACAC;IAEAN,eAAeP,MAAMQ;IAErB,uDAAuD;IACvD,MAAMM,oBAAoB,MAAMC,YAC9Bf,MACAQ,UACA,CAAC,sBAAsB,EAAEK,KAAK,GAAG,CAAC;IAGpC,IAAIC,mBAAmB;QACrB,6EAA6E;QAC7E,KAAK,MAAME,gBAAgBJ,cAAe;YACxC,MAAMK,YAAYD,aAAaE,QAAQ,CAAC,UACpCF,aAAaG,KAAK,CAAC,OAAO,CAAC,EAAE,GAC7BH;YACJ,kFAAkF;YAClF,MAAMI,YACJpB,MACAQ,UACA,CAAC,4BAA4B,EAAEK,KAAK,4BAA4B,EAAEG,aAAa,SAAS,EAAEH,KAAK,uCAAuC,EAAEI,UAAU,IAAI,CAAC;QAE3J;IACF,OAAO;QACL,oEAAoE;QACpE,MAAMI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AMtC,YAAYpB,MAAMQ,UAAUsC,UAAW,OAAO;IAC1D,MAAMI,UAAUlD,KAAKuB,IAAI,CAACf,UAAWgB,QAAQ;IAC7C,MAAMuC,KAAKb,QAAQtB,OAAO,CAACiC;IAC3B,MAAMG,YAAYd,QAAQe,KAAK,CAACf,QAAQgB,WAAW,CAAC,MAAMH,MAAM,GAAGA;IACnE,MAAMI,cAAcH,UAAU9C,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAEwC,MAAM,GAAGA;IAE7D,6EAA6E;IAC7E1D,KAAK6B,KAAK,CACRrB,UACA0C,QAAQkB,OAAO,CAACP,yBAAyB,IAAMM;IAEjD,OAAO;AACT,EAAE"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/ast.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { QueryBuilder } from '@getgrit/gritql';\nimport type { Tree } from '@nx/devkit';\nimport * as path from 'path';\nimport { updateGitIgnore } from './git';\nimport { isEsmWorkspace } from './module-format';\n\nconst GRIT_DIR = '.grit';\n\n/**\n * Normalize a relative module specifier for the workspace's module format.\n * ESM (`nodenext`) requires an explicit `.js` extension on relative imports;\n * CommonJS (`node16`) resolves them extensionless. Callers always pass the ESM\n * form (with `.js`); this strips the extension for CommonJS workspaces.\n */\nconst normalizeModuleSpecifier = (tree: Tree, from: string): string => {\n if (isEsmWorkspace(tree)) {\n return from;\n }\n const isRelative = from.startsWith('./') || from.startsWith('../');\n return isRelative && from.endsWith('.js') ? from.slice(0, -'.js'.length) : from;\n};\n\n// Pin the gritql native library's \"global\" stdlib directory to <workspace>/.grit so it doesn't try to write to /usr/local/.grit (or wherever node's grandparent resolves to).\nconst ensureGritDir = (tree: Tree) => {\n process.env.GRIT_GLOBAL_DIR ??= path.join(tree.root, GRIT_DIR);\n updateGitIgnore(tree, '.', (patterns) => [...patterns, GRIT_DIR]);\n};\n\nconst assertFilePath = (tree: Tree, filePath: string) => {\n if (!tree.exists(filePath)) {\n throw new Error(`No file located at ${filePath}`);\n }\n};\n\nexport const addDestructuredImport = async (\n tree: Tree,\n filePath: string,\n variableNames: string[],\n from: string,\n) => {\n assertFilePath(tree, filePath);\n from = normalizeModuleSpecifier(tree, from);\n\n // Check if there's an existing import from this module\n const hasExistingImport = await matchGritQL(\n tree,\n filePath,\n `\\`import { $_ } from '${from}'\\``,\n );\n\n if (hasExistingImport) {\n // For each new variable, use GritQL rewrite to add it if not already present\n for (const variableName of variableNames) {\n const localName = variableName.includes(' as ')\n ? variableName.split(' as ')[1]\n : variableName;\n // Use rewrite (=>) which correctly handles comma-separated import specifier lists\n await applyGritQL(\n tree,\n filePath,\n `\\`import { $imports } from '${from}'\\` => \\`import { $imports, ${variableName} } from '${from}'\\` where { $imports <: not contains \\`${localName}\\` }`,\n );\n }\n } else {\n // No existing import — prepend a new one (after shebang if present)\n const specifiers = variableNames.join(', ');\n const contents = tree.read(filePath)!.toString();\n const newImport = `import { ${specifiers} } from '${from}';\\n`;\n if (contents.startsWith('#!')) {\n const newlineIndex = contents.indexOf('\\n');\n tree.write(\n filePath,\n `${contents.substring(0, newlineIndex + 1)}${newImport}${contents.substring(newlineIndex + 1)}`,\n );\n } else {\n tree.write(filePath, `${newImport}${contents}`);\n }\n }\n};\n\n/**\n * Ensure a Python `from <module> import <name1>, <name2>, ...` statement\n * exists in the given file. If the module already has a `from <module> import`\n * line, any missing names are appended; otherwise a fresh import statement is\n * prepended to the file (ruff's import sorter will reorder it into place on\n * the next format pass).\n *\n * We try to append first (which only succeeds if an import-from for the\n * module already exists AND the name isn't yet in the list). If nothing\n * was rewritten after trying every requested name, we fall back to checking\n * whether the module is imported at all; if not, we prepend a fresh\n * `from <module> import ...` line.\n */\nexport const addPythonDestructuredImport = async (\n tree: Tree,\n filePath: string,\n variableNames: string[],\n from: string,\n) => {\n assertFilePath(tree, filePath);\n\n // Determine whether there's any `from <module> import ...` line in the file.\n // We detect this by attempting a no-op transformation — the file is unchanged,\n // but a successful match tells us the line exists.\n const beforeContents = tree.read(filePath)!.toString();\n let moduleAlreadyImported = false;\n for (const variableName of variableNames) {\n // Appends the name if the import-from exists and the name isn't already there.\n const appended = await applyGritQL(\n tree,\n filePath,\n `language python\\n\\`from ${from} import $names\\` where { $names <: not contains \\`${variableName}\\`, $names += \\`, ${variableName}\\` }`,\n );\n if (appended) {\n moduleAlreadyImported = true;\n }\n }\n\n // If the append succeeded for at least one name, we know the module line\n // exists; we're done. If nothing was appended we need to distinguish\n // between \"module not imported\" (need to add a new line) and \"module\n // imported but all names already present\" (no-op).\n if (moduleAlreadyImported) {\n return;\n }\n\n const allAlreadyPresent = await matchGritQL(\n tree,\n filePath,\n `language python\\n\\`from ${from} import $names\\` where { ${variableNames\n .map((n) => `$names <: contains \\`${n}\\``)\n .join(', ')} }`,\n );\n if (allAlreadyPresent) {\n return;\n }\n\n // No existing `from <module> import` line — prepend one. Ruff's import\n // sorter will place it in the right group on the next formatter pass.\n const specifiers = variableNames.join(', ');\n tree.write(filePath, `from ${from} import ${specifiers}\\n${beforeContents}`);\n};\n\n/**\n * Adds an `import <variableName> from '<from>'; statement to the beginning of the file,\n * if it doesn't already exist\n */\nexport const addSingleImport = async (\n tree: Tree,\n filePath: string,\n variableName: string,\n from: string,\n) => {\n assertFilePath(tree, filePath);\n from = normalizeModuleSpecifier(tree, from);\n\n // Check if default import already exists using GritQL\n const alreadyImported = await matchGritQL(\n tree,\n filePath,\n `\\`import ${variableName} from '${from}'\\``,\n );\n if (alreadyImported) {\n return;\n }\n\n // Prepend new import to file\n const contents = tree.read(filePath)!.toString();\n tree.write(filePath, `import ${variableName} from '${from}';\\n${contents}`);\n};\n\n/**\n * Adds an `export * from '<from>'; statement to the given TypeScript file.\n * Note that this will create the file if it does not exist in the tree.\n */\nexport const addStarExport = async (\n tree: Tree,\n filePath: string,\n from: string,\n) => {\n from = normalizeModuleSpecifier(tree, from);\n const contents = tree.read(filePath)?.toString() ?? '';\n\n // For empty/non-existent files, just write the export\n if (!contents.trim()) {\n tree.write(filePath, `export * from '${from}';\\n`);\n return;\n }\n\n // Check if already exported using GritQL\n const alreadyExported = await matchGritQL(\n tree,\n filePath,\n `\\`export * from '${from}'\\``,\n );\n if (alreadyExported) {\n return;\n }\n\n // Prepend new export to file\n tree.write(filePath, `export * from '${from}';\\n${contents}`);\n};\n\n/**\n * Return whether or not the given identifier is exported in the source file.\n * Checks for both `export { Identifier }` and `export type Identifier = ...`.\n */\nexport const hasExportDeclaration = async (\n tree: Tree,\n source: string,\n identifierName: string,\n): Promise<boolean> => {\n ensureGritDir(tree);\n const patterns = [\n `\\`export type ${identifierName} = $_\\``,\n `\\`export { ${identifierName} }\\``,\n `\\`export type { ${identifierName} } from $_\\``,\n ];\n\n for (const pattern of patterns) {\n try {\n const q = new QueryBuilder(`$p => $p where { $p <: ${pattern} }`);\n const result = await q.applyToFile({\n path: 'check.ts',\n content: source,\n });\n if (result !== null) return true;\n } catch {\n // Pattern didn't match, try next\n }\n }\n\n return false;\n};\n\n/**\n * Apply a GritQL pattern to a file in the Nx tree.\n */\nexport const applyGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<boolean> => {\n if (!tree.exists(filePath)) throw new Error(`No file at ${filePath}`);\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n const query = new QueryBuilder(pattern);\n const result = await query.applyToFile({ path: filePath, content: source });\n if (result && result.content !== source) {\n tree.write(filePath, result.content);\n return true;\n }\n return false;\n};\n\n/**\n * Check whether a GritQL pattern matches anywhere in a file.\n * Returns true if the pattern matches at least once.\n *\n * Accepts raw GritQL, including patterns that start with a `language <name>`\n * header (e.g. `language python\\n\\`print($_)\\``) — the pattern is passed\n * straight through to QueryBuilder without any wrapping rewrite.\n */\nexport const matchGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<boolean> => {\n if (!tree.exists(filePath)) return false;\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n let matched = false;\n try {\n const query = new QueryBuilder(pattern);\n query.filter(() => {\n matched = true;\n return true;\n });\n await query.applyToFile({ path: filePath, content: source });\n } catch {\n return false;\n }\n return matched;\n};\n\n/**\n * Capture the source text of the first match of a GritQL pattern.\n *\n * For example `` `dependencyCheck: $_` `` returns the whole\n * `dependencyCheck: { ... }` property text. Returns undefined if nothing\n * matches. The file is not modified.\n */\nexport const captureGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<string | undefined> => {\n if (!tree.exists(filePath)) return undefined;\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n let captured: string | undefined;\n try {\n const query = new QueryBuilder(pattern);\n query.filter((node) => {\n captured ??= node.text();\n return true;\n });\n await query.applyToFile({ path: filePath, content: source });\n } catch {\n return undefined;\n }\n return captured;\n};\n\n/**\n * Return the text of every node matching the GritQL pattern, in document order.\n */\nexport const captureAllGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n): Promise<string[]> => {\n if (!tree.exists(filePath)) return [];\n ensureGritDir(tree);\n const source = tree.read(filePath)!.toString();\n const captured: string[] = [];\n try {\n const query = new QueryBuilder(pattern);\n query.filter((node) => {\n captured.push(node.text());\n return true;\n });\n await query.applyToFile({ path: filePath, content: source });\n } catch {\n return [];\n }\n return captured;\n};\n\n/**\n * A unique token that is a valid identifier, so it can stand in for an array\n * element or object property inside a GritQL rewrite.\n */\nexport const GRIT_INSERT_PLACEHOLDER = '__GRIT_INSERT_PLACEHOLDER__';\n\n/**\n * Apply a GritQL rewrite that inserts {@link GRIT_INSERT_PLACEHOLDER}, then\n * replace the placeholder with `text`. Routing user-provided text through a\n * placeholder keeps it out of the GritQL pattern, where quotes, backticks or\n * `${...}` would otherwise break parsing.\n *\n * Any separator (e.g. a leading `, ` when appending to an array) must be part\n * of the GritQL pattern, not `text`. The one adjustment made here: if the\n * placeholder lands after a trailing line comment (`// ...`) — which would\n * comment out the text — the text is moved to its own line.\n *\n * The caller formats afterwards. Returns true if the pattern matched and the\n * file changed.\n */\nexport const insertViaGritQL = async (\n tree: Tree,\n filePath: string,\n pattern: string,\n text: string,\n): Promise<boolean> => {\n if (!(await applyGritQL(tree, filePath, pattern))) return false;\n const content = tree.read(filePath)!.toString();\n const at = content.indexOf(GRIT_INSERT_PLACEHOLDER);\n const lineSoFar = content.slice(content.lastIndexOf('\\n', at) + 1, at);\n const replacement = lineSoFar.includes('//') ? `\\n${text}` : text;\n\n // Function replacer so `$` in `text` isn't treated as a replacement pattern.\n tree.write(\n filePath,\n content.replace(GRIT_INSERT_PLACEHOLDER, () => replacement),\n );\n return true;\n};\n"],"names":["QueryBuilder","path","updateGitIgnore","isEsmWorkspace","GRIT_DIR","normalizeModuleSpecifier","tree","from","isRelative","startsWith","endsWith","slice","length","ensureGritDir","process","env","GRIT_GLOBAL_DIR","join","root","patterns","assertFilePath","filePath","exists","Error","addDestructuredImport","variableNames","hasExistingImport","matchGritQL","variableName","localName","includes","split","applyGritQL","specifiers","contents","read","toString","newImport","newlineIndex","indexOf","write","substring","addPythonDestructuredImport","beforeContents","moduleAlreadyImported","appended","allAlreadyPresent","map","n","addSingleImport","alreadyImported","addStarExport","trim","alreadyExported","hasExportDeclaration","source","identifierName","pattern","q","result","applyToFile","content","query","matched","filter","captureGritQL","undefined","captured","node","text","captureAllGritQL","push","GRIT_INSERT_PLACEHOLDER","insertViaGritQL","at","lineSoFar","lastIndexOf","replacement","replace"],"mappings":"AAAA;;;CAGC,GAED,SAASA,YAAY,QAAQ,kBAAkB;AAE/C,YAAYC,UAAU,OAAO;AAC7B,SAASC,eAAe,QAAQ,WAAQ;AACxC,SAASC,cAAc,QAAQ,qBAAkB;AAEjD,MAAMC,WAAW;AAEjB;;;;;CAKC,GACD,MAAMC,2BAA2B,CAACC,MAAYC;IAC5C,IAAIJ,eAAeG,OAAO;QACxB,OAAOC;IACT;IACA,MAAMC,aAAaD,KAAKE,UAAU,CAAC,SAASF,KAAKE,UAAU,CAAC;IAC5D,OAA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,KAAK,CAACkD,QAAQe,WAAW,CAAC,MAAMF,MAAM,GAAGA;IACnE,MAAMG,cAAcF,UAAU7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAEuC,MAAM,GAAGA;IAE7D,6EAA6E;IAC7E/D,KAAKkC,KAAK,CACRnB,UACAwC,QAAQiB,OAAO,CAACN,yBAAyB,IAAMK;IAEjD,OAAO;AACT,EAAE"}
@@ -44,4 +44,4 @@ export declare const buildInstallCommand: (pm: string, pkg: string, dev: boolean
44
44
  * The package manager is auto-detected by @aws/create-nx-workspace from the
45
45
  * invoking command, so --pm is not needed.
46
46
  */
47
- export declare const buildCreateNxWorkspaceCommand: (pm: string, workspace: string, iac?: "cdk" | "terraform", tag?: string) => string;
47
+ export declare const buildCreateNxWorkspaceCommand: (pm: string, workspace: string, iac?: "cdk" | "terraform", tag?: string, module?: "esm" | "cjs") => string;
@@ -70,7 +70,7 @@
70
70
  *
71
71
  * The package manager is auto-detected by @aws/create-nx-workspace from the
72
72
  * invoking command, so --pm is not needed.
73
- */ export const buildCreateNxWorkspaceCommand = (pm, workspace, iac, tag)=>{
73
+ */ export const buildCreateNxWorkspaceCommand = (pm, workspace, iac, tag, module)=>{
74
74
  const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;
75
75
  const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';
76
76
  const parts = [
@@ -83,6 +83,9 @@
83
83
  workspace,
84
84
  ...iac ? [
85
85
  `--iac=${iac}`
86
+ ] : [],
87
+ ...module ? [
88
+ `--module=${module}`
86
89
  ] : []
87
90
  ];
88
91
  return parts.join(' ');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command for a given package manager\n */\nexport const buildInstallCommand = (pm: string, pkg: string, dev: boolean) => {\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun install ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","buildCreateNxWorkspaceCommand","workspace","iac","tag","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD;;;;;;;;CAQC,GAUD,OAAO,MAAMA,2BAGT;IACFC,KAAK;QAAEC,MAAM;QAAOC,KAAK;QAAWC,QAAQ;IAAa;IACzDC,MAAM;QAAEH,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDE,MAAM;QAAEJ,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDG,KAAK;QAAEL,MAAM;QAAQC,KAAK;QAAOC,QAAQ;IAAa;AACxD,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMI,iCAAiC,CAACC,IAAYC;IACzD,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEP,QAAQO;IACrD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAME,kCAAkC,CAC7CH,IACAC;IAEA,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEN,OAAOM;IACpD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMG,sBAAsB,CAACJ,IAAYK,KAAaC;IAC3D,OAAQN;QACN,KAAK;YACH,OAAO,CAAC,SAAS,EAAEM,MAAM,OAAO,IAAI,EAAE,EAAED,KAAK;QAC/C,KAAK;YACH,OAAO,CAAC,SAAS,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QAC7C,KAAK;YACH,OAAO,CAAC,+BAA+B,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QACnE,KAAK;YACH,OAAO,CAAC,YAAY,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QAChD;YACE,OAAO,GAAGL,GAAG,SAAS,EAAEM,MAAM,QAAQ,KAAKD,KAAK;IACpD;AACF,EAAE;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAME,gCAAgC,CAC3CP,IACAQ,WACAC,KACAC;IAEA,MAAMC,eAAepB,wBAAwB,CAACS,GAAG,EAAEL,UAAU,GAAGK,GAAG,OAAO,CAAC;IAC3E,MAAMY,UAAUF,MAAM,CAAC,kBAAkB,EAAEA,KAAK,GAAG;IACnD,MAAMG,QAAQ;QACZF;QACAC;QACA,wEAAwE;WACpEZ,OAAO,QAAQ;YAAC;SAAK,GAAG,EAAE;QAC9BQ;WACIC,MAAM;YAAC,CAAC,MAAM,EAAEA,KAAK;SAAC,GAAG,EAAE;KAChC;IACD,OAAOI,MAAMC,IAAI,CAAC;AACpB,EAAE"}
1
+ {"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command for a given package manager\n */\nexport const buildInstallCommand = (pm: string, pkg: string, dev: boolean) => {\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun install ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n module?: 'esm' | 'cjs',\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ...(module ? [`--module=${module}`] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","buildCreateNxWorkspaceCommand","workspace","iac","tag","module","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD;;;;;;;;CAQC,GAUD,OAAO,MAAMA,2BAGT;IACFC,KAAK;QAAEC,MAAM;QAAOC,KAAK;QAAWC,QAAQ;IAAa;IACzDC,MAAM;QAAEH,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDE,MAAM;QAAEJ,MAAM;QAAQC,KAAK;QAAQC,QAAQ;IAAc;IACzDG,KAAK;QAAEL,MAAM;QAAQC,KAAK;QAAOC,QAAQ;IAAa;AACxD,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMI,iCAAiC,CAACC,IAAYC;IACzD,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEP,QAAQO;IACrD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAME,kCAAkC,CAC7CH,IACAC;IAEA,MAAMC,SAASX,wBAAwB,CAACS,GAAG,EAAEN,OAAOM;IACpD,OAAO,GAAGE,OAAO,CAAC,EAAED,SAAS;AAC/B,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMG,sBAAsB,CAACJ,IAAYK,KAAaC;IAC3D,OAAQN;QACN,KAAK;YACH,OAAO,CAAC,SAAS,EAAEM,MAAM,OAAO,IAAI,EAAE,EAAED,KAAK;QAC/C,KAAK;YACH,OAAO,CAAC,SAAS,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QAC7C,KAAK;YACH,OAAO,CAAC,+BAA+B,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QACnE,KAAK;YACH,OAAO,CAAC,YAAY,EAAEC,MAAM,QAAQ,KAAKD,KAAK;QAChD;YACE,OAAO,GAAGL,GAAG,SAAS,EAAEM,MAAM,QAAQ,KAAKD,KAAK;IACpD;AACF,EAAE;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAME,gCAAgC,CAC3CP,IACAQ,WACAC,KACAC,KACAC;IAEA,MAAMC,eAAerB,wBAAwB,CAACS,GAAG,EAAEL,UAAU,GAAGK,GAAG,OAAO,CAAC;IAC3E,MAAMa,UAAUH,MAAM,CAAC,kBAAkB,EAAEA,KAAK,GAAG;IACnD,MAAMI,QAAQ;QACZF;QACAC;QACA,wEAAwE;WACpEb,OAAO,QAAQ;YAAC;SAAK,GAAG,EAAE;QAC9BQ;WACIC,MAAM;YAAC,CAAC,MAAM,EAAEA,KAAK;SAAC,GAAG,EAAE;WAC3BE,SAAS;YAAC,CAAC,SAAS,EAAEA,QAAQ;SAAC,GAAG,EAAE;KACzC;IACD,OAAOG,MAAMC,IAAI,CAAC;AACpB,EAAE"}
@@ -3,6 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */ import { generateFiles, joinPathFragments, OverwriteStrategy, updateJson } from "@nx/devkit";
5
5
  import { addStarExport } from "../ast.js";
6
+ import { esmVars } from "../module-format.js";
6
7
  import { addDependencyToTargetIfNotPresent } from "../nx.js";
7
8
  import { PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, SHARED_TERRAFORM_DIR } from "../shared-constructs-constants.js";
8
9
  import { terraformProviderVersions } from "../versions.js";
@@ -20,10 +21,16 @@ export const addDynamoDBInfra = async (tree, options)=>{
20
21
  });
21
22
  };
22
23
  export const addDynamoDBCdkConstructs = async (tree, options)=>{
23
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'core'), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core'), options, {
24
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'core'), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core'), {
25
+ ...options,
26
+ ...esmVars(tree)
27
+ }, {
24
28
  overwriteStrategy: OverwriteStrategy.KeepExisting
25
29
  });
26
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'dynamodb'), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'app', 'dynamodb'), options, {
30
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'dynamodb'), joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'app', 'dynamodb'), {
31
+ ...options,
32
+ ...esmVars(tree)
33
+ }, {
27
34
  overwriteStrategy: OverwriteStrategy.KeepExisting
28
35
  });
29
36
  await addStarExport(tree, joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core', 'index.ts'), './dynamodb.js');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/dynamodb-constructs/dynamodb-constructs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { addStarExport } from '../ast';\nimport type { Iac } from '../iac';\nimport { addDependencyToTargetIfNotPresent } from '../nx';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants';\nimport { terraformProviderVersions } from '../versions';\n\nexport interface AddDynamoDBConstructOptions {\n projectName: string;\n nameClassName: string;\n nameKebabCase: string;\n tableName: string;\n projectRoot: string;\n}\n\nexport const addDynamoDBInfra = async (\n tree: Tree,\n options: AddDynamoDBConstructOptions & { iac: Iac },\n) => {\n if (options.iac === 'cdk') {\n await addDynamoDBCdkConstructs(tree, options);\n } else if (options.iac === 'terraform') {\n addDynamoDBTerraformModules(tree, options);\n } else {\n throw new Error(`Unsupported iac ${options.iac}`);\n }\n\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.projectName}:build`,\n );\n return config;\n },\n );\n};\n\nexport const addDynamoDBCdkConstructs = async (\n tree: Tree,\n options: AddDynamoDBConstructOptions,\n) => {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cdk', 'core'),\n joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core'),\n options,\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'dynamodb'),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'dynamodb',\n ),\n options,\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'index.ts',\n ),\n './dynamodb.js',\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'dynamodb',\n 'index.ts',\n ),\n `./${options.nameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n './dynamodb/index.js',\n );\n};\n\nexport const addDynamoDBTerraformModules = (\n tree: Tree,\n options: AddDynamoDBConstructOptions,\n) => {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'terraform', 'core'),\n joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'core'),\n { ...options, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'dynamodb',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'dynamodb',\n ),\n { ...options, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","addStarExport","addDependencyToTargetIfNotPresent","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","terraformProviderVersions","addDynamoDBInfra","tree","options","iac","addDynamoDBCdkConstructs","addDynamoDBTerraformModules","Error","config","projectName","dirname","overwriteStrategy","KeepExisting","nameKebabCase"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,UAAU,QACL,aAAa;AACpB,SAASC,aAAa,QAAQ,YAAS;AAEvC,SAASC,iCAAiC,QAAQ,WAAQ;AAC1D,SACEC,YAAY,EACZC,qB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SAC7DlB,kBAAkBK,cAAcE,sBAAsB,OAAO,SAC7D;QAAE,GAAGI,OAAO;QAAE,GAAGH,2BAA2B;IAAC,GAC7C;QACEW,mBAAmBlB,kBAAkBmB,YAAY;IACnD;IAGFrB,cACEW,MACAV,kBACE,YAAYkB,OAAO,EACnB,SACA,aACA,OACA,aAEFlB,kBACEK,cACAE,sBACA,OACA,OACA,aAEF;QAAE,GAAGI,OAAO;QAAE,GAAGH,2BAA2B;IAAC,GAC7C;QACEW,mBAAmBlB,kBAAkBmB,YAAY;IACnD;AAEJ,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/dynamodb-constructs/dynamodb-constructs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { addStarExport } from '../ast';\nimport type { Iac } from '../iac';\nimport { esmVars } from '../module-format';\nimport { addDependencyToTargetIfNotPresent } from '../nx';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants';\nimport { terraformProviderVersions } from '../versions';\n\nexport interface AddDynamoDBConstructOptions {\n projectName: string;\n nameClassName: string;\n nameKebabCase: string;\n tableName: string;\n projectRoot: string;\n}\n\nexport const addDynamoDBInfra = async (\n tree: Tree,\n options: AddDynamoDBConstructOptions & { iac: Iac },\n) => {\n if (options.iac === 'cdk') {\n await addDynamoDBCdkConstructs(tree, options);\n } else if (options.iac === 'terraform') {\n addDynamoDBTerraformModules(tree, options);\n } else {\n throw new Error(`Unsupported iac ${options.iac}`);\n }\n\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.projectName}:build`,\n );\n return config;\n },\n );\n};\n\nexport const addDynamoDBCdkConstructs = async (\n tree: Tree,\n options: AddDynamoDBConstructOptions,\n) => {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cdk', 'core'),\n joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR, 'src', 'core'),\n { ...options, ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'dynamodb'),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'dynamodb',\n ),\n { ...options, ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'index.ts',\n ),\n './dynamodb.js',\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'dynamodb',\n 'index.ts',\n ),\n `./${options.nameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n './dynamodb/index.js',\n );\n};\n\nexport const addDynamoDBTerraformModules = (\n tree: Tree,\n options: AddDynamoDBConstructOptions,\n) => {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'terraform', 'core'),\n joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'core'),\n { ...options, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'dynamodb',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'dynamodb',\n ),\n { ...options, ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","addStarExport","esmVars","addDependencyToTargetIfNotPresent","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","terraformProviderVersions","addDynamoDBInfra","tree","options","iac","addDynamoDBCdkConstructs","addDynamoDBTerraformModules","Error","config","projectName","dirname","overwriteStrategy","KeepExisting","nameKebabCase"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,UAAU,QACL,aAAa;AACpB,SAASC,aAAa,QAAQ,YAAS;AAEvC,SAASC,OAAO,QAAQ,sBAAmB;AAC3C,SAASC,iCAAiC,QAAQ,WAAQ;AAC1D,SACEC,YAAY,EACZC,qBAAqB,EACrBC,oBAAoB,QACf,oCAAiC;AACxC,SAASC,yBAAyB,QAAQ,iBAAc;AAUxD,OAAO,MAAMC,mBAAmB,OAC9BC,MACAC;IAEA,IAAIA,QAAQC,GAAG,KAAK,OAAO;QACzB,MAAMC,yBAAyBH,MAAMC;IACvC,OAAO,IAAIA,QAAQC,GAAG,KAAK,aAAa;QACtCE,4BAA4BJ,MAAMC;IACpC,OAAO;QACL,MAAM,IAAII,MAAM,CAAC,gBAAgB,EAAEJ,QAAQC,GAAG,EAAE;IAClD;IAEAX,WACES,MACAX,kBACEM,cACAM,QAAQC,GAAG,KAAK,QAAQN,wBAAwBC,sBAChD,iBAEF,CAACS;QACCZ,kCACEY,QACA,SACA,GAAGL,QAAQM,WAAW,CAAC,MAAM,CAAC;QAEhC,OAAOD;IACT;AAEJ,EAAE;AAEF,OAAO,MAAMH,2BAA2B,OACtCH,MACAC;IAEAb,cACEY,MACAX,kBAAkB,YAAYmB,OAAO,EAAE,SAAS,OAAO,SACvDnB,kBAAkBM,cAAcC,uBAAuB,OAAO,SAC9D;QAAE,GAAGK,OAAO;QAAE,GAAGR,QAAQO,KAAK;IAAC,GAC/B;QACES,mBAAmBnB,kBAAkBoB,YAAY;IACnD;IAGFtB,cACEY,MACAX,kBAAkB,YAAYmB,OAAO,EAAE,SAAS,OAAO,OAAO,aAC9DnB,kBACEM,cACAC,uBACA,OACA,OACA,aAEF;QAAE,GAAGK,OAAO;QAAE,GAAGR,QAAQO,KAAK;IAAC,GAC/B;QACES,mBAAmBnB,kBAAkBoB,YAAY;IACnD;IAGF,MAAMlB,cACJQ,MACAX,kBACEM,cACAC,uBACA,OACA,QACA,aAEF;IAEF,MAAMJ,cACJQ,MACAX,kBACEM,cACAC,uBACA,OACA,OACA,YACA,aAEF,CAAC,EAAE,EAAEK,QAAQU,aAAa,CAAC,GAAG,CAAC;IAEjC,MAAMnB,cACJQ,MACAX,kBACEM,cACAC,uBACA,OACA,OACA,aAEF;AAEJ,EAAE;AAEF,OAAO,MAAMQ,8BAA8B,CACzCJ,MACAC;IAEAb,cACEY,MACAX,kBAAkB,YAAYmB,OAAO,EAAE,SAAS,aAAa,SAC7DnB,kBAAkBM,cAAcE,sBAAsB,OAAO,SAC7D;QAAE,GAAGI,OAAO;QAAE,GAAGH,2BAA2B;IAAC,GAC7C;QACEW,mBAAmBnB,kBAAkBoB,YAAY;IACnD;IAGFtB,cACEY,MACAX,kBACE,YAAYmB,OAAO,EACnB,SACA,aACA,OACA,aAEFnB,kBACEM,cACAE,sBACA,OACA,OACA,aAEF;QAAE,GAAGI,OAAO;QAAE,GAAGH,2BAA2B;IAAC,GAC7C;QACEW,mBAAmBnB,kBAAkBoB,YAAY;IACnD;AAEJ,EAAE"}
@@ -3,8 +3,8 @@ import { AttributeType, ProjectionType } from 'aws-cdk-lib/aws-dynamodb';
3
3
  import {
4
4
  DynamoDBTable,
5
5
  DynamoDBTableProps,
6
- } from '../../core/dynamodb.js';
7
- import { findWorkspaceRoot } from '../../core/workspace.js';
6
+ } from '../../core/dynamodb<% if (esm) { %>.js<% } %>';
7
+ import { findWorkspaceRoot } from '../../core/workspace<% if (esm) { %>.js<% } %>';
8
8
  import { readFileSync } from 'fs';
9
9
  import { join } from "path";
10
10
  import { fileURLToPath } from "url";
@@ -12,7 +12,7 @@ import { fileURLToPath } from "url";
12
12
  const { runtimeConfigKey, tableConfig } = JSON.parse(
13
13
  readFileSync(
14
14
  join(
15
- findWorkspaceRoot(fileURLToPath(new URL(import.meta.url))),
15
+ findWorkspaceRoot(fileURLToPath(new URL(<% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>))),
16
16
  '<%= projectRoot %>/config.json',
17
17
  ),
18
18
  'utf-8',