|
| 1 | +# Salesforce CLI Plugin Lightning Dev - Cursor Rules |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +This is a Salesforce CLI plugin for Lightning development tools (LEX, Mobile, and Experience Sites). It's built with TypeScript, uses yarn for package management, and leverages wireit for intelligent build caching and task orchestration. |
| 6 | + |
| 7 | +## Key Technologies |
| 8 | + |
| 9 | +- **TypeScript**: Primary language for the plugin |
| 10 | +- **Wireit**: Build task orchestration with intelligent caching |
| 11 | +- **Yarn**: Package manager (v1.22.22 as specified in volta config) |
| 12 | +- **Node.js**: Runtime (v20.11.0 as specified in volta config) |
| 13 | +- **Salesforce CLI (sf)**: The platform this plugin extends |
| 14 | +- **Lightning Web Components (LWC)**: Core technology for component development |
| 15 | +- **Jest/Mocha**: Testing frameworks |
| 16 | + |
| 17 | +## Understanding Wireit Caching |
| 18 | + |
| 19 | +### What is Wireit? |
| 20 | + |
| 21 | +Wireit is a build orchestration tool that provides: |
| 22 | + |
| 23 | +- **Incremental builds**: Only rebuilds what has changed |
| 24 | +- **Intelligent caching**: Stores build outputs in `.wireit/` directory |
| 25 | +- **Task dependencies**: Automatically runs dependent tasks in correct order |
| 26 | +- **Parallel execution**: Runs independent tasks concurrently |
| 27 | + |
| 28 | +### Wireit Cache Location |
| 29 | + |
| 30 | +- Cache is stored in `.wireit/` directory at the project root |
| 31 | +- Contains fingerprints and outputs from previous builds |
| 32 | +- Can become corrupted or inconsistent, leading to build errors |
| 33 | + |
| 34 | +### Common Wireit Tasks in This Project |
| 35 | + |
| 36 | +- `build`: Main build task (depends on compile + lint) |
| 37 | +- `compile`: TypeScript compilation with incremental builds |
| 38 | +- `lint`: ESLint with caching |
| 39 | +- `test`: Comprehensive testing including unit tests, command reference, deprecation policy |
| 40 | +- `format`: Prettier formatting |
| 41 | + |
| 42 | +## Troubleshooting Build Issues |
| 43 | + |
| 44 | +### When to Run `clean-all` |
| 45 | + |
| 46 | +Run `yarn clean-all` when experiencing: |
| 47 | + |
| 48 | +- **Mysterious TypeScript errors** that don't match the actual code |
| 49 | +- **Outdated build outputs** not reflecting recent changes |
| 50 | +- **Wireit dependency errors** or inconsistent cache states |
| 51 | +- **"Cannot find module" errors** for modules that clearly exist |
| 52 | +- **Incremental builds failing** but full rebuilds work |
| 53 | +- **Test failures** that don't reproduce when running tests individually |
| 54 | +- **Linting errors** on unchanged files |
| 55 | + |
| 56 | +### The `clean-all` Process |
| 57 | + |
| 58 | +```bash |
| 59 | +# This command cleans ALL build artifacts and caches |
| 60 | +yarn clean-all |
| 61 | +``` |
| 62 | + |
| 63 | +What `clean-all` does: |
| 64 | + |
| 65 | +- Runs `sf-clean all` which removes: |
| 66 | + - `lib/` directory (compiled output) |
| 67 | + - `.wireit/` directory (all cached tasks and fingerprints) |
| 68 | + - `*.tsbuildinfo` files (TypeScript incremental compilation cache) |
| 69 | + - `.eslintcache` file (ESLint cache) |
| 70 | + - Other temporary build artifacts |
| 71 | + |
| 72 | +### Post-Cleanup Setup |
| 73 | + |
| 74 | +**CRITICAL**: After running `clean-all`, you must re-setup the environment: |
| 75 | + |
| 76 | +```bash |
| 77 | +# Always run these commands after clean-all |
| 78 | +yarn install && yarn build |
| 79 | +``` |
| 80 | + |
| 81 | +Why both commands are needed: |
| 82 | + |
| 83 | +1. `yarn install`: Ensures all dependencies are properly installed and linked |
| 84 | +2. `yarn build`: Rebuilds all artifacts and re-populates wireit cache |
| 85 | + |
| 86 | +### Alternative Cleaning Options |
| 87 | + |
| 88 | +- `yarn clean`: Light cleanup (preserves some caches) |
| 89 | +- Individual task clearing: Delete specific folders in `.wireit/` if you know which task is problematic |
| 90 | + |
| 91 | +## Development Workflow Best Practices |
| 92 | + |
| 93 | +### Starting Development |
| 94 | + |
| 95 | +```bash |
| 96 | +# Fresh start (if needed) |
| 97 | +yarn clean-all |
| 98 | +yarn install && yarn build |
| 99 | + |
| 100 | +# Normal development |
| 101 | +yarn build # Builds incrementally using wireit cache |
| 102 | +``` |
| 103 | + |
| 104 | +### Running Tests |
| 105 | + |
| 106 | +```bash |
| 107 | +yarn test # Full test suite with all checks |
| 108 | +yarn test:only # Just unit tests |
| 109 | +yarn test:nuts # Integration tests (slower) |
| 110 | +``` |
| 111 | + |
| 112 | +### Local Development |
| 113 | + |
| 114 | +```bash |
| 115 | +# Use local dev command instead of global sf |
| 116 | +./bin/dev lightning dev component |
| 117 | +./bin/dev lightning dev site |
| 118 | +./bin/dev lightning dev app |
| 119 | +``` |
| 120 | + |
| 121 | +### Linking for Testing |
| 122 | + |
| 123 | +```bash |
| 124 | +# Link plugin to global sf CLI for testing |
| 125 | +sf plugins link . |
| 126 | +sf plugins # Verify plugin is linked |
| 127 | +``` |
| 128 | + |
| 129 | +## Project-Specific Context |
| 130 | + |
| 131 | +### Lightning Development Commands |
| 132 | + |
| 133 | +This plugin provides three main commands: |
| 134 | + |
| 135 | +- `sf lightning dev component`: Preview LWC components locally |
| 136 | +- `sf lightning dev site`: Preview Experience Cloud sites locally |
| 137 | +- `sf lightning dev app`: Preview Lightning apps locally |
| 138 | + |
| 139 | +### LWR (Lightning Web Runtime) Integration |
| 140 | + |
| 141 | +- Uses LWR for server-side rendering and local development |
| 142 | +- Has special yarn scripts for linking/unlinking LWR dependencies |
| 143 | +- `__lwr_cache__/` directory stores LWR-specific cache |
| 144 | + |
| 145 | +### API Version Management |
| 146 | + |
| 147 | +- Supports multiple Salesforce API versions (62.0-65.0) |
| 148 | +- Has version mappings in `apiVersionMetadata` in package.json |
| 149 | +- Different tags target different org versions |
| 150 | + |
| 151 | +## File Structure Understanding |
| 152 | + |
| 153 | +### Key Directories |
| 154 | + |
| 155 | +- `src/`: Source TypeScript files |
| 156 | +- `lib/`: Compiled JavaScript output (generated) |
| 157 | +- `test/`: All test files (.test.ts, .nut.ts) |
| 158 | +- `messages/`: CLI command help text and internationalization |
| 159 | +- `.wireit/`: Build cache (can be safely deleted) |
| 160 | + |
| 161 | +### Important Files |
| 162 | + |
| 163 | +- `package.json`: Contains all wireit task definitions |
| 164 | +- `tsconfig.json`: TypeScript configuration |
| 165 | +- `lwc.config.json`: Lightning Web Components configuration |
| 166 | +- `.eslintcache`: ESLint cache file |
| 167 | + |
| 168 | +## Coding Guidelines |
| 169 | + |
| 170 | +### TypeScript Standards |
| 171 | + |
| 172 | +- Use strict TypeScript compilation settings |
| 173 | +- Follow Salesforce coding standards |
| 174 | +- Prefer explicit types over `any` |
| 175 | +- Use proper JSDoc comments for CLI commands |
| 176 | + |
| 177 | +### Testing Requirements |
| 178 | + |
| 179 | +- Unit tests for all new functionality |
| 180 | +- Integration tests (nuts) for CLI commands |
| 181 | +- Minimum 95% code coverage requirement |
| 182 | +- Mock external dependencies appropriately |
| 183 | + |
| 184 | +### CLI Command Development |
| 185 | + |
| 186 | +- Follow oclif patterns for command structure |
| 187 | +- Use proper message files for user-facing text |
| 188 | +- Include comprehensive help text and examples |
| 189 | +- Handle errors gracefully with user-friendly messages |
| 190 | + |
| 191 | +## Common Pitfalls to Avoid |
| 192 | + |
| 193 | +1. **Don't commit build artifacts**: `lib/` directory should never be committed |
| 194 | +2. **Don't ignore wireit cache issues**: If builds seem wrong, clean and rebuild |
| 195 | +3. **Don't skip the yarn install step**: After `clean-all`, always reinstall dependencies |
| 196 | +4. **Don't modify generated files**: Focus changes on `src/` directory |
| 197 | +5. **Don't use global sf CLI for development**: Use `./bin/dev` for local testing |
| 198 | + |
| 199 | +## Emergency Troubleshooting |
| 200 | + |
| 201 | +If everything seems broken: |
| 202 | + |
| 203 | +```bash |
| 204 | +# Nuclear option - start completely fresh |
| 205 | +rm -rf node_modules .wireit lib *.tsbuildinfo .eslintcache |
| 206 | +yarn install |
| 207 | +yarn build |
| 208 | +``` |
| 209 | + |
| 210 | +If wireit tasks seem stuck or corrupted: |
| 211 | + |
| 212 | +```bash |
| 213 | +# Just clear wireit cache |
| 214 | +rm -rf .wireit |
| 215 | +yarn build |
| 216 | +``` |
| 217 | + |
| 218 | +Remember: **When in doubt, `yarn clean-all && yarn install && yarn build`** - this solves 90% of build-related issues in this project. |
0 commit comments