Skip to content

Commit adea41f

Browse files
committed
chore: update
1 parent 546597b commit adea41f

7 files changed

Lines changed: 80 additions & 17 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"typecheck": "vue-tsc -b",
3030
"watch": "turbo watch build",
3131
"zip": "pnpm run zip:webext",
32-
"zip:webext": "turbo run build --filter=@vitejs/devtools-webext && node packages/webext/scripts/zip.mjs"
32+
"zip:webext": "turbo run build --filter=@vitejs/devtools-webext && pnpm --filter @vitejs/devtools-webext run zip"
3333
},
3434
"scripts-info": {
3535
"actionspack": "Update pinned GitHub Actions versions",

packages/core/src/client/webcomponents/state/__tests__/context-cache.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,27 @@ describe('dock state caches', () => {
8989
expect(context.docks.entries[0]?.icon)
9090
.toBe('http://localhost:5173/__devtools-vite/favicon.svg')
9191
})
92+
93+
it('resolves server-hosted launcher icons against the RPC server', async () => {
94+
const rpc = createMockRpc([{
95+
id: 'vitest',
96+
type: 'launcher',
97+
title: 'Vitest',
98+
icon: '/__devtools-vitest/favicon.svg',
99+
launcher: {
100+
title: 'Vitest UI',
101+
description: 'Start Vitest UI.',
102+
icon: '/__devtools-vitest/favicon.svg',
103+
status: 'idle',
104+
},
105+
}])
106+
107+
const context = await createDocksContext('standalone', rpc)
108+
const entry = context.docks.entries[0]
109+
110+
expect(entry?.icon)
111+
.toBe('http://localhost:5173/__devtools-vitest/favicon.svg')
112+
expect(entry?.type === 'launcher' && entry.launcher.icon)
113+
.toBe('http://localhost:5173/__devtools-vitest/favicon.svg')
114+
})
92115
})

packages/core/src/client/webcomponents/state/context.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@ export async function createDocksContext(
2828
}
2929

3030
const dockEntries = await useDocksEntries(rpc)
31-
const resolveEntryIcon = <T extends DevToolsDockEntry>(entry: T): T => ({
32-
...entry,
33-
icon: resolveDockIcon(entry.icon, rpc.connection),
34-
})
31+
const resolveEntryIcon = <T extends DevToolsDockEntry>(entry: T): T => {
32+
const resolved = {
33+
...entry,
34+
icon: resolveDockIcon(entry.icon, rpc.connection),
35+
}
36+
37+
if (resolved.type === 'launcher' && resolved.launcher.icon) {
38+
resolved.launcher = {
39+
...resolved.launcher,
40+
icon: resolveDockIcon(resolved.launcher.icon, rpc.connection),
41+
}
42+
}
43+
44+
return resolved
45+
}
3546

3647
// Client-only dock registry (0.7.10 `DocksEntriesContext` API). Docks
3748
// registered here live in this page only, merged over the server-provided

packages/webext/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"build:scripts": "tsdown",
2525
"build:client": "vite build",
2626
"watch": "tsdown --watch && vite build --watch",
27-
"prepack": "pnpm build"
27+
"prepack": "pnpm build",
28+
"zip": "tsx scripts/zip.ts"
2829
},
2930
"dependencies": {
3031
"@vitejs/devtools": "workspace:*",
@@ -33,6 +34,7 @@
3334
"webext-bridge": "catalog:deps"
3435
},
3536
"devDependencies": {
37+
"@types/archiver": "catalog:types",
3638
"@types/chrome": "catalog:types",
3739
"@vitejs/plugin-vue": "catalog:build",
3840
"archiver": "catalog:build",
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
// @ts-check
21
import fs from 'node:fs'
3-
import { createRequire } from 'node:module'
42
import path from 'node:path'
53
import { fileURLToPath } from 'node:url'
4+
import archiver from 'archiver'
65

7-
const require = createRequire(import.meta.url)
8-
const archiver = require('archiver')
6+
type ManifestFileCollection = string[] | Record<string, string>
7+
8+
interface ExtensionManifest {
9+
devtools_page?: string
10+
background?: { service_worker?: string }
11+
action?: { default_icon?: ManifestFileCollection }
12+
icons?: ManifestFileCollection
13+
content_scripts?: Array<{ js?: string[], css?: string[] }>
14+
}
915

1016
const packageDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
1117
const rootDir = path.resolve(packageDir, '../..')
@@ -28,17 +34,17 @@ const ignore = [
2834
'**/*.tsbuildinfo',
2935
]
3036

31-
const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'manifest.json'), 'utf8'))
37+
const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'manifest.json'), 'utf8')) as ExtensionManifest
3238
const requiredFiles = collectManifestFiles(manifest)
3339

3440
fs.rmSync(outFile, { force: true })
3541
fs.mkdirSync(outDir, { recursive: true })
3642

3743
const output = fs.createWriteStream(outFile)
3844
const archive = archiver('zip', { zlib: { level: 9 } })
39-
const entries = new Set()
45+
const entries = new Set<string>()
4046

41-
const done = new Promise((resolve, reject) => {
47+
const done = new Promise<void>((resolve, reject) => {
4248
output.on('close', resolve)
4349
output.on('error', reject)
4450
archive.on('entry', entry => entries.add(entry.name))
@@ -72,7 +78,7 @@ for (const file of requiredFiles) {
7278

7379
console.log(`Created ${path.relative(rootDir, outFile)} (${formatBytes(size)}, ${entries.size} files)`)
7480

75-
function collectManifestFiles(manifest) {
81+
function collectManifestFiles(manifest: ExtensionManifest): Set<string> {
7682
const files = new Set(['manifest.json'])
7783

7884
add(files, manifest.devtools_page)
@@ -88,12 +94,12 @@ function collectManifestFiles(manifest) {
8894
return files
8995
}
9096

91-
function add(files, value) {
97+
function add(files: Set<string>, value: string | undefined): void {
9298
if (typeof value === 'string')
9399
files.add(value)
94100
}
95101

96-
function addAll(files, value) {
102+
function addAll(files: Set<string>, value: ManifestFileCollection | undefined): void {
97103
if (Array.isArray(value)) {
98104
for (const entry of value)
99105
add(files, entry)
@@ -106,7 +112,7 @@ function addAll(files, value) {
106112
}
107113
}
108114

109-
function formatBytes(bytes) {
115+
function formatBytes(bytes: number): string {
110116
const units = ['B', 'KB', 'MB', 'GB']
111117
let size = bytes
112118
let unit = 0

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ catalogs:
207207
tsnapi: ^1.2.0
208208
vitest: ^4.1.10
209209
types:
210+
'@types/archiver': ^7.0.0
210211
'@types/chrome': ^0.2.5
211212
'@types/connect': ^3.4.38
212213
'@types/d3': ^7.4.3

0 commit comments

Comments
 (0)