|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is the **Power Platform VS Code extension** that provides tooling for creating, building, and deploying Power Platform solutions, packages, and Power Pages portals. The extension integrates the Power Platform CLI (pac) directly into VS Code and supports both desktop and web (vscode.dev) environments. |
| 8 | + |
| 9 | +**Important**: Always refer to `.github/instructions/memory-bank.instructions.md` for the latest architecture details and coding guidelines. |
| 10 | + |
| 11 | +## Build Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Initial setup |
| 15 | +npm ci # Clean install dependencies |
| 16 | +gulp ci # Full CI build |
| 17 | + |
| 18 | +# Development builds |
| 19 | +npm run build # Full build using gulp (same as running 'gulp') |
| 20 | +npm run compile-web # Build web version only (webpack) |
| 21 | +npm run watch-web # Watch mode for web development |
| 22 | + |
| 23 | +# Testing |
| 24 | +npm run test # Run unit tests |
| 25 | +npm run test-desktop-int # Run desktop integration tests |
| 26 | +npm run test-web-integration # Run web integration tests |
| 27 | +npm run test-common-int # Run common integration tests |
| 28 | +npm run coverage # Run tests with coverage |
| 29 | + |
| 30 | +# Linting |
| 31 | +gulp lint # Run ESLint (part of build process) |
| 32 | + |
| 33 | +# Package creation |
| 34 | +npm run dist # Create VSIX package for distribution |
| 35 | +``` |
| 36 | + |
| 37 | +## Architecture Overview |
| 38 | + |
| 39 | +### Multi-Target Build System |
| 40 | + |
| 41 | +The extension uses **webpack** with three distinct build targets: |
| 42 | + |
| 43 | +1. **Desktop Extension** (`src/client/extension.ts`) - Main VS Code extension |
| 44 | +2. **Web Extension** (`src/web/extension.ts`) - VS Code for Web support |
| 45 | +3. **Language Servers** (`src/server/`) - HTML/Liquid and YAML language servers |
| 46 | + |
| 47 | +Build configuration is in `webpack.config.js` with task orchestration via `gulpfile.mjs`. |
| 48 | + |
| 49 | +### Key Directory Structure |
| 50 | + |
| 51 | +- **`src/client/`** - Desktop extension code |
| 52 | + - `extension.ts` - Main entry point |
| 53 | + - `lib/` - Core libraries (CLI acquisition, PAC wrapper) |
| 54 | + - `pac/` - Power Platform CLI integration |
| 55 | + - `power-pages/` - Power Pages specific features |
| 56 | + - `actions-hub/` - Power Pages Actions Hub tree view |
| 57 | + - `metadata-diff/` - Compare local vs environment changes |
| 58 | + - `uriHandler/` - Deep link handling (vscode://... URIs) |
| 59 | + |
| 60 | +- **`src/web/`** - Web extension code (VS Code for Web) |
| 61 | + - Shares common utilities with desktop but has web-specific implementations |
| 62 | + |
| 63 | +- **`src/server/`** - Language server implementations |
| 64 | + - `YamlServer.ts` - YAML language features |
| 65 | + - `HtmlServer.ts` - HTML/Liquid language features |
| 66 | + |
| 67 | +- **`src/debugger/`** - PCF (Power Apps Component Framework) debugging support |
| 68 | + |
| 69 | +- **`src/common/`** - Shared code between desktop/web |
| 70 | + - `services/` - Core services (ArtemisService, BAPService, PPAPIService) |
| 71 | + - `utilities/` - Shared utilities |
| 72 | + - `OneDSLoggerTelemetry/` - Telemetry infrastructure |
| 73 | + - `ecs-features/` - Feature flag management |
| 74 | + |
| 75 | +### PAC CLI Integration |
| 76 | + |
| 77 | +The extension **automatically downloads and manages** the Power Platform CLI: |
| 78 | + |
| 79 | +- CLI acquisition: `src/client/lib/CliAcquisition.ts` |
| 80 | +- CLI wrapper: `src/client/pac/PacWrapper.ts` |
| 81 | +- CLI context: `src/client/pac/PacContext.ts` |
| 82 | + |
| 83 | +Always use `PacWrapper` for CLI operations: |
| 84 | + |
| 85 | +```typescript |
| 86 | +const pacWrapper = new PacWrapper(context); |
| 87 | +await pacWrapper.executeCommand(['solution', 'list']); |
| 88 | +``` |
| 89 | + |
| 90 | +### Service Architecture |
| 91 | + |
| 92 | +Three core services handle Power Platform API communication: |
| 93 | + |
| 94 | +1. **ArtemisService** - Power Pages specific APIs |
| 95 | +2. **BAPService** - Business Application Platform APIs |
| 96 | +3. **PPAPIService** - Power Platform APIs |
| 97 | + |
| 98 | +All services use `AuthenticationProvider` for Microsoft authentication. |
| 99 | + |
| 100 | +### Telemetry System |
| 101 | + |
| 102 | +Comprehensive telemetry using **OneDSLogger**: |
| 103 | + |
| 104 | +- Wrapper: `src/common/OneDSLoggerTelemetry/OneDSLoggerWrapper.ts` |
| 105 | +- Constants: `src/common/OneDSLoggerTelemetry/telemetryConstants.ts` |
| 106 | +- Separate tracking for desktop vs web experiences |
| 107 | +- Use `oneDSLoggerWrapper.getLogger()` for all telemetry events |
| 108 | + |
| 109 | +## Coding Standards |
| 110 | + |
| 111 | +### Style Guidelines (CRITICAL) |
| 112 | + |
| 113 | +- **Indentation**: 4 spaces (NO TABS) |
| 114 | +- **Functions**: Arrow functions `=>` preferred over anonymous functions |
| 115 | +- **Braces**: Same line, always use for loops/conditionals |
| 116 | +- **Parentheses**: No whitespace inside - `for (let i = 0; i < 10; i++)` |
| 117 | + |
| 118 | +### Naming Conventions |
| 119 | + |
| 120 | +- **PascalCase**: Types, interfaces, enums, enum values, classes |
| 121 | +- **camelCase**: Functions, methods, properties, local variables |
| 122 | +- **UPPER_CASE**: Constants |
| 123 | +- Use descriptive, whole words |
| 124 | + |
| 125 | +### String Literals & Localization |
| 126 | + |
| 127 | +- **"double quotes"**: User-facing strings needing localization |
| 128 | +- **'single quotes'**: Internal/technical strings |
| 129 | +- **ALL user-visible strings MUST be externalized** using `vscode-nls` |
| 130 | + |
| 131 | +### Comments & Documentation |
| 132 | + |
| 133 | +- Use **JSDoc** for functions, interfaces, enums, classes |
| 134 | +- Include parameter descriptions and return types |
| 135 | +- NO `//Arrange`, `//Act`, `//Assert` comments in tests |
| 136 | + |
| 137 | +## Testing Patterns |
| 138 | + |
| 139 | +### Framework |
| 140 | + |
| 141 | +- **Mocha** test framework |
| 142 | +- **Chai** assertions (use `expect`, not `assert`) |
| 143 | +- **Sinon** for stubs/spies/mocks |
| 144 | + |
| 145 | +### Test Organization |
| 146 | + |
| 147 | +- Unit tests: `src/*/test/unit/` |
| 148 | +- Integration tests: `src/*/test/integration/` |
| 149 | +- Mock dependencies extensively for unit tests |
| 150 | + |
| 151 | +### Running Single Tests |
| 152 | + |
| 153 | +```bash |
| 154 | +# Desktop integration test |
| 155 | +npm run test-desktop-int -- --grep "test name pattern" |
| 156 | + |
| 157 | +# Unit test |
| 158 | +npm run test -- --grep "test name pattern" |
| 159 | +``` |
| 160 | + |
| 161 | +## Power Platform Specific Patterns |
| 162 | + |
| 163 | +### Power Pages File Extensions |
| 164 | + |
| 165 | +Portal files use specific extensions (see `src/common/constants.ts`): |
| 166 | + |
| 167 | +- `.copy.html` - HTML content |
| 168 | +- `.custom_javascript.js` - Custom JavaScript |
| 169 | +- `.en-US.customcss.css` - Localized CSS |
| 170 | +- File callbacks: `src/client/power-pages/fileSystemCallbacks.ts` |
| 171 | + |
| 172 | +### Power Pages Actions Hub |
| 173 | + |
| 174 | +Tree view provider for managing Power Pages sites: |
| 175 | + |
| 176 | +- Main provider: `src/client/power-pages/actions-hub/ActionsHubTreeDataProvider.ts` |
| 177 | +- Tree items: `src/client/power-pages/actions-hub/tree-items/` |
| 178 | +- Handlers: `src/client/power-pages/actions-hub/handlers/` |
| 179 | +- Current site context: `src/client/power-pages/actions-hub/CurrentSiteContext.ts` |
| 180 | + |
| 181 | +### Metadata Diff Feature |
| 182 | + |
| 183 | +Compare local Power Pages files with environment: |
| 184 | + |
| 185 | +- Implementation: `src/client/power-pages/metadata-diff/` |
| 186 | +- Supports multiple comparison operations |
| 187 | +- Export/import comparison results |
| 188 | +- Tree and list view modes |
| 189 | + |
| 190 | +### Feature Flags |
| 191 | + |
| 192 | +Managed via ECS (Experimentation and Configuration Service): |
| 193 | + |
| 194 | +- Configuration: `src/common/ecs-features/ecsFeatureGates.ts` |
| 195 | +- Use feature flags to control rollout of new features |
| 196 | +- Example: `enableMetadataDiff`, `enableActionsHub` |
| 197 | + |
| 198 | +## Debugging the Extension |
| 199 | + |
| 200 | +Use VS Code's built-in debugging: |
| 201 | + |
| 202 | +1. Open repository in VS Code |
| 203 | +2. Select **"Launch VSCode Extension"** from Run/Debug dropdown |
| 204 | +3. Press **F5** to start debugging |
| 205 | +4. New VS Code window opens with extension loaded |
| 206 | + |
| 207 | +For web extension debugging, use **"Launch Web Extension"** configuration. |
| 208 | + |
| 209 | +## Common Patterns & Gotchas |
| 210 | + |
| 211 | +### Cross-Platform Considerations |
| 212 | + |
| 213 | +- Extension runs on Windows, macOS, Linux |
| 214 | +- PAC CLI has platform-specific binaries (`.exe` on Windows) |
| 215 | +- Use `path.join()` for file paths, never hardcode separators |
| 216 | +- Test on multiple platforms when dealing with file system operations |
| 217 | + |
| 218 | +### Authentication Flow |
| 219 | + |
| 220 | +- Uses VS Code's built-in authentication API |
| 221 | +- Provider ID: `PROVIDER_ID` from `src/common/services/AuthenticationProvider.ts` |
| 222 | +- Silent auth attempted first, interactive only when needed |
| 223 | +- Multiple cloud support: Public, USGov, USGovHigh, USGovDoD, China |
| 224 | + |
| 225 | +### Webpack Build Quirks |
| 226 | + |
| 227 | +- Known issue: Windows-style paths in localization (fixed with `gulp-replace` in build) |
| 228 | +- Webpack externals configured for VS Code API and telemetry dependencies |
| 229 | +- Three separate webpack configs for different targets |
| 230 | + |
| 231 | +### Memory Bank System |
| 232 | + |
| 233 | +If you see references to "memory bank" files in `.github/instructions/memory-bank.instructions.md`, this is documentation for GitHub Copilot's memory system. These files contain project context and should be maintained when making architectural changes. |
| 234 | + |
| 235 | +## Dependencies & Version Management |
| 236 | + |
| 237 | +### npm Overrides |
| 238 | + |
| 239 | +The project uses npm `overrides` in package.json to force transitive dependencies to secure versions. When adding dependencies, verify they don't introduce vulnerabilities. |
| 240 | + |
| 241 | +### Major Dependencies |
| 242 | + |
| 243 | +- `vscode` engine: ^1.91.0 |
| 244 | +- `@microsoft/generator-powerpages` - Yeoman generator for Power Pages |
| 245 | +- `puppeteer-core` - PCF debugging |
| 246 | +- `fluid-framework` - Collaborative features |
| 247 | +- `webpack` - Bundling |
| 248 | + |
| 249 | +### Updating Dependencies |
| 250 | + |
| 251 | +```bash |
| 252 | +npm outdated # Check for updates |
| 253 | +npm audit # Check for vulnerabilities |
| 254 | +npm audit fix # Auto-fix vulnerabilities (safe) |
| 255 | +``` |
| 256 | + |
| 257 | +## Pull Request & Commit Guidelines |
| 258 | + |
| 259 | +When creating commits: |
| 260 | + |
| 261 | +- Use descriptive commit messages |
| 262 | +- Include Co-Authored-By for pair programming |
| 263 | +- Reference issue numbers when applicable |
| 264 | +- Run `npm run build` and `npm run test` before committing |
| 265 | + |
| 266 | +Standard commit format: |
| 267 | +``` |
| 268 | +Brief description of change |
| 269 | +
|
| 270 | +- Detailed bullet points of changes |
| 271 | +- References to related issues |
| 272 | +
|
| 273 | +🤖 Generated with [Claude Code](https://claude.com/claude-code) |
| 274 | +
|
| 275 | +Co-Authored-By: Name <email> |
| 276 | +``` |
| 277 | + |
| 278 | +## Resources |
| 279 | + |
| 280 | +- [Power Platform CLI Documentation](https://learn.microsoft.com/power-platform/developer/cli/introduction) |
| 281 | +- Issue tracker: https://github.com/microsoft/powerplatform-vscode/issues |
| 282 | +- Contributing guidelines: CONTRIBUTING.md |
| 283 | +- Security policy: SECURITY.md |
0 commit comments