@aws/nx-plugin 1.0.0-rc.95 → 1.0.0-rc.97
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/LICENSE-THIRD-PARTY +234 -38
- package/migrations.json +65 -2
- package/package.json +6 -6
- package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/agentcore-gateway/generator.js +6 -0
- package/src/agentcore-gateway/generator.js.map +1 -1
- package/src/agentcore-gateway/react-connection/__snapshots__/generator.spec.ts.snap +4 -1
- package/src/agentcore-harness/__snapshots__/generator.spec.ts.snap +68 -4
- package/src/agentcore-harness/generator.js +6 -0
- package/src/agentcore-harness/generator.js.map +1 -1
- package/src/connection/gateway-runtime-config.js +1 -1
- package/src/connection/gateway-runtime-config.js.map +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +10 -16
- package/src/infra/app/generator.js +34 -7
- package/src/infra/app/generator.js.map +1 -1
- package/src/init/generator.d.ts +1 -1
- package/src/init/generator.js +8 -6
- package/src/init/generator.js.map +1 -1
- package/src/init/schema.d.js.map +1 -1
- package/src/init/schema.d.ts +1 -0
- package/src/init/schema.json +5 -0
- package/src/mcp-server/server.js +2 -0
- package/src/mcp-server/server.js.map +1 -1
- package/src/mcp-server/tools/best-practices.d.ts +28 -0
- package/src/mcp-server/tools/best-practices.js +43 -0
- package/src/mcp-server/tools/best-practices.js.map +1 -0
- package/src/mcp-server/tools/general-guidance.d.ts +1 -1
- package/src/mcp-server/tools/general-guidance.js +13 -4
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/migrations/latest/checkov-scan-cache-inputs/metadata.json +3 -0
- package/src/migrations/latest/checkov-scan-cache-inputs/migration.d.ts +6 -0
- package/src/migrations/latest/checkov-scan-cache-inputs/migration.js +58 -0
- package/src/migrations/latest/checkov-scan-cache-inputs/migration.js.map +1 -0
- package/src/migrations/latest/gateway-url-accessor/__snapshots__/migration.spec.ts.snap +84 -0
- package/src/migrations/latest/gateway-url-accessor/metadata.json +3 -0
- package/src/migrations/latest/gateway-url-accessor/migration.d.ts +6 -0
- package/src/migrations/latest/gateway-url-accessor/migration.js +94 -0
- package/src/migrations/latest/gateway-url-accessor/migration.js.map +1 -0
- package/src/migrations/latest/infra-deploy-express-mode/metadata.json +1 -1
- package/src/migrations/latest/infra-deploy-express-mode/migration.js +26 -28
- package/src/migrations/latest/infra-deploy-express-mode/migration.js.map +1 -1
- package/src/migrations/latest/py-lambda-powertools-context/metadata.json +3 -0
- package/src/migrations/latest/py-lambda-powertools-context/migration.d.ts +6 -0
- package/src/migrations/latest/py-lambda-powertools-context/migration.js +58 -0
- package/src/migrations/latest/py-lambda-powertools-context/migration.js.map +1 -0
- package/src/migrations/latest/script-project-quality-gates/metadata.json +3 -0
- package/src/migrations/latest/script-project-quality-gates/migration.d.ts +6 -0
- package/src/migrations/latest/script-project-quality-gates/migration.js +53 -0
- package/src/migrations/latest/script-project-quality-gates/migration.js.map +1 -0
- package/src/migrations/latest/smithy-extension-trait-aliases/__snapshots__/migration.spec.ts.snap +25 -0
- package/src/migrations/latest/smithy-extension-trait-aliases/metadata.json +3 -0
- package/src/migrations/latest/smithy-extension-trait-aliases/migration.d.ts +28 -0
- package/src/migrations/latest/smithy-extension-trait-aliases/migration.js +75 -0
- package/src/migrations/latest/smithy-extension-trait-aliases/migration.js.map +1 -0
- package/src/migrations/latest/terraform-validate-without-backend/metadata.json +3 -0
- package/src/migrations/latest/terraform-validate-without-backend/migration.d.ts +6 -0
- package/src/migrations/latest/terraform-validate-without-backend/migration.js +84 -0
- package/src/migrations/latest/terraform-validate-without-backend/migration.js.map +1 -0
- package/src/preset/__snapshots__/generator.spec.ts.snap +3 -5
- package/src/preset/generator.js +4 -25
- package/src/preset/generator.js.map +1 -1
- package/src/py/agent/a2a-connection/generator.d.ts +1 -1
- package/src/py/agent/gateway-connection/generator.d.ts +1 -1
- package/src/py/agent/mcp-connection/generator.d.ts +1 -1
- package/src/py/agent/react-connection/__snapshots__/generator.spec.ts.snap +4 -1
- package/src/py/agent/react-connection/generator.d.ts +29 -0
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +8 -10
- package/src/py/dynamodb/generator.js +34 -7
- package/src/py/dynamodb/generator.js.map +1 -1
- package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -1
- package/src/py/lambda-function/files/handler/__lambdaFunctionSnakeCase__.py.template +2 -1
- package/src/py/project/schema.json +3 -1
- package/src/py/rdb/__snapshots__/generator.spec.ts.snap +28 -12
- package/src/py/rdb/files/Dockerfile.create-db-user.template +7 -3
- package/src/py/rdb/files/Dockerfile.migration.template +7 -3
- package/src/py/rdb/generator.js +29 -28
- package/src/py/rdb/generator.js.map +1 -1
- package/src/smithy/react-connection/files/model/extensions.smithy.template +3 -3
- package/src/smithy/ts/api/generator.js +7 -2
- package/src/smithy/ts/api/generator.js.map +1 -1
- package/src/terraform/project/generator.js +34 -10
- package/src/terraform/project/generator.js.map +1 -1
- package/src/trpc/backend/generator.js +7 -1
- package/src/trpc/backend/generator.js.map +1 -1
- package/src/trpc/react/generator.js +6 -0
- package/src/trpc/react/generator.js.map +1 -1
- package/src/ts/agent/generator.js +3 -3
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/agent/react-connection/generator.d.ts +37 -0
- package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/ts/dynamodb/generator.js +30 -6
- package/src/ts/dynamodb/generator.js.map +1 -1
- package/src/ts/lib/biome.d.ts +15 -1
- package/src/ts/lib/biome.js +79 -63
- package/src/ts/lib/biome.js.map +1 -1
- package/src/ts/lib/generator.d.ts +13 -0
- package/src/ts/lib/generator.js +14 -9
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.d.ts +31 -1
- package/src/ts/lib/ts-project-utils.js +53 -0
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/lib/vitest.d.ts +6 -0
- package/src/ts/lib/vitest.js +16 -1
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/generator.js +3 -3
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +5 -0
- package/src/ts/rdb/files/Dockerfile.template +5 -0
- package/src/ts/rdb/generator.d.ts +8 -0
- package/src/ts/rdb/generator.js +28 -24
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +39 -0
- package/src/ts/rdb/trpc-connection/generator.js +13 -0
- package/src/ts/rdb/trpc-connection/generator.js.map +1 -1
- package/src/ts/react-website/agui/files/common/src/components/__agentNameKebabCase__-chat.tsx.template +9 -0
- package/src/ts/react-website/agui/files/common/src/hooks/useAgui__agentNameClassName__.tsx.template +4 -1
- package/src/ts/react-website/agui/generator.d.ts +21 -0
- package/src/ts/react-website/agui/generator.js +6 -2
- package/src/ts/react-website/agui/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +26 -22
- package/src/ts/react-website/app/generator.d.ts +42 -0
- package/src/ts/react-website/app/generator.js +4 -8
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/utils/agent-connection/agent-connection.d.ts +2 -1
- package/src/utils/agent-connection/agent-connection.js +6 -1
- package/src/utils/agent-connection/agent-connection.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +11 -7
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +14 -6
- package/src/utils/agent-core-packaging.js +5 -5
- package/src/utils/agent-core-packaging.js.map +1 -1
- package/src/utils/api-constructs/api-constructs.d.ts +5 -0
- package/src/utils/api-constructs/api-constructs.js +8 -0
- package/src/utils/api-constructs/api-constructs.js.map +1 -1
- package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +4 -2
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +4 -2
- package/src/utils/ast.d.ts +10 -0
- package/src/utils/ast.js +33 -0
- package/src/utils/ast.js.map +1 -1
- package/src/utils/dependencies.js +1 -10
- package/src/utils/dependencies.js.map +1 -1
- package/src/utils/docker.d.ts +11 -0
- package/src/utils/docker.js +16 -3
- package/src/utils/docker.js.map +1 -1
- package/src/utils/dynamodb-config.d.ts +48 -0
- package/src/utils/dynamodb-config.js +44 -0
- package/src/utils/dynamodb-config.js.map +1 -0
- package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +8 -4
- package/src/utils/git-secrets.d.ts +28 -0
- package/src/utils/git-secrets.js +66 -0
- package/src/utils/git-secrets.js.map +1 -0
- package/src/utils/init.js +7 -6
- package/src/utils/init.js.map +1 -1
- package/src/utils/local-project-dependency.d.ts +28 -0
- package/src/utils/local-project-dependency.js +40 -0
- package/src/utils/local-project-dependency.js.map +1 -0
- package/src/utils/nx.d.ts +14 -0
- package/src/utils/nx.js +30 -0
- package/src/utils/nx.js.map +1 -1
- package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +11 -6
- package/src/utils/script-project-targets.d.ts +26 -0
- package/src/utils/script-project-targets.js +75 -0
- package/src/utils/script-project-targets.js.map +1 -0
- package/src/utils/shared-shadcn.d.ts +13 -0
- package/src/utils/shared-shadcn.js +3 -2
- package/src/utils/shared-shadcn.js.map +1 -1
- package/src/utils/test.js +15 -0
- package/src/utils/test.js.map +1 -1
- package/src/utils/version-upgrade-migration/sync-vended-versions.js +4 -4
- package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -1
- package/src/utils/versions.d.ts +13 -9
- package/src/utils/versions.js +17 -8
- package/src/utils/versions.js.map +1 -1
- package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +8 -4
- package/src/py/dynamodb/files/__name__/__init__.py.template +0 -6
- package/src/py/dynamodb/files/__name__/entities/__init__.py.template +0 -4
- package/src/py/dynamodb/files/config.json.template +0 -24
- package/src/ts/dynamodb/files/config.json.template +0 -24
- package/src/ts/dynamodb/files/src/entities/index.ts.template +0 -1
- package/src/ts/dynamodb/files/src/index.ts.template +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
|
-
exports[`agentcore-harness generator > snapshot > snapshots the
|
|
3
|
+
exports[`agentcore-harness generator > snapshot > snapshots the rendered harness project files > packages/my-harness/README.md 1`] = `
|
|
4
4
|
"# @proj/my-harness
|
|
5
5
|
|
|
6
6
|
An [Amazon Bedrock AgentCore Harness](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/harness.html)
|
|
@@ -86,7 +86,7 @@ files and to \`src/PROMPT.md\` are preserved.
|
|
|
86
86
|
"
|
|
87
87
|
`;
|
|
88
88
|
|
|
89
|
-
exports[`agentcore-harness generator > snapshot > snapshots the
|
|
89
|
+
exports[`agentcore-harness generator > snapshot > snapshots the rendered harness project files > packages/my-harness/project.json 1`] = `
|
|
90
90
|
"{
|
|
91
91
|
"name": "@proj/my-harness",
|
|
92
92
|
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
@@ -101,19 +101,64 @@ exports[`agentcore-harness generator > snapshot > snapshots the four rendered ha
|
|
|
101
101
|
"iac": "cdk"
|
|
102
102
|
},
|
|
103
103
|
"targets": {
|
|
104
|
+
"build": {
|
|
105
|
+
"dependsOn": ["lint", "typecheck"]
|
|
106
|
+
},
|
|
104
107
|
"chat": {
|
|
105
108
|
"executor": "nx:run-commands",
|
|
106
109
|
"options": {
|
|
107
110
|
"commands": ["tsx ./scripts/chat.ts"],
|
|
108
111
|
"cwd": "{projectRoot}"
|
|
109
112
|
}
|
|
113
|
+
},
|
|
114
|
+
"format": {
|
|
115
|
+
"executor": "nx:run-commands",
|
|
116
|
+
"cache": true,
|
|
117
|
+
"inputs": ["biome"],
|
|
118
|
+
"options": {
|
|
119
|
+
"command": "biome format {projectRoot}"
|
|
120
|
+
},
|
|
121
|
+
"configurations": {
|
|
122
|
+
"fix": {
|
|
123
|
+
"command": "biome format --write {projectRoot}"
|
|
124
|
+
},
|
|
125
|
+
"skip-lint": {
|
|
126
|
+
"command": "node -e \\"\\""
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"lint": {
|
|
131
|
+
"executor": "nx:run-commands",
|
|
132
|
+
"cache": true,
|
|
133
|
+
"inputs": ["biome"],
|
|
134
|
+
"dependsOn": ["format"],
|
|
135
|
+
"options": {
|
|
136
|
+
"command": "biome lint {projectRoot}"
|
|
137
|
+
},
|
|
138
|
+
"configurations": {
|
|
139
|
+
"fix": {
|
|
140
|
+
"command": "biome check --write {projectRoot}"
|
|
141
|
+
},
|
|
142
|
+
"skip-lint": {
|
|
143
|
+
"command": "node -e \\"\\""
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"typecheck": {
|
|
148
|
+
"executor": "nx:run-commands",
|
|
149
|
+
"cache": true,
|
|
150
|
+
"inputs": ["default", "^default"],
|
|
151
|
+
"options": {
|
|
152
|
+
"command": "tsc --noEmit -p tsconfig.json",
|
|
153
|
+
"cwd": "{projectRoot}"
|
|
154
|
+
}
|
|
110
155
|
}
|
|
111
156
|
}
|
|
112
157
|
}
|
|
113
158
|
"
|
|
114
159
|
`;
|
|
115
160
|
|
|
116
|
-
exports[`agentcore-harness generator > snapshot > snapshots the
|
|
161
|
+
exports[`agentcore-harness generator > snapshot > snapshots the rendered harness project files > packages/my-harness/scripts/chat.ts 1`] = `
|
|
117
162
|
"// Chat CLI for MyHarness. Invokes the deployed Harness with InvokeHarness.
|
|
118
163
|
import { randomUUID } from 'node:crypto';
|
|
119
164
|
import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
|
|
@@ -216,7 +261,7 @@ await chatLoop(new HarnessAdapter(), '');
|
|
|
216
261
|
"
|
|
217
262
|
`;
|
|
218
263
|
|
|
219
|
-
exports[`agentcore-harness generator > snapshot > snapshots the
|
|
264
|
+
exports[`agentcore-harness generator > snapshot > snapshots the rendered harness project files > packages/my-harness/src/PROMPT.md 1`] = `
|
|
220
265
|
"# MyHarness
|
|
221
266
|
|
|
222
267
|
You are a helpful AI assistant.
|
|
@@ -235,3 +280,22 @@ When tools are available, prefer them over recollection for anything you can
|
|
|
235
280
|
look up, and report what a tool returned, including when it fails.
|
|
236
281
|
"
|
|
237
282
|
`;
|
|
283
|
+
|
|
284
|
+
exports[`agentcore-harness generator > snapshot > snapshots the rendered harness project files > packages/my-harness/tsconfig.json 1`] = `
|
|
285
|
+
"{
|
|
286
|
+
"extends": "../../tsconfig.base.json",
|
|
287
|
+
"compilerOptions": {
|
|
288
|
+
"composite": false,
|
|
289
|
+
"declarationMap": false,
|
|
290
|
+
"emitDeclarationOnly": false,
|
|
291
|
+
"noEmit": true,
|
|
292
|
+
"types": [
|
|
293
|
+
"node"
|
|
294
|
+
]
|
|
295
|
+
},
|
|
296
|
+
"include": [
|
|
297
|
+
"**/*.ts"
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
"
|
|
301
|
+
`;
|
|
@@ -12,6 +12,7 @@ import { addGeneratorMetricsIfApplicable } from "../utils/metrics.js";
|
|
|
12
12
|
import { kebabCase, toClassName } from "../utils/names.js";
|
|
13
13
|
import { getNpmScopePrefix } from "../utils/npm-scope.js";
|
|
14
14
|
import { addGeneratorMetadata, getGeneratorInfo, projectExists, readProjectConfigurationUnqualified } from "../utils/nx.js";
|
|
15
|
+
import { addScriptProjectTargets } from "../utils/script-project-targets.js";
|
|
15
16
|
import { SHARED_CONSTRUCTS_DEPENDENCIES, sharedConstructsGenerator } from "../utils/shared-constructs.js";
|
|
16
17
|
// scripts/chat.ts needs all of these whatever the infrastructure choice, so no
|
|
17
18
|
// entry is conditional. The harness project holds no manifest of its own, so
|
|
@@ -91,6 +92,11 @@ export const agentcoreHarnessGenerator = async (tree, options)=>{
|
|
|
91
92
|
cwd: '{projectRoot}'
|
|
92
93
|
}
|
|
93
94
|
};
|
|
95
|
+
// scripts/chat.ts is TypeScript the user runs and customises, so it goes
|
|
96
|
+
// through the workspace's build sweep.
|
|
97
|
+
addScriptProjectTargets(tree, {
|
|
98
|
+
project
|
|
99
|
+
});
|
|
94
100
|
updateProjectConfiguration(tree, project.name, project);
|
|
95
101
|
generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'project'), projectRoot, {
|
|
96
102
|
nameClassName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-harness/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 updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../utils/add-dependencies.js';\nimport { addAgentCoreHarnessInfra } from '../utils/agent-core-constructs/agent-core-constructs.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 { kebabCase, toClassName } from '../utils/names.js';\nimport { getNpmScopePrefix } from '../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n readProjectConfigurationUnqualified,\n} from '../utils/nx.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 { AgentcoreHarnessGeneratorSchema } from './schema';\n\n// scripts/chat.ts needs all of these whatever the infrastructure choice, so no\n// entry is conditional. The harness project holds no manifest of its own, so\n// every entry is declared against the workspace root.\nexport const DEPENDENCIES = declareDependencies<AgentCoreHarnessMetadata>()({\n ts: [\n { name: '@aws-sdk/client-bedrock-agentcore', root: true },\n { name: '@aws-sdk/client-appconfigdata', root: true },\n { name: '@aws-lambda-powertools/parameters', root: true },\n { name: 'agent-chat-cli', root: true },\n // tsx runs the chat script via the `chat` target; both are shared tooling.\n { name: '@types/node', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n});\n\nexport const AGENTCORE_HARNESS_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const agentcoreHarnessGenerator = async (\n tree: Tree,\n options: AgentcoreHarnessGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(nameKebabCase);\n const parentDir = options.directory ?? 'packages';\n const subDir = options.subDirectory ?? nameKebabCase;\n const projectRoot = joinPathFragments(parentDir, subDir);\n const fullyQualifiedProjectName = `${getNpmScopePrefix(tree)}${nameKebabCase}`;\n const infra = options.infra ?? 'agentcore';\n\n // AgentCore harness names must start with an ASCII letter and stay within 40\n // characters once the \"_<8 hex>\" suffix is appended, so cap the prefix at 31.\n // toClassName prefixes `_` (not a letter) for digit-leading names.\n const harnessNamePrefix = (\n /^[A-Za-z]/.test(nameClassName) ? nameClassName : `H${nameClassName}`\n ).slice(0, 31);\n\n // Reuse an existing project configuration; create it otherwise.\n let project: ProjectConfiguration;\n if (projectExists(tree, fullyQualifiedProjectName)) {\n project = readProjectConfigurationUnqualified(\n tree,\n fullyQualifiedProjectName,\n );\n } else {\n addProjectConfiguration(tree, fullyQualifiedProjectName, {\n name: fullyQualifiedProjectName,\n root: projectRoot,\n projectType: 'application',\n sourceRoot: projectRoot,\n tags: [],\n targets: {},\n metadata: {\n generator: AGENTCORE_HARNESS_GENERATOR_INFO.id,\n } as any,\n });\n project = readProjectConfigurationUnqualified(\n tree,\n fullyQualifiedProjectName,\n );\n }\n\n // `chat` runs the vended chat script against the deployed Harness. Re-run:\n // keep an existing target so user edits survive.\n project.targets ??= {};\n project.targets['chat'] ??= {\n executor: 'nx:run-commands',\n options: {\n commands: ['tsx ./scripts/chat.ts'],\n cwd: '{projectRoot}',\n },\n };\n updateProjectConfiguration(tree, project.name, project);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'project'),\n projectRoot,\n {\n nameClassName,\n nameKebabCase,\n fullyQualifiedName: fullyQualifiedProjectName,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Resolved before the metadata write because the recorded value is what the\n // declaration's predicates read; undefined when no infrastructure is written,\n // in which case neither provider's packages were added.\n const iac =\n infra === 'agentcore' ? await resolveIac(tree, options.iac) : undefined;\n\n // Record only what cannot drift once the user owns the generated\n // infrastructure: the project identity, its runtime config key, its auth mode\n // and which provider's infrastructure was written.\n const metadata: Omit<AgentCoreHarnessMetadata, 'generator'> = {\n name: nameKebabCase,\n rc: nameClassName,\n auth: 'iam',\n ...(iac ? { iac } : {}),\n };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedProjectName,\n AGENTCORE_HARNESS_GENERATOR_INFO,\n metadata,\n );\n\n // scripts/chat.ts dependencies; tsx runs it via the `chat` target.\n addTsDependencies(tree, DEPENDENCIES, { metadata });\n\n // Harness infrastructure is written only for `infra: agentcore`. A later\n // `infra: agentcore` rerun adds it without replacing project files.\n if (iac) {\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n await addAgentCoreHarnessInfra(tree, {\n harnessNameClassName: nameClassName,\n harnessNameKebabCase: nameKebabCase,\n projectRoot,\n harnessNamePrefix,\n iac,\n });\n }\n\n await addGeneratorMetricsIfApplicable(tree, [\n AGENTCORE_HARNESS_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\n/**\n * Harness details stored in the Harness Project's metadata. `iac` records which\n * provider's infrastructure was written, so the version sync can tell which\n * shared constructs packages this project owns.\n */\nexport interface AgentCoreHarnessMetadata extends IacMetadata {\n generator: string;\n name: string;\n rc: string;\n auth: 'iam';\n}\n\n/**\n * Read a Harness Project's metadata, validating it was generated by the\n * agentcore-harness generator before returning typed data.\n */\nexport const readAgentCoreHarnessMetadata = (\n project: ProjectConfiguration,\n): AgentCoreHarnessMetadata => {\n const metadata = project.metadata as any;\n if (metadata?.generator !== AGENTCORE_HARNESS_GENERATOR_INFO.id) {\n throw new Error(\n `Project '${project.name}' was not generated by the '${AGENTCORE_HARNESS_GENERATOR_INFO.id}' generator.`,\n );\n }\n return metadata as AgentCoreHarnessMetadata;\n};\n\nexport default agentcoreHarnessGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","addAgentCoreHarnessInfra","declareDependencies","ownedElsewhere","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","readProjectConfigurationUnqualified","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","name","root","dev","AGENTCORE_HARNESS_GENERATOR_INFO","filename","agentcoreHarnessGenerator","tree","options","nameKebabCase","nameClassName","parentDir","directory","subDir","subDirectory","projectRoot","fullyQualifiedProjectName","infra","harnessNamePrefix","test","slice","project","projectType","sourceRoot","tags","targets","metadata","generator","id","executor","commands","cwd","dirname","fullyQualifiedName","overwriteStrategy","KeepExisting","iac","undefined","rc","auth","harnessNameClassName","harnessNameKebabCase","preferInstallDependencies","languages","readAgentCoreHarnessMetadata","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACp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S,2BACAZ,kCACAsB;IAGF,mEAAmE;IACnE5C,kBAAkByB,MAAMR,cAAc;QAAE2B;IAAS;IAEjD,yEAAyE;IACzE,oEAAoE;IACpE,IAAIU,KAAK;QACP,MAAMtC,0BAA0BS,MAAM;YAAE6B;QAAI,GAAGrC;QAC/C,MAAMhB,yBAAyBwB,MAAM;YACnCiC,sBAAsB9B;YACtB+B,sBAAsBhC;YACtBM;YACAG;YACAkB;QACF;IACF;IAEA,MAAM/C,gCAAgCkB,MAAM;QAC1CH;KACD;IAED,MAAMlB,qBAAqBqB;IAC3B,OAAO,IACLnB,oBAAoBmB,MAAMC,QAAQkC,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAcF;;;CAGC,GACD,OAAO,MAAMC,+BAA+B,CAC1CvB;IAEA,MAAMK,WAAWL,QAAQK,QAAQ;IACjC,IAAIA,UAAUC,cAAcvB,iCAAiCwB,EAAE,EAAE;QAC/D,MAAM,IAAIiB,MACR,CAAC,SAAS,EAAExB,QAAQpB,IAAI,CAAC,4BAA4B,EAAEG,iCAAiCwB,EAAE,CAAC,YAAY,CAAC;IAE5G;IACA,OAAOF;AACT,EAAE;AAEF,eAAepB,0BAA0B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/agentcore-harness/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 updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../utils/add-dependencies.js';\nimport { addAgentCoreHarnessInfra } from '../utils/agent-core-constructs/agent-core-constructs.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 { kebabCase, toClassName } from '../utils/names.js';\nimport { getNpmScopePrefix } from '../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n readProjectConfigurationUnqualified,\n} from '../utils/nx.js';\nimport { addScriptProjectTargets } from '../utils/script-project-targets.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 { AgentcoreHarnessGeneratorSchema } from './schema';\n\n// scripts/chat.ts needs all of these whatever the infrastructure choice, so no\n// entry is conditional. The harness project holds no manifest of its own, so\n// every entry is declared against the workspace root.\nexport const DEPENDENCIES = declareDependencies<AgentCoreHarnessMetadata>()({\n ts: [\n { name: '@aws-sdk/client-bedrock-agentcore', root: true },\n { name: '@aws-sdk/client-appconfigdata', root: true },\n { name: '@aws-lambda-powertools/parameters', root: true },\n { name: 'agent-chat-cli', root: true },\n // tsx runs the chat script via the `chat` target; both are shared tooling.\n { name: '@types/node', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n});\n\nexport const AGENTCORE_HARNESS_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\nexport const agentcoreHarnessGenerator = async (\n tree: Tree,\n options: AgentcoreHarnessGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(nameKebabCase);\n const parentDir = options.directory ?? 'packages';\n const subDir = options.subDirectory ?? nameKebabCase;\n const projectRoot = joinPathFragments(parentDir, subDir);\n const fullyQualifiedProjectName = `${getNpmScopePrefix(tree)}${nameKebabCase}`;\n const infra = options.infra ?? 'agentcore';\n\n // AgentCore harness names must start with an ASCII letter and stay within 40\n // characters once the \"_<8 hex>\" suffix is appended, so cap the prefix at 31.\n // toClassName prefixes `_` (not a letter) for digit-leading names.\n const harnessNamePrefix = (\n /^[A-Za-z]/.test(nameClassName) ? nameClassName : `H${nameClassName}`\n ).slice(0, 31);\n\n // Reuse an existing project configuration; create it otherwise.\n let project: ProjectConfiguration;\n if (projectExists(tree, fullyQualifiedProjectName)) {\n project = readProjectConfigurationUnqualified(\n tree,\n fullyQualifiedProjectName,\n );\n } else {\n addProjectConfiguration(tree, fullyQualifiedProjectName, {\n name: fullyQualifiedProjectName,\n root: projectRoot,\n projectType: 'application',\n sourceRoot: projectRoot,\n tags: [],\n targets: {},\n metadata: {\n generator: AGENTCORE_HARNESS_GENERATOR_INFO.id,\n } as any,\n });\n project = readProjectConfigurationUnqualified(\n tree,\n fullyQualifiedProjectName,\n );\n }\n\n // `chat` runs the vended chat script against the deployed Harness. Re-run:\n // keep an existing target so user edits survive.\n project.targets ??= {};\n project.targets['chat'] ??= {\n executor: 'nx:run-commands',\n options: {\n commands: ['tsx ./scripts/chat.ts'],\n cwd: '{projectRoot}',\n },\n };\n // scripts/chat.ts is TypeScript the user runs and customises, so it goes\n // through the workspace's build sweep.\n addScriptProjectTargets(tree, { project });\n updateProjectConfiguration(tree, project.name, project);\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'project'),\n projectRoot,\n {\n nameClassName,\n nameKebabCase,\n fullyQualifiedName: fullyQualifiedProjectName,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Resolved before the metadata write because the recorded value is what the\n // declaration's predicates read; undefined when no infrastructure is written,\n // in which case neither provider's packages were added.\n const iac =\n infra === 'agentcore' ? await resolveIac(tree, options.iac) : undefined;\n\n // Record only what cannot drift once the user owns the generated\n // infrastructure: the project identity, its runtime config key, its auth mode\n // and which provider's infrastructure was written.\n const metadata: Omit<AgentCoreHarnessMetadata, 'generator'> = {\n name: nameKebabCase,\n rc: nameClassName,\n auth: 'iam',\n ...(iac ? { iac } : {}),\n };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedProjectName,\n AGENTCORE_HARNESS_GENERATOR_INFO,\n metadata,\n );\n\n // scripts/chat.ts dependencies; tsx runs it via the `chat` target.\n addTsDependencies(tree, DEPENDENCIES, { metadata });\n\n // Harness infrastructure is written only for `infra: agentcore`. A later\n // `infra: agentcore` rerun adds it without replacing project files.\n if (iac) {\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n await addAgentCoreHarnessInfra(tree, {\n harnessNameClassName: nameClassName,\n harnessNameKebabCase: nameKebabCase,\n projectRoot,\n harnessNamePrefix,\n iac,\n });\n }\n\n await addGeneratorMetricsIfApplicable(tree, [\n AGENTCORE_HARNESS_GENERATOR_INFO,\n ]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\n/**\n * Harness details stored in the Harness Project's metadata. `iac` records which\n * provider's infrastructure was written, so the version sync can tell which\n * shared constructs packages this project owns.\n */\nexport interface AgentCoreHarnessMetadata extends IacMetadata {\n generator: string;\n name: string;\n rc: string;\n auth: 'iam';\n}\n\n/**\n * Read a Harness Project's metadata, validating it was generated by the\n * agentcore-harness generator before returning typed data.\n */\nexport const readAgentCoreHarnessMetadata = (\n project: ProjectConfiguration,\n): AgentCoreHarnessMetadata => {\n const metadata = project.metadata as any;\n if (metadata?.generator !== AGENTCORE_HARNESS_GENERATOR_INFO.id) {\n throw new Error(\n `Project '${project.name}' was not generated by the '${AGENTCORE_HARNESS_GENERATOR_INFO.id}' generator.`,\n );\n }\n return metadata as AgentCoreHarnessMetadata;\n};\n\nexport default agentcoreHarnessGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","addTsDependencies","addAgentCoreHarnessInfra","declareDependencies","ownedElsewhere","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","projectExists","readProjectConfigurationUnqualified","addScriptProjectTargets","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","DEPENDENCIES","ts","name","root","dev","AGENTCORE_HARNESS_GENERATOR_INFO","filename","agentcoreHarnessGenerator","tree","options","nameKebabCase","nameClassName","parentDir","directory","subDir","subDirectory","projectRoot","fullyQualifiedProjectName","infra","harnessNamePrefix","test","slice","project","projectType","sourceRoot","tags","targets","metadata","generator","id","executor","commands","cwd","dirname","fullyQualifiedName","overwriteStrategy","KeepExisting","iac","undefined","rc","auth","harnessNameClassName","harnessNameKebabCase","preferInstallDependencies","languages","readAgentCoreHarnessMetadata","Error"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,+BAA+B;AACjE,SAASC,wBAAwB,QAAQ,0DAA0D;AACnG,SACEC,mBAAmB,EACnBC,cAAc,QACT,oCAAoC;AAC3C,SAASC,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,sBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,sBAAsB;AACtE,SAASC,SAAS,EAAEC,WAAW,QAAQ,oBAAoB;AAC3D,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,EACbC,mCAAmC,QAC9B,iBAAiB;AACxB,SAASC,uBAAuB,QAAQ,qCAAqC;AAC7E,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,gCAAgC;AAIvC,+EAA+E;AAC/E,6EAA6E;AAC7E,sDAAsD;AACtD,OAAO,MAAMC,eAAehB,sBAAgD;IAC1EiB,IAAI;QACF;YAAEC,MAAM;YAAqCC,MAAM;QAAK;QACxD;YAAED,MA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cAAcvB,iCAAiCwB,EAAE,EAAE;QAC/D,MAAM,IAAIiB,MACR,CAAC,SAAS,EAAExB,QAAQpB,IAAI,CAAC,4BAA4B,EAAEG,iCAAiCwB,EAAE,CAAC,YAAY,CAAC;IAE5G;IACA,OAAOF;AACT,EAAE;AAEF,eAAepB,0BAA0B"}
|
|
@@ -19,7 +19,7 @@ const CONNECTION_TF_MODULE_NAME = 'add_gateway_url_to_connection_runtime_config'
|
|
|
19
19
|
|
|
20
20
|
rc.set('connection', 'gateways', {
|
|
21
21
|
...rc.get('connection').gateways,
|
|
22
|
-
${options.gatewayNameClassName}: this.
|
|
22
|
+
${options.gatewayNameClassName}: this.gatewayUrl,
|
|
23
23
|
});\` where { $program <: not contains \`rc.set('connection', 'gateways', $_)\` }`);
|
|
24
24
|
}
|
|
25
25
|
const terraformConstructPath = joinPathFragments(PACKAGES_DIR, SHARED_TERRAFORM_DIR, 'src', 'app', 'gateways', options.gatewayNameKebabCase, `${options.gatewayNameKebabCase}.tf`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/connection/gateway-runtime-config.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, type Tree } from '@nx/devkit';\nimport { applyGritQL, matchGritQL } from '../utils/ast.js';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../utils/shared-constructs-constants.js';\n\nconst CONNECTION_TF_MODULE_NAME =\n 'add_gateway_url_to_connection_runtime_config';\n\n/**\n * Register the gateway's URL in the 'connection' namespace so it is published\n * to the website's runtime-config.json. Patches the generated CDK and\n * Terraform constructs in-place; idempotent.\n *\n * Note: the 'connection' namespace is stage-scoped — every StaticWebsite in\n * the stage will see this URL, not just the one the user connected.\n */\nexport const addGatewayUrlToConnectionNamespace = async (\n tree: Tree,\n options: {\n /** The kebab-case directory name that holds the construct, e.g. 'my-gateway'. */\n gatewayNameKebabCase: string;\n /** The class name of the gateway, e.g. 'MyGateway'. */\n gatewayNameClassName: string;\n },\n) => {\n const cdkConstructPath = joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'gateways',\n options.gatewayNameKebabCase,\n `${options.gatewayNameKebabCase}.ts`,\n );\n if (tree.exists(cdkConstructPath)) {\n await applyGritQL(\n tree,\n cdkConstructPath,\n `\\`rc.set('agentcore', 'gateways', $args);\\` => raw\\`rc.set('agentcore', 'gateways', $args);\n\n rc.set('connection', 'gateways', {\n ...rc.get('connection').gateways,\n ${options.gatewayNameClassName}: this.
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/connection/gateway-runtime-config.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, type Tree } from '@nx/devkit';\nimport { applyGritQL, matchGritQL } from '../utils/ast.js';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../utils/shared-constructs-constants.js';\n\nconst CONNECTION_TF_MODULE_NAME =\n 'add_gateway_url_to_connection_runtime_config';\n\n/**\n * Register the gateway's URL in the 'connection' namespace so it is published\n * to the website's runtime-config.json. Patches the generated CDK and\n * Terraform constructs in-place; idempotent.\n *\n * Note: the 'connection' namespace is stage-scoped — every StaticWebsite in\n * the stage will see this URL, not just the one the user connected.\n */\nexport const addGatewayUrlToConnectionNamespace = async (\n tree: Tree,\n options: {\n /** The kebab-case directory name that holds the construct, e.g. 'my-gateway'. */\n gatewayNameKebabCase: string;\n /** The class name of the gateway, e.g. 'MyGateway'. */\n gatewayNameClassName: string;\n },\n) => {\n const cdkConstructPath = joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'gateways',\n options.gatewayNameKebabCase,\n `${options.gatewayNameKebabCase}.ts`,\n );\n if (tree.exists(cdkConstructPath)) {\n await applyGritQL(\n tree,\n cdkConstructPath,\n `\\`rc.set('agentcore', 'gateways', $args);\\` => raw\\`rc.set('agentcore', 'gateways', $args);\n\n rc.set('connection', 'gateways', {\n ...rc.get('connection').gateways,\n ${options.gatewayNameClassName}: this.gatewayUrl,\n });\\` where { $program <: not contains \\`rc.set('connection', 'gateways', $_)\\` }`,\n );\n }\n\n const terraformConstructPath = joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'gateways',\n options.gatewayNameKebabCase,\n `${options.gatewayNameKebabCase}.tf`,\n );\n if (tree.exists(terraformConstructPath)) {\n const alreadyPatched = await matchGritQL(\n tree,\n terraformConstructPath,\n `language hcl\\n\\`module \"${CONNECTION_TF_MODULE_NAME}\" { $_ }\\``,\n );\n if (!alreadyPatched) {\n const source = tree.read(terraformConstructPath, 'utf-8')!;\n tree.write(\n terraformConstructPath,\n `${source.trimEnd()}\n\n# Also expose the gateway URL to the frontend via the 'connection' namespace\nmodule \"${CONNECTION_TF_MODULE_NAME}\" {\n source = \"../../../core/runtime-config/entry\"\n\n namespace = \"connection\"\n key = \"gateways\"\n value = { \"${options.gatewayNameClassName}\" = aws_bedrockagentcore_gateway.this.gateway_url }\n\n depends_on = [aws_bedrockagentcore_gateway.this]\n}\n`,\n );\n }\n }\n};\n"],"names":["joinPathFragments","applyGritQL","matchGritQL","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","CONNECTION_TF_MODULE_NAME","addGatewayUrlToConnectionNamespace","tree","options","cdkConstructPath","gatewayNameKebabCase","exists","gatewayNameClassName","terraformConstructPath","alreadyPatched","source","read","write","trimEnd"],"mappings":"AAAA;;;CAGC,GACD,SAASA,iBAAiB,QAAmB,aAAa;AAC1D,SAASC,WAAW,EAAEC,WAAW,QAAQ,kBAAkB;AAC3D,SACEC,YAAY,EACZC,qBAAqB,EACrBC,oBAAoB,QACf,0CAA0C;AAEjD,MAAMC,4BACJ;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,qCAAqC,OAChDC,MACAC;IAOA,MAAMC,mBAAmBV,kBACvBG,cACAC,uBACA,OACA,OACA,YACAK,QAAQE,oBAAoB,EAC5B,GAAGF,QAAQE,oBAAoB,CAAC,GAAG,CAAC;IAEtC,IAAIH,KAAKI,MAAM,CAACF,mBAAmB;QACjC,MAAMT,YACJO,MACAE,kBACA,CAAC;;;;MAID,EAAED,QAAQI,oBAAoB,CAAC;qFACgD,CAAC;IAEpF;IAEA,MAAMC,yBAAyBd,kBAC7BG,cACAE,sBACA,OACA,OACA,YACAI,QAAQE,oBAAoB,EAC5B,GAAGF,QAAQE,oBAAoB,CAAC,GAAG,CAAC;IAEtC,IAAIH,KAAKI,MAAM,CAACE,yBAAyB;QACvC,MAAMC,iBAAiB,MAAMb,YAC3BM,MACAM,wBACA,CAAC,wBAAwB,EAAER,0BAA0B,UAAU,CAAC;QAElE,IAAI,CAACS,gBAAgB;YACnB,MAAMC,SAASR,KAAKS,IAAI,CAACH,wBAAwB;YACjDN,KAAKU,KAAK,CACRJ,wBACA,GAAGE,OAAOG,OAAO,GAAG;;;QAGpB,EAAEb,0BAA0B;;;;;iBAKnB,EAAEG,QAAQI,oBAAoB,CAAC;;;;AAIhD,CAAC;QAEG;IACF;AACF,EAAE"}
|
|
@@ -4,16 +4,13 @@ exports[`infra generator > should add required dependencies to package.json > de
|
|
|
4
4
|
|
|
5
5
|
exports[`infra generator > should add required dependencies to package.json > dev-dependencies 1`] = `
|
|
6
6
|
{
|
|
7
|
-
"@nx/
|
|
8
|
-
"@nx/vitest": "23.1.2",
|
|
9
|
-
"@swc/helpers": "~0.5.18",
|
|
7
|
+
"@nx/vitest": "catalog:",
|
|
10
8
|
"@types/node": "catalog:",
|
|
11
9
|
"@vitest/coverage-v8": "catalog:",
|
|
12
10
|
"aws-cdk": "catalog:",
|
|
13
11
|
"esbuild": "catalog:",
|
|
14
|
-
"jsdom": "
|
|
12
|
+
"jsdom": "catalog:",
|
|
15
13
|
"tsx": "catalog:",
|
|
16
|
-
"typescript": "~6.0.3",
|
|
17
14
|
"vite": "catalog:",
|
|
18
15
|
"vitest": "catalog:",
|
|
19
16
|
}
|
|
@@ -23,16 +20,13 @@ exports[`infra generator > should add required dependencies to package.json > pa
|
|
|
23
20
|
{
|
|
24
21
|
"dependencies": {},
|
|
25
22
|
"devDependencies": {
|
|
26
|
-
"@nx/
|
|
27
|
-
"@nx/vitest": "23.1.2",
|
|
28
|
-
"@swc/helpers": "~0.5.18",
|
|
23
|
+
"@nx/vitest": "catalog:",
|
|
29
24
|
"@types/node": "catalog:",
|
|
30
25
|
"@vitest/coverage-v8": "catalog:",
|
|
31
26
|
"aws-cdk": "catalog:",
|
|
32
27
|
"esbuild": "catalog:",
|
|
33
|
-
"jsdom": "
|
|
28
|
+
"jsdom": "catalog:",
|
|
34
29
|
"tsx": "catalog:",
|
|
35
|
-
"typescript": "~6.0.3",
|
|
36
30
|
"vite": "catalog:",
|
|
37
31
|
"vitest": "catalog:",
|
|
38
32
|
},
|
|
@@ -53,7 +47,7 @@ exports[`infra generator > should configure Checkov target correctly > checkov-t
|
|
|
53
47
|
],
|
|
54
48
|
"executor": "nx:run-commands",
|
|
55
49
|
"inputs": [
|
|
56
|
-
"
|
|
50
|
+
"default",
|
|
57
51
|
],
|
|
58
52
|
"options": {
|
|
59
53
|
"command": "uvx --from checkov==3.3.16 checkov --config-file {projectRoot}/checkov.yml --directory dist/{projectRoot}/cdk.out --framework cloudformation",
|
|
@@ -84,7 +78,7 @@ exports[`infra generator > should configure project.json with correct targets >
|
|
|
84
78
|
],
|
|
85
79
|
"executor": "nx:run-commands",
|
|
86
80
|
"options": {
|
|
87
|
-
"command": "cdk deploy --require-approval=never
|
|
81
|
+
"command": "cdk deploy --require-approval=never",
|
|
88
82
|
"cwd": "{projectRoot}",
|
|
89
83
|
},
|
|
90
84
|
}
|
|
@@ -153,7 +147,7 @@ exports[`infra generator > should configure project.json with correct targets >
|
|
|
153
147
|
],
|
|
154
148
|
"executor": "nx:run-commands",
|
|
155
149
|
"inputs": [
|
|
156
|
-
"
|
|
150
|
+
"default",
|
|
157
151
|
],
|
|
158
152
|
"options": {
|
|
159
153
|
"command": "uvx --from checkov==3.3.16 checkov --config-file {projectRoot}/checkov.yml --directory dist/{projectRoot}/cdk.out --framework cloudformation",
|
|
@@ -179,7 +173,7 @@ exports[`infra generator > should configure project.json with correct targets >
|
|
|
179
173
|
],
|
|
180
174
|
"executor": "nx:run-commands",
|
|
181
175
|
"options": {
|
|
182
|
-
"command": "cdk deploy --require-approval=never
|
|
176
|
+
"command": "cdk deploy --require-approval=never",
|
|
183
177
|
"cwd": "{projectRoot}",
|
|
184
178
|
},
|
|
185
179
|
},
|
|
@@ -765,7 +759,7 @@ exports[`infra generator > should handle custom project names correctly > custom
|
|
|
765
759
|
],
|
|
766
760
|
"executor": "nx:run-commands",
|
|
767
761
|
"inputs": [
|
|
768
|
-
"
|
|
762
|
+
"default",
|
|
769
763
|
],
|
|
770
764
|
"options": {
|
|
771
765
|
"command": "uvx --from checkov==3.3.16 checkov --config-file {projectRoot}/checkov.yml --directory dist/{projectRoot}/cdk.out --framework cloudformation",
|
|
@@ -791,7 +785,7 @@ exports[`infra generator > should handle custom project names correctly > custom
|
|
|
791
785
|
],
|
|
792
786
|
"executor": "nx:run-commands",
|
|
793
787
|
"options": {
|
|
794
|
-
"command": "cdk deploy --require-approval=never
|
|
788
|
+
"command": "cdk deploy --require-approval=never",
|
|
795
789
|
"cwd": "{projectRoot}",
|
|
796
790
|
},
|
|
797
791
|
},
|
|
@@ -10,6 +10,7 @@ import { resolveContainers } from "../../utils/containers.js";
|
|
|
10
10
|
import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
|
|
11
11
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
12
12
|
import { installDependencies } from "../../utils/install.js";
|
|
13
|
+
import { addLocalProjectDependency } from "../../utils/local-project-dependency.js";
|
|
13
14
|
import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
14
15
|
import { esmVars } from "../../utils/module-format.js";
|
|
15
16
|
import { kebabCase } from "../../utils/names.js";
|
|
@@ -59,7 +60,8 @@ export const DEPENDENCIES = declareDependencies()({
|
|
|
59
60
|
export const INFRA_APP_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
60
61
|
export async function tsInfraGenerator(tree, schema) {
|
|
61
62
|
const lib = getTsLibDetails(tree, schema);
|
|
62
|
-
|
|
63
|
+
const isNewProject = !projectExists(tree, lib.fullyQualifiedName);
|
|
64
|
+
if (isNewProject) {
|
|
63
65
|
await tsProjectGenerator(tree, {
|
|
64
66
|
...schema,
|
|
65
67
|
preferInstallDependencies: false
|
|
@@ -108,7 +110,14 @@ export async function tsInfraGenerator(tree, schema) {
|
|
|
108
110
|
const namespace = kebabCase(fullyQualifiedName);
|
|
109
111
|
// The stage instantiated in main.ts. Quoted so the shell does not glob `*`.
|
|
110
112
|
const sandboxStagePattern = `"${namespace}-sandbox/*"`;
|
|
111
|
-
|
|
113
|
+
// `tsProjectGenerator` scaffolds a library `src`, which the CDK app layout
|
|
114
|
+
// replaces. Only on creation — on a re-run this is the user's infrastructure.
|
|
115
|
+
if (isNewProject) {
|
|
116
|
+
tree.delete(joinPathFragments(libraryRoot, 'src'));
|
|
117
|
+
}
|
|
118
|
+
// The guide walks through declaring resources in
|
|
119
|
+
// `src/stacks/application-stack.ts` and adding stages to `src/main.ts`, so
|
|
120
|
+
// everything here is scaffolded once and then left alone.
|
|
112
121
|
generateFiles(tree, joinPathFragments(import.meta.dirname, './files/app'), libraryRoot, {
|
|
113
122
|
synthDir: synthDirFromProject,
|
|
114
123
|
scopeAlias: scopeAlias,
|
|
@@ -120,7 +129,7 @@ export async function tsInfraGenerator(tree, schema) {
|
|
|
120
129
|
...schema,
|
|
121
130
|
...esmVars(tree)
|
|
122
131
|
}, {
|
|
123
|
-
overwriteStrategy: OverwriteStrategy.
|
|
132
|
+
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
124
133
|
});
|
|
125
134
|
updateJson(tree, `${libraryRoot}/project.json`, (config)=>{
|
|
126
135
|
config.projectType = 'application';
|
|
@@ -149,11 +158,17 @@ export async function tsInfraGenerator(tree, schema) {
|
|
|
149
158
|
command: 'cdk synth'
|
|
150
159
|
})
|
|
151
160
|
};
|
|
161
|
+
// `default` rather than the synth directory: `dist` is gitignored, so a
|
|
162
|
+
// fileset input pointed at it matches no tracked file and hashes to a
|
|
163
|
+
// constant — the scan would cache-hit forever and pass on infrastructure
|
|
164
|
+
// it never read. `default` carries the project's own sources plus the
|
|
165
|
+
// transitive `dependentTasksOutputFiles` entry, which resolves against
|
|
166
|
+
// the upstream `synth` task and so hashes the template actually scanned.
|
|
152
167
|
config.targets.checkov = {
|
|
153
168
|
cache: true,
|
|
154
169
|
executor: 'nx:run-commands',
|
|
155
170
|
inputs: [
|
|
156
|
-
'
|
|
171
|
+
'default'
|
|
157
172
|
],
|
|
158
173
|
outputs: [
|
|
159
174
|
'{workspaceRoot}/dist/{projectRoot}/checkov'
|
|
@@ -171,13 +186,14 @@ export async function tsInfraGenerator(tree, schema) {
|
|
|
171
186
|
'^assemble',
|
|
172
187
|
'compile'
|
|
173
188
|
],
|
|
174
|
-
// No --express
|
|
175
|
-
//
|
|
189
|
+
// No --express: this target deploys whichever stage is named, including
|
|
190
|
+
// beta and prod, so it waits for full resource stabilization. Express
|
|
191
|
+
// mode belongs to `deploy-sandbox`, which only ever deploys a sandbox.
|
|
176
192
|
options: stageConfig ? withCdkEnv({
|
|
177
193
|
command: `tsx packages/common/scripts/src/infra/infra-deploy.ts ${libraryRoot}`
|
|
178
194
|
}) : withCdkEnv({
|
|
179
195
|
cwd: '{projectRoot}',
|
|
180
|
-
command: 'cdk deploy --require-approval=never
|
|
196
|
+
command: 'cdk deploy --require-approval=never'
|
|
181
197
|
})
|
|
182
198
|
};
|
|
183
199
|
config.targets['deploy-sandbox'] = {
|
|
@@ -266,6 +282,17 @@ export async function tsInfraGenerator(tree, schema) {
|
|
|
266
282
|
] : []
|
|
267
283
|
])
|
|
268
284
|
}));
|
|
285
|
+
// `main.ts` and the application stack import the shared constructs.
|
|
286
|
+
addLocalProjectDependency(tree, {
|
|
287
|
+
consumerRoot: libraryRoot,
|
|
288
|
+
dependencyRoot: joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR)
|
|
289
|
+
});
|
|
290
|
+
if (stageConfig) {
|
|
291
|
+
addLocalProjectDependency(tree, {
|
|
292
|
+
consumerRoot: libraryRoot,
|
|
293
|
+
dependencyRoot: joinPathFragments(PACKAGES_DIR, SHARED_INFRA_CONFIG_DIR)
|
|
294
|
+
});
|
|
295
|
+
}
|
|
269
296
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
270
297
|
INFRA_APP_GENERATOR_INFO
|
|
271
298
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/infra/app/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 ProjectConfiguration,\n readProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport path from 'path';\nimport tsProjectGenerator, { getTsLibDetails } from '../../ts/lib/generator.js';\nimport { mergeTsReferences } from '../../ts/lib/ts-project-utils.js';\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 { formatFilesInSubtree } from '../../utils/format.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport { uvxCommand } from '../../utils/py.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_INFRA_CONFIG_DIR,\n} from '../../utils/shared-constructs-constants.js';\nimport { sharedInfraConfigGenerator } from '../../utils/shared-infra-config.js';\nimport {\n SHARED_INFRA_SCRIPTS_DEPENDENCIES,\n sharedInfraScriptsGenerator,\n} from '../../utils/shared-infra-scripts.js';\nimport type { TsInfraGeneratorSchema } from './schema';\n\n// This generator records no metadata, so nothing a predicate could read: the\n// CDK app always needs the app libraries, and the CLI, bundler and tsx are\n// shared tooling.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: 'aws-cdk-lib' },\n { name: 'constructs' },\n { name: 'source-map-support' },\n // The `aws-cdk` CLI, esbuild (CDK bundling) and tsx are shared tooling.\n { name: 'aws-cdk', dev: true, root: true },\n { name: 'esbuild', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_INFRA_SCRIPTS_DEPENDENCIES),\n ],\n});\n\nexport const INFRA_APP_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport async function tsInfraGenerator(\n tree: Tree,\n schema: TsInfraGeneratorSchema,\n): Promise<GeneratorCallback> {\n const lib = getTsLibDetails(tree, schema);\n\n if (!projectExists(tree, lib.fullyQualifiedName)) {\n await tsProjectGenerator(tree, {\n ...schema,\n preferInstallDependencies: false,\n });\n }\n\n // CDK shells out to a container engine to build image assets. Default\n // (docker) needs no env override; finch is set via CDK_DOCKER per\n // https://docs.aws.amazon.com/cdk/v2/guide/build-containers.html#build-container-replace.\n const containers = await resolveContainers(tree, 'inherit');\n const cdkEnv: Record<string, string> | undefined =\n containers === 'docker' ? undefined : { CDK_DOCKER: containers };\n const withCdkEnv = <T extends Record<string, unknown>>(opts: T): T => {\n if (!cdkEnv) return opts;\n const existingEnv = (opts.env as Record<string, string> | undefined) ?? {};\n return { ...opts, env: { ...existingEnv, ...cdkEnv } } as T;\n };\n\n // This generator IS the CDK infrastructure project, so the provider is fixed.\n addGeneratorMetadata(tree, lib.fullyQualifiedName, INFRA_APP_GENERATOR_INFO, {\n iac: 'cdk',\n });\n\n // Shared constructs always in CDK for typescript infra generator\n await sharedConstructsGenerator(\n tree,\n {\n iac: 'cdk',\n },\n DEPENDENCIES,\n );\n\n // Shared infra-config and infra-scripts packages (lazy creation, only when enabled)\n const stageConfig = schema.stageConfig ?? false;\n if (stageConfig) {\n await sharedInfraConfigGenerator(tree);\n await sharedInfraScriptsGenerator(tree, DEPENDENCIES);\n }\n\n const synthDirFromRoot = `/dist/${lib.dir}/cdk.out`;\n const synthDirFromProject =\n lib.dir\n .split('/')\n .map(() => '..')\n .join('/') + `/dist/${lib.dir}/cdk.out`;\n const distDirFromProjectRoot =\n lib.dir\n .split('/')\n .map(() => '..')\n .join('/') + '/dist/{projectRoot}/cdk.out';\n const projectConfig = readProjectConfiguration(tree, lib.fullyQualifiedName);\n const libraryRoot = projectConfig.root;\n const npmScopePrefix = getNpmScopePrefix(tree);\n const scopeAlias = npmScopePrefix;\n const fullyQualifiedName = `${npmScopePrefix}${schema.name}`;\n const namespace = kebabCase(fullyQualifiedName);\n // The stage instantiated in main.ts. Quoted so the shell does not glob `*`.\n const sandboxStagePattern = `\"${namespace}-sandbox/*\"`;\n tree.delete(joinPathFragments(libraryRoot, 'src'));\n\n generateFiles(\n tree, // the virtual file system\n joinPathFragments(import.meta.dirname, './files/app'), // path to the file templates\n libraryRoot, // destination path of the files\n {\n synthDir: synthDirFromProject,\n scopeAlias: scopeAlias,\n namespace,\n fullyQualifiedName,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n dir: lib.dir,\n stageConfig,\n ...schema,\n ...esmVars(tree),\n },\n {\n overwriteStrategy: OverwriteStrategy.Overwrite,\n },\n );\n\n updateJson(\n tree,\n `${libraryRoot}/project.json`,\n (config: ProjectConfiguration) => {\n config.projectType = 'application';\n // `synth` is the CDK artifact, so it belongs on `assemble` too; `checkov`\n // is a quality gate, so it stays on `build` alone.\n addArtifactDependencyToTargets(config, 'synth');\n addDependencyToTargetIfNotPresent(config, 'build', 'checkov');\n config.targets.compile.outputs = [\n '{workspaceRoot}/dist/{projectRoot}/tsc',\n ];\n config.targets.synth = {\n cache: true,\n executor: 'nx:run-commands',\n inputs: ['default'],\n outputs: ['{workspaceRoot}/dist/{projectRoot}/cdk.out'],\n dependsOn: ['^assemble', 'compile'], // compile clobbers dist directory, so ensure synth runs afterwards\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk synth',\n }),\n };\n config.targets.checkov = {\n cache: true,\n executor: 'nx:run-commands',\n inputs: ['{workspaceRoot}/dist/{projectRoot}/cdk.out'],\n outputs: ['{workspaceRoot}/dist/{projectRoot}/checkov'],\n dependsOn: ['synth'],\n options: {\n command: uvxCommand(\n 'checkov',\n '--config-file {projectRoot}/checkov.yml --directory dist/{projectRoot}/cdk.out --framework cloudformation',\n ),\n },\n };\n config.targets.deploy = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n // No --express here when stages are configured: this target deploys\n // whichever stage is named, including beta and prod.\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-deploy.ts ${libraryRoot}`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk deploy --require-approval=never --express',\n }),\n };\n config.targets['deploy-sandbox'] = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-deploy.ts ${libraryRoot} ${sandboxStagePattern} --express`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk deploy --require-approval=never ${sandboxStagePattern} --express`,\n }),\n };\n config.targets['deploy-ci'] = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk deploy --require-approval=never --app ${distDirFromProjectRoot}`,\n }),\n };\n config.targets.destroy = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-destroy.ts ${libraryRoot}`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk destroy',\n }),\n };\n config.targets['destroy-sandbox'] = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-destroy.ts ${libraryRoot} ${sandboxStagePattern}`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk destroy ${sandboxStagePattern}`,\n }),\n };\n config.targets['destroy-ci'] = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk destroy --app ${distDirFromProjectRoot}`,\n }),\n };\n config.targets.cdk = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk',\n }),\n };\n config.targets.bootstrap = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk bootstrap',\n }),\n };\n config.targets = sortObjectKeys(config.targets);\n return config;\n },\n );\n\n addTsDependencies(tree, DEPENDENCIES, { projectRoot: libraryRoot });\n\n updateJson(tree, `${libraryRoot}/tsconfig.lib.json`, (tsConfig) => ({\n ...tsConfig,\n references: mergeTsReferences(tsConfig.references, [\n {\n path: `${path.relative(\n libraryRoot,\n `${tree.root}/${PACKAGES_DIR}`,\n )}/${SHARED_CONSTRUCTS_DIR}/tsconfig.lib.json`,\n },\n ...(stageConfig\n ? [\n {\n path: `${path.relative(\n libraryRoot,\n `${tree.root}/${PACKAGES_DIR}`,\n )}/${SHARED_INFRA_CONFIG_DIR}/tsconfig.json`,\n },\n ]\n : []),\n ]),\n }));\n\n await addGeneratorMetricsIfApplicable(tree, [INFRA_APP_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\nexport default tsInfraGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","path","tsProjectGenerator","getTsLibDetails","mergeTsReferences","addTsDependencies","resolveContainers","declareDependencies","ownedElsewhere","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScopePrefix","addArtifactDependencyToTargets","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","uvxCommand","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_INFRA_CONFIG_DIR","sharedInfraConfigGenerator","SHARED_INFRA_SCRIPTS_DEPENDENCIES","sharedInfraScriptsGenerator","DEPENDENCIES","ts","name","dev","root","INFRA_APP_GENERATOR_INFO","filename","tsInfraGenerator","tree","schema","lib","fullyQualifiedName","preferInstallDependencies","containers","cdkEnv","undefined","CDK_DOCKER","withCdkEnv","opts","existingEnv","env","iac","stageConfig","synthDirFromRoot","dir","synthDirFromProject","split","map","join","distDirFromProjectRoot","projectConfig","libraryRoot","npmScopePrefix","scopeAlias","namespace","sandboxStagePattern","delete","dirname","synthDir","pkgMgrCmd","exec","overwriteStrategy","Overwrite","config","projectType","targets","compile","outputs","synth","cache","executor","inputs","dependsOn","options","cwd","command","checkov","deploy","destroy","cdk","bootstrap","projectRoot","tsConfig","references","relative","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,wBAAwB,EAExBC,UAAU,QACL,aAAa;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,sBAAsBC,eAAe,QAAQ,4BAA4B;AAChF,SAASC,iBAAiB,QAAQ,mCAAmC;AACrE,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SACEC,8BAA8B,EAC9BC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,gCAAgC,QAAQ,6BAA6B;AAC9E,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAmC;AAC1C,SACEC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,6CAA6C;AACpD,SAASC,0BAA0B,QAAQ,qCAAqC;AAChF,SACEC,iCAAiC,EACjCC,2BAA2B,QACtB,sCAAsC;AAG7C,6EAA6E;AAC7E,2EAA2E;AAC3E,kBAAkB;AAClB,OAAO,MAAMC,eAAexB,sBAAsB;IAChDyB,IAAI;QACF;YAAEC,MAAM;QAAc;QACtB;YAAEA,MAAM;QAAa;QACrB;YAAEA,MAAM;QAAqB;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AACH;KAAyB;IAEtE,MAAM3B,qBAAqB8B;IAC3B,OAAO,IACL7B,oBAAoB6B,MAAMC,OAAOG,yBAAyB,EAAE;YAC1DqD,WAAW;gBAAC;aAAa;QAC3B;AACJ;AACA,eAAe1D,iBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/infra/app/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 ProjectConfiguration,\n readProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport path from 'path';\nimport tsProjectGenerator, { getTsLibDetails } from '../../ts/lib/generator.js';\nimport { mergeTsReferences } from '../../ts/lib/ts-project-utils.js';\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 { formatFilesInSubtree } from '../../utils/format.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addLocalProjectDependency } from '../../utils/local-project-dependency.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport { uvxCommand } from '../../utils/py.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_INFRA_CONFIG_DIR,\n} from '../../utils/shared-constructs-constants.js';\nimport { sharedInfraConfigGenerator } from '../../utils/shared-infra-config.js';\nimport {\n SHARED_INFRA_SCRIPTS_DEPENDENCIES,\n sharedInfraScriptsGenerator,\n} from '../../utils/shared-infra-scripts.js';\nimport type { TsInfraGeneratorSchema } from './schema';\n\n// This generator records no metadata, so nothing a predicate could read: the\n// CDK app always needs the app libraries, and the CLI, bundler and tsx are\n// shared tooling.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: 'aws-cdk-lib' },\n { name: 'constructs' },\n { name: 'source-map-support' },\n // The `aws-cdk` CLI, esbuild (CDK bundling) and tsx are shared tooling.\n { name: 'aws-cdk', dev: true, root: true },\n { name: 'esbuild', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_INFRA_SCRIPTS_DEPENDENCIES),\n ],\n});\n\nexport const INFRA_APP_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport async function tsInfraGenerator(\n tree: Tree,\n schema: TsInfraGeneratorSchema,\n): Promise<GeneratorCallback> {\n const lib = getTsLibDetails(tree, schema);\n\n const isNewProject = !projectExists(tree, lib.fullyQualifiedName);\n if (isNewProject) {\n await tsProjectGenerator(tree, {\n ...schema,\n preferInstallDependencies: false,\n });\n }\n\n // CDK shells out to a container engine to build image assets. Default\n // (docker) needs no env override; finch is set via CDK_DOCKER per\n // https://docs.aws.amazon.com/cdk/v2/guide/build-containers.html#build-container-replace.\n const containers = await resolveContainers(tree, 'inherit');\n const cdkEnv: Record<string, string> | undefined =\n containers === 'docker' ? undefined : { CDK_DOCKER: containers };\n const withCdkEnv = <T extends Record<string, unknown>>(opts: T): T => {\n if (!cdkEnv) return opts;\n const existingEnv = (opts.env as Record<string, string> | undefined) ?? {};\n return { ...opts, env: { ...existingEnv, ...cdkEnv } } as T;\n };\n\n // This generator IS the CDK infrastructure project, so the provider is fixed.\n addGeneratorMetadata(tree, lib.fullyQualifiedName, INFRA_APP_GENERATOR_INFO, {\n iac: 'cdk',\n });\n\n // Shared constructs always in CDK for typescript infra generator\n await sharedConstructsGenerator(\n tree,\n {\n iac: 'cdk',\n },\n DEPENDENCIES,\n );\n\n // Shared infra-config and infra-scripts packages (lazy creation, only when enabled)\n const stageConfig = schema.stageConfig ?? false;\n if (stageConfig) {\n await sharedInfraConfigGenerator(tree);\n await sharedInfraScriptsGenerator(tree, DEPENDENCIES);\n }\n\n const synthDirFromRoot = `/dist/${lib.dir}/cdk.out`;\n const synthDirFromProject =\n lib.dir\n .split('/')\n .map(() => '..')\n .join('/') + `/dist/${lib.dir}/cdk.out`;\n const distDirFromProjectRoot =\n lib.dir\n .split('/')\n .map(() => '..')\n .join('/') + '/dist/{projectRoot}/cdk.out';\n const projectConfig = readProjectConfiguration(tree, lib.fullyQualifiedName);\n const libraryRoot = projectConfig.root;\n const npmScopePrefix = getNpmScopePrefix(tree);\n const scopeAlias = npmScopePrefix;\n const fullyQualifiedName = `${npmScopePrefix}${schema.name}`;\n const namespace = kebabCase(fullyQualifiedName);\n // The stage instantiated in main.ts. Quoted so the shell does not glob `*`.\n const sandboxStagePattern = `\"${namespace}-sandbox/*\"`;\n\n // `tsProjectGenerator` scaffolds a library `src`, which the CDK app layout\n // replaces. Only on creation — on a re-run this is the user's infrastructure.\n if (isNewProject) {\n tree.delete(joinPathFragments(libraryRoot, 'src'));\n }\n\n // The guide walks through declaring resources in\n // `src/stacks/application-stack.ts` and adding stages to `src/main.ts`, so\n // everything here is scaffolded once and then left alone.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, './files/app'),\n libraryRoot,\n {\n synthDir: synthDirFromProject,\n scopeAlias: scopeAlias,\n namespace,\n fullyQualifiedName,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n dir: lib.dir,\n stageConfig,\n ...schema,\n ...esmVars(tree),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n updateJson(\n tree,\n `${libraryRoot}/project.json`,\n (config: ProjectConfiguration) => {\n config.projectType = 'application';\n // `synth` is the CDK artifact, so it belongs on `assemble` too; `checkov`\n // is a quality gate, so it stays on `build` alone.\n addArtifactDependencyToTargets(config, 'synth');\n addDependencyToTargetIfNotPresent(config, 'build', 'checkov');\n config.targets.compile.outputs = [\n '{workspaceRoot}/dist/{projectRoot}/tsc',\n ];\n config.targets.synth = {\n cache: true,\n executor: 'nx:run-commands',\n inputs: ['default'],\n outputs: ['{workspaceRoot}/dist/{projectRoot}/cdk.out'],\n dependsOn: ['^assemble', 'compile'], // compile clobbers dist directory, so ensure synth runs afterwards\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk synth',\n }),\n };\n // `default` rather than the synth directory: `dist` is gitignored, so a\n // fileset input pointed at it matches no tracked file and hashes to a\n // constant — the scan would cache-hit forever and pass on infrastructure\n // it never read. `default` carries the project's own sources plus the\n // transitive `dependentTasksOutputFiles` entry, which resolves against\n // the upstream `synth` task and so hashes the template actually scanned.\n config.targets.checkov = {\n cache: true,\n executor: 'nx:run-commands',\n inputs: ['default'],\n outputs: ['{workspaceRoot}/dist/{projectRoot}/checkov'],\n dependsOn: ['synth'],\n options: {\n command: uvxCommand(\n 'checkov',\n '--config-file {projectRoot}/checkov.yml --directory dist/{projectRoot}/cdk.out --framework cloudformation',\n ),\n },\n };\n config.targets.deploy = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n // No --express: this target deploys whichever stage is named, including\n // beta and prod, so it waits for full resource stabilization. Express\n // mode belongs to `deploy-sandbox`, which only ever deploys a sandbox.\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-deploy.ts ${libraryRoot}`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk deploy --require-approval=never',\n }),\n };\n config.targets['deploy-sandbox'] = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-deploy.ts ${libraryRoot} ${sandboxStagePattern} --express`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk deploy --require-approval=never ${sandboxStagePattern} --express`,\n }),\n };\n config.targets['deploy-ci'] = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk deploy --require-approval=never --app ${distDirFromProjectRoot}`,\n }),\n };\n config.targets.destroy = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-destroy.ts ${libraryRoot}`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk destroy',\n }),\n };\n config.targets['destroy-sandbox'] = {\n executor: 'nx:run-commands',\n dependsOn: ['^assemble', 'compile'],\n options: stageConfig\n ? withCdkEnv({\n command: `tsx packages/common/scripts/src/infra/infra-destroy.ts ${libraryRoot} ${sandboxStagePattern}`,\n })\n : withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk destroy ${sandboxStagePattern}`,\n }),\n };\n config.targets['destroy-ci'] = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: `cdk destroy --app ${distDirFromProjectRoot}`,\n }),\n };\n config.targets.cdk = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk',\n }),\n };\n config.targets.bootstrap = {\n executor: 'nx:run-commands',\n options: withCdkEnv({\n cwd: '{projectRoot}',\n command: 'cdk bootstrap',\n }),\n };\n config.targets = sortObjectKeys(config.targets);\n return config;\n },\n );\n\n addTsDependencies(tree, DEPENDENCIES, { projectRoot: libraryRoot });\n\n updateJson(tree, `${libraryRoot}/tsconfig.lib.json`, (tsConfig) => ({\n ...tsConfig,\n references: mergeTsReferences(tsConfig.references, [\n {\n path: `${path.relative(\n libraryRoot,\n `${tree.root}/${PACKAGES_DIR}`,\n )}/${SHARED_CONSTRUCTS_DIR}/tsconfig.lib.json`,\n },\n ...(stageConfig\n ? [\n {\n path: `${path.relative(\n libraryRoot,\n `${tree.root}/${PACKAGES_DIR}`,\n )}/${SHARED_INFRA_CONFIG_DIR}/tsconfig.json`,\n },\n ]\n : []),\n ]),\n }));\n\n // `main.ts` and the application stack import the shared constructs.\n addLocalProjectDependency(tree, {\n consumerRoot: libraryRoot,\n dependencyRoot: joinPathFragments(PACKAGES_DIR, SHARED_CONSTRUCTS_DIR),\n });\n if (stageConfig) {\n addLocalProjectDependency(tree, {\n consumerRoot: libraryRoot,\n dependencyRoot: joinPathFragments(PACKAGES_DIR, SHARED_INFRA_CONFIG_DIR),\n });\n }\n\n await addGeneratorMetricsIfApplicable(tree, [INFRA_APP_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n}\nexport default tsInfraGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","path","tsProjectGenerator","getTsLibDetails","mergeTsReferences","addTsDependencies","resolveContainers","declareDependencies","ownedElsewhere","formatFilesInSubtree","installDependencies","addLocalProjectDependency","addGeneratorMetricsIfApplicable","esmVars","kebabCase","getNpmScopePrefix","addArtifactDependencyToTargets","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","uvxCommand","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_INFRA_CONFIG_DIR","sharedInfraConfigGenerator","SHARED_INFRA_SCRIPTS_DEPENDENCIES","sharedInfraScriptsGenerator","DEPENDENCIES","ts","name","dev","root","INFRA_APP_GENERATOR_INFO","filename","tsInfraGenerator","tree","schema","lib","isNewProject","fullyQualifiedName","preferInstallDependencies","containers","cdkEnv","undefined","CDK_DOCKER","withCdkEnv","opts","existingEnv","env","iac","stageConfig","synthDirFromRoot","dir","synthDirFromProject","split","map","join","distDirFromProjectRoot","projectConfig","libraryRoot","npmScopePrefix","scopeAlias","namespace","sandboxStagePattern","delete","dirname","synthDir","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","config","projectType","targets","compile","outputs","synth","cache","executor","inputs","dependsOn","options","cwd","command","checkov","deploy","destroy","cdk","bootstrap","projectRoot","tsConfig","references","relative","consumerRoot","dependencyRoot","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,wBAAwB,EAExBC,UAAU,QACL,aAAa;AACpB,OAAOC,UAAU,OAAO;AACxB,OAAOC,sBAAsBC,eAAe,QAAQ,4BAA4B;AAChF,SAASC,iBAAiB,QAAQ,mCAAmC;AACrE,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,yBAAyB,QAAQ,0CAA0C;AACpF,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SACEC,8BAA8B,EAC9BC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,gCAAgC,QAAQ,6BAA6B;AAC9E,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAmC;AAC1C,SACEC,YAAY,EACZC,qBAAqB,EACrBC,uBAAuB,QAClB,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Y,kBAAkB,CAAC,EAAE,CAAC+B,WAAc,CAAA;YAClE,GAAGA,QAAQ;YACXC,YAAY5F,kBAAkB2F,SAASC,UAAU,EAAE;gBACjD;oBACE/F,MAAM,GAAGA,KAAKgG,QAAQ,CACpBjC,aACA,GAAGxB,KAAKJ,IAAI,CAAC,CAAC,EAAEV,cAAc,EAC9B,CAAC,EAAEC,sBAAsB,kBAAkB,CAAC;gBAChD;mBACI4B,cACA;oBACE;wBACEtD,MAAM,GAAGA,KAAKgG,QAAQ,CACpBjC,aACA,GAAGxB,KAAKJ,IAAI,CAAC,CAAC,EAAEV,cAAc,EAC9B,CAAC,EAAEE,wBAAwB,cAAc,CAAC;oBAC9C;iBACD,GACD,EAAE;aACP;QACH,CAAA;IAEA,oEAAoE;IACpEjB,0BAA0B6B,MAAM;QAC9B0D,cAAclC;QACdmC,gBAAgBtG,kBAAkB6B,cAAcC;IAClD;IACA,IAAI4B,aAAa;QACf5C,0BAA0B6B,MAAM;YAC9B0D,cAAclC;YACdmC,gBAAgBtG,kBAAkB6B,cAAcE;QAClD;IACF;IAEA,MAAMhB,gCAAgC4B,MAAM;QAACH;KAAyB;IAEtE,MAAM5B,qBAAqB+B;IAC3B,OAAO,IACL9B,oBAAoB8B,MAAMC,OAAOI,yBAAyB,EAAE;YAC1DuD,WAAW;gBAAC;aAAa;QAC3B;AACJ;AACA,eAAe7D,iBAAiB"}
|
package/src/init/generator.d.ts
CHANGED
|
@@ -27,5 +27,5 @@ export declare const INIT_GENERATOR_INFO: NxGeneratorInfo;
|
|
|
27
27
|
* their workspace. Every step is idempotent — re-running against an
|
|
28
28
|
* already-initialised workspace is a safe no-op.
|
|
29
29
|
*/
|
|
30
|
-
export declare const initGenerator: (tree: Tree, { iac, mcp, containers, preferInstallDependencies }: InitGeneratorSchema) => Promise<GeneratorCallback>;
|
|
30
|
+
export declare const initGenerator: (tree: Tree, { iac, mcp, containers, gitSecrets, preferInstallDependencies, }: InitGeneratorSchema) => Promise<GeneratorCallback>;
|
|
31
31
|
export default initGenerator;
|
package/src/init/generator.js
CHANGED
|
@@ -3,17 +3,16 @@
|
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/ import { declareDependencies } from "../utils/declared-dependencies.js";
|
|
5
5
|
import { formatFilesInSubtree } from "../utils/format.js";
|
|
6
|
+
import { GIT_SECRETS_DEPENDENCIES, setUpGitSecrets } from "../utils/git-secrets.js";
|
|
6
7
|
import { applyWorkspaceInit, INIT_DEPENDENCIES } from "../utils/init.js";
|
|
7
8
|
import { installDependencies } from "../utils/install.js";
|
|
8
9
|
import { addGeneratorMetricsIfApplicable } from "../utils/metrics.js";
|
|
9
10
|
import { getGeneratorInfo } from "../utils/nx.js";
|
|
10
|
-
// `husky`
|
|
11
|
-
//
|
|
11
|
+
// `husky` is owned here rather than by the preset: both mark the workspace by
|
|
12
|
+
// writing aws-nx-plugin.config.mts, and only init has an id there.
|
|
12
13
|
export const DEPENDENCIES = declareDependencies()({
|
|
13
14
|
ts: [
|
|
14
|
-
|
|
15
|
-
name: 'husky'
|
|
16
|
-
},
|
|
15
|
+
...GIT_SECRETS_DEPENDENCIES,
|
|
17
16
|
...INIT_DEPENDENCIES
|
|
18
17
|
]
|
|
19
18
|
});
|
|
@@ -25,12 +24,15 @@ export const INIT_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
25
24
|
* with an established Nx workspace can adopt the plugin without recreating
|
|
26
25
|
* their workspace. Every step is idempotent — re-running against an
|
|
27
26
|
* already-initialised workspace is a safe no-op.
|
|
28
|
-
*/ export const initGenerator = async (tree, { iac, mcp, containers, preferInstallDependencies })=>{
|
|
27
|
+
*/ export const initGenerator = async (tree, { iac, mcp, containers, gitSecrets, preferInstallDependencies })=>{
|
|
29
28
|
await applyWorkspaceInit(tree, {
|
|
30
29
|
iac,
|
|
31
30
|
containers,
|
|
32
31
|
mcp
|
|
33
32
|
}, DEPENDENCIES);
|
|
33
|
+
if (gitSecrets !== false) {
|
|
34
|
+
setUpGitSecrets(tree, DEPENDENCIES);
|
|
35
|
+
}
|
|
34
36
|
await addGeneratorMetricsIfApplicable(tree, [
|
|
35
37
|
INIT_GENERATOR_INFO
|
|
36
38
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/init/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { GeneratorCallback, Tree } from '@nx/devkit';\nimport { declareDependencies } from '../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../utils/format.js';\nimport { applyWorkspaceInit, INIT_DEPENDENCIES } from '../utils/init.js';\nimport { installDependencies } from '../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../utils/metrics.js';\nimport { getGeneratorInfo, type NxGeneratorInfo } from '../utils/nx.js';\nimport type { InitGeneratorSchema } from './schema';\n\n// `husky`
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/init/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { GeneratorCallback, Tree } from '@nx/devkit';\nimport { declareDependencies } from '../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../utils/format.js';\nimport {\n GIT_SECRETS_DEPENDENCIES,\n setUpGitSecrets,\n} from '../utils/git-secrets.js';\nimport { applyWorkspaceInit, INIT_DEPENDENCIES } from '../utils/init.js';\nimport { installDependencies } from '../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../utils/metrics.js';\nimport { getGeneratorInfo, type NxGeneratorInfo } from '../utils/nx.js';\nimport type { InitGeneratorSchema } from './schema';\n\n// `husky` is owned here rather than by the preset: both mark the workspace by\n// writing aws-nx-plugin.config.mts, and only init has an id there.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...GIT_SECRETS_DEPENDENCIES, ...INIT_DEPENDENCIES],\n});\n\nexport const INIT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Configure an existing Nx workspace to use the @aws/nx-plugin.\n *\n * Runs the same deterministic setup the workspace preset performs, so teams\n * with an established Nx workspace can adopt the plugin without recreating\n * their workspace. Every step is idempotent — re-running against an\n * already-initialised workspace is a safe no-op.\n */\nexport const initGenerator = async (\n tree: Tree,\n {\n iac,\n mcp,\n containers,\n gitSecrets,\n preferInstallDependencies,\n }: InitGeneratorSchema,\n): Promise<GeneratorCallback> => {\n await applyWorkspaceInit(tree, { iac, containers, mcp }, DEPENDENCIES);\n\n if (gitSecrets !== false) {\n setUpGitSecrets(tree, DEPENDENCIES);\n }\n\n await addGeneratorMetricsIfApplicable(tree, [INIT_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default initGenerator;\n"],"names":["declareDependencies","formatFilesInSubtree","GIT_SECRETS_DEPENDENCIES","setUpGitSecrets","applyWorkspaceInit","INIT_DEPENDENCIES","installDependencies","addGeneratorMetricsIfApplicable","getGeneratorInfo","DEPENDENCIES","ts","INIT_GENERATOR_INFO","filename","initGenerator","tree","iac","mcp","containers","gitSecrets","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GAED,SAASA,mBAAmB,QAAQ,oCAAoC;AACxE,SAASC,oBAAoB,QAAQ,qBAAqB;AAC1D,SACEC,wBAAwB,EACxBC,eAAe,QACV,0BAA0B;AACjC,SAASC,kBAAkB,EAAEC,iBAAiB,QAAQ,mBAAmB;AACzE,SAASC,mBAAmB,QAAQ,sBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,sBAAsB;AACtE,SAASC,gBAAgB,QAA8B,iBAAiB;AAGxE,8EAA8E;AAC9E,mEAAmE;AACnE,OAAO,MAAMC,eAAeT,sBAAsB;IAChDU,IAAI;WAAIR;WAA6BG;KAAkB;AACzD,GAAG;AAEH,OAAO,MAAMM,sBAAuCH,iBAClD,YAAYI,QAAQ,EACpB;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMC,gBAAgB,OAC3BC,MACA,EACEC,GAAG,EACHC,GAAG,EACHC,UAAU,EACVC,UAAU,EACVC,yBAAyB,EACL;IAEtB,MAAMf,mBAAmBU,MAAM;QAAEC;QAAKE;QAAYD;IAAI,GAAGP;IAEzD,IAAIS,eAAe,OAAO;QACxBf,gBAAgBW,MAAML;IACxB;IAEA,MAAMF,gCAAgCO,MAAM;QAACH;KAAoB;IAEjE,MAAMV,qBAAqBa;IAC3B,OAAO,IACLR,oBAAoBQ,MAAMK,2BAA2B;YACnDC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAeP,cAAc"}
|
package/src/init/schema.d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/init/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Containers } from '../utils/containers.js';\nimport { Iac } from '../utils/iac.js';\n\nexport type InitContainersOption = Containers | 'infer';\n\nexport interface InitGeneratorSchema {\n readonly iac: Iac;\n readonly mcp?: boolean;\n readonly containers?: InitContainersOption;\n readonly preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAOD,
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/init/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Containers } from '../utils/containers.js';\nimport { Iac } from '../utils/iac.js';\n\nexport type InitContainersOption = Containers | 'infer';\n\nexport interface InitGeneratorSchema {\n readonly iac: Iac;\n readonly mcp?: boolean;\n readonly containers?: InitContainersOption;\n readonly gitSecrets?: boolean;\n readonly preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAOD,WAMC"}
|
package/src/init/schema.d.ts
CHANGED
package/src/init/schema.json
CHANGED
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"x-priority": "important",
|
|
14
14
|
"x-prompt": "Which provider would you like to manage your infrastructure?"
|
|
15
15
|
},
|
|
16
|
+
"gitSecrets": {
|
|
17
|
+
"type": "boolean",
|
|
18
|
+
"description": "Whether to configure git-secrets to prevent committing AWS credentials.",
|
|
19
|
+
"default": true
|
|
20
|
+
},
|
|
16
21
|
"mcp": {
|
|
17
22
|
"type": "boolean",
|
|
18
23
|
"description": "Whether to configure the Nx Plugin for AWS MCP server for use by coding agents.",
|