@aws/nx-plugin 1.0.7 → 1.0.9

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.
Files changed (63) hide show
  1. package/migrations.json +21 -1
  2. package/package.json +1 -1
  3. package/src/infra/app/__snapshots__/generator.spec.ts.snap +10 -0
  4. package/src/infra/app/files/app/README.md.template +12 -0
  5. package/src/infra/app/generator.js +8 -0
  6. package/src/infra/app/generator.js.map +1 -1
  7. package/src/migrations/latest/cache-inputs-outputs/metadata.json +3 -0
  8. package/src/migrations/latest/cache-inputs-outputs/migration.d.ts +6 -0
  9. package/src/migrations/latest/cache-inputs-outputs/migration.js +176 -0
  10. package/src/migrations/latest/cache-inputs-outputs/migration.js.map +1 -0
  11. package/src/migrations/latest/infra-test-loop/metadata.json +3 -0
  12. package/src/migrations/latest/infra-test-loop/migration.d.ts +6 -0
  13. package/src/migrations/latest/infra-test-loop/migration.js +110 -0
  14. package/src/migrations/latest/infra-test-loop/migration.js.map +1 -0
  15. package/src/migrations/latest/py-dynamodb-bind-base-model-meta/metadata.json +3 -0
  16. package/src/migrations/latest/py-dynamodb-bind-base-model-meta/migration.d.ts +6 -0
  17. package/src/migrations/latest/py-dynamodb-bind-base-model-meta/migration.js +56 -0
  18. package/src/migrations/latest/py-dynamodb-bind-base-model-meta/migration.js.map +1 -0
  19. package/src/migrations/latest/py-dynamodb-type-base-model-meta/metadata.json +3 -0
  20. package/src/migrations/latest/py-dynamodb-type-base-model-meta/migration.d.ts +6 -0
  21. package/src/migrations/latest/py-dynamodb-type-base-model-meta/migration.js +54 -0
  22. package/src/migrations/latest/py-dynamodb-type-base-model-meta/migration.js.map +1 -0
  23. package/src/migrations/v1.0.0-rc.90/0004-python-test-input-scoping/migration.js +8 -2
  24. package/src/migrations/v1.0.0-rc.90/0004-python-test-input-scoping/migration.js.map +1 -1
  25. package/src/open-api/py-client/files/client/__clientModuleName__.py.template +17 -6
  26. package/src/open-api/py-client/files/shared/errors.py.template +3 -5
  27. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +8 -4
  28. package/src/py/dynamodb/base-model-meta.d.ts +39 -0
  29. package/src/py/dynamodb/base-model-meta.js +54 -0
  30. package/src/py/dynamodb/base-model-meta.js.map +1 -0
  31. package/src/py/dynamodb/files/__name__/entities/base.py.template +4 -2
  32. package/src/smithy/project/__snapshots__/generator.spec.ts.snap +9 -0
  33. package/src/smithy/project/generator.d.ts +9 -0
  34. package/src/smithy/project/generator.js +15 -0
  35. package/src/smithy/project/generator.js.map +1 -1
  36. package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +2 -0
  37. package/src/terraform/project/generator.js +2 -4
  38. package/src/terraform/project/generator.js.map +1 -1
  39. package/src/ts/lib/__snapshots__/generator.spec.ts.snap +1 -1
  40. package/src/ts/lib/generator.d.ts +14 -3
  41. package/src/ts/lib/generator.js +18 -7
  42. package/src/ts/lib/generator.js.map +1 -1
  43. package/src/ts/rdb/generator.js +4 -0
  44. package/src/ts/rdb/generator.js.map +1 -1
  45. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +102 -2
  46. package/src/utils/__snapshots__/cdk-test-setup.spec.ts.snap +25 -0
  47. package/src/utils/cdk-test-setup.d.ts +22 -0
  48. package/src/utils/cdk-test-setup.js +38 -0
  49. package/src/utils/cdk-test-setup.js.map +1 -0
  50. package/src/utils/files/cdk-test-setup/tests/global-setup.ts.template +45 -0
  51. package/src/utils/shared-constructs.js +2 -0
  52. package/src/utils/shared-constructs.js.map +1 -1
  53. package/src/utils/test/python-dependencies.d.ts +6 -0
  54. package/src/utils/test/python-dependencies.js +9 -0
  55. package/src/utils/test/python-dependencies.js.map +1 -1
  56. package/src/utils/test/warm-python-cache.js +40 -21
  57. package/src/utils/test/warm-python-cache.js.map +1 -1
  58. package/src/utils/version-lockstep/hold.d.ts +26 -0
  59. package/src/utils/version-lockstep/hold.js +33 -0
  60. package/src/utils/version-lockstep/hold.js.map +1 -0
  61. package/src/utils/versions.d.ts +1 -1
  62. package/src/utils/versions.js +1 -1
  63. package/src/utils/versions.js.map +1 -1
@@ -112,11 +112,23 @@ const BUILD_DIR = 'dist/{projectRoot}/build';
112
112
  `{workspaceRoot}/${SMITHY_OUT_DIR}`,
113
113
  type === 'shapes' ? `{workspaceRoot}/${BUILD_DIR}/model.json` : `{workspaceRoot}/${BUILD_DIR}/openapi`
114
114
  ];
115
+ /**
116
+ * What a Smithy build target hashes: its own sources plus the outputs of the
117
+ * tasks it depends on. That covers a consumed shape library's output only
118
+ * when nx.json's `default` named input carries the `dependentTasksOutputFiles`
119
+ * entry, which only ts/lib/generator.ts writes - a Smithy-only workspace has
120
+ * no such entry, so `default` falls back to Nx's `{projectRoot}/**\/*`.
121
+ */ export const SMITHY_TARGET_INPUTS = [
122
+ 'default'
123
+ ];
115
124
  /**
116
125
  * The target that builds a service's Server SDK, shared with the migration moving
117
126
  * an existing project onto it.
118
127
  */ export const smithyGenerateSsdkTarget = ()=>({
119
128
  cache: true,
129
+ inputs: [
130
+ ...SMITHY_TARGET_INPUTS
131
+ ],
120
132
  outputs: [
121
133
  `{workspaceRoot}/${BUILD_DIR}/ssdk`
122
134
  ],
@@ -176,6 +188,9 @@ export const smithyProjectGenerator = async (tree, options)=>{
176
188
  },
177
189
  compile: {
178
190
  cache: true,
191
+ inputs: [
192
+ ...SMITHY_TARGET_INPUTS
193
+ ],
179
194
  outputs: smithyCompileOutputs(type),
180
195
  executor: 'nx:run-commands',
181
196
  options: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/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 type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n} from '@nx/devkit';\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 { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { toClassName, toKebabCase } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths.js';\nimport {\n smithyCliCommand,\n smithyMavenVersions,\n warnIfSmithyMissing,\n} from '../../utils/smithy.js';\nimport type { SmithyProjectGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface SmithyProjectMetadata {\n readonly smithyType: NonNullable<SmithyProjectGeneratorSchema['type']>;\n readonly namespace: string;\n}\n\n/**\n * Only a service project generates a Server SDK, so only a service needs the\n * bundler that turns it into the single module its backend imports. A shape\n * library assembles a model and stops.\n */\nconst isService = (metadata: SmithyProjectMetadata) =>\n metadata.smithyType === 'service';\n\n/**\n * Everything a Smithy build runs, all of it workspace tooling in the root\n * manifest rather than anything the model itself imports.\n *\n * Neither the Smithy CLI nor `mise` is among them: the compile target fetches mise\n * with `npx` and mise resolves the CLI, so neither is a workspace dependency — see\n * `utils/smithy.ts`.\n */\nexport const DEPENDENCIES = declareDependencies<SmithyProjectMetadata>()({\n ts: [\n // Added to the root by `FsCommands` as it builds each command.\n ...ownedElsewhere(FS_DEPENDENCIES),\n { name: 'rolldown', dev: true, root: true, when: isService },\n { name: 'rolldown-plugin-dts', dev: true, root: true, when: isService },\n // Resolved by `rolldown-plugin-dts` to emit the bundled declaration.\n { name: 'typescript', dev: true, root: true, when: isService },\n ],\n});\n\nexport const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Where the Smithy CLI writes its artifacts, and where the build publishes the\n * ones consumers read. Both sit under `dist` so a build writes nothing into the\n * project, keeping the source tree clean and the target's outputs cacheable.\n *\n * The CLI's own output is kept beside the published tree rather than inside it:\n * it holds the generated SSDK package and its installed `node_modules`, which\n * must not be mistaken for a build artifact.\n */\nconst SMITHY_OUT_DIR = 'dist/{projectRoot}/smithy';\nconst BUILD_DIR = 'dist/{projectRoot}/build';\n\n/** The projection every generated `smithy-build.json` builds. */\nconst SOURCE_PROJECTION = `${SMITHY_OUT_DIR}/source`;\n\n/** Where the generated TypeScript Server SDK lands before it is bundled. */\nconst SSDK_CODEGEN_DIR = `${SOURCE_PROJECTION}/typescript-ssdk-codegen`;\n\n/**\n * The commands that build a Smithy project's model, run from the workspace root.\n *\n * This is the whole of a shape library's build. A service's Server SDK is built\n * separately by {@link smithyGenerateSsdkCommands}, from the codegen output this\n * leaves under {@link SMITHY_OUT_DIR}.\n */\nexport const smithyCompileCommands = (\n cmd: FsCommands<typeof DEPENDENCIES>,\n type: SmithyProjectGeneratorSchema['type'],\n): string[] => [\n cmd.rm(BUILD_DIR),\n cmd.rm(SMITHY_OUT_DIR),\n cmd.mkdir(BUILD_DIR),\n // `imports` in smithy-build.json resolve relative to that file, so a shape\n // library is referenced by its path from the consuming project.\n `${smithyCliCommand()} build -c {projectRoot}/smithy-build.json --output ${SMITHY_OUT_DIR}`,\n ...(type === 'shapes'\n ? [\n cmd.cpFile(\n `${SOURCE_PROJECTION}/model/model.json`,\n `${BUILD_DIR}/model.json`,\n ),\n ]\n : [\n cmd.mkdir(`${BUILD_DIR}/openapi`),\n // Named after the service shape by the OpenAPI plugin, so it is matched\n // rather than named, and published under a stable name.\n cmd.cpGlobToFile(\n `${SOURCE_PROJECTION}/openapi/*.openapi.json`,\n `${BUILD_DIR}/openapi`,\n 'openapi.json',\n ),\n ]),\n];\n\n/**\n * The commands that turn a service's generated TypeScript Server SDK into the\n * single module its consumer imports, run from the workspace root.\n *\n * Only a service has one, and it reads what the model build left behind, so this\n * runs after `compile`.\n */\nexport const smithyGenerateSsdkCommands = (): string[] => [\n // `npm` regardless of the workspace's package manager: this installs a generated\n // package under `dist` that is not a workspace member, and npm ships with Node so\n // it is always present. It reads the user's `.npmrc`, so a private registry still\n // applies. `--include=dev` because the bundler resolves types from the generated\n // package's devDependencies, which `NODE_ENV=production` would otherwise omit.\n `npm install --prefix ${SSDK_CODEGEN_DIR} --include=dev --ignore-scripts --no-audit --no-fund`,\n // Bundled straight from the generated TypeScript sources, emitting the module and\n // its declarations together — see ssdk.rolldown.config.mjs for why the sources\n // rather than a `tsc` pre-pass.\n `rolldown -c {projectRoot}/ssdk.rolldown.config.mjs`,\n];\n\n/**\n * What the model build publishes, listed per artifact rather than as the whole\n * `build` directory: a service's `generate-ssdk` writes into that directory too, and\n * restoring `compile` from cache would otherwise discard the Server SDK beside it.\n */\nexport const smithyCompileOutputs = (\n type: SmithyProjectGeneratorSchema['type'],\n): string[] => [\n `{workspaceRoot}/${SMITHY_OUT_DIR}`,\n type === 'shapes'\n ? `{workspaceRoot}/${BUILD_DIR}/model.json`\n : `{workspaceRoot}/${BUILD_DIR}/openapi`,\n];\n\n/**\n * The target that builds a service's Server SDK, shared with the migration moving\n * an existing project onto it.\n */\nexport const smithyGenerateSsdkTarget = () => ({\n cache: true,\n outputs: [`{workspaceRoot}/${BUILD_DIR}/ssdk`],\n executor: 'nx:run-commands',\n dependsOn: ['compile'],\n options: {\n commands: smithyGenerateSsdkCommands(),\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n});\n\n/**\n * Write the rolldown config that bundles a service's generated Server SDK.\n *\n * Shared with the migration moving an existing project off the container build,\n * so a migrated project's config cannot drift from a freshly generated one.\n */\nexport const writeSsdkBundleConfig = (tree: Tree, projectRoot: string): void =>\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'ssdk-bundle'),\n projectRoot,\n // The config's paths are workspace-root relative, so it needs only the\n // project's root — the compile target runs from the workspace root.\n { projectRoot },\n // Generated configuration rather than anything the user edits, so a re-run\n // refreshes it — unlike the models beside it.\n { overwriteStrategy: OverwriteStrategy.Overwrite },\n );\n\nexport const smithyProjectGenerator = async (\n tree: Tree,\n options: SmithyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const cmd = new FsCommands(tree, DEPENDENCIES);\n const type = options.type ?? 'service';\n\n // Create project.json\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n\n if (!projectExists(tree, fullyQualifiedName)) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'library',\n targets: {\n build: {\n dependsOn:\n type === 'shapes' ? ['compile'] : ['compile', 'generate-ssdk'],\n },\n // Everything this project's build does is artifact production, so\n // `assemble` carries the same dependencies.\n assemble: {\n dependsOn:\n type === 'shapes' ? ['compile'] : ['compile', 'generate-ssdk'],\n },\n compile: {\n cache: true,\n outputs: smithyCompileOutputs(type),\n executor: 'nx:run-commands',\n options: {\n commands: smithyCompileCommands(cmd, type),\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n },\n // Only a service generates a Server SDK, and it is built from what the\n // model build leaves behind.\n ...(type === 'shapes'\n ? {}\n : { 'generate-ssdk': smithyGenerateSsdkTarget() }),\n },\n });\n }\n\n const serviceName = options.serviceName ?? options.name;\n const serviceNameClassName = toClassName(serviceName);\n const serviceNameKebabCase = toKebabCase(serviceName);\n const scope = getNpmScope(tree);\n const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', type),\n dir,\n {\n namespace,\n serviceNameClassName,\n serviceNameKebabCase,\n scope,\n projectRoot: dir,\n relativePathToWorkspaceRoot: getRelativePathToRootByDirectory(dir),\n ...smithyMavenVersions(),\n },\n {\n // Smithy models are user-owned — a re-run must not discard edits\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n if (type === 'service') {\n writeSsdkBundleConfig(tree, dir);\n }\n\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: SmithyProjectMetadata = { smithyType: type, namespace };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n SMITHY_PROJECT_GENERATOR_INFO,\n {\n ...metadata,\n ...(type === 'service' ? { apiName: options.name } : {}),\n },\n );\n\n // No projectRoot: a Smithy model project has no manifest of its own, and every\n // dependency here is workspace tooling the build runs rather than anything the\n // model imports.\n addTsDependencies(tree, DEPENDENCIES, { metadata });\n\n await addGeneratorMetricsIfApplicable(tree, [SMITHY_PROJECT_GENERATOR_INFO]);\n\n // On Windows the build runs the Smithy CLI from the PATH rather than through\n // mise, so flag a missing prerequisite while the project is still being set up.\n warnIfSmithyMissing();\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default smithyProjectGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","getTsLibDetails","addTsDependencies","declareDependencies","ownedElsewhere","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","getNpmScope","addGeneratorMetadata","getGeneratorInfo","projectExists","getRelativePathToRootByDirectory","smithyCliCommand","smithyMavenVersions","warnIfSmithyMissing","isService","metadata","smithyType","DEPENDENCIES","ts","name","dev","root","when","SMITHY_PROJECT_GENERATOR_INFO","filename","SMITHY_OUT_DIR","BUILD_DIR","SOURCE_PROJECTION","SSDK_CODEGEN_DIR","smithyCompileCommands","cmd","type","rm","mkdir","cpFile","cpGlobToFile","smithyGenerateSsdkCommands","smithyCompileOutputs","smithyGenerateSsdkTarget","cache","outputs","executor","dependsOn","options","commands","parallel","cwd","writeSsdkBundleConfig","tree","projectRoot","dirname","overwriteStrategy","Overwrite","smithyProjectGenerator","fullyQualifiedName","dir","sourceRoot","projectType","targets","build","assemble","compile","serviceName","serviceNameClassName","serviceNameKebabCase","scope","namespace","replace","relativePathToWorkspaceRoot","KeepExisting","apiName","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAoB;AAChE,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,WAAW,EAAEC,WAAW,QAAQ,uBAAuB;AAChE,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,gCAAgC,QAAQ,uBAAuB;AACxE,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,mBAAmB,QACd,wBAAwB;AAS/B;;;;CAIC,GACD,MAAMC,YAAY,CAACC,WACjBA,SAASC,UAAU,KAAK;AAE1B;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAepB,sBAA6C;IACvEqB,IAAI;QACF,+DAA+D;WAC5DpB,eAAeE;QAClB;YAAEmB,MAAM;YAAYC,KAAK;YAAMC,MAAM;YAAMC,MAAMR;QAAU;QAC3D;YAAEK,MAAM;YAAuBC,KAAK;YAAMC,MAAM;YAAMC,MAAMR;QAAU;QACtE,qEAAqE;QACrE;YAAEK,MAAM;YAAcC,KAAK;YAAMC,MAAM;YAAMC,MAAMR;QAAU;KAC9D;AACH,GAAG;AAEH,OAAO,MAAMS,gCAAiDf,iBAC5D,YAAYgB,QAAQ,EACpB;AAEF;;;;;;;;CAQC,GACD,MAAMC,iBAAiB;AACvB,MAAMC,YAAY;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D;QACF;IACF;IAEA,MAAMwB,cAAcnB,QAAQmB,WAAW,IAAInB,QAAQxB,IAAI;IACvD,MAAM4C,uBAAuB3D,YAAY0D;IACzC,MAAME,uBAAuB3D,YAAYyD;IACzC,MAAMG,QAAQ3D,YAAY0C;IAC1B,MAAMkB,YAAYvB,QAAQuB,SAAS,IAAI7D,YAAY4D,OAAOE,OAAO,CAAC,MAAM;IAExE3E,cACEwD,MACAvD,kBAAkB,YAAYyD,OAAO,EAAE,SAASnB,OAChDwB,KACA;QACEW;QACAH;QACAC;QACAC;QACAhB,aAAaM;QACba,6BAA6B1D,iCAAiC6C;QAC9D,GAAG3C,qBAAqB;IAC1B,GACA;QACE,iEAAiE;QACjEuC,mBAAmBzD,kBAAkB2E,YAAY;IACnD;IAGF,IAAItC,SAAS,WAAW;QACtBgB,sBAAsBC,MAAMO;IAC9B;IAEA,0EAA0E;IAC1E,8DAA8D;IAC9D,MAAMxC,WAAkC;QAAEC,YAAYe;QAAMmC;IAAU;IAEtE3D,qBACEyC,MACAM,oBACA/B,+BACA;QACE,GAAGR,QAAQ;QACX,GAAIgB,SAAS,YAAY;YAAEuC,SAAS3B,QAAQxB,IAAI;QAAC,IAAI,CAAC,CAAC;IACzD;IAGF,+EAA+E;IAC/E,+EAA+E;IAC/E,iBAAiB;IACjBvB,kBAAkBoD,MAAM/B,cAAc;QAAEF;IAAS;IAEjD,MAAMZ,gCAAgC6C,MAAM;QAACzB;KAA8B;IAE3E,6EAA6E;IAC7E,gFAAgF;IAChFV;IAEA,MAAMd,qBAAqBiD;IAC3B,OAAO,IACL9C,oBAAoB8C,MAAML,QAAQ4B,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAenB,uBAAuB"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/smithy/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 type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n} from '@nx/devkit';\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 { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { toClassName, toKebabCase } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addGeneratorMetadata,\n getGeneratorInfo,\n type NxGeneratorInfo,\n projectExists,\n} from '../../utils/nx.js';\nimport { getRelativePathToRootByDirectory } from '../../utils/paths.js';\nimport {\n smithyCliCommand,\n smithyMavenVersions,\n warnIfSmithyMissing,\n} from '../../utils/smithy.js';\nimport type { SmithyProjectGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface SmithyProjectMetadata {\n readonly smithyType: NonNullable<SmithyProjectGeneratorSchema['type']>;\n readonly namespace: string;\n}\n\n/**\n * Only a service project generates a Server SDK, so only a service needs the\n * bundler that turns it into the single module its backend imports. A shape\n * library assembles a model and stops.\n */\nconst isService = (metadata: SmithyProjectMetadata) =>\n metadata.smithyType === 'service';\n\n/**\n * Everything a Smithy build runs, all of it workspace tooling in the root\n * manifest rather than anything the model itself imports.\n *\n * Neither the Smithy CLI nor `mise` is among them: the compile target fetches mise\n * with `npx` and mise resolves the CLI, so neither is a workspace dependency — see\n * `utils/smithy.ts`.\n */\nexport const DEPENDENCIES = declareDependencies<SmithyProjectMetadata>()({\n ts: [\n // Added to the root by `FsCommands` as it builds each command.\n ...ownedElsewhere(FS_DEPENDENCIES),\n { name: 'rolldown', dev: true, root: true, when: isService },\n { name: 'rolldown-plugin-dts', dev: true, root: true, when: isService },\n // Resolved by `rolldown-plugin-dts` to emit the bundled declaration.\n { name: 'typescript', dev: true, root: true, when: isService },\n ],\n});\n\nexport const SMITHY_PROJECT_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\n/**\n * Where the Smithy CLI writes its artifacts, and where the build publishes the\n * ones consumers read. Both sit under `dist` so a build writes nothing into the\n * project, keeping the source tree clean and the target's outputs cacheable.\n *\n * The CLI's own output is kept beside the published tree rather than inside it:\n * it holds the generated SSDK package and its installed `node_modules`, which\n * must not be mistaken for a build artifact.\n */\nconst SMITHY_OUT_DIR = 'dist/{projectRoot}/smithy';\nconst BUILD_DIR = 'dist/{projectRoot}/build';\n\n/** The projection every generated `smithy-build.json` builds. */\nconst SOURCE_PROJECTION = `${SMITHY_OUT_DIR}/source`;\n\n/** Where the generated TypeScript Server SDK lands before it is bundled. */\nconst SSDK_CODEGEN_DIR = `${SOURCE_PROJECTION}/typescript-ssdk-codegen`;\n\n/**\n * The commands that build a Smithy project's model, run from the workspace root.\n *\n * This is the whole of a shape library's build. A service's Server SDK is built\n * separately by {@link smithyGenerateSsdkCommands}, from the codegen output this\n * leaves under {@link SMITHY_OUT_DIR}.\n */\nexport const smithyCompileCommands = (\n cmd: FsCommands<typeof DEPENDENCIES>,\n type: SmithyProjectGeneratorSchema['type'],\n): string[] => [\n cmd.rm(BUILD_DIR),\n cmd.rm(SMITHY_OUT_DIR),\n cmd.mkdir(BUILD_DIR),\n // `imports` in smithy-build.json resolve relative to that file, so a shape\n // library is referenced by its path from the consuming project.\n `${smithyCliCommand()} build -c {projectRoot}/smithy-build.json --output ${SMITHY_OUT_DIR}`,\n ...(type === 'shapes'\n ? [\n cmd.cpFile(\n `${SOURCE_PROJECTION}/model/model.json`,\n `${BUILD_DIR}/model.json`,\n ),\n ]\n : [\n cmd.mkdir(`${BUILD_DIR}/openapi`),\n // Named after the service shape by the OpenAPI plugin, so it is matched\n // rather than named, and published under a stable name.\n cmd.cpGlobToFile(\n `${SOURCE_PROJECTION}/openapi/*.openapi.json`,\n `${BUILD_DIR}/openapi`,\n 'openapi.json',\n ),\n ]),\n];\n\n/**\n * The commands that turn a service's generated TypeScript Server SDK into the\n * single module its consumer imports, run from the workspace root.\n *\n * Only a service has one, and it reads what the model build left behind, so this\n * runs after `compile`.\n */\nexport const smithyGenerateSsdkCommands = (): string[] => [\n // `npm` regardless of the workspace's package manager: this installs a generated\n // package under `dist` that is not a workspace member, and npm ships with Node so\n // it is always present. It reads the user's `.npmrc`, so a private registry still\n // applies. `--include=dev` because the bundler resolves types from the generated\n // package's devDependencies, which `NODE_ENV=production` would otherwise omit.\n `npm install --prefix ${SSDK_CODEGEN_DIR} --include=dev --ignore-scripts --no-audit --no-fund`,\n // Bundled straight from the generated TypeScript sources, emitting the module and\n // its declarations together — see ssdk.rolldown.config.mjs for why the sources\n // rather than a `tsc` pre-pass.\n `rolldown -c {projectRoot}/ssdk.rolldown.config.mjs`,\n];\n\n/**\n * What the model build publishes, listed per artifact rather than as the whole\n * `build` directory: a service's `generate-ssdk` writes into that directory too, and\n * restoring `compile` from cache would otherwise discard the Server SDK beside it.\n */\nexport const smithyCompileOutputs = (\n type: SmithyProjectGeneratorSchema['type'],\n): string[] => [\n `{workspaceRoot}/${SMITHY_OUT_DIR}`,\n type === 'shapes'\n ? `{workspaceRoot}/${BUILD_DIR}/model.json`\n : `{workspaceRoot}/${BUILD_DIR}/openapi`,\n];\n\n/**\n * What a Smithy build target hashes: its own sources plus the outputs of the\n * tasks it depends on. That covers a consumed shape library's output only\n * when nx.json's `default` named input carries the `dependentTasksOutputFiles`\n * entry, which only ts/lib/generator.ts writes - a Smithy-only workspace has\n * no such entry, so `default` falls back to Nx's `{projectRoot}/**\\/*`.\n */\nexport const SMITHY_TARGET_INPUTS = ['default'];\n\n/**\n * The target that builds a service's Server SDK, shared with the migration moving\n * an existing project onto it.\n */\nexport const smithyGenerateSsdkTarget = () => ({\n cache: true,\n inputs: [...SMITHY_TARGET_INPUTS],\n outputs: [`{workspaceRoot}/${BUILD_DIR}/ssdk`],\n executor: 'nx:run-commands',\n dependsOn: ['compile'],\n options: {\n commands: smithyGenerateSsdkCommands(),\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n});\n\n/**\n * Write the rolldown config that bundles a service's generated Server SDK.\n *\n * Shared with the migration moving an existing project off the container build,\n * so a migrated project's config cannot drift from a freshly generated one.\n */\nexport const writeSsdkBundleConfig = (tree: Tree, projectRoot: string): void =>\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'ssdk-bundle'),\n projectRoot,\n // The config's paths are workspace-root relative, so it needs only the\n // project's root — the compile target runs from the workspace root.\n { projectRoot },\n // Generated configuration rather than anything the user edits, so a re-run\n // refreshes it — unlike the models beside it.\n { overwriteStrategy: OverwriteStrategy.Overwrite },\n );\n\nexport const smithyProjectGenerator = async (\n tree: Tree,\n options: SmithyProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const cmd = new FsCommands(tree, DEPENDENCIES);\n const type = options.type ?? 'service';\n\n // Create project.json\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, options);\n\n if (!projectExists(tree, fullyQualifiedName)) {\n addProjectConfiguration(tree, fullyQualifiedName, {\n name: fullyQualifiedName,\n root: dir,\n sourceRoot: joinPathFragments(dir, 'src'),\n projectType: 'library',\n targets: {\n build: {\n dependsOn:\n type === 'shapes' ? ['compile'] : ['compile', 'generate-ssdk'],\n },\n // Everything this project's build does is artifact production, so\n // `assemble` carries the same dependencies.\n assemble: {\n dependsOn:\n type === 'shapes' ? ['compile'] : ['compile', 'generate-ssdk'],\n },\n compile: {\n cache: true,\n inputs: [...SMITHY_TARGET_INPUTS],\n outputs: smithyCompileOutputs(type),\n executor: 'nx:run-commands',\n options: {\n commands: smithyCompileCommands(cmd, type),\n parallel: false,\n cwd: '{workspaceRoot}',\n },\n },\n // Only a service generates a Server SDK, and it is built from what the\n // model build leaves behind.\n ...(type === 'shapes'\n ? {}\n : { 'generate-ssdk': smithyGenerateSsdkTarget() }),\n },\n });\n }\n\n const serviceName = options.serviceName ?? options.name;\n const serviceNameClassName = toClassName(serviceName);\n const serviceNameKebabCase = toKebabCase(serviceName);\n const scope = getNpmScope(tree);\n const namespace = options.namespace ?? toKebabCase(scope).replace(/-/g, '.');\n\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', type),\n dir,\n {\n namespace,\n serviceNameClassName,\n serviceNameKebabCase,\n scope,\n projectRoot: dir,\n relativePathToWorkspaceRoot: getRelativePathToRootByDirectory(dir),\n ...smithyMavenVersions(),\n },\n {\n // Smithy models are user-owned — a re-run must not discard edits\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n if (type === 'service') {\n writeSsdkBundleConfig(tree, dir);\n }\n\n // Recorded here and read by the declaration's predicates, so the packages\n // added below are exactly the ones the version sync will own.\n const metadata: SmithyProjectMetadata = { smithyType: type, namespace };\n\n addGeneratorMetadata(\n tree,\n fullyQualifiedName,\n SMITHY_PROJECT_GENERATOR_INFO,\n {\n ...metadata,\n ...(type === 'service' ? { apiName: options.name } : {}),\n },\n );\n\n // No projectRoot: a Smithy model project has no manifest of its own, and every\n // dependency here is workspace tooling the build runs rather than anything the\n // model imports.\n addTsDependencies(tree, DEPENDENCIES, { metadata });\n\n await addGeneratorMetricsIfApplicable(tree, [SMITHY_PROJECT_GENERATOR_INFO]);\n\n // On Windows the build runs the Smithy CLI from the PATH rather than through\n // mise, so flag a missing prerequisite while the project is still being set up.\n warnIfSmithyMissing();\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default smithyProjectGenerator;\n"],"names":["addProjectConfiguration","generateFiles","joinPathFragments","OverwriteStrategy","getTsLibDetails","addTsDependencies","declareDependencies","ownedElsewhere","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","installDependencies","addGeneratorMetricsIfApplicable","toClassName","toKebabCase","getNpmScope","addGeneratorMetadata","getGeneratorInfo","projectExists","getRelativePathToRootByDirectory","smithyCliCommand","smithyMavenVersions","warnIfSmithyMissing","isService","metadata","smithyType","DEPENDENCIES","ts","name","dev","root","when","SMITHY_PROJECT_GENERATOR_INFO","filename","SMITHY_OUT_DIR","BUILD_DIR","SOURCE_PROJECTION","SSDK_CODEGEN_DIR","smithyCompileCommands","cmd","type","rm","mkdir","cpFile","cpGlobToFile","smithyGenerateSsdkCommands","smithyCompileOutputs","SMITHY_TARGET_INPUTS","smithyGenerateSsdkTarget","cache","inputs","outputs","executor","dependsOn","options","commands","parallel","cwd","writeSsdkBundleConfig","tree","projectRoot","dirname","overwriteStrategy","Overwrite","smithyProjectGenerator","fullyQualifiedName","dir","sourceRoot","projectType","targets","build","assemble","compile","serviceName","serviceNameClassName","serviceNameKebabCase","scope","namespace","replace","relativePathToWorkspaceRoot","KeepExisting","apiName","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,uBAAuB,EAEvBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,QAEZ,aAAa;AACpB,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAoB;AAChE,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,WAAW,EAAEC,WAAW,QAAQ,uBAAuB;AAChE,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SACEC,oBAAoB,EACpBC,gBAAgB,EAEhBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,gCAAgC,QAAQ,uBAAuB;AACxE,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,mBAAmB,QACd,wBAAwB;AAS/B;;;;CAIC,GACD,MAAMC,YAAY,CAACC,WACj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,qBACE2C,MACAM,oBACAjC,+BACA;QACE,GAAGR,QAAQ;QACX,GAAIgB,SAAS,YAAY;YAAEyC,SAAS3B,QAAQ1B,IAAI;QAAC,IAAI,CAAC,CAAC;IACzD;IAGF,+EAA+E;IAC/E,+EAA+E;IAC/E,iBAAiB;IACjBvB,kBAAkBsD,MAAMjC,cAAc;QAAEF;IAAS;IAEjD,MAAMZ,gCAAgC+C,MAAM;QAAC3B;KAA8B;IAE3E,6EAA6E;IAC7E,gFAAgF;IAChFV;IAEA,MAAMd,qBAAqBmD;IAC3B,OAAO,IACLhD,oBAAoBgD,MAAML,QAAQ4B,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAenB,uBAAuB"}
@@ -2165,6 +2165,7 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with default optio
2165
2165
  },
2166
2166
  "compile": {
2167
2167
  "cache": true,
2168
+ "inputs": ["default"],
2168
2169
  "outputs": [
2169
2170
  "{workspaceRoot}/dist/{projectRoot}/smithy",
2170
2171
  "{workspaceRoot}/dist/{projectRoot}/build/openapi"
@@ -2185,6 +2186,7 @@ exports[`tsSmithyApiGenerator > should generate smithy ts api with default optio
2185
2186
  },
2186
2187
  "generate-ssdk": {
2187
2188
  "cache": true,
2189
+ "inputs": ["default"],
2188
2190
  "outputs": ["{workspaceRoot}/dist/{projectRoot}/build/ssdk"],
2189
2191
  "executor": "nx:run-commands",
2190
2192
  "dependsOn": ["compile"],
@@ -231,12 +231,10 @@ export async function terraformProjectGenerator(tree, schema) {
231
231
  '^init'
232
232
  ]
233
233
  },
234
+ // Reads remote state, which no input can hash.
234
235
  output: {
235
236
  executor: 'nx:run-commands',
236
- cache: true,
237
- inputs: [
238
- 'default'
239
- ],
237
+ cache: false,
240
238
  options: {
241
239
  command: 'terraform output -json',
242
240
  forwardAllArgs: true,
@@ -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,qB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;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,iBA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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"}
@@ -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. `reports/` and `coverage/` hold
38
- * pytest's JUnit and coverage XML, which carry a wall-clock timestamp and so
39
- * mint a fresh hash on every test run that would cascade through the graph.
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)
@@ -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. `reports/` and `coverage/` hold
34
- * pytest's JUnit and coverage XML, which carry a wall-clock timestamp and so
35
- * mint a fresh hash on every test run that would cascade through the graph.
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 in place, so the entry is neither duplicated nor left at a
42
- // different scope when a generator re-runs.
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,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BAAqByB;IAE3B,mFAAmF;IACnF,uEAAuE;IACvE,8EAA8E;IAC9E,OAAO,IACLxB,oBAAoBwB,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;A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ByB;IAE3B,mFAAmF;IACnF,uEAAuE;IACvE,8EAA8E;IAC9E,OAAO,IACLxB,oBAAoBwB,MAAMC,OAAOoD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AACF,eAAe7C,mBAAmB"}
@@ -224,6 +224,10 @@ export const tsRdbGenerator = async (tree, options)=>{
224
224
  }
225
225
  projectConfig.targets.generate = {
226
226
  executor: 'nx:run-commands',
227
+ cache: true,
228
+ inputs: [
229
+ 'default'
230
+ ],
227
231
  outputs: [
228
232
  '{projectRoot}/generated/prisma'
229
233
  ],