@aws/nx-plugin-mcp 1.0.0-rc.46 → 1.0.0-rc.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aws-nx-mcp.js +56 -39
- package/docs/get_started/existing-project.mdx +6 -2
- package/docs/get_started/quick-start.mdx +1 -1
- package/docs/get_started/tutorials/dungeon-game/1.mdx +2 -2
- package/docs/get_started/tutorials/dungeon-game/2.mdx +3 -3
- package/docs/get_started/tutorials/dungeon-game/overview.mdx +1 -0
- package/docs/guides/agentcore-gateway.mdx +1 -1
- package/docs/guides/connection/py-agent-dynamodb.mdx +1 -1
- package/docs/guides/connection/py-agent-rdb.mdx +1 -1
- package/docs/guides/connection/py-fast-api-rdb.mdx +1 -1
- package/docs/guides/connection/py-mcp-server-dynamodb.mdx +1 -1
- package/docs/guides/connection/py-mcp-server-rdb.mdx +1 -1
- package/docs/guides/connection/smithy-dynamodb.mdx +1 -1
- package/docs/guides/connection/smithy-rdb.mdx +3 -3
- package/docs/guides/connection/trpc-dynamodb.mdx +1 -1
- package/docs/guides/connection/ts-agent-a2a.mdx +1 -1
- package/docs/guides/connection/ts-agent-dynamodb.mdx +2 -2
- package/docs/guides/connection/ts-agent-gateway.mdx +1 -1
- package/docs/guides/connection/ts-agent-mcp.mdx +1 -1
- package/docs/guides/connection/ts-agent-rdb.mdx +4 -4
- package/docs/guides/connection/ts-mcp-server-dynamodb.mdx +2 -2
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +2 -2
- package/docs/guides/docker-bundling.mdx +2 -2
- package/docs/guides/fastapi.mdx +2 -2
- package/docs/guides/react-website-auth.mdx +2 -2
- package/docs/guides/react-website.mdx +3 -2
- package/docs/guides/runtime-config.mdx +1 -1
- package/docs/guides/trpc.mdx +4 -3
- package/docs/guides/ts-dynamodb.mdx +2 -1
- package/docs/guides/ts-rdb.mdx +3 -2
- package/docs/guides/ts-smithy-api.mdx +3 -2
- package/docs/guides/typescript-infrastructure.mdx +6 -5
- package/docs/guides/typescript-project.mdx +133 -26
- package/docs/guides/workspace.mdx +9 -2
- package/docs/snippets/agent/bedrock-deployment.mdx +4 -4
- package/docs/snippets/agent/runtime-arn.mdx +1 -1
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +1 -1
- package/docs/snippets/connection/lambda-dynamodb-access.mdx +1 -1
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +1 -1
- package/docs/snippets/dynamodb/deploying-table.mdx +5 -5
- package/docs/snippets/lambda-function/deploying-your-function.mdx +2 -2
- package/docs/snippets/mcp/bedrock-deployment.mdx +4 -4
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +7 -5
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +29 -10
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +4 -4
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +1 -1
- package/docs/snippets/prerequisites.mdx +2 -1
- package/docs/snippets/rdb/cluster-instances.mdx +1 -1
- package/docs/snippets/rdb/deletion-protection.mdx +1 -1
- package/docs/snippets/rdb/deploying.mdx +1 -1
- package/docs/snippets/rdb/encryption-key-rotation.mdx +1 -1
- package/docs/snippets/rdb/engine-version.mdx +2 -2
- package/docs/snippets/rdb/performance-insights.mdx +1 -1
- package/docs/snippets/rdb/rds-proxy.mdx +1 -1
- package/docs/snippets/rdb/removal-policy.mdx +2 -2
- package/docs/snippets/rdb/serverless-capacity.mdx +1 -1
- package/docs/snippets/required-prerequisites.mdx +1 -2
- package/generators.json +1 -1
- package/package.json +1 -1
- package/src/preset/schema.json +5 -0
|
@@ -342,7 +342,7 @@ infra.asset -> ecr: cdk deploy\nbuilds + pushes
|
|
|
342
342
|
|
|
343
343
|
```ts
|
|
344
344
|
import { DockerImageAsset, Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
345
|
-
import { findWorkspaceRoot } from '
|
|
345
|
+
import { findWorkspaceRoot } from '@my-scope/common-constructs';
|
|
346
346
|
import * as path from 'path';
|
|
347
347
|
import * as url from 'url';
|
|
348
348
|
|
|
@@ -356,7 +356,7 @@ const image = new DockerImageAsset(this, 'MyImage', {
|
|
|
356
356
|
});
|
|
357
357
|
```
|
|
358
358
|
|
|
359
|
-
The `findWorkspaceRoot` helper is generated by the <Link path="/guides/typescript-infrastructure">`ts#infra`</Link> generator and exported from
|
|
359
|
+
The `findWorkspaceRoot` helper is generated by the <Link path="/guides/typescript-infrastructure">`ts#infra`</Link> generator and exported from `@my-scope/common-constructs`. If you are not using shared constructs, you can hardcode the path to the `dist` directory relative to where `cdk` is invoked from — typically the workspace root — and omit the `findWorkspaceRoot` call entirely.
|
|
360
360
|
|
|
361
361
|
:::note[Running bundle before synth]
|
|
362
362
|
CDK does not run the `bundle`/`docker` targets automatically — you must run `nx build my-project` (or wire the deploy target to depend on `build`) before `cdk deploy`. The generators that use this pattern declare `docker` and `bundle` as dependencies of `build` so this happens transparently.
|
package/docs/guides/fastapi.mdx
CHANGED
|
@@ -445,7 +445,7 @@ The FastAPI generator creates CDK or Terraform infrastructure as code based on y
|
|
|
445
445
|
The CDK construct for deploying your API in the `common/constructs` folder. You can use this in a CDK application:
|
|
446
446
|
|
|
447
447
|
```ts {6-8}
|
|
448
|
-
import { MyApi } from '
|
|
448
|
+
import { MyApi } from '@my-scope/common-constructs';
|
|
449
449
|
|
|
450
450
|
export class ExampleStack extends Stack {
|
|
451
451
|
constructor(scope: Construct, id: string) {
|
|
@@ -473,7 +473,7 @@ This sets up:
|
|
|
473
473
|
If you selected to use `Cognito` authentication, you will need to supply the `identity` property to the API construct:
|
|
474
474
|
|
|
475
475
|
```ts {9}
|
|
476
|
-
import { MyApi, UserIdentity } from '
|
|
476
|
+
import { MyApi, UserIdentity } from '@my-scope/common-constructs';
|
|
477
477
|
|
|
478
478
|
export class ExampleStack extends Stack {
|
|
479
479
|
constructor(scope: Construct, id: string) {
|
|
@@ -149,7 +149,7 @@ You will need to add the user identity infrastructure to your stack, declaring i
|
|
|
149
149
|
```ts title="packages/infra/src/stacks/application-stack.ts" {3,9}
|
|
150
150
|
import { Stack } from 'aws-cdk-lib';
|
|
151
151
|
import { Construct } from 'constructs';
|
|
152
|
-
import { MyWebsite, UserIdentity } from '
|
|
152
|
+
import { MyWebsite, UserIdentity } from '@my-scope/common-constructs';
|
|
153
153
|
|
|
154
154
|
export class ApplicationStack extends Stack {
|
|
155
155
|
constructor(scope: Construct, id: string) {
|
|
@@ -218,7 +218,7 @@ In order to grant authenticated users access to perform certain actions, such as
|
|
|
218
218
|
```ts title="packages/infra/src/stacks/application-stack.ts" {12}
|
|
219
219
|
import { Stack } from 'aws-cdk-lib';
|
|
220
220
|
import { Construct } from 'constructs';
|
|
221
|
-
import { MyWebsite, UserIdentity, MyApi } from '
|
|
221
|
+
import { MyWebsite, UserIdentity, MyApi } from '@my-scope/common-constructs';
|
|
222
222
|
|
|
223
223
|
export class ApplicationStack extends Stack {
|
|
224
224
|
constructor(scope: Construct, id: string) {
|
|
@@ -59,6 +59,7 @@ The generator will create the following project structure in the `<directory>/<n
|
|
|
59
59
|
- tsconfig.json Base TypeScript configuration for source and tests
|
|
60
60
|
- tsconfig.app.json TypeScript configuration for source code
|
|
61
61
|
- tsconfig.spec.json TypeScript configuration for tests
|
|
62
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
62
63
|
</FileTree>
|
|
63
64
|
|
|
64
65
|
:::note[Without TanStack Router]
|
|
@@ -245,7 +246,7 @@ Your website CDK construct will deploy the `connection` namespace of the runtime
|
|
|
245
246
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
246
247
|
import { Stack } from 'aws-cdk-lib';
|
|
247
248
|
import { Construct } from 'constructs';
|
|
248
|
-
import { MyWebsite, MyApi } from '
|
|
249
|
+
import { MyWebsite, MyApi } from '@my-scope/common-constructs';
|
|
249
250
|
|
|
250
251
|
export class ApplicationStack extends Stack {
|
|
251
252
|
constructor(scope: Construct, id: string) {
|
|
@@ -427,7 +428,7 @@ You can use the CDK construct generated for you in `packages/common/constructs`
|
|
|
427
428
|
```ts title="packages/infra/src/stacks/application-stack.ts" {3, 9}
|
|
428
429
|
import { Stack } from 'aws-cdk-lib';
|
|
429
430
|
import { Construct } from 'constructs';
|
|
430
|
-
import { MyWebsite } from '
|
|
431
|
+
import { MyWebsite } from '@my-scope/common-constructs';
|
|
431
432
|
|
|
432
433
|
export class ApplicationStack extends Stack {
|
|
433
434
|
constructor(scope: Construct, id: string) {
|
|
@@ -70,7 +70,7 @@ Generated constructs automatically write relevant configuration to the `connecti
|
|
|
70
70
|
The `RuntimeConfig` CDK construct is a stage-scoped singleton. Use `set()` to write a key into a namespace:
|
|
71
71
|
|
|
72
72
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
73
|
-
import { RuntimeConfig } from '
|
|
73
|
+
import { RuntimeConfig } from '@my-scope/common-constructs';
|
|
74
74
|
|
|
75
75
|
const rc = RuntimeConfig.ensure(this);
|
|
76
76
|
|
package/docs/guides/trpc.mdx
CHANGED
|
@@ -66,6 +66,7 @@ The generator will create the following project structure in the `<directory>/<a
|
|
|
66
66
|
- client
|
|
67
67
|
- index.ts Type-safe client for machine-to-machine API calls
|
|
68
68
|
- tsconfig.json TypeScript configuration
|
|
69
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
69
70
|
- project.json Project configuration and build targets
|
|
70
71
|
|
|
71
72
|
</FileTree>
|
|
@@ -558,7 +559,7 @@ The CDK construct for deploying your API lives in the `common/constructs` folder
|
|
|
558
559
|
|
|
559
560
|
<OptionFilter when={{ auth: ['iam', 'custom'] }} description="CDK usage for IAM or Custom authentication">
|
|
560
561
|
```ts {6-8}
|
|
561
|
-
import { MyApi } from '
|
|
562
|
+
import { MyApi } from '@my-scope/common-constructs';
|
|
562
563
|
|
|
563
564
|
export class ExampleStack extends Stack {
|
|
564
565
|
constructor(scope: Construct, id: string) {
|
|
@@ -577,7 +578,7 @@ When using `Custom` auth, the construct creates a Lambda Authorizer internally f
|
|
|
577
578
|
|
|
578
579
|
<OptionFilter when={{ auth: 'cognito' }} description="CDK usage with Cognito authentication — pass the identity construct">
|
|
579
580
|
```ts {6,9}
|
|
580
|
-
import { MyApi, UserIdentity } from '
|
|
581
|
+
import { MyApi, UserIdentity } from '@my-scope/common-constructs';
|
|
581
582
|
|
|
582
583
|
export class ExampleStack extends Stack {
|
|
583
584
|
constructor(scope: Construct, id: string) {
|
|
@@ -813,7 +814,7 @@ This will automatically reload when you make changes to your API.
|
|
|
813
814
|
You can create a tRPC client to invoke your API in a type-safe manner. If you are calling your tRPC API from another backend, you can use the client in `src/client/index.ts`, for example:
|
|
814
815
|
|
|
815
816
|
```ts
|
|
816
|
-
import { createMyApiClient } from '
|
|
817
|
+
import { createMyApiClient } from '@my-scope/my-api';
|
|
817
818
|
|
|
818
819
|
const client = createMyApiClient({ url: 'https://my-api-url.example.com/' });
|
|
819
820
|
|
|
@@ -36,6 +36,7 @@ The generator creates the following project structure in the `<directory>/<name>
|
|
|
36
36
|
- example.ts Example ElectroDB entity definition
|
|
37
37
|
- index.ts Entity exports
|
|
38
38
|
- config.json Table configuration including GSI definitions and local development settings
|
|
39
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
39
40
|
- project.json Project configuration and build targets
|
|
40
41
|
</FileTree>
|
|
41
42
|
|
|
@@ -136,7 +137,7 @@ GSIs are defined in `config.json` at the project root under the `tableConfig.glo
|
|
|
136
137
|
In any TypeScript project, import entity factories from your DynamoDB package and use them directly:
|
|
137
138
|
|
|
138
139
|
```ts
|
|
139
|
-
import { createExampleEntity } from '
|
|
140
|
+
import { createExampleEntity } from '@my-scope/my-table';
|
|
140
141
|
|
|
141
142
|
const entity = await createExampleEntity();
|
|
142
143
|
const result = await entity.query.primary({ id: '123' }).go();
|
package/docs/guides/ts-rdb.mdx
CHANGED
|
@@ -47,6 +47,7 @@ The generator will create the following project structure in the `<directory>/<n
|
|
|
47
47
|
- .gitignore Git ignore entries including generated Prisma client output
|
|
48
48
|
- config.json Local development connection details and runtime config key
|
|
49
49
|
- Dockerfile Container image definition for the migration handler
|
|
50
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
50
51
|
- project.json Project configuration and build targets
|
|
51
52
|
- prisma.config.ts Configuration for Prisma CLI
|
|
52
53
|
</FileTree>
|
|
@@ -173,7 +174,7 @@ Replace `<engine>` with your container engine (`docker` or `finch`), `<scope>` w
|
|
|
173
174
|
In any TypeScript project, import `getPrisma` from your database package and call it to get a type-safe Prisma client:
|
|
174
175
|
|
|
175
176
|
```ts
|
|
176
|
-
import { getPrisma } from '
|
|
177
|
+
import { getPrisma } from '@my-scope/db';
|
|
177
178
|
|
|
178
179
|
const prisma = await getPrisma();
|
|
179
180
|
const users = await prisma.user.findMany({ orderBy: { id: 'asc' } });
|
|
@@ -340,7 +341,7 @@ export const listExampleTable = publicProcedure
|
|
|
340
341
|
If you are using the [middleware pattern](#injecting-the-prisma-client-via-middleware), add the `$disconnect()` call to the middleware so all procedures built on it are covered automatically:
|
|
341
342
|
|
|
342
343
|
```ts title="packages/api/src/middleware/db.ts"
|
|
343
|
-
import { getPrisma } from '
|
|
344
|
+
import { getPrisma } from '@my-scope/db';
|
|
344
345
|
import { initTRPC } from '@trpc/server';
|
|
345
346
|
|
|
346
347
|
export interface IDbContext {
|
|
@@ -46,6 +46,7 @@ The generator creates two related projects in the `<directory>/<api-name>` direc
|
|
|
46
46
|
<FileTree>
|
|
47
47
|
|
|
48
48
|
- **model/** Smithy model project
|
|
49
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
49
50
|
- project.json Project configuration and build targets
|
|
50
51
|
- smithy-build.json Smithy build configuration
|
|
51
52
|
- build.Dockerfile Docker configuration for building Smithy artifacts
|
|
@@ -588,7 +589,7 @@ The generator creates CDK or Terraform infrastructure based on your selected `ia
|
|
|
588
589
|
The CDK construct for deploying your API is in the `common/constructs` folder:
|
|
589
590
|
|
|
590
591
|
```ts {6-8}
|
|
591
|
-
import { MyApi } from '
|
|
592
|
+
import { MyApi } from '@my-scope/common-constructs';
|
|
592
593
|
|
|
593
594
|
export class ExampleStack extends Stack {
|
|
594
595
|
constructor(scope: Construct, id: string) {
|
|
@@ -615,7 +616,7 @@ This sets up:
|
|
|
615
616
|
If you selected `Cognito` authentication, you will need to supply the `identity` property to the API construct:
|
|
616
617
|
|
|
617
618
|
```ts {9}
|
|
618
|
-
import { MyApi, UserIdentity } from '
|
|
619
|
+
import { MyApi, UserIdentity } from '@my-scope/common-constructs';
|
|
619
620
|
|
|
620
621
|
export class ExampleStack extends Stack {
|
|
621
622
|
constructor(scope: Construct, id: string) {
|
|
@@ -38,6 +38,7 @@ The generator will create the following project structure in the `<directory>/<n
|
|
|
38
38
|
- stacks CDK Stack definitions
|
|
39
39
|
- application-stack.ts Main application stack
|
|
40
40
|
- cdk.json CDK configuration
|
|
41
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
41
42
|
- project.json Project configuration and build targets
|
|
42
43
|
- checkov.yml Checkov configuration file
|
|
43
44
|
|
|
@@ -102,7 +103,7 @@ The `env` property tells CDK which AWS account and region to deploy to. `CDK_DEF
|
|
|
102
103
|
If you generated with `stageConfig`, the `main.ts` reads account and region from a centralized config file instead, falling back to environment variables when no config is set:
|
|
103
104
|
|
|
104
105
|
```ts title="src/main.ts (with stageConfig)"
|
|
105
|
-
import { resolveStage } from '
|
|
106
|
+
import { resolveStage } from '@my-scope/common-infra-config';
|
|
106
107
|
|
|
107
108
|
// Looks up the stage under this project (packages/infra), falling back to
|
|
108
109
|
// shared stages. Returns undefined when no config exists for the stage.
|
|
@@ -271,7 +272,7 @@ If, for example, you created a tRPC API called `my-api`, you can simply import a
|
|
|
271
272
|
```ts title="src/stacks/application-stack.ts" {3, 9-12}
|
|
272
273
|
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
273
274
|
import { Construct } from 'constructs';
|
|
274
|
-
import { MyApi } from '
|
|
275
|
+
import { MyApi } from '@my-scope/common-constructs';
|
|
275
276
|
|
|
276
277
|
export class ApplicationStack extends Stack {
|
|
277
278
|
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
@@ -292,7 +293,7 @@ If you have used the <Link path="guides/react-website">React Website</Link> gene
|
|
|
292
293
|
```ts title="src/stacks/application-stack.ts" {3, 9-10}
|
|
293
294
|
import { Stack, StackProps } from 'aws-cdk-lib';
|
|
294
295
|
import { Construct } from 'constructs';
|
|
295
|
-
import { MyWebsite } from '
|
|
296
|
+
import { MyWebsite } from '@my-scope/common-constructs';
|
|
296
297
|
|
|
297
298
|
export class ApplicationStack extends Stack {
|
|
298
299
|
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
@@ -339,7 +340,7 @@ There may be instances where you want to suppress certain rules on resources. Yo
|
|
|
339
340
|
#### Supress a rule on a given construct
|
|
340
341
|
|
|
341
342
|
```typescript
|
|
342
|
-
import { suppressRules } from '
|
|
343
|
+
import { suppressRules } from '@my-scope/common-constructs';
|
|
343
344
|
|
|
344
345
|
// suppresses the CKV_AWS_XXX for the given construct.
|
|
345
346
|
suppressRules(construct, ['CKV_AWS_XXX'], 'Reason');
|
|
@@ -348,7 +349,7 @@ suppressRules(construct, ['CKV_AWS_XXX'], 'Reason');
|
|
|
348
349
|
#### Supress a rule on a descendant construct
|
|
349
350
|
|
|
350
351
|
```typescript
|
|
351
|
-
import { suppressRules } from '
|
|
352
|
+
import { suppressRules } from '@my-scope/common-constructs';
|
|
352
353
|
|
|
353
354
|
// Supresses the CKV_AWS_XXX for the construct or any of its descendants if it is an instance of Bucket
|
|
354
355
|
suppressRules(construct, ['CKV_AWS_XXX'], 'Reason', (construct) => construct instanceof Bucket);
|
|
@@ -3,12 +3,13 @@ title: TypeScript Projects
|
|
|
3
3
|
description: Reference documentation for TypeScript projects
|
|
4
4
|
generator: ts#project
|
|
5
5
|
---
|
|
6
|
-
import { FileTree } from '@astrojs/starlight/components';
|
|
6
|
+
import { FileTree, Tabs, TabItem, Steps } from '@astrojs/starlight/components';
|
|
7
7
|
import RunGenerator from '@components/run-generator.astro';
|
|
8
8
|
import InstallCommand from '@components/install-command.astro';
|
|
9
9
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
10
10
|
import NxCommands from '@components/nx-commands.astro';
|
|
11
11
|
import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
|
|
12
|
+
import CreateNxWorkspaceCommand from '@components/create-nx-workspace-command.astro';
|
|
12
13
|
import Link from '@components/link.astro';
|
|
13
14
|
|
|
14
15
|
The TypeScript project generator can be used to create a modern [TypeScript](https://www.typescriptlang.org/) library or application configured with best practices such as [ECMAScript Modules (ESM)](https://www.typescriptlang.org/docs/handbook/modules/reference.html), TypeScript [project references](https://www.typescriptlang.org/docs/handbook/project-references.html), [Vitest](https://vitest.dev/) for running tests and [Biome](https://biomejs.dev/) for linting and formatting.
|
|
@@ -33,6 +34,7 @@ The generator will create the following project structure in the `<directory>/<n
|
|
|
33
34
|
|
|
34
35
|
- src TypeScript source code
|
|
35
36
|
- index.ts
|
|
37
|
+
- package.json Project manifest defining the project's package name and dependencies
|
|
36
38
|
- project.json Project configuration and build targets
|
|
37
39
|
- tsconfig.json Base TypeScript configuration for this project (extends workspace root tsconfig.base.json)
|
|
38
40
|
- tsconfig.lib.json TypeScript configuration for your library (your runtime or packaged source)
|
|
@@ -41,8 +43,8 @@ The generator will create the following project structure in the `<directory>/<n
|
|
|
41
43
|
|
|
42
44
|
</FileTree>
|
|
43
45
|
|
|
44
|
-
:::tip[
|
|
45
|
-
|
|
46
|
+
:::tip[Project package.json]
|
|
47
|
+
The project's `package.json` starts minimal. As you add runtime dependencies they are declared here (shared build/test tooling stays in the workspace root) — you can find out more [below](#dependencies).
|
|
46
48
|
:::
|
|
47
49
|
|
|
48
50
|
You will also notice some changes to the following files in your workspace root:
|
|
@@ -85,13 +87,9 @@ export * from './algorithms/index.js';
|
|
|
85
87
|
[TypeScript aliases](https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths) for your project are configured in your workspace `tsconfig.base.json`, which allows you to reference your TypeScript project from other TypeScript projects:
|
|
86
88
|
|
|
87
89
|
```ts title="packages/my-other-project/src/index.ts"
|
|
88
|
-
import { sayHello } from '
|
|
90
|
+
import { sayHello } from '@my-scope/my-library';
|
|
89
91
|
```
|
|
90
92
|
|
|
91
|
-
:::note[Project Aliases]
|
|
92
|
-
Aliases for your TypeScript projects begin with a `:` rather than the traditional `@`, since this avoids the possibility of name conflicts between local packages in your workspace and remote packages in [NPM](https://www.npmjs.com/).
|
|
93
|
-
:::
|
|
94
|
-
|
|
95
93
|
When you add an import statement for a new project in your workspace for the first time, you will likely see an error in your IDE similar to the below:
|
|
96
94
|
|
|
97
95
|
<details>
|
|
@@ -106,28 +104,40 @@ File '/path/to/my/workspace/packages/my-library/src/index.ts' is not listed with
|
|
|
106
104
|
|
|
107
105
|
</details>
|
|
108
106
|
|
|
109
|
-
This is because a [project reference](https://www.typescriptlang.org/docs/handbook/project-references.html) has not yet been set up.
|
|
107
|
+
This is because a [project reference](https://www.typescriptlang.org/docs/handbook/project-references.html) has not yet been set up, and the imported project has not yet been declared as a workspace dependency in your project's `package.json`.
|
|
110
108
|
|
|
111
|
-
|
|
109
|
+
Your workspace is configured with sync generators which manage both for you, so you don't need to configure them by hand. Simply run the following command and Nx will add the required configuration:
|
|
112
110
|
|
|
113
111
|
<NxCommands commands={['sync']} />
|
|
114
112
|
|
|
115
|
-
|
|
113
|
+
```bash wrap
|
|
114
|
+
NX The workspace is out of sync
|
|
115
|
+
|
|
116
|
+
[@nx/js:typescript-sync]: Some TypeScript configuration files are missing project references to the projects they depend on, contain stale project references, or have duplicate project references.
|
|
117
|
+
[@aws/nx-plugin:ts#sync]: Local project dependencies are out of sync. The following workspace dependencies will be declared:
|
|
118
|
+
packages/my-other-project/package.json:
|
|
119
|
+
- @my-scope/my-library: workspace:*
|
|
120
|
+
|
|
121
|
+
Syncing the workspace...
|
|
122
|
+
The workspace was synced successfully!
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Nx's TypeScript sync generator adds the project reference, and the plugin's `ts#sync` generator declares the imported project in your project's `package.json` (`workspace:*` where the package manager supports the workspace protocol, `*` on npm and yarn classic), so the package manager links the local project on install. After this, the error in your IDE should be gone and you are ready to use your library.
|
|
116
126
|
|
|
117
127
|
:::tip[Build Shortcut]
|
|
118
|
-
You can also just build your project and you'll be prompted
|
|
128
|
+
You can also just build your project — the sync generators run first and you'll be prompted to apply any outstanding changes:
|
|
119
129
|
|
|
120
130
|
```bash wrap
|
|
121
|
-
|
|
131
|
+
NX The workspace is out of sync
|
|
122
132
|
|
|
123
|
-
|
|
133
|
+
...
|
|
124
134
|
|
|
125
|
-
? Would you like to sync the identified changes to get your workspace up to date?
|
|
135
|
+
? Would you like to sync the identified changes to get your workspace up to date? …
|
|
126
136
|
Yes, sync the changes and run the tasks
|
|
127
137
|
No, run the tasks without syncing the changes
|
|
128
138
|
```
|
|
129
139
|
|
|
130
|
-
Select `Yes` to allow Nx to
|
|
140
|
+
Select `Yes` to allow Nx to sync your workspace.
|
|
131
141
|
:::
|
|
132
142
|
|
|
133
143
|
### Keeping Path Aliases In Sync
|
|
@@ -136,13 +146,116 @@ If you add custom `compilerOptions.paths` entries in a project's `tsconfig.json`
|
|
|
136
146
|
|
|
137
147
|
### Dependencies
|
|
138
148
|
|
|
139
|
-
|
|
149
|
+
Each TypeScript project declares its third-party runtime dependencies in its own `package.json`. Build and test tooling shared across projects is defined in the root `package.json`.
|
|
150
|
+
|
|
151
|
+
To add a runtime dependency to a project, install it into that project:
|
|
152
|
+
|
|
153
|
+
<InstallCommand pkg="some-npm-package" project="@my-scope/my-library" />
|
|
154
|
+
|
|
155
|
+
You can also run your package manager's plain `add`/`install` command from within the project's directory.
|
|
156
|
+
|
|
157
|
+
To add a shared dev tool, install it at the workspace root:
|
|
158
|
+
|
|
159
|
+
<InstallCommand pkg="some-dev-tool" dev />
|
|
160
|
+
|
|
161
|
+
:::note
|
|
162
|
+
Biome's [`noUndeclaredDependencies`](https://biomejs.dev/linter/rules/no-undeclared-dependencies/) lint rule enforces that a project's source only imports packages declared in its own `package.json`. Config files, build scripts and tests are exempt, so shared tooling can stay at the root.
|
|
163
|
+
:::
|
|
164
|
+
|
|
165
|
+
#### Catalogs
|
|
166
|
+
|
|
167
|
+
For package managers which support catalogs ([pnpm](https://pnpm.io/catalogs), [yarn](https://yarnpkg.com/features/catalogs) and [bun](https://bun.com/docs/install/catalogs)), generators record each version in the catalog and reference it with the `catalog:` protocol (eg `"zod": "catalog:"`), so the catalog is the single source of truth for versions regardless of which project declares the dependency. This helps you to follow a [single version policy](https://nx.dev/concepts/decisions/dependency-management#single-version-policy), avoiding type conflicts and multiple copies of packages in deployment bundles.
|
|
168
|
+
|
|
169
|
+
When you add a new dependency yourself, keep it in the catalog too:
|
|
170
|
+
|
|
171
|
+
<Tabs syncKey="package-manager">
|
|
172
|
+
<TabItem label="pnpm">
|
|
173
|
+
The workspace sets [`catalogMode: strict`](https://pnpm.io/settings#catalogmode), so `pnpm add` records the version in the catalog and references it automatically — no extra steps.
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
pnpm add some-npm-package --filter my-library
|
|
177
|
+
```
|
|
178
|
+
</TabItem>
|
|
179
|
+
<TabItem label="yarn">
|
|
180
|
+
yarn's `catalog:` protocol only *references* an existing catalog entry — it cannot create one — so record the version first.
|
|
181
|
+
|
|
182
|
+
<Steps>
|
|
183
|
+
1. Add the version under `catalog` in `.yarnrc.yml`:
|
|
184
|
+
|
|
185
|
+
```yaml title=".yarnrc.yml"
|
|
186
|
+
catalog:
|
|
187
|
+
some-npm-package: ^1.0.0
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
2. Reference it from the project:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
yarn workspace @my-scope/my-library add some-npm-package@catalog:
|
|
194
|
+
```
|
|
195
|
+
</Steps>
|
|
196
|
+
</TabItem>
|
|
197
|
+
<TabItem label="bun">
|
|
198
|
+
bun's `catalog:` protocol only *references* an existing catalog entry — it cannot create one — so record the version first.
|
|
140
199
|
|
|
141
|
-
|
|
200
|
+
<Steps>
|
|
201
|
+
1. Add the version under `catalog` in the root `package.json`:
|
|
142
202
|
|
|
143
|
-
|
|
203
|
+
```json title="package.json"
|
|
204
|
+
{
|
|
205
|
+
"catalog": {
|
|
206
|
+
"some-npm-package": "^1.0.0"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
144
210
|
|
|
145
|
-
|
|
211
|
+
2. Reference it from the project:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
bun add some-npm-package@catalog: --cwd packages/my-library
|
|
215
|
+
```
|
|
216
|
+
</Steps>
|
|
217
|
+
</TabItem>
|
|
218
|
+
</Tabs>
|
|
219
|
+
|
|
220
|
+
:::tip[Aligning versions on npm]
|
|
221
|
+
npm has no catalog feature, so versions are declared directly in each `package.json`. To keep them consistent across projects, we recommend [syncpack](https://github.com/JamieMason/syncpack) (`npx syncpack lint`).
|
|
222
|
+
:::
|
|
223
|
+
|
|
224
|
+
##### Opting out of catalogs
|
|
225
|
+
|
|
226
|
+
Catalogs are enabled by default. To turn them off, create your workspace with `--catalog false`:
|
|
227
|
+
|
|
228
|
+
<CreateNxWorkspaceCommand workspace="my-project" extraArgs="--catalog false" />
|
|
229
|
+
|
|
230
|
+
Or set it in `aws-nx-plugin.config.mts` at any time:
|
|
231
|
+
|
|
232
|
+
```ts title="aws-nx-plugin.config.mts"
|
|
233
|
+
export default {
|
|
234
|
+
packageManager: {
|
|
235
|
+
catalogs: false,
|
|
236
|
+
},
|
|
237
|
+
} satisfies AwsNxPluginConfig;
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
With catalogs disabled, generators write dependency versions directly into each project's `package.json`, and keeping versions aligned across projects is your responsibility.
|
|
241
|
+
|
|
242
|
+
#### Declaring all dependencies at the root
|
|
243
|
+
|
|
244
|
+
If you prefer declaring every dependency in the root `package.json` only (no per-project dependency declarations), turn off the lint rule in the workspace `biome.json`:
|
|
245
|
+
|
|
246
|
+
```json title="biome.json"
|
|
247
|
+
{
|
|
248
|
+
"linter": {
|
|
249
|
+
"rules": {
|
|
250
|
+
"correctness": {
|
|
251
|
+
"noUndeclaredDependencies": "off"
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Projects resolve root-installed packages at build time, so everything still builds — you give up per-project manifests as an accurate record of each project's dependencies (which matters if you later publish a project or split the repo).
|
|
146
259
|
|
|
147
260
|
#### Runtime Code
|
|
148
261
|
|
|
@@ -193,12 +306,6 @@ Note that in the above target, we chose `src/index.ts` as our entrypoint for the
|
|
|
193
306
|
If you're building an AWS Lambda function, check out the <Link path="/guides/ts-lambda-function">`ts#lambda-function`</Link> generator as this configures bundling for you, as well as generating infrastructure and adding observability and type-safety.
|
|
194
307
|
:::
|
|
195
308
|
|
|
196
|
-
#### Publishing to NPM
|
|
197
|
-
|
|
198
|
-
If you are publishing your TypeScript project to NPM, you must create a `package.json` file for it.
|
|
199
|
-
|
|
200
|
-
This must declare the dependencies that your project references. Since at build time your project will resolve dependencies installed via the workspace root `package.json`, Biome's `noUndeclaredDependencies` rule will warn you if your project imports a package that isn't listed in its `package.json`.
|
|
201
|
-
|
|
202
309
|
### Building
|
|
203
310
|
|
|
204
311
|
Your TypeScript project is configured with a `build` target (defined in `project.json`), which you can run via:
|
|
@@ -6,6 +6,7 @@ import { FileTree } from '@astrojs/starlight/components';
|
|
|
6
6
|
import Link from '@components/link.astro';
|
|
7
7
|
import CreateNxWorkspaceCommand from '@components/create-nx-workspace-command.astro';
|
|
8
8
|
import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
|
|
9
|
+
import InstallCommand from '@components/install-command.astro';
|
|
9
10
|
import NxCommands from '@components/nx-commands.astro';
|
|
10
11
|
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
11
12
|
|
|
@@ -82,7 +83,11 @@ The default monorepo setup uses a [single version policy](https://nx.dev/concept
|
|
|
82
83
|
|
|
83
84
|
This means that all projects within your monorepo use the same version of dependencies by default, reducing issues related to packages in the same monorepo running into version mismatch issues.
|
|
84
85
|
|
|
85
|
-
From a Node perspective this means a single lockfile at the root with
|
|
86
|
+
From a Node perspective this means a single lockfile at the root, with dependencies installed once and linked into each project. Each Node project declares the runtime dependencies its source imports in its own `package.json`, while shared build/test tooling lives in the root `package.json` `devDependencies`. Add a project's runtime dependency by installing it into that project:
|
|
87
|
+
|
|
88
|
+
<InstallCommand pkg="some-npm-package" project="@my-scope/my-project" />
|
|
89
|
+
|
|
90
|
+
For package managers with catalog support ([pnpm](https://pnpm.io/catalogs), [yarn](https://yarnpkg.com/features/catalogs) and [bun](https://bun.com/docs/install/catalogs)), dependency versions are recorded in the catalog and referenced with the `catalog:` protocol, keeping a single source of truth for versions across every project's `package.json`. For npm workspaces, we recommend [syncpack](https://github.com/JamieMason/syncpack) to align versions declared across multiple `package.json` files.
|
|
86
91
|
|
|
87
92
|
From a Python perspective, this means a single `.venv` in the root of the monorepo with all dependencies installed into it. Each Python project has its own `pyproject.toml`, but the versions of those dependencies are managed by the UV workspace and subsequently written out to the `uv.lock` file in the root.
|
|
88
93
|
|
|
@@ -108,10 +113,12 @@ Run tests across all projects:
|
|
|
108
113
|
|
|
109
114
|
### Dev
|
|
110
115
|
|
|
111
|
-
|
|
116
|
+
Start all local development servers across your workspace:
|
|
112
117
|
|
|
113
118
|
<PackageManagerShortCommand commands={["dev"]} />
|
|
114
119
|
|
|
120
|
+
See the <Link path="guides/local-development">Local Development</Link> guide for more details.
|
|
121
|
+
|
|
115
122
|
### Sync
|
|
116
123
|
|
|
117
124
|
Run any [sync generators](https://nx.dev/concepts/sync-generators), which for example synchronise TypeScript project references (refer to the <Link path="guides/typescript-project">ts#project</Link> generator guide for more details):
|
|
@@ -15,7 +15,7 @@ A CDK construct is generated for your agent, named based on the `name` you chose
|
|
|
15
15
|
You can use this CDK construct in a CDK application:
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { MyProjectAgent } from '
|
|
18
|
+
import { MyProjectAgent } from '@my-scope/common-constructs';
|
|
19
19
|
|
|
20
20
|
export class ExampleStack extends Stack {
|
|
21
21
|
constructor(scope: Construct, id: string) {
|
|
@@ -69,7 +69,7 @@ By default, your Agent will be secured using IAM authentication, simply deploy i
|
|
|
69
69
|
<Infrastructure>
|
|
70
70
|
<Fragment slot="cdk">
|
|
71
71
|
```ts {5}
|
|
72
|
-
import { MyProjectAgent } from '
|
|
72
|
+
import { MyProjectAgent } from '@my-scope/common-constructs';
|
|
73
73
|
|
|
74
74
|
export class ExampleStack extends Stack {
|
|
75
75
|
constructor(scope: Construct, id: string) {
|
|
@@ -81,7 +81,7 @@ export class ExampleStack extends Stack {
|
|
|
81
81
|
You can grant access to invoke your agent on Bedrock AgentCore Runtime using the `grantInvokeAccess` method, for example:
|
|
82
82
|
|
|
83
83
|
```ts {8}
|
|
84
|
-
import { MyProjectAgent } from '
|
|
84
|
+
import { MyProjectAgent } from '@my-scope/common-constructs';
|
|
85
85
|
|
|
86
86
|
export class ExampleStack extends Stack {
|
|
87
87
|
constructor(scope: Construct, id: string) {
|
|
@@ -131,7 +131,7 @@ When you select `Cognito` authentication, the generator configures the agent to
|
|
|
131
131
|
The generated construct accepts an `identity` prop which configures Cognito authentication:
|
|
132
132
|
|
|
133
133
|
```ts {8}
|
|
134
|
-
import { MyProjectAgent, UserIdentity } from '
|
|
134
|
+
import { MyProjectAgent, UserIdentity } from '@my-scope/common-constructs';
|
|
135
135
|
|
|
136
136
|
export class ExampleStack extends Stack {
|
|
137
137
|
constructor(scope: Construct, id: string) {
|
|
@@ -12,7 +12,7 @@ You can obtain the runtime ARN from your infrastructure as follows:
|
|
|
12
12
|
<Fragment slot="cdk">
|
|
13
13
|
```ts {9}
|
|
14
14
|
import { CfnOutput } from 'aws-cdk-lib';
|
|
15
|
-
import { MyProjectAgent } from '
|
|
15
|
+
import { MyProjectAgent } from '@my-scope/common-constructs';
|
|
16
16
|
|
|
17
17
|
export class ExampleStack extends Stack {
|
|
18
18
|
constructor(scope: Construct, id: string) {
|
|
@@ -8,7 +8,7 @@ If your solution includes a website you can configure its CloudFront distributio
|
|
|
8
8
|
You can call the API `restrictCorsTo` method with website constructs, CloudFront distributions, origin strings, or a mix of them.
|
|
9
9
|
|
|
10
10
|
```ts
|
|
11
|
-
import { MyApi, MyWebsite } from '
|
|
11
|
+
import { MyApi, MyWebsite } from '@my-scope/common-constructs';
|
|
12
12
|
|
|
13
13
|
export class ExampleStack extends Stack {
|
|
14
14
|
constructor(scope: Construct, id: string) {
|
|
@@ -11,7 +11,7 @@ To allow Lambda functions to access the DynamoDB table, grant the necessary perm
|
|
|
11
11
|
Call `grantReadWriteData` on the table construct. This grants both the DynamoDB and KMS permissions required by the Lambda execution role:
|
|
12
12
|
|
|
13
13
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
14
|
-
import { MyTable } from '
|
|
14
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
15
15
|
|
|
16
16
|
const table = new MyTable(this, 'Table');
|
|
17
17
|
|
|
@@ -12,7 +12,7 @@ To allow your API to connect to the database at runtime, the API Lambda function
|
|
|
12
12
|
In your application stack, deploy the API into the same VPC as the database, then call `allowDefaultPortFrom` and `grantConnect` to open the network path and grant IAM `rds-db:connect` permission to each Lambda handler:
|
|
13
13
|
|
|
14
14
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
15
|
-
import { MyDatabase } from '
|
|
15
|
+
import { MyDatabase } from '@my-scope/common-constructs';
|
|
16
16
|
|
|
17
17
|
const db = new MyDatabase(this, 'Db', { vpc, ... });
|
|
18
18
|
|
|
@@ -10,7 +10,7 @@ The DynamoDB generator creates CDK or Terraform infrastructure based on your sel
|
|
|
10
10
|
The CDK construct is created in `common/constructs`. Example usage:
|
|
11
11
|
|
|
12
12
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
13
|
-
import { MyTable } from '
|
|
13
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
14
14
|
|
|
15
15
|
export class ApplicationStack extends Stack {
|
|
16
16
|
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
@@ -62,7 +62,7 @@ Disable it for environments where table deletion is expected, such as short-live
|
|
|
62
62
|
<Fragment slot="cdk">
|
|
63
63
|
|
|
64
64
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
65
|
-
import { MyTable } from '
|
|
65
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
66
66
|
|
|
67
67
|
const table = new MyTable(this, 'Table', {
|
|
68
68
|
deletionProtection: false,
|
|
@@ -89,7 +89,7 @@ The table defaults to on-demand (`PAY_PER_REQUEST`) billing. Switch to provision
|
|
|
89
89
|
|
|
90
90
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
91
91
|
import { BillingMode } from 'aws-cdk-lib/aws-dynamodb';
|
|
92
|
-
import { MyTable } from '
|
|
92
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
93
93
|
|
|
94
94
|
const table = new MyTable(this, 'Table', {
|
|
95
95
|
billingMode: BillingMode.PROVISIONED,
|
|
@@ -119,7 +119,7 @@ module "my_table" {
|
|
|
119
119
|
<Fragment slot="cdk">
|
|
120
120
|
|
|
121
121
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
122
|
-
import { MyTable } from '
|
|
122
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
123
123
|
|
|
124
124
|
const table = new MyTable(this, 'Table', {
|
|
125
125
|
pointInTimeRecoverySpecification: { pointInTimeRecoveryEnabled: false },
|
|
@@ -147,7 +147,7 @@ The KMS key used to encrypt the table has automatic key rotation enabled by defa
|
|
|
147
147
|
<Fragment slot="cdk">
|
|
148
148
|
|
|
149
149
|
```ts title="packages/infra/src/stacks/application-stack.ts"
|
|
150
|
-
import { MyTable } from '
|
|
150
|
+
import { MyTable } from '@my-scope/common-constructs';
|
|
151
151
|
|
|
152
152
|
const table = new MyTable(this, 'Table', {
|
|
153
153
|
enableKeyRotation: false,
|