@aws/nx-plugin 1.0.0-rc.89 → 1.0.0-rc.90
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.
- package/README.md +22 -22
- package/executors.json +5 -0
- package/generators.json +2 -1
- package/migrations.json +47 -2
- package/package.json +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +24 -12
- package/src/infra/app/generator.js +9 -7
- package/src/infra/app/generator.js.map +1 -1
- package/src/mcp-server/generator-info.d.ts +5 -0
- package/src/mcp-server/generator-info.js +6 -2
- package/src/mcp-server/generator-info.js.map +1 -1
- package/src/migrations/latest/add-assemble-target/metadata.json +3 -0
- package/src/migrations/latest/add-assemble-target/migration.d.ts +6 -0
- package/src/migrations/latest/add-assemble-target/migration.js +241 -0
- package/src/migrations/latest/add-assemble-target/migration.js.map +1 -0
- package/src/migrations/latest/declare-cacheable-target-inputs/metadata.json +3 -0
- package/src/migrations/latest/declare-cacheable-target-inputs/migration.d.ts +6 -0
- package/src/migrations/latest/declare-cacheable-target-inputs/migration.js +94 -0
- package/src/migrations/latest/declare-cacheable-target-inputs/migration.js.map +1 -0
- package/src/migrations/latest/dev-target-depends-on-pull-image/metadata.json +3 -0
- package/src/migrations/latest/dev-target-depends-on-pull-image/migration.d.ts +6 -0
- package/src/migrations/latest/dev-target-depends-on-pull-image/migration.js +67 -0
- package/src/migrations/latest/dev-target-depends-on-pull-image/migration.js.map +1 -0
- package/src/migrations/latest/docker-target-cache-soundness/metadata.json +3 -0
- package/src/migrations/latest/docker-target-cache-soundness/migration.d.ts +6 -0
- package/src/migrations/latest/docker-target-cache-soundness/migration.js +95 -0
- package/src/migrations/latest/docker-target-cache-soundness/migration.js.map +1 -0
- package/src/migrations/latest/open-api-codegen-executor/metadata.json +3 -0
- package/src/migrations/latest/open-api-codegen-executor/migration.d.ts +6 -0
- package/src/migrations/latest/open-api-codegen-executor/migration.js +100 -0
- package/src/migrations/latest/open-api-codegen-executor/migration.js.map +1 -0
- package/src/migrations/latest/python-test-input-scoping/metadata.json +3 -0
- package/src/migrations/latest/python-test-input-scoping/migration.d.ts +6 -0
- package/src/migrations/latest/python-test-input-scoping/migration.js +142 -0
- package/src/migrations/latest/python-test-input-scoping/migration.js.map +1 -0
- package/src/migrations/latest/terraform-fmt-check/metadata.json +3 -0
- package/src/migrations/latest/terraform-fmt-check/migration.d.ts +6 -0
- package/src/migrations/latest/terraform-fmt-check/migration.js +165 -0
- package/src/migrations/latest/terraform-fmt-check/migration.js.map +1 -0
- package/src/migrations/latest/terraform-provider-plugin-cache/metadata.json +3 -0
- package/src/migrations/latest/terraform-provider-plugin-cache/migration.d.ts +6 -0
- package/src/migrations/latest/terraform-provider-plugin-cache/migration.js +164 -0
- package/src/migrations/latest/terraform-provider-plugin-cache/migration.js.map +1 -0
- package/src/migrations/latest/vitest-coverage-output-dir/metadata.json +3 -0
- package/src/migrations/latest/vitest-coverage-output-dir/migration.d.ts +6 -0
- package/src/migrations/latest/vitest-coverage-output-dir/migration.js +177 -0
- package/src/migrations/latest/vitest-coverage-output-dir/migration.js.map +1 -0
- package/src/open-api/codegen/executor-schema.d.js +6 -0
- package/src/open-api/codegen/executor-schema.d.js.map +1 -0
- package/src/open-api/codegen/executor-schema.d.ts +18 -0
- package/src/open-api/codegen/executor-schema.json +33 -0
- package/src/open-api/codegen/executor.d.ts +18 -0
- package/src/open-api/codegen/executor.js +56 -0
- package/src/open-api/codegen/executor.js.map +1 -0
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -1
- package/src/py/agent/generator.js +21 -22
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/agent/react-connection/generator.js +9 -0
- package/src/py/agent/react-connection/generator.js.map +1 -1
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +0 -30
- package/src/py/fast-api/react/open-api.js +19 -7
- package/src/py/fast-api/react/open-api.js.map +1 -1
- package/src/py/mcp-server/generator.js +4 -4
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/project/generator.d.ts +9 -0
- package/src/py/project/generator.js +51 -1
- package/src/py/project/generator.js.map +1 -1
- package/src/py/rdb/generator.js +10 -4
- package/src/py/rdb/generator.js.map +1 -1
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +15 -0
- package/src/smithy/project/generator.js +10 -0
- package/src/smithy/project/generator.js.map +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +7 -0
- package/src/terraform/project/files/application/scripts/env.ts.template +11 -0
- package/src/terraform/project/files/application/scripts/init.ts.template +2 -1
- package/src/terraform/project/files/application/src/providers.tf.template +2 -2
- package/src/terraform/project/generator.d.ts +11 -1
- package/src/terraform/project/generator.js +104 -20
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/generator.js +2 -2
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/ts/agent/generator.js +4 -7
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/astro-docs/generator.js +5 -0
- package/src/ts/astro-docs/generator.js.map +1 -1
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +0 -30
- package/src/ts/dynamodb/generator.js +3 -0
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +10 -1
- package/src/ts/lib/__snapshots__/vitest.spec.ts.snap +1 -1
- package/src/ts/lib/generator.d.ts +16 -0
- package/src/ts/lib/generator.js +31 -5
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/vitest.d.ts +11 -0
- package/src/ts/lib/vitest.js +31 -2
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/generator.js +4 -7
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/rdb/generator.js +8 -5
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +27 -11
- package/src/ts/react-website/app/generator.js +9 -1
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/ts/sync/generator.js +19 -2
- package/src/ts/sync/generator.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +3 -3
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/api-constructs/api-constructs.js +2 -2
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/open-api-metadata.js +15 -36
- package/src/utils/api-constructs/open-api-metadata.js.map +1 -1
- package/src/utils/api-constructs/trpc-operations-metadata.js +9 -3
- package/src/utils/api-constructs/trpc-operations-metadata.js.map +1 -1
- package/src/utils/bundle/bundle.js +13 -4
- package/src/utils/bundle/bundle.js.map +1 -1
- package/src/utils/connection/open-api/react.js +7 -17
- package/src/utils/connection/open-api/react.js.map +1 -1
- package/src/utils/dcr-proxy-constructs/dcr-proxy-constructs.js +2 -2
- package/src/utils/dcr-proxy-constructs/dcr-proxy-constructs.js.map +1 -1
- package/src/utils/docker.d.ts +22 -10
- package/src/utils/docker.js +27 -17
- package/src/utils/docker.js.map +1 -1
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js +2 -2
- package/src/utils/dynamodb-constructs/dynamodb-constructs.js.map +1 -1
- package/src/utils/files/common/scripts/src/dynamodb/start-container.ts.template +0 -15
- package/src/utils/files/common/scripts/src/rdb/shared/start-container.ts.template +0 -15
- package/src/utils/format.d.ts +5 -0
- package/src/utils/format.js +5 -0
- package/src/utils/format.js.map +1 -1
- package/src/utils/function-constructs/function-constructs.js +2 -2
- package/src/utils/function-constructs/function-constructs.js.map +1 -1
- package/src/utils/generators.d.ts +33 -0
- package/src/utils/generators.js +18 -3
- package/src/utils/generators.js.map +1 -1
- package/src/utils/init.js +4 -6
- package/src/utils/init.js.map +1 -1
- package/src/utils/mock-project-graph.js +5 -2
- package/src/utils/mock-project-graph.js.map +1 -1
- package/src/utils/nx.d.ts +19 -0
- package/src/utils/nx.js +23 -0
- package/src/utils/nx.js.map +1 -1
- package/src/utils/open-api-codegen-target.d.ts +28 -0
- package/src/utils/open-api-codegen-target.js +31 -0
- package/src/utils/open-api-codegen-target.js.map +1 -0
- package/src/utils/rdb-constructs/rdb-constructs.js +2 -2
- package/src/utils/rdb-constructs/rdb-constructs.js.map +1 -1
- package/src/utils/website-constructs/website-constructs.js +2 -2
- package/src/utils/website-constructs/website-constructs.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator.js';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport {\n API_CONSTRUCTS_DEPENDENCIES,\n API_CONSTRUCTS_PY_DEPENDENCIES,\n addApiGatewayInfra,\n} from '../../utils/api-constructs/api-constructs.js';\nimport { addTrpcOperationsMetadataTarget } from '../../utils/api-constructs/trpc-operations-metadata.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport { assignPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants.js';\nimport type { TsTrpcApiGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsTrpcApiMetadata extends IacMetadata {\n readonly apiName: string;\n readonly apiType: string;\n readonly auth: TsTrpcApiGeneratorSchema['auth'];\n readonly infra: TsTrpcApiGeneratorSchema['infra'];\n readonly integrationPattern: 'isolated' | 'shared';\n}\n\n// Each entry names the branch it belongs to, so the same declaration drives both\n// adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsTrpcApiMetadata>()({\n ts: [\n { name: 'aws-xray-sdk-core' },\n { name: 'zod' },\n { name: '@aws-lambda-powertools/logger' },\n { name: '@aws-lambda-powertools/metrics' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-lambda-powertools/tracer' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@trpc/server' },\n { name: '@trpc/client' },\n { name: 'aws4fetch' },\n { name: '@aws-sdk/credential-providers' },\n // The custom authorizer handler wraps itself with middy and parses its event.\n { name: '@middy/core', when: (m) => m.auth === 'custom' },\n { name: '@aws-lambda-powertools/parser', when: (m) => m.auth === 'custom' },\n { name: '@types/aws-lambda', dev: true },\n { name: 'cors', dev: true },\n { name: '@types/cors', dev: true },\n // tsx runs the local server from the workspace root.\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(API_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n py: ownedElsewhere(API_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const TRPC_BACKEND_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([\n 'rest-lambda::isolated',\n 'rest-lambda::shared',\n 'http-lambda::isolated',\n 'http-lambda::shared',\n 'none::isolated',\n 'none::shared',\n]);\n\nexport async function tsTrpcApiGenerator(\n tree: Tree,\n options: TsTrpcApiGeneratorSchema,\n) {\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n options.infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (options.infra !== 'none') {\n validateTrpcInfraAndIntegrationPatternCombination(options);\n }\n\n const apiNamespace = getNpmScopePrefix(tree);\n const apiNameKebabCase = kebabCase(options.name);\n const apiNameClassName = toClassName(options.name);\n\n const backendName = apiNameKebabCase;\n const backendProjectName = `${apiNamespace}${backendName}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: backendName,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n backendProjectName,\n );\n const backendRoot = projectConfig.root;\n\n const port = assignPort(tree, projectConfig, 2022);\n\n const enhancedOptions = {\n backendProjectName,\n backendProjectAlias: backendProjectName,\n apiNameKebabCase,\n apiNameClassName,\n backendRoot,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n apiGatewayEventType: getApiGatewayEventType(options),\n port,\n ...options,\n ...esmVars(tree),\n };\n\n if (options.infra !== 'none') {\n await sharedConstructsGenerator(\n tree,\n {\n iac,\n },\n DEPENDENCIES,\n );\n\n await addApiGatewayInfra(\n tree,\n {\n apiProjectName: backendProjectName,\n apiNameClassName,\n apiNameKebabCase,\n constructType: options.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'trpc',\n projectAlias: enhancedOptions.backendProjectAlias,\n bundleOutputDir: joinPathFragments('dist', backendRoot, 'bundle'),\n integrationPattern: getIntegrationPattern(options),\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendRoot,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n auth: options.auth,\n iac,\n },\n DEPENDENCIES,\n );\n }\n\n // Recorded on the project below and read by the declaration's predicates, so\n // the packages added here are exactly the ones the version sync will own.\n const metadata: TsTrpcApiMetadata = {\n apiName: options.name,\n apiType: 'trpc',\n auth: options.auth,\n infra: options.infra,\n integrationPattern: getIntegrationPattern(options),\n ...(iac ? { iac } : {}),\n };\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n ...metadata,\n } as unknown;\n\n projectConfig.targets.serve = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: ['tsx --watch src/local-server.ts'],\n cwd: '{projectRoot}',\n },\n };\n\n projectConfig.targets['dev'] = {\n ...projectConfig.targets['dev'],\n ...projectConfig.targets.serve,\n options: {\n ...projectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n\n if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n },\n DEPENDENCIES,\n );\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n },\n DEPENDENCIES,\n );\n }\n\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n\n // Terraform defines one Lambda function per operation from a generated\n // metadata file; CDK derives the same information from the router's types.\n if (iac === 'terraform' && getIntegrationPattern(options) === 'isolated') {\n addTrpcOperationsMetadataTarget(tree, {\n apiNameKebabCase,\n project: projectConfig,\n templateOptions: esmVars(tree),\n });\n }\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendRoot,\n enhancedOptions,\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n tree.delete(joinPathFragments(backendRoot, 'src', 'lib'));\n\n if (options.infra !== 'none' && options.auth === 'custom') {\n const authorizerType = options.infra === 'http-lambda' ? 'http' : 'rest';\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'cdk',\n 'authorizer',\n authorizerType,\n ),\n joinPathFragments(backendRoot, 'src'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)\n if (options.infra !== 'rest-lambda' && options.infra !== 'none') {\n tree.delete(\n joinPathFragments(backendRoot, 'src', 'schema', 'z-async-iterable.ts'),\n );\n }\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: backendRoot,\n });\n addGeneratorMetadata(\n tree,\n backendName,\n TRPC_BACKEND_GENERATOR_INFO,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TRPC_BACKEND_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\n\nconst validateTrpcInfraAndIntegrationPatternCombination = (\n options: TsTrpcApiGeneratorSchema,\n) => {\n const integrationPattern = getIntegrationPattern(options);\n const permutation = `${options.infra}::${integrationPattern}`;\n\n if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {\n throw new Error(\n `Invalid tRPC infra/integrationPattern combination: ${options.infra} + ${integrationPattern}.`,\n );\n }\n};\n\nconst getIntegrationPattern = (\n options: TsTrpcApiGeneratorSchema,\n): 'isolated' | 'shared' => {\n return options.integrationPattern ?? 'isolated';\n};\n\nconst getApiGatewayEventType = (options: TsTrpcApiGeneratorSchema): string => {\n if (options.infra === 'rest-lambda') {\n return 'APIGatewayProxyEvent';\n }\n if (options.auth === 'iam') {\n return 'APIGatewayProxyEventV2WithIAMAuthorizer';\n } else if (options.auth === 'cognito') {\n return 'APIGatewayProxyEventV2WithJWTAuthorizer';\n }\n return 'APIGatewayProxyEventV2';\n};\n\nexport default tsTrpcApiGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addTsDependencies","API_CONSTRUCTS_DEPENDENCIES","API_CONSTRUCTS_PY_DEPENDENCIES","addApiGatewayInfra","addTrpcOperationsMetadataTarget","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","declareDependencies","ownedElsewhere","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScopePrefix","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getPackageManagerDisplayCommands","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","name","when","m","auth","dev","root","py","TRPC_BACKEND_GENERATOR_INFO","filename","VALID_TRPC_INTEGRATION_PERMUTATIONS","Set","tsTrpcApiGenerator","tree","options","iac","infra","undefined","validateTrpcInfraAndIntegrationPatternCombination","apiNamespace","apiNameKebabCase","apiNameClassName","backendName","backendProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","backendRoot","port","enhancedOptions","backendProjectAlias","pkgMgrCmd","exec","apiGatewayEventType","getApiGatewayEventType","apiProjectName","constructType","backend","type","projectAlias","bundleOutputDir","integrationPattern","getIntegrationPattern","authorizerBundleOutputDir","metadata","apiName","apiType","targets","serve","executor","continuous","commands","cwd","env","LOCAL_DEV","targetFilePath","external","project","templateOptions","dirname","overwriteStrategy","Overwrite","delete","authorizerType","KeepExisting","projectRoot","languages","permutation","has","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAi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GACD;YACEiC,mBAAmB5F,kBAAkBgG,YAAY;QACnD;IAEJ;IAEA,gGAAgG;IAChG,IAAIpD,QAAQE,KAAK,KAAK,iBAAiBF,QAAQE,KAAK,KAAK,QAAQ;QAC/DH,KAAKmD,MAAM,CACT/F,kBAAkB4D,aAAa,OAAO,UAAU;IAEpD;IAEAxD,kBAAkBwC,MAAMd,cAAc;QACpC+C;QACAqB,aAAatC;IACf;IACAtC,qBACEsB,MACAS,aACAd,6BACAsC;IAGF,MAAM7D,gCAAgC4B,MAAM;QAACL;KAA4B;IAEzE,MAAM1B,qBAAqB+B;IAC3B,OAAO,IACL7B,oBAAoB6B,MAAMC,QAAQa,yBAAyB,EAAE;YAC3DyC,WAAW;gBAAC;aAAa;QAC3B;AACJ;AAEA,MAAMlD,oDAAoD,CACxDJ;IAEA,MAAM6B,qBAAqBC,sBAAsB9B;IACjD,MAAMuD,cAAc,GAAGvD,QAAQE,KAAK,CAAC,EAAE,EAAE2B,oBAAoB;IAE7D,IAAI,CAACjC,oCAAoC4D,GAAG,CAACD,cAAc;QACzD,MAAM,IAAIE,MACR,CAAC,mDAAmD,EAAEzD,QAAQE,KAAK,CAAC,GAAG,EAAE2B,mBAAmB,CAAC,CAAC;IAElG;AACF;AAEA,MAAMC,wBAAwB,CAC5B9B;IAEA,OAAOA,QAAQ6B,kBAAkB,IAAI;AACvC;AAEA,MAAMP,yBAAyB,CAACtB;IAC9B,IAAIA,QAAQE,KAAK,KAAK,eAAe;QACnC,OAAO;IACT;IACA,IAAIF,QAAQV,IAAI,KAAK,OAAO;QAC1B,OAAO;IACT,OAAO,IAAIU,QAAQV,IAAI,KAAK,WAAW;QACrC,OAAO;IACT;IACA,OAAO;AACT;AAEA,eAAeQ,mBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/trpc/backend/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator.js';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport {\n API_CONSTRUCTS_DEPENDENCIES,\n API_CONSTRUCTS_PY_DEPENDENCIES,\n addApiGatewayInfra,\n} from '../../utils/api-constructs/api-constructs.js';\nimport { addTrpcOperationsMetadataTarget } from '../../utils/api-constructs/trpc-operations-metadata.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport { assignPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants.js';\nimport type { TsTrpcApiGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsTrpcApiMetadata extends IacMetadata {\n readonly apiName: string;\n readonly apiType: string;\n readonly auth: TsTrpcApiGeneratorSchema['auth'];\n readonly infra: TsTrpcApiGeneratorSchema['infra'];\n readonly integrationPattern: 'isolated' | 'shared';\n}\n\n// Each entry names the branch it belongs to, so the same declaration drives both\n// adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsTrpcApiMetadata>()({\n ts: [\n { name: 'aws-xray-sdk-core' },\n { name: 'zod' },\n { name: '@aws-lambda-powertools/logger' },\n { name: '@aws-lambda-powertools/metrics' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-lambda-powertools/tracer' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@trpc/server' },\n { name: '@trpc/client' },\n { name: 'aws4fetch' },\n { name: '@aws-sdk/credential-providers' },\n // The custom authorizer handler wraps itself with middy and parses its event.\n { name: '@middy/core', when: (m) => m.auth === 'custom' },\n { name: '@aws-lambda-powertools/parser', when: (m) => m.auth === 'custom' },\n { name: '@types/aws-lambda', dev: true },\n { name: 'cors', dev: true },\n { name: '@types/cors', dev: true },\n // tsx runs the local server from the workspace root.\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(API_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n py: ownedElsewhere(API_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const TRPC_BACKEND_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nconst VALID_TRPC_INTEGRATION_PERMUTATIONS = new Set([\n 'rest-lambda::isolated',\n 'rest-lambda::shared',\n 'http-lambda::isolated',\n 'http-lambda::shared',\n 'none::isolated',\n 'none::shared',\n]);\n\nexport async function tsTrpcApiGenerator(\n tree: Tree,\n options: TsTrpcApiGeneratorSchema,\n) {\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n options.infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (options.infra !== 'none') {\n validateTrpcInfraAndIntegrationPatternCombination(options);\n }\n\n const apiNamespace = getNpmScopePrefix(tree);\n const apiNameKebabCase = kebabCase(options.name);\n const apiNameClassName = toClassName(options.name);\n\n const backendName = apiNameKebabCase;\n const backendProjectName = `${apiNamespace}${backendName}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, backendProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: backendName,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n backendProjectName,\n );\n const backendRoot = projectConfig.root;\n\n const port = assignPort(tree, projectConfig, 2022);\n\n const enhancedOptions = {\n backendProjectName,\n backendProjectAlias: backendProjectName,\n apiNameKebabCase,\n apiNameClassName,\n backendRoot,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n apiGatewayEventType: getApiGatewayEventType(options),\n port,\n ...options,\n ...esmVars(tree),\n };\n\n if (options.infra !== 'none') {\n await sharedConstructsGenerator(\n tree,\n {\n iac,\n },\n DEPENDENCIES,\n );\n\n await addApiGatewayInfra(\n tree,\n {\n apiProjectName: backendProjectName,\n apiNameClassName,\n apiNameKebabCase,\n constructType: options.infra === 'http-lambda' ? 'http' : 'rest',\n backend: {\n type: 'trpc',\n projectAlias: enhancedOptions.backendProjectAlias,\n bundleOutputDir: joinPathFragments('dist', backendRoot, 'bundle'),\n integrationPattern: getIntegrationPattern(options),\n ...(options.auth === 'custom' && {\n authorizerBundleOutputDir: joinPathFragments(\n 'dist',\n backendRoot,\n 'bundle',\n 'authorizer',\n ),\n }),\n },\n auth: options.auth,\n iac,\n },\n DEPENDENCIES,\n );\n }\n\n // Recorded on the project below and read by the declaration's predicates, so\n // the packages added here are exactly the ones the version sync will own.\n const metadata: TsTrpcApiMetadata = {\n apiName: options.name,\n apiType: 'trpc',\n auth: options.auth,\n infra: options.infra,\n integrationPattern: getIntegrationPattern(options),\n ...(iac ? { iac } : {}),\n };\n\n projectConfig.metadata = {\n ...projectConfig.metadata,\n ...metadata,\n } as unknown;\n\n projectConfig.targets.serve = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: ['tsx --watch src/local-server.ts'],\n cwd: '{projectRoot}',\n },\n };\n\n projectConfig.targets['dev'] = {\n ...projectConfig.targets['dev'],\n ...projectConfig.targets.serve,\n options: {\n ...projectConfig.targets.serve.options,\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n\n if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/handler.ts',\n external: [/@aws-sdk\\/.*/], // lambda runtime provides aws sdk\n },\n DEPENDENCIES,\n );\n\n if (options.auth === 'custom') {\n await addTypeScriptBundleTarget(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/authorizer.ts',\n bundleOutputDir: 'authorizer',\n external: [/@aws-sdk\\/.*/],\n },\n DEPENDENCIES,\n );\n }\n\n addArtifactDependencyToTargets(projectConfig, 'bundle');\n\n // Terraform defines one Lambda function per operation from a generated\n // metadata file; CDK derives the same information from the router's types.\n if (iac === 'terraform' && getIntegrationPattern(options) === 'isolated') {\n addTrpcOperationsMetadataTarget(tree, {\n apiNameKebabCase,\n project: projectConfig,\n templateOptions: esmVars(tree),\n });\n }\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n backendRoot,\n enhancedOptions,\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n tree.delete(joinPathFragments(backendRoot, 'src', 'lib'));\n\n if (options.infra !== 'none' && options.auth === 'custom') {\n const authorizerType = options.infra === 'http-lambda' ? 'http' : 'rest';\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'api-constructs',\n 'files',\n 'cdk',\n 'authorizer',\n authorizerType,\n ),\n joinPathFragments(backendRoot, 'src'),\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n\n // Remove streaming schema helper for HTTP APIs (API Gateway HTTP API doesn't support streaming)\n if (options.infra !== 'rest-lambda' && options.infra !== 'none') {\n tree.delete(\n joinPathFragments(backendRoot, 'src', 'schema', 'z-async-iterable.ts'),\n );\n }\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: backendRoot,\n });\n addGeneratorMetadata(\n tree,\n backendName,\n TRPC_BACKEND_GENERATOR_INFO,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TRPC_BACKEND_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\n\nconst validateTrpcInfraAndIntegrationPatternCombination = (\n options: TsTrpcApiGeneratorSchema,\n) => {\n const integrationPattern = getIntegrationPattern(options);\n const permutation = `${options.infra}::${integrationPattern}`;\n\n if (!VALID_TRPC_INTEGRATION_PERMUTATIONS.has(permutation)) {\n throw new Error(\n `Invalid tRPC infra/integrationPattern combination: ${options.infra} + ${integrationPattern}.`,\n );\n }\n};\n\nconst getIntegrationPattern = (\n options: TsTrpcApiGeneratorSchema,\n): 'isolated' | 'shared' => {\n return options.integrationPattern ?? 'isolated';\n};\n\nconst getApiGatewayEventType = (options: TsTrpcApiGeneratorSchema): string => {\n if (options.infra === 'rest-lambda') {\n return 'APIGatewayProxyEvent';\n }\n if (options.auth === 'iam') {\n return 'APIGatewayProxyEventV2WithIAMAuthorizer';\n } else if (options.auth === 'cognito') {\n return 'APIGatewayProxyEventV2WithJWTAuthorizer';\n }\n return 'APIGatewayProxyEventV2';\n};\n\nexport default tsTrpcApiGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addTsDependencies","API_CONSTRUCTS_DEPENDENCIES","API_CONSTRUCTS_PY_DEPENDENCIES","addApiGatewayInfra","addTrpcOperationsMetadataTarget","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","declareDependencies","ownedElsewhere","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScopePrefix","addArtifactDependencyToTargets","addGeneratorMetadata","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getPackageManagerDisplayCommands","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","name","when","m","auth","dev","root","py","TRPC_BACKEND_GENERATOR_INFO","filename","VALID_TRPC_INTEGRATION_PERMUTATIONS","Set","tsTrpcApiGenerator","tree","options","iac","infra","undefined","validateTrpcInfraAndIntegrationPatternCombination","apiNamespace","apiNameKebabCase","apiNameClassName","backendName","backendProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","backendRoot","port","enhancedOptions","backendProjectAlias","pkgMgrCmd","exec","apiGatewayEventType","getApiGatewayEventType","apiProjectName","constructType","backend","type","projectAlias","bundleOutputDir","integrationPattern","getIntegrationPattern","authorizerBundleOutputDir","metadata","apiName","apiType","targets","serve","executor","continuous","commands","cwd","env","LOCAL_DEV","targetFilePath","external","project","templateOptions","dirname","overwriteStrategy","Overwrite","delete","authorizerType","KeepExisting","projectRoot","languages","permutation","has","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,wBAAwB,4BAA4B;AAC3D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,2BAA2B,EAC3BC,8BAA8B,EAC9BC,kBAAkB,QACb,+CAA+C;AACtD,SAASC,+BAA+B,QAAQ,yDAAyD;AACzG,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA+B;AACtC,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,UAAU,QAA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AqB+B;IAC3B,OAAO,IACL7B,oBAAoB6B,MAAMC,QAAQa,yBAAyB,EAAE;YAC3DyC,WAAW;gBAAC;aAAa;QAC3B;AACJ;AAEA,MAAMlD,oDAAoD,CACxDJ;IAEA,MAAM6B,qBAAqBC,sBAAsB9B;IACjD,MAAMuD,cAAc,GAAGvD,QAAQE,KAAK,CAAC,EAAE,EAAE2B,oBAAoB;IAE7D,IAAI,CAACjC,oCAAoC4D,GAAG,CAACD,cAAc;QACzD,MAAM,IAAIE,MACR,CAAC,mDAAmD,EAAEzD,QAAQE,KAAK,CAAC,GAAG,EAAE2B,mBAAmB,CAAC,CAAC;IAElG;AACF;AAEA,MAAMC,wBAAwB,CAC5B9B;IAEA,OAAOA,QAAQ6B,kBAAkB,IAAI;AACvC;AAEA,MAAMP,yBAAyB,CAACtB;IAC9B,IAAIA,QAAQE,KAAK,KAAK,eAAe;QACnC,OAAO;IACT;IACA,IAAIF,QAAQV,IAAI,KAAK,OAAO;QAC1B,OAAO;IACT,OAAO,IAAIU,QAAQV,IAAI,KAAK,WAAW;QACrC,OAAO;IACT;IACA,OAAO;AACT;AAEA,eAAeQ,mBAAmB"}
|
|
@@ -9,7 +9,7 @@ import { AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES, addAgentInfra } from "../../util
|
|
|
9
9
|
import { addTypeScriptBundleTarget, BUNDLE_DEPENDENCIES } from "../../utils/bundle/bundle.js";
|
|
10
10
|
import { resolveContainers } from "../../utils/containers.js";
|
|
11
11
|
import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
|
|
12
|
-
import { ADOT_IMAGE_DEPENDENCIES, addDockerScanTarget, DOCKER_DEPENDENCIES, NODE_IMAGE_DEPENDENCIES, nodeImageVersions } from "../../utils/docker.js";
|
|
12
|
+
import { ADOT_IMAGE_DEPENDENCIES, addDockerScanTarget, DOCKER_DEPENDENCIES, IMAGE_BUILD_CACHE, NODE_IMAGE_DEPENDENCIES, nodeImageVersions } from "../../utils/docker.js";
|
|
13
13
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
14
14
|
import { FS_DEPENDENCIES, FsCommands } from "../../utils/fs.js";
|
|
15
15
|
import { resolveIac } from "../../utils/iac.js";
|
|
@@ -18,7 +18,7 @@ import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
|
18
18
|
import { esmVars } from "../../utils/module-format.js";
|
|
19
19
|
import { kebabCase, toClassName } from "../../utils/names.js";
|
|
20
20
|
import { getNpmScope } from "../../utils/npm-scope.js";
|
|
21
|
-
import { addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
21
|
+
import { addArtifactDependencyToTargets, addComponentDevTarget, addComponentGeneratorMetadata, addDependencyToTargetIfNotPresent, getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
22
22
|
import { sortObjectKeys } from "../../utils/object.js";
|
|
23
23
|
import { getRelativePathToRootByDirectory } from "../../utils/paths.js";
|
|
24
24
|
import { assignPort } from "../../utils/port.js";
|
|
@@ -257,10 +257,7 @@ export const tsAgentGenerator = async (tree, options)=>{
|
|
|
257
257
|
const dockerTargetName = `${agentTargetPrefix}-docker`;
|
|
258
258
|
const fs = new FsCommands(tree, DEPENDENCIES);
|
|
259
259
|
project.targets[dockerTargetName] = {
|
|
260
|
-
cache:
|
|
261
|
-
outputs: [
|
|
262
|
-
`{workspaceRoot}/${dockerOutputDir}/Dockerfile`
|
|
263
|
-
],
|
|
260
|
+
cache: IMAGE_BUILD_CACHE,
|
|
264
261
|
executor: 'nx:run-commands',
|
|
265
262
|
options: {
|
|
266
263
|
commands: [
|
|
@@ -274,7 +271,7 @@ export const tsAgentGenerator = async (tree, options)=>{
|
|
|
274
271
|
]
|
|
275
272
|
};
|
|
276
273
|
addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);
|
|
277
|
-
|
|
274
|
+
addArtifactDependencyToTargets(project, 'docker');
|
|
278
275
|
addDockerScanTarget(tree, {
|
|
279
276
|
project,
|
|
280
277
|
containerEngine: containers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/agent/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { addAgentChatScripts } from '../../utils/agent-chat/agent-chat.js';\nimport {\n AGENT_CONNECTION_DEPENDENCIES,\n addTypeScriptFrameworkBase,\n ensureTypeScriptAgentConnectionProject,\n} from '../../utils/agent-connection/agent-connection.js';\nimport {\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addAgentInfra,\n} from '../../utils/agent-core-constructs/agent-core-constructs.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport {\n ADOT_IMAGE_DEPENDENCIES,\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n} from '../../utils/docker.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths.js';\nimport { assignPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants.js';\nimport { BASE_IMAGES, TS_VERSIONS } from '../../utils/versions.js';\nimport type { TsAgentGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsAgentMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n readonly protocol: string;\n readonly session: string;\n}\n\n// Each entry names the branch it belongs to, so the same declaration drives both\n// adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsAgentMetadata>()({\n ts: [\n { name: 'zod' },\n { name: '@strands-agents/sdk' },\n { name: '@aws-sdk/credential-providers' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@modelcontextprotocol/sdk' },\n { name: '@aws-sdk/client-s3', when: (m) => m.session === 's3' },\n { name: 'express', when: (m) => m.protocol !== 'http' },\n { name: '@a2a-js/sdk', when: (m) => m.protocol === 'a2a' },\n { name: '@ag-ui/aws-strands', when: (m) => m.protocol === 'ag-ui' },\n // @ag-ui/aws-strands declares these as peer dependencies but statically\n // imports them, so they must be installed for the bundler to inline them.\n { name: '@ag-ui/a2ui-toolkit', when: (m) => m.protocol === 'ag-ui' },\n { name: '@ag-ui/client', when: (m) => m.protocol === 'ag-ui' },\n { name: '@ag-ui/core', when: (m) => m.protocol === 'ag-ui' },\n { name: '@ag-ui/encoder', when: (m) => m.protocol === 'ag-ui' },\n { name: '@trpc/server', when: (m) => m.protocol === 'http' },\n { name: '@trpc/client', when: (m) => m.protocol === 'http' },\n { name: 'ws', when: (m) => m.protocol === 'http' },\n { name: 'cors', when: (m) => m.protocol !== 'a2a' },\n { name: 'aws4fetch', when: (m) => m.protocol === 'http' },\n { name: 'aws4fetch', when: (m) => m.auth === 'iam', dev: true },\n {\n name: '@aws-sdk/credential-providers',\n when: (m) => m.auth === 'iam',\n dev: true,\n },\n { name: '@types/node', dev: true },\n // The chat CLI runs standalone via tsx and resolves the deployed agent from\n // AppConfig when `RUNTIME_CONFIG_APP_ID` is set.\n { name: 'agent-chat-cli', dev: true },\n { name: '@aws-lambda-powertools/parameters', dev: true },\n { name: '@aws-sdk/client-appconfigdata', dev: true },\n // A2A chat builds a signed @a2a-js client factory for the deployed agent.\n { name: '@a2a-js/sdk', when: (m) => m.protocol === 'a2a', dev: true },\n { name: '@types/express', when: (m) => m.protocol !== 'http', dev: true },\n { name: '@types/ws', when: (m) => m.protocol === 'http', dev: true },\n { name: '@types/cors', dev: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(AGENT_CONNECTION_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const TS_AGENT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAgentGenerator = async (\n tree: Tree,\n options: TsAgentGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-agent`;\n const name = kebabCase(options.name || defaultName);\n const agentNameClassName = toClassName(name);\n const agentTargetPrefix = options.name ? name : 'agent';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n agentTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n const protocol = options.protocol ?? 'http';\n\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n const session = options.session ?? 's3';\n\n if (infra === 'none' && session !== 'in-memory') {\n console.warn(\n 'Warning: session is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n // Local-dev session storage lives at the workspace root\n // (`tmp/agents/strands/<agent-name>`), not inside the project, so each agent\n // gets its own storage directory. The `-dev`/`-serve` targets run with\n // cwd={projectRoot}, so compute that directory relative to the project root\n // here rather than resolving it at runtime (e.g. via import.meta.url),\n // which would need an extra runtime helper.\n const localSessionsDir = joinPathFragments(\n getRelativePathToRootByDirectory(project.root),\n `tmp/agents/strands/${name}`,\n );\n\n // Ensure the shared agent-connection project exists so the server entry\n // point can import `runWithSessionId` and propagate the AgentCore session\n // ID to any downstream MCP / A2A clients a later connection generator\n // wires into this agent.\n await ensureTypeScriptAgentConnectionProject(tree, DEPENDENCIES);\n // The agent server imports the framework base helpers (session cache + model\n // error logging) regardless of whether a connection client is wired in.\n await addTypeScriptFrameworkBase(tree, DEPENDENCIES);\n\n const templateContext = {\n name,\n agentNameClassName,\n distDir,\n protocol,\n session,\n localSessionsDir,\n agentConnectionImport: `@${getNpmScope(tree)}/agent-connection`,\n ...esmVars(tree),\n };\n\n // Generate common files shared by both protocols\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate protocol-specific files\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', protocol.toLowerCase()),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // AG-UI and A2A both mount an Express app and share the same session-id\n // middleware; HTTP relies on tRPC's createContext instead and has no\n // Express dependency to support it.\n if (protocol === 'ag-ui' || protocol === 'a2a') {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common-express'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(\n tree,\n project,\n {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/index.ts`,\n bundleOutputDir: joinPathFragments('agent', name),\n },\n DEPENDENCIES,\n );\n\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n distDir,\n name,\n protocol,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],\n nodeBaseImage: BASE_IMAGES.node,\n ...nodeImageVersions(),\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'agent',\n name,\n );\n const dockerTargetName = `${agentTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree, DEPENDENCIES);\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 addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${agentTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n // AG-UI uses HTTP as the AgentCore protocol type (AG-UI is HTTP-based with SSE over POST).\n const infraProtocol: 'http' | 'a2a' =\n protocol === 'ag-ui' ? 'http' : (protocol as 'http' | 'a2a');\n\n await addAgentInfra(tree, {\n agentNameKebabCase: name,\n agentNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n session,\n serverProtocol: infraProtocol,\n containers,\n });\n }\n\n // A2A servers use port 9000 as per the Strands A2A SDK default and AgentCore A2A contract.\n // HTTP and AG-UI agents use port 8081+ to avoid conflict with VS Code server on 8080.\n const localDevPortStart = protocol === 'a2a' ? 9000 : 8081;\n const localDevPort = assignPort(tree, project, localDevPortStart, {\n component: { info: TS_AGENT_GENERATOR_INFO, name: agentTargetPrefix },\n });\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: TsAgentMetadata = {\n port: localDevPort,\n rc: agentNameClassName,\n auth,\n protocol,\n session,\n ...(iac ? { iac } : {}),\n };\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\n });\n\n // Every protocol gets a standalone `chat.ts`. It connects to the local\n // `dev` server by default, or to the deployed agent (with the\n // appropriate auth) when `RUNTIME_CONFIG_APP_ID` is set.\n const scriptsDir = joinPathFragments(\n project.root,\n 'scripts',\n agentTargetPrefix,\n );\n addAgentChatScripts(tree, {\n scriptsDir,\n protocol,\n language: 'ts',\n agentNameClassName,\n auth,\n relativeAgentImport: `../../${targetSourceDirRelativeToProjectRoot}`,\n });\n\n const chatUrl =\n protocol === 'http'\n ? `ws://localhost:${localDevPort}/ws`\n : protocol === 'ag-ui'\n ? `http://localhost:${localDevPort}/invocations`\n : `http://localhost:${localDevPort}`;\n const chatCommand = `tsx ./scripts/${agentTargetPrefix}/chat.ts`;\n\n const agentTargets = {\n ...project.targets,\n [`${agentTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${agentTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${agentTargetPrefix}-chat`]: {\n executor: 'nx:run-commands',\n options: {\n commands: [chatCommand],\n cwd: '{projectRoot}',\n env: {\n URL: chatUrl,\n },\n },\n },\n };\n\n // Aggregate `<agent>-dev` under the project-level `dev` target.\n addComponentDevTarget(agentTargets, `${agentTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(agentTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_AGENT_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n agentTargetPrefix,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_AGENT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","addAgentChatScripts","AGENT_CONNECTION_DEPENDENCIES","addTypeScriptFrameworkBase","ensureTypeScriptAgentConnectionProject","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addAgentInfra","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","DOCKER_DEPENDENCIES","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getRelativePathToRootByDirectory","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","DEPENDENCIES","ts","name","when","m","session","protocol","auth","dev","root","py","TS_AGENT_GENERATOR_INFO","filename","tsAgentGenerator","tree","options","project","exists","Error","defaultName","split","pop","agentNameClassName","agentTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","iac","undefined","console","warn","localSessionsDir","templateContext","agentConnectionImport","dirname","overwriteStrategy","KeepExisting","toLowerCase","containers","dockerImageTag","targetFilePath","bundleOutputDir","adotVersion","jaegerVersion","nodeBaseImage","node","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","infraProtocol","agentNameKebabCase","projectName","serverProtocol","localDevPortStart","localDevPort","component","info","metadata","port","rc","projectRoot","scriptsDir","language","relativeAgentImport","chatUrl","chatCommand","agentTargets","continuous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gC,UAAU;YACVxC,SAAS;gBACPyC,UAAU;oBAACuB;iBAAY;gBACvBG,KAAK;gBACLC,KAAK;oBACHG,KAAKR;gBACP;YACF;QACF;IACF;IAEA,gEAAgE;IAChE1F,sBAAsB4F,cAAc,GAAGzD,kBAAkB,IAAI,CAAC;IAE9D/D,2BAA2BsD,MAAME,QAAQd,IAAI,EAAE;QAC7C,GAAGc,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBoC,SAAS3D,eAAeuF;IAC1B;IAEA3F,8BACEyB,MACAE,QAAQd,IAAI,EACZS,yBACAa,sCACAD,mBACAgD;IAGF,MAAMxF,gCAAgC+B,MAAM;QAACH;KAAwB;IAErE,MAAMjC,qBAAqBoC;IAC3B,OAAO,IACLhC,oBAAoBgC,MAAMC,QAAQwE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe3E,iBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/agent/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { addAgentChatScripts } from '../../utils/agent-chat/agent-chat.js';\nimport {\n AGENT_CONNECTION_DEPENDENCIES,\n addTypeScriptFrameworkBase,\n ensureTypeScriptAgentConnectionProject,\n} from '../../utils/agent-connection/agent-connection.js';\nimport {\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addAgentInfra,\n} from '../../utils/agent-core-constructs/agent-core-constructs.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport {\n ADOT_IMAGE_DEPENDENCIES,\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n IMAGE_BUILD_CACHE,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n} from '../../utils/docker.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths.js';\nimport { assignPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants.js';\nimport { BASE_IMAGES, TS_VERSIONS } from '../../utils/versions.js';\nimport type { TsAgentGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsAgentMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n readonly protocol: string;\n readonly session: string;\n}\n\n// Each entry names the branch it belongs to, so the same declaration drives both\n// adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsAgentMetadata>()({\n ts: [\n { name: 'zod' },\n { name: '@strands-agents/sdk' },\n { name: '@aws-sdk/credential-providers' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@modelcontextprotocol/sdk' },\n { name: '@aws-sdk/client-s3', when: (m) => m.session === 's3' },\n { name: 'express', when: (m) => m.protocol !== 'http' },\n { name: '@a2a-js/sdk', when: (m) => m.protocol === 'a2a' },\n { name: '@ag-ui/aws-strands', when: (m) => m.protocol === 'ag-ui' },\n // @ag-ui/aws-strands declares these as peer dependencies but statically\n // imports them, so they must be installed for the bundler to inline them.\n { name: '@ag-ui/a2ui-toolkit', when: (m) => m.protocol === 'ag-ui' },\n { name: '@ag-ui/client', when: (m) => m.protocol === 'ag-ui' },\n { name: '@ag-ui/core', when: (m) => m.protocol === 'ag-ui' },\n { name: '@ag-ui/encoder', when: (m) => m.protocol === 'ag-ui' },\n { name: '@trpc/server', when: (m) => m.protocol === 'http' },\n { name: '@trpc/client', when: (m) => m.protocol === 'http' },\n { name: 'ws', when: (m) => m.protocol === 'http' },\n { name: 'cors', when: (m) => m.protocol !== 'a2a' },\n { name: 'aws4fetch', when: (m) => m.protocol === 'http' },\n { name: 'aws4fetch', when: (m) => m.auth === 'iam', dev: true },\n {\n name: '@aws-sdk/credential-providers',\n when: (m) => m.auth === 'iam',\n dev: true,\n },\n { name: '@types/node', dev: true },\n // The chat CLI runs standalone via tsx and resolves the deployed agent from\n // AppConfig when `RUNTIME_CONFIG_APP_ID` is set.\n { name: 'agent-chat-cli', dev: true },\n { name: '@aws-lambda-powertools/parameters', dev: true },\n { name: '@aws-sdk/client-appconfigdata', dev: true },\n // A2A chat builds a signed @a2a-js client factory for the deployed agent.\n { name: '@a2a-js/sdk', when: (m) => m.protocol === 'a2a', dev: true },\n { name: '@types/express', when: (m) => m.protocol !== 'http', dev: true },\n { name: '@types/ws', when: (m) => m.protocol === 'http', dev: true },\n { name: '@types/cors', dev: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(AGENT_CONNECTION_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\n\nexport const TS_AGENT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAgentGenerator = async (\n tree: Tree,\n options: TsAgentGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-agent`;\n const name = kebabCase(options.name || defaultName);\n const agentNameClassName = toClassName(name);\n const agentTargetPrefix = options.name ? name : 'agent';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n agentTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n const protocol = options.protocol ?? 'http';\n\n // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n const session = options.session ?? 's3';\n\n if (infra === 'none' && session !== 'in-memory') {\n console.warn(\n 'Warning: session is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n // Local-dev session storage lives at the workspace root\n // (`tmp/agents/strands/<agent-name>`), not inside the project, so each agent\n // gets its own storage directory. The `-dev`/`-serve` targets run with\n // cwd={projectRoot}, so compute that directory relative to the project root\n // here rather than resolving it at runtime (e.g. via import.meta.url),\n // which would need an extra runtime helper.\n const localSessionsDir = joinPathFragments(\n getRelativePathToRootByDirectory(project.root),\n `tmp/agents/strands/${name}`,\n );\n\n // Ensure the shared agent-connection project exists so the server entry\n // point can import `runWithSessionId` and propagate the AgentCore session\n // ID to any downstream MCP / A2A clients a later connection generator\n // wires into this agent.\n await ensureTypeScriptAgentConnectionProject(tree, DEPENDENCIES);\n // The agent server imports the framework base helpers (session cache + model\n // error logging) regardless of whether a connection client is wired in.\n await addTypeScriptFrameworkBase(tree, DEPENDENCIES);\n\n const templateContext = {\n name,\n agentNameClassName,\n distDir,\n protocol,\n session,\n localSessionsDir,\n agentConnectionImport: `@${getNpmScope(tree)}/agent-connection`,\n ...esmVars(tree),\n };\n\n // Generate common files shared by both protocols\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Generate protocol-specific files\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', protocol.toLowerCase()),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // AG-UI and A2A both mount an Express app and share the same session-id\n // middleware; HTTP relies on tRPC's createContext instead and has no\n // Express dependency to support it.\n if (protocol === 'ag-ui' || protocol === 'a2a') {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'common-express'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(\n tree,\n project,\n {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/index.ts`,\n bundleOutputDir: joinPathFragments('agent', name),\n },\n DEPENDENCIES,\n );\n\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n {\n distDir,\n name,\n protocol,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],\n nodeBaseImage: BASE_IMAGES.node,\n ...nodeImageVersions(),\n ...esmVars(tree),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'agent',\n name,\n );\n const dockerTargetName = `${agentTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree, DEPENDENCIES);\n project.targets[dockerTargetName] = {\n cache: IMAGE_BUILD_CACHE,\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 addArtifactDependencyToTargets(project, 'docker');\n\n addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${agentTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n // AG-UI uses HTTP as the AgentCore protocol type (AG-UI is HTTP-based with SSE over POST).\n const infraProtocol: 'http' | 'a2a' =\n protocol === 'ag-ui' ? 'http' : (protocol as 'http' | 'a2a');\n\n await addAgentInfra(tree, {\n agentNameKebabCase: name,\n agentNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n session,\n serverProtocol: infraProtocol,\n containers,\n });\n }\n\n // A2A servers use port 9000 as per the Strands A2A SDK default and AgentCore A2A contract.\n // HTTP and AG-UI agents use port 8081+ to avoid conflict with VS Code server on 8080.\n const localDevPortStart = protocol === 'a2a' ? 9000 : 8081;\n const localDevPort = assignPort(tree, project, localDevPortStart, {\n component: { info: TS_AGENT_GENERATOR_INFO, name: agentTargetPrefix },\n });\n\n // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: TsAgentMetadata = {\n port: localDevPort,\n rc: agentNameClassName,\n auth,\n protocol,\n session,\n ...(iac ? { iac } : {}),\n };\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\n });\n\n // Every protocol gets a standalone `chat.ts`. It connects to the local\n // `dev` server by default, or to the deployed agent (with the\n // appropriate auth) when `RUNTIME_CONFIG_APP_ID` is set.\n const scriptsDir = joinPathFragments(\n project.root,\n 'scripts',\n agentTargetPrefix,\n );\n addAgentChatScripts(tree, {\n scriptsDir,\n protocol,\n language: 'ts',\n agentNameClassName,\n auth,\n relativeAgentImport: `../../${targetSourceDirRelativeToProjectRoot}`,\n });\n\n const chatUrl =\n protocol === 'http'\n ? `ws://localhost:${localDevPort}/ws`\n : protocol === 'ag-ui'\n ? `http://localhost:${localDevPort}/invocations`\n : `http://localhost:${localDevPort}`;\n const chatCommand = `tsx ./scripts/${agentTargetPrefix}/chat.ts`;\n\n const agentTargets = {\n ...project.targets,\n [`${agentTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${agentTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/index.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${agentTargetPrefix}-chat`]: {\n executor: 'nx:run-commands',\n options: {\n commands: [chatCommand],\n cwd: '{projectRoot}',\n env: {\n URL: chatUrl,\n },\n },\n },\n };\n\n // Aggregate `<agent>-dev` under the project-level `dev` target.\n addComponentDevTarget(agentTargets, `${agentTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(agentTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_AGENT_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n agentTargetPrefix,\n metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_AGENT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAgentGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","addAgentChatScripts","AGENT_CONNECTION_DEPENDENCIES","addTypeScriptFrameworkBase","ensureTypeScriptAgentConnectionProject","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addAgentInfra","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addArtifactDependencyToTargets","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","getRelativePathToRootByDirectory","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","DEPENDENCIES","ts","name","when","m","session","protocol","auth","dev","root","py","TS_AGENT_GENERATOR_INFO","filename","tsAgentGenerator","tree","options","project","exists","Error","defaultName","split","pop","agentNameClassName","agentTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","iac","undefined","console","warn","localSessionsDir","templateContext","agentConnectionImport","dirname","overwriteStrategy","KeepExisting","toLowerCase","containers","dockerImageTag","targetFilePath","bundleOutputDir","adotVersion","jaegerVersion","nodeBaseImage","node","dockerOutputDir","dockerTargetName","fs","targets","cache","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","infraProtocol","agentNameKebabCase","projectName","serverProtocol","localDevPortStart","localDevPort","component","info","metadata","port","rc","projectRoot","scriptsDir","language","relativeAgentImport","chatUrl","chatCommand","agentTargets","continuous","cwd","env","PORT","LOCAL_DEV","URL","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SACEC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,sCAAsC,QACjC,mDAAmD;AAC1D,SACEC,qCAAqC,EACrCC,aAAa,QACR,6DAA6D;AACpE,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA+B;AACtC,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,mBAAmB,EACnBC,iBAAiB,EACjBC,uBAAuB,EACvBC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAoB;AAChE,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC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,UAAU;YACV0B,YAAY;YACZjE,SAAS;gBACPwC,UAAU;oBAAC,CAAC,YAAY,EAAE7B,kBAAkB,SAAS,CAAC;iBAAC;gBACvDuD,KAAK;gBACLC,KAAK;oBACHC,MAAM,GAAGhB,cAAc;gBACzB;YACF;QACF;QACA,CAAC,GAAG5C,kBAAkB,IAAI,CAAC,CAAC,EAAE;YAC5B+B,UAAU;YACV0B,YAAY;YACZjE,SAAS;gBACPwC,UAAU;oBAAC,CAAC,YAAY,EAAE7B,kBAAkB,SAAS,CAAC;iBAAC;gBACvDuD,KAAK;gBACLC,KAAK;oBACHC,MAAM,GAAGhB,cAAc;oBACvBiB,WAAW;gBACb;YACF;QACF;QACA,CAAC,GAAG7D,kBAAkB,KAAK,CAAC,CAAC,EAAE;YAC7B+B,UAAU;YACVvC,SAAS;gBACPwC,UAAU;oBAACuB;iBAAY;gBACvBG,KAAK;gBACLC,KAAK;oBACHG,KAAKR;gBACP;YACF;QACF;IACF;IAEA,gEAAgE;IAChEzF,sBAAsB2F,cAAc,GAAGxD,kBAAkB,IAAI,CAAC;IAE9DjE,2BAA2BwD,MAAME,QAAQd,IAAI,EAAE;QAC7C,GAAGc,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBoC,SAAS3D,eAAesF;IAC1B;IAEA1F,8BACEyB,MACAE,QAAQd,IAAI,EACZS,yBACAa,sCACAD,mBACA+C;IAGF,MAAMxF,gCAAgCgC,MAAM;QAACH;KAAwB;IAErE,MAAMlC,qBAAqBqC;IAC3B,OAAO,IACLjC,oBAAoBiC,MAAMC,QAAQuE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe1E,iBAAiB"}
|
|
@@ -79,6 +79,11 @@ export const tsAstroDocsGenerator = async (tree, schema)=>{
|
|
|
79
79
|
const dir = joinPathFragments(schema.directory || '.', schema.subDirectory || docsNameKebabCase);
|
|
80
80
|
const alreadyExists = projectExists(tree, fullyQualifiedName);
|
|
81
81
|
const targets = {
|
|
82
|
+
// Inputs are left to Nx's implicit `["default", "^default"]`. Astro resolves
|
|
83
|
+
// imports from a dependency's source rather than its build output, and this
|
|
84
|
+
// target declares no `dependsOn` for `default`'s transitive
|
|
85
|
+
// `dependentTasksOutputFiles` to resolve against — so `^default` is the only
|
|
86
|
+
// thing keeping a dependency's content in the hash.
|
|
82
87
|
build: {
|
|
83
88
|
executor: 'nx:run-commands',
|
|
84
89
|
options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/astro-docs/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { declareDependencies } from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { toKebabCase } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport { ensureProjectPackageJson } from '../../utils/project-package-json.js';\nimport type { TsAstroDocsGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsAstroDocsMetadata {\n readonly framework: string;\n readonly includeTranslation: boolean;\n readonly includeBlog: boolean;\n}\n\n// Each entry names the branch it belongs to, so the same declaration drives both\n// adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsAstroDocsMetadata>()({\n ts: [\n { name: 'astro' },\n // Astro leaves `cookie` external in the prerender bundle, so the emitted\n // `dist` entry imports it directly. Node resolves that from `dist`, which\n // cannot reach astro's own nested copy, so the docs project declares it to\n // keep a compatible one in reach.\n { name: 'cookie' },\n { name: '@astrojs/starlight' },\n { name: 'starlight-blog', when: (m) => m.includeBlog },\n { name: '@strands-agents/sdk', when: (m) => m.includeTranslation },\n { name: 'commander', when: (m) => m.includeTranslation },\n { name: 'fast-glob', when: (m) => m.includeTranslation },\n { name: 'fs-extra', when: (m) => m.includeTranslation },\n { name: 'simple-git', when: (m) => m.includeTranslation },\n { name: '@types/fs-extra', when: (m) => m.includeTranslation, dev: true },\n // The translate target runs its script from the workspace root via tsx.\n { name: 'tsx', when: (m) => m.includeTranslation, dev: true, root: true },\n ],\n});\n\nexport const TS_ASTRO_DOCS_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAstroDocsGenerator = async (\n tree: Tree,\n schema: TsAstroDocsGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const includeTranslation = !(schema.noTranslation ?? false);\n const includeBlog = !(schema.noBlog ?? false);\n const npmScopePrefix = getNpmScopePrefix(tree);\n const docsNameKebabCase = toKebabCase(schema.name);\n const fullyQualifiedName = `${npmScopePrefix}${docsNameKebabCase}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || docsNameKebabCase,\n );\n\n const alreadyExists = projectExists(tree, fullyQualifiedName);\n\n const targets: ProjectConfiguration['targets'] = {\n build: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro build',\n cwd: dir,\n },\n outputs: [`{workspaceRoot}/${dir}/dist`],\n cache: true,\n },\n start: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro dev',\n cwd: dir,\n },\n continuous: true,\n },\n serve: {\n dependsOn: ['start'],\n },\n preview: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro preview',\n cwd: dir,\n },\n dependsOn: ['build'],\n continuous: true,\n },\n };\n\n if (includeTranslation) {\n targets['translate'] = {\n executor: 'nx:run-commands',\n options: {\n command: 'tsx ./scripts/translate.ts',\n cwd: dir,\n forwardAllArgs: true,\n },\n };\n }\n\n if (!alreadyExists) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'application',\n targets,\n });\n }\n\n ensureProjectPackageJson(tree, { dir, fullyQualifiedName });\n\n const templateOptions = {\n fullyQualifiedName,\n title: schema.name,\n includeTranslation,\n includeBlog,\n esm: isEsmWorkspace(tree),\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n today: new Date().toISOString().slice(0, 10),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'base'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // The sample blog post is always emitted above — drop it if the user opted out.\n if (!includeBlog) {\n tree.delete(\n joinPathFragments(\n dir,\n 'src',\n 'content',\n 'docs',\n 'en',\n 'blog',\n 'welcome.mdx',\n ),\n );\n }\n\n if (includeTranslation) {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'translation'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: TsAstroDocsMetadata = {\n framework: 'astro',\n includeTranslation,\n includeBlog,\n };\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n TS_ASTRO_DOCS_GENERATOR_INFO,\n metadata,\n );\n\n addTsDependencies(tree, DEPENDENCIES, { metadata, projectRoot: dir });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_ASTRO_DOCS_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAstroDocsGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","addTsDependencies","declareDependencies","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","getPackageManagerDisplayCommands","ensureProjectPackageJson","DEPENDENCIES","ts","name","when","m","includeBlog","includeTranslation","dev","root","TS_ASTRO_DOCS_GENERATOR_INFO","filename","tsAstroDocsGenerator","tree","schema","noTranslation","noBlog","npmScopePrefix","docsNameKebabCase","fullyQualifiedName","dir","directory","subDirectory","alreadyExists","targets","build","executor","options","command","cwd","outputs","cache","start","continuous","serve","dependsOn","preview","forwardAllArgs","sourceRoot","projectType","templateOptions","title","esm","pkgMgrCmd","exec","today","Date","toISOString","slice","dirname","overwriteStrategy","KeepExisting","delete","metadata","framework","projectRoot","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAGZ,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,gCAAgC,QAAQ,6BAA6B;AAC9E,SAASC,wBAAwB,QAAQ,sCAAsC;AAU/E,iFAAiF;AACjF,+BAA+B;AAC/B,OAAO,MAAMC,eAAeZ,sBAA2C;IACrEa,IAAI;QACF;YAAEC,MAAM;QAAQ;QAChB,yEAAyE;QACzE,0EAA0E;QAC1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AoB,iBACA;YAAEU,mBAAmB/D,kBAAkBgE,YAAY;QAAC;IAExD;IAEA,0EAA0E;IAC1E,8DAA8D;IAC9D,MAAME,WAAgC;QACpCC,WAAW;QACX/C;QACAD;IACF;IACAV,qBACEiB,MACAM,oBACAT,8BACA2C;IAGFjE,kBAAkByB,MAAMZ,cAAc;QAAEoD;QAAUE,aAAanC;IAAI;IAEnE,MAAM5B,gCAAgCqB,MAAM;QAACH;KAA6B;IAE1E,MAAMpB,qBAAqBuB;IAC3B,OAAO,IACLtB,oBAAoBsB,MAAMC,OAAO0C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe7C,qBAAqB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/astro-docs/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { declareDependencies } from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { toKebabCase } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport { ensureProjectPackageJson } from '../../utils/project-package-json.js';\nimport type { TsAstroDocsGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsAstroDocsMetadata {\n readonly framework: string;\n readonly includeTranslation: boolean;\n readonly includeBlog: boolean;\n}\n\n// Each entry names the branch it belongs to, so the same declaration drives both\n// adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsAstroDocsMetadata>()({\n ts: [\n { name: 'astro' },\n // Astro leaves `cookie` external in the prerender bundle, so the emitted\n // `dist` entry imports it directly. Node resolves that from `dist`, which\n // cannot reach astro's own nested copy, so the docs project declares it to\n // keep a compatible one in reach.\n { name: 'cookie' },\n { name: '@astrojs/starlight' },\n { name: 'starlight-blog', when: (m) => m.includeBlog },\n { name: '@strands-agents/sdk', when: (m) => m.includeTranslation },\n { name: 'commander', when: (m) => m.includeTranslation },\n { name: 'fast-glob', when: (m) => m.includeTranslation },\n { name: 'fs-extra', when: (m) => m.includeTranslation },\n { name: 'simple-git', when: (m) => m.includeTranslation },\n { name: '@types/fs-extra', when: (m) => m.includeTranslation, dev: true },\n // The translate target runs its script from the workspace root via tsx.\n { name: 'tsx', when: (m) => m.includeTranslation, dev: true, root: true },\n ],\n});\n\nexport const TS_ASTRO_DOCS_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsAstroDocsGenerator = async (\n tree: Tree,\n schema: TsAstroDocsGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const includeTranslation = !(schema.noTranslation ?? false);\n const includeBlog = !(schema.noBlog ?? false);\n const npmScopePrefix = getNpmScopePrefix(tree);\n const docsNameKebabCase = toKebabCase(schema.name);\n const fullyQualifiedName = `${npmScopePrefix}${docsNameKebabCase}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || docsNameKebabCase,\n );\n\n const alreadyExists = projectExists(tree, fullyQualifiedName);\n\n const targets: ProjectConfiguration['targets'] = {\n // Inputs are left to Nx's implicit `[\"default\", \"^default\"]`. Astro resolves\n // imports from a dependency's source rather than its build output, and this\n // target declares no `dependsOn` for `default`'s transitive\n // `dependentTasksOutputFiles` to resolve against — so `^default` is the only\n // thing keeping a dependency's content in the hash.\n build: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro build',\n cwd: dir,\n },\n outputs: [`{workspaceRoot}/${dir}/dist`],\n cache: true,\n },\n start: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro dev',\n cwd: dir,\n },\n continuous: true,\n },\n serve: {\n dependsOn: ['start'],\n },\n preview: {\n executor: 'nx:run-commands',\n options: {\n command: 'astro preview',\n cwd: dir,\n },\n dependsOn: ['build'],\n continuous: true,\n },\n };\n\n if (includeTranslation) {\n targets['translate'] = {\n executor: 'nx:run-commands',\n options: {\n command: 'tsx ./scripts/translate.ts',\n cwd: dir,\n forwardAllArgs: true,\n },\n };\n }\n\n if (!alreadyExists) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'application',\n targets,\n });\n }\n\n ensureProjectPackageJson(tree, { dir, fullyQualifiedName });\n\n const templateOptions = {\n fullyQualifiedName,\n title: schema.name,\n includeTranslation,\n includeBlog,\n esm: isEsmWorkspace(tree),\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n today: new Date().toISOString().slice(0, 10),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'base'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // The sample blog post is always emitted above — drop it if the user opted out.\n if (!includeBlog) {\n tree.delete(\n joinPathFragments(\n dir,\n 'src',\n 'content',\n 'docs',\n 'en',\n 'blog',\n 'welcome.mdx',\n ),\n );\n }\n\n if (includeTranslation) {\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'translation'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n }\n\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: TsAstroDocsMetadata = {\n framework: 'astro',\n includeTranslation,\n includeBlog,\n };\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n TS_ASTRO_DOCS_GENERATOR_INFO,\n metadata,\n );\n\n addTsDependencies(tree, DEPENDENCIES, { metadata, projectRoot: dir });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_ASTRO_DOCS_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsAstroDocsGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","addTsDependencies","declareDependencies","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","getPackageManagerDisplayCommands","ensureProjectPackageJson","DEPENDENCIES","ts","name","when","m","includeBlog","includeTranslation","dev","root","TS_ASTRO_DOCS_GENERATOR_INFO","filename","tsAstroDocsGenerator","tree","schema","noTranslation","noBlog","npmScopePrefix","docsNameKebabCase","fullyQualifiedName","dir","directory","subDirectory","alreadyExists","targets","build","executor","options","command","cwd","outputs","cache","start","continuous","serve","dependsOn","preview","forwardAllArgs","sourceRoot","projectType","templateOptions","title","esm","pkgMgrCmd","exec","today","Date","toISOString","slice","dirname","overwriteStrategy","KeepExisting","delete","metadata","framework","projectRoot","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAGZ,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,iBAAiB,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OAAOC,WAAW,GAAGC,KAAK,CAAC,GAAG;IAC3C;IAEA/D,cACE4B,MACA3B,kBAAkB,YAAY+D,OAAO,EAAE,SAAS,SAChD7B,KACAoB,iBACA;QAAEU,mBAAmB/D,kBAAkBgE,YAAY;IAAC;IAGtD,gFAAgF;IAChF,IAAI,CAAC7C,aAAa;QAChBO,KAAKuC,MAAM,CACTlE,kBACEkC,KACA,OACA,WACA,QACA,MACA,QACA;IAGN;IAEA,IAAIb,oBAAoB;QACtBtB,cACE4B,MACA3B,kBAAkB,YAAY+D,OAAO,EAAE,SAAS,gBAChD7B,KACAoB,iBACA;YAAEU,mBAAmB/D,kBAAkBgE,YAAY;QAAC;IAExD;IAEA,0EAA0E;IAC1E,8DAA8D;IAC9D,MAAME,WAAgC;QACpCC,WAAW;QACX/C;QACAD;IACF;IACAV,qBACEiB,MACAM,oBACAT,8BACA2C;IAGFjE,kBAAkByB,MAAMZ,cAAc;QAAEoD;QAAUE,aAAanC;IAAI;IAEnE,MAAM5B,gCAAgCqB,MAAM;QAACH;KAA6B;IAE1E,MAAMpB,qBAAqBuB;IAC3B,OAAO,IACLtB,oBAAoBsB,MAAMC,OAAO0C,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe7C,qBAAqB"}
|
|
@@ -591,27 +591,12 @@ const isRunning = (): boolean => {
|
|
|
591
591
|
return result.status === 0 && result.stdout.trim() === 'true';
|
|
592
592
|
};
|
|
593
593
|
|
|
594
|
-
// Ensure the image is available locally before starting the container.
|
|
595
|
-
const ensureImage = (): void => {
|
|
596
|
-
const inspect = spawnSync(containerEngine, ['image', 'inspect', image], {
|
|
597
|
-
stdio: 'ignore',
|
|
598
|
-
});
|
|
599
|
-
if (inspect.status !== 0) {
|
|
600
|
-
const pull = spawnSync(containerEngine, ['pull', image], {
|
|
601
|
-
stdio: 'inherit',
|
|
602
|
-
});
|
|
603
|
-
if (pull.status !== 0) process.exit(pull.status ?? 1);
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
|
|
607
594
|
// Multiple dynamo table packages run dev in parallel sharing the same
|
|
608
595
|
// container. All processes stream logs, but only the one that created the
|
|
609
596
|
// container stops it on exit — others just detach.
|
|
610
597
|
let created = false;
|
|
611
598
|
let runRetries = 0;
|
|
612
599
|
|
|
613
|
-
ensureImage();
|
|
614
|
-
|
|
615
600
|
for (;;) {
|
|
616
601
|
if (containerExists()) {
|
|
617
602
|
if (!isRunning()) {
|
|
@@ -1259,27 +1244,12 @@ const isRunning = (): boolean => {
|
|
|
1259
1244
|
return result.status === 0 && result.stdout.trim() === 'true';
|
|
1260
1245
|
};
|
|
1261
1246
|
|
|
1262
|
-
// Ensure the image is available locally before starting the container.
|
|
1263
|
-
const ensureImage = (): void => {
|
|
1264
|
-
const inspect = spawnSync(containerEngine, ['image', 'inspect', image], {
|
|
1265
|
-
stdio: 'ignore',
|
|
1266
|
-
});
|
|
1267
|
-
if (inspect.status !== 0) {
|
|
1268
|
-
const pull = spawnSync(containerEngine, ['pull', image], {
|
|
1269
|
-
stdio: 'inherit',
|
|
1270
|
-
});
|
|
1271
|
-
if (pull.status !== 0) process.exit(pull.status ?? 1);
|
|
1272
|
-
}
|
|
1273
|
-
};
|
|
1274
|
-
|
|
1275
1247
|
// Multiple dynamo table packages run dev in parallel sharing the same
|
|
1276
1248
|
// container. All processes stream logs, but only the one that created the
|
|
1277
1249
|
// container stops it on exit — others just detach.
|
|
1278
1250
|
let created = false;
|
|
1279
1251
|
let runRetries = 0;
|
|
1280
1252
|
|
|
1281
|
-
ensureImage();
|
|
1282
|
-
|
|
1283
1253
|
for (;;) {
|
|
1284
1254
|
if (containerExists()) {
|
|
1285
1255
|
if (!isRunning()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/dynamodb/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { relative } from 'node:path';\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n readProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport { addDynamoDBInfra } from '../../utils/dynamodb-constructs/dynamodb-constructs.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx.js';\nimport { assignSharedPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport {\n DYNAMODB_GENERATOR_IDS,\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants.js';\nimport {\n SHARED_DYNAMODB_SCRIPTS_DEPENDENCIES,\n sharedDynamoDBScriptsGenerator,\n} from '../../utils/shared-dynamodb-scripts.js';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator.js';\nimport type { TsDynamoDBGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: '@aws-sdk/client-dynamodb' },\n { name: 'electrodb' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@types/aws-lambda', dev: true },\n { name: '@types/node', dev: true },\n // tsx runs the local-dev scripts from the workspace root.\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_DYNAMODB_SCRIPTS_DEPENDENCIES),\n ],\n});\n\nexport const TS_DYNAMODB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsDynamoDBGenerator = async (\n tree: Tree,\n options: TsDynamoDBGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(options.name);\n const localTableName = `${getNpmScope(tree)}-${kebabCase(options.tableName ?? options.name)}`;\n const containerEngine = await resolveContainers(tree, 'inherit');\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n });\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n\n const localDynamoDBPort = assignSharedPort(\n tree,\n projectConfig,\n DYNAMODB_GENERATOR_IDS,\n 8000,\n );\n\n const containerName = `${getNpmScope(tree)}-dynamodb`;\n\n const templateOptions = {\n runtimeConfigKey: nameClassName,\n localDynamoDBPort,\n localTableName,\n containerName,\n containerEngine,\n ...esmVars(tree),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n );\n\n await sharedDynamoDBScriptsGenerator(tree, DEPENDENCIES);\n\n const scriptsDir = relative(\n dir,\n joinPathFragments(PACKAGES_DIR, SHARED_SCRIPTS_DIR, 'src', 'dynamodb'),\n );\n\n projectConfig.targets['pull-image'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/pull-image.ts`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['dev'] = {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `tsx ${scriptsDir}/start-container.ts`,\n `tsx ${scriptsDir}/create-local-table.ts`,\n ],\n parallel: true,\n cwd: '{projectRoot}',\n },\n };\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n // Recorded so the version sync can tell a CDK project from a Terraform one;\n // undefined when no infrastructure was generated.\n const iac =\n options.infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n TS_DYNAMODB_GENERATOR_INFO,\n iac ? { iac } : {},\n );\n\n if (options.infra !== 'none') {\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n await addDynamoDBInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n nameClassName,\n nameKebabCase,\n tableName: localTableName,\n projectRoot: dir,\n });\n }\n\n addTsDependencies(tree, DEPENDENCIES, { projectRoot: dir });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_DYNAMODB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsDynamoDBGenerator;\n"],"names":["relative","generateFiles","joinPathFragments","readProjectConfiguration","updateProjectConfiguration","addTsDependencies","resolveContainers","declareDependencies","ownedElsewhere","addDynamoDBInfra","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addGeneratorMetadata","getGeneratorInfo","assignSharedPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DYNAMODB_GENERATOR_IDS","PACKAGES_DIR","SHARED_SCRIPTS_DIR","SHARED_DYNAMODB_SCRIPTS_DEPENDENCIES","sharedDynamoDBScriptsGenerator","tsProjectGenerator","getTsLibDetails","DEPENDENCIES","ts","name","dev","root","TS_DYNAMODB_GENERATOR_INFO","filename","tsDynamoDBGenerator","tree","options","nameKebabCase","nameClassName","localTableName","tableName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","projectConfig","localDynamoDBPort","containerName","templateOptions","runtimeConfigKey","dirname","scriptsDir","targets","executor","command","cwd","continuous","commands","parallel","iac","infra","undefined","projectName","projectRoot","languages"],"mappings":"AAAA;;;CAGC,GAED,SAASA,QAAQ,QAAQ,YAAY;AACrC,SAEEC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EAExBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,gBAAgB,QAAQ,yDAAyD;AAC1F,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAuB;AAC9D,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SACEC,oBAAoB,EACpBC,gBAAgB,QAEX,oBAAoB;AAC3B,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAmC;AAC1C,SACEC,sBAAsB,EACtBC,YAAY,EACZC,kBAAkB,QACb,6CAA6C;AACpD,SACEC,oCAAoC,EACpCC,8BAA8B,QACzB,yCAAyC;AAChD,OAAOC,sBAAsBC,eAAe,QAAQ,sBAAsB;AAG1E,OAAO,MAAMC,eAAevB,sBAAsB;IAChDwB,IAAI;QACF;YAAEC,MAAM;QAA2B;QACnC;YAAEA,MAAM;QAAY;QACpB;YAAEA,MAAM;QAAoC;QAC5C;YAAEA,MAAM;QAAgC;QACxC;YAAEA,MAAM;YAAqBC,KAAK;QAAK;QACvC;YAAED,MAAM;YAAeC,KAAK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\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { relative } from 'node:path';\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n readProjectConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport { addDynamoDBInfra } from '../../utils/dynamodb-constructs/dynamodb-constructs.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx.js';\nimport { assignSharedPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport {\n DYNAMODB_GENERATOR_IDS,\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants.js';\nimport {\n SHARED_DYNAMODB_SCRIPTS_DEPENDENCIES,\n sharedDynamoDBScriptsGenerator,\n} from '../../utils/shared-dynamodb-scripts.js';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator.js';\nimport type { TsDynamoDBGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: '@aws-sdk/client-dynamodb' },\n { name: 'electrodb' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@types/aws-lambda', dev: true },\n { name: '@types/node', dev: true },\n // tsx runs the local-dev scripts from the workspace root.\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_DYNAMODB_SCRIPTS_DEPENDENCIES),\n ],\n});\n\nexport const TS_DYNAMODB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsDynamoDBGenerator = async (\n tree: Tree,\n options: TsDynamoDBGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(options.name);\n const localTableName = `${getNpmScope(tree)}-${kebabCase(options.tableName ?? options.name)}`;\n const containerEngine = await resolveContainers(tree, 'inherit');\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n });\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n\n const localDynamoDBPort = assignSharedPort(\n tree,\n projectConfig,\n DYNAMODB_GENERATOR_IDS,\n 8000,\n );\n\n const containerName = `${getNpmScope(tree)}-dynamodb`;\n\n const templateOptions = {\n runtimeConfigKey: nameClassName,\n localDynamoDBPort,\n localTableName,\n containerName,\n containerEngine,\n ...esmVars(tree),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n );\n\n await sharedDynamoDBScriptsGenerator(tree, DEPENDENCIES);\n\n const scriptsDir = relative(\n dir,\n joinPathFragments(PACKAGES_DIR, SHARED_SCRIPTS_DIR, 'src', 'dynamodb'),\n );\n\n projectConfig.targets['pull-image'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/pull-image.ts`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['dev'] = {\n executor: 'nx:run-commands',\n dependsOn: ['pull-image'],\n continuous: true,\n options: {\n commands: [\n `tsx ${scriptsDir}/start-container.ts`,\n `tsx ${scriptsDir}/create-local-table.ts`,\n ],\n parallel: true,\n cwd: '{projectRoot}',\n },\n };\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n // Recorded so the version sync can tell a CDK project from a Terraform one;\n // undefined when no infrastructure was generated.\n const iac =\n options.infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n TS_DYNAMODB_GENERATOR_INFO,\n iac ? { iac } : {},\n );\n\n if (options.infra !== 'none') {\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n await addDynamoDBInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n nameClassName,\n nameKebabCase,\n tableName: localTableName,\n projectRoot: dir,\n });\n }\n\n addTsDependencies(tree, DEPENDENCIES, { projectRoot: dir });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_DYNAMODB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsDynamoDBGenerator;\n"],"names":["relative","generateFiles","joinPathFragments","readProjectConfiguration","updateProjectConfiguration","addTsDependencies","resolveContainers","declareDependencies","ownedElsewhere","addDynamoDBInfra","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","toClassName","getNpmScope","addGeneratorMetadata","getGeneratorInfo","assignSharedPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DYNAMODB_GENERATOR_IDS","PACKAGES_DIR","SHARED_SCRIPTS_DIR","SHARED_DYNAMODB_SCRIPTS_DEPENDENCIES","sharedDynamoDBScriptsGenerator","tsProjectGenerator","getTsLibDetails","DEPENDENCIES","ts","name","dev","root","TS_DYNAMODB_GENERATOR_INFO","filename","tsDynamoDBGenerator","tree","options","nameKebabCase","nameClassName","localTableName","tableName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","projectConfig","localDynamoDBPort","containerName","templateOptions","runtimeConfigKey","dirname","scriptsDir","targets","executor","command","cwd","dependsOn","continuous","commands","parallel","iac","infra","undefined","projectName","projectRoot","languages"],"mappings":"AAAA;;;CAGC,GAED,SAASA,QAAQ,QAAQ,YAAY;AACrC,SAEEC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EAExBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,gBAAgB,QAAQ,yDAAyD;AAC1F,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAuB;AAC9D,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SACEC,oBAAoB,EACpBC,gBAAgB,QAEX,oBAAoB;AAC3B,SAASC,gBAAgB,QAAQ,sBAAsB;AACvD,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAmC;AAC1C,SACEC,sBAAsB,EACtBC,YAAY,EACZC,kBAAkB,QACb,6CAA6C;AACpD,SACEC,oCAAoC,EACpCC,8BAA8B,QACzB,yCAAyC;AAChD,OAAOC,sBAAsBC,eAAe,QAAQ,sBAAsB;AAG1E,OAAO,MAAMC,eAAevB,sBAAsB;IAChDwB,IAAI;QACF;YAAEC,MAAM;QAA2B;QACnC;YAAEA,MAAM;QAAY;QACpB;YAAEA,MAAM;QAAoC;QAC5C;YAAEA,M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,EAAE;AAEF,eAAelC,oBAAoB"}
|
|
@@ -59,7 +59,7 @@ exports[`ts lib generator > should configure named inputs in nx.json 1`] = `
|
|
|
59
59
|
"biome": ["default", "{workspaceRoot}/biome.json"],
|
|
60
60
|
"default": [
|
|
61
61
|
{
|
|
62
|
-
"dependentTasksOutputFiles": "
|
|
62
|
+
"dependentTasksOutputFiles": "!{reports,coverage}/**",
|
|
63
63
|
"transitive": true
|
|
64
64
|
}
|
|
65
65
|
]
|
|
@@ -84,6 +84,9 @@ exports[`ts lib generator > should generate library with custom directory > cust
|
|
|
84
84
|
"generator": "ts#project"
|
|
85
85
|
},
|
|
86
86
|
"targets": {
|
|
87
|
+
"assemble": {
|
|
88
|
+
"dependsOn": ["compile"]
|
|
89
|
+
},
|
|
87
90
|
"build": {
|
|
88
91
|
"dependsOn": ["lint", "compile", "test"]
|
|
89
92
|
},
|
|
@@ -169,6 +172,9 @@ exports[`ts lib generator > should generate library with default options > proje
|
|
|
169
172
|
"generator": "ts#project"
|
|
170
173
|
},
|
|
171
174
|
"targets": {
|
|
175
|
+
"assemble": {
|
|
176
|
+
"dependsOn": ["compile"]
|
|
177
|
+
},
|
|
172
178
|
"build": {
|
|
173
179
|
"dependsOn": ["lint", "compile", "test"]
|
|
174
180
|
},
|
|
@@ -252,6 +258,9 @@ exports[`ts lib generator > should generate library with subdirectory > subdir-p
|
|
|
252
258
|
"generator": "ts#project"
|
|
253
259
|
},
|
|
254
260
|
"targets": {
|
|
261
|
+
"assemble": {
|
|
262
|
+
"dependsOn": ["compile"]
|
|
263
|
+
},
|
|
255
264
|
"build": {
|
|
256
265
|
"dependsOn": ["lint", "compile", "test"]
|
|
257
266
|
},
|
|
@@ -15,7 +15,7 @@ export default defineConfig(() => ({
|
|
|
15
15
|
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
16
16
|
reporters: ['default'],
|
|
17
17
|
coverage: {
|
|
18
|
-
reportsDirectory: '
|
|
18
|
+
reportsDirectory: '../dist/test/test-output/vitest/coverage',
|
|
19
19
|
provider: 'v8' as const,
|
|
20
20
|
},
|
|
21
21
|
},
|
|
@@ -13,6 +13,22 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies.js"
|
|
|
13
13
|
readonly name: "@vitest/coverage-v8";
|
|
14
14
|
}], readonly import("../../utils/declared-dependencies.js").DeclaredPyDependency<"a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "ruff" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
|
|
15
15
|
export declare const TS_LIB_GENERATOR_INFO: NxGeneratorInfo;
|
|
16
|
+
/**
|
|
17
|
+
* Consumes build artifacts produced by a project's dependencies, so a task
|
|
18
|
+
* re-runs when the output it actually reads changes.
|
|
19
|
+
*
|
|
20
|
+
* Test reports are excluded rather than build artifacts included: several
|
|
21
|
+
* generators emit generated sources outside `dist` (an OpenAPI client under a
|
|
22
|
+
* website's `src/generated`, a Smithy SSDK, the Prisma client) and add them to
|
|
23
|
+
* `.gitignore`, which keeps them out of the project's own fileset — so this
|
|
24
|
+
* input is the only thing that hashes them. `reports/` and `coverage/` hold
|
|
25
|
+
* pytest's JUnit and coverage XML, which carry a wall-clock timestamp and so
|
|
26
|
+
* mint a fresh hash on every test run that would cascade through the graph.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEPENDENT_TASKS_OUTPUT_FILES_INPUT: {
|
|
29
|
+
dependentTasksOutputFiles: string;
|
|
30
|
+
transitive: boolean;
|
|
31
|
+
};
|
|
16
32
|
export interface TsLibDetails {
|
|
17
33
|
/**
|
|
18
34
|
* Full package name including scope (eg @foo/bar)
|
package/src/ts/lib/generator.js
CHANGED
|
@@ -21,6 +21,29 @@ export const DEPENDENCIES = declareDependencies()({
|
|
|
21
21
|
]
|
|
22
22
|
});
|
|
23
23
|
export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
24
|
+
/**
|
|
25
|
+
* Consumes build artifacts produced by a project's dependencies, so a task
|
|
26
|
+
* re-runs when the output it actually reads changes.
|
|
27
|
+
*
|
|
28
|
+
* Test reports are excluded rather than build artifacts included: several
|
|
29
|
+
* generators emit generated sources outside `dist` (an OpenAPI client under a
|
|
30
|
+
* website's `src/generated`, a Smithy SSDK, the Prisma client) and add them to
|
|
31
|
+
* `.gitignore`, which keeps them out of the project's own fileset — so this
|
|
32
|
+
* input is the only thing that hashes them. `reports/` and `coverage/` hold
|
|
33
|
+
* pytest's JUnit and coverage XML, which carry a wall-clock timestamp and so
|
|
34
|
+
* mint a fresh hash on every test run that would cascade through the graph.
|
|
35
|
+
*/ export const DEPENDENT_TASKS_OUTPUT_FILES_INPUT = {
|
|
36
|
+
dependentTasksOutputFiles: '!{reports,coverage}/**',
|
|
37
|
+
transitive: true
|
|
38
|
+
};
|
|
39
|
+
// Globs this generator has vended for the dependent-task-output input. Any of
|
|
40
|
+
// them is replaced in place, so the entry is neither duplicated nor left at a
|
|
41
|
+
// different scope when a generator re-runs.
|
|
42
|
+
const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [
|
|
43
|
+
'**/*',
|
|
44
|
+
'dist/**',
|
|
45
|
+
DEPENDENT_TASKS_OUTPUT_FILES_INPUT.dependentTasksOutputFiles
|
|
46
|
+
];
|
|
24
47
|
/**
|
|
25
48
|
* Returns details about the TS library to be created
|
|
26
49
|
*/ export const getTsLibDetails = (tree, schema)=>{
|
|
@@ -90,6 +113,12 @@ export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
90
113
|
'test'
|
|
91
114
|
]
|
|
92
115
|
};
|
|
116
|
+
// The artifact-only sibling of build, which the deploy targets depend on.
|
|
117
|
+
targets['assemble'] = {
|
|
118
|
+
dependsOn: [
|
|
119
|
+
'compile'
|
|
120
|
+
]
|
|
121
|
+
};
|
|
93
122
|
projectConfiguration.targets = sortObjectKeys(targets);
|
|
94
123
|
updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);
|
|
95
124
|
addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);
|
|
@@ -97,11 +126,8 @@ export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
97
126
|
nxJson.namedInputs = {
|
|
98
127
|
...nxJson.namedInputs,
|
|
99
128
|
default: [
|
|
100
|
-
...(nxJson.namedInputs?.default ?? []).filter((input)=>typeof input !== 'object' || !('dependentTasksOutputFiles' in input) || !(input.dependentTasksOutputFiles
|
|
101
|
-
|
|
102
|
-
dependentTasksOutputFiles: '**/*',
|
|
103
|
-
transitive: true
|
|
104
|
-
}
|
|
129
|
+
...(nxJson.namedInputs?.default ?? []).filter((input)=>typeof input !== 'object' || !('dependentTasksOutputFiles' in input) || !(VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS.includes(input.dependentTasksOutputFiles) && input.transitive)),
|
|
130
|
+
DEPENDENT_TASKS_OUTPUT_FILES_INPUT
|
|
105
131
|
]
|
|
106
132
|
};
|
|
107
133
|
const withDefaultInput = (base)=>({
|