@aws/nx-plugin 1.0.0-rc.31 → 1.0.0-rc.33

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 (198) hide show
  1. package/LICENSE-THIRD-PARTY +72 -70
  2. package/package.json +5 -5
  3. package/src/infra/app/__snapshots__/generator.spec.ts.snap +15 -15
  4. package/src/infra/app/files/app/src/main.ts.template +1 -1
  5. package/src/infra/app/files/app/src/stages/application-stage.ts.template +1 -1
  6. package/src/infra/app/generator.js +3 -1
  7. package/src/infra/app/generator.js.map +1 -1
  8. package/src/open-api/ts-client/__snapshots__/generator.content-type.spec.ts.snap +64 -3
  9. package/src/open-api/ts-client/__snapshots__/generator.multipart.spec.ts.snap +280 -0
  10. package/src/open-api/ts-client/files/client.gen.ts.template +37 -2
  11. package/src/open-api/ts-client/generator.js +5 -1
  12. package/src/open-api/ts-client/generator.js.map +1 -1
  13. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
  14. package/src/open-api/ts-hooks/generator.js +5 -1
  15. package/src/open-api/ts-hooks/generator.js.map +1 -1
  16. package/src/open-api/utils/normalise.js +13 -6
  17. package/src/open-api/utils/normalise.js.map +1 -1
  18. package/src/open-api/utils/parser.js +12 -1
  19. package/src/open-api/utils/parser.js.map +1 -1
  20. package/src/open-api/utils/types.d.ts +4 -1
  21. package/src/open-api/utils/types.js.map +1 -1
  22. package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
  23. package/src/preset/generator.d.ts +1 -1
  24. package/src/preset/generator.js +5 -2
  25. package/src/preset/generator.js.map +1 -1
  26. package/src/preset/schema.d.js.map +1 -1
  27. package/src/preset/schema.d.ts +2 -0
  28. package/src/preset/schema.json +6 -0
  29. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
  30. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
  31. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
  32. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  33. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +426 -18
  34. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  35. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
  36. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +283 -11
  37. package/src/smithy/ts/api/files/handler.ts.template +2 -2
  38. package/src/smithy/ts/api/files/local-server.ts.template +2 -2
  39. package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
  40. package/src/smithy/ts/api/files/service.ts.template +3 -3
  41. package/src/smithy/ts/api/generator.js +3 -1
  42. package/src/smithy/ts/api/generator.js.map +1 -1
  43. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +426 -18
  44. package/src/trpc/backend/files/src/client/index.ts.template +1 -1
  45. package/src/trpc/backend/files/src/handler.ts.template +1 -1
  46. package/src/trpc/backend/files/src/index.ts.template +5 -5
  47. package/src/trpc/backend/files/src/init.ts.template +1 -1
  48. package/src/trpc/backend/files/src/local-server.ts.template +1 -1
  49. package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
  50. package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
  51. package/src/trpc/backend/files/src/router.ts.template +2 -2
  52. package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
  53. package/src/trpc/backend/generator.js +3 -1
  54. package/src/trpc/backend/generator.js.map +1 -1
  55. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
  56. package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
  57. package/src/ts/agent/a2a-connection/generator.js +3 -1
  58. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  59. package/src/ts/agent/files/a2a/index.ts.template +1 -1
  60. package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
  61. package/src/ts/agent/files/http/client.ts.template +2 -2
  62. package/src/ts/agent/files/http/index.ts.template +2 -2
  63. package/src/ts/agent/files/http/router.ts.template +3 -3
  64. package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
  65. package/src/ts/agent/gateway-connection/generator.js +3 -1
  66. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  67. package/src/ts/agent/generator.js +5 -2
  68. package/src/ts/agent/generator.js.map +1 -1
  69. package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
  70. package/src/ts/agent/mcp-connection/generator.js +3 -1
  71. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  72. package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
  73. package/src/ts/astro-docs/generator.js +2 -0
  74. package/src/ts/astro-docs/generator.js.map +1 -1
  75. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  76. package/src/ts/dynamodb/files/src/client.ts.template +5 -2
  77. package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
  78. package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
  79. package/src/ts/dynamodb/files/src/index.ts.template +2 -2
  80. package/src/ts/dynamodb/generator.js +3 -1
  81. package/src/ts/dynamodb/generator.js.map +1 -1
  82. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  83. package/src/ts/lib/generator.js +7 -1
  84. package/src/ts/lib/generator.js.map +1 -1
  85. package/src/ts/lib/ts-project-utils.js +19 -4
  86. package/src/ts/lib/ts-project-utils.js.map +1 -1
  87. package/src/ts/lib/types.d.ts +6 -0
  88. package/src/ts/lib/types.js.map +1 -1
  89. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -31
  90. package/src/ts/mcp-server/generator.js +11 -22
  91. package/src/ts/mcp-server/generator.js.map +1 -1
  92. package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
  93. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
  94. package/src/ts/nx-generator/generator.js +5 -2
  95. package/src/ts/nx-generator/generator.js.map +1 -1
  96. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
  97. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
  98. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
  99. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
  100. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
  101. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
  102. package/src/ts/nx-plugin/generator.js +3 -1
  103. package/src/ts/nx-plugin/generator.js.map +1 -1
  104. package/src/ts/nx-plugin/utils.js +7 -4
  105. package/src/ts/nx-plugin/utils.js.map +1 -1
  106. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
  107. package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
  108. package/src/ts/rdb/files/src/index.ts.template +1 -1
  109. package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
  110. package/src/ts/rdb/files/src/prisma.ts.template +7 -4
  111. package/src/ts/rdb/generator.js +3 -1
  112. package/src/ts/rdb/generator.js.map +1 -1
  113. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
  114. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
  115. package/src/utils/agent-chat/agent-chat.js +3 -1
  116. package/src/utils/agent-chat/agent-chat.js.map +1 -1
  117. package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
  118. package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
  119. package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
  120. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  121. package/src/utils/agent-connection/agent-connection.js +4 -1
  122. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  123. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
  124. package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
  125. package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
  126. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
  127. package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
  128. package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
  129. package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
  130. package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
  131. package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
  132. package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
  133. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  134. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
  135. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
  136. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
  137. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
  138. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
  139. package/src/utils/api-constructs/api-constructs.js +8 -2
  140. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  141. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
  142. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
  143. package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
  144. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
  145. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
  146. package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
  147. package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
  148. package/src/utils/api-constructs/files/terraform/app/apis/http/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
  149. package/src/utils/api-constructs/files/terraform/app/apis/rest/__apiNameKebabCase__/__apiNameKebabCase__.tf.template +69 -1
  150. package/src/utils/ast.js +16 -0
  151. package/src/utils/ast.js.map +1 -1
  152. package/src/utils/commands.d.ts +1 -1
  153. package/src/utils/commands.js +4 -1
  154. package/src/utils/commands.js.map +1 -1
  155. package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
  156. package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
  157. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
  158. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
  159. package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
  160. package/src/utils/files/common/constructs/src/index.ts.template +2 -2
  161. package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
  162. package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
  163. package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
  164. package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
  165. package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
  166. package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
  167. package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
  168. package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
  169. package/src/utils/function-constructs/function-constructs.js +3 -1
  170. package/src/utils/function-constructs/function-constructs.js.map +1 -1
  171. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
  172. package/src/utils/identity-constructs/identity-constructs.js +5 -1
  173. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  174. package/src/utils/module-format.d.ts +28 -0
  175. package/src/utils/module-format.js +28 -0
  176. package/src/utils/module-format.js.map +1 -0
  177. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
  178. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
  179. package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
  180. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  181. package/src/utils/shared-constructs.js +3 -1
  182. package/src/utils/shared-constructs.js.map +1 -1
  183. package/src/utils/shared-infra-config.js +3 -1
  184. package/src/utils/shared-infra-config.js.map +1 -1
  185. package/src/utils/shared-infra-scripts.js +3 -1
  186. package/src/utils/shared-infra-scripts.js.map +1 -1
  187. package/src/utils/shared-shadcn.js +3 -1
  188. package/src/utils/shared-shadcn.js.map +1 -1
  189. package/src/utils/test.d.ts +2 -0
  190. package/src/utils/test.js +7 -1
  191. package/src/utils/test.js.map +1 -1
  192. package/src/utils/versions.d.ts +61 -61
  193. package/src/utils/versions.js +59 -59
  194. package/src/utils/versions.js.map +1 -1
  195. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
  196. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
  197. package/src/utils/website-constructs/website-constructs.js +9 -2
  198. package/src/utils/website-constructs/website-constructs.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/agent/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addAgentChatScripts } from '../../utils/agent-chat/agent-chat';\nimport {\n addTypeScriptFrameworkBase,\n ensureTypeScriptAgentConnectionProject,\n} from '../../utils/agent-connection/agent-connection';\nimport { addAgentInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { TS_VERSIONS, withVersions } from '../../utils/versions';\nimport type { TsAgentGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAgentGenerator = async (\n tree: Tree,\n options: TsAgentGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-agent`;\n const name = kebabCase(options.name || defaultName);\n const agentNameClassName = toClassName(name);\n const agentTargetPrefix = options.name ? name : 'agent';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n agentTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n const protocol = options.protocol ?? 'http';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n // Ensure the shared agent-connection project exists so the server entry\n // point can import `runWithSessionId` and propagate the AgentCore session\n // ID to any downstream MCP / A2A clients a later connection generator\n // wires into this agent.\n await ensureTypeScriptAgentConnectionProject(tree);\n // The agent server imports the framework base helpers (session cache + model\n // error logging) regardless of whether a connection client is wired in.\n await addTypeScriptFrameworkBase(tree);\n\n const templateContext = {\n name,\n agentNameClassName,\n distDir,\n agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`,\n };\n\n // Generate common files shared by both protocols\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate protocol-specific files\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', protocol.toLowerCase()),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(tree, project, {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/index.ts`,\n bundleOutputDir: joinPathFragments('agent', name),\n });\n\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n distDir,\n name,\n protocol,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'agent',\n name,\n );\n const dockerTargetName = `${agentTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n outputs: [`{workspaceRoot}/${dockerOutputDir}/Dockerfile`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // AG-UI uses HTTP as the AgentCore protocol type (AG-UI is HTTP-based with SSE over POST).\n const infraProtocol: 'http' | 'a2a' =\n protocol === 'ag-ui' ? 'http' : (protocol as 'http' | 'a2a');\n\n await addAgentInfra(tree, {\n agentNameKebabCase: name,\n agentNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n serverProtocol: infraProtocol,\n containers,\n });\n }\n\n // Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'zod',\n '@strands-agents/sdk',\n '@aws-sdk/credential-providers',\n '@aws-sdk/client-appconfigdata',\n '@aws-lambda-powertools/parameters',\n '@modelcontextprotocol/sdk',\n ...(protocol === 'a2a'\n ? (['express', '@a2a-js/sdk'] as const)\n : protocol === 'ag-ui'\n ? ([\n '@ag-ui/aws-strands',\n '@ag-ui/core',\n '@ag-ui/encoder',\n 'express',\n 'cors',\n ] as const)\n : ([\n '@trpc/server',\n '@trpc/client',\n 'ws',\n 'cors',\n 'aws4fetch',\n ] as const)),\n ]),\n withVersions([\n // The chat CLI runs standalone via tsx for every protocol, and resolves\n // the deployed agent from AppConfig when `RUNTIME_CONFIG_APP_ID` is set.\n 'tsx',\n '@types/node',\n 'agent-chat-cli',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ...(auth === 'iam'\n ? (['aws4fetch', '@aws-sdk/credential-providers'] as const)\n : ([] as const)),\n // A2A chat builds a signed @a2a-js client factory for the deployed agent.\n ...(protocol === 'a2a' ? (['@a2a-js/sdk'] as const) : ([] as const)),\n ...(protocol === 'a2a' || protocol === 'ag-ui'\n ? (['@types/express', '@types/cors'] as const)\n : (['@types/ws', '@types/cors'] as const)),\n ]),\n );\n\n // A2A servers use port 9000 as per the Strands A2A SDK default and AgentCore A2A contract.\n // HTTP and AG-UI agents use port 8081+ to avoid conflict with VS Code server on 8080.\n const localDevPortStart = protocol === 'a2a' ? 9000 : 8081;\n const localDevPort = assignPort(tree, project, localDevPortStart, {\n component: { info: TS_AGENT_GENERATOR_INFO, name: agentTargetPrefix },\n });\n\n // Every protocol gets a standalone `chat.ts`. It connects to the local\n // `dev` server by default, or to the deployed agent (with the\n // appropriate auth) when `RUNTIME_CONFIG_APP_ID` is set.\n const scriptsDir = joinPathFragments(\n project.root,\n 'scripts',\n agentTargetPrefix,\n );\n addAgentChatScripts(tree, {\n scriptsDir,\n protocol,\n language: 'ts',\n agentNameClassName,\n auth,\n relativeAgentImport: `../../${targetSourceDirRelativeToProjectRoot}`,\n });\n\n const chatUrl =\n protocol === 'http'\n ? `ws://localhost:${localDevPort}/ws`\n : protocol === 'ag-ui'\n ? `http://localhost:${localDevPort}/invocations`\n : `http://localhost:${localDevPort}`;\n const chatCommand = `tsx ./scripts/${agentTargetPrefix}/chat.ts`;\n\n const agentTargets = {\n ...project.targets,\n [`${agentTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${agentTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${agentTargetPrefix}-chat`]: {\n executor: 'nx:run-commands',\n options: {\n commands: [chatCommand],\n cwd: '{projectRoot}',\n env: {\n URL: chatUrl,\n },\n },\n },\n };\n\n // Aggregate `<agent>-dev` under the project-level `dev` target.\n addComponentDevTarget(agentTargets, `${agentTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(agentTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_AGENT_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n agentTargetPrefix,\n { port: localDevPort, rc: agentNameClassName, auth, protocol },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_AGENT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addAgentChatScripts","addTypeScriptFrameworkBase","ensureTypeScriptAgentConnectionProject","addAgentInfra","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","TS_VERSIONS","withVersions","TS_AGENT_GENERATOR_INFO","filename","tsAgentGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","agentNameClassName","agentTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","protocol","auth","console","warn","templateContext","agentConnectionImport","dirname","overwriteStrategy","KeepExisting","toLowerCase","containers","dockerImageTag","targetFilePath","bundleOutputDir","adotVersion","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","iac","infraProtocol","agentNameKebabCase","projectName","serverProtocol","localDevPortStart","localDevPort","component","info","scriptsDir","language","relativeAgentImport","chatUrl","chatCommand","agentTargets","continuous","cwd","env","PORT","LOCAL_DEV","URL","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,mBAAmB,QAAQ,uCAAoC;AACxE,SACEC,0BAA0B,EAC1BC,sCAAsC,QACjC,mDAAgD;AACvD,SAASC,aAAa,QAAQ,6DAA0D;AACxF,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,qBAAqB,EACrBC,6BAA6B,EAC7BC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,UAAU,QAAQ,sBAAmB;AAC9C,SAASC,yBAAyB,QAAQ,mCAAgC;AAC1E,SAASC,WAAW,EAAEC,YAAY,QAAQ,0BAAuB;AAGjE,OAAO,MAAMC,0BAA2CP,iBACtD,YAAYQ,QAAQ,EACpB;AAEF,OAAO,MAAMC,mBAAmB,OAC9BC,MACAC;IAEA,MAAMC,UAAUX,oCAAoCS,MAAMC,QAAQC,OAAO;IAE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AwB;IAErE,MAAMlB,qBAAqBqB;IAC3B,OAAO,IACLlB,oBAAoBkB,MAAMC,QAAQkE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAerE,iBAAiB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/agent/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addAgentChatScripts } from '../../utils/agent-chat/agent-chat';\nimport {\n addTypeScriptFrameworkBase,\n ensureTypeScriptAgentConnectionProject,\n} from '../../utils/agent-connection/agent-connection';\nimport { addAgentInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { TS_VERSIONS, withVersions } from '../../utils/versions';\nimport type { TsAgentGeneratorSchema } from './schema';\n\nexport const TS_AGENT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAgentGenerator = async (\n tree: Tree,\n options: TsAgentGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-agent`;\n const name = kebabCase(options.name || defaultName);\n const agentNameClassName = toClassName(name);\n const agentTargetPrefix = options.name ? name : 'agent';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n agentTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n const protocol = options.protocol ?? 'http';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n // Ensure the shared agent-connection project exists so the server entry\n // point can import `runWithSessionId` and propagate the AgentCore session\n // ID to any downstream MCP / A2A clients a later connection generator\n // wires into this agent.\n await ensureTypeScriptAgentConnectionProject(tree);\n // The agent server imports the framework base helpers (session cache + model\n // error logging) regardless of whether a connection client is wired in.\n await addTypeScriptFrameworkBase(tree);\n\n const templateContext = {\n name,\n agentNameClassName,\n distDir,\n agentConnectionImport: `:${getNpmScope(tree)}/agent-connection`,\n ...esmVars(tree),\n };\n\n // Generate common files shared by both protocols\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate protocol-specific files\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', protocol.toLowerCase()),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(tree, project, {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/index.ts`,\n bundleOutputDir: joinPathFragments('agent', name),\n });\n\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n distDir,\n name,\n protocol,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'agent',\n name,\n );\n const dockerTargetName = `${agentTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n outputs: [`{workspaceRoot}/${dockerOutputDir}/Dockerfile`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // AG-UI uses HTTP as the AgentCore protocol type (AG-UI is HTTP-based with SSE over POST).\n const infraProtocol: 'http' | 'a2a' =\n protocol === 'ag-ui' ? 'http' : (protocol as 'http' | 'a2a');\n\n await addAgentInfra(tree, {\n agentNameKebabCase: name,\n agentNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n serverProtocol: infraProtocol,\n containers,\n });\n }\n\n // Add dependencies\n addDependenciesToPackageJson(\n tree,\n withVersions([\n 'zod',\n '@strands-agents/sdk',\n '@aws-sdk/credential-providers',\n '@aws-sdk/client-appconfigdata',\n '@aws-lambda-powertools/parameters',\n '@modelcontextprotocol/sdk',\n ...(protocol === 'a2a'\n ? (['express', '@a2a-js/sdk'] as const)\n : protocol === 'ag-ui'\n ? ([\n '@ag-ui/aws-strands',\n '@ag-ui/core',\n '@ag-ui/encoder',\n 'express',\n 'cors',\n ] as const)\n : ([\n '@trpc/server',\n '@trpc/client',\n 'ws',\n 'cors',\n 'aws4fetch',\n ] as const)),\n ]),\n withVersions([\n // The chat CLI runs standalone via tsx for every protocol, and resolves\n // the deployed agent from AppConfig when `RUNTIME_CONFIG_APP_ID` is set.\n 'tsx',\n '@types/node',\n 'agent-chat-cli',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ...(auth === 'iam'\n ? (['aws4fetch', '@aws-sdk/credential-providers'] as const)\n : ([] as const)),\n // A2A chat builds a signed @a2a-js client factory for the deployed agent.\n ...(protocol === 'a2a' ? (['@a2a-js/sdk'] as const) : ([] as const)),\n ...(protocol === 'a2a' || protocol === 'ag-ui'\n ? (['@types/express', '@types/cors'] as const)\n : (['@types/ws', '@types/cors'] as const)),\n ]),\n );\n\n // A2A servers use port 9000 as per the Strands A2A SDK default and AgentCore A2A contract.\n // HTTP and AG-UI agents use port 8081+ to avoid conflict with VS Code server on 8080.\n const localDevPortStart = protocol === 'a2a' ? 9000 : 8081;\n const localDevPort = assignPort(tree, project, localDevPortStart, {\n component: { info: TS_AGENT_GENERATOR_INFO, name: agentTargetPrefix },\n });\n\n // Every protocol gets a standalone `chat.ts`. It connects to the local\n // `dev` server by default, or to the deployed agent (with the\n // appropriate auth) when `RUNTIME_CONFIG_APP_ID` is set.\n const scriptsDir = joinPathFragments(\n project.root,\n 'scripts',\n agentTargetPrefix,\n );\n addAgentChatScripts(tree, {\n scriptsDir,\n protocol,\n language: 'ts',\n agentNameClassName,\n auth,\n relativeAgentImport: `../../${targetSourceDirRelativeToProjectRoot}`,\n });\n\n const chatUrl =\n protocol === 'http'\n ? `ws://localhost:${localDevPort}/ws`\n : protocol === 'ag-ui'\n ? `http://localhost:${localDevPort}/invocations`\n : `http://localhost:${localDevPort}`;\n const chatCommand = `tsx ./scripts/${agentTargetPrefix}/chat.ts`;\n\n const agentTargets = {\n ...project.targets,\n [`${agentTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${agentTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${agentTargetPrefix}-chat`]: {\n executor: 'nx:run-commands',\n options: {\n commands: [chatCommand],\n cwd: '{projectRoot}',\n env: {\n URL: chatUrl,\n },\n },\n },\n };\n\n // Aggregate `<agent>-dev` under the project-level `dev` target.\n addComponentDevTarget(agentTargets, `${agentTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(agentTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_AGENT_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n agentTargetPrefix,\n { port: localDevPort, rc: agentNameClassName, auth, protocol },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_AGENT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addAgentChatScripts","addTypeScriptFrameworkBase","ensureTypeScriptAgentConnectionProject","addAgentInfra","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","TS_VERSIONS","withVersions","TS_AGENT_GENERATOR_INFO","filename","tsAgentGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","agentNameClassName","agentTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","protocol","auth","console","warn","templateContext","agentConnectionImport","dirname","overwriteStrategy","KeepExisting","toLowerCase","containers","dockerImageTag","targetFilePath","bundleOutputDir","adotVersion","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","iac","infraProtocol","agentNameKebabCase","projectName","serverProtocol","localDevPortStart","localDevPort","component","info","scriptsDir","language","relativeAgentImport","chatUrl","chatCommand","agentTargets","continuous","cwd","env","PORT","LOCAL_DEV","URL","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,mBAAmB,QAAQ,uCAAoC;AACxE,SACEC,0BAA0B,EAC1BC,sCAAsC,QACjC,mDAAgD;AACvD,SAASC,aAAa,QAAQ,6DAA0D;AACxF,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAA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AkB,SAAS,CAAC;iBAAC;gBACvD8C,KAAK;gBACLC,KAAK;oBACHC,MAAM,GAAGZ,cAAc;oBACvBa,WAAW;gBACb;YACF;QACF;QACA,CAAC,GAAGpD,kBAAkB,KAAK,CAAC,CAAC,EAAE;YAC7B4B,UAAU;YACVtC,SAAS;gBACPuC,UAAU;oBAACiB;iBAAY;gBACvBG,KAAK;gBACLC,KAAK;oBACHG,KAAKR;gBACP;YACF;QACF;IACF;IAEA,gEAAgE;IAChErE,sBAAsBuE,cAAc,GAAG/C,kBAAkB,IAAI,CAAC;IAE9DxC,2BAA2B6B,MAAME,QAAQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBkC,SAAS5C,eAAekE;IAC1B;IAEAtE,8BACEY,MACAE,QAAQK,IAAI,EACZV,yBACAe,sCACAD,mBACA;QAAEsD,MAAMf;QAAcgB,IAAIxD;QAAoBS;QAAMD;IAAS;IAG/D,MAAMpC,gCAAgCkB,MAAM;QAACH;KAAwB;IAErE,MAAMnB,qBAAqBsB;IAC3B,OAAO,IACLnB,oBAAoBmB,MAAMC,QAAQkE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAerE,iBAAiB"}
@@ -1,6 +1,6 @@
1
1
  import { McpClient } from '@strands-agents/sdk';
2
- import { AgentCoreMcpClientStrands } from '../core/agentcore-mcp-client-strands.js';
3
- import { getAgentCoreRuntimeConfig } from '../core/runtime-config.js';
2
+ import { AgentCoreMcpClientStrands } from '../core/agentcore-mcp-client-strands<% if (esm) { %>.js<% } %>';
3
+ import { getAgentCoreRuntimeConfig } from '../core/runtime-config<% if (esm) { %>.js<% } %>';
4
4
 
5
5
  /** Strands client for the <%- mcpServerClassName %> MCP server. */
6
6
  export class <%- mcpServerClassName %>ClientStrands {
@@ -7,6 +7,7 @@ import { addDestructuredImport, addStarExport } from "../../../utils/ast.js";
7
7
  import { formatFilesInSubtree } from "../../../utils/format.js";
8
8
  import { installDependencies } from "../../../utils/install.js";
9
9
  import { addGeneratorMetricsIfApplicable } from "../../../utils/metrics.js";
10
+ import { esmVars } from "../../../utils/module-format.js";
10
11
  import { kebabCase } from "../../../utils/names.js";
11
12
  import { getNpmScope } from "../../../utils/npm-scope.js";
12
13
  import { addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../../utils/nx.js";
@@ -35,7 +36,8 @@ export const tsAgentMcpConnectionGenerator = async (tree, options)=>{
35
36
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'), joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'), {
36
37
  mcpServerKebabCase,
37
38
  mcpServerClassName,
38
- mcpServerPort
39
+ mcpServerPort,
40
+ ...esmVars(tree)
39
41
  }, {
40
42
  overwriteStrategy: OverwriteStrategy.KeepExisting
41
43
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/mcp-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentMcpConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_MCP_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentMcpConnectionGenerator = async (\n tree: Tree,\n options: TsAgentMcpConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const agentComponent = options.sourceComponent;\n const mcpComponent = options.targetComponent;\n\n if (!agentComponent || !mcpComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> mcp connections',\n );\n }\n\n if (mcpComponent.auth && mcpComponent.auth.toLowerCase() !== 'iam') {\n throw new Error(\n `MCP server connection currently only supports IAM authentication, but '${mcpComponent.name}' uses '${mcpComponent.auth}' authentication.`,\n );\n }\n\n const mcpComponentName = mcpComponent.name ?? 'mcp-server';\n const mcpServerClassName = mcpComponent.rc as string;\n const mcpServerKebabCase = kebabCase(mcpServerClassName);\n const mcpServerPort = mcpComponent.port ?? 8000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the MCP core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'mcp');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n mcpServerKebabCase,\n mcpServerClassName,\n mcpServerPort,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${mcpServerKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add MCP tools\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${mcpServerClassName}ClientStrands`;\n const clientVarName =\n mcpServerClassName.charAt(0).toLowerCase() + mcpServerClassName.slice(1);\n\n // Add import for the client\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Set up dev target\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const mcpDevTargetName = `${mcpComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: mcpDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies required by the MCP core client + vended client\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_MCP_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentMcpConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_MCP_CONNECTION_GENERATOR_INFO","filename","tsAgentMcpConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","mcpComponent","targetComponent","Error","auth","toLowerCase","name","mcpComponentName","mcpServerClassName","rc","mcpServerKebabCase","mcpServerPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","agentName","devTargetName","mcpDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAqB;AAC1E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBAAgBR,oCACpBK,MACAC,QAAQE,aAAa;IAGvB,MAAMC,iBAAiBH,QAAQI,eAAe;IAC9C,MAAMC,eAAeL,QAAQM,eAAe;IAE5C,IAAI,CAACH,kBAAkB,CAACE,cAAc;QACpC,M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,eACAE,iBACAC;IAEJ;IAEA,uBAAuB;IACvB,MAAMG,YAAY3B,eAAeO,IAAI,IAAI;IACzC,MAAMqB,gBAAgB,GAAGD,UAAU,IAAI,CAAC;IACxC,MAAME,mBAAmB,GAAGrB,iBAAiB,IAAI,CAAC;IAElD,IAAIV,cAAcgC,OAAO,EAAE,CAACF,cAAc,EAAE;QAC1CvC,kCAAkCS,eAAe8B,eAAe;YAC9DG,UAAU;gBAAChC,cAAcQ,IAAI;aAAC;YAC9ByB,QAAQH;QACV;QACApD,2BAA2BmB,MAAME,cAAcS,IAAI,EAAET;IACvD;IAEA,sEAAsE;IACtEzB,6BACEuB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMN,gCAAgCU,MAAM;QAC1CH;KACD;IAED,MAAMT,qBAAqBY;IAC3B,OAAO,IACLX,oBAAoBW,MAAMC,QAAQoC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAevC,8BAA8B"}
1
+ {"version":3,"sources":["../../../../../../../packages/nx-plugin/src/ts/agent/mcp-connection/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport {\n AGENT_CONNECTION_PROJECT_DIR,\n addTypeScriptClientToAgent,\n addTypeScriptCoreClient,\n ensureTypeScriptAgentConnectionProject,\n} from '../../../utils/agent-connection/agent-connection';\nimport { addDestructuredImport, addStarExport } from '../../../utils/ast';\nimport { formatFilesInSubtree } from '../../../utils/format';\nimport { installDependencies } from '../../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../../utils/metrics';\nimport { esmVars } from '../../../utils/module-format';\nimport { kebabCase } from '../../../utils/names';\nimport { getNpmScope } from '../../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../../utils/nx';\nimport { withVersions } from '../../../utils/versions';\nimport type { TsAgentMcpConnectionGeneratorSchema } from './schema';\n\nexport const TS_AGENT_MCP_CONNECTION_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const tsAgentMcpConnectionGenerator = async (\n tree: Tree,\n options: TsAgentMcpConnectionGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const sourceProject = readProjectConfigurationUnqualified(\n tree,\n options.sourceProject,\n );\n const targetProject = readProjectConfigurationUnqualified(\n tree,\n options.targetProject,\n );\n\n const agentComponent = options.sourceComponent;\n const mcpComponent = options.targetComponent;\n\n if (!agentComponent || !mcpComponent) {\n throw new Error(\n 'Both sourceComponent and targetComponent must be provided for ts#agent -> mcp connections',\n );\n }\n\n if (mcpComponent.auth && mcpComponent.auth.toLowerCase() !== 'iam') {\n throw new Error(\n `MCP server connection currently only supports IAM authentication, but '${mcpComponent.name}' uses '${mcpComponent.auth}' authentication.`,\n );\n }\n\n const mcpComponentName = mcpComponent.name ?? 'mcp-server';\n const mcpServerClassName = mcpComponent.rc as string;\n const mcpServerKebabCase = kebabCase(mcpServerClassName);\n const mcpServerPort = mcpComponent.port ?? 8000;\n\n const npmScope = getNpmScope(tree);\n\n // 1. Ensure the shared agent-connection project exists + has the MCP core client\n await ensureTypeScriptAgentConnectionProject(tree);\n await addTypeScriptCoreClient(tree, 'mcp');\n\n // 2. Generate the per-connection <Name>Client into app/\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'agent-connection', 'app'),\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'app'),\n {\n mcpServerKebabCase,\n mcpServerClassName,\n mcpServerPort,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add re-export to index.ts\n await addStarExport(\n tree,\n joinPathFragments(AGENT_CONNECTION_PROJECT_DIR, 'src', 'index.ts'),\n `./app/${mcpServerKebabCase}-client-strands.js`,\n );\n\n // 3. AST transform agent.ts to add MCP tools\n const agentSourceDir = joinPathFragments(\n sourceProject.root,\n agentComponent.path ?? 'src',\n );\n const agentFilePath = joinPathFragments(agentSourceDir, 'agent.ts');\n\n if (tree.exists(agentFilePath)) {\n const clientClassName = `${mcpServerClassName}ClientStrands`;\n const clientVarName =\n mcpServerClassName.charAt(0).toLowerCase() + mcpServerClassName.slice(1);\n\n // Add import for the client\n await addDestructuredImport(\n tree,\n agentFilePath,\n [clientClassName],\n `:${npmScope}/agent-connection`,\n );\n\n await addTypeScriptClientToAgent(\n tree,\n agentFilePath,\n clientClassName,\n clientVarName,\n );\n }\n\n // 4. Set up dev target\n const agentName = agentComponent.name ?? 'agent';\n const devTargetName = `${agentName}-dev`;\n const mcpDevTargetName = `${mcpComponentName}-dev`;\n\n if (sourceProject.targets?.[devTargetName]) {\n addDependencyToTargetIfNotPresent(sourceProject, devTargetName, {\n projects: [targetProject.name],\n target: mcpDevTargetName,\n });\n updateProjectConfiguration(tree, sourceProject.name, sourceProject);\n }\n\n // 5. Add dependencies required by the MCP core client + vended client\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@modelcontextprotocol/sdk',\n '@strands-agents/sdk',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n 'aws4fetch',\n '@aws-sdk/credential-providers',\n ]),\n {},\n );\n\n await addGeneratorMetricsIfApplicable(tree, [\n TS_AGENT_MCP_CONNECTION_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentMcpConnectionGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","AGENT_CONNECTION_PROJECT_DIR","addTypeScriptClientToAgent","addTypeScriptCoreClient","ensureTypeScriptAgentConnectionProject","addDestructuredImport","addStarExport","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScope","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","withVersions","TS_AGENT_MCP_CONNECTION_GENERATOR_INFO","filename","tsAgentMcpConnectionGenerator","tree","options","sourceProject","targetProject","agentComponent","sourceComponent","mcpComponent","targetComponent","Error","auth","toLowerCase","name","mcpComponentName","mcpServerClassName","rc","mcpServerKebabCase","mcpServerPort","port","npmScope","dirname","overwriteStrategy","KeepExisting","agentSourceDir","root","path","agentFilePath","exists","clientClassName","clientVarName","charAt","slice","agentName","devTargetName","mcpDevTargetName","targets","projects","target","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SACEC,4BAA4B,EAC5BC,0BAA0B,EAC1BC,uBAAuB,EACvBC,sCAAsC,QACjC,sDAAmD;AAC1D,SAASC,qBAAqB,EAAEC,aAAa,QAAQ,wBAAqB;AAC1E,SAASC,oBAAoB,QAAQ,2BAAwB;AAC7D,SAASC,mBAAmB,QAAQ,4BAAyB;AAC7D,SAASC,+BAA+B,QAAQ,4BAAyB;AACzE,SAASC,OAAO,QAAQ,kCAA+B;AACvD,SAASC,SAAS,QAAQ,0BAAuB;AACjD,SAASC,WAAW,QAAQ,8BAA2B;AACvD,SACEC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,uBAAoB;AAC3B,SAASC,YAAY,QAAQ,6BAA0B;AAGvD,OAAO,MAAMC,yCACXH,iBAAiB,YAAYI,QAAQ,EAAE;AAEzC,OAAO,MAAMC,gCAAgC,OAC3CC,MACAC;IAEA,MAAMC,gBAAgBP,oCACpBK,MACAC,QAAQC,aAAa;IAEvB,MAAMC,gBA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,CAAC,GAAGnB,WAAW,KAAKG,mBAAmBiB,KAAK,CAAC;QAExE,4BAA4B;QAC5B,MAAM7C,sBACJe,MACAyB,eACA;YAACE;SAAgB,EACjB,CAAC,CAAC,EAAET,SAAS,iBAAiB,CAAC;QAGjC,MAAMpC,2BACJkB,MACAyB,eACAE,iBACAC;IAEJ;IAEA,uBAAuB;IACvB,MAAMG,YAAY3B,eAAeO,IAAI,IAAI;IACzC,MAAMqB,gBAAgB,GAAGD,UAAU,IAAI,CAAC;IACxC,MAAME,mBAAmB,GAAGrB,iBAAiB,IAAI,CAAC;IAElD,IAAIV,cAAcgC,OAAO,EAAE,CAACF,cAAc,EAAE;QAC1CvC,kCAAkCS,eAAe8B,eAAe;YAC9DG,UAAU;gBAAChC,cAAcQ,IAAI;aAAC;YAC9ByB,QAAQH;QACV;QACArD,2BAA2BoB,MAAME,cAAcS,IAAI,EAAET;IACvD;IAEA,sEAAsE;IACtE1B,6BACEwB,MACAJ,aAAa;QACX;QACA;QACA;QACA;QACA;QACA;KACD,GACD,CAAC;IAGH,MAAMP,gCAAgCW,MAAM;QAC1CH;KACD;IAED,MAAMV,qBAAqBa;IAC3B,OAAO,IACLZ,oBAAoBY,MAAMC,QAAQoC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAevC,8BAA8B"}
@@ -44,8 +44,9 @@ interface TranslateConfig {
44
44
  translationCommitMessage?: string;
45
45
  }
46
46
 
47
- const PROJECT_ROOT = path.resolve(__dirname, '..');
48
- const CONFIG_PATH = path.resolve(__dirname, 'translate.config.json');
47
+ const SCRIPTS_DIR = <% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>;
48
+ const PROJECT_ROOT = path.resolve(SCRIPTS_DIR, '..');
49
+ const CONFIG_PATH = path.resolve(SCRIPTS_DIR, 'translate.config.json');
49
50
  const config: TranslateConfig = JSON.parse(
50
51
  fs.readFileSync(CONFIG_PATH, 'utf-8'),
51
52
  );
@@ -5,6 +5,7 @@
5
5
  import { formatFilesInSubtree } from "../../utils/format.js";
6
6
  import { installDependencies } from "../../utils/install.js";
7
7
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
8
+ import { isEsmWorkspace } from "../../utils/module-format.js";
8
9
  import { toKebabCase } from "../../utils/names.js";
9
10
  import { getNpmScopePrefix } from "../../utils/npm-scope.js";
10
11
  import { addGeneratorMetadata, getGeneratorInfo, projectExists } from "../../utils/nx.js";
@@ -81,6 +82,7 @@ export const tsAstroDocsGenerator = async (tree, schema)=>{
81
82
  title: schema.name,
82
83
  includeTranslation,
83
84
  includeBlog,
85
+ esm: isEsmWorkspace(tree),
84
86
  pkgMgrCmd: getPackageManagerDisplayCommands().exec,
85
87
  today: new Date().toISOString().slice(0, 10)
86
88
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/astro-docs/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toKebabCase } from '../../utils/names';\nimport { getNpmScopePrefix } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport { type ITsDepVersion, withVersions } from '../../utils/versions';\nimport type { TsAstroDocsGeneratorSchema } from './schema';\n\nexport const TS_ASTRO_DOCS_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAstroDocsGenerator = async (\n tree: Tree,\n schema: TsAstroDocsGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const includeTranslation = !(schema.noTranslation ?? false);\n const includeBlog = !(schema.noBlog ?? false);\n const npmScopePrefix = getNpmScopePrefix(tree);\n const docsNameKebabCase = toKebabCase(schema.name);\n const fullyQualifiedName = `${npmScopePrefix}${docsNameKebabCase}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || docsNameKebabCase,\n );\n\n const alreadyExists = projectExists(tree, fullyQualifiedName);\n\n const targets: ProjectConfiguration['targets'] = {\n build: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro build',\n cwd: dir,\n },\n outputs: [`{workspaceRoot}/${dir}/dist`],\n cache: true,\n },\n start: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro dev',\n cwd: dir,\n },\n continuous: true,\n },\n serve: {\n dependsOn: ['start'],\n },\n preview: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro preview',\n cwd: dir,\n },\n dependsOn: ['build'],\n continuous: true,\n },\n };\n\n if (includeTranslation) {\n targets['translate'] = {\n executor: 'nx:run-commands',\n options: {\n command: 'tsx ./scripts/translate.ts',\n cwd: dir,\n forwardAllArgs: true,\n },\n };\n }\n\n if (!alreadyExists) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'application',\n targets,\n });\n }\n\n const templateOptions = {\n fullyQualifiedName,\n title: schema.name,\n includeTranslation,\n includeBlog,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n today: new Date().toISOString().slice(0, 10),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'base'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // The sample blog post is always emitted above — drop it if the user opted out.\n if (!includeBlog) {\n tree.delete(\n joinPathFragments(\n dir,\n 'src',\n 'content',\n 'docs',\n 'en',\n 'blog',\n 'welcome.mdx',\n ),\n );\n }\n\n if (includeTranslation) {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'translation'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_ASTRO_DOCS_GENERATOR_INFO, {\n framework: 'astro',\n includeTranslation,\n includeBlog,\n });\n\n const dependencies: ITsDepVersion[] = ['astro', '@astrojs/starlight'];\n const devDependencies: ITsDepVersion[] = [];\n\n if (includeBlog) {\n dependencies.push('starlight-blog');\n }\n\n if (includeTranslation) {\n dependencies.push(\n '@strands-agents/sdk',\n 'commander',\n 'fast-glob',\n 'fs-extra',\n 'simple-git',\n );\n devDependencies.push('tsx', '@types/fs-extra');\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions(dependencies),\n withVersions(devDependencies),\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_ASTRO_DOCS_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAstroDocsGenerator;\n"],"names":["addDependenciesToPackageJson","addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","getPackageManagerDisplayCommands","withVersions","TS_ASTRO_DOCS_GENERATOR_INFO","filename","tsAstroDocsGenerator","tree","schema","includeTranslation","noTranslation","includeBlog","noBlog","npmScopePrefix","docsNameKebabCase","name","fullyQualifiedName","dir","directory","subDirectory","alreadyExists","targets","build","executor","options","command","cwd","outputs","cache","start","continuous","serve","dependsOn","preview","forwardAllArgs","root","sourceRoot","projectType","templateOptions","title","pkgMgrCmd","exec","today","Date","toISOString","slice","dirname","overwriteStrategy","KeepExisting","delete","framework","dependencies","devDependencies","push","preferIn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EFD,gBAAgBC,IAAI,CAAC,OAAO;IAC9B;IAEAhE,6BACEkB,MACAJ,aAAagD,eACbhD,aAAaiD;IAGf,MAAMxD,gCAAgCW,MAAM;QAACH;KAA6B;IAE1E,MAAMV,qBAAqBa;IAC3B,OAAO,IACLZ,oBAAoBY,MAAMC,OAAO8C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAejD,qBAAqB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/astro-docs/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { toKebabCase } from '../../utils/names';\nimport { getNpmScopePrefix } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport { type ITsDepVersion, withVersions } from '../../utils/versions';\nimport type { TsAstroDocsGeneratorSchema } from './schema';\n\nexport const TS_ASTRO_DOCS_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAstroDocsGenerator = async (\n tree: Tree,\n schema: TsAstroDocsGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const includeTranslation = !(schema.noTranslation ?? false);\n const includeBlog = !(schema.noBlog ?? false);\n const npmScopePrefix = getNpmScopePrefix(tree);\n const docsNameKebabCase = toKebabCase(schema.name);\n const fullyQualifiedName = `${npmScopePrefix}${docsNameKebabCase}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || docsNameKebabCase,\n );\n\n const alreadyExists = projectExists(tree, fullyQualifiedName);\n\n const targets: ProjectConfiguration['targets'] = {\n build: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro build',\n cwd: dir,\n },\n outputs: [`{workspaceRoot}/${dir}/dist`],\n cache: true,\n },\n start: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro dev',\n cwd: dir,\n },\n continuous: true,\n },\n serve: {\n dependsOn: ['start'],\n },\n preview: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro preview',\n cwd: dir,\n },\n dependsOn: ['build'],\n continuous: true,\n },\n };\n\n if (includeTranslation) {\n targets['translate'] = {\n executor: 'nx:run-commands',\n options: {\n command: 'tsx ./scripts/translate.ts',\n cwd: dir,\n forwardAllArgs: true,\n },\n };\n }\n\n if (!alreadyExists) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'application',\n targets,\n });\n }\n\n const templateOptions = {\n fullyQualifiedName,\n title: schema.name,\n includeTranslation,\n includeBlog,\n esm: isEsmWorkspace(tree),\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n today: new Date().toISOString().slice(0, 10),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'base'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // The sample blog post is always emitted above — drop it if the user opted out.\n if (!includeBlog) {\n tree.delete(\n joinPathFragments(\n dir,\n 'src',\n 'content',\n 'docs',\n 'en',\n 'blog',\n 'welcome.mdx',\n ),\n );\n }\n\n if (includeTranslation) {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'translation'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_ASTRO_DOCS_GENERATOR_INFO, {\n framework: 'astro',\n includeTranslation,\n includeBlog,\n });\n\n const dependencies: ITsDepVersion[] = ['astro', '@astrojs/starlight'];\n const devDependencies: ITsDepVersion[] = [];\n\n if (includeBlog) {\n dependencies.push('starlight-blog');\n }\n\n if (includeTranslation) {\n dependencies.push(\n '@strands-agents/sdk',\n 'commander',\n 'fast-glob',\n 'fs-extra',\n 'simple-git',\n );\n devDependencies.push('tsx', '@types/fs-extra');\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions(dependencies),\n withVersions(devDependencies),\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_ASTRO_DOCS_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAstroDocsGenerator;\n"],"names":["addDependenciesToPackageJson","addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","getPackageManagerDisplayCommands","withVersions","TS_ASTRO_DOCS_GENERATOR_INFO","filename","tsAstroDocsGenerator","tree","schema","includeTranslation","noTranslation","includeBlog","noBlog","npmScopePrefix","docsNameKebabCase","name","fullyQualifiedName","dir","directory","subDirectory","alreadyExists","targets","build","executor","options","command","cwd","outputs","cache","start","continuous","serve","dependsOn","preview","forwardAllArgs","root","sourceRoot","projectType","templateOptions","title","esm","pkgMgrCmd","exec","today","Date","toISOString","slice","dirname","overwriteStrategy","KeepExisting","delete","framework","dependencies","devDependencies","push","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAGZ,aAAa;AACpB,SAASC,oBAAoB,QAAQ,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AM1D,gCAAgCY,MAAM;QAACH;KAA6B;IAE1E,MAAMX,qBAAqBc;IAC3B,OAAO,IACLb,oBAAoBa,MAAMC,OAAO+C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAelD,qBAAqB"}
@@ -35,7 +35,7 @@ exports[`ts#dynamodb generator > should generate terraform modules when iac is t
35
35
  required_providers {
36
36
  aws = {
37
37
  source = "hashicorp/aws"
38
- version = "6.52.0"
38
+ version = "6.54.0"
39
39
  }
40
40
  }
41
41
  }
@@ -192,7 +192,7 @@ exports[`ts#dynamodb generator > should generate terraform modules when iac is t
192
192
  required_providers {
193
193
  aws = {
194
194
  source = "hashicorp/aws"
195
- version = "6.52.0"
195
+ version = "6.54.0"
196
196
  }
197
197
  random = {
198
198
  source = "hashicorp/random"
@@ -1,13 +1,16 @@
1
1
  import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
2
  import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
3
3
  import { readFileSync } from 'fs';
4
- import { join, dirname } from 'path';
4
+ import { join<% if (esm) { %>, dirname<% } %> } from 'path';
5
+ <%_ if (esm) { _%>
5
6
  import { fileURLToPath } from 'url';
7
+ <%_ } _%>
6
8
 
7
9
  // Generated: must match runtimeConfigKey in config.json
8
10
  const runtimeConfigKey = '<%= runtimeConfigKey %>';
9
-
11
+ <% if (esm) { %>
10
12
  const __dirname = dirname(fileURLToPath(import.meta.url));
13
+ <%_ } _%>
11
14
  // config.json is only present in local dev (not included in the deployed bundle); guard with LOCAL_DEV check
12
15
  const localDev = () =>
13
16
  JSON.parse(readFileSync(join(__dirname, '../config.json'), 'utf-8')).localDev;
@@ -1,5 +1,5 @@
1
1
  import { Entity } from 'electrodb';
2
- import { getDynamoDBClient, resolveTableName } from '../client.js';
2
+ import { getDynamoDBClient, resolveTableName } from '../client<% if (esm) { %>.js<% } %>';
3
3
 
4
4
  // Example entity - replace with your own entities using ElectroDB
5
5
  // See https://electrodb.dev/en/modeling/entities/ for documentation
@@ -1 +1 @@
1
- export { createExampleEntity } from './example.js';
1
+ export { createExampleEntity } from './example<% if (esm) { %>.js<% } %>';
@@ -1,2 +1,2 @@
1
- export { getDynamoDBClient, resolveTableName } from './client.js';
2
- export * from './entities/index.js';
1
+ export { getDynamoDBClient, resolveTableName } from './client<% if (esm) { %>.js<% } %>';
2
+ export * from './entities/index<% if (esm) { %>.js<% } %>';
@@ -9,6 +9,7 @@ import { formatFilesInSubtree } from "../../utils/format.js";
9
9
  import { resolveIac } from "../../utils/iac.js";
10
10
  import { installDependencies } from "../../utils/install.js";
11
11
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
12
+ import { esmVars } from "../../utils/module-format.js";
12
13
  import { kebabCase, toClassName } from "../../utils/names.js";
13
14
  import { getNpmScope } from "../../utils/npm-scope.js";
14
15
  import { addGeneratorMetadata, getGeneratorInfo } from "../../utils/nx.js";
@@ -51,7 +52,8 @@ export const tsDynamoDBGenerator = async (tree, options)=>{
51
52
  localDynamoDBPort,
52
53
  localTableName,
53
54
  containerName,
54
- containerEngine
55
+ containerEngine,
56
+ ...esmVars(tree)
55
57
  };
56
58
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), dir, templateOptions);
57
59
  await sharedDynamoDBScriptsGenerator(tree);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/dynamodb/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { relative } from 'node:path';\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n readProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { resolveContainers } from '../../utils/containers';\nimport { addDynamoDBInfra } from '../../utils/dynamodb-constructs/dynamodb-constructs';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { assignSharedPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport {\n DYNAMODB_GENERATOR_IDS,\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants';\nimport { sharedDynamoDBScriptsGenerator } from '../../utils/shared-dynamodb-scripts';\nimport { withVersions } from '../../utils/versions';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator';\nimport type { TsDynamoDBGeneratorSchema } from './schema';\n\nexport const TS_DYNAMODB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsDynamoDBGenerator = async (\n tree: Tree,\n options: TsDynamoDBGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(options.name);\n const localTableName = `${getNpmScope(tree)}-${kebabCase(options.tableName ?? options.name)}`;\n const containerEngine = await resolveContainers(tree, 'inherit');\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n });\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: options.directory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n\n const localDynamoDBPort = assignSharedPort(\n tree,\n projectConfig,\n DYNAMODB_GENERATOR_IDS,\n 8000,\n );\n\n const containerName = `${getNpmScope(tree)}-dynamodb`;\n\n const templateOptions = {\n runtimeConfigKey: nameClassName,\n localDynamoDBPort,\n localTableName,\n containerName,\n containerEngine,\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n );\n\n await sharedDynamoDBScriptsGenerator(tree);\n\n const scriptsDir = relative(\n dir,\n joinPathFragments(PACKAGES_DIR, SHARED_SCRIPTS_DIR, 'src', 'dynamodb'),\n );\n\n projectConfig.targets['pull-image'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/pull-image.ts`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['dev'] = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `tsx ${scriptsDir}/start-container.ts`,\n `tsx ${scriptsDir}/create-local-table.ts`,\n ],\n parallel: true,\n cwd: '{projectRoot}',\n },\n };\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n addGeneratorMetadata(tree, fullyQualifiedName, TS_DYNAMODB_GENERATOR_INFO);\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n await addDynamoDBInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n nameClassName,\n nameKebabCase,\n tableName: localTableName,\n projectRoot: dir,\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@aws-sdk/client-dynamodb',\n 'electrodb',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ]),\n withVersions(['tsx', '@types/aws-lambda', '@types/node']),\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_DYNAMODB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsDynamoDBGenerator;\n"],"names":["relative","addDependenciesToPackageJson","generateFiles","joinPathFragments","readProjectConfiguration","updateProjectConfiguration","resolveContainers","addDynamoDBInfra","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScope","addGeneratorMetadata","getGeneratorInfo","assignSharedPort","sharedConstructsGenerator","DYNAMODB_GENERATOR_IDS","PACKAGES_DIR","SHARED_SCRIPTS_DIR","sharedDynamoDBScriptsGenerator","withVersions","tsProjectGenerator","getTsLibDetails","TS_DYNAMODB_GENERATOR_INFO","filename","tsDynamoDBGenerator","tree","options","nameKebabCase","name","nameClassName","localTableName","tableName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","projectConfig","localDynamoDBPort","containerName","templateOptions","runtimeConfigKey","dirname","scriptsDir","targets","executor","command","cwd","continuous","commands","parallel","infra","iac","projectName","projectRoot","languages"],"mappings":"AAAA;;;CAGC,GAED,SAASA,QAAQ,QAAQ,YAAY;AACrC,SACEC,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EAExBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,gBAAgB,QAAQ,yDAAsD;AACvF,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,oBAAoB,EACpBC,gBAAgB,QAEX,oBAAiB;AACxB,SAASC,gBAAgB,QAAQ,sBAAmB;AACpD,SAASC,yBAAyB,QAAQ,mCAAgC;AAC1E,SACEC,sBAAsB,EACtBC,YAAY,EACZC,kBAAkB,QACb,6CAA0C;AACjD,SAASC,8BAA8B,QAAQ,yCAAsC;AACrF,SAASC,YAAY,QAAQ,0BAAuB;AACpD,OAAOC,sBAAsBC,eAAe,QAAQ,sBAAmB;AAGvE,OAAO,MAAMC,6BAA8CV,iBACzD,YAAYW,QAAQ,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cO,OAAO,CAAC,MAAM,GAAG;QAC7BC,UAAU;QACVG,YAAY;QACZxB,SAAS;YACPyB,UAAU;gBACR,CAAC,IAAI,EAAEN,WAAW,mBAAmB,CAAC;gBACtC,CAAC,IAAI,EAAEA,WAAW,sBAAsB,CAAC;aAC1C;YACDO,UAAU;YACVH,KAAK;QACP;IACF;IAEAhD,2BAA2BwB,MAAMQ,oBAAoBM;IACrD5B,qBAAqBc,MAAMQ,oBAAoBX;IAE/C,IAAII,QAAQ2B,KAAK,KAAK,QAAQ;QAC5B,MAAMC,MAAM,MAAMjD,WAAWoB,MAAMC,QAAQ4B,GAAG;QAC9C,MAAMxC,0BAA0BW,MAAM;YAAE6B;QAAI;QAC5C,MAAMnD,iBAAiBsB,MAAM;YAC3B6B;YACAC,aAAatB;YACbJ;YACAF;YACAI,WAAWD;YACX0B,aAAatB;QACf;IACF;IAEArC,6BACE4B,MACAN,aAAa;QACX;QACA;QACA;QACA;KACD,GACDA,aAAa;QAAC;QAAO;QAAqB;KAAc;IAG1D,MAAMZ,gCAAgCkB,MAAM;QAACH;KAA2B;IAExE,MAAMlB,qBAAqBqB;IAC3B,OAAO,IACLnB,oBAAoBmB,MAAMC,QAAQY,yBAAyB,EAAE;YAC3DmB,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAejC,oBAAoB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/dynamodb/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { relative } from 'node:path';\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n readProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { resolveContainers } from '../../utils/containers';\nimport { addDynamoDBInfra } from '../../utils/dynamodb-constructs/dynamodb-constructs';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { assignSharedPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport {\n DYNAMODB_GENERATOR_IDS,\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants';\nimport { sharedDynamoDBScriptsGenerator } from '../../utils/shared-dynamodb-scripts';\nimport { withVersions } from '../../utils/versions';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator';\nimport type { TsDynamoDBGeneratorSchema } from './schema';\n\nexport const TS_DYNAMODB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsDynamoDBGenerator = async (\n tree: Tree,\n options: TsDynamoDBGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(options.name);\n const localTableName = `${getNpmScope(tree)}-${kebabCase(options.tableName ?? options.name)}`;\n const containerEngine = await resolveContainers(tree, 'inherit');\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n });\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: options.directory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n\n const localDynamoDBPort = assignSharedPort(\n tree,\n projectConfig,\n DYNAMODB_GENERATOR_IDS,\n 8000,\n );\n\n const containerName = `${getNpmScope(tree)}-dynamodb`;\n\n const templateOptions = {\n runtimeConfigKey: nameClassName,\n localDynamoDBPort,\n localTableName,\n containerName,\n containerEngine,\n ...esmVars(tree),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n );\n\n await sharedDynamoDBScriptsGenerator(tree);\n\n const scriptsDir = relative(\n dir,\n joinPathFragments(PACKAGES_DIR, SHARED_SCRIPTS_DIR, 'src', 'dynamodb'),\n );\n\n projectConfig.targets['pull-image'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/pull-image.ts`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['dev'] = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `tsx ${scriptsDir}/start-container.ts`,\n `tsx ${scriptsDir}/create-local-table.ts`,\n ],\n parallel: true,\n cwd: '{projectRoot}',\n },\n };\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n addGeneratorMetadata(tree, fullyQualifiedName, TS_DYNAMODB_GENERATOR_INFO);\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n await addDynamoDBInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n nameClassName,\n nameKebabCase,\n tableName: localTableName,\n projectRoot: dir,\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@aws-sdk/client-dynamodb',\n 'electrodb',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ]),\n withVersions(['tsx', '@types/aws-lambda', '@types/node']),\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_DYNAMODB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsDynamoDBGenerator;\n"],"names":["relative","addDependenciesToPackageJson","generateFiles","joinPathFragments","readProjectConfiguration","updateProjectConfiguration","resolveContainers","addDynamoDBInfra","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addGeneratorMetadata","getGeneratorInfo","assignSharedPort","sharedConstructsGenerator","DYNAMODB_GENERATOR_IDS","PACKAGES_DIR","SHARED_SCRIPTS_DIR","sharedDynamoDBScriptsGenerator","withVersions","tsProjectGenerator","getTsLibDetails","TS_DYNAMODB_GENERATOR_INFO","filename","tsDynamoDBGenerator","tree","options","nameKebabCase","name","nameClassName","localTableName","tableName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","projectConfig","localDynamoDBPort","containerName","templateOptions","runtimeConfigKey","dirname","scriptsDir","targets","executor","command","cwd","continuous","commands","parallel","infra","iac","projectName","projectRoot","languages"],"mappings":"AAAA;;;CAGC,GAED,SAASA,QAAQ,QAAQ,YAAY;AACrC,SACEC,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EAExBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,gBAAgB,QAAQ,yDAAsD;AACvF,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,oBAAoB,EACpBC,gBAAgB,QAEX,oBAAiB;AACxB,SAASC,gBAAgB,QAAQ,sBAAmB;AACpD,SAASC,yBAAyB,QAAQ,mCAAgC;AAC1E,SACEC,sBAAsB,EACtBC,YAAY,EACZC,kBAAkB,QACb,6CAA0C;AACjD,SAASC,8BAA8B,QAAQ,yCAAsC;AACrF,SAASC,YAAY,QAAQ,0BAAuB;AACpD,OAAOC,s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;QACpCC,UAAU;QACVrB,SAAS;YACPsB,SAAS,CAAC,IAAI,EAAEH,WAAW,cAAc,CAAC;YAC1CI,KAAK;QACP;IACF;IACAV,cAAcO,OAAO,CAAC,MAAM,GAAG;QAC7BC,UAAU;QACVG,YAAY;QACZxB,SAAS;YACPyB,UAAU;gBACR,CAAC,IAAI,EAAEN,WAAW,mBAAmB,CAAC;gBACtC,CAAC,IAAI,EAAEA,WAAW,sBAAsB,CAAC;aAC1C;YACDO,UAAU;YACVH,KAAK;QACP;IACF;IAEAjD,2BAA2ByB,MAAMQ,oBAAoBM;IACrD5B,qBAAqBc,MAAMQ,oBAAoBX;IAE/C,IAAII,QAAQ2B,KAAK,KAAK,QAAQ;QAC5B,MAAMC,MAAM,MAAMlD,WAAWqB,MAAMC,QAAQ4B,GAAG;QAC9C,MAAMxC,0BAA0BW,MAAM;YAAE6B;QAAI;QAC5C,MAAMpD,iBAAiBuB,MAAM;YAC3B6B;YACAC,aAAatB;YACbJ;YACAF;YACAI,WAAWD;YACX0B,aAAatB;QACf;IACF;IAEAtC,6BACE6B,MACAN,aAAa;QACX;QACA;QACA;QACA;KACD,GACDA,aAAa;QAAC;QAAO;QAAqB;KAAc;IAG1D,MAAMb,gCAAgCmB,MAAM;QAACH;KAA2B;IAExE,MAAMnB,qBAAqBsB;IAC3B,OAAO,IACLpB,oBAAoBoB,MAAMC,QAAQY,yBAAyB,EAAE;YAC3DmB,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAejC,oBAAoB"}
@@ -139,7 +139,7 @@ exports[`ts-lambda-function generator > terraform iac > should generate terrafor
139
139
  required_providers {
140
140
  aws = {
141
141
  source = "hashicorp/aws"
142
- version = "6.52.0"
142
+ version = "6.54.0"
143
143
  }
144
144
  archive = {
145
145
  source = "hashicorp/archive"
@@ -320,7 +320,7 @@ exports[`ts-lambda-function generator > terraform iac > should match snapshot fo
320
320
  required_providers {
321
321
  aws = {
322
322
  source = "hashicorp/aws"
323
- version = "6.52.0"
323
+ version = "6.54.0"
324
324
  }
325
325
  archive = {
326
326
  source = "hashicorp/archive"
@@ -6,6 +6,7 @@ import { libraryGenerator } from "@nx/js";
6
6
  import { formatFilesInSubtree } from "../../utils/format.js";
7
7
  import { installDependencies } from "../../utils/install.js";
8
8
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
9
+ import { isEsmWorkspace } from "../../utils/module-format.js";
9
10
  import { toKebabCase } from "../../utils/names.js";
10
11
  import { getNpmScopePrefix } from "../../utils/npm-scope.js";
11
12
  import { addGeneratorMetadata, getGeneratorInfo, projectExists } from "../../utils/nx.js";
@@ -30,6 +31,9 @@ export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
30
31
  * Generates a typescript project
31
32
  */ export const tsProjectGenerator = async (tree, schema)=>{
32
33
  const { fullyQualifiedName, dir } = getTsLibDetails(tree, schema);
34
+ // The module format is workspace-wide, established by the preset when the
35
+ // workspace is created, so vending generators always infer it from the tree.
36
+ const esm = isEsmWorkspace(tree);
33
37
  // Only scaffold the project on first run; on re-run skip creation so user
34
38
  // edits are preserved, but continue to (re)apply the configuration below.
35
39
  if (!projectExists(tree, fullyQualifiedName)) {
@@ -49,6 +53,7 @@ export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
49
53
  tree.delete(joinPathFragments(dir, 'src'));
50
54
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), joinPathFragments(dir), {
51
55
  fullyQualifiedName,
56
+ esm,
52
57
  pkgMgrCmd: getPackageManagerDisplayCommands().exec
53
58
  }, {
54
59
  overwriteStrategy: OverwriteStrategy.KeepExisting
@@ -56,7 +61,8 @@ export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
56
61
  }
57
62
  await configureTsProject(tree, {
58
63
  dir,
59
- fullyQualifiedName
64
+ fullyQualifiedName,
65
+ esm
60
66
  });
61
67
  const projectConfiguration = readProjectConfiguration(tree, fullyQualifiedName);
62
68
  const targets = projectConfiguration.targets;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n type NxJsonConfiguration,\n OverwriteStrategy,\n readProjectConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { libraryGenerator } from '@nx/js';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { toKebabCase } from '../../utils/names';\nimport { getNpmScopePrefix } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport type { TsProjectGeneratorSchema } from './schema';\nimport { configureTsProject } from './ts-project-utils';\n\nexport const TS_LIB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport interface TsLibDetails {\n /**\n * Full package name including scope (eg @foo/bar)\n */\n readonly fullyQualifiedName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n}\n\n/**\n * Returns details about the TS library to be created\n */\nexport const getTsLibDetails = (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): TsLibDetails => {\n const scope = getNpmScopePrefix(tree);\n const normalizedName = toKebabCase(schema.name);\n const fullyQualifiedName = `${scope}${normalizedName}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName };\n};\n\n/**\n * Generates a typescript project\n */\nexport const tsProjectGenerator = async (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, schema);\n\n // Only scaffold the project on first run; on re-run skip creation so user\n // edits are preserved, but continue to (re)apply the configuration below.\n if (!projectExists(tree, fullyQualifiedName)) {\n await libraryGenerator(tree, {\n ...schema,\n name: fullyQualifiedName,\n directory: dir,\n skipPackageJson: true,\n bundler: 'tsc', // TODO: consider supporting others\n linter: 'none',\n unitTestRunner: 'vitest',\n // Register the @nx/vitest plugin so the test target is inferred rather\n // than emitting the deprecated @nx/vitest:test executor target.\n addPlugin: true,\n });\n\n // Replace with simpler sample source code\n tree.delete(joinPathFragments(dir, 'src'));\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n joinPathFragments(dir),\n {\n fullyQualifiedName,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n await configureTsProject(tree, {\n dir,\n fullyQualifiedName,\n });\n\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n const targets = projectConfiguration.targets;\n\n targets['compile'] = {\n executor: 'nx:run-commands',\n outputs: ['{workspaceRoot}/dist/{projectRoot}/tsc'],\n options: {\n command: 'tsc --build tsconfig.lib.json',\n cwd: '{projectRoot}',\n },\n };\n targets['build'] = {\n dependsOn: ['lint', 'compile', 'test'],\n };\n projectConfiguration.targets = sortObjectKeys(targets);\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);\n\n updateJson(tree, 'nx.json', (nxJson: NxJsonConfiguration) => {\n nxJson.namedInputs = {\n ...nxJson.namedInputs,\n default: [\n ...(nxJson.namedInputs?.default ?? []).filter(\n (input) =>\n typeof input !== 'object' ||\n !('dependentTasksOutputFiles' in input) ||\n !(input.dependentTasksOutputFiles === '**/*' && input.transitive),\n ),\n {\n dependentTasksOutputFiles: '**/*',\n transitive: true,\n },\n ],\n };\n\n nxJson.targetDefaults = {\n ...nxJson.targetDefaults,\n compile: {\n cache: true,\n ...nxJson.targetDefaults?.compile,\n inputs: [\n ...(nxJson.targetDefaults?.compile?.inputs ?? []).filter(\n (i) => i !== 'default',\n ),\n 'default',\n ],\n },\n build: {\n cache: true,\n ...nxJson.targetDefaults?.build,\n inputs: [\n ...(nxJson.targetDefaults?.build?.inputs ?? []).filter(\n (i) => i !== 'default',\n ),\n 'default',\n ],\n },\n test: {\n ...nxJson.targetDefaults?.test,\n inputs: [\n ...(nxJson.targetDefaults?.test?.inputs ?? []).filter(\n (i) => i !== 'default',\n ),\n 'default',\n ],\n },\n };\n\n // Ensure we only declare a single typescript plugin with the correct settings\n nxJson.plugins = [\n {\n plugin: '@nx/js/typescript',\n options: {\n typecheck: {\n targetName: 'typecheck',\n },\n build: {\n targetName: 'compile',\n configName: 'tsconfig.lib.json',\n buildDepsName: 'build-deps',\n watchDepsName: 'watch-deps',\n },\n },\n },\n ...(nxJson.plugins ?? []).filter(\n (p) => typeof p === 'string' || p.plugin !== '@nx/js/typescript',\n ),\n ];\n\n return nxJson;\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_LIB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n // `installDependencies` ensures vitest resolves for the `typescript` language (the\n // generated vitest.config.mts imports it and Nx loads that config when\n // computing the project graph), so a deferred install still runs when needed.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\nexport default tsProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","libraryGenerator","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","configureTsProject","TS_LIB_GENERATOR_INFO","filename","getTsLibDetails","tree","schema","scope","normalizedName","name","fullyQualifiedName","dir","directory","subDirectory","tsProjectGenerator","skipPackageJson","bundler","linter","unitTestRunner","addPlugin","delete","dirname","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","projectConfiguration","targets","executor","outputs","options","command","cwd","dependsOn","nxJson","namedInputs","default","filter","input","dependentTasksOutputFiles","transitive","targetDefaults","compile","cache","inputs","i","build","test","plugins","plugin","typecheck","targetName","configName","buildDepsName","watchDepsName","p","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EAEjBC,iBAAiB,EACjBC,wBAAwB,EAExBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,WAAW,QAAQ,uBAAoB;AAChD,SAASC,iBAAiB,QAAQ,2BAAwB;AAC1D,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,gCAAgC,QAAQ,6BAA0B;AAE3E,SAASC,kBAAkB,QAAQ,wBAAqB;AAExD,OAAO,MAAMC,wBAAyCL,iBACpD,YAAYM,QAAQ,EACpB;AAaF;;CAEC,GACD,OAAO,MAAMC,kBAAkB,CAC7BC,MACAC;IAEA,MAAMC,QAAQZ,kBAAkBU;IAChC,MAAMG,iBAAiBd,YAAYY,OAAOG,IAAI;IAC9C,MAAMC,qBAAqB,GAAGH,QAAQC,gBAAgB;IACtD,yDAAyD;IACzD,MAAMG,MAAM1B,kBACVqB,OAAOM,SAAS,IAAI,KACpBN,OAAOO,YAAY,IAAIL;IAEzB,OAAO;QAAEG;QAAKD;IAAmB;AACnC,EAAE;AAEF;;CAEC,GACD,OAAO,MAAMI,qBAAqB,OAChCT,MACAC;IAEA,MAAM,EAAEI,kBAAkB,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a,MAAMC,OAAOkD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AACF,eAAe3C,mBAAmB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n type NxJsonConfiguration,\n OverwriteStrategy,\n readProjectConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { libraryGenerator } from '@nx/js';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { toKebabCase } from '../../utils/names';\nimport { getNpmScopePrefix } from '../../utils/npm-scope';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager';\nimport type { TsProjectGeneratorSchema } from './schema';\nimport { configureTsProject } from './ts-project-utils';\n\nexport const TS_LIB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport interface TsLibDetails {\n /**\n * Full package name including scope (eg @foo/bar)\n */\n readonly fullyQualifiedName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n}\n\n/**\n * Returns details about the TS library to be created\n */\nexport const getTsLibDetails = (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): TsLibDetails => {\n const scope = getNpmScopePrefix(tree);\n const normalizedName = toKebabCase(schema.name);\n const fullyQualifiedName = `${scope}${normalizedName}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName };\n};\n\n/**\n * Generates a typescript project\n */\nexport const tsProjectGenerator = async (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, schema);\n // The module format is workspace-wide, established by the preset when the\n // workspace is created, so vending generators always infer it from the tree.\n const esm = isEsmWorkspace(tree);\n\n // Only scaffold the project on first run; on re-run skip creation so user\n // edits are preserved, but continue to (re)apply the configuration below.\n if (!projectExists(tree, fullyQualifiedName)) {\n await libraryGenerator(tree, {\n ...schema,\n name: fullyQualifiedName,\n directory: dir,\n skipPackageJson: true,\n bundler: 'tsc', // TODO: consider supporting others\n linter: 'none',\n unitTestRunner: 'vitest',\n // Register the @nx/vitest plugin so the test target is inferred rather\n // than emitting the deprecated @nx/vitest:test executor target.\n addPlugin: true,\n });\n\n // Replace with simpler sample source code\n tree.delete(joinPathFragments(dir, 'src'));\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n joinPathFragments(dir),\n {\n fullyQualifiedName,\n esm,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n await configureTsProject(tree, {\n dir,\n fullyQualifiedName,\n esm,\n });\n\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n const targets = projectConfiguration.targets;\n\n targets['compile'] = {\n executor: 'nx:run-commands',\n outputs: ['{workspaceRoot}/dist/{projectRoot}/tsc'],\n options: {\n command: 'tsc --build tsconfig.lib.json',\n cwd: '{projectRoot}',\n },\n };\n targets['build'] = {\n dependsOn: ['lint', 'compile', 'test'],\n };\n projectConfiguration.targets = sortObjectKeys(targets);\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);\n\n updateJson(tree, 'nx.json', (nxJson: NxJsonConfiguration) => {\n nxJson.namedInputs = {\n ...nxJson.namedInputs,\n default: [\n ...(nxJson.namedInputs?.default ?? []).filter(\n (input) =>\n typeof input !== 'object' ||\n !('dependentTasksOutputFiles' in input) ||\n !(input.dependentTasksOutputFiles === '**/*' && input.transitive),\n ),\n {\n dependentTasksOutputFiles: '**/*',\n transitive: true,\n },\n ],\n };\n\n nxJson.targetDefaults = {\n ...nxJson.targetDefaults,\n compile: {\n cache: true,\n ...nxJson.targetDefaults?.compile,\n inputs: [\n ...(nxJson.targetDefaults?.compile?.inputs ?? []).filter(\n (i) => i !== 'default',\n ),\n 'default',\n ],\n },\n build: {\n cache: true,\n ...nxJson.targetDefaults?.build,\n inputs: [\n ...(nxJson.targetDefaults?.build?.inputs ?? []).filter(\n (i) => i !== 'default',\n ),\n 'default',\n ],\n },\n test: {\n ...nxJson.targetDefaults?.test,\n inputs: [\n ...(nxJson.targetDefaults?.test?.inputs ?? []).filter(\n (i) => i !== 'default',\n ),\n 'default',\n ],\n },\n };\n\n // Ensure we only declare a single typescript plugin with the correct settings\n nxJson.plugins = [\n {\n plugin: '@nx/js/typescript',\n options: {\n typecheck: {\n targetName: 'typecheck',\n },\n build: {\n targetName: 'compile',\n configName: 'tsconfig.lib.json',\n buildDepsName: 'build-deps',\n watchDepsName: 'watch-deps',\n },\n },\n },\n ...(nxJson.plugins ?? []).filter(\n (p) => typeof p === 'string' || p.plugin !== '@nx/js/typescript',\n ),\n ];\n\n return nxJson;\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_LIB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n // `installDependencies` ensures vitest resolves for the `typescript` language (the\n // generated vitest.config.mts imports it and Nx loads that config when\n // computing the project graph), so a deferred install still runs when needed.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\nexport default tsProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","libraryGenerator","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","configureTsProject","TS_LIB_GENERATOR_INFO","filename","getTsLibDetails","tree","schema","scope","normalizedName","name","fullyQualifiedName","dir","directory","subDirectory","tsProjectGenerator","esm","skipPackageJson","bundler","linter","unitTestRunner","addPlugin","delete","dirname","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","projectConfiguration","targets","executor","outputs","options","command","cwd","dependsOn","nxJson","namedInputs","default","filter","input","dependentTasksOutputFiles","transitive","targetDefaults","compile","cache","inputs","i","build","test","plugins","plugin","typecheck","targetName","configName","buildDepsName","watchDepsName","p","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EAEjBC,iBAAiB,EACjBC,wBAAwB,EAExBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,cAAc,QAAQ,+BAA4B;AAC3D,SAASC,WAAW,QAAQ,uBAAoB;AAChD,SAASC,iBAAiB,QAAQ,2BAAwB;AAC1D,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,gCAAgC,QAAQ,6BAA0B;AAE3E,SAASC,kBAAkB,QAAQ,wBAAqB;AAExD,OAAO,MAAMC,wBAAyCL,iBACpD,YAAYM,QAAQ,EACpB;AAaF;;CAEC,GACD,OAAO,MAAMC,kBAAkB,CAC7BC,MACAC;IAEA,MAAMC,QAAQZ,kBAAkBU;IAChC,MAAMG,iBAAiBd,YAAYY,OAAOG,IAAI;IAC9C,MAAMC,qBA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Ae;wBACfC,eAAe;oBACjB;gBACF;YACF;eACG,AAACpB,CAAAA,OAAOc,OAAO,IAAI,EAAE,AAAD,EAAGX,MAAM,CAC9B,CAACkB,IAAM,OAAOA,MAAM,YAAYA,EAAEN,MAAM,KAAK;SAEhD;QAED,OAAOf;IACT;IAEA,MAAM3C,gCAAgCa,MAAM;QAACH;KAAsB;IAEnE,MAAMZ,qBAAqBe;IAE3B,mFAAmF;IACnF,uEAAuE;IACvE,8EAA8E;IAC9E,OAAO,IACLd,oBAAoBc,MAAMC,OAAOmD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AACF,eAAe5C,mBAAmB"}
@@ -4,6 +4,7 @@
4
4
  */ import { joinPathFragments, updateJson } from "@nx/devkit";
5
5
  import { join, relative } from "path";
6
6
  import { addLicenseCheckToLintTarget } from "../../license/config.js";
7
+ import { isEsmWorkspace } from "../../utils/module-format.js";
7
8
  import { toScopeAlias } from "../../utils/npm-scope.js";
8
9
  import { configureBiomeLint } from "./biome.js";
9
10
  import { configureVitest } from "./vitest.js";
@@ -27,7 +28,11 @@ import { configureVitest } from "./vitest.js";
27
28
  /**
28
29
  * Updates typescript projects
29
30
  */ export const configureTsProject = async (tree, options)=>{
30
- // Remove conflicting commonjs module from tsconfig
31
+ // When the caller doesn't specify a module format, infer it from the
32
+ // workspace root package.json (defaulting to ESM for a fresh workspace).
33
+ const esm = options.esm ?? isEsmWorkspace(tree);
34
+ // Remove a conflicting `module: commonjs` from the project tsconfig.json
35
+ // (CommonJS is configured on tsconfig.lib.json below when needed).
31
36
  updateJson(tree, join(options.dir, 'tsconfig.json'), (tsConfig)=>({
32
37
  ...tsConfig,
33
38
  compilerOptions: {
@@ -46,7 +51,15 @@ import { configureVitest } from "./vitest.js";
46
51
  baseUrl: undefined,
47
52
  rootDir: '.',
48
53
  outDir: distDir,
49
- tsBuildInfoFile: join(distDir, 'tsconfig.lib.tsbuildinfo')
54
+ tsBuildInfoFile: join(distDir, 'tsconfig.lib.tsbuildinfo'),
55
+ // @nx/js configures the lib for ESM (module `nodenext`). CommonJS
56
+ // projects use `node16`, which honours the workspace's
57
+ // `type: commonjs`, emits CommonJS and resolves extensionless relative
58
+ // imports. (Plain `commonjs`/`node` is deprecated in TypeScript 6.)
59
+ ...esm ? {} : {
60
+ module: 'node16',
61
+ moduleResolution: 'node16'
62
+ }
50
63
  }
51
64
  }));
52
65
  }
@@ -79,10 +92,12 @@ import { configureVitest } from "./vitest.js";
79
92
  ])
80
93
  }));
81
94
  }
82
- // Update the root package.json
95
+ // Update the root package.json. ESM projects require `type: module`; for
96
+ // CommonJS we write an explicit `type: commonjs` marker (which Node treats
97
+ // identically to an absent `type`).
83
98
  updateJson(tree, 'package.json', (packageJson)=>({
84
99
  ...packageJson,
85
- type: 'module'
100
+ type: esm ? 'module' : 'commonjs'
86
101
  }));
87
102
  // Remove package.json if it exists
88
103
  if (tree.exists(join(options.dir, 'package.json'))) {