@aws/nx-plugin 1.0.7 → 1.0.8
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/migrations.json +16 -1
- package/package.json +1 -1
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +10 -0
- package/src/infra/app/files/app/README.md.template +12 -0
- package/src/infra/app/generator.js +8 -0
- package/src/infra/app/generator.js.map +1 -1
- package/src/migrations/latest/cache-inputs-outputs/metadata.json +3 -0
- package/src/migrations/latest/cache-inputs-outputs/migration.d.ts +6 -0
- package/src/migrations/latest/cache-inputs-outputs/migration.js +176 -0
- package/src/migrations/latest/cache-inputs-outputs/migration.js.map +1 -0
- package/src/migrations/latest/infra-test-loop/metadata.json +3 -0
- package/src/migrations/latest/infra-test-loop/migration.d.ts +6 -0
- package/src/migrations/latest/infra-test-loop/migration.js +110 -0
- package/src/migrations/latest/infra-test-loop/migration.js.map +1 -0
- package/src/migrations/latest/py-dynamodb-type-base-model-meta/metadata.json +3 -0
- package/src/migrations/latest/py-dynamodb-type-base-model-meta/migration.d.ts +6 -0
- package/src/migrations/latest/py-dynamodb-type-base-model-meta/migration.js +87 -0
- package/src/migrations/latest/py-dynamodb-type-base-model-meta/migration.js.map +1 -0
- package/src/migrations/v1.0.0-rc.90/0004-python-test-input-scoping/migration.js +8 -2
- package/src/migrations/v1.0.0-rc.90/0004-python-test-input-scoping/migration.js.map +1 -1
- package/src/open-api/py-client/files/client/__clientModuleName__.py.template +17 -6
- package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/py/dynamodb/files/__name__/entities/base.py.template +2 -2
- package/src/smithy/project/__snapshots__/generator.spec.ts.snap +9 -0
- package/src/smithy/project/generator.d.ts +9 -0
- package/src/smithy/project/generator.js +15 -0
- package/src/smithy/project/generator.js.map +1 -1
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +2 -0
- package/src/terraform/project/generator.js +2 -4
- package/src/terraform/project/generator.js.map +1 -1
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/lib/generator.d.ts +14 -3
- package/src/ts/lib/generator.js +18 -7
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/rdb/generator.js +4 -0
- package/src/ts/rdb/generator.js.map +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +102 -2
- package/src/utils/__snapshots__/cdk-test-setup.spec.ts.snap +25 -0
- package/src/utils/cdk-test-setup.d.ts +22 -0
- package/src/utils/cdk-test-setup.js +38 -0
- package/src/utils/cdk-test-setup.js.map +1 -0
- package/src/utils/files/cdk-test-setup/tests/global-setup.ts.template +45 -0
- package/src/utils/shared-constructs.js +2 -0
- package/src/utils/shared-constructs.js.map +1 -1
- package/src/utils/test/python-dependencies.d.ts +6 -0
- package/src/utils/test/python-dependencies.js +9 -0
- package/src/utils/test/python-dependencies.js.map +1 -1
- package/src/utils/test/warm-python-cache.js +40 -21
- package/src/utils/test/warm-python-cache.js.map +1 -1
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/utils/versions.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/terraform/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readNxJson,\n type TargetConfiguration,\n type Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\nimport { join, relative } from 'path';\nimport { addLicenseCheckToLintTarget } from '../../license/config.js';\nimport { getTsLibDetails } from '../../ts/lib/generator.js';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { updateGitIgnore } from '../../utils/git.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { kebabCase } from '../../utils/names.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { uvxCommand } from '../../utils/py.js';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n SHARED_TERRAFORM_DIR,\n SHARED_TERRAFORM_NAME,\n} from '../../utils/shared-constructs-constants.js';\nimport {\n terraformProviderVersions,\n withVersions,\n} from '../../utils/versions.js';\nimport type { TerraformProjectGeneratorSchema } from './schema';\n\n// Terraform projects carry no package.json, so their build tooling and the AWS\n// SDK the vended deploy scripts import are declared at the workspace root. This\n// generator records no metadata, so nothing a predicate could read.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: '@nx-extend/terraform', dev: true, root: true },\n { name: 'shx', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n { name: '@aws-sdk/client-s3', dev: true, root: true },\n { name: '@aws-sdk/client-sts', dev: true, root: true },\n { name: '@aws-sdk/credential-providers', dev: true, root: true },\n { name: '@smithy/config-resolver', dev: true, root: true },\n { name: '@smithy/node-config-provider', dev: true, root: true },\n // Declared for its pinned version, which goes into npm's `overrides` below.\n { name: '@nx/devkit', versionOnly: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n});\n\nconst NX_EXTEND_PLUGIN = '@nx-extend/terraform';\nexport const TERRAFORM_PROJECT_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\n/**\n * Checks formatting, mirroring the TypeScript and Python `format` targets: the\n * base target fails on an unformatted file and the `fix` configuration rewrites\n * it. Writing from the base target would rewrite the `default` input the hash is\n * computed over, so the target could never cache-hit.\n *\n * Scoped to the project's own `src` rather than `-recursive`, so it checks the\n * files the vended templates cover. `-diff` names what to fix when it fails.\n */\nexport const TERRAFORM_FORMAT_TARGET: TargetConfiguration = {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default'],\n options: {\n command: 'terraform fmt -check -diff',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n configurations: {\n fix: {\n command: 'terraform fmt',\n },\n 'skip-lint': {\n // Cross-platform no-op (`true` is not available on Windows cmd).\n command: 'node -e \"\"',\n },\n },\n};\n\nexport async function terraformProjectGenerator(\n tree: Tree,\n schema: TerraformProjectGeneratorSchema,\n): Promise<GeneratorCallback> {\n // Just use getTsLibDetails as it isn't specific to TS\n const lib = getTsLibDetails(tree, schema);\n const { fullyQualifiedName: sharedTfProjectName } = getTsLibDetails(tree, {\n name: SHARED_TERRAFORM_NAME,\n });\n\n const outDirToRootRelativePath = relative(\n join(tree.root, lib.dir, 'src'),\n tree.root,\n ).replace(/\\\\/g, '/');\n const distDir = joinPathFragments(\n outDirToRootRelativePath,\n 'dist',\n '{projectRoot}',\n );\n const tfDistDir = joinPathFragments(distDir, 'terraform');\n const checkovReportJsonPath = joinPathFragments(\n distDir,\n 'checkov',\n 'checkov_report.json',\n );\n // `terraform-init` keeps its `.terraform` here rather than in `src`, so it\n // never races the backend-configured targets over the shared one. `test` and\n // `validate` read this same directory rather than initialising their own.\n const initDataDir = joinPathFragments(distDir, 'terraform-init');\n\n // Provider downloads persist here, so a target whose `.terraform` was cleaned\n // links the providers it already has rather than re-downloading them. Nx does\n // not interpolate `{workspaceRoot}` inside `env`, so this is relative to the\n // target's `cwd`. It sits under `.terraform`, which this generator gitignores\n // — that is also what keeps the providers out of Nx's file walk — and unlike\n // `.nx/cache` it survives `nx reset`.\n //\n // One cache per project rather than one for the workspace: two `terraform\n // init` runs filling a shared cache concurrently each compute a different hash\n // for the same provider, because the hash covers a directory the other is\n // still writing, and terraform then rejects the mismatch against the lock\n // file. `terraform-init` is the only target that fills it, and the targets that\n // need the providers depend on that one, so no two writers ever meet.\n const pluginCacheDir = joinPathFragments(\n outDirToRootRelativePath,\n '.terraform',\n 'plugin-cache',\n '{projectRoot}',\n );\n\n // Calculate relative path from current project to common/terraform/metrics\n // Use forward slashes for terraform module source paths (even on Windows)\n const metricsModulePath = relative(\n join(tree.root, lib.dir, 'src'),\n join(tree.root, 'packages', SHARED_TERRAFORM_DIR, 'src', 'metrics'),\n ).replace(/\\\\/g, '/');\n\n updateGitIgnore(tree, '.', (patterns) => [...patterns, '.terraform']);\n\n const applicationTargets: {\n [targetName: string]: TargetConfiguration;\n } = {\n apply: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n command: `terraform apply ${tfDistDir}/dev.tfplan`,\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n dependsOn: ['plan'],\n },\n bootstrap: {\n executor: 'nx:run-commands',\n options: {\n forwardAllArgs: true,\n commands: ['tsx {projectRoot}/scripts/bootstrap.ts {projectRoot}'],\n cwd: '{workspaceRoot}',\n },\n },\n 'bootstrap-destroy': {\n executor: 'nx:run-commands',\n options: {\n forwardAllArgs: true,\n commands: [\n 'tsx {projectRoot}/scripts/bootstrap-destroy.ts {projectRoot}',\n ],\n cwd: '{workspaceRoot}',\n },\n },\n build: {\n dependsOn: ['format', 'checkov', 'test', `${sharedTfProjectName}:build`],\n },\n deploy: {\n dependsOn: ['apply'],\n },\n // The artifact-only sibling of build, which `plan` depends on.\n assemble: {\n dependsOn: [`${sharedTfProjectName}:assemble`],\n },\n destroy: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n command: 'terraform destroy -var-file=env/dev.tfvars',\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n dependsOn: ['init'],\n },\n init: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n env: { TF_ENV: 'dev' },\n },\n },\n options: {\n forwardAllArgs: true,\n commands: ['tsx {projectRoot}/scripts/init.ts {projectRoot}'],\n cwd: '{workspaceRoot}',\n },\n dependsOn: ['terraform-init', '^init'],\n },\n output: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default'],\n options: {\n command: 'terraform output -json',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n },\n plan: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n commands: [\n `shx mkdir -p ${tfDistDir}`,\n `terraform plan -var-file=env/dev.tfvars -out=${tfDistDir}/dev.tfplan`,\n ],\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n parallel: false,\n },\n dependsOn: ['init', 'validate', '^validate', 'assemble'],\n },\n };\n\n const libTargets: {\n [targetName: string]: TargetConfiguration;\n } = {\n build: {\n dependsOn: ['format', 'checkov', 'test'],\n },\n // A Terraform library vends modules rather than a deployable artifact, so\n // its `assemble` carries only whatever the consuming projects register on it.\n assemble: {\n executor: 'nx:noop',\n },\n format: TERRAFORM_FORMAT_TARGET,\n // Terraform has no linter of its own, so `lint` orchestrates the format\n // check. It exists so `nx run-many --target lint` reaches terraform\n // projects, and so `--configuration=fix` and `--configuration=skip-lint`\n // propagate to `format` the way they do for TypeScript and Python projects.\n lint: {\n dependsOn: ['format'],\n },\n init: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n commands: [\n {\n command: `shx mkdir -p ${pluginCacheDir}`,\n forwardAllArgs: false,\n },\n 'terraform init',\n ],\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n parallel: false,\n env: { TF_PLUGIN_CACHE_DIR: pluginCacheDir },\n },\n dependsOn: ['terraform-init'],\n },\n // `-backend=false` installs the modules and providers without configuring\n // the S3 backend, so this needs no credentials and runs on a fresh\n // workspace before `bootstrap`. Uncached: a cache hit on another machine\n // would report success over an empty `TF_DATA_DIR` and plugin cache.\n 'terraform-init': {\n executor: 'nx:run-commands',\n options: {\n commands: [\n { command: `shx mkdir -p ${pluginCacheDir}`, forwardAllArgs: false },\n 'terraform init -backend=false',\n ],\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n parallel: false,\n env: {\n TF_DATA_DIR: initDataDir,\n TF_PLUGIN_CACHE_DIR: pluginCacheDir,\n },\n },\n },\n // `^production` mirrors `test`: checkov resolves the relative modules a\n // project consumes, so a change in one must invalidate the scan.\n checkov: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default', '^production'],\n outputs: ['{workspaceRoot}/dist/{projectRoot}/checkov'],\n options: {\n command: uvxCommand(\n 'checkov',\n `--config-file ../checkov.yml --directory . -o cli -o json --output-file-path console,${checkovReportJsonPath}`,\n ),\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n },\n // Terraform's native test framework, which runs any `.tftest.hcl` files.\n // A project with none is a no-op success. Runs against the `TF_DATA_DIR`\n // `terraform-init` prepared, so it needs no credentials and works on a fresh\n // workspace before `bootstrap`. `^production` is what invalidates the cache\n // when a consumed module changes; `{projectRoot}/**/*` alone would serve a\n // stale pass.\n //\n // `TF_DATA_DIR` is terraform's working directory, not an artifact: its\n // provider entries are symlinks into the shared plugin cache, so restoring\n // it on another machine would yield dangling links while the commands that\n // repopulate them are skipped. Declaring no outputs keeps a cache hit to\n // what it actually asserts — that the tests passed for these inputs.\n test: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default', '^production'],\n outputs: [],\n options: {\n command: 'terraform test',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n env: { TF_DATA_DIR: initDataDir },\n },\n dependsOn: ['terraform-init'],\n },\n // Mirrors `test`: validates against the `TF_DATA_DIR` `terraform-init`\n // prepared, and declares no outputs for the same reason (see `test` above).\n validate: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default', '^production'],\n outputs: [],\n options: {\n command: 'terraform validate',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n env: { TF_DATA_DIR: initDataDir },\n },\n dependsOn: ['terraform-init'],\n },\n };\n\n const projectConfiguration = {\n root: lib.dir,\n projectType: schema.type,\n sourceRoot: joinPathFragments(lib.dir, 'src'),\n targets: sortObjectKeys({\n ...libTargets,\n ...(schema.type === 'application' ? applicationTargets : {}),\n }),\n };\n\n // Only create the project configuration on first run; skip it on re-run so\n // existing project.json customisations are preserved.\n if (!projectExists(tree, lib.fullyQualifiedName)) {\n addProjectConfiguration(tree, lib.fullyQualifiedName, projectConfiguration);\n }\n\n // The `lint` target checks licenses alongside formatting, as it does for\n // TypeScript and Python projects.\n addLicenseCheckToLintTarget(tree, lib.fullyQualifiedName);\n\n // This generator IS the Terraform project, so the provider is fixed.\n addGeneratorMetadata(\n tree,\n lib.fullyQualifiedName,\n TERRAFORM_PROJECT_GENERATOR_INFO,\n { iac: 'terraform' },\n );\n\n // The guides tell the reader to declare resources in `main.tf`, add variables\n // and outputs, and configure environments in `env/*.tfvars`, so everything\n // here is scaffolded once and then left alone. Provider version bumps reach\n // `providers.tf` through the vended version sync, which rewrites the pin in\n // place rather than the whole file.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, `./files/${schema.type}`),\n lib.dir,\n {\n metricsModulePath,\n stateKeyPrefix: kebabCase(lib.fullyQualifiedName),\n ...terraformProviderVersions(),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Checkov skips are the user's to curate, so preserve any they have added.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, './files/checkov'),\n lib.dir,\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n const nxJson = readNxJson(tree);\n\n if (\n !nxJson.plugins?.find((p) =>\n typeof p === 'string'\n ? p === NX_EXTEND_PLUGIN\n : p.plugin === NX_EXTEND_PLUGIN,\n )\n ) {\n nxJson.plugins = [...(nxJson.plugins ?? []), NX_EXTEND_PLUGIN];\n updateNxJson(tree, nxJson);\n }\n\n // Ensure shared constructs for Terraform are created\n await sharedConstructsGenerator(tree, { iac: 'terraform' }, DEPENDENCIES);\n\n // Add Terraform metrics\n await addGeneratorMetricsIfApplicable(tree, [\n TERRAFORM_PROJECT_GENERATOR_INFO,\n ]);\n\n addTsDependencies(tree, DEPENDENCIES);\n\n // @nx-extend/terraform has a peer dependency on @nx/devkit ^21.0.0 which causes\n // npm install to fail, so for NPM we add a resolution\n // Can remove when https://github.com/TriPSs/nx-extend/issues/407 is addressed\n if (detectPackageManager() === 'npm') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.overrides = {\n ...packageJson.overrides,\n ...withVersions(DEPENDENCIES, ['@nx/devkit']),\n };\n return packageJson;\n });\n }\n\n // `updateProjectConfiguration` re-serialises project.json with every inline\n // array expanded, which the vended `format` target rejects.\n await formatFilesInSubtree(tree);\n\n // `@nx-extend/terraform` is registered as an Nx plugin in nx.json, so Nx\n // loads it when computing the project graph — it must resolve even if the\n // caller would otherwise prefer to defer installing.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n ensureResolvable: [NX_EXTEND_PLUGIN],\n });\n}\nexport default terraformProjectGenerator;\n"],"names":["addProjectConfiguration","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readNxJson","updateJson","updateNxJson","join","relative","addLicenseCheckToLintTarget","getTsLibDetails","addTsDependencies","declareDependencies","ownedElsewhere","formatFilesInSubtree","updateGitIgnore","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","addGeneratorMetadata","getGeneratorInfo","projectExists","sortObjectKeys","uvxCommand","sharedConstructsGenerator","SHARED_CONSTRUCTS_DEPENDENCIES","SHARED_TERRAFORM_DIR","SHARED_TERRAFORM_NAME","terraformProviderVersions","withVersions","DEPENDENCIES","ts","name","dev","root","versionOnly","NX_EXTEND_PLUGIN","TERRAFORM_PROJECT_GENERATOR_INFO","filename","TERRAFORM_FORMAT_TARGET","executor","cache","inputs","options","command","forwardAllArgs","cwd","configurations","fix","terraformProjectGenerator","tree","schema","lib","fullyQualifiedName","sharedTfProjectName","outDirToRootRelativePath","dir","replace","distDir","tfDistDir","checkovReportJsonPath","initDataDir","pluginCacheDir","metricsModulePath","patterns","applicationTargets","apply","defaultConfiguration","dependsOn","bootstrap","commands","build","deploy","assemble","destroy","init","env","TF_ENV","output","plan","parallel","libTargets","format","lint","TF_PLUGIN_CACHE_DIR","TF_DATA_DIR","checkov","outputs","test","validate","projectConfiguration","projectType","type","sourceRoot","targets","iac","dirname","stateKeyPrefix","overwriteStrategy","KeepExisting","nxJson","plugins","find","p","plugin","packageJson","overrides","preferInstallDependencies","languages","ensureResolvable"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EACvBC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,UAAU,EAGVC,UAAU,EACVC,YAAY,QACP,aAAa;AACpB,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AACtC,SAASC,2BAA2B,QAAQ,0BAA0B;AACtE,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,yBAAyB,QAAQ,mCAAmC;AAC7E,SACEC,8BAA8B,EAC9BC,oBAAoB,EACpBC,qBAAqB,QAChB,6CAA6C;AACpD,SACEC,yBAAyB,EACzBC,YAAY,QACP,0BAA0B;AAGjC,+EAA+E;AAC/E,gFAAgF;AAChF,oEAAoE;AACpE,OAAO,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AhD,kBAAkB,YAAY8F,OAAO,EAAE,oBACvC5C,IAAII,GAAG,EACP,CAAC,GACD;QACE0C,mBAAmB/F,kBAAkBgG,YAAY;IACnD;IAGF,MAAMC,SAAShG,WAAW8C;IAE1B,IACE,CAACkD,OAAOC,OAAO,EAAEC,KAAK,CAACC,IACrB,OAAOA,MAAM,WACTA,MAAMnE,mBACNmE,EAAEC,MAAM,KAAKpE,mBAEnB;QACAgE,OAAOC,OAAO,GAAG;eAAKD,OAAOC,OAAO,IAAI,EAAE;YAAGjE;SAAiB;QAC9D9B,aAAa4C,MAAMkD;IACrB;IAEA,qDAAqD;IACrD,MAAM5E,0BAA0B0B,MAAM;QAAE6C,KAAK;IAAY,GAAGjE;IAE5D,wBAAwB;IACxB,MAAMb,gCAAgCiC,MAAM;QAC1Cb;KACD;IAED1B,kBAAkBuC,MAAMpB;IAExB,gFAAgF;IAChF,sDAAsD;IACtD,8EAA8E;IAC9E,IAAI9B,2BAA2B,OAAO;QACpCK,WAAW6C,MAAM,gBAAgB,CAACuD;YAChCA,YAAYC,SAAS,GAAG;gBACtB,GAAGD,YAAYC,SAAS;gBACxB,GAAG7E,aAAaC,cAAc;oBAAC;iBAAa,CAAC;YAC/C;YACA,OAAO2E;QACT;IACF;IAEA,4EAA4E;IAC5E,4DAA4D;IAC5D,MAAM3F,qBAAqBoC;IAE3B,yEAAyE;IACzE,0EAA0E;IAC1E,qDAAqD;IACrD,OAAO,IACLlC,oBAAoBkC,MAAMC,OAAOwD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;YACzBC,kBAAkB;gBAACzE;aAAiB;QACtC;AACJ;AACA,eAAea,0BAA0B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/terraform/project/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addProjectConfiguration,\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readNxJson,\n type TargetConfiguration,\n type Tree,\n updateJson,\n updateNxJson,\n} from '@nx/devkit';\nimport { join, relative } from 'path';\nimport { addLicenseCheckToLintTarget } from '../../license/config.js';\nimport { getTsLibDetails } from '../../ts/lib/generator.js';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { updateGitIgnore } from '../../utils/git.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { kebabCase } from '../../utils/names.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { uvxCommand } from '../../utils/py.js';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n SHARED_TERRAFORM_DIR,\n SHARED_TERRAFORM_NAME,\n} from '../../utils/shared-constructs-constants.js';\nimport {\n terraformProviderVersions,\n withVersions,\n} from '../../utils/versions.js';\nimport type { TerraformProjectGeneratorSchema } from './schema';\n\n// Terraform projects carry no package.json, so their build tooling and the AWS\n// SDK the vended deploy scripts import are declared at the workspace root. This\n// generator records no metadata, so nothing a predicate could read.\nexport const DEPENDENCIES = declareDependencies()({\n ts: [\n { name: '@nx-extend/terraform', dev: true, root: true },\n { name: 'shx', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n { name: '@aws-sdk/client-s3', dev: true, root: true },\n { name: '@aws-sdk/client-sts', dev: true, root: true },\n { name: '@aws-sdk/credential-providers', dev: true, root: true },\n { name: '@smithy/config-resolver', dev: true, root: true },\n { name: '@smithy/node-config-provider', dev: true, root: true },\n // Declared for its pinned version, which goes into npm's `overrides` below.\n { name: '@nx/devkit', versionOnly: true },\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ],\n});\n\nconst NX_EXTEND_PLUGIN = '@nx-extend/terraform';\nexport const TERRAFORM_PROJECT_GENERATOR_INFO: NxGeneratorInfo =\n getGeneratorInfo(import.meta.filename);\n\n/**\n * Checks formatting, mirroring the TypeScript and Python `format` targets: the\n * base target fails on an unformatted file and the `fix` configuration rewrites\n * it. Writing from the base target would rewrite the `default` input the hash is\n * computed over, so the target could never cache-hit.\n *\n * Scoped to the project's own `src` rather than `-recursive`, so it checks the\n * files the vended templates cover. `-diff` names what to fix when it fails.\n */\nexport const TERRAFORM_FORMAT_TARGET: TargetConfiguration = {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default'],\n options: {\n command: 'terraform fmt -check -diff',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n configurations: {\n fix: {\n command: 'terraform fmt',\n },\n 'skip-lint': {\n // Cross-platform no-op (`true` is not available on Windows cmd).\n command: 'node -e \"\"',\n },\n },\n};\n\nexport async function terraformProjectGenerator(\n tree: Tree,\n schema: TerraformProjectGeneratorSchema,\n): Promise<GeneratorCallback> {\n // Just use getTsLibDetails as it isn't specific to TS\n const lib = getTsLibDetails(tree, schema);\n const { fullyQualifiedName: sharedTfProjectName } = getTsLibDetails(tree, {\n name: SHARED_TERRAFORM_NAME,\n });\n\n const outDirToRootRelativePath = relative(\n join(tree.root, lib.dir, 'src'),\n tree.root,\n ).replace(/\\\\/g, '/');\n const distDir = joinPathFragments(\n outDirToRootRelativePath,\n 'dist',\n '{projectRoot}',\n );\n const tfDistDir = joinPathFragments(distDir, 'terraform');\n const checkovReportJsonPath = joinPathFragments(\n distDir,\n 'checkov',\n 'checkov_report.json',\n );\n // `terraform-init` keeps its `.terraform` here rather than in `src`, so it\n // never races the backend-configured targets over the shared one. `test` and\n // `validate` read this same directory rather than initialising their own.\n const initDataDir = joinPathFragments(distDir, 'terraform-init');\n\n // Provider downloads persist here, so a target whose `.terraform` was cleaned\n // links the providers it already has rather than re-downloading them. Nx does\n // not interpolate `{workspaceRoot}` inside `env`, so this is relative to the\n // target's `cwd`. It sits under `.terraform`, which this generator gitignores\n // — that is also what keeps the providers out of Nx's file walk — and unlike\n // `.nx/cache` it survives `nx reset`.\n //\n // One cache per project rather than one for the workspace: two `terraform\n // init` runs filling a shared cache concurrently each compute a different hash\n // for the same provider, because the hash covers a directory the other is\n // still writing, and terraform then rejects the mismatch against the lock\n // file. `terraform-init` is the only target that fills it, and the targets that\n // need the providers depend on that one, so no two writers ever meet.\n const pluginCacheDir = joinPathFragments(\n outDirToRootRelativePath,\n '.terraform',\n 'plugin-cache',\n '{projectRoot}',\n );\n\n // Calculate relative path from current project to common/terraform/metrics\n // Use forward slashes for terraform module source paths (even on Windows)\n const metricsModulePath = relative(\n join(tree.root, lib.dir, 'src'),\n join(tree.root, 'packages', SHARED_TERRAFORM_DIR, 'src', 'metrics'),\n ).replace(/\\\\/g, '/');\n\n updateGitIgnore(tree, '.', (patterns) => [...patterns, '.terraform']);\n\n const applicationTargets: {\n [targetName: string]: TargetConfiguration;\n } = {\n apply: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n command: `terraform apply ${tfDistDir}/dev.tfplan`,\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n dependsOn: ['plan'],\n },\n bootstrap: {\n executor: 'nx:run-commands',\n options: {\n forwardAllArgs: true,\n commands: ['tsx {projectRoot}/scripts/bootstrap.ts {projectRoot}'],\n cwd: '{workspaceRoot}',\n },\n },\n 'bootstrap-destroy': {\n executor: 'nx:run-commands',\n options: {\n forwardAllArgs: true,\n commands: [\n 'tsx {projectRoot}/scripts/bootstrap-destroy.ts {projectRoot}',\n ],\n cwd: '{workspaceRoot}',\n },\n },\n build: {\n dependsOn: ['format', 'checkov', 'test', `${sharedTfProjectName}:build`],\n },\n deploy: {\n dependsOn: ['apply'],\n },\n // The artifact-only sibling of build, which `plan` depends on.\n assemble: {\n dependsOn: [`${sharedTfProjectName}:assemble`],\n },\n destroy: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n command: 'terraform destroy -var-file=env/dev.tfvars',\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n dependsOn: ['init'],\n },\n init: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n env: { TF_ENV: 'dev' },\n },\n },\n options: {\n forwardAllArgs: true,\n commands: ['tsx {projectRoot}/scripts/init.ts {projectRoot}'],\n cwd: '{workspaceRoot}',\n },\n dependsOn: ['terraform-init', '^init'],\n },\n // Reads remote state, which no input can hash.\n output: {\n executor: 'nx:run-commands',\n cache: false,\n options: {\n command: 'terraform output -json',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n },\n plan: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n commands: [\n `shx mkdir -p ${tfDistDir}`,\n `terraform plan -var-file=env/dev.tfvars -out=${tfDistDir}/dev.tfplan`,\n ],\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n parallel: false,\n },\n dependsOn: ['init', 'validate', '^validate', 'assemble'],\n },\n };\n\n const libTargets: {\n [targetName: string]: TargetConfiguration;\n } = {\n build: {\n dependsOn: ['format', 'checkov', 'test'],\n },\n // A Terraform library vends modules rather than a deployable artifact, so\n // its `assemble` carries only whatever the consuming projects register on it.\n assemble: {\n executor: 'nx:noop',\n },\n format: TERRAFORM_FORMAT_TARGET,\n // Terraform has no linter of its own, so `lint` orchestrates the format\n // check. It exists so `nx run-many --target lint` reaches terraform\n // projects, and so `--configuration=fix` and `--configuration=skip-lint`\n // propagate to `format` the way they do for TypeScript and Python projects.\n lint: {\n dependsOn: ['format'],\n },\n init: {\n executor: 'nx:run-commands',\n defaultConfiguration: 'dev',\n configurations: {\n dev: {\n commands: [\n {\n command: `shx mkdir -p ${pluginCacheDir}`,\n forwardAllArgs: false,\n },\n 'terraform init',\n ],\n },\n },\n options: {\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n parallel: false,\n env: { TF_PLUGIN_CACHE_DIR: pluginCacheDir },\n },\n dependsOn: ['terraform-init'],\n },\n // `-backend=false` installs the modules and providers without configuring\n // the S3 backend, so this needs no credentials and runs on a fresh\n // workspace before `bootstrap`. Uncached: a cache hit on another machine\n // would report success over an empty `TF_DATA_DIR` and plugin cache.\n 'terraform-init': {\n executor: 'nx:run-commands',\n options: {\n commands: [\n { command: `shx mkdir -p ${pluginCacheDir}`, forwardAllArgs: false },\n 'terraform init -backend=false',\n ],\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n parallel: false,\n env: {\n TF_DATA_DIR: initDataDir,\n TF_PLUGIN_CACHE_DIR: pluginCacheDir,\n },\n },\n },\n // `^production` mirrors `test`: checkov resolves the relative modules a\n // project consumes, so a change in one must invalidate the scan.\n checkov: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default', '^production'],\n outputs: ['{workspaceRoot}/dist/{projectRoot}/checkov'],\n options: {\n command: uvxCommand(\n 'checkov',\n `--config-file ../checkov.yml --directory . -o cli -o json --output-file-path console,${checkovReportJsonPath}`,\n ),\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n },\n },\n // Terraform's native test framework, which runs any `.tftest.hcl` files.\n // A project with none is a no-op success. Runs against the `TF_DATA_DIR`\n // `terraform-init` prepared, so it needs no credentials and works on a fresh\n // workspace before `bootstrap`. `^production` is what invalidates the cache\n // when a consumed module changes; `{projectRoot}/**/*` alone would serve a\n // stale pass.\n //\n // `TF_DATA_DIR` is terraform's working directory, not an artifact: its\n // provider entries are symlinks into the shared plugin cache, so restoring\n // it on another machine would yield dangling links while the commands that\n // repopulate them are skipped. Declaring no outputs keeps a cache hit to\n // what it actually asserts — that the tests passed for these inputs.\n test: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default', '^production'],\n outputs: [],\n options: {\n command: 'terraform test',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n env: { TF_DATA_DIR: initDataDir },\n },\n dependsOn: ['terraform-init'],\n },\n // Mirrors `test`: validates against the `TF_DATA_DIR` `terraform-init`\n // prepared, and declares no outputs for the same reason (see `test` above).\n validate: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['default', '^production'],\n outputs: [],\n options: {\n command: 'terraform validate',\n forwardAllArgs: true,\n cwd: '{projectRoot}/src',\n env: { TF_DATA_DIR: initDataDir },\n },\n dependsOn: ['terraform-init'],\n },\n };\n\n const projectConfiguration = {\n root: lib.dir,\n projectType: schema.type,\n sourceRoot: joinPathFragments(lib.dir, 'src'),\n targets: sortObjectKeys({\n ...libTargets,\n ...(schema.type === 'application' ? applicationTargets : {}),\n }),\n };\n\n // Only create the project configuration on first run; skip it on re-run so\n // existing project.json customisations are preserved.\n if (!projectExists(tree, lib.fullyQualifiedName)) {\n addProjectConfiguration(tree, lib.fullyQualifiedName, projectConfiguration);\n }\n\n // The `lint` target checks licenses alongside formatting, as it does for\n // TypeScript and Python projects.\n addLicenseCheckToLintTarget(tree, lib.fullyQualifiedName);\n\n // This generator IS the Terraform project, so the provider is fixed.\n addGeneratorMetadata(\n tree,\n lib.fullyQualifiedName,\n TERRAFORM_PROJECT_GENERATOR_INFO,\n { iac: 'terraform' },\n );\n\n // The guides tell the reader to declare resources in `main.tf`, add variables\n // and outputs, and configure environments in `env/*.tfvars`, so everything\n // here is scaffolded once and then left alone. Provider version bumps reach\n // `providers.tf` through the vended version sync, which rewrites the pin in\n // place rather than the whole file.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, `./files/${schema.type}`),\n lib.dir,\n {\n metricsModulePath,\n stateKeyPrefix: kebabCase(lib.fullyQualifiedName),\n ...terraformProviderVersions(),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Checkov skips are the user's to curate, so preserve any they have added.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, './files/checkov'),\n lib.dir,\n {},\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n const nxJson = readNxJson(tree);\n\n if (\n !nxJson.plugins?.find((p) =>\n typeof p === 'string'\n ? p === NX_EXTEND_PLUGIN\n : p.plugin === NX_EXTEND_PLUGIN,\n )\n ) {\n nxJson.plugins = [...(nxJson.plugins ?? []), NX_EXTEND_PLUGIN];\n updateNxJson(tree, nxJson);\n }\n\n // Ensure shared constructs for Terraform are created\n await sharedConstructsGenerator(tree, { iac: 'terraform' }, DEPENDENCIES);\n\n // Add Terraform metrics\n await addGeneratorMetricsIfApplicable(tree, [\n TERRAFORM_PROJECT_GENERATOR_INFO,\n ]);\n\n addTsDependencies(tree, DEPENDENCIES);\n\n // @nx-extend/terraform has a peer dependency on @nx/devkit ^21.0.0 which causes\n // npm install to fail, so for NPM we add a resolution\n // Can remove when https://github.com/TriPSs/nx-extend/issues/407 is addressed\n if (detectPackageManager() === 'npm') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.overrides = {\n ...packageJson.overrides,\n ...withVersions(DEPENDENCIES, ['@nx/devkit']),\n };\n return packageJson;\n });\n }\n\n // `updateProjectConfiguration` re-serialises project.json with every inline\n // array expanded, which the vended `format` target rejects.\n await formatFilesInSubtree(tree);\n\n // `@nx-extend/terraform` is registered as an Nx plugin in nx.json, so Nx\n // loads it when computing the project graph — it must resolve even if the\n // caller would otherwise prefer to defer installing.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n ensureResolvable: [NX_EXTEND_PLUGIN],\n });\n}\nexport default terraformProjectGenerator;\n"],"names":["addProjectConfiguration","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readNxJson","updateJson","updateNxJson","join","relative","addLicenseCheckToLintTarget","getTsLibDetails","addTsDependencies","declareDependencies","ownedElsewhere","formatFilesInSubtree","updateGitIgnore","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","addGeneratorMetadata","getGeneratorInfo","projectExists","sortObjectKeys","uvxCommand","sharedConstructsGenerator","SHARED_CONSTRUCTS_DEPENDENCIES","SHARED_TERRAFORM_DIR","SHARED_TERRAFORM_NAME","terraformProviderVersions","withVersions","DEPENDENCIES","ts","name","dev","root","versionOnly","NX_EXTEND_PLUGIN","TERRAFORM_PROJECT_GENERATOR_INFO","filename","TERRAFORM_FORMAT_TARGET","executor","cache","inputs","options","command","forwardAllArgs","cwd","configurations","fix","terraformProjectGenerator","tree","schema","lib","fullyQualifiedName","sharedTfProjectName","outDirToRootRelativePath","dir","replace","distDir","tfDistDir","checkovReportJsonPath","initDataDir","pluginCacheDir","metricsModulePath","patterns","applicationTargets","apply","defaultConfiguration","dependsOn","bootstrap","commands","build","deploy","assemble","destroy","init","env","TF_ENV","output","plan","parallel","libTargets","format","lint","TF_PLUGIN_CACHE_DIR","TF_DATA_DIR","checkov","outputs","test","validate","projectConfiguration","projectType","type","sourceRoot","targets","iac","dirname","stateKeyPrefix","overwriteStrategy","KeepExisting","nxJson","plugins","find","p","plugin","packageJson","overrides","preferInstallDependencies","languages","ensureResolvable"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EACvBC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,UAAU,EAGVC,UAAU,EACVC,YAAY,QACP,aAAa;AACpB,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AACtC,SAASC,2BAA2B,QAAQ,0BAA0B;AACtE,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SACEC,oBA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OAAOwD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;YACzBC,kBAAkB;gBAACzE;aAAiB;QACtC;AACJ;AACA,eAAea,0BAA0B"}
|
|
@@ -59,7 +59,7 @@ exports[`ts lib generator > should configure named inputs in nx.json 1`] = `
|
|
|
59
59
|
"biome": ["default", "{workspaceRoot}/biome.json"],
|
|
60
60
|
"default": [
|
|
61
61
|
{
|
|
62
|
-
"dependentTasksOutputFiles": "!{reports,coverage}
|
|
62
|
+
"dependentTasksOutputFiles": "!{reports/**,coverage/**,dist/**/checkov/checkov_report.json,dist/**/test-output/vitest/coverage/**}",
|
|
63
63
|
"transitive": true
|
|
64
64
|
}
|
|
65
65
|
]
|
|
@@ -34,14 +34,25 @@ export declare const TS_LIB_GENERATOR_INFO: NxGeneratorInfo;
|
|
|
34
34
|
* generators emit generated sources outside `dist` (an OpenAPI client under a
|
|
35
35
|
* website's `src/generated`, a Smithy SSDK, the Prisma client) and add them to
|
|
36
36
|
* `.gitignore`, which keeps them out of the project's own fileset — so this
|
|
37
|
-
* input is the only thing that hashes them.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* input is the only thing that hashes them.
|
|
38
|
+
*
|
|
39
|
+
* The excluded paths are reports nothing downstream reads, and each is
|
|
40
|
+
* rewritten on every run that produces it, which would mint a fresh hash that
|
|
41
|
+
* cascades through the graph:
|
|
42
|
+
* - `reports/` and `coverage/` hold pytest's JUnit and coverage XML, which
|
|
43
|
+
* carry a wall-clock timestamp.
|
|
44
|
+
* - `dist/<project>/checkov/checkov_report.json` is the report a CDK or Terraform
|
|
45
|
+
* project's checkov scan writes, rewritten whenever the scan is uncached.
|
|
46
|
+
* - `dist/<project>/test-output/vitest/coverage/` is vitest's coverage output.
|
|
47
|
+
*
|
|
48
|
+
* Each report is matched by its full path, so a project whose path contains a
|
|
49
|
+
* `checkov` or `coverage` segment keeps its build output hashed.
|
|
40
50
|
*/
|
|
41
51
|
export declare const DEPENDENT_TASKS_OUTPUT_FILES_INPUT: {
|
|
42
52
|
dependentTasksOutputFiles: string;
|
|
43
53
|
transitive: boolean;
|
|
44
54
|
};
|
|
55
|
+
export declare const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS: string[];
|
|
45
56
|
export interface TsLibDetails {
|
|
46
57
|
/**
|
|
47
58
|
* Full package name including scope (eg @foo/bar)
|
package/src/ts/lib/generator.js
CHANGED
|
@@ -30,19 +30,30 @@ export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
|
30
30
|
* generators emit generated sources outside `dist` (an OpenAPI client under a
|
|
31
31
|
* website's `src/generated`, a Smithy SSDK, the Prisma client) and add them to
|
|
32
32
|
* `.gitignore`, which keeps them out of the project's own fileset — so this
|
|
33
|
-
* input is the only thing that hashes them.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* input is the only thing that hashes them.
|
|
34
|
+
*
|
|
35
|
+
* The excluded paths are reports nothing downstream reads, and each is
|
|
36
|
+
* rewritten on every run that produces it, which would mint a fresh hash that
|
|
37
|
+
* cascades through the graph:
|
|
38
|
+
* - `reports/` and `coverage/` hold pytest's JUnit and coverage XML, which
|
|
39
|
+
* carry a wall-clock timestamp.
|
|
40
|
+
* - `dist/<project>/checkov/checkov_report.json` is the report a CDK or Terraform
|
|
41
|
+
* project's checkov scan writes, rewritten whenever the scan is uncached.
|
|
42
|
+
* - `dist/<project>/test-output/vitest/coverage/` is vitest's coverage output.
|
|
43
|
+
*
|
|
44
|
+
* Each report is matched by its full path, so a project whose path contains a
|
|
45
|
+
* `checkov` or `coverage` segment keeps its build output hashed.
|
|
36
46
|
*/ export const DEPENDENT_TASKS_OUTPUT_FILES_INPUT = {
|
|
37
|
-
dependentTasksOutputFiles: '!{reports,coverage}
|
|
47
|
+
dependentTasksOutputFiles: '!{reports/**,coverage/**,dist/**/checkov/checkov_report.json,dist/**/test-output/vitest/coverage/**}',
|
|
38
48
|
transitive: true
|
|
39
49
|
};
|
|
40
50
|
// Globs this generator has vended for the dependent-task-output input. Any of
|
|
41
|
-
// them is replaced
|
|
42
|
-
//
|
|
43
|
-
const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [
|
|
51
|
+
// them is replaced, so the entry is neither duplicated nor left at a different
|
|
52
|
+
// scope when a generator or migration re-runs.
|
|
53
|
+
export const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [
|
|
44
54
|
'**/*',
|
|
45
55
|
'dist/**',
|
|
56
|
+
'!{reports,coverage}/**',
|
|
46
57
|
DEPENDENT_TASKS_OUTPUT_FILES_INPUT.dependentTasksOutputFiles
|
|
47
58
|
];
|
|
48
59
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n type NxJsonConfiguration,\n OverwriteStrategy,\n readProjectConfiguration,\n type TargetConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { libraryGenerator } from '@nx/js';\nimport { declareDependencies } from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { toKebabCase } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n mergeTarget,\n mergeTargetDefault,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport type { TsProjectGeneratorSchema } from './schema';\nimport {\n configureTsProject,\n TS_PROJECT_DEPENDENCIES,\n} from './ts-project-utils.js';\nimport { VITEST_DEPENDENCIES } from './vitest.js';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...VITEST_DEPENDENCIES, ...TS_PROJECT_DEPENDENCIES],\n});\n\nexport const TS_LIB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Consumes build artifacts produced by a project's dependencies, so a task\n * re-runs when the output it actually reads changes.\n *\n * Test reports are excluded rather than build artifacts included: several\n * generators emit generated sources outside `dist` (an OpenAPI client under a\n * website's `src/generated`, a Smithy SSDK, the Prisma client) and add them to\n * `.gitignore`, which keeps them out of the project's own fileset — so this\n * input is the only thing that hashes them. `reports/` and `coverage/` hold\n * pytest's JUnit and coverage XML, which carry a wall-clock timestamp and so\n * mint a fresh hash on every test run that would cascade through the graph.\n */\nexport const DEPENDENT_TASKS_OUTPUT_FILES_INPUT = {\n dependentTasksOutputFiles: '!{reports,coverage}/**',\n transitive: true,\n};\n\n// Globs this generator has vended for the dependent-task-output input. Any of\n// them is replaced in place, so the entry is neither duplicated nor left at a\n// different scope when a generator re-runs.\nconst VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [\n '**/*',\n 'dist/**',\n DEPENDENT_TASKS_OUTPUT_FILES_INPUT.dependentTasksOutputFiles,\n];\n\nexport interface TsLibDetails {\n /**\n * Full package name including scope (eg @foo/bar)\n */\n readonly fullyQualifiedName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n}\n\n/**\n * Returns details about the TS library to be created\n */\nexport const getTsLibDetails = (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): TsLibDetails => {\n const scope = getNpmScopePrefix(tree);\n const normalizedName = toKebabCase(schema.name);\n const fullyQualifiedName = `${scope}${normalizedName}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName };\n};\n\n/**\n * Generates a typescript project\n */\nexport const tsProjectGenerator = async (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, schema);\n // The module format is workspace-wide, established by the preset when the\n // workspace is created, so vending generators always infer it from the tree.\n const esm = isEsmWorkspace(tree);\n\n // Only scaffold the project on first run; on re-run skip creation so user\n // edits are preserved, but continue to (re)apply the configuration below.\n if (!projectExists(tree, fullyQualifiedName)) {\n await libraryGenerator(tree, {\n ...schema,\n name: fullyQualifiedName,\n directory: dir,\n skipPackageJson: true,\n bundler: 'tsc', // TODO: consider supporting others\n linter: 'none',\n unitTestRunner: 'vitest',\n // Register the @nx/vitest plugin so the test target is inferred rather\n // than emitting the deprecated @nx/vitest:test executor target.\n addPlugin: true,\n });\n\n // Replace with simpler sample source code\n tree.delete(joinPathFragments(dir, 'src'));\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n joinPathFragments(dir),\n {\n fullyQualifiedName,\n esm,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n await configureTsProject(\n tree,\n {\n dir,\n fullyQualifiedName,\n esm,\n },\n DEPENDENCIES,\n );\n\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n const targets = projectConfiguration.targets;\n\n // Merged rather than assigned so a re-run converges this generator's own\n // configuration without discarding what other generators contributed to the\n // same targets — the `bundle` that ts#lambda-function adds to build and\n // assemble, say, which those targets must keep depending on.\n targets['compile'] = mergeTarget(targets['compile'], {\n executor: 'nx:run-commands',\n outputs: ['{workspaceRoot}/dist/{projectRoot}/tsc'],\n options: {\n command: 'tsc --build tsconfig.lib.json',\n cwd: '{projectRoot}',\n },\n });\n targets['build'] = mergeTarget(targets['build'], {\n dependsOn: ['lint', 'compile', 'test'],\n });\n // The artifact-only sibling of build, which the deploy targets depend on.\n targets['assemble'] = mergeTarget(targets['assemble'], {\n dependsOn: ['compile'],\n });\n projectConfiguration.targets = sortObjectKeys(targets);\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);\n\n updateJson(tree, 'nx.json', (nxJson: NxJsonConfiguration) => {\n nxJson.namedInputs = {\n ...nxJson.namedInputs,\n default: [\n ...(nxJson.namedInputs?.default ?? []).filter(\n (input) =>\n typeof input !== 'object' ||\n !('dependentTasksOutputFiles' in input) ||\n !(\n VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS.includes(\n input.dependentTasksOutputFiles as string,\n ) && input.transitive\n ),\n ),\n DEPENDENT_TASKS_OUTPUT_FILES_INPUT,\n ],\n };\n\n const withDefaultInput = (base: Partial<TargetConfiguration>) => ({\n ...base,\n inputs: [\n ...(base.inputs ?? []).filter((i) => i !== 'default'),\n 'default',\n ],\n });\n\n nxJson.targetDefaults = {\n ...nxJson.targetDefaults,\n compile: mergeTargetDefault(nxJson.targetDefaults?.compile, (base) => ({\n cache: true,\n ...withDefaultInput(base),\n })),\n build: mergeTargetDefault(nxJson.targetDefaults?.build, (base) => ({\n cache: true,\n ...withDefaultInput(base),\n })),\n test: mergeTargetDefault(nxJson.targetDefaults?.test, withDefaultInput),\n };\n\n // Ensure we only declare a single typescript plugin with the correct settings\n nxJson.plugins = [\n {\n plugin: '@nx/js/typescript',\n options: {\n typecheck: {\n targetName: 'typecheck',\n },\n build: {\n targetName: 'compile',\n configName: 'tsconfig.lib.json',\n buildDepsName: 'build-deps',\n watchDepsName: 'watch-deps',\n },\n },\n },\n ...(nxJson.plugins ?? []).filter(\n (p) => typeof p === 'string' || p.plugin !== '@nx/js/typescript',\n ),\n ];\n\n return nxJson;\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_LIB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n // `installDependencies` ensures vitest resolves for the `typescript` language (the\n // generated vitest.config.mts imports it and Nx loads that config when\n // computing the project graph), so a deferred install still runs when needed.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\nexport default tsProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","libraryGenerator","declareDependencies","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","mergeTarget","mergeTargetDefault","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","configureTsProject","TS_PROJECT_DEPENDENCIES","VITEST_DEPENDENCIES","DEPENDENCIES","ts","TS_LIB_GENERATOR_INFO","filename","DEPENDENT_TASKS_OUTPUT_FILES_INPUT","dependentTasksOutputFiles","transitive","VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS","getTsLibDetails","tree","schema","scope","normalizedName","name","fullyQualifiedName","dir","directory","subDirectory","tsProjectGenerator","esm","skipPackageJson","bundler","linter","unitTestRunner","addPlugin","delete","dirname","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","projectConfiguration","targets","executor","outputs","options","command","cwd","dependsOn","nxJson","namedInputs","default","filter","input","includes","withDefaultInput","base","inputs","i","targetDefaults","compile","cache","build","test","plugins","plugin","typecheck","targetName","configName","buildDepsName","watchDepsName","p","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EAEjBC,iBAAiB,EACjBC,wBAAwB,EAGxBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,iBAAiB,Q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MAAMC,OAAOoD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AACF,eAAe7C,mBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n type NxJsonConfiguration,\n OverwriteStrategy,\n readProjectConfiguration,\n type TargetConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { libraryGenerator } from '@nx/js';\nimport { declareDependencies } from '../../utils/declared-dependencies.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { toKebabCase } from '../../utils/names.js';\nimport { getNpmScopePrefix } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n mergeTarget,\n mergeTargetDefault,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { getPackageManagerDisplayCommands } from '../../utils/pkg-manager.js';\nimport type { TsProjectGeneratorSchema } from './schema';\nimport {\n configureTsProject,\n TS_PROJECT_DEPENDENCIES,\n} from './ts-project-utils.js';\nimport { VITEST_DEPENDENCIES } from './vitest.js';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...VITEST_DEPENDENCIES, ...TS_PROJECT_DEPENDENCIES],\n});\n\nexport const TS_LIB_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Consumes build artifacts produced by a project's dependencies, so a task\n * re-runs when the output it actually reads changes.\n *\n * Test reports are excluded rather than build artifacts included: several\n * generators emit generated sources outside `dist` (an OpenAPI client under a\n * website's `src/generated`, a Smithy SSDK, the Prisma client) and add them to\n * `.gitignore`, which keeps them out of the project's own fileset — so this\n * input is the only thing that hashes them.\n *\n * The excluded paths are reports nothing downstream reads, and each is\n * rewritten on every run that produces it, which would mint a fresh hash that\n * cascades through the graph:\n * - `reports/` and `coverage/` hold pytest's JUnit and coverage XML, which\n * carry a wall-clock timestamp.\n * - `dist/<project>/checkov/checkov_report.json` is the report a CDK or Terraform\n * project's checkov scan writes, rewritten whenever the scan is uncached.\n * - `dist/<project>/test-output/vitest/coverage/` is vitest's coverage output.\n *\n * Each report is matched by its full path, so a project whose path contains a\n * `checkov` or `coverage` segment keeps its build output hashed.\n */\nexport const DEPENDENT_TASKS_OUTPUT_FILES_INPUT = {\n dependentTasksOutputFiles:\n '!{reports/**,coverage/**,dist/**/checkov/checkov_report.json,dist/**/test-output/vitest/coverage/**}',\n transitive: true,\n};\n\n// Globs this generator has vended for the dependent-task-output input. Any of\n// them is replaced, so the entry is neither duplicated nor left at a different\n// scope when a generator or migration re-runs.\nexport const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [\n '**/*',\n 'dist/**',\n '!{reports,coverage}/**',\n DEPENDENT_TASKS_OUTPUT_FILES_INPUT.dependentTasksOutputFiles,\n];\n\nexport interface TsLibDetails {\n /**\n * Full package name including scope (eg @foo/bar)\n */\n readonly fullyQualifiedName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n}\n\n/**\n * Returns details about the TS library to be created\n */\nexport const getTsLibDetails = (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): TsLibDetails => {\n const scope = getNpmScopePrefix(tree);\n const normalizedName = toKebabCase(schema.name);\n const fullyQualifiedName = `${scope}${normalizedName}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName };\n};\n\n/**\n * Generates a typescript project\n */\nexport const tsProjectGenerator = async (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, schema);\n // The module format is workspace-wide, established by the preset when the\n // workspace is created, so vending generators always infer it from the tree.\n const esm = isEsmWorkspace(tree);\n\n // Only scaffold the project on first run; on re-run skip creation so user\n // edits are preserved, but continue to (re)apply the configuration below.\n if (!projectExists(tree, fullyQualifiedName)) {\n await libraryGenerator(tree, {\n ...schema,\n name: fullyQualifiedName,\n directory: dir,\n skipPackageJson: true,\n bundler: 'tsc', // TODO: consider supporting others\n linter: 'none',\n unitTestRunner: 'vitest',\n // Register the @nx/vitest plugin so the test target is inferred rather\n // than emitting the deprecated @nx/vitest:test executor target.\n addPlugin: true,\n });\n\n // Replace with simpler sample source code\n tree.delete(joinPathFragments(dir, 'src'));\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n joinPathFragments(dir),\n {\n fullyQualifiedName,\n esm,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n await configureTsProject(\n tree,\n {\n dir,\n fullyQualifiedName,\n esm,\n },\n DEPENDENCIES,\n );\n\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n const targets = projectConfiguration.targets;\n\n // Merged rather than assigned so a re-run converges this generator's own\n // configuration without discarding what other generators contributed to the\n // same targets — the `bundle` that ts#lambda-function adds to build and\n // assemble, say, which those targets must keep depending on.\n targets['compile'] = mergeTarget(targets['compile'], {\n executor: 'nx:run-commands',\n outputs: ['{workspaceRoot}/dist/{projectRoot}/tsc'],\n options: {\n command: 'tsc --build tsconfig.lib.json',\n cwd: '{projectRoot}',\n },\n });\n targets['build'] = mergeTarget(targets['build'], {\n dependsOn: ['lint', 'compile', 'test'],\n });\n // The artifact-only sibling of build, which the deploy targets depend on.\n targets['assemble'] = mergeTarget(targets['assemble'], {\n dependsOn: ['compile'],\n });\n projectConfiguration.targets = sortObjectKeys(targets);\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);\n\n updateJson(tree, 'nx.json', (nxJson: NxJsonConfiguration) => {\n nxJson.namedInputs = {\n ...nxJson.namedInputs,\n default: [\n ...(nxJson.namedInputs?.default ?? []).filter(\n (input) =>\n typeof input !== 'object' ||\n !('dependentTasksOutputFiles' in input) ||\n !(\n VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS.includes(\n input.dependentTasksOutputFiles as string,\n ) && input.transitive\n ),\n ),\n DEPENDENT_TASKS_OUTPUT_FILES_INPUT,\n ],\n };\n\n const withDefaultInput = (base: Partial<TargetConfiguration>) => ({\n ...base,\n inputs: [\n ...(base.inputs ?? []).filter((i) => i !== 'default'),\n 'default',\n ],\n });\n\n nxJson.targetDefaults = {\n ...nxJson.targetDefaults,\n compile: mergeTargetDefault(nxJson.targetDefaults?.compile, (base) => ({\n cache: true,\n ...withDefaultInput(base),\n })),\n build: mergeTargetDefault(nxJson.targetDefaults?.build, (base) => ({\n cache: true,\n ...withDefaultInput(base),\n })),\n test: mergeTargetDefault(nxJson.targetDefaults?.test, withDefaultInput),\n };\n\n // Ensure we only declare a single typescript plugin with the correct settings\n nxJson.plugins = [\n {\n plugin: '@nx/js/typescript',\n options: {\n typecheck: {\n targetName: 'typecheck',\n },\n build: {\n targetName: 'compile',\n configName: 'tsconfig.lib.json',\n buildDepsName: 'build-deps',\n watchDepsName: 'watch-deps',\n },\n },\n },\n ...(nxJson.plugins ?? []).filter(\n (p) => typeof p === 'string' || p.plugin !== '@nx/js/typescript',\n ),\n ];\n\n return nxJson;\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_LIB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n // `installDependencies` ensures vitest resolves for the `typescript` language (the\n // generated vitest.config.mts imports it and Nx loads that config when\n // computing the project graph), so a deferred install still runs when needed.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\nexport default tsProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","libraryGenerator","declareDependencies","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","mergeTarget","mergeTargetDefault","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","configureTsProject","TS_PROJECT_DEPENDENCIES","VITEST_DEPENDENCIES","DEPENDENCIES","ts","TS_LIB_GENERATOR_INFO","filename","DEPENDENT_TASKS_OUTPUT_FILES_INPUT","dependentTasksOutputFiles","transitive","VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS","getTsLibDetails","tree","schema","scope","normalizedName","name","fullyQualifiedName","dir","directory","subDirectory","tsProjectGenerator","esm","skipPackageJson","bundler","linter","unitTestRunner","addPlugin","delete","dirname","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","projectConfiguration","targets","executor","outputs","options","command","cwd","dependsOn","nxJson","namedInputs","default","filter","input","includes","withDefaultInput","base","inputs","i","targetDefaults","compile","cache","build","test","plugins","plugin","typecheck","targetName","configName","buildDepsName","watchDepsName","p","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EAEjBC,iBAAiB,EACjBC,wBAAwB,EAGxBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,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B,MAAMC,OAAOoD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AACF,eAAe7C,mBAAmB"}
|
package/src/ts/rdb/generator.js
CHANGED
|
@@ -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 detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readProjectConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n writeJson,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { addStarExport } from '../../utils/ast.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport {\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n IMAGE_BUILD_CACHE,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n PRISMA_IMAGE_DEPENDENCIES,\n} from '../../utils/docker.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { updateGitIgnore } from '../../utils/git.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, snakeCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx.js';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths.js';\nimport { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace.js';\nimport { assignPort } from '../../utils/port.js';\nimport { addRdbInfra } from '../../utils/rdb-constructs/rdb-constructs.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport {\n type IacMetadata,\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants.js';\nimport {\n SHARED_RDB_SCRIPTS_DEPENDENCIES,\n sharedRdbScriptsGenerator,\n} from '../../utils/shared-rdb-scripts.js';\nimport { TS_VERSIONS } from '../../utils/versions.js';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator.js';\nimport type { TsRdbGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsRdbMetadata extends IacMetadata {\n readonly engine: TsRdbGeneratorSchema['engine'];\n}\n\n// Each entry names the engine branch it belongs to, so the same declaration\n// drives both adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsRdbMetadata>()({\n ts: [\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@aws-sdk/client-secrets-manager' },\n { name: '@aws-sdk/rds-signer' },\n { name: '@prisma/client' },\n { name: '@prisma/adapter-mariadb', when: (m) => m.engine === 'mysql' },\n { name: 'mariadb', when: (m) => m.engine === 'mysql' },\n { name: '@prisma/adapter-pg', when: (m) => m.engine !== 'mysql' },\n { name: 'pg', when: (m) => m.engine !== 'mysql' },\n { name: '@types/aws-lambda', dev: true },\n { name: '@types/pg', when: (m) => m.engine !== 'mysql', dev: true },\n // The prisma CLI and tsx run migration/seed scripts from the root.\n { name: 'prisma', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_RDB_SCRIPTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(PRISMA_IMAGE_DEPENDENCIES),\n ],\n});\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 subDirectory: options.subDirectory,\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: fullyQualifiedName,\n databaseProvider: options.engine === 'mysql' ? 'mysql' : 'postgresql',\n prismaVersion: TS_VERSIONS.prisma,\n deepmergeTsVersion: TS_VERSIONS['deepmerge-ts'],\n mysql2Version: TS_VERSIONS.mysql2,\n ...nodeImageVersions(),\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 // The Prisma schema and models, the handlers and the prisma client module are\n // all user-editable, so a re-run (to add infrastructure, or after a failed\n // run) must not clobber the user's schema and edits.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // The barrel re-exports prisma.ts. `tsProjectGenerator` writes a stub index.ts\n // when it creates the project, so the re-export is added to whatever is there\n // rather than replacing it — which also leaves a user's own additions to the\n // barrel alone on a re-run.\n await addStarExport(\n tree,\n joinPathFragments(dir, 'src', 'index.ts'),\n './prisma.js',\n );\n\n // config.json is framework-owned: it carries values derived from the\n // generator's options, so it converges on a re-run with changed options.\n writeJson(tree, joinPathFragments(dir, 'config.json'), {\n runtimeConfigKey: nameClassName,\n localDev: {\n containerEngine,\n containerName,\n image: dockerImage,\n port: localDbPort,\n host: localDbHost,\n dbName: databaseName,\n dbUser: localDbUser,\n dbPassword: localDbPassword,\n dbEngine: options.engine,\n },\n });\n updateGitIgnore(tree, dir, (patterns) => [...patterns, 'generated/prisma']);\n await sharedRdbScriptsGenerator(tree, options.engine, DEPENDENCIES);\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, DEPENDENCIES);\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(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/migration-handler.ts',\n bundleOutputDir: 'migration',\n },\n DEPENDENCIES,\n );\n await addTypeScriptBundleTarget(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/create-db-user-handler.ts',\n bundleOutputDir: 'create-db-user',\n },\n DEPENDENCIES,\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.cpDir(\n 'prisma',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma`,\n ),\n fs.cpFile(\n 'prisma.config.ts',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma.config.ts`,\n ),\n fs.cpFile(\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 dependsOn: ['pull-image'],\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 // Recorded in the metadata below so the version sync can tell a CDK project\n // from a Terraform one; undefined when no infrastructure was generated, in\n // which case neither provider's packages were added.\n const iac =\n options.infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (options.infra !== 'none') {\n // The migration image ships under both providers — Terraform pushes the\n // locally built tag, CDK builds the same context as an image asset — so the\n // build and its scan are wired up for either.\n projectConfig.targets['docker'] = {\n cache: IMAGE_BUILD_CACHE,\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 addArtifactDependencyToTargets(projectConfig, 'docker');\n\n addDockerScanTarget(\n tree,\n {\n project: projectConfig,\n containerEngine,\n trivyTargetName: 'trivy',\n dockerTargetName: 'docker',\n imageTags: [migrationDockerImageTag],\n },\n DEPENDENCIES,\n );\n addArtifactDependencyToTargets(projectConfig, 'bundle');\n }\n addDependencyToTargetIfNotPresent(projectConfig, 'compile', 'generate');\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: TsRdbMetadata = {\n engine: options.engine,\n ...(iac ? { iac } : {}),\n };\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n TS_RDB_GENERATOR_INFO,\n metadata,\n );\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n await addRdbInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n projectRoot: dir,\n nameClassName,\n nameKebabCase,\n databasePackageAlias: 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 addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: projectConfig.root,\n });\n\n // @prisma/adapter-pg depends on @types/pg ^8.16.0. Yarn does not dedupe it to\n // the workspace's pinned @types/pg, so it installs a separate copy under the\n // adapter's own node_modules whenever a newer @types/pg is published. The two\n // copies declare structurally incompatible Pool types, so passing our `new\n // Pool(...)` to `new PrismaPg(...)` fails to compile. Scope the resolution to\n // the adapter so other @types/pg consumers are unaffected. Classic yarn only\n // honours the `**/`-prefixed descriptor in a workspace and berry only the\n // bare one, so declare both.\n if (options.engine === 'postgres' && detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@prisma/adapter-pg/@types/pg': TS_VERSIONS['@types/pg'],\n '@prisma/adapter-pg/@types/pg': TS_VERSIONS['@types/pg'],\n };\n return packageJson;\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","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","writeJson","addTsDependencies","addStarExport","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","addDockerScanTarget","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","PRISMA_IMAGE_DEPENDENCIES","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","updateGitIgnore","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","snakeCase","toClassName","getNpmScope","addArtifactDependencyToTargets","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","getRelativePathToRootByDirectory","registerPnpmBuiltDependencies","assignPort","addRdbInfra","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","PACKAGES_DIR","SHARED_SCRIPTS_DIR","SHARED_RDB_SCRIPTS_DEPENDENCIES","sharedRdbScriptsGenerator","TS_VERSIONS","tsProjectGenerator","getTsLibDetails","DEPENDENCIES","ts","name","when","m","engine","dev","root","TS_RDB_GENERATOR_INFO","filename","tsRdbGenerator","tree","options","nameKebabCase","nameClassName","databaseUser","databaseName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","tsConfig","include","projectConfig","localDbPort","localDbHost","localDbUser","localDbPassword","containerName","dockerImage","templateOptions","runtimeConfigKey","databasePackageAlias","databaseProvider","prismaVersion","prisma","deepmergeTsVersion","mysql2Version","mysql2","prismaAdapterPackage","prismaAdapterClassName","localDbName","dirname","overwriteStrategy","KeepExisting","localDev","image","port","host","dbName","dbUser","dbPassword","dbEngine","patterns","waitForDbScript","scriptsDir","relativePathToRoot","fs","migrationBundleDir","migrationDockerImageTag","infra","targetFilePath","bundleOutputDir","bundleTarget","targets","commands","rolldownCommand","command","rm","mkdir","cpDir","cpFile","parallel","generate","executor","outputs","cwd","dependsOn","continuous","env","LOCAL_DEV","iac","undefined","cache","project","trivyTargetName","dockerTargetName","imageTags","metadata","projectName","projectRoot","adminUser","createDbUserBundleDir","framework","packageJson","resolutions","languages"],"mappings":"AAAA;;;CAGC,GACD,SAASA,QAAQ,QAAQ,YAAY;AACrC,SACEC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,wBAAwB,EAExBC,UAAU,EACVC,0BAA0B,EAC1BC,SAAS,QACJ,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,aAAa,QAAQ,qBAAqB;AACnD,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA+B;AACtC,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SACEC,mBAAmB,EACnBC,mBAAmB,EACnBC,iBAAiB,EACjBC,uBAAuB,EACvBC,iBAAiB,EACjBC,yBAAyB,QACpB,wBAAwB;AAC/B,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAoB;AAChE,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,OAAO,QAAQ,+BAA+B;AACvD,SAASC,SAAS,EAAEC,SAAS,EAAEC,WAAW,QAAQ,uBAAuB;AACzE,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SACEC,8BAA8B,EAC9BC,iCAAiC,EACjCC,oBAAoB,EACpBC,gBAAgB,QAEX,oBAAoB;AAC3B,SAASC,gCAAgC,QAAQ,uBAAuB;AACxE,SAASC,6BAA6B,QAAQ,gCAAgC;AAC9E,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,WAAW,QAAQ,+CAA+C;AAC3E,SACEC,8BAA8B,EAC9BC,yBAAyB,QACpB,mCAAmC;AAC1C,SAEEC,YAAY,EACZC,kBAAkB,QACb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F,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 detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readProjectConfiguration,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n writeJson,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { addStarExport } from '../../utils/ast.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport {\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n IMAGE_BUILD_CACHE,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n PRISMA_IMAGE_DEPENDENCIES,\n} from '../../utils/docker.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { updateGitIgnore } from '../../utils/git.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { esmVars } from '../../utils/module-format.js';\nimport { kebabCase, snakeCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addDependencyToTargetIfNotPresent,\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n} from '../../utils/nx.js';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths.js';\nimport { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace.js';\nimport { assignPort } from '../../utils/port.js';\nimport { addRdbInfra } from '../../utils/rdb-constructs/rdb-constructs.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport {\n type IacMetadata,\n PACKAGES_DIR,\n SHARED_SCRIPTS_DIR,\n} from '../../utils/shared-constructs-constants.js';\nimport {\n SHARED_RDB_SCRIPTS_DEPENDENCIES,\n sharedRdbScriptsGenerator,\n} from '../../utils/shared-rdb-scripts.js';\nimport { TS_VERSIONS } from '../../utils/versions.js';\nimport tsProjectGenerator, { getTsLibDetails } from '../lib/generator.js';\nimport type { TsRdbGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsRdbMetadata extends IacMetadata {\n readonly engine: TsRdbGeneratorSchema['engine'];\n}\n\n// Each entry names the engine branch it belongs to, so the same declaration\n// drives both adding and the version sync.\nexport const DEPENDENCIES = declareDependencies<TsRdbMetadata>()({\n ts: [\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@aws-sdk/client-secrets-manager' },\n { name: '@aws-sdk/rds-signer' },\n { name: '@prisma/client' },\n { name: '@prisma/adapter-mariadb', when: (m) => m.engine === 'mysql' },\n { name: 'mariadb', when: (m) => m.engine === 'mysql' },\n { name: '@prisma/adapter-pg', when: (m) => m.engine !== 'mysql' },\n { name: 'pg', when: (m) => m.engine !== 'mysql' },\n { name: '@types/aws-lambda', dev: true },\n { name: '@types/pg', when: (m) => m.engine !== 'mysql', dev: true },\n // The prisma CLI and tsx run migration/seed scripts from the root.\n { name: 'prisma', dev: true, root: true },\n { name: 'tsx', dev: true, root: true },\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(SHARED_RDB_SCRIPTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(PRISMA_IMAGE_DEPENDENCIES),\n ],\n});\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 subDirectory: options.subDirectory,\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: fullyQualifiedName,\n databaseProvider: options.engine === 'mysql' ? 'mysql' : 'postgresql',\n prismaVersion: TS_VERSIONS.prisma,\n deepmergeTsVersion: TS_VERSIONS['deepmerge-ts'],\n mysql2Version: TS_VERSIONS.mysql2,\n ...nodeImageVersions(),\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 // The Prisma schema and models, the handlers and the prisma client module are\n // all user-editable, so a re-run (to add infrastructure, or after a failed\n // run) must not clobber the user's schema and edits.\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n dir,\n templateOptions,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // The barrel re-exports prisma.ts. `tsProjectGenerator` writes a stub index.ts\n // when it creates the project, so the re-export is added to whatever is there\n // rather than replacing it — which also leaves a user's own additions to the\n // barrel alone on a re-run.\n await addStarExport(\n tree,\n joinPathFragments(dir, 'src', 'index.ts'),\n './prisma.js',\n );\n\n // config.json is framework-owned: it carries values derived from the\n // generator's options, so it converges on a re-run with changed options.\n writeJson(tree, joinPathFragments(dir, 'config.json'), {\n runtimeConfigKey: nameClassName,\n localDev: {\n containerEngine,\n containerName,\n image: dockerImage,\n port: localDbPort,\n host: localDbHost,\n dbName: databaseName,\n dbUser: localDbUser,\n dbPassword: localDbPassword,\n dbEngine: options.engine,\n },\n });\n updateGitIgnore(tree, dir, (patterns) => [...patterns, 'generated/prisma']);\n await sharedRdbScriptsGenerator(tree, options.engine, DEPENDENCIES);\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, DEPENDENCIES);\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(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/migration-handler.ts',\n bundleOutputDir: 'migration',\n },\n DEPENDENCIES,\n );\n await addTypeScriptBundleTarget(\n tree,\n projectConfig,\n {\n targetFilePath: 'src/create-db-user-handler.ts',\n bundleOutputDir: 'create-db-user',\n },\n DEPENDENCIES,\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.cpDir(\n 'prisma',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma`,\n ),\n fs.cpFile(\n 'prisma.config.ts',\n `${relativePathToRoot}dist/{projectRoot}/bundle/migration/prisma.config.ts`,\n ),\n fs.cpFile(\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 cache: true,\n inputs: ['default'],\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 dependsOn: ['pull-image'],\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 // Recorded in the metadata below so the version sync can tell a CDK project\n // from a Terraform one; undefined when no infrastructure was generated, in\n // which case neither provider's packages were added.\n const iac =\n options.infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\n\n if (options.infra !== 'none') {\n // The migration image ships under both providers — Terraform pushes the\n // locally built tag, CDK builds the same context as an image asset — so the\n // build and its scan are wired up for either.\n projectConfig.targets['docker'] = {\n cache: IMAGE_BUILD_CACHE,\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 addArtifactDependencyToTargets(projectConfig, 'docker');\n\n addDockerScanTarget(\n tree,\n {\n project: projectConfig,\n containerEngine,\n trivyTargetName: 'trivy',\n dockerTargetName: 'docker',\n imageTags: [migrationDockerImageTag],\n },\n DEPENDENCIES,\n );\n addArtifactDependencyToTargets(projectConfig, 'bundle');\n }\n addDependencyToTargetIfNotPresent(projectConfig, 'compile', 'generate');\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfig);\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: TsRdbMetadata = {\n engine: options.engine,\n ...(iac ? { iac } : {}),\n };\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n TS_RDB_GENERATOR_INFO,\n metadata,\n );\n\n if (options.infra !== 'none') {\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n await addRdbInfra(tree, {\n iac,\n projectName: fullyQualifiedName,\n projectRoot: dir,\n nameClassName,\n nameKebabCase,\n databasePackageAlias: 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 addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: projectConfig.root,\n });\n\n // @prisma/adapter-pg depends on @types/pg ^8.16.0. Yarn does not dedupe it to\n // the workspace's pinned @types/pg, so it installs a separate copy under the\n // adapter's own node_modules whenever a newer @types/pg is published. The two\n // copies declare structurally incompatible Pool types, so passing our `new\n // Pool(...)` to `new PrismaPg(...)` fails to compile. Scope the resolution to\n // the adapter so other @types/pg consumers are unaffected. Classic yarn only\n // honours the `**/`-prefixed descriptor in a workspace and berry only the\n // bare one, so declare both.\n if (options.engine === 'postgres' && detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@prisma/adapter-pg/@types/pg': TS_VERSIONS['@types/pg'],\n '@prisma/adapter-pg/@types/pg': TS_VERSIONS['@types/pg'],\n };\n return packageJson;\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","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","writeJson","addTsDependencies","addStarExport","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","addDockerScanTarget","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","PRISMA_IMAGE_DEPENDENCIES","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","updateGitIgnore","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","esmVars","kebabCase","snakeCase","toClassName","getNpmScope","addArtifactDependencyToTargets","addDependencyToTargetIfNotPresent","addGeneratorMetadata","getGeneratorInfo","getRelativePathToRootByDirectory","registerPnpmBuiltDependencies","assignPort","addRdbInfra","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","PACKAGES_DIR","SHARED_SCRIPTS_DIR","SHARED_RDB_SCRIPTS_DEPENDENCIES","sharedRdbScriptsGenerator","TS_VERSIONS","tsProjectGenerator","getTsLibDetails","DEPENDENCIES","ts","name","when","m","engine","dev","root","TS_RDB_GENERATOR_INFO","filename","tsRdbGenerator","tree","options","nameKebabCase","nameClassName","databaseUser","databaseName","containerEngine","fullyQualifiedName","dir","directory","subDirectory","projectExists","preferInstallDependencies","tsConfig","include","projectConfig","localDbPort","localDbHost","localDbUser","localDbPassword","containerName","dockerImage","templateOptions","runtimeConfigKey","databasePackageAlias","databaseProvider","prismaVersion","prisma","deepmergeTsVersion","mysql2Version","mysql2","prismaAdapterPackage","prismaAdapterClassName","localDbName","dirname","overwriteStrategy","KeepExisting","localDev","image","port","host","dbName","dbUser","dbPassword","dbEngine","patterns","waitForDbScript","scriptsDir","relativePathToRoot","fs","migrationBundleDir","migrationDockerImageTag","infra","targetFilePath","bundleOutputDir","bundleTarget","targets","commands","rolldownCommand","command","rm","mkdir","cpDir","cpFile","parallel","generate","executor","cache","inputs","outputs","cwd","dependsOn","continuous","env","LOCAL_DEV","iac","undefined","project","trivyTargetName","dockerTargetName","imageTags","metadata","projectName","projectRoot","adminUser","createDbUserBundleDir","framework","packageJson","resolutions","languages"],"mappings":"AAAA;;;CAGC,GACD,SAASA,QAAQ,QAAQ,YAAY;AACrC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
|
1227
1227
|
"biome": ["default", "{workspaceRoot}/biome.json"],
|
|
1228
1228
|
"default": [
|
|
1229
1229
|
{
|
|
1230
|
-
"dependentTasksOutputFiles": "!{reports,coverage}
|
|
1230
|
+
"dependentTasksOutputFiles": "!{reports/**,coverage/**,dist/**/checkov/checkov_report.json,dist/**/test-output/vitest/coverage/**}",
|
|
1231
1231
|
"transitive": true
|
|
1232
1232
|
}
|
|
1233
1233
|
]
|
|
@@ -2202,6 +2202,55 @@ export * from './core/index.js';
|
|
|
2202
2202
|
"
|
|
2203
2203
|
`;
|
|
2204
2204
|
|
|
2205
|
+
exports[`react-website generator > Tanstack router integration > should generate website with no router correctly > packages/common/constructs/tests/global-setup.ts 1`] = `
|
|
2206
|
+
"import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
2207
|
+
import { tmpdir } from 'node:os';
|
|
2208
|
+
import { join } from 'node:path';
|
|
2209
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2210
|
+
|
|
2211
|
+
const VARIABLES = ['TMPDIR', 'TEMP', 'TMP', 'CDK_CONTEXT_JSON'];
|
|
2212
|
+
|
|
2213
|
+
const remove = (dir: string) => {
|
|
2214
|
+
try {
|
|
2215
|
+
rmSync(dir, { recursive: true, force: true });
|
|
2216
|
+
} catch {
|
|
2217
|
+
// Retried below.
|
|
2218
|
+
}
|
|
2219
|
+
return !existsSync(dir);
|
|
2220
|
+
};
|
|
2221
|
+
|
|
2222
|
+
export default function setup() {
|
|
2223
|
+
const previous = VARIABLES.map((name) => [name, process.env[name]] as const);
|
|
2224
|
+
const dir = mkdtempSync(join(tmpdir(), 'cdk-test-'));
|
|
2225
|
+
process.env.TMPDIR = dir;
|
|
2226
|
+
process.env.TEMP = dir;
|
|
2227
|
+
process.env.TMP = dir;
|
|
2228
|
+
process.env.CDK_CONTEXT_JSON = JSON.stringify({
|
|
2229
|
+
...JSON.parse(process.env.CDK_CONTEXT_JSON ?? '{}'),
|
|
2230
|
+
'aws:cdk:bundling-stacks': [],
|
|
2231
|
+
});
|
|
2232
|
+
|
|
2233
|
+
return async () => {
|
|
2234
|
+
// Exiting workers may still be deleting their cdk.out here, so retry.
|
|
2235
|
+
const deadline = Date.now() + 2000;
|
|
2236
|
+
while (!remove(dir) && Date.now() < deadline) {
|
|
2237
|
+
await sleep(50);
|
|
2238
|
+
}
|
|
2239
|
+
if (existsSync(dir)) {
|
|
2240
|
+
console.warn(\`Could not remove the CDK test directory \${dir}\`);
|
|
2241
|
+
}
|
|
2242
|
+
for (const [name, value] of previous) {
|
|
2243
|
+
if (value === undefined) {
|
|
2244
|
+
delete process.env[name];
|
|
2245
|
+
} else {
|
|
2246
|
+
process.env[name] = value;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
};
|
|
2250
|
+
}
|
|
2251
|
+
"
|
|
2252
|
+
`;
|
|
2253
|
+
|
|
2205
2254
|
exports[`react-website generator > Tanstack router integration > should generate website with no router correctly > packages/common/constructs/tsconfig.json 1`] = `
|
|
2206
2255
|
"{
|
|
2207
2256
|
"extends": "../../../tsconfig.base.json",
|
|
@@ -2302,6 +2351,7 @@ export default defineConfig(() => ({
|
|
|
2302
2351
|
root: import.meta.dirname,
|
|
2303
2352
|
cacheDir: '../../../node_modules/.vite/packages/common/constructs',
|
|
2304
2353
|
test: {
|
|
2354
|
+
globalSetup: ['./tests/global-setup.ts'],
|
|
2305
2355
|
passWithNoTests: true,
|
|
2306
2356
|
name: '@proj/common-constructs',
|
|
2307
2357
|
watch: false,
|
|
@@ -3103,7 +3153,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
3103
3153
|
"biome": ["default", "{workspaceRoot}/biome.json"],
|
|
3104
3154
|
"default": [
|
|
3105
3155
|
{
|
|
3106
|
-
"dependentTasksOutputFiles": "!{reports,coverage}
|
|
3156
|
+
"dependentTasksOutputFiles": "!{reports/**,coverage/**,dist/**/checkov/checkov_report.json,dist/**/test-output/vitest/coverage/**}",
|
|
3107
3157
|
"transitive": true
|
|
3108
3158
|
}
|
|
3109
3159
|
]
|
|
@@ -4082,6 +4132,55 @@ export * from './core/index.js';
|
|
|
4082
4132
|
"
|
|
4083
4133
|
`;
|
|
4084
4134
|
|
|
4135
|
+
exports[`react-website generator > Tanstack router integration > should generate website with router correctly > packages/common/constructs/tests/global-setup.ts 1`] = `
|
|
4136
|
+
"import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
4137
|
+
import { tmpdir } from 'node:os';
|
|
4138
|
+
import { join } from 'node:path';
|
|
4139
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
4140
|
+
|
|
4141
|
+
const VARIABLES = ['TMPDIR', 'TEMP', 'TMP', 'CDK_CONTEXT_JSON'];
|
|
4142
|
+
|
|
4143
|
+
const remove = (dir: string) => {
|
|
4144
|
+
try {
|
|
4145
|
+
rmSync(dir, { recursive: true, force: true });
|
|
4146
|
+
} catch {
|
|
4147
|
+
// Retried below.
|
|
4148
|
+
}
|
|
4149
|
+
return !existsSync(dir);
|
|
4150
|
+
};
|
|
4151
|
+
|
|
4152
|
+
export default function setup() {
|
|
4153
|
+
const previous = VARIABLES.map((name) => [name, process.env[name]] as const);
|
|
4154
|
+
const dir = mkdtempSync(join(tmpdir(), 'cdk-test-'));
|
|
4155
|
+
process.env.TMPDIR = dir;
|
|
4156
|
+
process.env.TEMP = dir;
|
|
4157
|
+
process.env.TMP = dir;
|
|
4158
|
+
process.env.CDK_CONTEXT_JSON = JSON.stringify({
|
|
4159
|
+
...JSON.parse(process.env.CDK_CONTEXT_JSON ?? '{}'),
|
|
4160
|
+
'aws:cdk:bundling-stacks': [],
|
|
4161
|
+
});
|
|
4162
|
+
|
|
4163
|
+
return async () => {
|
|
4164
|
+
// Exiting workers may still be deleting their cdk.out here, so retry.
|
|
4165
|
+
const deadline = Date.now() + 2000;
|
|
4166
|
+
while (!remove(dir) && Date.now() < deadline) {
|
|
4167
|
+
await sleep(50);
|
|
4168
|
+
}
|
|
4169
|
+
if (existsSync(dir)) {
|
|
4170
|
+
console.warn(\`Could not remove the CDK test directory \${dir}\`);
|
|
4171
|
+
}
|
|
4172
|
+
for (const [name, value] of previous) {
|
|
4173
|
+
if (value === undefined) {
|
|
4174
|
+
delete process.env[name];
|
|
4175
|
+
} else {
|
|
4176
|
+
process.env[name] = value;
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
};
|
|
4180
|
+
}
|
|
4181
|
+
"
|
|
4182
|
+
`;
|
|
4183
|
+
|
|
4085
4184
|
exports[`react-website generator > Tanstack router integration > should generate website with router correctly > packages/common/constructs/tsconfig.json 1`] = `
|
|
4086
4185
|
"{
|
|
4087
4186
|
"extends": "../../../tsconfig.base.json",
|
|
@@ -4182,6 +4281,7 @@ export default defineConfig(() => ({
|
|
|
4182
4281
|
root: import.meta.dirname,
|
|
4183
4282
|
cacheDir: '../../../node_modules/.vite/packages/common/constructs',
|
|
4184
4283
|
test: {
|
|
4284
|
+
globalSetup: ['./tests/global-setup.ts'],
|
|
4185
4285
|
passWithNoTests: true,
|
|
4186
4286
|
name: '@proj/common-constructs',
|
|
4187
4287
|
watch: false,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`cdk test global setup > addCdkTestGlobalSetup > should keep the infra vitest config well formed 1`] = `
|
|
4
|
+
"import { defineConfig } from 'vitest/config';
|
|
5
|
+
|
|
6
|
+
export default defineConfig(() => ({
|
|
7
|
+
root: import.meta.dirname,
|
|
8
|
+
cacheDir: '../../node_modules/.vite/packages/infra',
|
|
9
|
+
test: {
|
|
10
|
+
globalSetup: ['./tests/global-setup.ts'],
|
|
11
|
+
passWithNoTests: true,
|
|
12
|
+
name: '@proj/infra',
|
|
13
|
+
watch: false,
|
|
14
|
+
globals: true,
|
|
15
|
+
environment: 'jsdom',
|
|
16
|
+
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
17
|
+
reporters: ['default'],
|
|
18
|
+
coverage: {
|
|
19
|
+
reportsDirectory: '../../dist/packages/infra/test-output/vitest/coverage',
|
|
20
|
+
provider: 'v8' as const,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
}));
|
|
24
|
+
"
|
|
25
|
+
`;
|