diff --git a/package.json b/package.json index 08e6c4f2b..be81eba43 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,9 @@ "test:e2e": "pnpm -C e2e run test", "test": "vitest", "typecheck": "vue-tsc -b", - "watch": "turbo watch build" + "watch": "turbo watch build", + "zip": "pnpm run zip:webext", + "zip:webext": "turbo run build --filter=@vitejs/devtools-webext && pnpm --filter @vitejs/devtools-webext run zip" }, "scripts-info": { "actionspack": "Update pinned GitHub Actions versions", @@ -53,7 +55,9 @@ "test:e2e": "Run end-to-end tests", "test": "Run unit tests with Vitest", "typecheck": "Type-check all packages with vue-tsc", - "watch": "Rebuild changed packages on file change via turbo watch" + "watch": "Rebuild changed packages on file change via turbo watch", + "zip": "Build and package the browser extension", + "zip:webext": "Build and package the browser extension as a zip file" }, "devDependencies": { "@antfu/eslint-config": "catalog:devtools", diff --git a/packages/kit/src/client/remote.test.ts b/packages/kit/src/client/remote.test.ts deleted file mode 100644 index 09ccc0423..000000000 --- a/packages/kit/src/client/remote.test.ts +++ /dev/null @@ -1,81 +0,0 @@ -import type { RemoteConnectionInfo } from '../types' -import { Buffer } from 'node:buffer' -import { REMOTE_CONNECTION_KEY } from 'devframe/constants' -import { describe, expect, it } from 'vitest' -import { parseRemoteConnection } from './remote' - -function encode(payload: Partial): string { - return Buffer.from(JSON.stringify(payload), 'utf8') - .toString('base64') - .replace(/\+/g, '-') - .replace(/\//g, '_') - .replace(/=+$/, '') -} - -const VALID_PAYLOAD: RemoteConnectionInfo = { - v: 1, - backend: 'websocket', - websocket: 'ws://localhost:7812', - authToken: 'happy-lion-7', - origin: 'http://localhost:5173', -} - -describe('parseRemoteConnection', () => { - it('returns null when the URL carries no descriptor', () => { - expect(parseRemoteConnection('https://example.com/page')).toBeNull() - }) - - it('parses a fragment-transport descriptor', () => { - const encoded = encode(VALID_PAYLOAD) - const url = `https://example.com/page#${REMOTE_CONNECTION_KEY}=${encoded}` - expect(parseRemoteConnection(url)).toEqual(VALID_PAYLOAD) - }) - - it('parses a query-transport descriptor', () => { - const encoded = encode(VALID_PAYLOAD) - const url = `https://example.com/page?${REMOTE_CONNECTION_KEY}=${encoded}` - expect(parseRemoteConnection(url)).toEqual(VALID_PAYLOAD) - }) - - it('prefers fragment over query when both are present', () => { - const fragPayload = { ...VALID_PAYLOAD, authToken: 'from-fragment' } - const queryPayload = { ...VALID_PAYLOAD, authToken: 'from-query' } - const url = `https://example.com/page` - + `?${REMOTE_CONNECTION_KEY}=${encode(queryPayload)}` - + `#${REMOTE_CONNECTION_KEY}=${encode(fragPayload)}` - expect(parseRemoteConnection(url)?.authToken).toBe('from-fragment') - }) - - it('accepts a raw fragment string', () => { - const encoded = encode(VALID_PAYLOAD) - expect(parseRemoteConnection(`#${REMOTE_CONNECTION_KEY}=${encoded}`)).toEqual(VALID_PAYLOAD) - }) - - it('accepts a raw query string', () => { - const encoded = encode(VALID_PAYLOAD) - expect(parseRemoteConnection(`?${REMOTE_CONNECTION_KEY}=${encoded}`)).toEqual(VALID_PAYLOAD) - }) - - it('throws on malformed base64', () => { - const url = `https://example.com/page#${REMOTE_CONNECTION_KEY}=not@valid!base64` - expect(() => parseRemoteConnection(url)).toThrow(/Failed to decode/) - }) - - it('throws on version mismatch', () => { - const encoded = encode({ ...VALID_PAYLOAD, v: 2 as 1 }) - const url = `https://example.com/page#${REMOTE_CONNECTION_KEY}=${encoded}` - expect(() => parseRemoteConnection(url)).toThrow(/Unsupported remote connection descriptor version/) - }) - - it('throws when required fields are missing', () => { - const encoded = encode({ v: 1, backend: 'websocket' }) - const url = `https://example.com/page#${REMOTE_CONNECTION_KEY}=${encoded}` - expect(() => parseRemoteConnection(url)).toThrow(/websocket URL/) - }) - - it('throws when payload is not an object', () => { - const encoded = encode(null as unknown as RemoteConnectionInfo) - const url = `https://example.com/page#${REMOTE_CONNECTION_KEY}=${encoded}` - expect(() => parseRemoteConnection(url)).toThrow(/must be an object/) - }) -}) diff --git a/packages/webext/app/background/background.html b/packages/webext/app/background/background.html new file mode 100644 index 000000000..c31d2da99 --- /dev/null +++ b/packages/webext/app/background/background.html @@ -0,0 +1,9 @@ + + + + Vite DevTools Background + + + + + diff --git a/packages/webext/app/panel/App.vue b/packages/webext/app/panel/App.vue new file mode 100644 index 000000000..5ad47fb9c --- /dev/null +++ b/packages/webext/app/panel/App.vue @@ -0,0 +1,79 @@ + + +