@aws/nx-plugin 1.0.0-rc.95 → 1.0.0-rc.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/LICENSE-THIRD-PARTY +234 -38
  2. package/migrations.json +65 -2
  3. package/package.json +6 -6
  4. package/src/agentcore-gateway/__snapshots__/generator.spec.ts.snap +1 -1
  5. package/src/agentcore-gateway/generator.js +6 -0
  6. package/src/agentcore-gateway/generator.js.map +1 -1
  7. package/src/agentcore-gateway/react-connection/__snapshots__/generator.spec.ts.snap +4 -1
  8. package/src/agentcore-harness/__snapshots__/generator.spec.ts.snap +68 -4
  9. package/src/agentcore-harness/generator.js +6 -0
  10. package/src/agentcore-harness/generator.js.map +1 -1
  11. package/src/connection/gateway-runtime-config.js +1 -1
  12. package/src/connection/gateway-runtime-config.js.map +1 -1
  13. package/src/infra/app/__snapshots__/generator.spec.ts.snap +10 -16
  14. package/src/infra/app/generator.js +34 -7
  15. package/src/infra/app/generator.js.map +1 -1
  16. package/src/init/generator.d.ts +1 -1
  17. package/src/init/generator.js +8 -6
  18. package/src/init/generator.js.map +1 -1
  19. package/src/init/schema.d.js.map +1 -1
  20. package/src/init/schema.d.ts +1 -0
  21. package/src/init/schema.json +5 -0
  22. package/src/mcp-server/server.js +2 -0
  23. package/src/mcp-server/server.js.map +1 -1
  24. package/src/mcp-server/tools/best-practices.d.ts +28 -0
  25. package/src/mcp-server/tools/best-practices.js +43 -0
  26. package/src/mcp-server/tools/best-practices.js.map +1 -0
  27. package/src/mcp-server/tools/general-guidance.d.ts +1 -1
  28. package/src/mcp-server/tools/general-guidance.js +13 -4
  29. package/src/mcp-server/tools/general-guidance.js.map +1 -1
  30. package/src/migrations/latest/checkov-scan-cache-inputs/metadata.json +3 -0
  31. package/src/migrations/latest/checkov-scan-cache-inputs/migration.d.ts +6 -0
  32. package/src/migrations/latest/checkov-scan-cache-inputs/migration.js +58 -0
  33. package/src/migrations/latest/checkov-scan-cache-inputs/migration.js.map +1 -0
  34. package/src/migrations/latest/gateway-url-accessor/__snapshots__/migration.spec.ts.snap +84 -0
  35. package/src/migrations/latest/gateway-url-accessor/metadata.json +3 -0
  36. package/src/migrations/latest/gateway-url-accessor/migration.d.ts +6 -0
  37. package/src/migrations/latest/gateway-url-accessor/migration.js +94 -0
  38. package/src/migrations/latest/gateway-url-accessor/migration.js.map +1 -0
  39. package/src/migrations/latest/infra-deploy-express-mode/metadata.json +1 -1
  40. package/src/migrations/latest/infra-deploy-express-mode/migration.js +26 -28
  41. package/src/migrations/latest/infra-deploy-express-mode/migration.js.map +1 -1
  42. package/src/migrations/latest/py-lambda-powertools-context/metadata.json +3 -0
  43. package/src/migrations/latest/py-lambda-powertools-context/migration.d.ts +6 -0
  44. package/src/migrations/latest/py-lambda-powertools-context/migration.js +58 -0
  45. package/src/migrations/latest/py-lambda-powertools-context/migration.js.map +1 -0
  46. package/src/migrations/latest/script-project-quality-gates/metadata.json +3 -0
  47. package/src/migrations/latest/script-project-quality-gates/migration.d.ts +6 -0
  48. package/src/migrations/latest/script-project-quality-gates/migration.js +53 -0
  49. package/src/migrations/latest/script-project-quality-gates/migration.js.map +1 -0
  50. package/src/migrations/latest/smithy-extension-trait-aliases/__snapshots__/migration.spec.ts.snap +25 -0
  51. package/src/migrations/latest/smithy-extension-trait-aliases/metadata.json +3 -0
  52. package/src/migrations/latest/smithy-extension-trait-aliases/migration.d.ts +28 -0
  53. package/src/migrations/latest/smithy-extension-trait-aliases/migration.js +75 -0
  54. package/src/migrations/latest/smithy-extension-trait-aliases/migration.js.map +1 -0
  55. package/src/migrations/latest/terraform-validate-without-backend/metadata.json +3 -0
  56. package/src/migrations/latest/terraform-validate-without-backend/migration.d.ts +6 -0
  57. package/src/migrations/latest/terraform-validate-without-backend/migration.js +84 -0
  58. package/src/migrations/latest/terraform-validate-without-backend/migration.js.map +1 -0
  59. package/src/preset/__snapshots__/generator.spec.ts.snap +3 -5
  60. package/src/preset/generator.js +4 -25
  61. package/src/preset/generator.js.map +1 -1
  62. package/src/py/agent/a2a-connection/generator.d.ts +1 -1
  63. package/src/py/agent/gateway-connection/generator.d.ts +1 -1
  64. package/src/py/agent/mcp-connection/generator.d.ts +1 -1
  65. package/src/py/agent/react-connection/__snapshots__/generator.spec.ts.snap +4 -1
  66. package/src/py/agent/react-connection/generator.d.ts +29 -0
  67. package/src/py/dynamodb/__snapshots__/generator.spec.ts.snap +8 -10
  68. package/src/py/dynamodb/generator.js +34 -7
  69. package/src/py/dynamodb/generator.js.map +1 -1
  70. package/src/py/lambda-function/__snapshots__/generator.spec.ts.snap +2 -1
  71. package/src/py/lambda-function/files/handler/__lambdaFunctionSnakeCase__.py.template +2 -1
  72. package/src/py/project/schema.json +3 -1
  73. package/src/py/rdb/__snapshots__/generator.spec.ts.snap +28 -12
  74. package/src/py/rdb/files/Dockerfile.create-db-user.template +7 -3
  75. package/src/py/rdb/files/Dockerfile.migration.template +7 -3
  76. package/src/py/rdb/generator.js +29 -28
  77. package/src/py/rdb/generator.js.map +1 -1
  78. package/src/smithy/react-connection/files/model/extensions.smithy.template +3 -3
  79. package/src/smithy/ts/api/generator.js +7 -2
  80. package/src/smithy/ts/api/generator.js.map +1 -1
  81. package/src/terraform/project/generator.js +34 -10
  82. package/src/terraform/project/generator.js.map +1 -1
  83. package/src/trpc/backend/generator.js +7 -1
  84. package/src/trpc/backend/generator.js.map +1 -1
  85. package/src/trpc/react/generator.js +6 -0
  86. package/src/trpc/react/generator.js.map +1 -1
  87. package/src/ts/agent/generator.js +3 -3
  88. package/src/ts/agent/generator.js.map +1 -1
  89. package/src/ts/agent/react-connection/generator.d.ts +37 -0
  90. package/src/ts/dynamodb/__snapshots__/generator.spec.ts.snap +2 -0
  91. package/src/ts/dynamodb/generator.js +30 -6
  92. package/src/ts/dynamodb/generator.js.map +1 -1
  93. package/src/ts/lib/biome.d.ts +15 -1
  94. package/src/ts/lib/biome.js +79 -63
  95. package/src/ts/lib/biome.js.map +1 -1
  96. package/src/ts/lib/generator.d.ts +13 -0
  97. package/src/ts/lib/generator.js +14 -9
  98. package/src/ts/lib/generator.js.map +1 -1
  99. package/src/ts/lib/ts-project-utils.d.ts +31 -1
  100. package/src/ts/lib/ts-project-utils.js +53 -0
  101. package/src/ts/lib/ts-project-utils.js.map +1 -1
  102. package/src/ts/lib/vitest.d.ts +6 -0
  103. package/src/ts/lib/vitest.js +16 -1
  104. package/src/ts/lib/vitest.js.map +1 -1
  105. package/src/ts/mcp-server/generator.js +3 -3
  106. package/src/ts/mcp-server/generator.js.map +1 -1
  107. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +5 -0
  108. package/src/ts/rdb/files/Dockerfile.template +5 -0
  109. package/src/ts/rdb/generator.d.ts +8 -0
  110. package/src/ts/rdb/generator.js +28 -24
  111. package/src/ts/rdb/generator.js.map +1 -1
  112. package/src/ts/rdb/trpc-connection/__snapshots__/generator.spec.ts.snap +39 -0
  113. package/src/ts/rdb/trpc-connection/generator.js +13 -0
  114. package/src/ts/rdb/trpc-connection/generator.js.map +1 -1
  115. package/src/ts/react-website/agui/files/common/src/components/__agentNameKebabCase__-chat.tsx.template +9 -0
  116. package/src/ts/react-website/agui/files/common/src/hooks/useAgui__agentNameClassName__.tsx.template +4 -1
  117. package/src/ts/react-website/agui/generator.d.ts +21 -0
  118. package/src/ts/react-website/agui/generator.js +6 -2
  119. package/src/ts/react-website/agui/generator.js.map +1 -1
  120. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +26 -22
  121. package/src/ts/react-website/app/generator.d.ts +42 -0
  122. package/src/ts/react-website/app/generator.js +4 -8
  123. package/src/ts/react-website/app/generator.js.map +1 -1
  124. package/src/utils/agent-connection/agent-connection.d.ts +2 -1
  125. package/src/utils/agent-connection/agent-connection.js +6 -1
  126. package/src/utils/agent-connection/agent-connection.js.map +1 -1
  127. package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +11 -7
  128. package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +14 -6
  129. package/src/utils/agent-core-packaging.js +5 -5
  130. package/src/utils/agent-core-packaging.js.map +1 -1
  131. package/src/utils/api-constructs/api-constructs.d.ts +5 -0
  132. package/src/utils/api-constructs/api-constructs.js +8 -0
  133. package/src/utils/api-constructs/api-constructs.js.map +1 -1
  134. package/src/utils/api-constructs/files/cdk/app/apis/http/__apiNameKebabCase__.ts.template +4 -2
  135. package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +4 -2
  136. package/src/utils/ast.d.ts +10 -0
  137. package/src/utils/ast.js +33 -0
  138. package/src/utils/ast.js.map +1 -1
  139. package/src/utils/dependencies.js +1 -10
  140. package/src/utils/dependencies.js.map +1 -1
  141. package/src/utils/docker.d.ts +11 -0
  142. package/src/utils/docker.js +16 -3
  143. package/src/utils/docker.js.map +1 -1
  144. package/src/utils/dynamodb-config.d.ts +48 -0
  145. package/src/utils/dynamodb-config.js +44 -0
  146. package/src/utils/dynamodb-config.js.map +1 -0
  147. package/src/utils/dynamodb-constructs/files/cdk/app/dynamodb/__nameKebabCase__.ts.template +8 -4
  148. package/src/utils/git-secrets.d.ts +28 -0
  149. package/src/utils/git-secrets.js +66 -0
  150. package/src/utils/git-secrets.js.map +1 -0
  151. package/src/utils/init.js +7 -6
  152. package/src/utils/init.js.map +1 -1
  153. package/src/utils/local-project-dependency.d.ts +28 -0
  154. package/src/utils/local-project-dependency.js +40 -0
  155. package/src/utils/local-project-dependency.js.map +1 -0
  156. package/src/utils/nx.d.ts +14 -0
  157. package/src/utils/nx.js +30 -0
  158. package/src/utils/nx.js.map +1 -1
  159. package/src/utils/rdb-constructs/files/cdk/app/dbs/__nameKebabCase__.ts.template +11 -6
  160. package/src/utils/script-project-targets.d.ts +26 -0
  161. package/src/utils/script-project-targets.js +75 -0
  162. package/src/utils/script-project-targets.js.map +1 -0
  163. package/src/utils/shared-shadcn.d.ts +13 -0
  164. package/src/utils/shared-shadcn.js +3 -2
  165. package/src/utils/shared-shadcn.js.map +1 -1
  166. package/src/utils/test.js +15 -0
  167. package/src/utils/test.js.map +1 -1
  168. package/src/utils/version-upgrade-migration/sync-vended-versions.js +4 -4
  169. package/src/utils/version-upgrade-migration/sync-vended-versions.js.map +1 -1
  170. package/src/utils/versions.d.ts +13 -9
  171. package/src/utils/versions.js +17 -8
  172. package/src/utils/versions.js.map +1 -1
  173. package/src/utils/website-constructs/files/cdk/app/static-websites/__websiteNameKebabCase__.ts.template +8 -4
  174. package/src/py/dynamodb/files/__name__/__init__.py.template +0 -6
  175. package/src/py/dynamodb/files/__name__/entities/__init__.py.template +0 -4
  176. package/src/py/dynamodb/files/config.json.template +0 -24
  177. package/src/ts/dynamodb/files/config.json.template +0 -24
  178. package/src/ts/dynamodb/files/src/entities/index.ts.template +0 -1
  179. package/src/ts/dynamodb/files/src/index.ts.template +0 -2
@@ -4,75 +4,77 @@
4
4
  */ import { readNxJson, updateNxJson, updateProjectConfiguration } from "@nx/devkit";
5
5
  import { readProjectConfigurationUnqualified } from "../../utils/nx.js";
6
6
  import { sortObjectKeys } from "../../utils/object.js";
7
- export const configureBiomeLint = async (tree, options)=>{
8
- const projectJson = readProjectConfigurationUnqualified(tree, options.fullyQualifiedName);
9
- const biomeConfigured = tree.exists('biome.json');
10
- // When there's no root Biome configuration (eg the user removed it), make the
11
- // lint target a no-op rather than failing on a missing config.
12
- const lintTarget = biomeConfigured ? {
13
- executor: 'nx:run-commands',
14
- cache: true,
15
- inputs: [
16
- 'biome'
17
- ],
18
- options: {
19
- command: 'biome lint {projectRoot}'
20
- },
21
- configurations: {
22
- fix: {
23
- command: 'biome check --write {projectRoot}'
7
+ /**
8
+ * The `format` and `lint` targets every Biome-linted project gets, so a project
9
+ * that isn't scaffolded by `ts#project` (e.g. an AgentCore Gateway hosting only
10
+ * `local-dev.ts`) is linted identically rather than by its own copy.
11
+ *
12
+ * When there's no root Biome configuration (eg the user removed it), the targets
13
+ * are no-ops rather than failing on a missing config.
14
+ */ export const biomeTargets = (tree)=>{
15
+ if (!tree.exists('biome.json')) {
16
+ return {
17
+ format: {
18
+ executor: 'nx:noop'
24
19
  },
25
- 'skip-lint': {
26
- // Cross-platform no-op (`true` is not available on Windows cmd).
27
- command: 'node -e ""'
20
+ lint: {
21
+ executor: 'nx:noop'
28
22
  }
29
- },
30
- // Format before linting so any fixable formatting issues (eg line too
31
- // long) are resolved first, mirroring the Python project generator.
32
- dependsOn: [
33
- 'format'
34
- ]
35
- } : {
36
- executor: 'nx:noop'
37
- };
38
- // The base format target checks formatting (failing when files aren't
39
- // formatted); the `fix` configuration writes the changes. `skip-lint` is a
40
- // no-op so `nx lint --configuration=skip-lint` propagates cleanly through the
41
- // lint -> format dependency edge.
42
- const formatTarget = biomeConfigured ? {
43
- executor: 'nx:run-commands',
44
- cache: true,
45
- inputs: [
46
- 'biome'
47
- ],
48
- options: {
49
- command: 'biome format {projectRoot}'
50
- },
51
- configurations: {
52
- fix: {
53
- command: 'biome format --write {projectRoot}'
23
+ };
24
+ }
25
+ return {
26
+ // The base format target checks formatting (failing when files aren't
27
+ // formatted); the `fix` configuration writes the changes. `skip-lint` is a
28
+ // no-op so `nx lint --configuration=skip-lint` propagates cleanly through
29
+ // the lint -> format dependency edge.
30
+ format: {
31
+ executor: 'nx:run-commands',
32
+ cache: true,
33
+ inputs: [
34
+ 'biome'
35
+ ],
36
+ options: {
37
+ command: 'biome format {projectRoot}'
54
38
  },
55
- 'skip-lint': {
56
- // Cross-platform no-op (`true` is not available on Windows cmd).
57
- command: 'node -e ""'
39
+ configurations: {
40
+ fix: {
41
+ command: 'biome format --write {projectRoot}'
42
+ },
43
+ 'skip-lint': {
44
+ // Cross-platform no-op (`true` is not available on Windows cmd).
45
+ command: 'node -e ""'
46
+ }
58
47
  }
48
+ },
49
+ lint: {
50
+ executor: 'nx:run-commands',
51
+ cache: true,
52
+ inputs: [
53
+ 'biome'
54
+ ],
55
+ options: {
56
+ command: 'biome lint {projectRoot}'
57
+ },
58
+ configurations: {
59
+ fix: {
60
+ command: 'biome check --write {projectRoot}'
61
+ },
62
+ 'skip-lint': {
63
+ command: 'node -e ""'
64
+ }
65
+ },
66
+ // Format before linting so any fixable formatting issues (eg line too
67
+ // long) are resolved first, mirroring the Python project generator.
68
+ dependsOn: [
69
+ 'format'
70
+ ]
59
71
  }
60
- } : {
61
- executor: 'nx:noop'
62
72
  };
63
- updateProjectConfiguration(tree, options.fullyQualifiedName, {
64
- ...projectJson,
65
- // Sort targets so the lint and format targets land in deterministic
66
- // positions regardless of whether they already existed (keeps re-runs
67
- // stable)
68
- targets: sortObjectKeys({
69
- ...projectJson?.targets,
70
- format: formatTarget,
71
- lint: lintTarget
72
- })
73
- });
74
- // Register the `biome` named input so lint targets are cache-invalidated when
75
- // the root biome.json changes.
73
+ };
74
+ /**
75
+ * Register the `biome` named input so lint targets are cache-invalidated when
76
+ * the root biome.json changes.
77
+ */ export const registerBiomeNamedInput = (tree)=>{
76
78
  const nxJson = readNxJson(tree);
77
79
  if (!nxJson.namedInputs?.biome || !nxJson.namedInputs.biome.includes('{workspaceRoot}/biome.json')) {
78
80
  updateNxJson(tree, {
@@ -87,5 +89,19 @@ export const configureBiomeLint = async (tree, options)=>{
87
89
  });
88
90
  }
89
91
  };
92
+ export const configureBiomeLint = async (tree, options)=>{
93
+ const projectJson = readProjectConfigurationUnqualified(tree, options.fullyQualifiedName);
94
+ updateProjectConfiguration(tree, options.fullyQualifiedName, {
95
+ ...projectJson,
96
+ // Sort targets so the lint and format targets land in deterministic
97
+ // positions regardless of whether they already existed (keeps re-runs
98
+ // stable)
99
+ targets: sortObjectKeys({
100
+ ...projectJson?.targets,
101
+ ...biomeTargets(tree)
102
+ })
103
+ });
104
+ registerBiomeNamedInput(tree);
105
+ };
90
106
 
91
107
  //# sourceMappingURL=biome.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/biome.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n readNxJson,\n type Tree,\n updateNxJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { readProjectConfigurationUnqualified } from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport type { ConfigureProjectOptions } from './types.js';\n\nexport const configureBiomeLint = async (\n tree: Tree,\n options: ConfigureProjectOptions,\n) => {\n const projectJson = readProjectConfigurationUnqualified(\n tree,\n options.fullyQualifiedName,\n );\n\n const biomeConfigured = tree.exists('biome.json');\n\n // When there's no root Biome configuration (eg the user removed it), make the\n // lint target a no-op rather than failing on a missing config.\n const lintTarget = biomeConfigured\n ? {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['biome'],\n options: {\n command: 'biome lint {projectRoot}',\n },\n configurations: {\n fix: {\n command: 'biome check --write {projectRoot}',\n },\n 'skip-lint': {\n // Cross-platform no-op (`true` is not available on Windows cmd).\n command: 'node -e \"\"',\n },\n },\n // Format before linting so any fixable formatting issues (eg line too\n // long) are resolved first, mirroring the Python project generator.\n dependsOn: ['format'],\n }\n : { executor: 'nx:noop' };\n\n // The base format target checks formatting (failing when files aren't\n // formatted); the `fix` configuration writes the changes. `skip-lint` is a\n // no-op so `nx lint --configuration=skip-lint` propagates cleanly through the\n // lint -> format dependency edge.\n const formatTarget = biomeConfigured\n ? {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['biome'],\n options: {\n command: 'biome format {projectRoot}',\n },\n configurations: {\n fix: {\n command: 'biome format --write {projectRoot}',\n },\n 'skip-lint': {\n // Cross-platform no-op (`true` is not available on Windows cmd).\n command: 'node -e \"\"',\n },\n },\n }\n : { executor: 'nx:noop' };\n\n updateProjectConfiguration(tree, options.fullyQualifiedName, {\n ...projectJson,\n // Sort targets so the lint and format targets land in deterministic\n // positions regardless of whether they already existed (keeps re-runs\n // stable)\n targets: sortObjectKeys({\n ...projectJson?.targets,\n format: formatTarget,\n lint: lintTarget,\n }),\n });\n\n // Register the `biome` named input so lint targets are cache-invalidated when\n // the root biome.json changes.\n const nxJson = readNxJson(tree);\n if (\n !nxJson.namedInputs?.biome ||\n !nxJson.namedInputs.biome.includes('{workspaceRoot}/biome.json')\n ) {\n updateNxJson(tree, {\n ...nxJson,\n namedInputs: {\n ...nxJson.namedInputs,\n biome: ['default', '{workspaceRoot}/biome.json'],\n },\n });\n }\n};\n"],"names":["readNxJson","updateNxJson","updateProjectConfiguration","readProjectConfigurationUnqualified","sortObjectKeys","configureBiomeLint","tree","options","projectJson","fullyQualifiedName","biomeConfigured","exists","lintTarget","executor","cache","inputs","command","configurations","fix","dependsOn","formatTarget","targets","format","lint","nxJson","namedInputs","biome","includes"],"mappings":"AAAA;;;CAGC,GACD,SACEA,UAAU,EAEVC,YAAY,EACZC,0BAA0B,QACrB,aAAa;AACpB,SAASC,mCAAmC,QAAQ,oBAAoB;AACxE,SAASC,cAAc,QAAQ,wBAAwB;AAGvD,OAAO,MAAMC,qBAAqB,OAChCC,MACAC;IAEA,MAAMC,cAAcL,oCAClBG,MACAC,QAAQE,kBAAkB;IAG5B,MAAMC,kBAAkBJ,KAAKK,MAAM,CAAC;IAEpC,8EAA8E;IAC9E,+DAA+D;IAC/D,MAAMC,aAAaF,kBACf;QACEG,UAAU;QACVC,OAAO;QACPC,QAAQ;YAAC;SAAQ;QACjBR,SAAS;YACPS,SAAS;QACX;QACAC,gBAAgB;YACdC,KAAK;gBACHF,SAAS;YACX;YACA,aAAa;gBACX,iEAAiE;gBACjEA,SAAS;YACX;QACF;QACA,sEAAsE;QACtE,oEAAoE;QACpEG,WAAW;YAAC;SAAS;IACvB,IACA;QAAEN,UAAU;IAAU;IAE1B,sEAAsE;IACtE,2EAA2E;IAC3E,8EAA8E;IAC9E,kCAAkC;IAClC,MAAMO,eAAeV,kBACjB;QACEG,UAAU;QACVC,OAAO;QACPC,QAAQ;YAAC;SAAQ;QACjBR,SAAS;YACPS,SAAS;QACX;QACAC,gBAAgB;YACdC,KAAK;gBACHF,SAAS;YACX;YACA,aAAa;gBACX,iEAAiE;gBACjEA,SAAS;YACX;QACF;IACF,IACA;QAAEH,UAAU;IAAU;IAE1BX,2BAA2BI,MAAMC,QAAQE,kBAAkB,EAAE;QAC3D,GAAGD,WAAW;QACd,oEAAoE;QACpE,sEAAsE;QACtE,UAAU;QACVa,SAASjB,eAAe;YACtB,GAAGI,aAAaa,OAAO;YACvBC,QAAQF;YACRG,MAAMX;QACR;IACF;IAEA,8EAA8E;IAC9E,+BAA+B;IAC/B,MAAMY,SAASxB,WAAWM;IAC1B,IACE,CAACkB,OAAOC,WAAW,EAAEC,SACrB,CAACF,OAAOC,WAAW,CAACC,KAAK,CAACC,QAAQ,CAAC,+BACnC;QACA1B,aAAaK,MAAM;YACjB,GAAGkB,MAAM;YACTC,aAAa;gBACX,GAAGD,OAAOC,WAAW;gBACrBC,OAAO;oBAAC;oBAAW;iBAA6B;YAClD;QACF;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/biome.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n readNxJson,\n type TargetConfiguration,\n type Tree,\n updateNxJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { readProjectConfigurationUnqualified } from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport type { ConfigureProjectOptions } from './types.js';\n\n/**\n * The `format` and `lint` targets every Biome-linted project gets, so a project\n * that isn't scaffolded by `ts#project` (e.g. an AgentCore Gateway hosting only\n * `local-dev.ts`) is linted identically rather than by its own copy.\n *\n * When there's no root Biome configuration (eg the user removed it), the targets\n * are no-ops rather than failing on a missing config.\n */\nexport const biomeTargets = (\n tree: Tree,\n): Record<'format' | 'lint', TargetConfiguration> => {\n if (!tree.exists('biome.json')) {\n return { format: { executor: 'nx:noop' }, lint: { executor: 'nx:noop' } };\n }\n return {\n // The base format target checks formatting (failing when files aren't\n // formatted); the `fix` configuration writes the changes. `skip-lint` is a\n // no-op so `nx lint --configuration=skip-lint` propagates cleanly through\n // the lint -> format dependency edge.\n format: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['biome'],\n options: {\n command: 'biome format {projectRoot}',\n },\n configurations: {\n fix: {\n command: 'biome format --write {projectRoot}',\n },\n 'skip-lint': {\n // Cross-platform no-op (`true` is not available on Windows cmd).\n command: 'node -e \"\"',\n },\n },\n },\n lint: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: ['biome'],\n options: {\n command: 'biome lint {projectRoot}',\n },\n configurations: {\n fix: {\n command: 'biome check --write {projectRoot}',\n },\n 'skip-lint': {\n command: 'node -e \"\"',\n },\n },\n // Format before linting so any fixable formatting issues (eg line too\n // long) are resolved first, mirroring the Python project generator.\n dependsOn: ['format'],\n },\n };\n};\n\n/**\n * Register the `biome` named input so lint targets are cache-invalidated when\n * the root biome.json changes.\n */\nexport const registerBiomeNamedInput = (tree: Tree): void => {\n const nxJson = readNxJson(tree);\n if (\n !nxJson.namedInputs?.biome ||\n !nxJson.namedInputs.biome.includes('{workspaceRoot}/biome.json')\n ) {\n updateNxJson(tree, {\n ...nxJson,\n namedInputs: {\n ...nxJson.namedInputs,\n biome: ['default', '{workspaceRoot}/biome.json'],\n },\n });\n }\n};\n\nexport const configureBiomeLint = async (\n tree: Tree,\n options: ConfigureProjectOptions,\n) => {\n const projectJson = readProjectConfigurationUnqualified(\n tree,\n options.fullyQualifiedName,\n );\n\n updateProjectConfiguration(tree, options.fullyQualifiedName, {\n ...projectJson,\n // Sort targets so the lint and format targets land in deterministic\n // positions regardless of whether they already existed (keeps re-runs\n // stable)\n targets: sortObjectKeys({\n ...projectJson?.targets,\n ...biomeTargets(tree),\n }),\n });\n\n registerBiomeNamedInput(tree);\n};\n"],"names":["readNxJson","updateNxJson","updateProjectConfiguration","readProjectConfigurationUnqualified","sortObjectKeys","biomeTargets","tree","exists","format","executor","lint","cache","inputs","options","command","configurations","fix","dependsOn","registerBiomeNamedInput","nxJson","namedInputs","biome","includes","configureBiomeLint","projectJson","fullyQualifiedName","targets"],"mappings":"AAAA;;;CAGC,GACD,SACEA,UAAU,EAGVC,YAAY,EACZC,0BAA0B,QACrB,aAAa;AACpB,SAASC,mCAAmC,QAAQ,oBAAoB;AACxE,SAASC,cAAc,QAAQ,wBAAwB;AAGvD;;;;;;;CAOC,GACD,OAAO,MAAMC,eAAe,CAC1BC;IAEA,IAAI,CAACA,KAAKC,MAAM,CAAC,eAAe;QAC9B,OAAO;YAAEC,QAAQ;gBAAEC,UAAU;YAAU;YAAGC,MAAM;gBAAED,UAAU;YAAU;QAAE;IAC1E;IACA,OAAO;QACL,sEAAsE;QACtE,2EAA2E;QAC3E,0EAA0E;QAC1E,sCAAsC;QACtCD,QAAQ;YACNC,UAAU;YACVE,OAAO;YACPC,QAAQ;gBAAC;aAAQ;YACjBC,SAAS;gBACPC,SAAS;YACX;YACAC,gBAAgB;gBACdC,KAAK;oBACHF,SAAS;gBACX;gBACA,aAAa;oBACX,iEAAiE;oBACjEA,SAAS;gBACX;YACF;QACF;QACAJ,MAAM;YACJD,UAAU;YACVE,OAAO;YACPC,QAAQ;gBAAC;aAAQ;YACjBC,SAAS;gBACPC,SAAS;YACX;YACAC,gBAAgB;gBACdC,KAAK;oBACHF,SAAS;gBACX;gBACA,aAAa;oBACXA,SAAS;gBACX;YACF;YACA,sEAAsE;YACtE,oEAAoE;YACpEG,WAAW;gBAAC;aAAS;QACvB;IACF;AACF,EAAE;AAEF;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACZ;IACtC,MAAMa,SAASnB,WAAWM;IAC1B,IACE,CAACa,OAAOC,WAAW,EAAEC,SACrB,CAACF,OAAOC,WAAW,CAACC,KAAK,CAACC,QAAQ,CAAC,+BACnC;QACArB,aAAaK,MAAM;YACjB,GAAGa,MAAM;YACTC,aAAa;gBACX,GAAGD,OAAOC,WAAW;gBACrBC,OAAO;oBAAC;oBAAW;iBAA6B;YAClD;QACF;IACF;AACF,EAAE;AAEF,OAAO,MAAME,qBAAqB,OAChCjB,MACAO;IAEA,MAAMW,cAAcrB,oCAClBG,MACAO,QAAQY,kBAAkB;IAG5BvB,2BAA2BI,MAAMO,QAAQY,kBAAkB,EAAE;QAC3D,GAAGD,WAAW;QACd,oEAAoE;QACpE,sEAAsE;QACtE,UAAU;QACVE,SAAStB,eAAe;YACtB,GAAGoB,aAAaE,OAAO;YACvB,GAAGrB,aAAaC,KAAK;QACvB;IACF;IAEAY,wBAAwBZ;AAC1B,EAAE"}
@@ -11,6 +11,19 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies.js"
11
11
  readonly name: "vitest";
12
12
  }, {
13
13
  readonly name: "@vitest/coverage-v8";
14
+ }, {
15
+ readonly name: "jsdom";
16
+ }, {
17
+ readonly name: "@nx/vitest";
18
+ readonly dev: true;
19
+ readonly root: true;
20
+ }, {
21
+ readonly name: "@types/node";
22
+ readonly dev: true;
23
+ }, {
24
+ readonly name: "@types/node";
25
+ readonly dev: true;
26
+ readonly root: true;
14
27
  }], readonly import("../../utils/declared-dependencies.js").DeclaredPyDependency<"ruff" | "a2a-sdk" | "ag-ui-langgraph" | "ag-ui-protocol" | "ag-ui-strands" | "aiosqlite" | "aws-lambda-powertools" | "aws-lambda-powertools[tracer]" | "aws-lambda-powertools[parser]" | "aws-opentelemetry-distro" | "bedrock-agentcore" | "boto3" | "checkov" | "fastapi" | "fastapi[standard]" | "httpx" | "langchain" | "langchain-aws" | "langchain-mcp-adapters" | "langgraph" | "langgraph-checkpoint-aws" | "langgraph-checkpoint-sqlite" | "mcp" | "pip-check-updates" | "pip-licenses" | "strands-agents" | "strands-agents[a2a]" | "strands-agents-tools" | "ty" | "pynamodb" | "uvicorn" | "sqlmodel" | "alembic" | "aiomysql" | "asyncpg" | "greenlet", Record<string, never>>[]>;
15
28
  export declare const TS_LIB_GENERATOR_INFO: NxGeneratorInfo;
16
29
  /**
@@ -10,14 +10,15 @@ import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
10
10
  import { isEsmWorkspace } from "../../utils/module-format.js";
11
11
  import { toKebabCase } from "../../utils/names.js";
12
12
  import { getNpmScopePrefix } from "../../utils/npm-scope.js";
13
- import { addGeneratorMetadata, getGeneratorInfo, mergeTargetDefault, projectExists } from "../../utils/nx.js";
13
+ import { addGeneratorMetadata, getGeneratorInfo, mergeTarget, mergeTargetDefault, projectExists } from "../../utils/nx.js";
14
14
  import { sortObjectKeys } from "../../utils/object.js";
15
15
  import { getPackageManagerDisplayCommands } from "../../utils/pkg-manager.js";
16
- import { configureTsProject } from "./ts-project-utils.js";
16
+ import { configureTsProject, TS_PROJECT_DEPENDENCIES } from "./ts-project-utils.js";
17
17
  import { VITEST_DEPENDENCIES } from "./vitest.js";
18
18
  export const DEPENDENCIES = declareDependencies()({
19
19
  ts: [
20
- ...VITEST_DEPENDENCIES
20
+ ...VITEST_DEPENDENCIES,
21
+ ...TS_PROJECT_DEPENDENCIES
21
22
  ]
22
23
  });
23
24
  export const TS_LIB_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
@@ -96,7 +97,11 @@ const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [
96
97
  }, DEPENDENCIES);
97
98
  const projectConfiguration = readProjectConfiguration(tree, fullyQualifiedName);
98
99
  const targets = projectConfiguration.targets;
99
- targets['compile'] = {
100
+ // Merged rather than assigned so a re-run converges this generator's own
101
+ // configuration without discarding what other generators contributed to the
102
+ // same targets — the `bundle` that ts#lambda-function adds to build and
103
+ // assemble, say, which those targets must keep depending on.
104
+ targets['compile'] = mergeTarget(targets['compile'], {
100
105
  executor: 'nx:run-commands',
101
106
  outputs: [
102
107
  '{workspaceRoot}/dist/{projectRoot}/tsc'
@@ -105,20 +110,20 @@ const VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [
105
110
  command: 'tsc --build tsconfig.lib.json',
106
111
  cwd: '{projectRoot}'
107
112
  }
108
- };
109
- targets['build'] = {
113
+ });
114
+ targets['build'] = mergeTarget(targets['build'], {
110
115
  dependsOn: [
111
116
  'lint',
112
117
  'compile',
113
118
  'test'
114
119
  ]
115
- };
120
+ });
116
121
  // The artifact-only sibling of build, which the deploy targets depend on.
117
- targets['assemble'] = {
122
+ targets['assemble'] = mergeTarget(targets['assemble'], {
118
123
  dependsOn: [
119
124
  'compile'
120
125
  ]
121
- };
126
+ });
122
127
  projectConfiguration.targets = sortObjectKeys(targets);
123
128
  updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);
124
129
  addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);
@@ -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 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 { configureTsProject } from './ts-project-utils.js';\nimport { VITEST_DEPENDENCIES } from './vitest.js';\n\nexport const DEPENDENCIES = declareDependencies()({\n ts: [...VITEST_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 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'] = {\n dependsOn: ['lint', 'compile', 'test'],\n };\n // The artifact-only sibling of build, which the deploy targets depend on.\n 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","mergeTargetDefault","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","configureTsProject","VITEST_DEPENDENCIES","DEPENDENCIES","ts","TS_LIB_GENERATOR_INFO","filename","DEPENDENT_TASKS_OUTPUT_FILES_INPUT","dependentTasksOutputFiles","transitive","VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS","getTsLibDetails","tree","schema","scope","normalizedName","name","fullyQualifiedName","dir","directory","subDirectory","tsProjectGenerator","esm","skipPackageJson","bundler","linter","unitTestRunner","addPlugin","delete","dirname","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","projectConfiguration","targets","executor","outputs","options","command","cwd","dependsOn","nxJson","namedInputs","default","filter","input","includes","withDefaultInput","base","inputs","i","targetDefaults","compile","cache","build","test","plugins","plugin","typecheck","targetName","configName","buildDepsName","watchDepsName","p","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EAEjBC,iBAAiB,EACjBC,wBAAwB,EAGxBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SACEC,oBAAoB,EACpBC,gBAAgB,EAChBC,kBAAkB,EAElBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,gCAAgC,QAAQ,6BAA6B;AAE9E,SAASC,kBAAkB,QAAQ,wBAAwB;AAC3D,SAASC,mBAAmB,QAAQ,cAAc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AASxD,mBAAmB6C,OAAOU,cAAc,EAAEC,SAAS,CAACJ,OAAU,CAAA;oBACrEK,OAAO;oBACP,GAAGN,iBAAiBC,KAAK;gBAC3B,CAAA;YACAM,OAAO1D,mBAAmB6C,OAAOU,cAAc,EAAEG,OAAO,CAACN,OAAU,CAAA;oBACjEK,OAAO;oBACP,GAAGN,iBAAiBC,KAAK;gBAC3B,CAAA;YACAO,MAAM3D,mBAAmB6C,OAAOU,cAAc,EAAEI,MAAMR;QACxD;QAEA,8EAA8E;QAC9EN,OAAOe,OAAO,GAAG;YACf;gBACEC,QAAQ;gBACRpB,SAAS;oBACPqB,WAAW;wBACTC,YAAY;oBACd;oBACAL,OAAO;wBACLK,YAAY;wBACZC,YAAY;wBACZC,eAAe;wBACfC,eAAe;oBACjB;gBACF;YACF;eACG,AAACrB,CAAAA,OAAOe,OAAO,IAAI,EAAE,AAAD,EAAGZ,MAAM,CAC9B,CAACmB,IAAM,OAAOA,MAAM,YAAYA,EAAEN,MAAM,KAAK;SAEhD;QAED,OAAOhB;IACT;IAEA,MAAMnD,gCAAgCqB,MAAM;QAACP;KAAsB;IAEnE,MAAMhB,qBAAqBuB;IAE3B,mFAAmF;IACnF,uEAAuE;IACvE,8EAA8E;IAC9E,OAAO,IACLtB,oBAAoBsB,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. `reports/` and `coverage/` hold\n * pytest's JUnit and coverage XML, which carry a wall-clock timestamp and so\n * mint a fresh hash on every test run that would cascade through the graph.\n */\nexport const DEPENDENT_TASKS_OUTPUT_FILES_INPUT = {\n dependentTasksOutputFiles: '!{reports,coverage}/**',\n transitive: true,\n};\n\n// Globs this generator has vended for the dependent-task-output input. Any of\n// them is replaced in place, so the entry is neither duplicated nor left at a\n// different scope when a generator re-runs.\nconst VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS = [\n '**/*',\n 'dist/**',\n DEPENDENT_TASKS_OUTPUT_FILES_INPUT.dependentTasksOutputFiles,\n];\n\nexport interface TsLibDetails {\n /**\n * Full package name including scope (eg @foo/bar)\n */\n readonly fullyQualifiedName: string;\n /**\n * Directory of the library relative to the root\n */\n readonly dir: string;\n}\n\n/**\n * Returns details about the TS library to be created\n */\nexport const getTsLibDetails = (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): TsLibDetails => {\n const scope = getNpmScopePrefix(tree);\n const normalizedName = toKebabCase(schema.name);\n const fullyQualifiedName = `${scope}${normalizedName}`;\n // NB: interactive nx generator cli can pass empty string\n const dir = joinPathFragments(\n schema.directory || '.',\n schema.subDirectory || normalizedName,\n );\n return { dir, fullyQualifiedName };\n};\n\n/**\n * Generates a typescript project\n */\nexport const tsProjectGenerator = async (\n tree: Tree,\n schema: TsProjectGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const { fullyQualifiedName, dir } = getTsLibDetails(tree, schema);\n // The module format is workspace-wide, established by the preset when the\n // workspace is created, so vending generators always infer it from the tree.\n const esm = isEsmWorkspace(tree);\n\n // Only scaffold the project on first run; on re-run skip creation so user\n // edits are preserved, but continue to (re)apply the configuration below.\n if (!projectExists(tree, fullyQualifiedName)) {\n await libraryGenerator(tree, {\n ...schema,\n name: fullyQualifiedName,\n directory: dir,\n skipPackageJson: true,\n bundler: 'tsc', // TODO: consider supporting others\n linter: 'none',\n unitTestRunner: 'vitest',\n // Register the @nx/vitest plugin so the test target is inferred rather\n // than emitting the deprecated @nx/vitest:test executor target.\n addPlugin: true,\n });\n\n // Replace with simpler sample source code\n tree.delete(joinPathFragments(dir, 'src'));\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n joinPathFragments(dir),\n {\n fullyQualifiedName,\n esm,\n pkgMgrCmd: getPackageManagerDisplayCommands().exec,\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n }\n await configureTsProject(\n tree,\n {\n dir,\n fullyQualifiedName,\n esm,\n },\n DEPENDENCIES,\n );\n\n const projectConfiguration = readProjectConfiguration(\n tree,\n fullyQualifiedName,\n );\n const targets = projectConfiguration.targets;\n\n // Merged rather than assigned so a re-run converges this generator's own\n // configuration without discarding what other generators contributed to the\n // same targets — the `bundle` that ts#lambda-function adds to build and\n // assemble, say, which those targets must keep depending on.\n targets['compile'] = mergeTarget(targets['compile'], {\n executor: 'nx:run-commands',\n outputs: ['{workspaceRoot}/dist/{projectRoot}/tsc'],\n options: {\n command: 'tsc --build tsconfig.lib.json',\n cwd: '{projectRoot}',\n },\n });\n targets['build'] = mergeTarget(targets['build'], {\n dependsOn: ['lint', 'compile', 'test'],\n });\n // The artifact-only sibling of build, which the deploy targets depend on.\n targets['assemble'] = mergeTarget(targets['assemble'], {\n dependsOn: ['compile'],\n });\n projectConfiguration.targets = sortObjectKeys(targets);\n\n updateProjectConfiguration(tree, fullyQualifiedName, projectConfiguration);\n\n addGeneratorMetadata(tree, fullyQualifiedName, TS_LIB_GENERATOR_INFO);\n\n updateJson(tree, 'nx.json', (nxJson: NxJsonConfiguration) => {\n nxJson.namedInputs = {\n ...nxJson.namedInputs,\n default: [\n ...(nxJson.namedInputs?.default ?? []).filter(\n (input) =>\n typeof input !== 'object' ||\n !('dependentTasksOutputFiles' in input) ||\n !(\n VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS.includes(\n input.dependentTasksOutputFiles as string,\n ) && input.transitive\n ),\n ),\n DEPENDENT_TASKS_OUTPUT_FILES_INPUT,\n ],\n };\n\n const withDefaultInput = (base: Partial<TargetConfiguration>) => ({\n ...base,\n inputs: [\n ...(base.inputs ?? []).filter((i) => i !== 'default'),\n 'default',\n ],\n });\n\n nxJson.targetDefaults = {\n ...nxJson.targetDefaults,\n compile: mergeTargetDefault(nxJson.targetDefaults?.compile, (base) => ({\n cache: true,\n ...withDefaultInput(base),\n })),\n build: mergeTargetDefault(nxJson.targetDefaults?.build, (base) => ({\n cache: true,\n ...withDefaultInput(base),\n })),\n test: mergeTargetDefault(nxJson.targetDefaults?.test, withDefaultInput),\n };\n\n // Ensure we only declare a single typescript plugin with the correct settings\n nxJson.plugins = [\n {\n plugin: '@nx/js/typescript',\n options: {\n typecheck: {\n targetName: 'typecheck',\n },\n build: {\n targetName: 'compile',\n configName: 'tsconfig.lib.json',\n buildDepsName: 'build-deps',\n watchDepsName: 'watch-deps',\n },\n },\n },\n ...(nxJson.plugins ?? []).filter(\n (p) => typeof p === 'string' || p.plugin !== '@nx/js/typescript',\n ),\n ];\n\n return nxJson;\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_LIB_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n\n // `installDependencies` ensures vitest resolves for the `typescript` language (the\n // generated vitest.config.mts imports it and Nx loads that config when\n // computing the project graph), so a deferred install still runs when needed.\n return () =>\n installDependencies(tree, schema.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\nexport default tsProjectGenerator;\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","readProjectConfiguration","updateJson","updateProjectConfiguration","libraryGenerator","declareDependencies","formatFilesInSubtree","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","toKebabCase","getNpmScopePrefix","addGeneratorMetadata","getGeneratorInfo","mergeTarget","mergeTargetDefault","projectExists","sortObjectKeys","getPackageManagerDisplayCommands","configureTsProject","TS_PROJECT_DEPENDENCIES","VITEST_DEPENDENCIES","DEPENDENCIES","ts","TS_LIB_GENERATOR_INFO","filename","DEPENDENT_TASKS_OUTPUT_FILES_INPUT","dependentTasksOutputFiles","transitive","VENDED_DEPENDENT_TASKS_OUTPUT_GLOBS","getTsLibDetails","tree","schema","scope","normalizedName","name","fullyQualifiedName","dir","directory","subDirectory","tsProjectGenerator","esm","skipPackageJson","bundler","linter","unitTestRunner","addPlugin","delete","dirname","pkgMgrCmd","exec","overwriteStrategy","KeepExisting","projectConfiguration","targets","executor","outputs","options","command","cwd","dependsOn","nxJson","namedInputs","default","filter","input","includes","withDefaultInput","base","inputs","i","targetDefaults","compile","cache","build","test","plugins","plugin","typecheck","targetName","configName","buildDepsName","watchDepsName","p","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SAEEA,aAAa,EACbC,iBAAiB,EAEjBC,iBAAiB,EACjBC,wBAAwB,EAGxBC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,mBAAmB,QAAQ,uCAAuC;AAC3E,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,WAAW,QAAQ,uBAAuB;AACnD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SACEC,oBAAoB,EACpBC,gBAAgB,EAChBC,WAAW,EACXC,kBAAkB,EAElBC,aAAa,QACR,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,wBAAwB;AACvD,SAASC,gCAAgC,QAAQ,6BAA6B;AAE9E,SACEC,kBAAkB,EAClBC,uBAAuB,QAClB,wBAAwB;AAC/B,SAASC,mBAAmB,QAAQ,cAAc;AAElD,OAAO,MAAMC,eAAejB,sBAAsB;IAChDkB,IAAI;WAAIF;WAAwBD;KAAwB;AAC1D,GAAG;AAEH,OAAO,MAAMI,wBAAyCX,iBACpD,YAAYY,QAAQ,EACpB;AAEF;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,qCAAqC;IAChDC,2BAA2B;IAC3BC,YAAY;AACd,EAAE;AAEF,8EAA8E;AAC9E,8EAA8E;AAC9E,4CAA4C;AAC5C,MAAMC,sCAAsC;IAC1C;IACA;IACAH,mCAAmCC,yBAAyB;CAC7D;AAaD;;CAEC,GACD,OAAO,MAAMG,kBAAkB,CAC7BC,MACAC;IAEA,MAAMC,QAAQtB,kBAAkBoB;IAChC,MAAMG,iBAAiBxB,YAAYsB,OAAOG,IAAI;IAC9C,MAAMC,qBAAqB,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,OAAOe,OAAO,GAAG;YACf;gBACEC,QAAQ;gBACRpB,SAAS;oBACPqB,WAAW;wBACTC,YAAY;oBACd;oBACAL,OAAO;wBACLK,YAAY;wBACZC,YAAY;wBACZC,eAAe;wBACfC,eAAe;oBACjB;gBACF;YACF;eACG,AAACrB,CAAAA,OAAOe,OAAO,IAAI,EAAE,AAAD,EAAGZ,MAAM,CAC9B,CAACmB,IAAM,OAAOA,MAAM,YAAYA,EAAEN,MAAM,KAAK;SAEhD;QAED,OAAOhB;IACT;IAEA,MAAMrD,gCAAgCuB,MAAM;QAACP;KAAsB;IAEnE,MAAMlB,qBAAqByB;IAE3B,mFAAmF;IACnF,uEAAuE;IACvE,8EAA8E;IAC9E,OAAO,IACLxB,oBAAoBwB,MAAMC,OAAOoD,yBAAyB,EAAE;YAC1DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AACF,eAAe7C,mBAAmB"}
@@ -9,14 +9,44 @@ import { type VITEST_DEPENDENCIES } from './vitest.js';
9
9
  interface TsConfigReference {
10
10
  path: string;
11
11
  }
12
+ /**
13
+ * Dependencies a caller must declare to configure a TypeScript project.
14
+ *
15
+ * `@nx/js` writes `types: ['node']` into every project's `tsconfig.lib.json`, so
16
+ * the types must be declared for `tsc` to resolve them. Declared twice: on the
17
+ * project whose tsconfig names them, and at the root, which `@nx/js` seeded until
18
+ * Nx 23.2 stopped.
19
+ */
20
+ export declare const TS_PROJECT_DEPENDENCIES: readonly [{
21
+ readonly name: "@types/node";
22
+ readonly dev: true;
23
+ }, {
24
+ readonly name: "@types/node";
25
+ readonly dev: true;
26
+ readonly root: true;
27
+ }];
12
28
  /**
13
29
  * Merges new TypeScript project references into existing ones, deduplicating by
14
30
  * path and preserving the order of existing references so re-running a
15
31
  * generator neither duplicates nor reorders references.
16
32
  */
17
33
  export declare const mergeTsReferences: (existing: TsConfigReference[] | undefined, toAdd: TsConfigReference[]) => TsConfigReference[];
34
+ /**
35
+ * Merges a reference to another project's directory into existing TypeScript
36
+ * project references, treating any reference that resolves inside that
37
+ * directory as the same reference.
38
+ *
39
+ * `nx sync` rewrites a reference to a project's `tsconfig.json` into the
40
+ * specific `tsconfig.lib.json` it resolves to, so matching on the exact path
41
+ * alone would append a second reference to the same project on every re-run —
42
+ * which leaves the workspace out of sync and fails the next `build`.
43
+ *
44
+ * `projectDirRef` is the referenced project's directory, relative to the
45
+ * tsconfig being updated (eg `../common/shadcn`).
46
+ */
47
+ export declare const mergeTsProjectDirReference: (existing: TsConfigReference[] | undefined, projectDirRef: string) => TsConfigReference[];
18
48
  /**
19
49
  * Updates typescript projects
20
50
  */
21
- export declare const configureTsProject: <const D extends DependencyDeclaration>(tree: Tree, options: ConfigureProjectOptions, declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>) => Promise<void>;
51
+ export declare const configureTsProject: <const D extends DependencyDeclaration>(tree: Tree, options: ConfigureProjectOptions, declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D> & MustDeclare<typeof TS_PROJECT_DEPENDENCIES, D>) => Promise<void>;
22
52
  export {};
@@ -4,12 +4,31 @@
4
4
  */ import { joinPathFragments, logger, updateJson } from "@nx/devkit";
5
5
  import { join, relative } from "path";
6
6
  import { addLicenseCheckToLintTarget } from "../../license/config.js";
7
+ import { addTsDependencies } from "../../utils/add-dependencies.js";
7
8
  import { AWS_NX_PLUGIN_CONFIG_FILE_NAME } from "../../utils/config/utils.js";
8
9
  import { forDependencies } from "../../utils/declared-dependencies.js";
9
10
  import { isEsmWorkspace } from "../../utils/module-format.js";
10
11
  import { ensureProjectPackageJson } from "../../utils/project-package-json.js";
11
12
  import { configureBiomeLint } from "./biome.js";
12
13
  import { configureVitest } from "./vitest.js";
14
+ /**
15
+ * Dependencies a caller must declare to configure a TypeScript project.
16
+ *
17
+ * `@nx/js` writes `types: ['node']` into every project's `tsconfig.lib.json`, so
18
+ * the types must be declared for `tsc` to resolve them. Declared twice: on the
19
+ * project whose tsconfig names them, and at the root, which `@nx/js` seeded until
20
+ * Nx 23.2 stopped.
21
+ */ export const TS_PROJECT_DEPENDENCIES = [
22
+ {
23
+ name: '@types/node',
24
+ dev: true
25
+ },
26
+ {
27
+ name: '@types/node',
28
+ dev: true,
29
+ root: true
30
+ }
31
+ ];
13
32
  /**
14
33
  * Merges new TypeScript project references into existing ones, deduplicating by
15
34
  * path and preserving the order of existing references so re-running a
@@ -27,6 +46,30 @@ import { configureVitest } from "./vitest.js";
27
46
  }
28
47
  return references;
29
48
  };
49
+ /**
50
+ * Merges a reference to another project's directory into existing TypeScript
51
+ * project references, treating any reference that resolves inside that
52
+ * directory as the same reference.
53
+ *
54
+ * `nx sync` rewrites a reference to a project's `tsconfig.json` into the
55
+ * specific `tsconfig.lib.json` it resolves to, so matching on the exact path
56
+ * alone would append a second reference to the same project on every re-run —
57
+ * which leaves the workspace out of sync and fails the next `build`.
58
+ *
59
+ * `projectDirRef` is the referenced project's directory, relative to the
60
+ * tsconfig being updated (eg `../common/shadcn`).
61
+ */ export const mergeTsProjectDirReference = (existing, projectDirRef)=>{
62
+ const references = [
63
+ ...existing ?? []
64
+ ];
65
+ const alreadyReferenced = references.some((ref)=>ref.path === projectDirRef || ref.path.startsWith(`${projectDirRef}/tsconfig`));
66
+ return alreadyReferenced ? references : [
67
+ ...references,
68
+ {
69
+ path: `${projectDirRef}/tsconfig.json`
70
+ }
71
+ ];
72
+ };
30
73
  /**
31
74
  * Updates typescript projects
32
75
  */ export const configureTsProject = async (tree, options, declaration)=>{
@@ -104,6 +147,16 @@ import { configureVitest } from "./vitest.js";
104
147
  fullyQualifiedName: options.fullyQualifiedName,
105
148
  esm
106
149
  });
150
+ // From this helper's constant, not the caller's declaration, which marks these
151
+ // `ownedElsewhere` because the install happens here.
152
+ addTsDependencies(tree, {
153
+ ts: [
154
+ ...TS_PROJECT_DEPENDENCIES
155
+ ],
156
+ py: []
157
+ }, {
158
+ projectRoot: options.dir
159
+ });
107
160
  await configureBiomeLint(tree, options);
108
161
  await configureVitest(tree, options, forDependencies(declaration));
109
162
  // If license checking is configured, make this project's lint target depend
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/ts-project-utils.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, logger, type Tree, updateJson } from '@nx/devkit';\nimport { join, relative } from 'path';\nimport { addLicenseCheckToLintTarget } from '../../license/config.js';\nimport { AWS_NX_PLUGIN_CONFIG_FILE_NAME } from '../../utils/config/utils.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../utils/declared-dependencies.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { ensureProjectPackageJson } from '../../utils/project-package-json.js';\nimport { configureBiomeLint } from './biome.js';\nimport type { ConfigureProjectOptions } from './types.js';\nimport { configureVitest, type VITEST_DEPENDENCIES } from './vitest.js';\n\ninterface TsConfigReference {\n path: string;\n}\n\n/**\n * Merges new TypeScript project references into existing ones, deduplicating by\n * path and preserving the order of existing references so re-running a\n * generator neither duplicates nor reorders references.\n */\nexport const mergeTsReferences = (\n existing: TsConfigReference[] | undefined,\n toAdd: TsConfigReference[],\n): TsConfigReference[] => {\n const references = [...(existing ?? [])];\n const existingPaths = new Set(references.map((ref) => ref.path));\n for (const ref of toAdd) {\n if (!existingPaths.has(ref.path)) {\n references.push(ref);\n existingPaths.add(ref.path);\n }\n }\n return references;\n};\n\n/**\n * Updates typescript projects\n */\nexport const configureTsProject = async <const D extends DependencyDeclaration>(\n tree: Tree,\n options: ConfigureProjectOptions,\n declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>,\n) => {\n // Point users at init when the workspace hasn't been configured, since\n // lint/format targets and workspace dependency sync depend on it.\n if (!tree.exists(AWS_NX_PLUGIN_CONFIG_FILE_NAME)) {\n logger.warn(\n `This workspace has no ${AWS_NX_PLUGIN_CONFIG_FILE_NAME} — run 'nx g @aws/nx-plugin:init' (or 'nx add @aws/nx-plugin') to configure linting, formatting and workspace dependency sync.`,\n );\n }\n\n // When the caller doesn't specify a module format, infer it from the\n // workspace root package.json (defaulting to ESM for a fresh workspace).\n const esm = options.esm ?? isEsmWorkspace(tree);\n\n // Remove a conflicting `module: commonjs` from the project tsconfig.json\n // (CommonJS is configured on tsconfig.lib.json below when needed).\n updateJson(tree, join(options.dir, 'tsconfig.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n module:\n tsConfig.compilerOptions?.module === 'commonjs'\n ? undefined\n : tsConfig.compilerOptions?.module,\n },\n }));\n const outDirToRootRelativePath = relative(\n join(tree.root, options.dir),\n tree.root,\n );\n const distDir = join(outDirToRootRelativePath, 'dist', options.dir, 'tsc');\n // Remove baseUrl and rootDir from the tsconfig.lib.json\n if (tree.exists(join(options.dir, 'tsconfig.lib.json'))) {\n updateJson(tree, join(options.dir, 'tsconfig.lib.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n baseUrl: undefined,\n rootDir: '.',\n outDir: distDir,\n tsBuildInfoFile: join(distDir, 'tsconfig.lib.tsbuildinfo'),\n // @nx/js configures the lib for ESM (module `nodenext`). CommonJS\n // projects use `node16`, which honours the workspace's\n // `type: commonjs`, emits CommonJS and resolves extensionless relative\n // imports. (Plain `commonjs`/`node` is deprecated in TypeScript 6.)\n ...(esm ? {} : { module: 'node16', moduleResolution: 'node16' }),\n },\n }));\n }\n // Update root project tsconfig\n updateJson(tree, 'tsconfig.base.json', (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n // baseUrl is deprecated in TypeScript 6 — use ./ prefix in paths instead\n baseUrl: undefined,\n rootDir: '.',\n paths: {\n ...tsConfig.compilerOptions?.paths,\n [options.fullyQualifiedName]: [\n `./${joinPathFragments(options.dir, 'src', 'index.ts')}`,\n ],\n },\n },\n }));\n if (tree.exists('tsconfig.json')) {\n updateJson(tree, 'tsconfig.json', (tsConfig) => ({\n ...tsConfig,\n // Add project references, deduplicating and preserving existing order\n references: mergeTsReferences(tsConfig.references, [\n { path: `./${options.dir}` },\n ]),\n }));\n }\n // Every project carries a minimal private package.json so the workspace\n // follows the standard npm package layout (see ensureProjectPackageJson).\n ensureProjectPackageJson(tree, {\n dir: options.dir,\n fullyQualifiedName: options.fullyQualifiedName,\n esm,\n });\n\n await configureBiomeLint(tree, options);\n await configureVitest(\n tree,\n options,\n forDependencies<typeof VITEST_DEPENDENCIES>(declaration),\n );\n\n // If license checking is configured, make this project's lint target depend\n // on the root license-check target. No-op if there's no license-check target\n // (i.e. the license generator hasn't run); the license generator wires up\n // existing projects itself, so this works regardless of generator order.\n addLicenseCheckToLintTarget(tree, options.fullyQualifiedName);\n};\n"],"names":["joinPathFragments","logger","updateJson","join","relative","addLicenseCheckToLintTarget","AWS_NX_PLUGIN_CONFIG_FILE_NAME","forDependencies","isEsmWorkspace","ensureProjectPackageJson","configureBiomeLint","configureVitest","mergeTsReferences","existing","toAdd","references","existingPaths","Set","map","ref","path","has","push","add","configureTsProject","tree","options","declaration","exists","warn","esm","dir","tsConfig","compilerOptions","module","undefined","outDirToRootRelativePath","root","distDir","baseUrl","rootDir","outDir","tsBuildInfoFile","moduleResolution","paths","fullyQualifiedName"],"mappings":"AAAA;;;CAGC,GACD,SAASA,iBAAiB,EAAEC,MAAM,EAAaC,UAAU,QAAQ,aAAa;AAC9E,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AACtC,SAASC,2BAA2B,QAAQ,0BAA0B;AACtE,SAASC,8BAA8B,QAAQ,8BAA8B;AAC7E,SAEEC,eAAe,QAEV,uCAAuC;AAC9C,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,wBAAwB,QAAQ,sCAAsC;AAC/E,SAASC,kBAAkB,QAAQ,aAAa;AAEhD,SAASC,eAAe,QAAkC,cAAc;AAMxE;;;;CAIC,GACD,OAAO,MAAMC,oBAAoB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C9D,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/ts-project-utils.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { joinPathFragments, logger, type Tree, updateJson } from '@nx/devkit';\nimport { join, relative } from 'path';\nimport { addLicenseCheckToLintTarget } from '../../license/config.js';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport { AWS_NX_PLUGIN_CONFIG_FILE_NAME } from '../../utils/config/utils.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../utils/declared-dependencies.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { ensureProjectPackageJson } from '../../utils/project-package-json.js';\nimport type { ITsDepVersion } from '../../utils/versions.js';\nimport { configureBiomeLint } from './biome.js';\nimport type { ConfigureProjectOptions } from './types.js';\nimport { configureVitest, type VITEST_DEPENDENCIES } from './vitest.js';\n\ninterface TsConfigReference {\n path: string;\n}\n\n/**\n * Dependencies a caller must declare to configure a TypeScript project.\n *\n * `@nx/js` writes `types: ['node']` into every project's `tsconfig.lib.json`, so\n * the types must be declared for `tsc` to resolve them. Declared twice: on the\n * project whose tsconfig names them, and at the root, which `@nx/js` seeded until\n * Nx 23.2 stopped.\n */\nexport const TS_PROJECT_DEPENDENCIES = [\n { name: '@types/node', dev: true },\n { name: '@types/node', dev: true, root: true },\n] as const satisfies readonly {\n name: ITsDepVersion;\n dev?: boolean;\n root?: boolean;\n}[];\n\n/**\n * Merges new TypeScript project references into existing ones, deduplicating by\n * path and preserving the order of existing references so re-running a\n * generator neither duplicates nor reorders references.\n */\nexport const mergeTsReferences = (\n existing: TsConfigReference[] | undefined,\n toAdd: TsConfigReference[],\n): TsConfigReference[] => {\n const references = [...(existing ?? [])];\n const existingPaths = new Set(references.map((ref) => ref.path));\n for (const ref of toAdd) {\n if (!existingPaths.has(ref.path)) {\n references.push(ref);\n existingPaths.add(ref.path);\n }\n }\n return references;\n};\n\n/**\n * Merges a reference to another project's directory into existing TypeScript\n * project references, treating any reference that resolves inside that\n * directory as the same reference.\n *\n * `nx sync` rewrites a reference to a project's `tsconfig.json` into the\n * specific `tsconfig.lib.json` it resolves to, so matching on the exact path\n * alone would append a second reference to the same project on every re-run —\n * which leaves the workspace out of sync and fails the next `build`.\n *\n * `projectDirRef` is the referenced project's directory, relative to the\n * tsconfig being updated (eg `../common/shadcn`).\n */\nexport const mergeTsProjectDirReference = (\n existing: TsConfigReference[] | undefined,\n projectDirRef: string,\n): TsConfigReference[] => {\n const references = [...(existing ?? [])];\n const alreadyReferenced = references.some(\n (ref) =>\n ref.path === projectDirRef ||\n ref.path.startsWith(`${projectDirRef}/tsconfig`),\n );\n return alreadyReferenced\n ? references\n : [...references, { path: `${projectDirRef}/tsconfig.json` }];\n};\n\n/**\n * Updates typescript projects\n */\nexport const configureTsProject = async <const D extends DependencyDeclaration>(\n tree: Tree,\n options: ConfigureProjectOptions,\n declaration: D &\n MustDeclare<typeof VITEST_DEPENDENCIES, D> &\n MustDeclare<typeof TS_PROJECT_DEPENDENCIES, D>,\n) => {\n // Point users at init when the workspace hasn't been configured, since\n // lint/format targets and workspace dependency sync depend on it.\n if (!tree.exists(AWS_NX_PLUGIN_CONFIG_FILE_NAME)) {\n logger.warn(\n `This workspace has no ${AWS_NX_PLUGIN_CONFIG_FILE_NAME} — run 'nx g @aws/nx-plugin:init' (or 'nx add @aws/nx-plugin') to configure linting, formatting and workspace dependency sync.`,\n );\n }\n\n // When the caller doesn't specify a module format, infer it from the\n // workspace root package.json (defaulting to ESM for a fresh workspace).\n const esm = options.esm ?? isEsmWorkspace(tree);\n\n // Remove a conflicting `module: commonjs` from the project tsconfig.json\n // (CommonJS is configured on tsconfig.lib.json below when needed).\n updateJson(tree, join(options.dir, 'tsconfig.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n module:\n tsConfig.compilerOptions?.module === 'commonjs'\n ? undefined\n : tsConfig.compilerOptions?.module,\n },\n }));\n const outDirToRootRelativePath = relative(\n join(tree.root, options.dir),\n tree.root,\n );\n const distDir = join(outDirToRootRelativePath, 'dist', options.dir, 'tsc');\n // Remove baseUrl and rootDir from the tsconfig.lib.json\n if (tree.exists(join(options.dir, 'tsconfig.lib.json'))) {\n updateJson(tree, join(options.dir, 'tsconfig.lib.json'), (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n baseUrl: undefined,\n rootDir: '.',\n outDir: distDir,\n tsBuildInfoFile: join(distDir, 'tsconfig.lib.tsbuildinfo'),\n // @nx/js configures the lib for ESM (module `nodenext`). CommonJS\n // projects use `node16`, which honours the workspace's\n // `type: commonjs`, emits CommonJS and resolves extensionless relative\n // imports. (Plain `commonjs`/`node` is deprecated in TypeScript 6.)\n ...(esm ? {} : { module: 'node16', moduleResolution: 'node16' }),\n },\n }));\n }\n // Update root project tsconfig\n updateJson(tree, 'tsconfig.base.json', (tsConfig) => ({\n ...tsConfig,\n compilerOptions: {\n ...tsConfig.compilerOptions,\n // baseUrl is deprecated in TypeScript 6 — use ./ prefix in paths instead\n baseUrl: undefined,\n rootDir: '.',\n paths: {\n ...tsConfig.compilerOptions?.paths,\n [options.fullyQualifiedName]: [\n `./${joinPathFragments(options.dir, 'src', 'index.ts')}`,\n ],\n },\n },\n }));\n if (tree.exists('tsconfig.json')) {\n updateJson(tree, 'tsconfig.json', (tsConfig) => ({\n ...tsConfig,\n // Add project references, deduplicating and preserving existing order\n references: mergeTsReferences(tsConfig.references, [\n { path: `./${options.dir}` },\n ]),\n }));\n }\n // Every project carries a minimal private package.json so the workspace\n // follows the standard npm package layout (see ensureProjectPackageJson).\n ensureProjectPackageJson(tree, {\n dir: options.dir,\n fullyQualifiedName: options.fullyQualifiedName,\n esm,\n });\n\n // From this helper's constant, not the caller's declaration, which marks these\n // `ownedElsewhere` because the install happens here.\n addTsDependencies(\n tree,\n { ts: [...TS_PROJECT_DEPENDENCIES], py: [] },\n { projectRoot: options.dir },\n );\n\n await configureBiomeLint(tree, options);\n await configureVitest(\n tree,\n options,\n forDependencies<typeof VITEST_DEPENDENCIES>(declaration),\n );\n\n // If license checking is configured, make this project's lint target depend\n // on the root license-check target. No-op if there's no license-check target\n // (i.e. the license generator hasn't run); the license generator wires up\n // existing projects itself, so this works regardless of generator order.\n addLicenseCheckToLintTarget(tree, options.fullyQualifiedName);\n};\n"],"names":["joinPathFragments","logger","updateJson","join","relative","addLicenseCheckToLintTarget","addTsDependencies","AWS_NX_PLUGIN_CONFIG_FILE_NAME","forDependencies","isEsmWorkspace","ensureProjectPackageJson","configureBiomeLint","configureVitest","TS_PROJECT_DEPENDENCIES","name","dev","root","mergeTsReferences","existing","toAdd","references","existingPaths","Set","map","ref","path","has","push","add","mergeTsProjectDirReference","projectDirRef","alreadyReferenced","some","startsWith","configureTsProject","tree","options","declaration","exists","warn","esm","dir","tsConfig","compilerOptions","module","undefined","outDirToRootRelativePath","distDir","baseUrl","rootDir","outDir","tsBuildInfoFile","moduleResolution","paths","fullyQualifiedName","ts","py","projectRoot"],"mappings":"AAAA;;;CAGC,GACD,SAASA,iBAAiB,EAAEC,MAAM,EAAaC,UAAU,QAAQ,aAAa;AAC9E,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AACtC,SAASC,2BAA2B,QAAQ,0BAA0B;AACtE,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,8BAA8B,QAAQ,8BAA8B;AAC7E,SAEEC,eAAe,QAEV,uCAAuC;AAC9C,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,wBAAwB,QAAQ,sCAAsC;AAE/E,SAASC,kBAAkB,QAAQ,aAAa;AAEhD,SAASC,eAAe,QAAkC,cAAc;AAMxE;;;;;;;CAOC,GACD,OAAO,MAAMC,0BAA0B;IACrC;QAAEC,MAAM;QAAeC,KAAK;IAAK;IACjC;QAAED,MAAM;QAAeC,KAAK;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,SAAStB,UAAU,EAAE;oBACjD;wBAAEK,MAAM,CAAC,EAAE,EAAEW,QAAQK,GAAG,EAAE;oBAAC;iBAC5B;YACH,CAAA;IACF;IACA,wEAAwE;IACxE,0EAA0E;IAC1E/B,yBAAyByB,MAAM;QAC7BM,KAAKL,QAAQK,GAAG;QAChBa,oBAAoBlB,QAAQkB,kBAAkB;QAC9Cd;IACF;IAEA,+EAA+E;IAC/E,qDAAqD;IACrDlC,kBACE6B,MACA;QAAEoB,IAAI;eAAI1C;SAAwB;QAAE2C,IAAI,EAAE;IAAC,GAC3C;QAAEC,aAAarB,QAAQK,GAAG;IAAC;IAG7B,MAAM9B,mBAAmBwB,MAAMC;IAC/B,MAAMxB,gBACJuB,MACAC,SACA5B,gBAA4C6B;IAG9C,4EAA4E;IAC5E,6EAA6E;IAC7E,0EAA0E;IAC1E,yEAAyE;IACzEhC,4BAA4B8B,MAAMC,QAAQkB,kBAAkB;AAC9D,EAAE"}
@@ -23,5 +23,11 @@ export declare const VITEST_DEPENDENCIES: readonly [{
23
23
  readonly name: "vitest";
24
24
  }, {
25
25
  readonly name: "@vitest/coverage-v8";
26
+ }, {
27
+ readonly name: "jsdom";
28
+ }, {
29
+ readonly name: "@nx/vitest";
30
+ readonly dev: true;
31
+ readonly root: true;
26
32
  }];
27
33
  export declare const configureVitest: <const D extends DependencyDeclaration>(tree: Tree, options: ConfigureProjectOptions, declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>) => Promise<void>;
@@ -57,6 +57,19 @@ const readGritPattern = (name)=>readFileSync(join(import.meta.dirname, 'grit', `
57
57
  },
58
58
  {
59
59
  name: '@vitest/coverage-v8'
60
+ },
61
+ // `@nx/vitest` writes `environment: 'jsdom'` into the config it generates.
62
+ {
63
+ name: 'jsdom'
64
+ },
65
+ // Registered in nx.json as an inferred-target plugin, so it must resolve when
66
+ // Nx builds the project graph. `@nx/js` installed it until Nx 23.2, which now
67
+ // only reaches for it transiently while its generator runs. Like the other nx
68
+ // packages it upgrades through `packageJsonUpdates`, not the version sync.
69
+ {
70
+ name: '@nx/vitest',
71
+ dev: true,
72
+ root: true
60
73
  }
61
74
  ];
62
75
  export const configureVitest = async (tree, options, declaration)=>{
@@ -93,7 +106,9 @@ export const configureVitest = async (tree, options, declaration)=>{
93
106
  addDependenciesToPackageJson(tree, {}, withVersions(forDependencies(declaration), [
94
107
  'vite',
95
108
  'vitest',
96
- '@vitest/coverage-v8'
109
+ '@vitest/coverage-v8',
110
+ 'jsdom',
111
+ '@nx/vitest'
97
112
  ]));
98
113
  };
99
114
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/vitest.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n readNxJson,\n type Tree,\n updateNxJson,\n} from '@nx/devkit';\nimport { readFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { applyGritQL } from '../../utils/ast.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../utils/declared-dependencies.js';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies.js';\nimport { type ITsDepVersion, withVersions } from '../../utils/versions.js';\nimport type { ConfigureProjectOptions } from './types.js';\n\nconst readGritPattern = (name: string): string =>\n readFileSync(\n join(import.meta.dirname, 'grit', `${name}.grit`),\n 'utf-8',\n ).trim();\n\n/**\n * Resolve the config's `root` from `import.meta.dirname`.\n *\n * `@nx/js` writes `root: __dirname`, which Vite's native config loader does not\n * provide — it warns today and will reject once `configLoader: 'native'` becomes\n * the default. Scoped with `some` to a direct property of the object the config\n * factory returns, so a nested `root` (a `test.alias` entry, say) is untouched.\n */\nconst ROOT_IMPORT_META_DIRNAME = `\\`defineConfig(() => ({ $props }))\\` where {\n $props <: some \\`root: __dirname\\` as $root,\n $root => \\`root: import.meta.dirname\\`\n}`;\n\n/** The `reportsDirectory` `@nx/vitest` writes, resolved against the project root. */\nexport const GENERATED_REPORTS_DIRECTORY = './test-output/vitest/coverage';\n\n/**\n * The coverage directory for a project, as a path relative to the project root\n * (vitest resolves `reportsDirectory` against the config's `root`).\n *\n * Coverage lands under the workspace's `dist` rather than inside the project, so\n * the HTML reporter's vendored assets are neither formatted by the `format`\n * target nor counted as an input to the project's own tasks.\n */\nexport const getCoverageReportsDirectory = (dir: string): string =>\n joinPathFragments(\n relative(join('/', dir), '/'),\n 'dist',\n dir,\n 'test-output/vitest/coverage',\n );\n\n/**\n * Point coverage at the project's `dist` directory.\n *\n * `@nx/vitest` writes `reportsDirectory: './test-output/vitest/coverage'`, which\n * resolves inside the project. Coverage is off by default, so the directory is\n * dormant until someone runs `vitest --coverage` — at which point the HTML\n * reporter's bundled third-party scripts land in the project, where the `format`\n * target reformats them (failing the build from then on) and the `default` named\n * input counts them, so no task in the project can ever be cached again.\n *\n * Anchored to the exact literal `@nx/vitest` generates, and scoped to the\n * `coverage` block of the config's own `test` object, so a directory the user has\n * repointed is left alone.\n */\nconst coverageReportsDirectoryPattern = (dir: string): string =>\n `\\`test: { $props }\\` where {\n $props <: within \\`defineConfig($_)\\`,\n $props <: some \\`coverage: { $cov }\\`,\n $cov <: some \\`reportsDirectory: '${GENERATED_REPORTS_DIRECTORY}'\\` as $reportsDirectory,\n $reportsDirectory => \\`reportsDirectory: '${getCoverageReportsDirectory(dir)}'\\`\n}`;\n\n/** Dependencies a caller must declare to configure vitest. */\nexport const VITEST_DEPENDENCIES = [\n { name: 'vite' },\n { name: 'vitest' },\n { name: '@vitest/coverage-v8' },\n] as const satisfies readonly { name: ITsDepVersion }[];\n\nexport const configureVitest = async <const D extends DependencyDeclaration>(\n tree: Tree,\n options: ConfigureProjectOptions,\n declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>,\n) => {\n // Find vitest.config.mts or vite.config.mts\n const configPath = [\n join(options.dir, 'vitest.config.mts'),\n join(options.dir, 'vite.config.mts'),\n ].find((config) => tree.exists(config));\n\n if (configPath) {\n await applyGritQL(\n tree,\n configPath,\n readGritPattern('vitest-pass-with-no-tests'),\n );\n\n await applyGritQL(tree, configPath, ROOT_IMPORT_META_DIRNAME);\n\n await applyGritQL(\n tree,\n configPath,\n coverageReportsDirectoryPattern(options.dir),\n );\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n targetDefaults: {\n ...(nxJson.targetDefaults ?? {}),\n '@nx/vitest:test': {\n cache: true,\n inputs: ['default', '^production'],\n configurations: {\n 'update-snapshot': {\n args: '--update',\n },\n },\n ...nxJson.targetDefaults['@nx/vitest:test'],\n },\n },\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n {},\n withVersions(forDependencies<typeof VITEST_DEPENDENCIES>(declaration), [\n 'vite',\n 'vitest',\n '@vitest/coverage-v8',\n ]),\n );\n};\n"],"names":["joinPathFragments","readNxJson","updateNxJson","readFileSync","join","relative","applyGritQL","forDependencies","addDependenciesToPackageJson","withVersions","readGritPattern","name","dirname","trim","ROOT_IMPORT_META_DIRNAME","GENERATED_REPORTS_DIRECTORY","getCoverageReportsDirectory","dir","coverageReportsDirectoryPattern","VITEST_DEPENDENCIES","configureVitest","tree","options","declaration","configPath","find","config","exists","nxJson","targetDefaults","cache","inputs","configurations","args"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,EACjBC,UAAU,EAEVC,YAAY,QACP,aAAa;AACpB,SAASC,YAAY,QAAQ,KAAK;AAClC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AACtC,SAASC,WAAW,QAAQ,qBAAqB;AACjD,SAEEC,eAAe,QAEV,uCAAuC;AAC9C,SAASC,4BAA4B,QAAQ,8BAA8B;AAC3E,SAA6BC,YAAY,QAAQ,0BAA0B;AAG3E,MAAMC,kBAAkB,CAACC,OACvBR,aACEC,KAAK,YAAYQ,OAAO,EAAE,QAAQ,GAAGD,KAAK,KAAK,CAAC,GAChD,SACAE,IAAI;AAER;;;;;;;CAOC,GACD,MAA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AEL,EAAE"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/lib/vitest.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n joinPathFragments,\n readNxJson,\n type Tree,\n updateNxJson,\n} from '@nx/devkit';\nimport { readFileSync } from 'fs';\nimport { join, relative } from 'path';\nimport { applyGritQL } from '../../utils/ast.js';\nimport {\n type DependencyDeclaration,\n forDependencies,\n type MustDeclare,\n} from '../../utils/declared-dependencies.js';\nimport { addDependenciesToPackageJson } from '../../utils/dependencies.js';\nimport { type ITsDepVersion, withVersions } from '../../utils/versions.js';\nimport type { ConfigureProjectOptions } from './types.js';\n\nconst readGritPattern = (name: string): string =>\n readFileSync(\n join(import.meta.dirname, 'grit', `${name}.grit`),\n 'utf-8',\n ).trim();\n\n/**\n * Resolve the config's `root` from `import.meta.dirname`.\n *\n * `@nx/js` writes `root: __dirname`, which Vite's native config loader does not\n * provide — it warns today and will reject once `configLoader: 'native'` becomes\n * the default. Scoped with `some` to a direct property of the object the config\n * factory returns, so a nested `root` (a `test.alias` entry, say) is untouched.\n */\nconst ROOT_IMPORT_META_DIRNAME = `\\`defineConfig(() => ({ $props }))\\` where {\n $props <: some \\`root: __dirname\\` as $root,\n $root => \\`root: import.meta.dirname\\`\n}`;\n\n/** The `reportsDirectory` `@nx/vitest` writes, resolved against the project root. */\nexport const GENERATED_REPORTS_DIRECTORY = './test-output/vitest/coverage';\n\n/**\n * The coverage directory for a project, as a path relative to the project root\n * (vitest resolves `reportsDirectory` against the config's `root`).\n *\n * Coverage lands under the workspace's `dist` rather than inside the project, so\n * the HTML reporter's vendored assets are neither formatted by the `format`\n * target nor counted as an input to the project's own tasks.\n */\nexport const getCoverageReportsDirectory = (dir: string): string =>\n joinPathFragments(\n relative(join('/', dir), '/'),\n 'dist',\n dir,\n 'test-output/vitest/coverage',\n );\n\n/**\n * Point coverage at the project's `dist` directory.\n *\n * `@nx/vitest` writes `reportsDirectory: './test-output/vitest/coverage'`, which\n * resolves inside the project. Coverage is off by default, so the directory is\n * dormant until someone runs `vitest --coverage` — at which point the HTML\n * reporter's bundled third-party scripts land in the project, where the `format`\n * target reformats them (failing the build from then on) and the `default` named\n * input counts them, so no task in the project can ever be cached again.\n *\n * Anchored to the exact literal `@nx/vitest` generates, and scoped to the\n * `coverage` block of the config's own `test` object, so a directory the user has\n * repointed is left alone.\n */\nconst coverageReportsDirectoryPattern = (dir: string): string =>\n `\\`test: { $props }\\` where {\n $props <: within \\`defineConfig($_)\\`,\n $props <: some \\`coverage: { $cov }\\`,\n $cov <: some \\`reportsDirectory: '${GENERATED_REPORTS_DIRECTORY}'\\` as $reportsDirectory,\n $reportsDirectory => \\`reportsDirectory: '${getCoverageReportsDirectory(dir)}'\\`\n}`;\n\n/** Dependencies a caller must declare to configure vitest. */\nexport const VITEST_DEPENDENCIES = [\n { name: 'vite' },\n { name: 'vitest' },\n { name: '@vitest/coverage-v8' },\n // `@nx/vitest` writes `environment: 'jsdom'` into the config it generates.\n { name: 'jsdom' },\n // Registered in nx.json as an inferred-target plugin, so it must resolve when\n // Nx builds the project graph. `@nx/js` installed it until Nx 23.2, which now\n // only reaches for it transiently while its generator runs. Like the other nx\n // packages it upgrades through `packageJsonUpdates`, not the version sync.\n { name: '@nx/vitest', dev: true, root: true },\n] as const satisfies readonly {\n name: ITsDepVersion;\n dev?: boolean;\n root?: boolean;\n}[];\n\nexport const configureVitest = async <const D extends DependencyDeclaration>(\n tree: Tree,\n options: ConfigureProjectOptions,\n declaration: D & MustDeclare<typeof VITEST_DEPENDENCIES, D>,\n) => {\n // Find vitest.config.mts or vite.config.mts\n const configPath = [\n join(options.dir, 'vitest.config.mts'),\n join(options.dir, 'vite.config.mts'),\n ].find((config) => tree.exists(config));\n\n if (configPath) {\n await applyGritQL(\n tree,\n configPath,\n readGritPattern('vitest-pass-with-no-tests'),\n );\n\n await applyGritQL(tree, configPath, ROOT_IMPORT_META_DIRNAME);\n\n await applyGritQL(\n tree,\n configPath,\n coverageReportsDirectoryPattern(options.dir),\n );\n\n const nxJson = readNxJson(tree);\n updateNxJson(tree, {\n ...nxJson,\n targetDefaults: {\n ...(nxJson.targetDefaults ?? {}),\n '@nx/vitest:test': {\n cache: true,\n inputs: ['default', '^production'],\n configurations: {\n 'update-snapshot': {\n args: '--update',\n },\n },\n ...nxJson.targetDefaults['@nx/vitest:test'],\n },\n },\n });\n }\n\n addDependenciesToPackageJson(\n tree,\n {},\n withVersions(forDependencies<typeof VITEST_DEPENDENCIES>(declaration), [\n 'vite',\n 'vitest',\n '@vitest/coverage-v8',\n 'jsdom',\n '@nx/vitest',\n ]),\n );\n};\n"],"names":["joinPathFragments","readNxJson","updateNxJson","readFileSync","join","relative","applyGritQL","forDependencies","addDependenciesToPackageJson","withVersions","readGritPattern","name","dirname","trim","ROOT_IMPORT_META_DIRNAME","GENERATED_REPORTS_DIRECTORY","getCoverageReportsDirectory","dir","coverageReportsDirectoryPattern","VITEST_DEPENDENCIES","dev","root","configureVitest","tree","options","declaration","configPath","find","config","exists","nxJson","targetDefaults","cache","inputs","configurations","args"],"mappings":"AAAA;;;CAGC,GACD,SACEA,iBAAiB,EACjBC,UAAU,EAEVC,YAAY,QACP,aAAa;AACpB,SAASC,YAAY,QAAQ,KAAK;AAClC,SAASC,IAAI,EAAEC,QAAQ,QAAQ,OAAO;AACtC,SAASC,WAAW,QAAQ,qBAAqB;AACjD,SAEEC,eAAe,QAEV,uCAAuC;AAC9C,SAASC,4BAA4B,QAAQ,8BAA8B;AAC3E,SAA6BC,YAAY,QAAQ,0BAA0B;AAG3E,MAAMC,kBAAkB,CAACC,OACvBR,aACEC,KAAK,YAAYQ,OAAO,EAAE,QAAQ,GAAGD,KAAK,KAAK,CAAC,GAChD,SACAE,IAAI;AAER;;;;;;;CAOC,GACD,MAAMC,2BAA2B,CAAC;;;CAGjC,CAAC;AAEF,mFAAmF,GACnF,OAAO,MAAMC,8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