|
| 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 | +VSIX Manifest Designer is a VS Code extension that provides a visual designer for VS Code extension manifest (`package.json`) files using the Custom Editor API. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +npm run install:all # Install all dependencies (root + webview-ui) |
| 13 | +npm run compile # Build extension and webview |
| 14 | +npm run compile:extension # Build extension only |
| 15 | +npm run compile:webview # Build webview only |
| 16 | +npm run watch # Watch extension for changes |
| 17 | +npm run watch:webview # Watch webview for changes (dev server) |
| 18 | +npm run package # Create VSIX package |
| 19 | +``` |
| 20 | + |
| 21 | +## Development |
| 22 | + |
| 23 | +1. Run `npm run install:all` to install all dependencies |
| 24 | +2. Run `npm run compile` to build everything |
| 25 | +3. Press F5 in VS Code to launch the Extension Development Host |
| 26 | + |
| 27 | +For webview development, run `npm run watch:webview` in a separate terminal for hot reload. |
| 28 | + |
| 29 | +## Architecture |
| 30 | + |
| 31 | +``` |
| 32 | +src/ # Extension code (TypeScript) |
| 33 | +├── extension.ts # Extension entry point |
| 34 | +├── editor/ |
| 35 | +│ └── ManifestEditorProvider.ts # Custom editor provider |
| 36 | +├── models/ |
| 37 | +│ ├── index.ts # Model exports |
| 38 | +│ └── VscodeManifest.ts # TypeScript interfaces for manifest |
| 39 | +├── services/ |
| 40 | +│ ├── index.ts # Service exports |
| 41 | +│ ├── ManifestService.ts # Parse/serialize with round-trip preservation |
| 42 | +│ └── ValidationService.ts # Field validation |
| 43 | +└── webview/ |
| 44 | + ├── getNonce.ts # CSP nonce generator |
| 45 | + └── getWebviewContent.ts # Webview HTML generator (loads Svelte bundle) |
| 46 | +
|
| 47 | +webview-ui/ # Webview code (Svelte + Vite) |
| 48 | +├── src/ |
| 49 | +│ ├── main.ts # Svelte app entry point |
| 50 | +│ ├── App.svelte # Root component |
| 51 | +│ ├── stores/ |
| 52 | +│ │ └── manifestStore.ts # Svelte stores for state management |
| 53 | +│ ├── components/ |
| 54 | +│ │ ├── Navigation.svelte # Sidebar navigation |
| 55 | +│ │ └── views/ |
| 56 | +│ │ └── MetadataView.svelte # Metadata editing view |
| 57 | +│ └── styles/ |
| 58 | +│ └── global.css # Global styles with VS Code theming |
| 59 | +├── vite.config.ts # Vite build configuration |
| 60 | +└── package.json # Webview dependencies |
| 61 | +
|
| 62 | +out/ # Build output |
| 63 | +├── extension.js # Bundled extension |
| 64 | +└── webview/ |
| 65 | + ├── main.js # Bundled Svelte app |
| 66 | + └── assets/ |
| 67 | + └── main.css # Extracted CSS |
| 68 | +``` |
| 69 | + |
| 70 | +### Models |
| 71 | + |
| 72 | +**VscodeManifest.ts** defines TypeScript interfaces for all VS Code extension manifest fields: |
| 73 | +- Core fields: name, version, publisher, engines |
| 74 | +- Display: displayName, description, icon, categories |
| 75 | +- Contributions: commands, configuration, menus, keybindings, views, languages, grammars, themes, snippets, custom editors, and more |
| 76 | +- Marketplace: galleryBanner, badges, repository |
| 77 | + |
| 78 | +### Services |
| 79 | + |
| 80 | +**ManifestService** handles parsing and serialization: |
| 81 | +- `parse(content)` - Parse JSON to VscodeManifest, detect indentation |
| 82 | +- `serialize(manifest, options)` - Convert back to JSON preserving formatting |
| 83 | +- `update(original, updates)` - Merge updates without losing other fields |
| 84 | +- `detectExtension(manifest)` - Check if package.json is a VS Code extension |
| 85 | +- `initializeAsExtension(manifest)` - Add minimal extension fields |
| 86 | + |
| 87 | +**ValidationService** validates manifest fields: |
| 88 | +- `validate(manifest)` - Full validation returning errors/warnings/info |
| 89 | +- `validateField(field, value)` - Single field validation |
| 90 | +- Checks: required fields, formats (semver, npm name), categories, commands, configuration, activation events, best practices |
| 91 | + |
| 92 | +### Webview UI (Svelte) |
| 93 | + |
| 94 | +The webview is built with Svelte + Vite for a reactive, component-based UI. |
| 95 | + |
| 96 | +**Stores** (`manifestStore.ts`): |
| 97 | +- `manifestStore` - Main store with manifest data, validation, detection status |
| 98 | +- `navigationStore` - Current view selection |
| 99 | +- Helper functions: `postMessage()`, `getVsCodeApi()` |
| 100 | + |
| 101 | +**Views**: |
| 102 | +- `MetadataView` - Edit name, displayName, version, publisher, description, categories, icon, galleryBanner, keywords |
| 103 | +- Placeholder views for: Activation, Contributions, Capabilities, Marketplace |
| 104 | + |
| 105 | +**Theming**: Uses VS Code CSS custom properties (`--vscode-*`) for seamless theme integration. |
| 106 | + |
| 107 | +## Key Patterns |
| 108 | + |
| 109 | +### Custom Editor Registration |
| 110 | + |
| 111 | +The extension uses `vscode.window.registerCustomEditorProvider` with: |
| 112 | +- View type: `vsixManifestDesigner.editor` |
| 113 | +- Priority: `option` (user can choose to open with designer) |
| 114 | +- File pattern: `package.json` |
| 115 | + |
| 116 | +### Webview Communication |
| 117 | + |
| 118 | +Messages from extension to webview: |
| 119 | +- `update` - Parsed manifest, detection result, validation result |
| 120 | +- `parseError` - JSON parse error with line/column |
| 121 | + |
| 122 | +Messages from webview to extension: |
| 123 | +- `ready` - Webview initialized, request data |
| 124 | +- `edit` - Raw content edit |
| 125 | +- `updateManifest` - Partial manifest updates (preserves other fields) |
| 126 | +- `initializeAsExtension` - Add engines.vscode, contributes, activationEvents |
| 127 | +- `closeEditor` - Close designer, open with default editor |
| 128 | + |
| 129 | +### Round-Trip Preservation |
| 130 | + |
| 131 | +ManifestService preserves: |
| 132 | +- Original indentation (spaces or tabs) |
| 133 | +- Trailing newline presence |
| 134 | +- Non-extension fields (scripts, dependencies, etc.) |
| 135 | + |
| 136 | +### Extension Detection |
| 137 | + |
| 138 | +A package.json is considered a VS Code extension if it has any of: |
| 139 | +- `engines.vscode` |
| 140 | +- `contributes` (non-empty) |
| 141 | +- `activationEvents` (non-empty) |
| 142 | + |
| 143 | +If none are present, webview offers to initialize as extension or close. |
| 144 | + |
| 145 | +### Content Security Policy |
| 146 | + |
| 147 | +Webview uses strict CSP with nonce-based script execution for security. |
| 148 | + |
| 149 | +## Testing |
| 150 | + |
| 151 | +To test the extension: |
| 152 | +1. Run `npm run install:all` and `npm run compile` |
| 153 | +2. Press F5 to launch Extension Development Host |
| 154 | +3. Open a folder with a `package.json` file |
| 155 | +4. Right-click the `package.json` file |
| 156 | +5. Select "Open With..." > "Extension Manifest Designer" |
| 157 | +6. For VS Code extension manifests: see Metadata view with validation |
| 158 | +7. For regular package.json: see prompt to initialize or close |
0 commit comments