Skip to content

Commit b99597f

Browse files
committed
Refactor webview packages and improve build setup
- Rename packages/shared to packages/webview-shared - Use @repo namespace for internal packages - Move api.ts out of react folder (not React-specific) - Move tsconfig.webview.json to packages folder for sharing - Fix tsBuildInfoFile location to prevent stale build issues - Add concurrently for watch:all command - Add warnOnUnassignedImports to ESLint for CSS import ordering - Remove unnecessary visibility handler from TasksPanel - Add title parameter to getWebviewHtml - Add index.css placeholder to tasks package - Rename vite config helper to avoid Vitest detection
1 parent 9b458f9 commit b99597f

25 files changed

+100
-77
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ organized as a pnpm workspace in `packages/`.
7575

7676
```text
7777
packages/
78-
├── shared/ # Shared types, React hooks, and Vite config
78+
├── webview-shared/ # Shared types, React hooks, and Vite config
7979
│ └── extension.d.ts # Types exposed to extension (excludes React)
80-
└── tasks/ # Example webview (copy this for new webviews)
80+
└── tasks/ # Example webview (copy this for new webviews)
8181
8282
src/webviews/
8383
├── util.ts # getWebviewHtml() helper
@@ -86,16 +86,15 @@ src/webviews/
8686

8787
Key patterns:
8888

89-
- **Type sharing**: Extension imports types from `@coder/shared` via path mapping
90-
to `extension.d.ts`. Webviews import directly from `@coder/shared/react`.
89+
- **Type sharing**: Extension imports types from `@repo/webview-shared` via path mapping
90+
to `extension.d.ts`. Webviews import directly from `@repo/webview-shared/react`.
9191
- **Message passing**: Use `postMessage()`/`useMessage()` hooks for communication.
9292
- **Lifecycle**: Dispose event listeners properly (see `TasksPanel.ts` for example).
9393

9494
### Development
9595

9696
```bash
97-
pnpm watch # Rebuild extension on changes
98-
pnpm dev:webviews # Rebuild webviews on changes (run in separate terminal)
97+
pnpm watch:all # Rebuild extension and webviews on changes
9998
```
10099

101100
Press F5 to launch the Extension Development Host. Use "Developer: Reload Webviews"

eslint.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default defineConfig(
2121
"**/*.d.ts",
2222
"vitest.config.ts",
2323
"**/vite.config*.ts",
24+
"**/createWebviewConfig.ts",
2425
".vscode-test/**",
2526
],
2627
},
@@ -100,6 +101,7 @@ export default defineConfig(
100101
"newlines-between": "always",
101102
alphabetize: { order: "asc", caseInsensitive: true },
102103
sortTypesGroup: true,
104+
warnOnUnassignedImports: true,
103105
},
104106
],
105107
"no-duplicate-imports": "off",
@@ -187,7 +189,7 @@ export default defineConfig(
187189
},
188190
},
189191
rules: {
190-
// Only add React-specific rules, TS rules already applied via **/*.ts config above
192+
// TS rules already applied above; add React-specific rules
191193
...reactPlugin.configs.recommended.rules,
192194
...reactPlugin.configs["jsx-runtime"].rules, // React 17+ JSX transform
193195
...reactHooksPlugin.configs.recommended.rules,

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"build": "pnpm build:webviews && tsc --noEmit && node esbuild.mjs",
2222
"build:production": "NODE_ENV=production pnpm build:webviews && tsc --noEmit && node esbuild.mjs --production",
2323
"build:webviews": "pnpm -r --filter \"./packages/*\" build",
24-
"dev:webviews": "pnpm -r --filter \"./packages/*\" --parallel dev",
2524
"fmt": "prettier --write --cache --cache-strategy content .",
2625
"fmt:check": "prettier --check --cache --cache-strategy content .",
2726
"lint": "eslint --cache --cache-strategy content .",
@@ -33,7 +32,9 @@
3332
"test:ci": "CI=true pnpm test",
3433
"test:integration": "tsc -p test --outDir out && node esbuild.mjs && vscode-test",
3534
"vscode:prepublish": "pnpm build:production",
36-
"watch": "node esbuild.mjs --watch"
35+
"watch:all": "concurrently -n extension,webviews \"pnpm watch:extension\" \"pnpm watch:webviews\"",
36+
"watch:extension": "node esbuild.mjs --watch",
37+
"watch:webviews": "pnpm -r --filter \"./packages/*\" --parallel dev"
3738
},
3839
"contributes": {
3940
"configuration": {
@@ -466,6 +467,7 @@
466467
"@vscode/vsce": "^3.7.1",
467468
"bufferutil": "^4.1.0",
468469
"coder": "github:coder/coder#main",
470+
"concurrently": "^9.2.1",
469471
"dayjs": "^1.11.19",
470472
"electron": "^40.0.0",
471473
"esbuild": "^0.27.2",

packages/shared/src/react/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/tasks/index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/tasks/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@coder/tasks-webview",
2+
"name": "@repo/tasks",
33
"version": "1.0.0",
44
"description": "Coder Tasks webview panel",
55
"private": true,
@@ -9,7 +9,7 @@
99
"dev": "vite build --watch"
1010
},
1111
"dependencies": {
12-
"@coder/shared": "workspace:*",
12+
"@repo/webview-shared": "workspace:*",
1313
"@vscode-elements/react-elements": "^2.4.0",
1414
"react": "^19.0.0",
1515
"react-dom": "^19.0.0"

packages/tasks/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { postMessage, useMessage } from "@coder/shared/react";
1+
import { postMessage, useMessage } from "@repo/webview-shared/react";
22
import {
33
VscodeButton,
44
VscodeProgressRing,
55
} from "@vscode-elements/react-elements";
66
import { useCallback, useEffect, useState } from "react";
77

8-
import type { WebviewMessage } from "@coder/shared";
8+
import type { WebviewMessage } from "@repo/webview-shared";
99

1010
export default function App() {
1111
const [ready, setReady] = useState(false);

packages/tasks/src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* Webview styles */

packages/tasks/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
33

44
import App from "./App";
5+
import "./index.css";
56

67
const root = document.getElementById("root");
78
if (root) {

packages/tasks/tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"extends": "../shared/tsconfig.webview.json",
2+
"extends": "../tsconfig.webview.json",
33
"compilerOptions": {
44
"paths": {
5-
"@coder/shared": ["../shared/src"],
6-
"@coder/shared/*": ["../shared/src/*"]
5+
"@repo/webview-shared": ["../webview-shared/src"]
76
}
87
},
98
"include": ["src"],
10-
"references": [{ "path": "../shared" }]
9+
"references": [{ "path": "../webview-shared" }]
1110
}

0 commit comments

Comments
 (0)