@aws/nx-plugin 1.0.0-rc.32 → 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 (188) 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/files/client.gen.ts.template +1 -1
  9. package/src/open-api/ts-client/generator.js +5 -1
  10. package/src/open-api/ts-client/generator.js.map +1 -1
  11. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +2 -2
  12. package/src/open-api/ts-hooks/generator.js +5 -1
  13. package/src/open-api/ts-hooks/generator.js.map +1 -1
  14. package/src/preset/__snapshots__/generator.spec.ts.snap +1 -1
  15. package/src/preset/generator.d.ts +1 -1
  16. package/src/preset/generator.js +5 -2
  17. package/src/preset/generator.js.map +1 -1
  18. package/src/preset/schema.d.js.map +1 -1
  19. package/src/preset/schema.d.ts +2 -0
  20. package/src/preset/schema.json +6 -0
  21. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +7 -7
  22. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +8 -8
  23. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +89 -3
  24. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  25. package/src/py/fast-api/__snapshots__/generator.terraform.spec.ts.snap +12 -12
  26. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  27. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +91 -5
  28. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -7
  29. package/src/smithy/ts/api/files/handler.ts.template +2 -2
  30. package/src/smithy/ts/api/files/local-server.ts.template +2 -2
  31. package/src/smithy/ts/api/files/operations/echo.ts.template +2 -2
  32. package/src/smithy/ts/api/files/service.ts.template +3 -3
  33. package/src/smithy/ts/api/generator.js +3 -1
  34. package/src/smithy/ts/api/generator.js.map +1 -1
  35. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +12 -12
  36. package/src/trpc/backend/files/src/client/index.ts.template +1 -1
  37. package/src/trpc/backend/files/src/handler.ts.template +1 -1
  38. package/src/trpc/backend/files/src/index.ts.template +5 -5
  39. package/src/trpc/backend/files/src/init.ts.template +1 -1
  40. package/src/trpc/backend/files/src/local-server.ts.template +1 -1
  41. package/src/trpc/backend/files/src/middleware/index.ts.template +7 -7
  42. package/src/trpc/backend/files/src/procedures/echo.ts.template +2 -2
  43. package/src/trpc/backend/files/src/router.ts.template +2 -2
  44. package/src/trpc/backend/files/src/schema/index.ts.template +1 -1
  45. package/src/trpc/backend/generator.js +3 -1
  46. package/src/trpc/backend/generator.js.map +1 -1
  47. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +89 -3
  48. package/src/ts/agent/a2a-connection/files/agent-connection/app/__targetAgentKebabCase__-client-strands.ts.template +2 -2
  49. package/src/ts/agent/a2a-connection/generator.js +3 -1
  50. package/src/ts/agent/a2a-connection/generator.js.map +1 -1
  51. package/src/ts/agent/files/a2a/index.ts.template +1 -1
  52. package/src/ts/agent/files/ag-ui/index.ts.template +1 -1
  53. package/src/ts/agent/files/http/client.ts.template +2 -2
  54. package/src/ts/agent/files/http/index.ts.template +2 -2
  55. package/src/ts/agent/files/http/router.ts.template +3 -3
  56. package/src/ts/agent/gateway-connection/files/agent-connection/app/__gatewayKebabCase__-client-strands.ts.template +2 -2
  57. package/src/ts/agent/gateway-connection/generator.js +3 -1
  58. package/src/ts/agent/gateway-connection/generator.js.map +1 -1
  59. package/src/ts/agent/generator.js +5 -2
  60. package/src/ts/agent/generator.js.map +1 -1
  61. package/src/ts/agent/mcp-connection/files/agent-connection/app/__mcpServerKebabCase__-client-strands.ts.template +2 -2
  62. package/src/ts/agent/mcp-connection/generator.js +3 -1
  63. package/src/ts/agent/mcp-connection/generator.js.map +1 -1
  64. package/src/ts/astro-docs/files/translation/scripts/translate.ts.template +3 -2
  65. package/src/ts/astro-docs/generator.js +2 -0
  66. package/src/ts/astro-docs/generator.js.map +1 -1
  67. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -2
  68. package/src/ts/dynamodb/files/src/client.ts.template +5 -2
  69. package/src/ts/dynamodb/files/src/entities/example.ts.template +1 -1
  70. package/src/ts/dynamodb/files/src/entities/index.ts.template +1 -1
  71. package/src/ts/dynamodb/files/src/index.ts.template +2 -2
  72. package/src/ts/dynamodb/generator.js +3 -1
  73. package/src/ts/dynamodb/generator.js.map +1 -1
  74. package/src/ts/lambda-function/__snapshots__/generator.spec.ts.snap +2 -2
  75. package/src/ts/lib/generator.js +7 -1
  76. package/src/ts/lib/generator.js.map +1 -1
  77. package/src/ts/lib/ts-project-utils.js +19 -4
  78. package/src/ts/lib/ts-project-utils.js.map +1 -1
  79. package/src/ts/lib/types.d.ts +6 -0
  80. package/src/ts/lib/types.js.map +1 -1
  81. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +94 -8
  82. package/src/ts/mcp-server/generator.js +3 -2
  83. package/src/ts/mcp-server/generator.js.map +1 -1
  84. package/src/ts/nx-generator/files/local/generator.ts.template +2 -2
  85. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +2 -2
  86. package/src/ts/nx-generator/generator.js +5 -2
  87. package/src/ts/nx-generator/generator.js.map +1 -1
  88. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +5 -5
  89. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +2 -2
  90. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +1 -1
  91. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +2 -2
  92. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +2 -2
  93. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +3 -3
  94. package/src/ts/nx-plugin/generator.js +3 -1
  95. package/src/ts/nx-plugin/generator.js.map +1 -1
  96. package/src/ts/nx-plugin/utils.js +7 -4
  97. package/src/ts/nx-plugin/utils.js.map +1 -1
  98. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +4 -4
  99. package/src/ts/rdb/files/src/create-db-user-handler.ts.template +2 -2
  100. package/src/ts/rdb/files/src/index.ts.template +1 -1
  101. package/src/ts/rdb/files/src/migration-handler.ts.template +1 -1
  102. package/src/ts/rdb/files/src/prisma.ts.template +7 -4
  103. package/src/ts/rdb/generator.js +3 -1
  104. package/src/ts/rdb/generator.js.map +1 -1
  105. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +35 -35
  106. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +2 -2
  107. package/src/utils/agent-chat/agent-chat.js +3 -1
  108. package/src/utils/agent-chat/agent-chat.js.map +1 -1
  109. package/src/utils/agent-chat/files/a2a/chat.ts.template +1 -1
  110. package/src/utils/agent-chat/files/ag-ui/chat.ts.template +1 -1
  111. package/src/utils/agent-chat/files/http-py/chat.ts.template +2 -2
  112. package/src/utils/agent-chat/files/http-ts/chat.ts.template +1 -1
  113. package/src/utils/agent-connection/agent-connection.js +4 -1
  114. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  115. package/src/utils/agent-connection/files/core-a2a/agentcore-a2a-client-config.ts.template +2 -2
  116. package/src/utils/agent-connection/files/core-auth/agentcore-fetch.ts.template +1 -1
  117. package/src/utils/agent-connection/files/core-gateway/agentcore-gateway-mcp-transport.ts.template +2 -2
  118. package/src/utils/agent-connection/files/core-mcp/agentcore-mcp-transport.ts.template +2 -2
  119. package/src/utils/agent-connection/files/core-shared/agentcore-transport.ts.template +1 -1
  120. package/src/utils/agent-connection/files/core-strands/a2a/agentcore-a2a-client-strands.ts.template +1 -1
  121. package/src/utils/agent-connection/files/core-strands/base/with-session-id-strands.ts.template +1 -1
  122. package/src/utils/agent-connection/files/core-strands/gateway/agentcore-gateway-mcp-client-strands.ts.template +1 -1
  123. package/src/utils/agent-connection/files/core-strands/mcp/agentcore-mcp-client-strands.ts.template +1 -1
  124. package/src/utils/agent-core-constructs/agent-core-constructs.js +10 -3
  125. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  126. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +3 -3
  127. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +4 -4
  128. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +1 -1
  129. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +27 -0
  130. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +60 -1
  131. package/src/utils/api-constructs/api-constructs.js +8 -2
  132. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  133. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +8 -8
  134. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +8 -8
  135. package/src/utils/api-constructs/files/cdk/core/api/http/http-api.ts.template +3 -3
  136. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account/index.js.template +32 -20
  137. package/src/utils/api-constructs/files/cdk/core/api/rest/api-gateway-account.ts.template +1 -1
  138. package/src/utils/api-constructs/files/cdk/core/api/rest/rest-api.ts.template +4 -4
  139. package/src/utils/api-constructs/files/cdk/core/api/trpc/trpc-utils.ts.template +1 -1
  140. package/src/utils/ast.js +16 -0
  141. package/src/utils/ast.js.map +1 -1
  142. package/src/utils/commands.d.ts +1 -1
  143. package/src/utils/commands.js +4 -1
  144. package/src/utils/commands.js.map +1 -1
  145. package/src/utils/dynamodb-constructs/dynamodb-constructs.js +9 -2
  146. package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
  147. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +3 -3
  148. package/src/utils/dynamodb-constructs/files/cdk/core/dynamodb.ts.template +1 -1
  149. package/src/utils/files/common/constructs/src/core/index.ts.template +4 -4
  150. package/src/utils/files/common/constructs/src/index.ts.template +2 -2
  151. package/src/utils/files/common/infra-config/src/index.ts.template +3 -3
  152. package/src/utils/files/common/infra-config/src/resolve-stage.ts.template +2 -2
  153. package/src/utils/files/common/infra-config/src/stages.config.ts.template +1 -1
  154. package/src/utils/files/common/scripts/src/infra/infra-deploy.ts.template +1 -1
  155. package/src/utils/files/common/scripts/src/infra/infra-destroy.ts.template +1 -1
  156. package/src/utils/files/common/scripts/src/infra/stage-credentials/run.ts.template +3 -3
  157. package/src/utils/files/common/shadcn/src/index.ts.template +2 -2
  158. package/src/utils/function-constructs/files/cdk/app/lambda-functions/__nameKebabCase__.ts.template +1 -1
  159. package/src/utils/function-constructs/function-constructs.js +3 -1
  160. package/src/utils/function-constructs/function-constructs.js.map +1 -1
  161. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +2 -2
  162. package/src/utils/identity-constructs/identity-constructs.js +5 -1
  163. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  164. package/src/utils/module-format.d.ts +28 -0
  165. package/src/utils/module-format.js +28 -0
  166. package/src/utils/module-format.js.map +1 -0
  167. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +5 -5
  168. package/src/utils/rdb-constructs/files/cdk/core/rdb/aurora.ts.template +1 -1
  169. package/src/utils/rdb-constructs/rdb-constructs.js +9 -2
  170. package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
  171. package/src/utils/shared-constructs.js +3 -1
  172. package/src/utils/shared-constructs.js.map +1 -1
  173. package/src/utils/shared-infra-config.js +3 -1
  174. package/src/utils/shared-infra-config.js.map +1 -1
  175. package/src/utils/shared-infra-scripts.js +3 -1
  176. package/src/utils/shared-infra-scripts.js.map +1 -1
  177. package/src/utils/shared-shadcn.js +3 -1
  178. package/src/utils/shared-shadcn.js.map +1 -1
  179. package/src/utils/test.d.ts +2 -0
  180. package/src/utils/test.js +7 -1
  181. package/src/utils/test.js.map +1 -1
  182. package/src/utils/versions.d.ts +58 -58
  183. package/src/utils/versions.js +56 -56
  184. package/src/utils/versions.js.map +1 -1
  185. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +2 -2
  186. package/src/utils/website-constructs/files/cdk/core/static-website.ts.template +2 -2
  187. package/src/utils/website-constructs/website-constructs.js +9 -2
  188. package/src/utils/website-constructs/website-constructs.js.map +1 -1
@@ -12,6 +12,7 @@ import { FsCommands } from "../../utils/fs.js";
12
12
  import { resolveIac } from "../../utils/iac.js";
13
13
  import { installDependencies } from "../../utils/install.js";
14
14
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
15
+ import { isEsmWorkspace } from "../../utils/module-format.js";
15
16
  import { kebabCase, toClassName } from "../../utils/names.js";
16
17
  import { getNpmScope } from "../../utils/npm-scope.js";
17
18
  import { addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
@@ -41,8 +42,8 @@ export const tsMcpServerGenerator = async (tree, options)=>{
41
42
  const projectPackageJsonPath = joinPathFragments(project.root, 'package.json');
42
43
  // Generate esm if the module system is esm, otherwise commonjs. Projects
43
44
  // don't typically have their own package.json (dependencies are declared in
44
- // the workspace root), so fall back to the root which is esm by default.
45
- const esm = readJson(tree, tree.exists(projectPackageJsonPath) ? projectPackageJsonPath : 'package.json').type === 'module';
45
+ // the workspace root), so fall back to the workspace format when absent.
46
+ const esm = tree.exists(projectPackageJsonPath) ? readJson(tree, projectPackageJsonPath).type === 'module' : isEsmWorkspace(tree);
46
47
  // Generate example server
47
48
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), targetSourceDir, {
48
49
  name,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport { addMcpServerInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { 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 { TsMcpServerGeneratorSchema } from './schema';\n\nexport const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsMcpServerGenerator = async (\n tree: Tree,\n options: TsMcpServerGeneratorSchema,\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())}-mcp-server`;\n const name = kebabCase(options.name || defaultName);\n const mcpServerNameClassName = toClassName(name);\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n mcpTargetPrefix,\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\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 const projectPackageJsonPath = joinPathFragments(\n project.root,\n 'package.json',\n );\n\n // Generate esm if the module system is esm, otherwise commonjs. Projects\n // don't typically have their own package.json (dependencies are declared in\n // the workspace root), so fall back to the root which is esm by default.\n const esm =\n readJson(\n tree,\n tree.exists(projectPackageJsonPath)\n ? projectPackageJsonPath\n : 'package.json',\n ).type === 'module';\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n targetSourceDir,\n {\n name,\n esm,\n distDir,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add dependencies\n const deps = withVersions([\n '@modelcontextprotocol/sdk',\n 'zod',\n 'express',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ]);\n const devDeps = withVersions([\n 'tsx',\n '@types/express',\n '@modelcontextprotocol/inspector',\n ]);\n\n // Add hosting based on infra\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}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n });\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-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 // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n } else {\n // No Dockerfile needed for non-hosted MCP\n tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));\n }\n\n addDependenciesToPackageJson(tree, deps, devDeps);\n // Add to the project's package.json too if it has one (e.g. nx plugins),\n // otherwise dependencies live in the workspace root only.\n if (tree.exists(projectPackageJsonPath)) {\n addDependenciesToPackageJson(tree, deps, devDeps, projectPackageJsonPath);\n }\n\n // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range\n // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so\n // without a resolution it installs a separate zod under the SDK's own node_modules.\n // The two zod copies have structurally incompatible types, which breaks type\n // inference for registerTool inputSchema. Scope the resolution to the SDK so\n // other consumers (e.g. @tanstack/router-generator pinning zod@3) are unaffected.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n };\n return packageJson;\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: TS_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/stdio.ts`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- tsx --watch ${relativeSourceDir}/stdio.ts`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(mcpTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_MCP_SERVER_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n mcpTargetPrefix,\n {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["addDependenciesToPackageJson","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addMcpServerInfra","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","TS_VERSIONS","withVersions","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","overwriteStrategy","KeepExisting","deps","devDeps","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","iac","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,wBAAwB,QAAQ,oCAAiC;AAC1E,SAASC,iBAAiB,QAAQ,6DAA0D;AAC5F,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,+BAAgDP,iBAC3D,YAAYQ,QAAQ,EACpB;AAEF,OAAO,MAAMC,uBAAuB,OAClCC,MACAC;IAEA,MAAMC,UAAUX,oCAAoCS,MAAMC,QAAQC,OAAO;IAEzE,IAAI,CAACF,KAAKG,MAAM,CAAClC,kBAAkBiC,QAAQE,IAAI,EAAE,mBAAmB;QAClE,MAAM,IAAIC,MACR,CAAC,oBAAoB,EAAEJ,QAAQC,OAAO,CAAC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C,GAAGhD,gBAAgB,QAAQ,CAAC,CAAC,EAAE;YAC9B6B,UAAU;YACVe,YAAY;YACZ,uEAAuE;YACvE,wEAAwE;YACxE,aAAa;YACbX,WAAW;gBAAC,GAAGjC,gBAAgB,IAAI,CAAC;aAAC;YACrCV,SAAS;gBACPwC,UAAU;oBACR,CAAC,6DAA6D,EAAEU,aAAa,IAAI,CAAC;iBACnF;gBACDK,KAAK;YACP;QACF;QACA,CAAC,GAAG7C,gBAAgB,cAAc,CAAC,CAAC,EAAE;YACpC6B,UAAU;YACVe,YAAY;YACZtD,SAAS;gBACPwC,UAAU;oBACR,CAAC,6BAA6B,EAAE3B,kBAAkB,SAAS,CAAC;iBAC7D;gBACD0C,KAAK;YACP;QACF;IACF;IAEA,8DAA8D;IAC9DrE,sBAAsBmE,YAAY,GAAG3C,gBAAgB,IAAI,CAAC;IAE1DtC,2BAA2B2B,MAAME,QAAQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBmC,SAAS7C,eAAe8D;IAC1B;IAEAlE,8BACEY,MACAE,QAAQK,IAAI,EACZV,8BACAe,sCACAD,iBACA;QACEiD,MAAMT;QACNU,IAAInD;QACJQ;IACF;IAGF,MAAMnC,gCAAgCiB,MAAM;QAACH;KAA6B;IAE1E,MAAMvB,wBAAwB0B,MAAMzB;IAEpC,MAAMI,qBAAqBqB;IAC3B,OAAO,IACLlB,oBAAoBkB,MAAMC,QAAQ6D,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAehE,qBAAqB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport { addMcpServerInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { 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 { isEsmWorkspace } 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 { TsMcpServerGeneratorSchema } from './schema';\n\nexport const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsMcpServerGenerator = async (\n tree: Tree,\n options: TsMcpServerGeneratorSchema,\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())}-mcp-server`;\n const name = kebabCase(options.name || defaultName);\n const mcpServerNameClassName = toClassName(name);\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n mcpTargetPrefix,\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\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 const projectPackageJsonPath = joinPathFragments(\n project.root,\n 'package.json',\n );\n\n // Generate esm if the module system is esm, otherwise commonjs. Projects\n // don't typically have their own package.json (dependencies are declared in\n // the workspace root), so fall back to the workspace format when absent.\n const esm = tree.exists(projectPackageJsonPath)\n ? readJson(tree, projectPackageJsonPath).type === 'module'\n : isEsmWorkspace(tree);\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n targetSourceDir,\n {\n name,\n esm,\n distDir,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add dependencies\n const deps = withVersions([\n '@modelcontextprotocol/sdk',\n 'zod',\n 'express',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ]);\n const devDeps = withVersions([\n 'tsx',\n '@types/express',\n '@modelcontextprotocol/inspector',\n ]);\n\n // Add hosting based on infra\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}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n });\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-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 // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n } else {\n // No Dockerfile needed for non-hosted MCP\n tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));\n }\n\n addDependenciesToPackageJson(tree, deps, devDeps);\n // Add to the project's package.json too if it has one (e.g. nx plugins),\n // otherwise dependencies live in the workspace root only.\n if (tree.exists(projectPackageJsonPath)) {\n addDependenciesToPackageJson(tree, deps, devDeps, projectPackageJsonPath);\n }\n\n // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range\n // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so\n // without a resolution it installs a separate zod under the SDK's own node_modules.\n // The two zod copies have structurally incompatible types, which breaks type\n // inference for registerTool inputSchema. Scope the resolution to the SDK so\n // other consumers (e.g. @tanstack/router-generator pinning zod@3) are unaffected.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n };\n return packageJson;\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: TS_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/stdio.ts`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- tsx --watch ${relativeSourceDir}/stdio.ts`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(mcpTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_MCP_SERVER_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n mcpTargetPrefix,\n {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["addDependenciesToPackageJson","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addMcpServerInfra","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","TS_VERSIONS","withVersions","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","overwriteStrategy","KeepExisting","deps","devDeps","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","iac","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC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AAU;oBACR,CAAC,6DAA6D,EAAEU,aAAa,IAAI,CAAC;iBACnF;gBACDK,KAAK;YACP;QACF;QACA,CAAC,GAAG7C,gBAAgB,cAAc,CAAC,CAAC,EAAE;YACpC6B,UAAU;YACVe,YAAY;YACZtD,SAAS;gBACPwC,UAAU;oBACR,CAAC,6BAA6B,EAAE3B,kBAAkB,SAAS,CAAC;iBAC7D;gBACD0C,KAAK;YACP;QACF;IACF;IAEA,8DAA8D;IAC9DrE,sBAAsBmE,YAAY,GAAG3C,gBAAgB,IAAI,CAAC;IAE1DvC,2BAA2B4B,MAAME,QAAQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBmC,SAAS7C,eAAe8D;IAC1B;IAEAlE,8BACEY,MACAE,QAAQK,IAAI,EACZV,8BACAe,sCACAD,iBACA;QACEiD,MAAMT;QACNU,IAAInD;QACJQ;IACF;IAGF,MAAMpC,gCAAgCkB,MAAM;QAACH;KAA6B;IAE1E,MAAMxB,wBAAwB2B,MAAM1B;IAEpC,MAAMI,qBAAqBsB;IAC3B,OAAO,IACLnB,oBAAoBmB,MAAMC,QAAQ6D,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAehE,qBAAqB"}
@@ -1,9 +1,9 @@
1
1
  import { type GeneratorCallback, type Tree, generateFiles, joinPathFragments } from "@nx/devkit";
2
- import type { <%- namePascalCase %>GeneratorSchema } from './schema.js';
2
+ import type { <%- namePascalCase %>GeneratorSchema } from './schema<% if (esm) { %>.js<% } %>';
3
3
 
4
4
  export const <%- nameCamelCase %>Generator = async (tree: Tree, options: <%- namePascalCase %>GeneratorSchema): Promise<GeneratorCallback | void> => {
5
5
  // TODO: implement your generator here, for example:
6
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), 'target/dir', options);
6
+ generateFiles(tree, joinPathFragments(<% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>, 'files'), 'target/dir', options);
7
7
  };
8
8
 
9
9
  export default <%- nameCamelCase %>Generator;
@@ -1,12 +1,12 @@
1
1
  import { type GeneratorCallback, type Tree } from "@nx/devkit";
2
- import type { <%- namePascalCase %>GeneratorSchema } from './schema.js';
2
+ import type { <%- namePascalCase %>GeneratorSchema } from './schema<% if (esm) { %>.js<% } %>';
3
3
  import { type NxGeneratorInfo, getGeneratorInfo } from '<%- pathToProjectSourceRoot %>utils/nx';
4
4
  import { addGeneratorMetricsIfApplicable } from '<%- pathToProjectSourceRoot %>utils/metrics';
5
5
  import { formatFilesInSubtree } from '<%- pathToProjectSourceRoot %>utils/format';
6
6
  import { installDependencies } from '<%- pathToProjectSourceRoot %>utils/install';
7
7
 
8
8
  export const <%- nameUpperSnakeCase %>_GENERATOR_INFO: NxGeneratorInfo =
9
- getGeneratorInfo(import.meta.filename);
9
+ getGeneratorInfo(<% if (esm) { %>import.meta.filename<% } else { %>__filename<% } %>);
10
10
 
11
11
  export const <%- nameCamelCase %>Generator = async (tree: Tree, options: <%- namePascalCase %>GeneratorSchema): Promise<GeneratorCallback> => {
12
12
 
@@ -10,6 +10,7 @@ import { addStarExport, applyGritQL } from "../../utils/ast.js";
10
10
  import { formatFilesInSubtree } from "../../utils/format.js";
11
11
  import { installDependencies } from "../../utils/install.js";
12
12
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
13
+ import { esmVars } from "../../utils/module-format.js";
13
14
  import { kebabCase, pascalCase, snakeCase } from "../../utils/names.js";
14
15
  import { addComponentGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
15
16
  import { sortObjectKeys } from "../../utils/object.js";
@@ -38,7 +39,8 @@ export const tsNxGeneratorGenerator = async (tree, options)=>{
38
39
  isNxPluginForAws,
39
40
  pathToProjectSourceRoot: getRelativePathToRootByDirectory(generatorSubDir),
40
41
  generatorDir,
41
- generatorSubDir
42
+ generatorSubDir,
43
+ ...esmVars(tree)
42
44
  };
43
45
  // Add the common files, preserving any the user has already implemented
44
46
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'common'), generatorDir, {
@@ -77,7 +79,8 @@ export const tsNxGeneratorGenerator = async (tree, options)=>{
77
79
  });
78
80
  const indexPath = joinPathFragments(sourceRoot, 'index.ts');
79
81
  if (tree.exists(indexPath)) {
80
- // NodeNext requires explicit extensions; the local plugin is ESM.
82
+ // ESM projects require the explicit `.js` extension; `addStarExport`
83
+ // strips it for CommonJS workspaces.
81
84
  await addStarExport(tree, indexPath, `./${generatorSubDir}/generator.js`);
82
85
  }
83
86
  addComponentGeneratorMetadata(tree, plugin.name, NX_GENERATOR_GENERATOR_INFO, joinPathFragments(srcDir, generatorSubDir), name);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-generator/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n writeJson,\n} from '@nx/devkit';\nimport camelCase from 'lodash.camelcase';\nimport PackageJson from '../../../package.json' with { type: 'json' };\nimport { addStarExport, applyGritQL } from '../../utils/ast';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, pascalCase, snakeCase } from '../../utils/names';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths';\nimport { configureTsProjectAsNxPlugin } from '../nx-plugin/utils';\nimport type { TsNxGeneratorGeneratorSchema } from './schema';\n\nexport const NX_GENERATOR_GENERATOR_INFO = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsNxGeneratorGenerator = async (\n tree: Tree,\n options: TsNxGeneratorGeneratorSchema,\n): Promise<GeneratorCallback | void> => {\n const { name, directory, project: pluginProject, description } = options;\n\n const plugin = readProjectConfigurationUnqualified(tree, pluginProject);\n const sourceRoot = plugin.sourceRoot ?? joinPathFragments(plugin.root, 'src');\n const sourceRootParts = sourceRoot.split('/');\n const srcDir = sourceRootParts[sourceRootParts.length - 1];\n const generatorSubDir = directory ?? kebabCase(name);\n const generatorDir = joinPathFragments(sourceRoot, generatorSubDir);\n\n const rootPackageJson = tree.exists('package.json')\n ? readJson(tree, 'package.json')\n : undefined;\n const isNxPluginForAws = rootPackageJson?.name === '@aws/nx-plugin-source';\n\n // Configure the targeted project as an Nx Plugin\n configureTsProjectAsNxPlugin(tree, pluginProject);\n\n const enhancedOptions = {\n name,\n description,\n namePascalCase: pascalCase(name),\n nameCamelCase: camelCase(name),\n nameKebabCase: kebabCase(name),\n nameUpperSnakeCase: snakeCase(name).toUpperCase(),\n isNxPluginForAws,\n pathToProjectSourceRoot: getRelativePathToRootByDirectory(generatorSubDir),\n generatorDir,\n generatorSubDir,\n };\n\n // Add the common files, preserving any the user has already implemented\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n generatorDir,\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add the files specific to this repo vs a local generator in another project\n if (isNxPluginForAws) {\n // Generators should be in the @aws/nx-plugin project\n if (pluginProject !== PackageJson.name) {\n throw new Error(\n `Generators should be added to the ${PackageJson.name} project.`,\n );\n }\n\n // Add the generator\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'nx-plugin-for-aws',\n 'generator',\n ),\n generatorDir,\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate guide page in docs\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'nx-plugin-for-aws',\n 'docs',\n ),\n joinPathFragments('docs', 'src', 'content', 'docs', 'en', 'guides'),\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Update the docs config to add the page entry to the Generator guides sidebar section\n await applyGritQL(\n tree,\n joinPathFragments('docs', 'astro.config.mjs'),\n `\\`items: [$items]\\` where { $items <: within \\`sidebar: [$_]\\`, $items <: contains \\`'ts#project'\\`, $items <: not contains \\`'/guides/${enhancedOptions.nameKebabCase}'\\`, $items += \\`, { label: '${name}', link: '/guides/${enhancedOptions.nameKebabCase}' }\\` }`,\n );\n\n // Expose the generator from the SDK for known prefixes (ts# / py#)\n addSdkExport(tree, plugin.root, name, generatorSubDir, enhancedOptions);\n } else {\n // Local generator in a project other than nx-plugin-for-aws\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'local'),\n generatorDir,\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const indexPath = joinPathFragments(sourceRoot, 'index.ts');\n if (tree.exists(indexPath)) {\n // NodeNext requires explicit extensions; the local plugin is ESM.\n await addStarExport(tree, indexPath, `./${generatorSubDir}/generator.js`);\n }\n\n addComponentGeneratorMetadata(\n tree,\n plugin.name,\n NX_GENERATOR_GENERATOR_INFO,\n joinPathFragments(srcDir, generatorSubDir),\n name,\n );\n }\n\n const factoryBasePath = `./${srcDir}/${generatorSubDir}`;\n\n // Update generators.json\n const generatorsJsonPath = joinPathFragments(plugin.root, 'generators.json');\n const generatorsJson = tree.exists(generatorsJsonPath)\n ? readJson(tree, generatorsJsonPath)\n : { generators: {} };\n // Metrics are only tracked within the @aws/nx-plugin repo. Reuse the existing\n // metric for a same-name re-run, otherwise allocate a new one.\n let metric: string | undefined;\n if (isNxPluginForAws) {\n const existingMetrics = Object.values(generatorsJson?.generators ?? {})\n .map((g: any) => g.metric)\n .filter((m): m is string => typeof m === 'string');\n metric =\n generatorsJson?.generators?.[name]?.metric ??\n (existingMetrics.length > 0 ? incrementMetric(existingMetrics) : 'g1');\n }\n writeJson(tree, generatorsJsonPath, {\n ...generatorsJson,\n generators: sortObjectKeys({\n ...generatorsJson?.generators,\n [name]: {\n factory: `${factoryBasePath}/generator`,\n schema: `${factoryBasePath}/schema.json`,\n description:\n description ?? 'TODO: Add short description of the generator',\n ...(isNxPluginForAws ? { metric } : {}),\n },\n }),\n });\n\n await addGeneratorMetricsIfApplicable(tree, [NX_GENERATOR_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nconst incrementMetric = (metrics: string[]): string => {\n const maxMetric = Math.max(...metrics.map((m) => Number(m.slice(1))));\n return `g${maxMetric + 1}`;\n};\n\n// Maps a generator name prefix to the SDK entry point that should re-export it\nconst SDK_EXPORT_PREFIXES: Record<string, string> = {\n 'ts#': 'ts',\n 'py#': 'py',\n};\n\n// Re-exports a generated generator from the matching SDK entry point so it is\n// available programmatically as part of @aws/nx-plugin's SDK\nconst addSdkExport = (\n tree: Tree,\n pluginRoot: string,\n name: string,\n generatorSubDir: string,\n options: { nameCamelCase: string; namePascalCase: string },\n): void => {\n const prefix = Object.keys(SDK_EXPORT_PREFIXES).find((p) =>\n name.startsWith(p),\n );\n if (!prefix) {\n return;\n }\n\n const sdkPath = joinPathFragments(\n pluginRoot,\n 'src',\n 'sdk',\n `${SDK_EXPORT_PREFIXES[prefix]}.ts`,\n );\n const generatorExport = `${options.nameCamelCase}Generator`;\n const schemaExport = `${options.namePascalCase}GeneratorSchema`;\n const moduleBase = `../${generatorSubDir}`;\n\n const contents = tree.exists(sdkPath) ? tree.read(sdkPath).toString() : '';\n // Idempotent: skip if this generator is already exported\n if (contents.includes(`${moduleBase}/generator`)) {\n return;\n }\n\n const block = `// ${options.namePascalCase} Generator\\nexport { ${generatorExport} } from '${moduleBase}/generator';\\nexport type { ${schemaExport} } from '${moduleBase}/schema';\\n`;\n\n const prefixContents = contents.trim()\n ? `${contents.replace(/\\s*$/, '')}\\n\\n`\n : '';\n tree.write(sdkPath, `${prefixContents}${block}`);\n};\n\nexport default tsNxGeneratorGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readJson","writeJson","camelCase","PackageJson","type","addStarExport","applyGritQL","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","pascalCase","snakeCase","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getRelativePathToRootByDirectory","configureTsProjectAsNxPlugin","NX_GENERATOR_GENERATOR_INFO","filename","tsNxGeneratorGenerator","tree","options","name","directory","project","pluginProject","description","plugin","sourceRoot","root","sourceRootParts","split","srcDir","length","generatorSubDir","generatorDir","rootPackageJson","exists","undefined","isNxPluginForAws","enhancedOptions","namePascalCase","nameCamelCase","nameKebabCase","nameUpperSnakeCase","toUpperCase","pathToProjectSourceRoot","dirname","overwriteStrategy","KeepExisting","Error","addSdkExport","indexPath","factoryBasePath","generatorsJsonPath","generatorsJson","generators","metric","existingMetrics","Object","values","map","g","filter","m","incrementMetric","factory","schema","preferInstallDependencies","languages","metrics","maxMetric","Math","max","Number","slice","SDK_EXPORT_PREFIXES","pluginRoot","prefix","keys","find","p","startsWith","sdkPath","generatorExport","schemaExport","moduleBase","contents","read","toString","includes","block","prefixContents","trim","replace","write"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,SAAS,QACJ,aAAa;AACpB,OAAOC,eAAe,mBAAmB;AACzC,OAAOC,iBAAiB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACtE,SAASC,aAAa,EAAEC,WAAW,QAAQ,qBAAkB;AAC7D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,SAAS,EAAEC,UAAU,EAAEC,SAAS,QAAQ,uBAAoB;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,sBAA8C;IAClD,OAAO;IACP,OAAO;AACT;AAEA,8EAA8E;AAC9E,6DAA6D;AAC7D,MAAMzB,eAAe,CACnB/B,MACAyD,YACAvD,MACAY,iBACAb;IAEA,MAAMyD,SAASnB,OAAOoB,IAAI,CAACH,qBAAqBI,IAAI,CAAC,CAACC,IACpD3D,KAAK4D,UAAU,CAACD;IAElB,IAAI,CAACH,QAAQ;QACX;IACF;IAEA,MAAMK,UAAUvF,kBACdiF,YACA,OACA,OACA,GAAGD,mBAAmB,CAACE,OAAO,CAAC,GAAG,CAAC;IAErC,MAAMM,kBAAkB,GAAG/D,QAAQqB,aAAa,CAAC,SAAS,CAAC;IAC3D,MAAM2C,eAAe,GAAGhE,QAAQoB,cAAc,CAAC,eAAe,CAAC;IAC/D,MAAM6C,aAAa,CAAC,GAAG,EAAEpD,iBAAiB;IAE1C,MAAMqD,WAAWnE,KAAKiB,MAAM,CAAC8C,WAAW/D,KAAKoE,IAAI,CAACL,SAASM,QAAQ,KAAK;IACxE,yDAAyD;IACzD,IAAIF,SAASG,QAAQ,CAAC,GAAGJ,WAAW,UAAU,CAAC,GAAG;QAChD;IACF;IAEA,MAAMK,QAAQ,CAAC,GAAG,EAAEtE,QAAQoB,cAAc,CAAC,qBAAqB,EAAE2C,gBAAgB,SAAS,EAAEE,WAAW,4BAA4B,EAAED,aAAa,SAAS,EAAEC,WAAW,WAAW,CAAC;IAErL,MAAMM,iBAAiBL,SAASM,IAAI,KAChC,GAAGN,SAASO,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,GACrC;IACJ1E,KAAK2E,KAAK,CAACZ,SAAS,GAAGS,iBAAiBD,OAAO;AACjD;AAEA,eAAexE,uBAAuB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-generator/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n writeJson,\n} from '@nx/devkit';\nimport camelCase from 'lodash.camelcase';\nimport PackageJson from '../../../package.json' with { type: 'json' };\nimport { addStarExport, applyGritQL } 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, pascalCase, snakeCase } from '../../utils/names';\nimport {\n addComponentGeneratorMetadata,\n getGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths';\nimport { configureTsProjectAsNxPlugin } from '../nx-plugin/utils';\nimport type { TsNxGeneratorGeneratorSchema } from './schema';\n\nexport const NX_GENERATOR_GENERATOR_INFO = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsNxGeneratorGenerator = async (\n tree: Tree,\n options: TsNxGeneratorGeneratorSchema,\n): Promise<GeneratorCallback | void> => {\n const { name, directory, project: pluginProject, description } = options;\n\n const plugin = readProjectConfigurationUnqualified(tree, pluginProject);\n const sourceRoot = plugin.sourceRoot ?? joinPathFragments(plugin.root, 'src');\n const sourceRootParts = sourceRoot.split('/');\n const srcDir = sourceRootParts[sourceRootParts.length - 1];\n const generatorSubDir = directory ?? kebabCase(name);\n const generatorDir = joinPathFragments(sourceRoot, generatorSubDir);\n\n const rootPackageJson = tree.exists('package.json')\n ? readJson(tree, 'package.json')\n : undefined;\n const isNxPluginForAws = rootPackageJson?.name === '@aws/nx-plugin-source';\n\n // Configure the targeted project as an Nx Plugin\n configureTsProjectAsNxPlugin(tree, pluginProject);\n\n const enhancedOptions = {\n name,\n description,\n namePascalCase: pascalCase(name),\n nameCamelCase: camelCase(name),\n nameKebabCase: kebabCase(name),\n nameUpperSnakeCase: snakeCase(name).toUpperCase(),\n isNxPluginForAws,\n pathToProjectSourceRoot: getRelativePathToRootByDirectory(generatorSubDir),\n generatorDir,\n generatorSubDir,\n ...esmVars(tree),\n };\n\n // Add the common files, preserving any the user has already implemented\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n generatorDir,\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add the files specific to this repo vs a local generator in another project\n if (isNxPluginForAws) {\n // Generators should be in the @aws/nx-plugin project\n if (pluginProject !== PackageJson.name) {\n throw new Error(\n `Generators should be added to the ${PackageJson.name} project.`,\n );\n }\n\n // Add the generator\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'nx-plugin-for-aws',\n 'generator',\n ),\n generatorDir,\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate guide page in docs\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'nx-plugin-for-aws',\n 'docs',\n ),\n joinPathFragments('docs', 'src', 'content', 'docs', 'en', 'guides'),\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Update the docs config to add the page entry to the Generator guides sidebar section\n await applyGritQL(\n tree,\n joinPathFragments('docs', 'astro.config.mjs'),\n `\\`items: [$items]\\` where { $items <: within \\`sidebar: [$_]\\`, $items <: contains \\`'ts#project'\\`, $items <: not contains \\`'/guides/${enhancedOptions.nameKebabCase}'\\`, $items += \\`, { label: '${name}', link: '/guides/${enhancedOptions.nameKebabCase}' }\\` }`,\n );\n\n // Expose the generator from the SDK for known prefixes (ts# / py#)\n addSdkExport(tree, plugin.root, name, generatorSubDir, enhancedOptions);\n } else {\n // Local generator in a project other than nx-plugin-for-aws\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'local'),\n generatorDir,\n {\n ...enhancedOptions,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const indexPath = joinPathFragments(sourceRoot, 'index.ts');\n if (tree.exists(indexPath)) {\n // ESM projects require the explicit `.js` extension; `addStarExport`\n // strips it for CommonJS workspaces.\n await addStarExport(tree, indexPath, `./${generatorSubDir}/generator.js`);\n }\n\n addComponentGeneratorMetadata(\n tree,\n plugin.name,\n NX_GENERATOR_GENERATOR_INFO,\n joinPathFragments(srcDir, generatorSubDir),\n name,\n );\n }\n\n const factoryBasePath = `./${srcDir}/${generatorSubDir}`;\n\n // Update generators.json\n const generatorsJsonPath = joinPathFragments(plugin.root, 'generators.json');\n const generatorsJson = tree.exists(generatorsJsonPath)\n ? readJson(tree, generatorsJsonPath)\n : { generators: {} };\n // Metrics are only tracked within the @aws/nx-plugin repo. Reuse the existing\n // metric for a same-name re-run, otherwise allocate a new one.\n let metric: string | undefined;\n if (isNxPluginForAws) {\n const existingMetrics = Object.values(generatorsJson?.generators ?? {})\n .map((g: any) => g.metric)\n .filter((m): m is string => typeof m === 'string');\n metric =\n generatorsJson?.generators?.[name]?.metric ??\n (existingMetrics.length > 0 ? incrementMetric(existingMetrics) : 'g1');\n }\n writeJson(tree, generatorsJsonPath, {\n ...generatorsJson,\n generators: sortObjectKeys({\n ...generatorsJson?.generators,\n [name]: {\n factory: `${factoryBasePath}/generator`,\n schema: `${factoryBasePath}/schema.json`,\n description:\n description ?? 'TODO: Add short description of the generator',\n ...(isNxPluginForAws ? { metric } : {}),\n },\n }),\n });\n\n await addGeneratorMetricsIfApplicable(tree, [NX_GENERATOR_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nconst incrementMetric = (metrics: string[]): string => {\n const maxMetric = Math.max(...metrics.map((m) => Number(m.slice(1))));\n return `g${maxMetric + 1}`;\n};\n\n// Maps a generator name prefix to the SDK entry point that should re-export it\nconst SDK_EXPORT_PREFIXES: Record<string, string> = {\n 'ts#': 'ts',\n 'py#': 'py',\n};\n\n// Re-exports a generated generator from the matching SDK entry point so it is\n// available programmatically as part of @aws/nx-plugin's SDK\nconst addSdkExport = (\n tree: Tree,\n pluginRoot: string,\n name: string,\n generatorSubDir: string,\n options: { nameCamelCase: string; namePascalCase: string },\n): void => {\n const prefix = Object.keys(SDK_EXPORT_PREFIXES).find((p) =>\n name.startsWith(p),\n );\n if (!prefix) {\n return;\n }\n\n const sdkPath = joinPathFragments(\n pluginRoot,\n 'src',\n 'sdk',\n `${SDK_EXPORT_PREFIXES[prefix]}.ts`,\n );\n const generatorExport = `${options.nameCamelCase}Generator`;\n const schemaExport = `${options.namePascalCase}GeneratorSchema`;\n const moduleBase = `../${generatorSubDir}`;\n\n const contents = tree.exists(sdkPath) ? tree.read(sdkPath).toString() : '';\n // Idempotent: skip if this generator is already exported\n if (contents.includes(`${moduleBase}/generator`)) {\n return;\n }\n\n const block = `// ${options.namePascalCase} Generator\\nexport { ${generatorExport} } from '${moduleBase}/generator';\\nexport type { ${schemaExport} } from '${moduleBase}/schema';\\n`;\n\n const prefixContents = contents.trim()\n ? `${contents.replace(/\\s*$/, '')}\\n\\n`\n : '';\n tree.write(sdkPath, `${prefixContents}${block}`);\n};\n\nexport default tsNxGeneratorGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readJson","writeJson","camelCase","PackageJson","type","addStarExport","applyGritQL","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","pascalCase","snakeCase","addComponentGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getRelativePathToRootByDirectory","configureTsProjectAsNxPlugin","NX_GENERATOR_GENERATOR_INFO","filename","tsNxGeneratorGenerator","tree","options","name","directory","project","pluginProject","description","plugin","sourceRoot","root","sourceRootParts","split","srcDir","length","generatorSubDir","generatorDir","rootPackageJson","exists","undefined","isNxPluginForAws","enhancedOptions","namePascalCase","nameCamelCase","nameKebabCase","nameUpperSnakeCase","toUpperCase","pathToProjectSourceRoot","dirname","overwriteStrategy","KeepExisting","Error","addSdkExport","indexPath","factoryBasePath","generatorsJsonPath","generatorsJson","generators","metric","existingMetrics","Object","values","map","g","filter","m","incrementMetric","factory","schema","preferInstallDependencies","languages","metrics","maxMetric","Math","max","Number","slice","SDK_EXPORT_PREFIXES","pluginRoot","prefix","keys","find","p","startsWith","sdkPath","generatorExport","schemaExport","moduleBase","contents","read","toString","includes","block","prefixContents","trim","replace","write"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,SAAS,QACJ,aAAa;AACpB,OAAOC,eAAe,mBAAmB;AACzC,OAAOC,iBAAiB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACtE,SAASC,aAAa,EAAEC,WAAW,QAAQ,qBAAkB;AAC7D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,SAAS,EAAEC,UAAU,EAAEC,SAAS,QAAQ,uBAAoB;AACrE,SACEC,6BAA6B,EAC7BC,gBAAgB,EAChBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,SAASC,gCAAgC,QAAQ,uBAAoB;AACrE,SAASC,4BAA4B,QAAQ,wBAAqB;AAGlE,OAAO,MAAMC,8BAA8BL,iBACzC,YAAYM,QAAQ,EACpB;AAEF,OAAO,MAAMC,yBAAyB,OACpCC,MACAC;IAEA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,SAASC,aAAa,EAAEC,WAAW,EAAE,GAAGL;IAEjE,MAAMM,SAASd,oCAAoCO,MAAMK;IACzD,MAAMG,aAAaD,OAAOC,UAAU,IAAIjC,kBAAkBgC,OAAOE,IAAI,EAAE;IACvE,MAAMC,kBAAkBF,WAAWG,KAAK,CAAC;IACzC,MAAMC,SAASF,eAAe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AAa,CAAC,GAAG,EAAEpD,iBAAiB;IAE1C,MAAMqD,WAAWnE,KAAKiB,MAAM,CAAC8C,WAAW/D,KAAKoE,IAAI,CAACL,SAASM,QAAQ,KAAK;IACxE,yDAAyD;IACzD,IAAIF,SAASG,QAAQ,CAAC,GAAGJ,WAAW,UAAU,CAAC,GAAG;QAChD;IACF;IAEA,MAAMK,QAAQ,CAAC,GAAG,EAAEtE,QAAQoB,cAAc,CAAC,qBAAqB,EAAE2C,gBAAgB,SAAS,EAAEE,WAAW,4BAA4B,EAAED,aAAa,SAAS,EAAEC,WAAW,WAAW,CAAC;IAErL,MAAMM,iBAAiBL,SAASM,IAAI,KAChC,GAAGN,SAASO,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,GACrC;IACJ1E,KAAK2E,KAAK,CAACZ,SAAS,GAAGS,iBAAiBD,OAAO;AACjD;AAEA,eAAexE,uBAAuB"}
@@ -1,9 +1,9 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { registerCreateWorkspaceCommandTool } from './tools/create-workspace-command.js';
3
- import { registerGeneralGuidanceTool } from './tools/general-guidance.js';
4
- import { registerListGeneratorsTool } from './tools/list-generators.js';
5
- import { registerGeneratorGuideTool } from './tools/generator-guide.js';
6
- import { getPackageName } from './utils.js';
2
+ import { registerCreateWorkspaceCommandTool } from './tools/create-workspace-command<% if (esm) { %>.js<% } %>';
3
+ import { registerGeneralGuidanceTool } from './tools/general-guidance<% if (esm) { %>.js<% } %>';
4
+ import { registerListGeneratorsTool } from './tools/list-generators<% if (esm) { %>.js<% } %>';
5
+ import { registerGeneratorGuideTool } from './tools/generator-guide<% if (esm) { %>.js<% } %>';
6
+ import { getPackageName } from './utils<% if (esm) { %>.js<% } %>';
7
7
 
8
8
  /**
9
9
  * Create the MCP Server
@@ -1,7 +1,7 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
- import { PackageManagerSchema } from '../schema.js';
4
- import { buildCreateCommand, buildInstallCommand, getPackageName } from '../utils.js';
3
+ import { PackageManagerSchema } from '../schema<% if (esm) { %>.js<% } %>';
4
+ import { buildCreateCommand, buildInstallCommand, getPackageName } from '../utils<% if (esm) { %>.js<% } %>';
5
5
 
6
6
  /**
7
7
  * Registers a tool which tells a model how to create an Nx workspace
@@ -16,7 +16,7 @@ export const registerGeneralGuidanceTool = (server: McpServer) => {
16
16
  {
17
17
  type: 'text' as const,
18
18
  text: fs.readFileSync(
19
- path.resolve(import.meta.dirname, '../resources/GENERAL_GUIDANCE.md'),
19
+ path.resolve(<% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>, '../resources/GENERAL_GUIDANCE.md'),
20
20
  'utf-8',
21
21
  ),
22
22
  },
@@ -1,7 +1,7 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
- import { renderGeneratorInfo, listGenerators } from '../utils.js';
4
- import { PackageManagerSchema } from '../schema.js';
3
+ import { renderGeneratorInfo, listGenerators } from '../utils<% if (esm) { %>.js<% } %>';
4
+ import { PackageManagerSchema } from '../schema<% if (esm) { %>.js<% } %>';
5
5
  import * as fs from 'fs';
6
6
  import * as path from 'path';
7
7
 
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import { PackageManagerSchema } from '../schema.js';
3
- import { renderGeneratorInfo, listGenerators } from '../utils.js';
2
+ import { PackageManagerSchema } from '../schema<% if (esm) { %>.js<% } %>';
3
+ import { renderGeneratorInfo, listGenerators } from '../utils<% if (esm) { %>.js<% } %>';
4
4
 
5
5
  /**
6
6
  * Registers a tool which lists details about the available generators
@@ -9,20 +9,20 @@ export interface NxGeneratorInfo {
9
9
 
10
10
  export const getPackageName = (): string =>
11
11
  JSON.parse(
12
- fs.readFileSync(path.resolve(import.meta.dirname, '../../package.json'), 'utf-8'),
12
+ fs.readFileSync(path.resolve(<% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>, '../../package.json'), 'utf-8'),
13
13
  ).name;
14
14
 
15
15
  export const listGenerators = (): NxGeneratorInfo[] =>
16
16
  Object.entries(
17
17
  JSON.parse(
18
18
  fs.readFileSync(
19
- path.resolve(import.meta.dirname, '../../generators.json'),
19
+ path.resolve(<% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>, '../../generators.json'),
20
20
  'utf-8',
21
21
  ),
22
22
  ).generators,
23
23
  ).map(([id, info]: any) => ({
24
24
  id,
25
- resolvedPath: path.resolve(import.meta.dirname, '..', '..', info.factory, '..'),
25
+ resolvedPath: path.resolve(<% if (esm) { %>import.meta.dirname<% } else { %>__dirname<% } %>, '..', '..', info.factory, '..'),
26
26
  description: info.description,
27
27
  }));
28
28
 
@@ -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 { esmVars } from "../../utils/module-format.js";
8
9
  import { addDependencyToTargetIfNotPresent, addGeneratorMetadata, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
9
10
  import { sortObjectKeys } from "../../utils/object.js";
10
11
  import tsProjectGenerator, { getTsLibDetails } from "../lib/generator.js";
@@ -85,7 +86,8 @@ export const tsNxPluginGenerator = async (tree, options)=>{
85
86
  tree.delete(joinPathFragments(mcpPath, 'resources', 'sample-guidance.ts'));
86
87
  // Add generator MCP server
87
88
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'mcp-server'), mcpPath, {
88
- name: fullyQualifiedName
89
+ name: fullyQualifiedName,
90
+ ...esmVars(tree)
89
91
  }, {
90
92
  overwriteStrategy: OverwriteStrategy.KeepExisting
91
93
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-plugin/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator';\nimport tsMcpServerGenerator from '../mcp-server/generator';\nimport type { TsNxPluginGeneratorSchema } from './schema';\nimport { configureTsProjectAsNxPlugin } from './utils';\n\nexport const TS_NX_PLUGIN_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsNxPluginGenerator = async (\n tree: Tree,\n options: TsNxPluginGeneratorSchema,\n): Promise<GeneratorCallback> => {\n // Generate a TypeScript project as the base\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n await tsProjectGenerator(tree, {\n ...options,\n preferInstallDependencies: false,\n });\n\n // Configure the typescript project as an Nx Plugin\n configureTsProjectAsNxPlugin(tree, fullyQualifiedName);\n\n // Add a \"package\" target which creates a package which can be published to NPM\n const project = readProjectConfigurationUnqualified(tree, fullyQualifiedName);\n project.targets = {\n ...project.targets,\n package: {\n executor: '@nx/js:tsc',\n outputs: ['{options.outputPath}'],\n options: {\n outputPath: `dist/{projectRoot}/package`,\n main: `{projectRoot}/src/index.ts`,\n tsConfig: `{projectRoot}/tsconfig.lib.json`,\n assets: [\n `{projectRoot}/*.md`,\n `{projectRoot}/LICENSE*`,\n `{projectRoot}/NOTICE`,\n {\n input: './{projectRoot}/src',\n glob: '**/!(*.ts)',\n output: './src',\n },\n {\n input: './{projectRoot}/src',\n glob: '**/*.d.ts',\n output: './src',\n },\n {\n input: './{projectRoot}',\n glob: 'generators.json',\n output: '.',\n },\n {\n input: './{projectRoot}',\n glob: 'executors.json',\n output: '.',\n },\n ],\n },\n },\n build: {\n ...project.targets?.build,\n },\n };\n // Append the package dependency without moving an existing entry, so re-runs\n // do not reorder the build dependencies.\n addDependencyToTargetIfNotPresent(project, 'build', 'package');\n // Sort targets so their order is stable regardless of insertion order.\n project.targets = sortObjectKeys(project.targets);\n updateProjectConfiguration(tree, fullyQualifiedName, project);\n\n // Add an MCP Server\n await tsMcpServerGenerator(tree, {\n project: fullyQualifiedName,\n infra: 'none',\n iac: 'cdk', // not used\n preferInstallDependencies: false,\n });\n\n const mcpPath = joinPathFragments(project.sourceRoot, 'mcp-server');\n const mcpServerPath = joinPathFragments(mcpPath, 'server.ts');\n\n // Remove the sample server and tools\n tree.delete(mcpServerPath);\n tree.delete(joinPathFragments(mcpPath, 'tools', 'add.ts'));\n tree.delete(joinPathFragments(mcpPath, 'resources', 'sample-guidance.ts'));\n\n // Add generator MCP server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'mcp-server'),\n mcpPath,\n {\n name: fullyQualifiedName,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addGeneratorMetadata(tree, project.name, TS_NX_PLUGIN_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [TS_NX_PLUGIN_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsNxPluginGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","tsProjectGenerator","getTsLibDetails","tsMcpServerGenerator","configureTsProjectAsNxPlugin","TS_NX_PLUGIN_GENERATOR_INFO","filename","tsNxPluginGenerator","tree","options","fullyQualifiedName","dir","preferInstallDependencies","project","targets","package","executor","outputs","outputPath","main","tsConfig","assets","input","glob","output","build","infra","iac","mcpPath","sourceRoot","mcpServerPath","delete","dirname","name","overwriteStrategy","KeepExisting","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,OAAOC,sBAAsBC,eAAe,QAAQ,sBAAmB;AACvE,OAAOC,0BAA0B,6BAA0B;AAE3D,SAASC,4BAA4B,QAAQ,aAAU;AAEvD,OAAO,MAAMC,8BAA+CP,iBAC1D,YAAYQ,QAAQ,EACpB;AAEF,OAAO,MAAMC,sBAAsB,OACjCC,MACAC;IAEA,4CAA4C;IAC5C,MAAM,EAAEC,kBAAkB,EAAEC,GAAG,EAAE,GAAGT,gBAAgBM,MAAMC;IAC1D,MAAMR,mBAAmBO,MAAM;QAC7B,GAAGC,OAAO;QACVG,2BAA2B;IAC7B;IAEA,mDAAmD;IACnDR,6BAA6BI,MAAME;IAEnC,+EAA+E;IAC/E,MAAMG,UAAUd,oCAAoCS,MAAME;IAC1DG,QAAQC,OAAO,GAAG;QAChB,GAAGD,QAAQC,OAAO;QAClBC,SAAS;YACPC,UAAU;YACVC,SAAS;gBAAC;aAAuB;YACjCR,SAAS;gBACPS,YAAY,CAAC,0BAA0B,CAAC;gBACxCC,MAAM,CAAC,0BAA0B,CAAC;gBAClCC,UAAU,CAAC,+BAA+B,CAAC;gBAC3CC,QAAQ;oBACN,CAAC,kBAAkB,CAAC;oBAC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,eAAe7B,oBAAoB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-plugin/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator';\nimport tsMcpServerGenerator from '../mcp-server/generator';\nimport type { TsNxPluginGeneratorSchema } from './schema';\nimport { configureTsProjectAsNxPlugin } from './utils';\n\nexport const TS_NX_PLUGIN_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsNxPluginGenerator = async (\n tree: Tree,\n options: TsNxPluginGeneratorSchema,\n): Promise<GeneratorCallback> => {\n // Generate a TypeScript project as the base\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n await tsProjectGenerator(tree, {\n ...options,\n preferInstallDependencies: false,\n });\n\n // Configure the typescript project as an Nx Plugin\n configureTsProjectAsNxPlugin(tree, fullyQualifiedName);\n\n // Add a \"package\" target which creates a package which can be published to NPM\n const project = readProjectConfigurationUnqualified(tree, fullyQualifiedName);\n project.targets = {\n ...project.targets,\n package: {\n executor: '@nx/js:tsc',\n outputs: ['{options.outputPath}'],\n options: {\n outputPath: `dist/{projectRoot}/package`,\n main: `{projectRoot}/src/index.ts`,\n tsConfig: `{projectRoot}/tsconfig.lib.json`,\n assets: [\n `{projectRoot}/*.md`,\n `{projectRoot}/LICENSE*`,\n `{projectRoot}/NOTICE`,\n {\n input: './{projectRoot}/src',\n glob: '**/!(*.ts)',\n output: './src',\n },\n {\n input: './{projectRoot}/src',\n glob: '**/*.d.ts',\n output: './src',\n },\n {\n input: './{projectRoot}',\n glob: 'generators.json',\n output: '.',\n },\n {\n input: './{projectRoot}',\n glob: 'executors.json',\n output: '.',\n },\n ],\n },\n },\n build: {\n ...project.targets?.build,\n },\n };\n // Append the package dependency without moving an existing entry, so re-runs\n // do not reorder the build dependencies.\n addDependencyToTargetIfNotPresent(project, 'build', 'package');\n // Sort targets so their order is stable regardless of insertion order.\n project.targets = sortObjectKeys(project.targets);\n updateProjectConfiguration(tree, fullyQualifiedName, project);\n\n // Add an MCP Server\n await tsMcpServerGenerator(tree, {\n project: fullyQualifiedName,\n infra: 'none',\n iac: 'cdk', // not used\n preferInstallDependencies: false,\n });\n\n const mcpPath = joinPathFragments(project.sourceRoot, 'mcp-server');\n const mcpServerPath = joinPathFragments(mcpPath, 'server.ts');\n\n // Remove the sample server and tools\n tree.delete(mcpServerPath);\n tree.delete(joinPathFragments(mcpPath, 'tools', 'add.ts'));\n tree.delete(joinPathFragments(mcpPath, 'resources', 'sample-guidance.ts'));\n\n // Add generator MCP server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'mcp-server'),\n mcpPath,\n {\n name: fullyQualifiedName,\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n addGeneratorMetadata(tree, project.name, TS_NX_PLUGIN_GENERATOR_INFO);\n\n await addGeneratorMetricsIfApplicable(tree, [TS_NX_PLUGIN_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsNxPluginGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","tsProjectGenerator","getTsLibDetails","tsMcpServerGenerator","configureTsProjectAsNxPlugin","TS_NX_PLUGIN_GENERATOR_INFO","filename","tsNxPluginGenerator","tree","options","fullyQualifiedName","dir","preferInstallDependencies","project","targets","package","executor","outputs","outputPath","main","tsConfig","assets","input","glob","output","build","infra","iac","mcpPath","sourceRoot","mcpServerPath","delete","dirname","name","overwriteStrategy","KeepExisting","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAAQ,wBAAqB;AACpD,OAAOC,sBAAsBC,eAAe,QAAQ,sBAAmB;AACvE,OAAOC,0BAA0B,6BAA0B;AAE3D,SAASC,4BAA4B,QAAQ,aAAU;AAEvD,OAAO,MAAMC,8BAA+CP,iBAC1D,YAAYQ,QAAQ,EACpB;AAEF,OAAO,MAAMC,sBAAsB,OACjCC,MACAC;IAEA,4CAA4C;IAC5C,MAAM,EAAEC,kBAAkB,EAAEC,GAAG,EAAE,GAAGT,gBAAgBM,MAAMC;IAC1D,MAAMR,mBAAmBO,MAAM;QAC7B,GAAGC,OAAO;QACVG,2BAA2B;IAC7B;IAEA,mDAAmD;IACnDR,6BAA6BI,MAAME;IAEnC,+EAA+E;IAC/E,MAAMG,UAAUd,oCAAoCS,MAAME;IAC1DG,QAAQC,OAAO,GAAG;QAChB,GAAGD,QAAQC,OAAO;QAClBC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AY;IAAC;IAGtDtC,qBAAqBW,MAAMK,QAAQoB,IAAI,EAAE5B;IAEzC,MAAMX,gCAAgCc,MAAM;QAACH;KAA4B;IAEzE,MAAMb,qBAAqBgB;IAC3B,OAAO,IACLf,oBAAoBe,MAAMC,QAAQG,yBAAyB,EAAE;YAC3DwB,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe7B,oBAAoB"}
@@ -5,6 +5,7 @@
5
5
  import PackageJson from "../../../package.json" with {
6
6
  type: 'json'
7
7
  };
8
+ import { isEsmWorkspace } from "../../utils/module-format.js";
8
9
  import { readProjectConfigurationUnqualified } from "../../utils/nx.js";
9
10
  import { withVersions } from "../../utils/versions.js";
10
11
  /**
@@ -30,11 +31,13 @@ import { withVersions } from "../../utils/versions.js";
30
31
  name: project.name
31
32
  });
32
33
  }
34
+ const esm = isEsmWorkspace(tree);
33
35
  updateJson(tree, pluginPackageJsonPath, (pkg)=>{
34
- // Mark the plugin as ESM so Nx loads its `.ts` generators as ES modules via
35
- // Node's native type stripping (the workspace root is also `type: module`).
36
- pkg.type ??= 'module';
37
- pkg.main ??= './src/index.js';
36
+ // Match the plugin's module system to the workspace. Nx loads `.ts`
37
+ // generators via Node's native type stripping, as ESM (workspace root is
38
+ // `type: module`) or CommonJS accordingly.
39
+ pkg.type ??= esm ? 'module' : 'commonjs';
40
+ pkg.main ??= esm ? './src/index.js' : './src/index';
38
41
  pkg.generators ??= './generators.json';
39
42
  return pkg;
40
43
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-plugin/utils.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 joinPathFragments,\n readJson,\n type Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport PackageJson from '../../../package.json' with { type: 'json' };\nimport { readProjectConfigurationUnqualified } from '../../utils/nx';\nimport { withVersions } from '../../utils/versions';\n\n/**\n * Configures a TypeScript project as an Nx Plugin\n */\nexport const configureTsProjectAsNxPlugin = (\n tree: Tree,\n projectName: string,\n) => {\n const project = readProjectConfigurationUnqualified(tree, projectName);\n\n const tsConfigPath = joinPathFragments(project.root, 'tsconfig.json');\n if (!tree.exists(tsConfigPath)) {\n throw new Error(\n `Selected plugin project ${projectName} is not a TypeScript project`,\n );\n }\n\n // Create an empty generators.json if one dosn't exist\n const generatorsJsonPath = joinPathFragments(project.root, 'generators.json');\n if (!tree.exists(generatorsJsonPath)) {\n writeJson(tree, generatorsJsonPath, {\n generators: {},\n });\n }\n\n // Create a package.json if one doesn't exist, and configure \"type\", \"main\"\n // and \"generators\"\n const pluginPackageJsonPath = joinPathFragments(project.root, 'package.json');\n if (!tree.exists(pluginPackageJsonPath)) {\n writeJson(tree, pluginPackageJsonPath, {\n name: project.name,\n });\n }\n updateJson(tree, pluginPackageJsonPath, (pkg) => {\n // Mark the plugin as ESM so Nx loads its `.ts` generators as ES modules via\n // Node's native type stripping (the workspace root is also `type: module`).\n pkg.type ??= 'module';\n pkg.main ??= './src/index.js';\n pkg.generators ??= './generators.json';\n return pkg;\n });\n\n const rootPackageJson = tree.exists('package.json')\n ? readJson(tree, 'package.json')\n : undefined;\n const isNxPluginForAws = rootPackageJson?.name === '@aws/nx-plugin-source';\n\n if (!isNxPluginForAws) {\n // Add the required dependencies to the root package.json, and project's package.json\n const deps = {\n ...withVersions(['@nx/devkit']),\n // Include dependency on @aws/nx-plugin\n [PackageJson.name]: `^${PackageJson.version}`,\n };\n // Generated workspaces are `\"type\": \"module\"`, so Nx loads the plugin's\n // `.ts` generators as ESM via Node's native type stripping — no swc/ts-node\n // transpiler is required.\n addDependenciesToPackageJson(tree, {}, deps);\n addDependenciesToPackageJson(tree, deps, {}, pluginPackageJsonPath);\n }\n};\n"],"names":["addDependenciesToPackageJson","joinPathFragments","readJson","updateJson","writeJson","PackageJson","type","readProjectConfigurationUnqualified","withVersions","configureTsProjectAsNxPlugin","tree","projectName","project","tsConfigPath","root","exists","Error","generatorsJsonPath","generators","pluginPackageJsonPath","name","pkg","main","rootPackageJson","undefined","isNxPluginForAws","deps","version"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,SAAS,QACJ,aAAa;AACpB,OAAOC,iBAAiB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACtE,SAASC,mCAAmC,QAAQ,oBAAiB;AACrE,SAASC,YAAY,QAAQ,0BAAuB;AAEpD;;CAEC,GACD,OAAO,MAAMC,+BAA+B,CAC1CC,MACAC;IAEA,MAAMC,UAAUL,oCAAoCG,MAAMC;IAE1D,MAAME,eAAeZ,kBAAkBW,QAAQE,IAAI,EAAE;IACrD,IAAI,CAACJ,KAAKK,MAAM,CAACF,eAAe;QAC9B,MAAM,IAAIG,MACR,CAAC,wBAAwB,EAAEL,YAAY,4BAA4B,CAAC;IAExE;IAEA,sDAAsD;IACtD,MAAMM,qBAAqBhB,kBAAkBW,QAAQE,IAAI,EAAE;IAC3D,IAAI,CAACJ,KAAKK,MAAM,CAACE,qBAAqB;QACpCb,UAAUM,MAAMO,oBAAoB;YAClCC,YAAY,CAAC;QACf;IACF;IAEA,2EAA2E;IAC3E,mBAAmB;IACnB,MAAMC,wBAAwBlB,kBAAkBW,QAAQE,IAAI,EAAE;IAC9D,IAAI,CAACJ,KAAKK,MAAM,CAACI,wBAAwB;QACvCf,UAAUM,MAAMS,uBAAuB;YACrCC,MAAMR,QAAQQ,IAAI;QACpB;IACF;IACAjB,WAAWO,MAAMS,uBAAuB,CAACE;QACvC,4EAA4E;QAC5E,4EAA4E;QAC5EA,IAAIf,IAAI,KAAK;QACbe,IAAIC,IAAI,KAAK;QACbD,IAAIH,UAAU,KAAK;QACnB,OAAOG;IACT;IAEA,MAAME,kBAAkBb,KAAKK,MAAM,CAAC,kBAChCb,SAASQ,MAAM,kBACfc;IACJ,MAAMC,mBAAmBF,iBAAiBH,SAAS;IAEnD,IAAI,CAACK,kBAAkB;QACrB,qFAAqF;QACrF,MAAMC,OAAO;YACX,GAAGlB,aAAa;gBAAC;aAAa,CAAC;YAC/B,uCAAuC;YACvC,CAACH,YAAYe,IAAI,CAAC,EAAE,CAAC,CAAC,EAAEf,YAAYsB,OAAO,EAAE;QAC/C;QACA,wEAAwE;QACxE,4EAA4E;QAC5E,0BAA0B;QAC1B3B,6BAA6BU,MAAM,CAAC,GAAGgB;QACvC1B,6BAA6BU,MAAMgB,MAAM,CAAC,GAAGP;IAC/C;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/nx-plugin/utils.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 joinPathFragments,\n readJson,\n type Tree,\n updateJson,\n writeJson,\n} from '@nx/devkit';\nimport PackageJson from '../../../package.json' with { type: 'json' };\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { readProjectConfigurationUnqualified } from '../../utils/nx';\nimport { withVersions } from '../../utils/versions';\n\n/**\n * Configures a TypeScript project as an Nx Plugin\n */\nexport const configureTsProjectAsNxPlugin = (\n tree: Tree,\n projectName: string,\n) => {\n const project = readProjectConfigurationUnqualified(tree, projectName);\n\n const tsConfigPath = joinPathFragments(project.root, 'tsconfig.json');\n if (!tree.exists(tsConfigPath)) {\n throw new Error(\n `Selected plugin project ${projectName} is not a TypeScript project`,\n );\n }\n\n // Create an empty generators.json if one dosn't exist\n const generatorsJsonPath = joinPathFragments(project.root, 'generators.json');\n if (!tree.exists(generatorsJsonPath)) {\n writeJson(tree, generatorsJsonPath, {\n generators: {},\n });\n }\n\n // Create a package.json if one doesn't exist, and configure \"type\", \"main\"\n // and \"generators\"\n const pluginPackageJsonPath = joinPathFragments(project.root, 'package.json');\n if (!tree.exists(pluginPackageJsonPath)) {\n writeJson(tree, pluginPackageJsonPath, {\n name: project.name,\n });\n }\n const esm = isEsmWorkspace(tree);\n updateJson(tree, pluginPackageJsonPath, (pkg) => {\n // Match the plugin's module system to the workspace. Nx loads `.ts`\n // generators via Node's native type stripping, as ESM (workspace root is\n // `type: module`) or CommonJS accordingly.\n pkg.type ??= esm ? 'module' : 'commonjs';\n pkg.main ??= esm ? './src/index.js' : './src/index';\n pkg.generators ??= './generators.json';\n return pkg;\n });\n\n const rootPackageJson = tree.exists('package.json')\n ? readJson(tree, 'package.json')\n : undefined;\n const isNxPluginForAws = rootPackageJson?.name === '@aws/nx-plugin-source';\n\n if (!isNxPluginForAws) {\n // Add the required dependencies to the root package.json, and project's package.json\n const deps = {\n ...withVersions(['@nx/devkit']),\n // Include dependency on @aws/nx-plugin\n [PackageJson.name]: `^${PackageJson.version}`,\n };\n // Generated workspaces are `\"type\": \"module\"`, so Nx loads the plugin's\n // `.ts` generators as ESM via Node's native type stripping — no swc/ts-node\n // transpiler is required.\n addDependenciesToPackageJson(tree, {}, deps);\n addDependenciesToPackageJson(tree, deps, {}, pluginPackageJsonPath);\n }\n};\n"],"names":["addDependenciesToPackageJson","joinPathFragments","readJson","updateJson","writeJson","PackageJson","type","isEsmWorkspace","readProjectConfigurationUnqualified","withVersions","configureTsProjectAsNxPlugin","tree","projectName","project","tsConfigPath","root","exists","Error","generatorsJsonPath","generators","pluginPackageJsonPath","name","esm","pkg","main","rootPackageJson","undefined","isNxPluginForAws","deps","version"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,SAAS,QACJ,aAAa;AACpB,OAAOC,iBAAiB,6BAA6B;IAAEC,MAAM;AAAO,EAAE;AACtE,SAASC,cAAc,QAAQ,+BAA4B;AAC3D,SAASC,mCAAmC,QAAQ,oBAAiB;AACrE,SAASC,YAAY,QAAQ,0BAAuB;AAEpD;;CAEC,GACD,OAAO,MAAMC,+BAA+B,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vC5B,6BAA6BW,MAAMiB,MAAM,CAAC,GAAGR;IAC/C;AACF,EAAE"}
@@ -792,7 +792,7 @@ terraform {
792
792
  required_providers {
793
793
  aws = {
794
794
  source = "hashicorp/aws"
795
- version = "6.52.0"
795
+ version = "6.54.0"
796
796
  }
797
797
  null = {
798
798
  source = "hashicorp/null"
@@ -1554,7 +1554,7 @@ exports[`ts#rdb generator > should generate terraform modules when iac is Terraf
1554
1554
  }
1555
1555
  aws = {
1556
1556
  source = "hashicorp/aws"
1557
- version = "6.52.0"
1557
+ version = "6.54.0"
1558
1558
  }
1559
1559
  null = {
1560
1560
  source = "hashicorp/null"
@@ -2281,7 +2281,7 @@ terraform {
2281
2281
  required_providers {
2282
2282
  aws = {
2283
2283
  source = "hashicorp/aws"
2284
- version = "6.52.0"
2284
+ version = "6.54.0"
2285
2285
  }
2286
2286
  null = {
2287
2287
  source = "hashicorp/null"
@@ -3043,7 +3043,7 @@ exports[`ts#rdb generator > should generate terraform modules with MySQL engine
3043
3043
  }
3044
3044
  aws = {
3045
3045
  source = "hashicorp/aws"
3046
- version = "6.52.0"
3046
+ version = "6.54.0"
3047
3047
  }
3048
3048
  null = {
3049
3049
  source = "hashicorp/null"
@@ -2,10 +2,10 @@ import type { CloudFormationCustomResourceEvent } from 'aws-lambda';
2
2
  import { randomBytes } from 'node:crypto';
3
3
  <%_ if (engine === 'mysql') { _%>
4
4
  import { createPool, type PoolConnection } from 'mariadb';
5
- import { getDatabaseSecret, withConnectionRetry } from './utils.js';
5
+ import { getDatabaseSecret, withConnectionRetry } from './utils<% if (esm) { %>.js<% } %>';
6
6
  <%_ } else { _%>
7
7
  import { Client, escapeIdentifier } from 'pg';
8
- import { getDatabaseSecret, withConnectionRetry } from './utils.js';
8
+ import { getDatabaseSecret, withConnectionRetry } from './utils<% if (esm) { %>.js<% } %>';
9
9
  <%_ } _%>
10
10
 
11
11
  type OnEventResult = {
@@ -1 +1 @@
1
- export { getPrisma } from './prisma.js';
1
+ export { getPrisma } from './prisma<% if (esm) { %>.js<% } %>';
@@ -1,6 +1,6 @@
1
1
  import { execFile } from 'node:child_process';
2
2
  import { promisify } from 'node:util';
3
- import { getDatabaseSecret, withConnectionRetry } from './utils.js';
3
+ import { getDatabaseSecret, withConnectionRetry } from './utils<% if (esm) { %>.js<% } %>';
4
4
 
5
5
  const buildDatabaseUrl = async (): Promise<string> => {
6
6
  const { host, port, dbname, username, password } = await getDatabaseSecret();
@@ -1,18 +1,21 @@
1
1
  import { <%= prismaAdapterClassName %> } from '<%= prismaAdapterPackage %>';
2
2
  import { Signer } from '@aws-sdk/rds-signer';
3
- import { Prisma, PrismaClient } from '../generated/prisma/client.js';
3
+ import { Prisma, PrismaClient } from '../generated/prisma/client<% if (esm) { %>.js<% } %>';
4
4
  <%_ if (engine === 'postgres') { _%>
5
5
  import { Pool } from 'pg';
6
6
  <%_ } _%>
7
7
  import { readFileSync } from 'fs';
8
- import { join, dirname } from 'path';
8
+ import { join<% if (esm) { %>, dirname<% } %> } from 'path';
9
+ <%_ if (esm) { _%>
9
10
  import { fileURLToPath } from 'url';
10
- import { getDatabaseConfig } from './utils.js';
11
+ <%_ } _%>
12
+ import { getDatabaseConfig } from './utils<% if (esm) { %>.js<% } %>';
11
13
 
12
14
  // Generated: must match runtimeConfigKey in config.json
13
15
  const runtimeConfigKey = '<%= runtimeConfigKey %>';
14
-
16
+ <% if (esm) { %>
15
17
  const __dirname = dirname(fileURLToPath(import.meta.url));
18
+ <%_ } _%>
16
19
  // config.json is only present in local dev (not included in the deployed bundle); guard with LOCAL_DEV check
17
20
  const localDev = () =>
18
21
  JSON.parse(readFileSync(join(__dirname, '../config.json'), 'utf-8')).localDev;
@@ -11,6 +11,7 @@ import { updateGitIgnore } from "../../utils/git.js";
11
11
  import { resolveIac } from "../../utils/iac.js";
12
12
  import { installDependencies } from "../../utils/install.js";
13
13
  import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
14
+ import { esmVars } from "../../utils/module-format.js";
14
15
  import { kebabCase, snakeCase, toClassName } from "../../utils/names.js";
15
16
  import { getNpmScope, toScopeAlias } from "../../utils/npm-scope.js";
16
17
  import { addDependencyToTargetIfNotPresent, addGeneratorMetadata, getGeneratorInfo } from "../../utils/nx.js";
@@ -78,7 +79,8 @@ export const tsRdbGenerator = async (tree, options)=>{
78
79
  localDbPassword,
79
80
  containerEngine,
80
81
  containerName,
81
- dockerImage
82
+ dockerImage,
83
+ ...esmVars(tree)
82
84
  };
83
85
  generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), dir, templateOptions);
84
86
  updateGitIgnore(tree, dir, (patterns)=>[