@aws/nx-plugin 1.0.0-rc.37 → 1.0.0-rc.39
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/generators.json +7 -0
- package/package.json +1 -1
- package/src/init/generator.d.ts +18 -0
- package/src/init/generator.js +35 -0
- package/src/init/generator.js.map +1 -0
- package/src/init/schema.d.js +6 -0
- package/src/init/schema.d.js.map +1 -0
- package/src/init/schema.d.ts +16 -0
- package/src/init/schema.json +35 -0
- package/src/mcp-server/generator-info.js +27 -13
- package/src/mcp-server/generator-info.js.map +1 -1
- package/src/mcp-server/guide-pipeline.js +16 -1
- package/src/mcp-server/guide-pipeline.js.map +1 -1
- package/src/mcp-server/server.js +2 -0
- package/src/mcp-server/server.js.map +1 -1
- package/src/mcp-server/tools/add-to-existing-project.d.ts +12 -0
- package/src/mcp-server/tools/add-to-existing-project.js +36 -0
- package/src/mcp-server/tools/add-to-existing-project.js.map +1 -0
- package/src/mcp-server/tools/general-guidance.d.ts +1 -1
- package/src/mcp-server/tools/general-guidance.js +1 -0
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +3 -0
- package/src/preset/generator.js +19 -129
- package/src/preset/generator.js.map +1 -1
- package/src/py/agent/files/deploy/Dockerfile.template +1 -1
- package/src/py/agent/generator.js +13 -2
- package/src/py/agent/generator.js.map +1 -1
- package/src/py/mcp-server/files/deploy/Dockerfile.template +1 -1
- package/src/py/mcp-server/generator.js +13 -2
- package/src/py/mcp-server/generator.js.map +1 -1
- package/src/py/rdb/generator.js +11 -0
- package/src/py/rdb/generator.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +4 -1
- package/src/ts/agent/files/deploy/Dockerfile.template +4 -1
- package/src/ts/agent/generator.js +13 -1
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +0 -7
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/mcp-server/files/Dockerfile.template +4 -1
- package/src/ts/mcp-server/generator.js +14 -2
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +8 -1
- package/src/ts/rdb/files/Dockerfile.template +8 -1
- package/src/ts/rdb/generator.js +11 -0
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/utils/base-tsconfig.d.ts +30 -0
- package/src/utils/base-tsconfig.js +32 -0
- package/src/utils/base-tsconfig.js.map +1 -0
- package/src/utils/commands.d.ts +9 -2
- package/src/utils/commands.js +19 -9
- package/src/utils/commands.js.map +1 -1
- package/src/utils/docker.d.ts +44 -0
- package/src/utils/docker.js +81 -0
- package/src/utils/docker.js.map +1 -0
- package/src/utils/init.d.ts +53 -0
- package/src/utils/init.js +251 -0
- package/src/utils/init.js.map +1 -0
- package/src/utils/versions.d.ts +18 -1
- package/src/utils/versions.js +16 -0
- package/src/utils/versions.js.map +1 -1
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
FROM public.ecr.aws/lambda/nodejs:24
|
|
2
2
|
|
|
3
|
+
# Upgrade npm to a version free of known HIGH/CRITICAL vulnerabilities
|
|
4
|
+
RUN npm install -g npm@<%= npmVersion %>
|
|
5
|
+
|
|
3
6
|
WORKDIR ${LAMBDA_TASK_ROOT}
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
# npm blocks dependency install scripts by default; allow prisma's so its
|
|
9
|
+
# postinstall downloads the schema-engine binary needed to run migrations.
|
|
10
|
+
RUN printf 'allow-scripts[]=prisma\nallow-scripts[]=@prisma/engines\n' > .npmrc \
|
|
11
|
+
&& npm install prisma@<%= prismaVersion %> \
|
|
12
|
+
&& rm .npmrc
|
|
6
13
|
|
|
7
14
|
COPY index.js ./index.js
|
|
8
15
|
COPY prisma ./prisma
|
package/src/ts/rdb/generator.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { addDependenciesToPackageJson, generateFiles, joinPathFragments, readProjectConfiguration, updateJson, updateProjectConfiguration } from "@nx/devkit";
|
|
6
6
|
import { addTypeScriptBundleTarget } from "../../utils/bundle/bundle.js";
|
|
7
7
|
import { resolveContainers } from "../../utils/containers.js";
|
|
8
|
+
import { addDockerScanTarget } from "../../utils/docker.js";
|
|
8
9
|
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
9
10
|
import { FsCommands } from "../../utils/fs.js";
|
|
10
11
|
import { updateGitIgnore } from "../../utils/git.js";
|
|
@@ -70,6 +71,7 @@ export const tsRdbGenerator = async (tree, options)=>{
|
|
|
70
71
|
databasePackageAlias: toScopeAlias(fullyQualifiedName),
|
|
71
72
|
databaseProvider: options.engine === 'mysql' ? 'mysql' : 'postgresql',
|
|
72
73
|
prismaVersion: TS_VERSIONS.prisma,
|
|
74
|
+
npmVersion: TS_VERSIONS.npm,
|
|
73
75
|
prismaAdapterPackage: options.engine === 'mysql' ? '@prisma/adapter-mariadb' : '@prisma/adapter-pg',
|
|
74
76
|
prismaAdapterClassName: options.engine === 'mysql' ? 'PrismaMariaDb' : 'PrismaPg',
|
|
75
77
|
localDbPort,
|
|
@@ -187,6 +189,15 @@ export const tsRdbGenerator = async (tree, options)=>{
|
|
|
187
189
|
]
|
|
188
190
|
};
|
|
189
191
|
addDependencyToTargetIfNotPresent(projectConfig, 'build', 'docker');
|
|
192
|
+
addDockerScanTarget(tree, {
|
|
193
|
+
project: projectConfig,
|
|
194
|
+
containerEngine,
|
|
195
|
+
trivyTargetName: 'trivy',
|
|
196
|
+
dockerTargetName: 'docker',
|
|
197
|
+
imageTags: [
|
|
198
|
+
migrationDockerImageTag
|
|
199
|
+
]
|
|
200
|
+
});
|
|
190
201
|
}
|
|
191
202
|
addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');
|
|
192
203
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/rdb/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { relative } from 'node:path';\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n readProjectConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { updateGitIgnore } from '../../utils/git';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, snakeCase, toClassName } from '../../utils/names';\nimport { getNpmScope, toScopeAlias } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths';\nimport { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace';\nimport { assignPort } from '../../utils/port';\nimport { addRdbInfra } from '../../utils/rdb-constructs/rdb-constructs';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport {\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants';\nimport { sharedRdbScriptsGenerator } from '../../utils/shared-rdb-scripts';\nimport { TS_VERSIONS, withVersions } from '../../utils/versions';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator';\nimport type { TsRdbGeneratorSchema } from './schema';\n\nexport const TS_RDB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsRdbGenerator = async (\n tree: Tree,\n options: TsRdbGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(options.name);\n const databaseUser = options.databaseUser ?? 'dbadmin';\n const databaseName = snakeCase(options.databaseName ?? options.name);\n const containerEngine = await resolveContainers(tree, 'inherit');\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n });\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: options.directory,\n preferInstallDependencies: false,\n });\n }\n\n updateJson(tree, joinPathFragments(dir, 'tsconfig.lib.json'), (tsConfig) => ({\n ...tsConfig,\n include: ['src/**/*.ts', 'generated/prisma/**/*.ts'],\n }));\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n const localDbPort = assignPort(\n tree,\n projectConfig,\n options.engine === 'mysql' ? 3306 : 5432,\n );\n const localDbHost = 'localhost';\n const localDbUser = options.engine === 'mysql' ? 'root' : 'dbadmin';\n const localDbPassword = 'password';\n const containerName = `${getNpmScope(tree)}-${databaseName}`;\n const dockerImage =\n options.engine === 'mysql'\n ? 'public.ecr.aws/docker/library/mysql:8.0.44'\n : 'public.ecr.aws/docker/library/postgres:17.7';\n\n const templateOptions = {\n engine: options.engine,\n runtimeConfigKey: nameClassName,\n databasePackageAlias: toScopeAlias(fullyQualifiedName),\n databaseProvider: options.engine === 'mysql' ? 'mysql' : 'postgresql',\n prismaVersion: TS_VERSIONS.prisma,\n prismaAdapterPackage:\n options.engine === 'mysql'\n ? '@prisma/adapter-mariadb'\n : '@prisma/adapter-pg',\n prismaAdapterClassName:\n options.engine === 'mysql' ? 'PrismaMariaDb' : 'PrismaPg',\n localDbPort,\n localDbHost,\n localDbName: databaseName,\n localDbUser,\n localDbPassword,\n containerEngine,\n containerName,\n dockerImage,\n ...esmVars(tree),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n );\n updateGitIgnore(tree, dir, (patterns) => [...patterns, 'generated/prisma']);\n await sharedRdbScriptsGenerator(tree, options.engine);\n const waitForDbScript =\n options.engine === 'mysql'\n ? 'wait-for-mysql-db.ts'\n : 'wait-for-postgres-db.ts';\n const scriptsDir = relative(\n dir,\n joinPathFragments(PACKAGES_DIR, SHARED_SCRIPTS_DIR, 'src', 'rdb'),\n );\n const relativePathToRoot = getRelativePathToRootByDirectory(\n projectConfig.root,\n );\n const fs = new FsCommands(tree);\n const migrationBundleDir = joinPathFragments(\n 'dist',\n projectConfig.root,\n 'bundle',\n 'migration',\n );\n const migrationDockerImageTag = `${getNpmScope(tree)}-${kebabCase(options.name)}-migration:latest`;\n\n if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/migration-handler.ts',\n bundleOutputDir: 'migration',\n });\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/create-db-user-handler.ts',\n bundleOutputDir: 'create-db-user',\n });\n const bundleTarget = projectConfig.targets['bundle'];\n // The bundle target starts with a single rolldown `command`. Wrap it with\n // the migration asset copy steps, unless it has already been transformed\n // into a `commands` array on a previous run.\n if (!bundleTarget.options.commands) {\n const rolldownCommand = bundleTarget.options.command;\n delete bundleTarget.options.command;\n bundleTarget.options = {\n ...bundleTarget.options,\n commands: [\n fs.rm(`${relativePathToRoot}dist/{projectRoot}/bundle/migration`),\n fs.mkdir(`${relativePathToRoot}dist/{projectRoot}/bundle/migration`),\n fs.cp(\n 'prisma',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma`,\n ),\n fs.cp(\n 'prisma.config.ts',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma.config.ts`,\n ),\n fs.cp(\n 'Dockerfile',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/Dockerfile`,\n ),\n rolldownCommand,\n ],\n parallel: false,\n };\n }\n }\n\n projectConfig.targets.generate = {\n executor: 'nx:run-commands',\n outputs: ['{projectRoot}/generated/prisma'],\n options: {\n command: 'prisma generate',\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['pull-image'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/pull-image.ts`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['dev'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/start-container.ts`,\n cwd: '{projectRoot}',\n },\n continuous: true,\n };\n projectConfig.targets['wait-for-db'] = {\n executor: 'nx:run-commands',\n dependsOn: ['dev'],\n options: {\n command: `tsx ${scriptsDir}/${waitForDbScript}`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets.prisma = {\n executor: 'nx:run-commands',\n dependsOn: ['dev', 'wait-for-db'],\n options: {\n cwd: '{projectRoot}',\n command: 'prisma',\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n if (iac === 'terraform') {\n projectConfig.targets['docker'] = {\n cache: true,\n executor: 'nx:run-commands',\n options: {\n command: `${containerEngine} build --platform linux/arm64 --provenance=false -t ${migrationDockerImageTag} ${migrationBundleDir}`,\n },\n dependsOn: ['bundle'],\n };\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'docker');\n }\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n }\n addDependencyToTargetIfNotPresent(projectConfig, 'compile', 'generate');\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n addGeneratorMetadata(tree, fullyQualifiedName, TS_RDB_GENERATOR_INFO, {\n engine: options.engine,\n });\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n await addRdbInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n projectRoot: dir,\n nameClassName,\n nameKebabCase,\n databasePackageAlias: toScopeAlias(fullyQualifiedName),\n databaseName,\n adminUser: databaseUser,\n engine: options.engine,\n migrationBundleDir,\n createDbUserBundleDir: joinPathFragments(\n 'dist',\n projectConfig.root,\n 'bundle',\n 'create-db-user',\n ),\n framework: options.framework,\n migrationDockerImageTag,\n containerEngine,\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n '@aws-sdk/client-secrets-manager',\n '@aws-sdk/rds-signer',\n '@prisma/client',\n ...(options.engine === 'mysql'\n ? (['@prisma/adapter-mariadb', 'mariadb'] as const)\n : (['@prisma/adapter-pg', 'pg'] as const)),\n ]),\n withVersions([\n 'prisma',\n 'tsx',\n '@types/aws-lambda',\n ...(options.engine === 'mysql'\n ? ([] as const)\n : (['@types/pg'] as const)),\n ]),\n );\n\n registerPnpmBuiltDependencies(tree, {\n '@prisma/engines': false,\n prisma: false,\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_RDB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsRdbGenerator;\n"],"names":["relative","addDependenciesToPackageJson","generateFiles","joinPathFragments","readProjectConfiguration","updateJson","updateProjectConfiguration","addTypeScriptBundleTarget","resolveContainers","formatFilesInSubtree","FsCommands","updateGitIgnore","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","snakeCase","toClassName","getNpmScope","toScopeAlias","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","getRelativePathToRootByDirectory","registerPnpmBuiltDependencies","assignPort","addRdbInfra","sharedConstructsGenerator","PACKAGES_DIR","SHARED_SCRIPTS_DIR","sharedRdbScriptsGenerator","TS_VERSIONS","withVersions","tsProjectGenerator","getTsLibDetails","TS_RDB_GENERATOR_INFO","filename","tsRdbGenerator","tree","options","nameKebabCase","name","nameClassName","databaseUser","databaseName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","tsConfig","include","projectConfig","localDbPort","engine","localDbHost","localDbUser","localDbPassword","containerName","dockerImage","templateOptions","runtimeConfigKey","databasePackageAlias","databaseProvider","prismaVersion","prisma","prismaAdapterPackage","prismaAdapterClassName","localDbName","dirname","patterns","waitForDbScript","scriptsDir","relativePathToRoot","root","fs","migrationBundleDir","migrationDockerImageTag","infra","targetFilePath","bundleOutputDir","bundleTarget","targets","commands","rolldownCommand","command","rm","mkdir","cp","parallel","generate","executor","outputs","cwd","continuous","dependsOn","env","LOCAL_DEV","iac","cache","projectName","projectRoot","adminUser","createDbUserBundleDir","framework","languages"],"mappings":"AAAA;;;CAGC,GACD,SAASA,QAAQ,QAAQ,YAAY;AACrC,SACEC,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EAExBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,eAAe,QAAQ,qBAAkB;AAClD,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,OAAO,QAAQ,+BAA4B;AACpD,SAASC,SAAS,EAAEC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AACtE,SAASC,WAAW,EAAEC,YAAY,QAAQ,2BAAwB;AAClE,SACEC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,QAEX,oBAAiB;AACxB,SAASC,gCAAgC,QAAQ,uBAAoB;AACrE,SAASC,6BAA6B,QAAQ,gCAA6B;AAC3E,SAASC,UAAU,QAAQ,sBAAmB;AAC9C,SAASC,WAAW,QAAQ,+CAA4C;AACxE,SAASC,yBAAyB,QAAQ,mCAAgC;AAC1E,SACEC,YAAY,EACZC,kBAAkB,QACb,6CAA0C;AACjD,SAASC,yBAAyB,QAAQ,oCAAiC;AAC3E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,KAAK,UAClB;YAAC;YAA2B;SAAU,GACtC;YAAC;YAAsB;SAAK;KAClC,GACDxB,aAAa;QACX;QACA;QACA;WACIO,QAAQiB,MAAM,KAAK,UAClB,EAAE,GACF;YAAC;SAAY;KACnB;IAGHhC,8BAA8Bc,MAAM;QAClC,mBAAmB;QACnB6B,QAAQ;IACV;IAEA,MAAMtD,gCAAgCyB,MAAM;QAACH;KAAsB;IAEnE,MAAM3B,qBAAqB8B;IAC3B,OAAO,IACL1B,oBAAoB0B,MAAMC,QAAQY,yBAAyB,EAAE;YAC3DwD,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAetE,eAAe"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/rdb/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { relative } from 'node:path';\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n readProjectConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { addDockerScanTarget } from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { updateGitIgnore } from '../../utils/git';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { esmVars } from '../../utils/module-format';\nimport { kebabCase, snakeCase, toClassName } from '../../utils/names';\nimport { getNpmScope, toScopeAlias } from '../../utils/npm-scope';\nimport {\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths';\nimport { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace';\nimport { assignPort } from '../../utils/port';\nimport { addRdbInfra } from '../../utils/rdb-constructs/rdb-constructs';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport {\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants';\nimport { sharedRdbScriptsGenerator } from '../../utils/shared-rdb-scripts';\nimport { TS_VERSIONS, withVersions } from '../../utils/versions';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator';\nimport type { TsRdbGeneratorSchema } from './schema';\n\nexport const TS_RDB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsRdbGenerator = async (\n tree: Tree,\n options: TsRdbGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const nameKebabCase = kebabCase(options.name);\n const nameClassName = toClassName(options.name);\n const databaseUser = options.databaseUser ?? 'dbadmin';\n const databaseName = snakeCase(options.databaseName ?? options.name);\n const containerEngine = await resolveContainers(tree, 'inherit');\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, {\n name: options.name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n });\n\n let projectExists: boolean;\n try {\n readProjectConfiguration(tree, fullyQualifiedName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name: options.name,\n directory: options.directory,\n preferInstallDependencies: false,\n });\n }\n\n updateJson(tree, joinPathFragments(dir, 'tsconfig.lib.json'), (tsConfig) => ({\n ...tsConfig,\n include: ['src/**/*.ts', 'generated/prisma/**/*.ts'],\n }));\n\n const projectConfig = readProjectConfiguration(tree, fullyQualifiedName);\n const localDbPort = assignPort(\n tree,\n projectConfig,\n options.engine === 'mysql' ? 3306 : 5432,\n );\n const localDbHost = 'localhost';\n const localDbUser = options.engine === 'mysql' ? 'root' : 'dbadmin';\n const localDbPassword = 'password';\n const containerName = `${getNpmScope(tree)}-${databaseName}`;\n const dockerImage =\n options.engine === 'mysql'\n ? 'public.ecr.aws/docker/library/mysql:8.0.44'\n : 'public.ecr.aws/docker/library/postgres:17.7';\n\n const templateOptions = {\n engine: options.engine,\n runtimeConfigKey: nameClassName,\n databasePackageAlias: toScopeAlias(fullyQualifiedName),\n databaseProvider: options.engine === 'mysql' ? 'mysql' : 'postgresql',\n prismaVersion: TS_VERSIONS.prisma,\n npmVersion: TS_VERSIONS.npm,\n prismaAdapterPackage:\n options.engine === 'mysql'\n ? '@prisma/adapter-mariadb'\n : '@prisma/adapter-pg',\n prismaAdapterClassName:\n options.engine === 'mysql' ? 'PrismaMariaDb' : 'PrismaPg',\n localDbPort,\n localDbHost,\n localDbName: databaseName,\n localDbUser,\n localDbPassword,\n containerEngine,\n containerName,\n dockerImage,\n ...esmVars(tree),\n };\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n );\n updateGitIgnore(tree, dir, (patterns) => [...patterns, 'generated/prisma']);\n await sharedRdbScriptsGenerator(tree, options.engine);\n const waitForDbScript =\n options.engine === 'mysql'\n ? 'wait-for-mysql-db.ts'\n : 'wait-for-postgres-db.ts';\n const scriptsDir = relative(\n dir,\n joinPathFragments(PACKAGES_DIR, SHARED_SCRIPTS_DIR, 'src', 'rdb'),\n );\n const relativePathToRoot = getRelativePathToRootByDirectory(\n projectConfig.root,\n );\n const fs = new FsCommands(tree);\n const migrationBundleDir = joinPathFragments(\n 'dist',\n projectConfig.root,\n 'bundle',\n 'migration',\n );\n const migrationDockerImageTag = `${getNpmScope(tree)}-${kebabCase(options.name)}-migration:latest`;\n\n if (options.infra !== 'none') {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/migration-handler.ts',\n bundleOutputDir: 'migration',\n });\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: 'src/create-db-user-handler.ts',\n bundleOutputDir: 'create-db-user',\n });\n const bundleTarget = projectConfig.targets['bundle'];\n // The bundle target starts with a single rolldown `command`. Wrap it with\n // the migration asset copy steps, unless it has already been transformed\n // into a `commands` array on a previous run.\n if (!bundleTarget.options.commands) {\n const rolldownCommand = bundleTarget.options.command;\n delete bundleTarget.options.command;\n bundleTarget.options = {\n ...bundleTarget.options,\n commands: [\n fs.rm(`${relativePathToRoot}dist/{projectRoot}/bundle/migration`),\n fs.mkdir(`${relativePathToRoot}dist/{projectRoot}/bundle/migration`),\n fs.cp(\n 'prisma',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma`,\n ),\n fs.cp(\n 'prisma.config.ts',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma.config.ts`,\n ),\n fs.cp(\n 'Dockerfile',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/Dockerfile`,\n ),\n rolldownCommand,\n ],\n parallel: false,\n };\n }\n }\n\n projectConfig.targets.generate = {\n executor: 'nx:run-commands',\n outputs: ['{projectRoot}/generated/prisma'],\n options: {\n command: 'prisma generate',\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['pull-image'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/pull-image.ts`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets['dev'] = {\n executor: 'nx:run-commands',\n options: {\n command: `tsx ${scriptsDir}/start-container.ts`,\n cwd: '{projectRoot}',\n },\n continuous: true,\n };\n projectConfig.targets['wait-for-db'] = {\n executor: 'nx:run-commands',\n dependsOn: ['dev'],\n options: {\n command: `tsx ${scriptsDir}/${waitForDbScript}`,\n cwd: '{projectRoot}',\n },\n };\n projectConfig.targets.prisma = {\n executor: 'nx:run-commands',\n dependsOn: ['dev', 'wait-for-db'],\n options: {\n cwd: '{projectRoot}',\n command: 'prisma',\n env: {\n LOCAL_DEV: 'true',\n },\n },\n };\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n if (iac === 'terraform') {\n projectConfig.targets['docker'] = {\n cache: true,\n executor: 'nx:run-commands',\n options: {\n command: `${containerEngine} build --platform linux/arm64 --provenance=false -t ${migrationDockerImageTag} ${migrationBundleDir}`,\n },\n dependsOn: ['bundle'],\n };\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'docker');\n\n addDockerScanTarget(tree, {\n project: projectConfig,\n containerEngine,\n trivyTargetName: 'trivy',\n dockerTargetName: 'docker',\n imageTags: [migrationDockerImageTag],\n });\n }\n addDependencyToTargetIfNotPresent(projectConfig, 'build', 'bundle');\n }\n addDependencyToTargetIfNotPresent(projectConfig, 'compile', 'generate');\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n addGeneratorMetadata(tree, fullyQualifiedName, TS_RDB_GENERATOR_INFO, {\n engine: options.engine,\n });\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n await addRdbInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n projectRoot: dir,\n nameClassName,\n nameKebabCase,\n databasePackageAlias: toScopeAlias(fullyQualifiedName),\n databaseName,\n adminUser: databaseUser,\n engine: options.engine,\n migrationBundleDir,\n createDbUserBundleDir: joinPathFragments(\n 'dist',\n projectConfig.root,\n 'bundle',\n 'create-db-user',\n ),\n framework: options.framework,\n migrationDockerImageTag,\n containerEngine,\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n withVersions([\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n '@aws-sdk/client-secrets-manager',\n '@aws-sdk/rds-signer',\n '@prisma/client',\n ...(options.engine === 'mysql'\n ? (['@prisma/adapter-mariadb', 'mariadb'] as const)\n : (['@prisma/adapter-pg', 'pg'] as const)),\n ]),\n withVersions([\n 'prisma',\n 'tsx',\n '@types/aws-lambda',\n ...(options.engine === 'mysql'\n ? ([] as const)\n : (['@types/pg'] as const)),\n ]),\n );\n\n registerPnpmBuiltDependencies(tree, {\n '@prisma/engines': false,\n prisma: false,\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_RDB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsRdbGenerator;\n"],"names":["relative","addDependenciesToPackageJson","generateFiles","joinPathFragments","readProjectConfiguration","updateJson","updateProjectConfiguration","addTypeScriptBundleTarget","resolveContainers","addDockerScanTarget","formatFilesInSubtree","FsCommands","updateGitIgnore","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","snakeCase","toClassName","getNpmScope","toScopeAlias","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","getRelativePathToRootByDirectory","registerPnpmBuiltDependencies","assignPort","addRdbInfra","sharedConstructsGenerator","PACKAGES_DIR","SHARED_SCRIPTS_DIR","sharedRdbScriptsGenerator","TS_VERSIONS","withVersions","tsProjectGenerator","getTsLibDetails","TS_RDB_GENERATOR_INFO","filename","tsRdbGenerator","tree","options","nameKebabCase","name","nameClassName","databaseUser","databaseName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","tsConfig","include","projectConfig","localDbPort","engine","localDbHost","localDbUser","localDbPassword","containerName","dockerImage","templateOptions","runtimeConfigKey","databasePackageAlias","databaseProvider","prismaVersion","prisma","npmVersion","npm","prismaAdapterPackage","prismaAdapterClassName","localDbName","dirname","patterns","waitForDbScript","scriptsDir","relativePathToRoot","root","fs","migrationBundleDir","migrationDockerImageTag","infra","targetFilePath","bundleOutputDir","bundleTarget","targets","commands","rolldownCommand","command","rm","mkdir","cp","parallel","generate","executor","outputs","cwd","continuous","dependsOn","env","LOCAL_DEV","iac","cache","project","trivyTargetName","dockerTargetName","imageTags","projectName","projectRoot","adminUser","createDbUserBundleDir","framework","languages"],"mappings":"AAAA;;;CAGC,GACD,SAASA,QAAQ,QAAQ,YAAY;AACrC,SACEC,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,wBAAwB,EAExBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,yBAAyB,QAA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,oBAAoB0B,MAAMC,QAAQY,yBAAyB,EAAE;YAC3D8D,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe5E,eAAe"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The `tsconfig.base.json` compiler options the plugin's TypeScript projects
|
|
7
|
+
* rely on (project references, ESM, emit-less typecheck). Mirrors what
|
|
8
|
+
* `@nx/js` `initGenerator` produces for a fresh TS-solution workspace.
|
|
9
|
+
*
|
|
10
|
+
* Kept dependency-free so the docs site can import it directly and render the
|
|
11
|
+
* options without them drifting from what the generator writes.
|
|
12
|
+
*/
|
|
13
|
+
export declare const BASE_TSCONFIG_COMPILER_OPTIONS: {
|
|
14
|
+
composite: boolean;
|
|
15
|
+
declarationMap: boolean;
|
|
16
|
+
emitDeclarationOnly: boolean;
|
|
17
|
+
importHelpers: boolean;
|
|
18
|
+
isolatedModules: boolean;
|
|
19
|
+
lib: string[];
|
|
20
|
+
module: string;
|
|
21
|
+
moduleResolution: string;
|
|
22
|
+
noEmitOnError: boolean;
|
|
23
|
+
noFallthroughCasesInSwitch: boolean;
|
|
24
|
+
noImplicitOverride: boolean;
|
|
25
|
+
noImplicitReturns: boolean;
|
|
26
|
+
noUnusedLocals: boolean;
|
|
27
|
+
skipLibCheck: boolean;
|
|
28
|
+
strict: boolean;
|
|
29
|
+
target: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ /**
|
|
5
|
+
* The `tsconfig.base.json` compiler options the plugin's TypeScript projects
|
|
6
|
+
* rely on (project references, ESM, emit-less typecheck). Mirrors what
|
|
7
|
+
* `@nx/js` `initGenerator` produces for a fresh TS-solution workspace.
|
|
8
|
+
*
|
|
9
|
+
* Kept dependency-free so the docs site can import it directly and render the
|
|
10
|
+
* options without them drifting from what the generator writes.
|
|
11
|
+
*/ export const BASE_TSCONFIG_COMPILER_OPTIONS = {
|
|
12
|
+
composite: true,
|
|
13
|
+
declarationMap: true,
|
|
14
|
+
emitDeclarationOnly: true,
|
|
15
|
+
importHelpers: true,
|
|
16
|
+
isolatedModules: true,
|
|
17
|
+
lib: [
|
|
18
|
+
'es2022'
|
|
19
|
+
],
|
|
20
|
+
module: 'nodenext',
|
|
21
|
+
moduleResolution: 'nodenext',
|
|
22
|
+
noEmitOnError: true,
|
|
23
|
+
noFallthroughCasesInSwitch: true,
|
|
24
|
+
noImplicitOverride: true,
|
|
25
|
+
noImplicitReturns: true,
|
|
26
|
+
noUnusedLocals: true,
|
|
27
|
+
skipLibCheck: true,
|
|
28
|
+
strict: true,
|
|
29
|
+
target: 'es2022'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=base-tsconfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/base-tsconfig.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * The `tsconfig.base.json` compiler options the plugin's TypeScript projects\n * rely on (project references, ESM, emit-less typecheck). Mirrors what\n * `@nx/js` `initGenerator` produces for a fresh TS-solution workspace.\n *\n * Kept dependency-free so the docs site can import it directly and render the\n * options without them drifting from what the generator writes.\n */\nexport const BASE_TSCONFIG_COMPILER_OPTIONS = {\n composite: true,\n declarationMap: true,\n emitDeclarationOnly: true,\n importHelpers: true,\n isolatedModules: true,\n lib: ['es2022'],\n module: 'nodenext',\n moduleResolution: 'nodenext',\n noEmitOnError: true,\n noFallthroughCasesInSwitch: true,\n noImplicitOverride: true,\n noImplicitReturns: true,\n noUnusedLocals: true,\n skipLibCheck: true,\n strict: true,\n target: 'es2022',\n};\n"],"names":["BASE_TSCONFIG_COMPILER_OPTIONS","composite","declarationMap","emitDeclarationOnly","importHelpers","isolatedModules","lib","module","moduleResolution","noEmitOnError","noFallthroughCasesInSwitch","noImplicitOverride","noImplicitReturns","noUnusedLocals","skipLibCheck","strict","target"],"mappings":"AAAA;;;CAGC,GAED;;;;;;;CAOC,GACD,OAAO,MAAMA,iCAAiC;IAC5CC,WAAW;IACXC,gBAAgB;IAChBC,qBAAqB;IACrBC,eAAe;IACfC,iBAAiB;IACjBC,KAAK;QAAC;KAAS;IACfC,QAAQ;IACRC,kBAAkB;IAClBC,eAAe;IACfC,4BAA4B;IAC5BC,oBAAoB;IACpBC,mBAAmB;IACnBC,gBAAgB;IAChBC,cAAc;IACdC,QAAQ;IACRC,QAAQ;AACV,EAAE"}
|
package/src/utils/commands.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* The nx version the plugin is built against. Commands that download nx
|
|
3
|
+
* (e.g. `nx init`) pin to this version so the workspace's nx matches the
|
|
4
|
+
* plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.
|
|
4
5
|
*/
|
|
6
|
+
export declare const NX_VERSION: "23.0.2";
|
|
5
7
|
/**
|
|
6
8
|
* Display-friendly command prefixes for each package manager.
|
|
7
9
|
*
|
|
@@ -32,6 +34,11 @@ export declare const buildPackageManagerShortCommand: (pm: string, command: stri
|
|
|
32
34
|
* Build an install command for a given package manager
|
|
33
35
|
*/
|
|
34
36
|
export declare const buildInstallCommand: (pm: string, pkg: string, dev: boolean) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Build the command that adds Nx to a non-Nx project, pinned to the nx
|
|
39
|
+
* version the plugin is built against.
|
|
40
|
+
*/
|
|
41
|
+
export declare const buildNxInitCommand: (pm: string) => string;
|
|
35
42
|
/**
|
|
36
43
|
* Build a command to create a new workspace using @aws/create-nx-workspace.
|
|
37
44
|
*
|
package/src/utils/commands.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @see docs/src/components/package-manager-short-command.astro
|
|
12
|
-
*/ export const PACKAGE_MANAGER_COMMANDS = {
|
|
4
|
+
*/ import { TS_VERSIONS } from "./versions.js";
|
|
5
|
+
/**
|
|
6
|
+
* The nx version the plugin is built against. Commands that download nx
|
|
7
|
+
* (e.g. `nx init`) pin to this version so the workspace's nx matches the
|
|
8
|
+
* plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.
|
|
9
|
+
*/ export const NX_VERSION = TS_VERSIONS['@nx/devkit'];
|
|
10
|
+
export const PACKAGE_MANAGER_COMMANDS = {
|
|
13
11
|
npm: {
|
|
14
12
|
exec: 'npx',
|
|
15
13
|
run: 'npm run',
|
|
@@ -59,6 +57,18 @@
|
|
|
59
57
|
return `${pm} install ${dev ? '-D ' : ''}${pkg}`;
|
|
60
58
|
}
|
|
61
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Build the command that adds Nx to a non-Nx project, pinned to the nx
|
|
62
|
+
* version the plugin is built against.
|
|
63
|
+
*/ export const buildNxInitCommand = (pm)=>{
|
|
64
|
+
const dlxPrefix = {
|
|
65
|
+
npm: 'npx',
|
|
66
|
+
pnpm: 'pnpm dlx',
|
|
67
|
+
yarn: 'yarn dlx',
|
|
68
|
+
bun: 'bunx'
|
|
69
|
+
}[pm] ?? 'npx';
|
|
70
|
+
return `${dlxPrefix} nx@${NX_VERSION} init`;
|
|
71
|
+
};
|
|
62
72
|
/**
|
|
63
73
|
* Build a command to create a new workspace using @aws/create-nx-workspace.
|
|
64
74
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command for a given package manager\n */\nexport const buildInstallCommand = (pm: string, pkg: string, dev: boolean) => {\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun install ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n module?: 'esm' | 'cjs',\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ...(module ? [`--module=${module}`] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","buildCreateNxWorkspaceCommand","workspace","iac","tag","module","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/commands.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { TS_VERSIONS } from './versions';\n\n/**\n * The nx version the plugin is built against. Commands that download nx\n * (e.g. `nx init`) pin to this version so the workspace's nx matches the\n * plugin's `@nx/*` packages — a mismatch deadlocks `nx sync`.\n */\nexport const NX_VERSION = TS_VERSIONS['@nx/devkit'];\n\n/**\n * Display-friendly command prefixes for each package manager.\n *\n * - `exec`: prefix for running local binaries (e.g. `npx nx`, `pnpm nx`, `bunx nx`)\n * - `run`: prefix for running package.json scripts (e.g. `npm run build`, `pnpm build`)\n *\n * @see docs/src/components/package-manager-exec-command.astro\n * @see docs/src/components/package-manager-short-command.astro\n */\nexport interface PackageManagerDisplayCommands {\n /** Prefix for running local binaries: npx, pnpm, yarn, bunx */\n exec: string;\n /** Prefix for running package.json scripts: `npm run`, pnpm, yarn, bun */\n run: string;\n /** Prefix for `create` commands: `npm create`, `pnpm create`, etc. */\n create: string;\n}\n\nexport const PACKAGE_MANAGER_COMMANDS: Record<\n string,\n PackageManagerDisplayCommands\n> = {\n npm: { exec: 'npx', run: 'npm run', create: 'npm create' },\n pnpm: { exec: 'pnpm', run: 'pnpm', create: 'pnpm create' },\n yarn: { exec: 'yarn', run: 'yarn', create: 'yarn create' },\n bun: { exec: 'bunx', run: 'bun', create: 'bun create' },\n};\n\n/**\n * Build a package manager exec command (e.g. pnpm cmd, npx cmd, bunx cmd)\n */\nexport const buildPackageManagerExecCommand = (pm: string, command: string) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.exec ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build a short package manager command (e.g. pnpm build, npm run build)\n */\nexport const buildPackageManagerShortCommand = (\n pm: string,\n command: string,\n) => {\n const prefix = PACKAGE_MANAGER_COMMANDS[pm]?.run ?? pm;\n return `${prefix} ${command}`;\n};\n\n/**\n * Build an install command for a given package manager\n */\nexport const buildInstallCommand = (pm: string, pkg: string, dev: boolean) => {\n switch (pm) {\n case 'pnpm':\n return `pnpm add ${dev ? '-D' : '-'}w ${pkg}`;\n case 'yarn':\n return `yarn add ${dev ? '-D ' : ''}${pkg}`;\n case 'npm':\n return `npm install --legacy-peer-deps ${dev ? '-D ' : ''}${pkg}`;\n case 'bun':\n return `bun install ${dev ? '-D ' : ''}${pkg}`;\n default:\n return `${pm} install ${dev ? '-D ' : ''}${pkg}`;\n }\n};\n\n/**\n * Build the command that adds Nx to a non-Nx project, pinned to the nx\n * version the plugin is built against.\n */\nexport const buildNxInitCommand = (pm: string) => {\n const dlxPrefix =\n { npm: 'npx', pnpm: 'pnpm dlx', yarn: 'yarn dlx', bun: 'bunx' }[pm] ??\n 'npx';\n return `${dlxPrefix} nx@${NX_VERSION} init`;\n};\n\n/**\n * Build a command to create a new workspace using @aws/create-nx-workspace.\n *\n * Uses the `create` shorthand for each package manager:\n * npm create @aws/nx-workspace my-project\n * pnpm create @aws/nx-workspace my-project\n * yarn create @aws/nx-workspace my-project\n * bun create @aws/nx-workspace my-project\n *\n * The package manager is auto-detected by @aws/create-nx-workspace from the\n * invoking command, so --pm is not needed.\n */\nexport const buildCreateNxWorkspaceCommand = (\n pm: string,\n workspace: string,\n iac?: 'cdk' | 'terraform',\n tag?: string,\n module?: 'esm' | 'cjs',\n) => {\n const createPrefix = PACKAGE_MANAGER_COMMANDS[pm]?.create ?? `${pm} create`;\n const pkgName = tag ? `@aws/nx-workspace@${tag}` : '@aws/nx-workspace';\n const parts = [\n createPrefix,\n pkgName,\n // npm requires '--' to stop interpreting subsequent flags as npm config\n ...(pm === 'npm' ? ['--'] : []),\n workspace,\n ...(iac ? [`--iac=${iac}`] : []),\n ...(module ? [`--module=${module}`] : []),\n ];\n return parts.join(' ');\n};\n"],"names":["TS_VERSIONS","NX_VERSION","PACKAGE_MANAGER_COMMANDS","npm","exec","run","create","pnpm","yarn","bun","buildPackageManagerExecCommand","pm","command","prefix","buildPackageManagerShortCommand","buildInstallCommand","pkg","dev","buildNxInitCommand","dlxPrefix","buildCreateNxWorkspaceCommand","workspace","iac","tag","module","createPrefix","pkgName","parts","join"],"mappings":"AAAA;;;CAGC,GACD,SAASA,WAAW,QAAQ,gBAAa;AAEzC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KAAK;IAAO,CAAC,CAACE,GAAG,IACnE;IACF,OAAO,GAAGQ,UAAU,IAAI,EAAElB,WAAW,KAAK,CAAC;AAC7C,EAAE;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAMmB,gCAAgC,CAC3CT,IACAU,WACAC,KACAC,KACAC;IAEA,MAAMC,eAAevB,wBAAwB,CAACS,GAAG,EAAEL,UAAU,GAAGK,GAAG,OAAO,CAAC;IAC3E,MAAMe,UAAUH,MAAM,CAAC,kBAAkB,EAAEA,KAAK,GAAG;IACnD,MAAMI,QAAQ;QACZF;QACAC;QACA,wEAAwE;WACpEf,OAAO,QAAQ;YAAC;SAAK,GAAG,EAAE;QAC9BU;WACIC,MAAM;YAAC,CAAC,MAAM,EAAEA,KAAK;SAAC,GAAG,EAAE;WAC3BE,SAAS;YAAC,CAAC,SAAS,EAAEA,QAAQ;SAAC,GAAG,EAAE;KACzC;IACD,OAAOG,MAAMC,IAAI,CAAC;AACpB,EAAE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { type ProjectConfiguration, type Tree } from '@nx/devkit';
|
|
6
|
+
export interface DockerScanTargetOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Project configuration to add the scan target to (mutated in place).
|
|
9
|
+
*/
|
|
10
|
+
readonly project: ProjectConfiguration;
|
|
11
|
+
/**
|
|
12
|
+
* Container engine command to invoke (\`docker\` or \`finch\`).
|
|
13
|
+
*/
|
|
14
|
+
readonly containerEngine: string;
|
|
15
|
+
/**
|
|
16
|
+
* Name of the scan target to add, e.g. \`my-agent-trivy\`.
|
|
17
|
+
*/
|
|
18
|
+
readonly trivyTargetName: string;
|
|
19
|
+
/**
|
|
20
|
+
* Name of the docker target that builds the image(s) to scan. The scan
|
|
21
|
+
* target depends on it.
|
|
22
|
+
*/
|
|
23
|
+
readonly dockerTargetName: string;
|
|
24
|
+
/**
|
|
25
|
+
* Tags of the images built by the docker target which should be scanned.
|
|
26
|
+
*/
|
|
27
|
+
readonly imageTags: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add a cacheable Trivy scan target for the images built by a docker target,
|
|
31
|
+
* wire it under the aggregate \`trivy\` target, and make \`build\` depend on it.
|
|
32
|
+
*
|
|
33
|
+
* The scan target depends on the docker target and declares the project source
|
|
34
|
+
* as its inputs, so an unchanged image is never re-scanned (a cache hit skips
|
|
35
|
+
* the scan entirely). Each image is saved to a tarball under
|
|
36
|
+
* \`dist/<projectRoot>/trivy/<scan-key>\` (kept out of any Docker build context)
|
|
37
|
+
* and scanned with the pinned ECR-hosted Trivy image via a workspace-relative
|
|
38
|
+
* bind mount, so the same commands work under both docker and finch. The scan
|
|
39
|
+
* fails the build (exit code 1) on HIGH/CRITICAL vulnerabilities.
|
|
40
|
+
*
|
|
41
|
+
* A \`.trivyignore\` is vended at the project root (kept if it already exists)
|
|
42
|
+
* for suppressing findings.
|
|
43
|
+
*/
|
|
44
|
+
export declare const addDockerScanTarget: (tree: Tree, options: DockerScanTargetOptions) => void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { joinPathFragments } from "@nx/devkit";
|
|
5
|
+
import { FsCommands } from "./fs.js";
|
|
6
|
+
import { addDependencyToTargetIfNotPresent } from "./nx.js";
|
|
7
|
+
import { CONTAINER_VERSIONS } from "./versions.js";
|
|
8
|
+
const TRIVY_IGNORE_FILE = '.trivyignore';
|
|
9
|
+
const TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.g. CVE-2021-12345) per line to
|
|
10
|
+
# suppress it during the image scan run on build.
|
|
11
|
+
# https://trivy.dev/latest/docs/configuration/filtering/#by-finding-ids
|
|
12
|
+
`;
|
|
13
|
+
/**
|
|
14
|
+
* Add a cacheable Trivy scan target for the images built by a docker target,
|
|
15
|
+
* wire it under the aggregate \`trivy\` target, and make \`build\` depend on it.
|
|
16
|
+
*
|
|
17
|
+
* The scan target depends on the docker target and declares the project source
|
|
18
|
+
* as its inputs, so an unchanged image is never re-scanned (a cache hit skips
|
|
19
|
+
* the scan entirely). Each image is saved to a tarball under
|
|
20
|
+
* \`dist/<projectRoot>/trivy/<scan-key>\` (kept out of any Docker build context)
|
|
21
|
+
* and scanned with the pinned ECR-hosted Trivy image via a workspace-relative
|
|
22
|
+
* bind mount, so the same commands work under both docker and finch. The scan
|
|
23
|
+
* fails the build (exit code 1) on HIGH/CRITICAL vulnerabilities.
|
|
24
|
+
*
|
|
25
|
+
* A \`.trivyignore\` is vended at the project root (kept if it already exists)
|
|
26
|
+
* for suppressing findings.
|
|
27
|
+
*/ export const addDockerScanTarget = (tree, options)=>{
|
|
28
|
+
const { project, containerEngine, trivyTargetName, dockerTargetName } = options;
|
|
29
|
+
const { imageTags } = options;
|
|
30
|
+
const projectRoot = project.root;
|
|
31
|
+
const ignoreFilePath = joinPathFragments(projectRoot, TRIVY_IGNORE_FILE);
|
|
32
|
+
if (!tree.exists(ignoreFilePath)) {
|
|
33
|
+
tree.write(ignoreFilePath, TRIVY_IGNORE_CONTENTS);
|
|
34
|
+
}
|
|
35
|
+
// Stage scan artifacts in a directory unique to this scan target so that
|
|
36
|
+
// sibling targets in the same project (e.g. multiple agents) don't clobber
|
|
37
|
+
// each other's tarballs when run in parallel. The first image tag is unique
|
|
38
|
+
// per target, so it makes a stable, collision-free key.
|
|
39
|
+
const scanKey = imageTags[0].replace(/[^a-zA-Z0-9-]/g, '-');
|
|
40
|
+
const scanDir = joinPathFragments('dist', projectRoot, 'trivy', scanKey);
|
|
41
|
+
const trivyImage = `public.ecr.aws/aquasecurity/trivy:${CONTAINER_VERSIONS.trivy}`;
|
|
42
|
+
const fs = new FsCommands(tree);
|
|
43
|
+
const commands = [
|
|
44
|
+
fs.rm(scanDir),
|
|
45
|
+
fs.mkdir(scanDir),
|
|
46
|
+
fs.cp(ignoreFilePath, joinPathFragments(scanDir, TRIVY_IGNORE_FILE))
|
|
47
|
+
];
|
|
48
|
+
imageTags.forEach((imageTag, index)=>{
|
|
49
|
+
const tarName = `image-${index}.tar`;
|
|
50
|
+
commands.push(`${containerEngine} save -o ${joinPathFragments(scanDir, tarName)} ${imageTag}`, `${containerEngine} run --rm -v "./${scanDir}":/scan ${trivyImage} image --input /scan/${tarName} --ignorefile /scan/${TRIVY_IGNORE_FILE} --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 --no-progress -q`);
|
|
51
|
+
});
|
|
52
|
+
project.targets ??= {};
|
|
53
|
+
project.targets[trivyTargetName] = {
|
|
54
|
+
cache: true,
|
|
55
|
+
// The scanned image is fully determined by the project source, so caching
|
|
56
|
+
// on the source ensures an unchanged image is never re-scanned.
|
|
57
|
+
inputs: [
|
|
58
|
+
'default',
|
|
59
|
+
'^production'
|
|
60
|
+
],
|
|
61
|
+
outputs: [
|
|
62
|
+
`{workspaceRoot}/${scanDir}`
|
|
63
|
+
],
|
|
64
|
+
executor: 'nx:run-commands',
|
|
65
|
+
options: {
|
|
66
|
+
commands,
|
|
67
|
+
parallel: false
|
|
68
|
+
},
|
|
69
|
+
dependsOn: [
|
|
70
|
+
dockerTargetName
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
// Aggregate per-component scan targets under a single `trivy` target, and
|
|
74
|
+
// make `build` run the scan.
|
|
75
|
+
if (trivyTargetName !== 'trivy') {
|
|
76
|
+
addDependencyToTargetIfNotPresent(project, 'trivy', trivyTargetName);
|
|
77
|
+
}
|
|
78
|
+
addDependencyToTargetIfNotPresent(project, 'build', 'trivy');
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=docker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/nx-plugin/src/utils/docker.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n type ProjectConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { FsCommands } from './fs';\nimport { addDependencyToTargetIfNotPresent } from './nx';\nimport { CONTAINER_VERSIONS } from './versions';\n\nconst TRIVY_IGNORE_FILE = '.trivyignore';\n\nconst TRIVY_IGNORE_CONTENTS = `# Trivy ignore file. Add one vulnerability ID (e.g. CVE-2021-12345) per line to\n# suppress it during the image scan run on build.\n# https://trivy.dev/latest/docs/configuration/filtering/#by-finding-ids\n`;\n\nexport interface DockerScanTargetOptions {\n /**\n * Project configuration to add the scan target to (mutated in place).\n */\n readonly project: ProjectConfiguration;\n /**\n * Container engine command to invoke (\\`docker\\` or \\`finch\\`).\n */\n readonly containerEngine: string;\n /**\n * Name of the scan target to add, e.g. \\`my-agent-trivy\\`.\n */\n readonly trivyTargetName: string;\n /**\n * Name of the docker target that builds the image(s) to scan. The scan\n * target depends on it.\n */\n readonly dockerTargetName: string;\n /**\n * Tags of the images built by the docker target which should be scanned.\n */\n readonly imageTags: string[];\n}\n\n/**\n * Add a cacheable Trivy scan target for the images built by a docker target,\n * wire it under the aggregate \\`trivy\\` target, and make \\`build\\` depend on it.\n *\n * The scan target depends on the docker target and declares the project source\n * as its inputs, so an unchanged image is never re-scanned (a cache hit skips\n * the scan entirely). Each image is saved to a tarball under\n * \\`dist/<projectRoot>/trivy/<scan-key>\\` (kept out of any Docker build context)\n * and scanned with the pinned ECR-hosted Trivy image via a workspace-relative\n * bind mount, so the same commands work under both docker and finch. The scan\n * fails the build (exit code 1) on HIGH/CRITICAL vulnerabilities.\n *\n * A \\`.trivyignore\\` is vended at the project root (kept if it already exists)\n * for suppressing findings.\n */\nexport const addDockerScanTarget = (\n tree: Tree,\n options: DockerScanTargetOptions,\n): void => {\n const { project, containerEngine, trivyTargetName, dockerTargetName } =\n options;\n const { imageTags } = options;\n const projectRoot = project.root;\n\n const ignoreFilePath = joinPathFragments(projectRoot, TRIVY_IGNORE_FILE);\n if (!tree.exists(ignoreFilePath)) {\n tree.write(ignoreFilePath, TRIVY_IGNORE_CONTENTS);\n }\n\n // Stage scan artifacts in a directory unique to this scan target so that\n // sibling targets in the same project (e.g. multiple agents) don't clobber\n // each other's tarballs when run in parallel. The first image tag is unique\n // per target, so it makes a stable, collision-free key.\n const scanKey = imageTags[0].replace(/[^a-zA-Z0-9-]/g, '-');\n const scanDir = joinPathFragments('dist', projectRoot, 'trivy', scanKey);\n const trivyImage = `public.ecr.aws/aquasecurity/trivy:${CONTAINER_VERSIONS.trivy}`;\n\n const fs = new FsCommands(tree);\n const commands = [\n fs.rm(scanDir),\n fs.mkdir(scanDir),\n fs.cp(ignoreFilePath, joinPathFragments(scanDir, TRIVY_IGNORE_FILE)),\n ];\n\n imageTags.forEach((imageTag, index) => {\n const tarName = `image-${index}.tar`;\n commands.push(\n `${containerEngine} save -o ${joinPathFragments(scanDir, tarName)} ${imageTag}`,\n `${containerEngine} run --rm -v \"./${scanDir}\":/scan ${trivyImage} image --input /scan/${tarName} --ignorefile /scan/${TRIVY_IGNORE_FILE} --scanners vuln --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 --no-progress -q`,\n );\n });\n\n project.targets ??= {};\n project.targets[trivyTargetName] = {\n cache: true,\n // The scanned image is fully determined by the project source, so caching\n // on the source ensures an unchanged image is never re-scanned.\n inputs: ['default', '^production'],\n outputs: [`{workspaceRoot}/${scanDir}`],\n executor: 'nx:run-commands',\n options: {\n commands,\n parallel: false,\n },\n dependsOn: [dockerTargetName],\n };\n\n // Aggregate per-component scan targets under a single `trivy` target, and\n // make `build` run the scan.\n if (trivyTargetName !== 'trivy') {\n addDependencyToTargetIfNotPresent(project, 'trivy', trivyTargetName);\n }\n addDependencyToTargetIfNotPresent(project, 'build', 'trivy');\n};\n"],"names":["joinPathFragments","FsCommands","addDependencyToTargetIfNotPresent","CONTAINER_VERSIONS","TRIVY_IGNORE_FILE","TRIVY_IGNORE_CONTENTS","addDockerScanTarget","tree","options","project","containerEngine","trivyTargetName","dockerTargetName","imageTags","projectRoot","root","ignoreFilePath","exists","write","scanKey","replace","scanDir","trivyImage","trivy","fs","commands","rm","mkdir","cp","forEach","imageTag","index","tarName","push","targets","cache","inputs","outputs","executor","parallel","dependsOn"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,QAGZ,aAAa;AACpB,SAASC,UAAU,QAAQ,UAAO;AAClC,SAASC,iCAAiC,QAAQ,UAAO;AACzD,SAASC,kBAAkB,QAAQ,gBAAa;AAEhD,MAAMC,oBAAoB;AAE1B,MAAMC,wBAAwB,CAAC;;;AAG/B,CAAC;AA0BD;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,sBAAsB,CACjCC,MACAC;IAEA,MAAM,EAAEC,OAAO,EAAEC,eAAe,EAAEC,eAAe,EAAEC,gBAAgB,EAAE,GACnEJ;IACF,MAAM,EAAEK,SAAS,EAAE,GAAGL;IACtB,MAAMM,cAAcL,QAAQM,IAAI;IAEhC,MAAMC,iBAAiBhB,kBAAkBc,aAAaV;IACtD,IAAI,CAACG,KAAKU,MAAM,CAACD,iBAAiB;QAChCT,KAAKW,KAAK,CAACF,gBAAgBX;IAC7B;IAEA,yEAAyE;IACzE,2EAA2E;IAC3E,4EAA4E;IAC5E,wDAAwD;IACxD,MAAMc,UAAUN,SAAS,CAAC,EAAE,CAACO,OAAO,CAAC,kBAAkB;IACvD,MAAMC,UAAUrB,kBAAkB,QAAQc,aAAa,SAASK;IAChE,MAAMG,aAAa,CAAC,kCAAkC,EAAEnB,mBAAmBoB,KAAK,EAAE;IAElF,MAAMC,KAAK,IAAIvB,WAAWM;IAC1B,MAAMkB,WAAW;QACfD,GAAGE,EAAE,CAACL;QACNG,GAAGG,KAAK,CAACN;QACTG,GAAGI,EAAE,CAACZ,gBAAgBhB,kBAAkBqB,SAASjB;KAClD;IAEDS,UAAUgB,OAAO,CAAC,CAACC,UAAUC;QAC3B,MAAMC,UAAU,CAAC,MAAM,EAAED,MAAM,IAAI,CAAC;QACpCN,SAASQ,IAAI,CACX,GAAGvB,gBAAgB,SAAS,EAAEV,kBAAkBqB,SAASW,SAAS,CAAC,EAAEF,UAAU,EAC/E,GAAGpB,gBAAgB,gBAAgB,EAAEW,QAAQ,QAAQ,EAAEC,WAAW,qBAAqB,EAAEU,QAAQ,oBAAoB,EAAE5B,kBAAkB,yFAAyF,CAAC;IAEvO;IAEAK,QAAQyB,OAAO,KAAK,CAAC;IACrBzB,QAAQyB,OAAO,CAACvB,gBAAgB,GAAG;QACjCwB,OAAO;QACP,0EAA0E;QAC1E,gEAAgE;QAChEC,QAAQ;YAAC;YAAW;SAAc;QAClCC,SAAS;YAAC,CAAC,gBAAgB,EAAEhB,SAAS;SAAC;QACvCiB,UAAU;QACV9B,SAAS;YACPiB;YACAc,UAAU;QACZ;QACAC,WAAW;YAAC5B;SAAiB;IAC/B;IAEA,0EAA0E;IAC1E,6BAA6B;IAC7B,IAAID,oBAAoB,SAAS;QAC/BT,kCAAkCO,SAAS,SAASE;IACtD;IACAT,kCAAkCO,SAAS,SAAS;AACtD,EAAE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { OverwriteStrategy, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type Containers } from './containers';
|
|
7
|
+
import type { Iac } from './iac';
|
|
8
|
+
export declare const PNPM_BUILT_DEPENDENCIES: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Options controlling how the workspace is initialised. These mirror the
|
|
11
|
+
* preset schema so a workspace created via the preset and one initialised via
|
|
12
|
+
* the `init` generator end up in the same shape.
|
|
13
|
+
*/
|
|
14
|
+
export interface ApplyWorkspaceInitOptions {
|
|
15
|
+
/** The IaC provider to record in the plugin config. */
|
|
16
|
+
readonly iac: Iac;
|
|
17
|
+
/**
|
|
18
|
+
* The container engine to record. `undefined`/`'infer'` picks docker when
|
|
19
|
+
* installed, else finch.
|
|
20
|
+
*/
|
|
21
|
+
readonly containers?: Containers | 'infer';
|
|
22
|
+
/** Whether to configure MCP servers for coding agents. Defaults to true. */
|
|
23
|
+
readonly mcp?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* How to treat the generated workspace README. The preset owns the README of
|
|
26
|
+
* a greenfield workspace (`Overwrite`); the `init` generator must not clobber
|
|
27
|
+
* an existing workspace's README (`KeepExisting`, the default).
|
|
28
|
+
*/
|
|
29
|
+
readonly readmeOverwriteStrategy?: OverwriteStrategy;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to overwrite root package.json scripts that already exist. The
|
|
32
|
+
* preset owns a greenfield workspace's scripts (`true`); the `init`
|
|
33
|
+
* generator must not clobber an existing workspace's scripts (`false`,
|
|
34
|
+
* the default) — it only adds the convenience scripts that are absent.
|
|
35
|
+
*/
|
|
36
|
+
readonly overwriteScripts?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Transform an Nx workspace into one ready to run `@aws/nx-plugin` generators.
|
|
40
|
+
*
|
|
41
|
+
* This is the deterministic core shared by the workspace preset and the `init`
|
|
42
|
+
* generator. It is safe to re-run: every step is idempotent (config merges,
|
|
43
|
+
* keyed nx.json / package.json entries, create-if-missing files), so running
|
|
44
|
+
* it against an already-initialised workspace is a no-op.
|
|
45
|
+
*
|
|
46
|
+
* It preserves the workspace's module format: the root package.json `type`
|
|
47
|
+
* field is owned by the preset (written from its `--module` option) and left
|
|
48
|
+
* untouched here. It does NOT rewrite an existing `tsconfig.base.json`'s
|
|
49
|
+
* compiler options, migrate a workspace's package manager, or restructure
|
|
50
|
+
* existing projects — those are decisions for the user (see the "add to an
|
|
51
|
+
* existing workspace" guide).
|
|
52
|
+
*/
|
|
53
|
+
export declare const applyWorkspaceInit: (tree: Tree, { iac, containers, mcp, readmeOverwriteStrategy, overwriteScripts, }: ApplyWorkspaceInitOptions) => Promise<void>;
|