|
| 1 | +# Local Development Setup |
| 2 | + |
| 3 | +This guide explains how to set up the agentcore-cli for local development when the L3 constructs package is not yet published to npm. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js >= 20 |
| 8 | +- npm |
| 9 | +- Both packages cloned as siblings: |
| 10 | + ``` |
| 11 | + workspace/ |
| 12 | + ├── agentcore-cli/ |
| 13 | + └── agentcore-l3-cdk-constructs/ |
| 14 | + ``` |
| 15 | + |
| 16 | +## Setup Steps |
| 17 | + |
| 18 | +### 1. Install and Build the L3 Constructs Package |
| 19 | + |
| 20 | +```bash |
| 21 | +cd agentcore-l3-cdk-constructs |
| 22 | +npm install |
| 23 | +npm run build |
| 24 | +``` |
| 25 | + |
| 26 | +### 2. Create Global npm Link |
| 27 | + |
| 28 | +```bash |
| 29 | +npm link |
| 30 | +``` |
| 31 | + |
| 32 | +This creates a global symlink that makes `@aws/agentcore-l3-cdk-constructs` available to other local projects. |
| 33 | + |
| 34 | +### 3. Build the CLI |
| 35 | + |
| 36 | +```bash |
| 37 | +cd ../agentcore-cli |
| 38 | +npm install |
| 39 | +npm run build |
| 40 | +``` |
| 41 | + |
| 42 | +### 4. Create a Test Project |
| 43 | + |
| 44 | +```bash |
| 45 | +npm run cli create |
| 46 | +``` |
| 47 | + |
| 48 | +Follow the prompts to create a new project. |
| 49 | + |
| 50 | +### 5. Link the L3 Constructs in the Generated Project |
| 51 | + |
| 52 | +The generated CDK project includes a postinstall script that automatically attempts to link `@aws/agentcore-l3-cdk-constructs`. However, if npm install was run before you created the global link, you may need to manually link it: |
| 53 | + |
| 54 | +```bash |
| 55 | +cd <your-project>/agentcore/cdk |
| 56 | +npm link @aws/agentcore-l3-cdk-constructs |
| 57 | +``` |
| 58 | + |
| 59 | +Alternatively, you can re-run npm install to trigger the postinstall script: |
| 60 | + |
| 61 | +```bash |
| 62 | +npm install |
| 63 | +``` |
| 64 | + |
| 65 | +### 6. Build and Test |
| 66 | + |
| 67 | +```bash |
| 68 | +npm run build |
| 69 | +``` |
| 70 | + |
| 71 | +## How npm link Works |
| 72 | + |
| 73 | +1. `npm link` in the L3 package creates a global symlink |
| 74 | +2. `npm link @aws/agentcore-l3-cdk-constructs` in the CDK project creates a local symlink to the global one |
| 75 | +3. Changes to the L3 package are immediately reflected (after rebuilding) |
| 76 | + |
| 77 | +## Troubleshooting |
| 78 | + |
| 79 | +### "Cannot find module" errors |
| 80 | + |
| 81 | +Make sure you've built the L3 constructs package: |
| 82 | +```bash |
| 83 | +cd agentcore-l3-cdk-constructs |
| 84 | +npm run build |
| 85 | +``` |
| 86 | + |
| 87 | +### Link not working |
| 88 | + |
| 89 | +Re-create the links: |
| 90 | +```bash |
| 91 | +# In L3 constructs |
| 92 | +npm unlink |
| 93 | +npm link |
| 94 | + |
| 95 | +# In generated CDK project |
| 96 | +npm unlink @aws/agentcore-l3-cdk-constructs |
| 97 | +npm link @aws/agentcore-l3-cdk-constructs |
| 98 | +``` |
| 99 | + |
| 100 | +### Changes not reflected |
| 101 | + |
| 102 | +Rebuild the L3 constructs package: |
| 103 | +```bash |
| 104 | +cd agentcore-l3-cdk-constructs |
| 105 | +npm run build |
| 106 | +``` |
| 107 | + |
| 108 | +## Alternative: Using LOCAL_L3_PATH |
| 109 | + |
| 110 | +If you prefer, you can set the `LOCAL_L3_PATH` environment variable before running create: |
| 111 | + |
| 112 | +```bash |
| 113 | +# Windows PowerShell |
| 114 | +$env:LOCAL_L3_PATH = "C:\path\to\agentcore-l3-cdk-constructs" |
| 115 | +npm run cli create |
| 116 | + |
| 117 | +# Windows CMD |
| 118 | +set LOCAL_L3_PATH=C:\path\to\agentcore-l3-cdk-constructs |
| 119 | +npm run cli create |
| 120 | +``` |
| 121 | + |
| 122 | +This will automatically use `file:` protocol in package.json instead of requiring npm link. |
0 commit comments