@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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/infra-deploy-express-mode/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n getProjects,\n type MigrationReturnObject,\n type TargetConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { INFRA_APP_GENERATOR_INFO } from '../../../infra/app/generator.js';\nimport { formatFilesInSubtree } from '../../../utils/format.js';\n\n/**\n * Deploy using CloudFormation express mode from the deploy
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/infra-deploy-express-mode/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n getProjects,\n type MigrationReturnObject,\n type TargetConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { INFRA_APP_GENERATOR_INFO } from '../../../infra/app/generator.js';\nimport { formatFilesInSubtree } from '../../../utils/format.js';\n\n/**\n * Deploy using CloudFormation express mode from the deploy-sandbox target of\n * ts#infra projects, and wait for full stabilization everywhere else.\n *\n * Express mode completes each resource operation as soon as its configuration is\n * applied rather than waiting for full stabilization, which is a much faster\n * iteration cycle for development deploys. It returns before resources have\n * settled, so it suits only the stage you iterate on.\n *\n * `deploy-sandbox` therefore gets it, since it only ever deploys the sandbox\n * stage. `deploy` names whichever stage you give it, including beta and prod, and\n * `deploy-ci` runs from a pipeline - both wait for full stabilization.\n */\n\nconst EXPRESS_FLAG = '--express';\nconst NO_EXPRESS_FLAG = '--no-express';\n\n/** Whether `deploy-sandbox` should carry the flag, and `deploy` should not. */\nconst WANTS_EXPRESS: Record<string, boolean> = {\n 'deploy-sandbox': true,\n deploy: false,\n};\n\n/**\n * Whether the command is one of the deploy commands this migration vends -\n * either a direct `cdk deploy`, or the stage-config `infra-deploy.ts` script\n * that wraps it. Anything else has been hand-written and is reported rather\n * than rewritten.\n */\nconst isGeneratedDeployCommand = (command: string): boolean =>\n /(^|\\s)cdk\\s+deploy(\\s|$)/.test(command) ||\n command.includes('infra-deploy.ts');\n\nconst divergedNextStep = (\n projectName: string,\n target: string,\n wantsExpress: boolean,\n): string =>\n wantsExpress\n ? `${projectName}: its ${target} target has been customised, so it was left as it is. Add \"${EXPRESS_FLAG}\" to the target's command to deploy using CloudFormation express mode.`\n : `${projectName}: its ${target} target has been customised, so it was left as it is. Remove \"${EXPRESS_FLAG}\" from the target's command so it waits for full resource stabilization - this target can name any stage, including production.`;\n\n/** Drops the flag wherever it sits, leaving the rest of the command untouched. */\nconst withoutExpress = (command: string): string =>\n command\n .split(/\\s+/)\n .filter((arg) => arg !== EXPRESS_FLAG)\n .join(' ');\n\nexport default async function migration(\n tree: Tree,\n): Promise<MigrationReturnObject> {\n const nextSteps: string[] = [];\n let migrated = false;\n\n for (const [name, project] of getProjects(tree)) {\n if (\n (project.metadata as { generator?: string } | undefined)?.generator !==\n INFRA_APP_GENERATOR_INFO.id\n ) {\n continue;\n }\n\n let projectChanged = false;\n\n for (const [targetName, wantsExpress] of Object.entries(WANTS_EXPRESS)) {\n const target: TargetConfiguration | undefined =\n project.targets?.[targetName];\n const command = target?.options?.command;\n if (!target || typeof command !== 'string') {\n continue;\n }\n\n const args = command.split(/\\s+/);\n const hasExpress = args.includes(EXPRESS_FLAG);\n\n // Already in the wanted state, so re-running - and a project generated\n // after this change - is a no-op.\n if (hasExpress === wantsExpress) {\n continue;\n }\n\n // `--no-express` is a deliberate opt-out, so honour it rather than\n // flipping the user back to express mode.\n if (wantsExpress && args.includes(NO_EXPRESS_FLAG)) {\n continue;\n }\n\n if (!isGeneratedDeployCommand(command)) {\n nextSteps.push(divergedNextStep(name, targetName, wantsExpress));\n continue;\n }\n\n // Appended last so it stays clear of the stage pattern, which the\n // stage-config deploy script reads from the first positional argument.\n target.options.command = wantsExpress\n ? `${command} ${EXPRESS_FLAG}`\n : withoutExpress(command);\n projectChanged = true;\n }\n\n if (projectChanged) {\n updateProjectConfiguration(tree, name, project);\n migrated = true;\n }\n }\n\n if (migrated) {\n await formatFilesInSubtree(tree);\n }\n\n return { nextSteps };\n}\n"],"names":["getProjects","updateProjectConfiguration","INFRA_APP_GENERATOR_INFO","formatFilesInSubtree","EXPRESS_FLAG","NO_EXPRESS_FLAG","WANTS_EXPRESS","deploy","isGeneratedDeployCommand","command","test","includes","divergedNextStep","projectName","target","wantsExpress","withoutExpress","split","filter","arg","join","migration","tree","nextSteps","migrated","name","project","metadata","generator","id","projectChanged","targetName","Object","entries","targets","options","args","hasExpress","push"],"mappings":"AAAA;;;CAGC,GACD,SACEA,WAAW,EAIXC,0BAA0B,QACrB,aAAa;AACpB,SAASC,wBAAwB,QAAQ,kCAAkC;AAC3E,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE;;;;;;;;;;;;CAYC,GAED,MAAMC,eAAe;AACrB,MAAMC,kBAAkB;AAExB,6EAA6E,GAC7E,MAAMC,gBAAyC;IAC7C,kBAAkB;IAClBC,QAAQ;AACV;AAEA;;;;;CAKC,GACD,MAAMC,2BAA2B,CAACC,UAChC,2BAA2BC,IAAI,CAACD,YAChCA,QAAQE,QAAQ,CAAC;AAEnB,MAAMC,mBAAmB,CACvBC,aACAC,QACAC,eAEAA,eACI,GAAGF,YAAY,MAAM,EAAEC,OAAO,2DAA2D,EAAEV,aAAa,sEAAsE,CAAC,GAC/K,GAAGS,YAAY,MAAM,EAAEC,OAAO,8DAA8D,EAAEV,aAAa,+HAA+H,CAAC;AAEjP,gFAAgF,GAChF,MAAMY,iBAAiB,CAACP,UACtBA,QACGQ,KAAK,CAAC,OACNC,MAAM,CAAC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
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type MigrationReturnObject, type Tree } from '@nx/devkit';
|
|
6
|
+
export default function migration(tree: Tree): Promise<MigrationReturnObject>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { getProjects, joinPathFragments } from "@nx/devkit";
|
|
5
|
+
import { LAMBDA_FUNCTION_GENERATOR_INFO } from "../../../py/lambda-function/generator.js";
|
|
6
|
+
import { applyGritQL, matchGritQL } from "../../../utils/ast.js";
|
|
7
|
+
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
8
|
+
/**
|
|
9
|
+
* Wire powertools Lambda context injection and the cold start metric into
|
|
10
|
+
* handlers generated by py#lambda-function.
|
|
11
|
+
*
|
|
12
|
+
* `@logger.inject_lambda_context` is what annotates each log record with the
|
|
13
|
+
* function name, request id, memory size and cold start flag, and
|
|
14
|
+
* `capture_cold_start_metric` is what emits the `ColdStart` metric.
|
|
15
|
+
*
|
|
16
|
+
* Both rewrites are scoped to the decorator list of the `lambda_handler`
|
|
17
|
+
* definition, so a `@metrics.log_metrics` decorating another function in the
|
|
18
|
+
* same module is left alone.
|
|
19
|
+
*/ const INJECT_CONTEXT = '@logger.inject_lambda_context';
|
|
20
|
+
const LOG_METRICS_OLD = '@metrics.log_metrics';
|
|
21
|
+
const LOG_METRICS_NEW = '@metrics.log_metrics(capture_cold_start_metric=True)';
|
|
22
|
+
const HANDLER_DECORATORS = (body)=>`language python
|
|
23
|
+
decorated_definition($decorators, $definition) where {
|
|
24
|
+
$definition <: contains \`lambda_handler\`,
|
|
25
|
+
${body}
|
|
26
|
+
}`;
|
|
27
|
+
/** The shape the generator produces: a bare `log_metrics` below the tracer. */ const GENERATED_SHAPE = HANDLER_DECORATORS(`$decorators <: contains \`@tracer.capture_lambda_handler\`,
|
|
28
|
+
$decorators <: contains \`${LOG_METRICS_OLD}\``);
|
|
29
|
+
const ALREADY_MIGRATED = HANDLER_DECORATORS(`$decorators <: contains \`${INJECT_CONTEXT}\`,
|
|
30
|
+
$decorators <: contains \`${LOG_METRICS_NEW}\``);
|
|
31
|
+
const REWRITE = HANDLER_DECORATORS(`$decorators <: contains \`@tracer.capture_lambda_handler\` => raw\`@tracer.capture_lambda_handler
|
|
32
|
+
${INJECT_CONTEXT}\`,
|
|
33
|
+
$decorators <: contains \`${LOG_METRICS_OLD}\` => \`${LOG_METRICS_NEW}\``);
|
|
34
|
+
const migrateHandler = async (tree, handlerPath, nextSteps)=>{
|
|
35
|
+
if (!tree.exists(handlerPath)) return;
|
|
36
|
+
if (await matchGritQL(tree, handlerPath, ALREADY_MIGRATED)) return;
|
|
37
|
+
if (!await matchGritQL(tree, handlerPath, GENERATED_SHAPE)) {
|
|
38
|
+
nextSteps.push(`${handlerPath}: diverged from the generated py#lambda-function shape - left untouched. To annotate logs with the Lambda context and emit a ColdStart metric, add \`${INJECT_CONTEXT}\` to the handler and change \`${LOG_METRICS_OLD}\` to \`${LOG_METRICS_NEW}\`.`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
await applyGritQL(tree, handlerPath, REWRITE);
|
|
42
|
+
};
|
|
43
|
+
export default async function migration(tree) {
|
|
44
|
+
const nextSteps = [];
|
|
45
|
+
for (const project of getProjects(tree).values()){
|
|
46
|
+
const components = (project.metadata?.components ?? []).filter((component)=>component.generator === LAMBDA_FUNCTION_GENERATOR_INFO.id);
|
|
47
|
+
for (const component of components){
|
|
48
|
+
if (!component.path) continue;
|
|
49
|
+
await migrateHandler(tree, joinPathFragments(project.root, component.path), nextSteps);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
await formatFilesInSubtree(tree);
|
|
53
|
+
return {
|
|
54
|
+
nextSteps
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/py-lambda-powertools-context/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n getProjects,\n joinPathFragments,\n type MigrationReturnObject,\n type Tree,\n} from '@nx/devkit';\nimport { LAMBDA_FUNCTION_GENERATOR_INFO } from '../../../py/lambda-function/generator.js';\nimport { applyGritQL, matchGritQL } from '../../../utils/ast.js';\nimport { formatFilesInSubtree } from '../../../utils/format.js';\nimport type { ComponentMetadata } from '../../../utils/nx.js';\n\n/**\n * Wire powertools Lambda context injection and the cold start metric into\n * handlers generated by py#lambda-function.\n *\n * `@logger.inject_lambda_context` is what annotates each log record with the\n * function name, request id, memory size and cold start flag, and\n * `capture_cold_start_metric` is what emits the `ColdStart` metric.\n *\n * Both rewrites are scoped to the decorator list of the `lambda_handler`\n * definition, so a `@metrics.log_metrics` decorating another function in the\n * same module is left alone.\n */\nconst INJECT_CONTEXT = '@logger.inject_lambda_context';\nconst LOG_METRICS_OLD = '@metrics.log_metrics';\nconst LOG_METRICS_NEW = '@metrics.log_metrics(capture_cold_start_metric=True)';\n\nconst HANDLER_DECORATORS = (body: string) => `language python\ndecorated_definition($decorators, $definition) where {\n $definition <: contains \\`lambda_handler\\`,\n ${body}\n}`;\n\n/** The shape the generator produces: a bare `log_metrics` below the tracer. */\nconst GENERATED_SHAPE =\n HANDLER_DECORATORS(`$decorators <: contains \\`@tracer.capture_lambda_handler\\`,\n $decorators <: contains \\`${LOG_METRICS_OLD}\\``);\n\nconst ALREADY_MIGRATED =\n HANDLER_DECORATORS(`$decorators <: contains \\`${INJECT_CONTEXT}\\`,\n $decorators <: contains \\`${LOG_METRICS_NEW}\\``);\n\nconst REWRITE =\n HANDLER_DECORATORS(`$decorators <: contains \\`@tracer.capture_lambda_handler\\` => raw\\`@tracer.capture_lambda_handler\n${INJECT_CONTEXT}\\`,\n $decorators <: contains \\`${LOG_METRICS_OLD}\\` => \\`${LOG_METRICS_NEW}\\``);\n\nconst migrateHandler = async (\n tree: Tree,\n handlerPath: string,\n nextSteps: string[],\n): Promise<void> => {\n if (!tree.exists(handlerPath)) return;\n\n if (await matchGritQL(tree, handlerPath, ALREADY_MIGRATED)) return;\n\n if (!(await matchGritQL(tree, handlerPath, GENERATED_SHAPE))) {\n nextSteps.push(\n `${handlerPath}: diverged from the generated py#lambda-function shape - left untouched. To annotate logs with the Lambda context and emit a ColdStart metric, add \\`${INJECT_CONTEXT}\\` to the handler and change \\`${LOG_METRICS_OLD}\\` to \\`${LOG_METRICS_NEW}\\`.`,\n );\n return;\n }\n\n await applyGritQL(tree, handlerPath, REWRITE);\n};\n\nexport default async function migration(\n tree: Tree,\n): Promise<MigrationReturnObject> {\n const nextSteps: string[] = [];\n\n for (const project of getProjects(tree).values()) {\n const components = (\n (project.metadata as { components?: ComponentMetadata[] })?.components ??\n []\n ).filter(\n (component) => component.generator === LAMBDA_FUNCTION_GENERATOR_INFO.id,\n );\n\n for (const component of components) {\n if (!component.path) continue;\n await migrateHandler(\n tree,\n joinPathFragments(project.root, component.path),\n nextSteps,\n );\n }\n }\n\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n}\n"],"names":["getProjects","joinPathFragments","LAMBDA_FUNCTION_GENERATOR_INFO","applyGritQL","matchGritQL","formatFilesInSubtree","INJECT_CONTEXT","LOG_METRICS_OLD","LOG_METRICS_NEW","HANDLER_DECORATORS","body","GENERATED_SHAPE","ALREADY_MIGRATED","REWRITE","migrateHandler","tree","handlerPath","nextSteps","exists","push","migration","project","values","components","metadata","filter","component","generator","id","path","root"],"mappings":"AAAA;;;CAGC,GACD,SACEA,WAAW,EACXC,iBAAiB,QAGZ,aAAa;AACpB,SAASC,8BAA8B,QAAQ,2CAA2C;A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,EAAE;YACrB,MAAMf,eACJC,MACAd,kBAAkBoB,QAAQS,IAAI,EAAEJ,UAAUG,IAAI,GAC9CZ;QAEJ;IACF;IAEA,MAAMZ,qBAAqBU;IAE3B,OAAO;QAAEE;IAAU;AACrB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type MigrationReturnObject, type Tree } from '@nx/devkit';
|
|
6
|
+
export default function migration(tree: Tree): Promise<MigrationReturnObject>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { getProjects, joinPathFragments, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
+
import { AGENTCORE_GATEWAY_GENERATOR_INFO } from "../../../agentcore-gateway/generator.js";
|
|
6
|
+
import { AGENTCORE_HARNESS_GENERATOR_INFO } from "../../../agentcore-harness/generator.js";
|
|
7
|
+
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
8
|
+
import { addScriptProjectTargets } from "../../../utils/script-project-targets.js";
|
|
9
|
+
/**
|
|
10
|
+
* AgentCore Gateway and Harness projects host TypeScript that runs through
|
|
11
|
+
* `tsx` — a Gateway's `local-dev.ts` (which the connection generators edit) and
|
|
12
|
+
* a Harness's `scripts/chat.ts`. Neither project had a `tsconfig.json` or a
|
|
13
|
+
* `build`, `lint`, `format` or `typecheck` target, so that code was invisible to
|
|
14
|
+
* `nx run-many --target build --all` and a type error in it only surfaced at
|
|
15
|
+
* runtime.
|
|
16
|
+
*
|
|
17
|
+
* How to write a migration:
|
|
18
|
+
* - https://nx.dev/docs/kb/migration-generators
|
|
19
|
+
* - What `nextSteps` means: https://nx.dev/docs/reference/devkit/MigrationReturnObject
|
|
20
|
+
*/ /** The generators whose projects gain the gates. */ const SCRIPT_PROJECT_GENERATORS = [
|
|
21
|
+
AGENTCORE_GATEWAY_GENERATOR_INFO.id,
|
|
22
|
+
AGENTCORE_HARNESS_GENERATOR_INFO.id
|
|
23
|
+
];
|
|
24
|
+
export default async function migration(tree) {
|
|
25
|
+
const nextSteps = [];
|
|
26
|
+
for (const [, project] of getProjects(tree)){
|
|
27
|
+
const generator = project.metadata?.generator;
|
|
28
|
+
if (!generator || !SCRIPT_PROJECT_GENERATORS.includes(generator)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// Already migrated (or the user added their own gates).
|
|
32
|
+
if (project.targets?.typecheck) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// A project that has been reworked into a compiled `ts#project` owns its own
|
|
36
|
+
// tsconfig graph, so leave it alone rather than layering a `noEmit` config on
|
|
37
|
+
// top of one that emits.
|
|
38
|
+
if (tree.exists(joinPathFragments(project.root, 'tsconfig.lib.json'))) {
|
|
39
|
+
nextSteps.push(`Project '${project.name}' has a tsconfig.lib.json, so its quality gates were left as they are. Confirm its build covers the TypeScript at ${project.root}.`);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
addScriptProjectTargets(tree, {
|
|
43
|
+
project
|
|
44
|
+
});
|
|
45
|
+
updateProjectConfiguration(tree, project.name, project);
|
|
46
|
+
}
|
|
47
|
+
await formatFilesInSubtree(tree);
|
|
48
|
+
return {
|
|
49
|
+
nextSteps
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/script-project-quality-gates/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n getProjects,\n joinPathFragments,\n type MigrationReturnObject,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { AGENTCORE_GATEWAY_GENERATOR_INFO } from '../../../agentcore-gateway/generator.js';\nimport { AGENTCORE_HARNESS_GENERATOR_INFO } from '../../../agentcore-harness/generator.js';\nimport { formatFilesInSubtree } from '../../../utils/format.js';\nimport { addScriptProjectTargets } from '../../../utils/script-project-targets.js';\n\n/**\n * AgentCore Gateway and Harness projects host TypeScript that runs through\n * `tsx` — a Gateway's `local-dev.ts` (which the connection generators edit) and\n * a Harness's `scripts/chat.ts`. Neither project had a `tsconfig.json` or a\n * `build`, `lint`, `format` or `typecheck` target, so that code was invisible to\n * `nx run-many --target build --all` and a type error in it only surfaced at\n * runtime.\n *\n * How to write a migration:\n * - https://nx.dev/docs/kb/migration-generators\n * - What `nextSteps` means: https://nx.dev/docs/reference/devkit/MigrationReturnObject\n */\n\n/** The generators whose projects gain the gates. */\nconst SCRIPT_PROJECT_GENERATORS = [\n AGENTCORE_GATEWAY_GENERATOR_INFO.id,\n AGENTCORE_HARNESS_GENERATOR_INFO.id,\n];\n\nexport default async function migration(\n tree: Tree,\n): Promise<MigrationReturnObject> {\n const nextSteps: string[] = [];\n\n for (const [, project] of getProjects(tree)) {\n const generator = (project.metadata as { generator?: string } | undefined)\n ?.generator;\n if (!generator || !SCRIPT_PROJECT_GENERATORS.includes(generator)) {\n continue;\n }\n // Already migrated (or the user added their own gates).\n if (project.targets?.typecheck) {\n continue;\n }\n // A project that has been reworked into a compiled `ts#project` owns its own\n // tsconfig graph, so leave it alone rather than layering a `noEmit` config on\n // top of one that emits.\n if (tree.exists(joinPathFragments(project.root, 'tsconfig.lib.json'))) {\n nextSteps.push(\n `Project '${project.name}' has a tsconfig.lib.json, so its quality gates were left as they are. Confirm its build covers the TypeScript at ${project.root}.`,\n );\n continue;\n }\n\n addScriptProjectTargets(tree, { project });\n updateProjectConfiguration(tree, project.name, project);\n }\n\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n}\n"],"names":["getProjects","joinPathFragments","updateProjectConfiguration","AGENTCORE_GATEWAY_GENERATOR_INFO","AGENTCORE_HARNESS_GENERATOR_INFO","formatFilesInSubtree","addScriptProjectTargets","SCRIPT_PROJECT_GENERATORS","id","migration","tree","nextSteps","project","generator","metadata","includes","targets","typecheck","exists","root","push","name"],"mappings":"AAAA;;;CAGC,GACD,SACEA,WAAW,EACXC,iBAAiB,EAGjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gCAAgC,QAAQ,0CAA0C;AAC3F,SAASC,gCAAgC,QAAQ,0CAA0C;AAC3F,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,uBAAuB,QAAQ,2CAA2C;AAEnF;;;;;;;;;;;CAWC,GAED,kDAAkD,GAClD,MAAMC,4BAA4B;IAChCJ,iCAAiCK,EAAE;IACnCJ,iCAAiCI,EAAE;CACpC;AAED,eAAe,eAAeC,UAC5BC,IAAU;IAEV,MAAMC,YAAsB,EAAE;IAE9B,KAAK,MAAM,GAAGC,QAAQ,IAAIZ,YAAYU,MAAO;QAC3C,MAAMG,YAAaD,QAAQE,QAAQ,EAC/BD;QACJ,IAAI,CAACA,aAAa,CAACN,0BAA0BQ,QAAQ,CAACF,YAAY;YAChE;QACF;QACA,wDAAwD;QACxD,IAAID,QAAQI,OAAO,EAAEC,WAAW;YAC9B;QACF;QACA,6EAA6E;QAC7E,8EAA8E;QAC9E,yBAAyB;QACzB,IAAIP,KAAKQ,MAAM,CAACjB,kBAAkBW,QAAQO,IAAI,EAAE,uBAAuB;YACrER,UAAUS,IAAI,CACZ,CAAC,SAAS,EAAER,QAAQS,IAAI,CAAC,kHAAkH,EAAET,QAAQO,IAAI,CAAC,CAAC,CAAC;YAE9J;QACF;QAEAb,wBAAwBI,MAAM;YAAEE;QAAQ;QACxCV,2BAA2BQ,MAAME,QAAQS,IAAI,EAAET;IACjD;IAEA,MAAMP,qBAAqBK;IAE3B,OAAO;QAAEC;IAAU;AACrB"}
|
package/src/migrations/latest/smithy-extension-trait-aliases/__snapshots__/migration.spec.ts.snap
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`smithy-extension-trait-aliases migration > should alias every vended trait 1`] = `
|
|
4
|
+
"$version: "2.0"
|
|
5
|
+
|
|
6
|
+
namespace com.example
|
|
7
|
+
|
|
8
|
+
use smithy.openapi#specificationExtension
|
|
9
|
+
|
|
10
|
+
@trait
|
|
11
|
+
@specificationExtension(as: "x-query")
|
|
12
|
+
structure query {}
|
|
13
|
+
|
|
14
|
+
@trait
|
|
15
|
+
@specificationExtension(as: "x-mutation")
|
|
16
|
+
structure mutation {}
|
|
17
|
+
|
|
18
|
+
@trait
|
|
19
|
+
@specificationExtension(as: "x-cursor")
|
|
20
|
+
structure cursor {
|
|
21
|
+
inputToken: String
|
|
22
|
+
enabled: Boolean
|
|
23
|
+
}
|
|
24
|
+
"
|
|
25
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type MigrationReturnObject, type Tree } from '@nx/devkit';
|
|
6
|
+
/**
|
|
7
|
+
* Give each trait in a Smithy model's `extensions.smithy` an explicit
|
|
8
|
+
* `@specificationExtension(as: "...")` alias.
|
|
9
|
+
*
|
|
10
|
+
* Without the alias Smithy derives the OpenAPI key from the trait's shape id and
|
|
11
|
+
* emits a namespace-prefixed key (`x-<namespace>-query`), which the client code
|
|
12
|
+
* generator does not read — so the `@query`, `@mutation` and `@cursor` traits
|
|
13
|
+
* have no effect on the generated client. The alias pins each key to the
|
|
14
|
+
* unprefixed name the generator recognises.
|
|
15
|
+
*
|
|
16
|
+
* How to write a migration:
|
|
17
|
+
* - https://nx.dev/docs/kb/migration-generators
|
|
18
|
+
* - What `nextSteps` means: https://nx.dev/docs/reference/devkit/MigrationReturnObject
|
|
19
|
+
*
|
|
20
|
+
* Guardrails:
|
|
21
|
+
* - Smithy IDL is not a language GritQL parses, so each edit is anchored to the
|
|
22
|
+
* exact `@trait` + `@specificationExtension` + `structure <name>` triple the
|
|
23
|
+
* generator vends.
|
|
24
|
+
* - A declaration that already carries an `as:` argument, or that has diverged
|
|
25
|
+
* from the vended shape, is left alone and reported via `nextSteps`.
|
|
26
|
+
* - Idempotent: an aliased declaration no longer matches the bare pattern.
|
|
27
|
+
*/
|
|
28
|
+
export default function migration(tree: Tree): Promise<MigrationReturnObject>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { getProjects, joinPathFragments } from "@nx/devkit";
|
|
5
|
+
import { SMITHY_PROJECT_GENERATOR_INFO } from "../../../smithy/project/generator.js";
|
|
6
|
+
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
7
|
+
/** The traits the connection generator vends, each named after its OpenAPI key. */ const TRAITS = [
|
|
8
|
+
'query',
|
|
9
|
+
'mutation',
|
|
10
|
+
'cursor'
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Matches a bare `@specificationExtension` applied to the named structure, with
|
|
14
|
+
* the `@trait` and `@specificationExtension` traits adjacent to the `structure`
|
|
15
|
+
* they annotate. A declaration that already carries an argument does not match.
|
|
16
|
+
*/ const bareDeclaration = (trait)=>new RegExp(`(@trait\\s*\\n\\s*@specificationExtension)(\\s*\\n\\s*structure\\s+${trait}\\s*\\{)`);
|
|
17
|
+
/**
|
|
18
|
+
* Give each trait in a Smithy model's `extensions.smithy` an explicit
|
|
19
|
+
* `@specificationExtension(as: "...")` alias.
|
|
20
|
+
*
|
|
21
|
+
* Without the alias Smithy derives the OpenAPI key from the trait's shape id and
|
|
22
|
+
* emits a namespace-prefixed key (`x-<namespace>-query`), which the client code
|
|
23
|
+
* generator does not read — so the `@query`, `@mutation` and `@cursor` traits
|
|
24
|
+
* have no effect on the generated client. The alias pins each key to the
|
|
25
|
+
* unprefixed name the generator recognises.
|
|
26
|
+
*
|
|
27
|
+
* How to write a migration:
|
|
28
|
+
* - https://nx.dev/docs/kb/migration-generators
|
|
29
|
+
* - What `nextSteps` means: https://nx.dev/docs/reference/devkit/MigrationReturnObject
|
|
30
|
+
*
|
|
31
|
+
* Guardrails:
|
|
32
|
+
* - Smithy IDL is not a language GritQL parses, so each edit is anchored to the
|
|
33
|
+
* exact `@trait` + `@specificationExtension` + `structure <name>` triple the
|
|
34
|
+
* generator vends.
|
|
35
|
+
* - A declaration that already carries an `as:` argument, or that has diverged
|
|
36
|
+
* from the vended shape, is left alone and reported via `nextSteps`.
|
|
37
|
+
* - Idempotent: an aliased declaration no longer matches the bare pattern.
|
|
38
|
+
*/ export default async function migration(tree) {
|
|
39
|
+
const nextSteps = [];
|
|
40
|
+
for (const [, project] of getProjects(tree)){
|
|
41
|
+
if ((project.metadata ?? {}).generator !== SMITHY_PROJECT_GENERATOR_INFO.id) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const extensionsPath = joinPathFragments(project.sourceRoot ?? joinPathFragments(project.root, 'src'), 'extensions.smithy');
|
|
45
|
+
if (!tree.exists(extensionsPath)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const before = tree.read(extensionsPath, 'utf-8') ?? '';
|
|
49
|
+
let after = before;
|
|
50
|
+
const skipped = [];
|
|
51
|
+
for (const trait of TRAITS){
|
|
52
|
+
if (after.includes(`@specificationExtension(as: "x-${trait}")`)) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const bare = bareDeclaration(trait);
|
|
56
|
+
if (!bare.test(after)) {
|
|
57
|
+
skipped.push(trait);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
after = after.replace(bare, `$1(as: "x-${trait}")$2`);
|
|
61
|
+
}
|
|
62
|
+
if (after !== before) {
|
|
63
|
+
tree.write(extensionsPath, after);
|
|
64
|
+
}
|
|
65
|
+
if (skipped.length > 0) {
|
|
66
|
+
nextSteps.push(`${extensionsPath}: add ${skipped.map((trait)=>`\`(as: "x-${trait}")\``).join(', ')} to the \`@specificationExtension\` trait on ${skipped.map((trait)=>`\`${trait}\``).join(', ')}, so Smithy emits the ${skipped.map((trait)=>`\`x-${trait}\``).join(', ')} OpenAPI ${skipped.length === 1 ? 'key' : 'keys'} the client generator reads.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
await formatFilesInSubtree(tree);
|
|
70
|
+
return {
|
|
71
|
+
nextSteps
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/smithy-extension-trait-aliases/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n getProjects,\n joinPathFragments,\n type MigrationReturnObject,\n type Tree,\n} from '@nx/devkit';\nimport { SMITHY_PROJECT_GENERATOR_INFO } from '../../../smithy/project/generator.js';\nimport { formatFilesInSubtree } from '../../../utils/format.js';\n\n/** The traits the connection generator vends, each named after its OpenAPI key. */\nconst TRAITS = ['query', 'mutation', 'cursor'] as const;\n\n/**\n * Matches a bare `@specificationExtension` applied to the named structure, with\n * the `@trait` and `@specificationExtension` traits adjacent to the `structure`\n * they annotate. A declaration that already carries an argument does not match.\n */\nconst bareDeclaration = (trait: string) =>\n new RegExp(\n `(@trait\\\\s*\\\\n\\\\s*@specificationExtension)(\\\\s*\\\\n\\\\s*structure\\\\s+${trait}\\\\s*\\\\{)`,\n );\n\n/**\n * Give each trait in a Smithy model's `extensions.smithy` an explicit\n * `@specificationExtension(as: \"...\")` alias.\n *\n * Without the alias Smithy derives the OpenAPI key from the trait's shape id and\n * emits a namespace-prefixed key (`x-<namespace>-query`), which the client code\n * generator does not read — so the `@query`, `@mutation` and `@cursor` traits\n * have no effect on the generated client. The alias pins each key to the\n * unprefixed name the generator recognises.\n *\n * How to write a migration:\n * - https://nx.dev/docs/kb/migration-generators\n * - What `nextSteps` means: https://nx.dev/docs/reference/devkit/MigrationReturnObject\n *\n * Guardrails:\n * - Smithy IDL is not a language GritQL parses, so each edit is anchored to the\n * exact `@trait` + `@specificationExtension` + `structure <name>` triple the\n * generator vends.\n * - A declaration that already carries an `as:` argument, or that has diverged\n * from the vended shape, is left alone and reported via `nextSteps`.\n * - Idempotent: an aliased declaration no longer matches the bare pattern.\n */\nexport default async function migration(\n tree: Tree,\n): Promise<MigrationReturnObject> {\n const nextSteps: string[] = [];\n\n for (const [, project] of getProjects(tree)) {\n if (\n ((project.metadata as any) ?? {}).generator !==\n SMITHY_PROJECT_GENERATOR_INFO.id\n ) {\n continue;\n }\n\n const extensionsPath = joinPathFragments(\n project.sourceRoot ?? joinPathFragments(project.root, 'src'),\n 'extensions.smithy',\n );\n if (!tree.exists(extensionsPath)) {\n continue;\n }\n\n const before = tree.read(extensionsPath, 'utf-8') ?? '';\n let after = before;\n const skipped: string[] = [];\n\n for (const trait of TRAITS) {\n if (after.includes(`@specificationExtension(as: \"x-${trait}\")`)) {\n // Already aliased.\n continue;\n }\n const bare = bareDeclaration(trait);\n if (!bare.test(after)) {\n skipped.push(trait);\n continue;\n }\n after = after.replace(bare, `$1(as: \"x-${trait}\")$2`);\n }\n\n if (after !== before) {\n tree.write(extensionsPath, after);\n }\n\n if (skipped.length > 0) {\n nextSteps.push(\n `${extensionsPath}: add ${skipped\n .map((trait) => `\\`(as: \"x-${trait}\")\\``)\n .join(\n ', ',\n )} to the \\`@specificationExtension\\` trait on ${skipped.map((trait) => `\\`${trait}\\``).join(', ')}, so Smithy emits the ${skipped.map((trait) => `\\`x-${trait}\\``).join(', ')} OpenAPI ${skipped.length === 1 ? 'key' : 'keys'} the client generator reads.`,\n );\n }\n }\n\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n}\n"],"names":["getProjects","joinPathFragments","SMITHY_PROJECT_GENERATOR_INFO","formatFilesInSubtree","TRAITS","bareDeclaration","trait","RegExp","migration","tree","nextSteps","project","metadata","generator","id","extensionsPath","sourceRoot","root","exists","before","read","after","skipped","includes","bare","test","push","replace","write","length","map","join"],"mappings":"AAAA;;;CAGC,GACD,SACEA,WAAW,EACXC,iBAAiB,QAGZ,aAAa;AACpB,SAASC,6BAA6B,QAAQ,uCAAuC;AACrF,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE,iFAAiF,GACjF,MAAMC,SAAS;IAAC;IAAS;IAAY;CAAS;AAE9C;;;;CAIC,GACD,MAAMC,kBAAkB,CAACC,QACvB,IAAIC,OACF,CAAC,mEAAmE,EAAED,MAAM,QAAQ,CAAC;AAGzF;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,eAAe,eAAeE,UAC5BC,IAAU;IAEV,MAAMC,YAAsB,EAAE;IAE9B,KAAK,MAAM,GAAGC,QAAQ,IAAIX,YAAYS,MAAO;QAC3C,IACE,AAAC,CAAA,AAACE,QAAQC,QAAQ,IAAY,CAAC,CAAA,EAAGC,SAAS,KAC3CX,8BAA8BY,EAAE,EAChC;YACA;QACF;QAEA,MAAMC,iBAAiBd,kBACrBU,QAAQK,UAAU,IAAIf,kBAAkBU,QAAQM,IAAI,EAAE,QACtD;QAEF,IAAI,CAACR,KAAKS,MAAM,CAACH,iBAAiB;YAChC;QACF;QAEA,MAAMI,SAASV,KAAKW,IAAI,CAACL,gBAAgB,YAAY;QACrD,IAAIM,QAAQF;QACZ,MAAMG,UAAoB,EAAE;QAE5B,KAAK,MAAMhB,SAASF,OAAQ;YAC1B,IAAIiB,MAAME,QAAQ,CAAC,CAAC,+BAA+B,EAAEjB,MAAM,EAAE,CAAC,GAAG;gBAE/D;YACF;YACA,MAAMkB,OAAOnB,gBAAgBC;YAC7B,IAAI,CAACkB,KAAKC,IAAI,CAACJ,QAAQ;gBACrBC,QAAQI,IAAI,CAACpB;gBACb;YACF;YACAe,QAAQA,MAAMM,OAAO,CAACH,MAAM,CAAC,UAAU,EAAElB,MAAM,IAAI,CAAC;QACtD;QAEA,IAAIe,UAAUF,QAAQ;YACpBV,KAAKmB,KAAK,CAACb,gBAAgBM;QAC7B;QAEA,IAAIC,QAAQO,MAAM,GAAG,GAAG;YACtBnB,UAAUgB,IAAI,CACZ,GAAGX,eAAe,MAAM,EAAEO,QACvBQ,GAAG,CAAC,CAACxB,QAAU,CAAC,UAAU,EAAEA,MAAM,IAAI,CAAC,EACvCyB,IAAI,CACH,MACA,6CAA6C,EAAET,QAAQQ,GAAG,CAAC,CAACxB,QAAU,CAAC,EAAE,EAAEA,MAAM,EAAE,CAAC,EAAEyB,IAAI,CAAC,MAAM,sBAAsB,EAAET,QAAQQ,GAAG,CAAC,CAACxB,QAAU,CAAC,IAAI,EAAEA,MAAM,EAAE,CAAC,EAAEyB,IAAI,CAAC,MAAM,SAAS,EAAET,QAAQO,MAAM,KAAK,IAAI,QAAQ,OAAO,4BAA4B,CAAC;QAEnQ;IACF;IAEA,MAAM1B,qBAAqBM;IAE3B,OAAO;QAAEC;IAAU;AACrB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type MigrationReturnObject, type Tree } from '@nx/devkit';
|
|
6
|
+
export default function migration(tree: Tree): Promise<MigrationReturnObject>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { getProjects, joinPathFragments, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
+
import { relative } from "path";
|
|
6
|
+
import { TERRAFORM_PROJECT_GENERATOR_INFO } from "../../../terraform/project/generator.js";
|
|
7
|
+
import { formatFilesInSubtree } from "../../../utils/format.js";
|
|
8
|
+
/**
|
|
9
|
+
* Run `validate` against a backendless `terraform init` of its own, so it works
|
|
10
|
+
* on a fresh workspace.
|
|
11
|
+
*
|
|
12
|
+
* It previously depended on the `init` target. On an application project that
|
|
13
|
+
* runs the vended `scripts/init.ts`, which configures the S3 backend and fails
|
|
14
|
+
* with a raw `NoSuchBucket` trace until `bootstrap` has created the state
|
|
15
|
+
* bucket — so the first target the guide invites the reader to try was
|
|
16
|
+
* unrunnable, while `lint`, `test` and `checkov` all worked.
|
|
17
|
+
*
|
|
18
|
+
* `-backend=false` installs the modules and providers validation needs without
|
|
19
|
+
* configuring the backend, exactly as `test` already does, so no credentials are
|
|
20
|
+
* involved. `TF_DATA_DIR` keeps that `.terraform` out of `src` so it never races
|
|
21
|
+
* the backend-configured targets over the shared one, and the shared plugin
|
|
22
|
+
* cache means the providers are linked rather than re-downloaded.
|
|
23
|
+
*/ const VALIDATE_TARGET = 'validate';
|
|
24
|
+
/** The command the pre-fix target ran, on its own. */ const VENDED_COMMAND = 'terraform validate';
|
|
25
|
+
const divergedMessage = (projectName)=>`${projectName}:${VALIDATE_TARGET}: has diverged from the generated shape - left untouched. To run it before \`bootstrap\`, have it run \`terraform init -backend=false\` ahead of \`terraform validate\` rather than depending on the \`init\` target, which configures the S3 backend.`;
|
|
26
|
+
/** Path from a target running in `{projectRoot}/src` to the workspace root. */ const rootRelativePathFrom = (projectRoot)=>(relative(joinPathFragments(projectRoot, 'src'), '.') || '.').replace(/\\/g, '/');
|
|
27
|
+
/** Whether the target is the exact shape the pre-fix generator produced. */ const hasVendedShape = (target)=>target.executor === 'nx:run-commands' && target.options?.command === VENDED_COMMAND && !target.options?.commands && target.options?.cwd === '{projectRoot}/src' && target.dependsOn?.length === 1 && target.dependsOn[0] === 'init';
|
|
28
|
+
export default async function migration(tree) {
|
|
29
|
+
const nextSteps = [];
|
|
30
|
+
for (const [projectName, project] of getProjects(tree)){
|
|
31
|
+
const generator = project.metadata?.generator;
|
|
32
|
+
if (generator !== TERRAFORM_PROJECT_GENERATOR_INFO.id) continue;
|
|
33
|
+
const target = project.targets?.[VALIDATE_TARGET];
|
|
34
|
+
if (!target) continue;
|
|
35
|
+
// A target already running its own init needs nothing, which also makes a
|
|
36
|
+
// re-run — and a project generated after the fix — a no-op.
|
|
37
|
+
if (target.options?.env?.TF_DATA_DIR) continue;
|
|
38
|
+
if (!hasVendedShape(target)) {
|
|
39
|
+
nextSteps.push(divergedMessage(projectName));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const rootRelativePath = rootRelativePathFrom(project.root);
|
|
43
|
+
const pluginCacheDir = joinPathFragments(rootRelativePath, '.terraform', 'plugin-cache', '{projectRoot}').replace(/\\/g, '/');
|
|
44
|
+
const validateDataDir = joinPathFragments(rootRelativePath, 'dist', '{projectRoot}', 'terraform-validate').replace(/\\/g, '/');
|
|
45
|
+
const { command: _command, ...options } = target.options;
|
|
46
|
+
const { dependsOn: _dependsOn, ...rest } = target;
|
|
47
|
+
project.targets[VALIDATE_TARGET] = {
|
|
48
|
+
...rest,
|
|
49
|
+
// `^production` mirrors `test`: validation resolves the relative modules a
|
|
50
|
+
// project consumes, so a change in one must invalidate it.
|
|
51
|
+
inputs: [
|
|
52
|
+
'default',
|
|
53
|
+
'^production'
|
|
54
|
+
],
|
|
55
|
+
// `TF_DATA_DIR` is terraform's working directory, not an artifact — its
|
|
56
|
+
// provider entries are symlinks into the shared plugin cache.
|
|
57
|
+
outputs: [],
|
|
58
|
+
options: {
|
|
59
|
+
...options,
|
|
60
|
+
commands: [
|
|
61
|
+
{
|
|
62
|
+
command: `shx mkdir -p ${pluginCacheDir}`,
|
|
63
|
+
forwardAllArgs: false
|
|
64
|
+
},
|
|
65
|
+
'terraform init -backend=false',
|
|
66
|
+
VENDED_COMMAND
|
|
67
|
+
],
|
|
68
|
+
parallel: false,
|
|
69
|
+
env: {
|
|
70
|
+
...options.env,
|
|
71
|
+
TF_DATA_DIR: validateDataDir,
|
|
72
|
+
TF_PLUGIN_CACHE_DIR: pluginCacheDir
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
updateProjectConfiguration(tree, projectName, project);
|
|
77
|
+
}
|
|
78
|
+
await formatFilesInSubtree(tree);
|
|
79
|
+
return {
|
|
80
|
+
nextSteps
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/nx-plugin/src/migrations/latest/terraform-validate-without-backend/migration.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n getProjects,\n joinPathFragments,\n type MigrationReturnObject,\n type ProjectConfiguration,\n type TargetConfiguration,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { relative } from 'path';\nimport { TERRAFORM_PROJECT_GENERATOR_INFO } from '../../../terraform/project/generator.js';\nimport { formatFilesInSubtree } from '../../../utils/format.js';\n\n/**\n * Run `validate` against a backendless `terraform init` of its own, so it works\n * on a fresh workspace.\n *\n * It previously depended on the `init` target. On an application project that\n * runs the vended `scripts/init.ts`, which configures the S3 backend and fails\n * with a raw `NoSuchBucket` trace until `bootstrap` has created the state\n * bucket — so the first target the guide invites the reader to try was\n * unrunnable, while `lint`, `test` and `checkov` all worked.\n *\n * `-backend=false` installs the modules and providers validation needs without\n * configuring the backend, exactly as `test` already does, so no credentials are\n * involved. `TF_DATA_DIR` keeps that `.terraform` out of `src` so it never races\n * the backend-configured targets over the shared one, and the shared plugin\n * cache means the providers are linked rather than re-downloaded.\n */\n\nconst VALIDATE_TARGET = 'validate';\n\n/** The command the pre-fix target ran, on its own. */\nconst VENDED_COMMAND = 'terraform validate';\n\nconst divergedMessage = (projectName: string) =>\n `${projectName}:${VALIDATE_TARGET}: has diverged from the generated shape - left untouched. To run it before \\`bootstrap\\`, have it run \\`terraform init -backend=false\\` ahead of \\`terraform validate\\` rather than depending on the \\`init\\` target, which configures the S3 backend.`;\n\n/** Path from a target running in `{projectRoot}/src` to the workspace root. */\nconst rootRelativePathFrom = (projectRoot: string) =>\n (relative(joinPathFragments(projectRoot, 'src'), '.') || '.').replace(\n /\\\\/g,\n '/',\n );\n\n/** Whether the target is the exact shape the pre-fix generator produced. */\nconst hasVendedShape = (target: TargetConfiguration): boolean =>\n target.executor === 'nx:run-commands' &&\n target.options?.command === VENDED_COMMAND &&\n !target.options?.commands &&\n target.options?.cwd === '{projectRoot}/src' &&\n target.dependsOn?.length === 1 &&\n target.dependsOn[0] === 'init';\n\nexport default async function migration(\n tree: Tree,\n): Promise<MigrationReturnObject> {\n const nextSteps: string[] = [];\n\n for (const [projectName, project] of getProjects(tree)) {\n const generator = (project.metadata as { generator?: string } | undefined)\n ?.generator;\n if (generator !== TERRAFORM_PROJECT_GENERATOR_INFO.id) continue;\n\n const target = project.targets?.[VALIDATE_TARGET];\n if (!target) continue;\n\n // A target already running its own init needs nothing, which also makes a\n // re-run — and a project generated after the fix — a no-op.\n if (target.options?.env?.TF_DATA_DIR) continue;\n\n if (!hasVendedShape(target)) {\n nextSteps.push(divergedMessage(projectName));\n continue;\n }\n\n const rootRelativePath = rootRelativePathFrom(project.root);\n const pluginCacheDir = joinPathFragments(\n rootRelativePath,\n '.terraform',\n 'plugin-cache',\n '{projectRoot}',\n ).replace(/\\\\/g, '/');\n const validateDataDir = joinPathFragments(\n rootRelativePath,\n 'dist',\n '{projectRoot}',\n 'terraform-validate',\n ).replace(/\\\\/g, '/');\n\n const { command: _command, ...options } = target.options;\n const { dependsOn: _dependsOn, ...rest } = target;\n\n project.targets[VALIDATE_TARGET] = {\n ...rest,\n // `^production` mirrors `test`: validation resolves the relative modules a\n // project consumes, so a change in one must invalidate it.\n inputs: ['default', '^production'],\n // `TF_DATA_DIR` is terraform's working directory, not an artifact — its\n // provider entries are symlinks into the shared plugin cache.\n outputs: [],\n options: {\n ...options,\n commands: [\n { command: `shx mkdir -p ${pluginCacheDir}`, forwardAllArgs: false },\n 'terraform init -backend=false',\n VENDED_COMMAND,\n ],\n parallel: false,\n env: {\n ...options.env,\n TF_DATA_DIR: validateDataDir,\n TF_PLUGIN_CACHE_DIR: pluginCacheDir,\n },\n },\n };\n\n updateProjectConfiguration(\n tree,\n projectName,\n project as ProjectConfiguration,\n );\n }\n\n await formatFilesInSubtree(tree);\n\n return { nextSteps };\n}\n"],"names":["getProjects","joinPathFragments","updateProjectConfiguration","relative","TERRAFORM_PROJECT_GENERATOR_INFO","formatFilesInSubtree","VALIDATE_TARGET","VENDED_COMMAND","divergedMessage","projectName","rootRelativePathFrom","projectRoot","replace","hasVendedShape","target","executor","options","command","commands","cwd","dependsOn","length","migration","tree","nextSteps","project","generator","metadata","id","targets","env","TF_DATA_DIR","push","rootRelativePath","root","pluginCacheDir","validateDataDir","_command","_dependsOn","rest","inputs","outputs","forwardAllArgs","parallel","TF_PLUGIN_CACHE_DIR"],"mappings":"AAAA;;;CAGC,GACD,SACEA,WAAW,EACXC,iBAAiB,EAKjBC,0BAA0B,QACrB,aAAa;AACpB,SAASC,QAAQ,QAAQ,OAAO;AAChC,SAASC,gCAAgC,QAAQ,0CAA0C;AAC3F,SAASC,oBAAoB,QAAQ,2BAA2B;AAEhE;;;;;;;;;;;;;;;CAeC,GAED,MAAMC,kBAAkB;AAExB,oDAAoD,GACpD,MAAMC,iBAAiB;AAEvB,MAAMC,kBAAkB,CAACC,cACvB,GAAGA,YAAY,CAAC,EAAEH,gBAAgB,sPAAsP,CAAC;AAE3R,6EAA6E,GAC7E,MAAMI,uBAAuB,CAACC,cAC5B,AAACR,CAAAA,SAASF,kBAAkBU,aAA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AAwE;YACxE,8DAA8D;YAC9DC,SAAS,EAAE;YACXzB,SAAS;gBACP,GAAGA,OAAO;gBACVE,UAAU;oBACR;wBAAED,SAAS,CAAC,aAAa,EAAEkB,gBAAgB;wBAAEO,gBAAgB;oBAAM;oBACnE;oBACAnC;iBACD;gBACDoC,UAAU;gBACVb,KAAK;oBACH,GAAGd,QAAQc,GAAG;oBACdC,aAAaK;oBACbQ,qBAAqBT;gBACvB;YACF;QACF;QAEAjC,2BACEqB,MACAd,aACAgB;IAEJ;IAEA,MAAMpB,qBAAqBkB;IAE3B,OAAO;QAAEC;IAAU;AACrB"}
|
|
@@ -60,8 +60,6 @@ exports[`preset generator > should run successfully > .mcp.json 1`] = `
|
|
|
60
60
|
"
|
|
61
61
|
`;
|
|
62
62
|
|
|
63
|
-
exports[`preset generator > should run successfully > .prettierrc 1`] = `"{"singleQuote":true}"`;
|
|
64
|
-
|
|
65
63
|
exports[`preset generator > should run successfully > .vscode/mcp.json 1`] = `
|
|
66
64
|
"{
|
|
67
65
|
"servers": {
|
|
@@ -420,9 +418,9 @@ onlyBuiltDependencies:
|
|
|
420
418
|
- sharp
|
|
421
419
|
catalogMode: strict
|
|
422
420
|
catalog:
|
|
423
|
-
nx: 23.
|
|
424
|
-
'@nx/js': 23.
|
|
425
|
-
'@nx/workspace': 23.
|
|
421
|
+
nx: 23.2.0
|
|
422
|
+
'@nx/js': 23.2.0
|
|
423
|
+
'@nx/workspace': 23.2.0
|
|
426
424
|
typescript: ~6.0.3
|
|
427
425
|
'@biomejs/biome': 2.5.11
|
|
428
426
|
'@aws/nx-plugin': ^0.0.0
|
package/src/preset/generator.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/ import {
|
|
4
|
+
*/ import { OverwriteStrategy, updateJson } from "@nx/devkit";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
6
|
import enquirer from "enquirer";
|
|
7
|
-
import { readFileSync } from "fs";
|
|
8
7
|
import { ensureAwsNxPluginConfig, updateAwsNxPluginConfig } from "../utils/config/utils.js";
|
|
9
8
|
import { declareDependencies } from "../utils/declared-dependencies.js";
|
|
10
|
-
import { addDependenciesToPackageJson } from "../utils/dependencies.js";
|
|
11
9
|
import { formatFilesInSubtree } from "../utils/format.js";
|
|
10
|
+
import { GIT_SECRETS_DEPENDENCIES, setUpGitSecrets } from "../utils/git-secrets.js";
|
|
12
11
|
import { applyWorkspaceInit, INIT_DEPENDENCIES } from "../utils/init.js";
|
|
13
12
|
import { installDependencies } from "../utils/install.js";
|
|
14
13
|
import { getGeneratorInfo } from "../utils/nx.js";
|
|
15
|
-
import { withVersions } from "../utils/versions.js";
|
|
16
14
|
export const DEPENDENCIES = declareDependencies()({
|
|
17
15
|
ts: [
|
|
18
|
-
|
|
19
|
-
name: 'husky'
|
|
20
|
-
},
|
|
16
|
+
...GIT_SECRETS_DEPENDENCIES,
|
|
21
17
|
...INIT_DEPENDENCIES
|
|
22
18
|
]
|
|
23
19
|
});
|
|
@@ -68,23 +64,6 @@ export const PRESET_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
68
64
|
return false;
|
|
69
65
|
}
|
|
70
66
|
}
|
|
71
|
-
const setUpGitSecrets = (tree)=>{
|
|
72
|
-
const gitSecretsDir = joinPathFragments(import.meta.dirname, 'git-secrets-files', 'git-secrets-dir');
|
|
73
|
-
const huskyDir = joinPathFragments(import.meta.dirname, 'git-secrets-files', 'husky-dir');
|
|
74
|
-
tree.write('.git-secrets/git-secrets', readFileSync(joinPathFragments(gitSecretsDir, 'git-secrets'), 'utf-8'));
|
|
75
|
-
tree.write('.husky/pre-commit', readFileSync(joinPathFragments(huskyDir, 'pre-commit'), 'utf-8'));
|
|
76
|
-
tree.write('.gitallowed', '\\.git-secrets/git-secrets:\n');
|
|
77
|
-
updateJson(tree, 'package.json', (json)=>({
|
|
78
|
-
...json,
|
|
79
|
-
scripts: {
|
|
80
|
-
...json.scripts,
|
|
81
|
-
prepare: 'husky'
|
|
82
|
-
}
|
|
83
|
-
}));
|
|
84
|
-
addDependenciesToPackageJson(tree, {}, withVersions(DEPENDENCIES, [
|
|
85
|
-
'husky'
|
|
86
|
-
]));
|
|
87
|
-
};
|
|
88
67
|
export const presetGenerator = async (tree, { iac, gitSecrets, mcp, containers, module, catalog, preferInstallDependencies })=>{
|
|
89
68
|
if (isAmazonian() && !process.env.VITEST && !process.env.CI && process.env.NX_DRY_RUN !== 'true' && process.env.NX_INTERACTIVE !== 'false') {
|
|
90
69
|
const { engagementId } = await enquirer.prompt([
|
|
@@ -126,7 +105,7 @@ export const presetGenerator = async (tree, { iac, gitSecrets, mcp, containers,
|
|
|
126
105
|
tree.delete('libs/.gitkeep');
|
|
127
106
|
tree.write('packages/.gitkeep', '');
|
|
128
107
|
if (gitSecrets !== false) {
|
|
129
|
-
setUpGitSecrets(tree);
|
|
108
|
+
setUpGitSecrets(tree, DEPENDENCIES);
|
|
130
109
|
}
|
|
131
110
|
await formatFilesInSubtree(tree);
|
|
132
111
|
return ()=>installDependencies(tree, preferInstallDependencies, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/preset/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
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/preset/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 OverwriteStrategy,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { execSync } from 'child_process';\nimport enquirer from 'enquirer';\nimport {\n ensureAwsNxPluginConfig,\n updateAwsNxPluginConfig,\n} from '../utils/config/utils.js';\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 { getGeneratorInfo, type NxGeneratorInfo } from '../utils/nx.js';\nimport type { PresetGeneratorSchema } from './schema';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...GIT_SECRETS_DEPENDENCIES, ...INIT_DEPENDENCIES],\n});\n\nexport const PRESET_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Determines if the current user is an Amazon employee based on their git configuration.\n *\n * This function checks the git user email configuration to identify Amazon employees\n * by looking for email addresses with Amazon domains (e.g., @amazon.com, @amazon.co.uk).\n *\n * @returns {boolean} True if the user's git email has an Amazon domain, false otherwise\n *\n * @example\n * // Returns true for Amazon employee emails\n * // git config user.email = \"john.doe@amazon.com\"\n * isAmazonian(); // true\n *\n * @example\n * // Returns false for non-Amazon emails\n * // git config user.email = \"user@example.com\"\n * isAmazonian(); // false\n *\n * @example\n * // Returns false when git config is not available or throws an error\n * isAmazonian(); // false\n */\nexport function isAmazonian(): boolean {\n try {\n // Execute git command to retrieve the user's configured email address\n const gitEmail = execSync('git config user.email', {\n encoding: 'utf8',\n }).trim();\n\n // Return false if no email is configured\n if (!gitEmail) {\n return false;\n }\n\n // Split email address to extract domain part\n const emailParts = gitEmail.split('@');\n if (emailParts.length < 2) {\n return false;\n }\n\n // Extract domain and normalize to lowercase for comparison\n const domain = emailParts[1].toLowerCase();\n\n // Check if domain starts with 'amazon.' (covers amazon.com, amazon.co.uk, etc.)\n return domain.startsWith('amazon.');\n } catch (error) {\n // Return false if git command fails or any other error occurs\n // This handles cases where git is not installed or configured\n return false;\n }\n}\n\nexport const presetGenerator = async (\n tree: Tree,\n {\n iac,\n gitSecrets,\n mcp,\n containers,\n module,\n catalog,\n preferInstallDependencies,\n }: PresetGeneratorSchema,\n): Promise<GeneratorCallback> => {\n if (\n isAmazonian() &&\n !process.env.VITEST &&\n !process.env.CI &&\n process.env.NX_DRY_RUN !== 'true' &&\n process.env.NX_INTERACTIVE !== 'false'\n ) {\n const { engagementId } = await enquirer.prompt<{ engagementId?: string }>([\n {\n name: 'engagementId',\n message: 'Please enter your engagementId (if known)',\n type: 'input',\n initial: 'None',\n },\n ]);\n\n if (engagementId != 'None') {\n await ensureAwsNxPluginConfig(tree);\n await updateAwsNxPluginConfig(tree, { tags: [engagementId] });\n }\n }\n\n // The preset owns the greenfield workspace's module format: write the root\n // `type` explicitly from the chosen `--module` so later generators can\n // infer it. The `init` generator never touches an existing workspace's\n // `type` field.\n updateJson(tree, 'package.json', (packageJson) => ({\n ...packageJson,\n type: (module ?? 'esm') === 'esm' ? 'module' : 'commonjs',\n }));\n\n // Apply the deterministic workspace configuration shared with the `init`\n // generator. The preset owns the README of a greenfield workspace.\n await applyWorkspaceInit(\n tree,\n {\n iac,\n containers,\n mcp,\n catalogs: catalog ?? true,\n readmeOverwriteStrategy: OverwriteStrategy.Overwrite,\n overwriteScripts: true,\n },\n DEPENDENCIES,\n );\n\n tree.delete('apps/.gitkeep');\n tree.delete('libs/.gitkeep');\n tree.write('packages/.gitkeep', '');\n\n if (gitSecrets !== false) {\n setUpGitSecrets(tree, DEPENDENCIES);\n }\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default presetGenerator;\n"],"names":["OverwriteStrategy","updateJson","execSync","enquirer","ensureAwsNxPluginConfig","updateAwsNxPluginConfig","declareDependencies","formatFilesInSubtree","GIT_SECRETS_DEPENDENCIES","setUpGitSecrets","applyWorkspaceInit","INIT_DEPENDENCIES","installDependencies","getGeneratorInfo","DEPENDENCIES","ts","PRESET_GENERATOR_INFO","filename","isAmazonian","gitEmail","encoding","trim","emailParts","split","length","domain","toLowerCase","startsWith","error","presetGenerator","tree","iac","gitSecrets","mcp","containers","module","catalog","preferInstallDependencies","process","env","VITEST","CI","NX_DRY_RUN","NX_INTERACTIVE","engagementId","prompt","name","message","type","initial","tags","packageJson","catalogs","readmeOverwriteStrategy","Overwrite","overwriteScripts","delete","write","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,iBAAiB,EAEjBC,UAAU,QACL,aAAa;AACpB,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,OAAOC,cAAc,WAAW;AAChC,SACEC,uBAAuB,EACvBC,uBAAuB,QAClB,2BAA2B;AAClC,SAASC,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,gBAAgB,QAA8B,iBAAiB;AAGxE,OAAO,MAAMC,eAAeR,sBAAsB;IAChDS,IAAI;WAAIP;WAA6BG;KAAkB;AACzD,GAAG;AAEH,OAAO,MAAMK,wBAAyCH,iBACpD,YAAYI,QAAQ,EACpB;AAEF;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,SAASC;IACd,IAAI;QACF,sEAAsE;QACtE,MAAMC,WAAWjB,SAAS,yBAAyB;YACjDkB,UAAU;QACZ,GAAGC,IAAI;QAEP,yCAAyC;QACzC,IAAI,CAACF,UAAU;YACb,OAAO;QACT;QAEA,6CAA6C;QAC7C,MAAMG,aAAaH,SAASI,KAAK,CAAC;QAClC,IAAID,WAAWE,MAAM,GAAG,GAAG;YACzB,OAAO;QACT;QAEA,2DAA2D;QAC3D,MAAMC,SAASH,UAAU,CAAC,EAAE,CAACI,WAAW;QAExC,gFAAgF;QAChF,OAAOD,OAAOE,UAAU,CAAC;IAC3B,EAAE,OAAOC,OAAO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