@vitejs/devtools 0.0.0-alpha.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DockIcon-Jbdv1CYn.js +1720 -0
- package/dist/DockStandalone-Dd6Dcd5B.js +81 -0
- package/dist/LogItem-CfTxUV6A.js +204 -0
- package/dist/ToastOverlay-BVErqkif.js +1048 -0
- package/dist/ViewBuiltinLogs-DQLxnQ1c.js +427 -0
- package/dist/ViewBuiltinTerminals-B83FB-cT.js +10407 -0
- package/dist/cli-commands-DRp01A04.js +178 -0
- package/dist/cli-commands.d.ts +18 -0
- package/dist/cli-commands.js +3 -0
- package/dist/cli.js +5 -94
- package/dist/client/inject.js +170 -18
- package/dist/client/standalone/assets/DockStandalone-B8W-HO8N.js +1 -0
- package/dist/client/standalone/assets/LogItem-B-ayIBi6.js +1 -0
- package/dist/client/standalone/assets/ViewBuiltinLogs-B8M7lPbt.js +1 -0
- package/dist/client/standalone/assets/ViewBuiltinTerminals-Dkd5qdlN.js +36 -0
- package/dist/client/standalone/assets/dist-ZC9UAo6H.js +1 -0
- package/dist/client/standalone/assets/index-6F2y1lxr.css +1 -0
- package/dist/client/standalone/assets/index-odNIfapG.js +4 -0
- package/dist/client/standalone/index.html +5 -3
- package/dist/client/webcomponents.d.ts +21656 -30
- package/dist/client/webcomponents.js +305 -423
- package/dist/config.d.ts +25 -0
- package/dist/config.js +14 -0
- package/dist/dirs.js +7 -3
- package/dist/{dist-BuuUhVT5.js → dist-3NIYLDlS.js} +2261 -936
- package/dist/index.d.ts +256 -14
- package/dist/index.js +2 -4
- package/dist/plugins-6tW2SoNv.js +2115 -0
- package/dist/popup-EDv_a9nQ.js +358 -0
- package/dist/utils--qjmgani.js +6 -0
- package/package.json +51 -21
- package/dist/client/standalone/assets/index-DULlvzQC.css +0 -1
- package/dist/client/standalone/assets/index-Dpd5aqgb.js +0 -7
- package/dist/dirs-DcSK9l9L.js +0 -9
- package/dist/plugins-Cj9DSRH1.js +0 -1348
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { a as createDevToolsContext, i as getPort, n as renderDockImportsMap, o as ansis_default, r as createDevToolsMiddleware, t as DevTools } from "./plugins-6tW2SoNv.js";
|
|
2
|
+
import { dirClientStandalone } from "./dirs.js";
|
|
3
|
+
import { resolveConfig } from "vite";
|
|
4
|
+
import { DEVTOOLS_CONNECTION_META_FILENAME, DEVTOOLS_DIRNAME, DEVTOOLS_DOCK_IMPORTS_FILENAME, DEVTOOLS_MOUNT_PATH, DEVTOOLS_RPC_DUMP_DIRNAME, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME } from "@vitejs/devtools-kit/constants";
|
|
5
|
+
import { dirname, join, relative, resolve } from "pathe";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { dumpFunctions, getRpcHandler } from "@vitejs/devtools-rpc";
|
|
8
|
+
import process from "node:process";
|
|
9
|
+
import sirv from "sirv";
|
|
10
|
+
import { createApp, eventHandler, fromNodeMiddleware, sendRedirect, toNodeListener } from "h3";
|
|
11
|
+
import fs$1 from "node:fs/promises";
|
|
12
|
+
import { createServer } from "node:http";
|
|
13
|
+
import open from "open";
|
|
14
|
+
//#region src/node/standalone.ts
|
|
15
|
+
async function startStandaloneDevTools(options = {}) {
|
|
16
|
+
const { cwd = process.cwd(), command = "build", mode = "production" } = options;
|
|
17
|
+
const resolved = await resolveConfig({
|
|
18
|
+
configFile: options.config,
|
|
19
|
+
root: cwd,
|
|
20
|
+
plugins: [DevTools()]
|
|
21
|
+
}, command, mode);
|
|
22
|
+
dedupeVitePlugins(resolved.plugins, (plugin) => plugin.name?.startsWith("vite:devtools"));
|
|
23
|
+
return {
|
|
24
|
+
config: resolved,
|
|
25
|
+
context: await createDevToolsContext(resolved)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function dedupeVitePlugins(plugins, include) {
|
|
29
|
+
const toDelete = [];
|
|
30
|
+
const map = /* @__PURE__ */ new Map();
|
|
31
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
32
|
+
const plugin = plugins[i];
|
|
33
|
+
if (!plugin || !include(plugin)) continue;
|
|
34
|
+
if (map.has(plugin.name)) toDelete.push(i);
|
|
35
|
+
else map.set(plugin.name, plugin);
|
|
36
|
+
}
|
|
37
|
+
toDelete.sort((a, b) => b - a);
|
|
38
|
+
for (const i of toDelete) plugins.splice(i, 1);
|
|
39
|
+
return plugins;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/node/static-dump.ts
|
|
43
|
+
function makeDumpKey(name) {
|
|
44
|
+
return encodeURIComponent(name.replaceAll(":", "~"));
|
|
45
|
+
}
|
|
46
|
+
function makeStaticPath(name) {
|
|
47
|
+
return `${DEVTOOLS_RPC_DUMP_DIRNAME}/${makeDumpKey(name)}.static.json`;
|
|
48
|
+
}
|
|
49
|
+
function makeQueryRecordPath(name, hash) {
|
|
50
|
+
return `${DEVTOOLS_RPC_DUMP_DIRNAME}/${makeDumpKey(name)}.record.${hash}.json`;
|
|
51
|
+
}
|
|
52
|
+
function makeQueryFallbackPath(name) {
|
|
53
|
+
return `${DEVTOOLS_RPC_DUMP_DIRNAME}/${makeDumpKey(name)}.fallback.json`;
|
|
54
|
+
}
|
|
55
|
+
async function resolveRecord(record) {
|
|
56
|
+
return typeof record === "function" ? await record() : record;
|
|
57
|
+
}
|
|
58
|
+
async function collectStaticRpcDump(definitions, context) {
|
|
59
|
+
const manifest = {};
|
|
60
|
+
const files = {};
|
|
61
|
+
for (const definition of definitions) {
|
|
62
|
+
const type = definition.type ?? "query";
|
|
63
|
+
if (type === "static") {
|
|
64
|
+
const handler = await getRpcHandler(definition, context);
|
|
65
|
+
const path = makeStaticPath(definition.name);
|
|
66
|
+
files[path] = { output: await Promise.resolve(handler()) };
|
|
67
|
+
manifest[definition.name] = {
|
|
68
|
+
type: "static",
|
|
69
|
+
path
|
|
70
|
+
};
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (type !== "query") continue;
|
|
74
|
+
const store = await dumpFunctions([definition], context);
|
|
75
|
+
if (!(definition.name in store.definitions)) continue;
|
|
76
|
+
const queryEntry = {
|
|
77
|
+
type: "query",
|
|
78
|
+
records: {}
|
|
79
|
+
};
|
|
80
|
+
const prefix = `${definition.name}---`;
|
|
81
|
+
for (const [recordKey, recordOrGetter] of Object.entries(store.records)) {
|
|
82
|
+
if (!recordKey.startsWith(prefix)) continue;
|
|
83
|
+
const key = recordKey.slice(prefix.length);
|
|
84
|
+
const record = await resolveRecord(recordOrGetter);
|
|
85
|
+
if (key === "fallback") {
|
|
86
|
+
const path = makeQueryFallbackPath(definition.name);
|
|
87
|
+
files[path] = record;
|
|
88
|
+
queryEntry.fallback = path;
|
|
89
|
+
} else {
|
|
90
|
+
const path = makeQueryRecordPath(definition.name, key);
|
|
91
|
+
files[path] = record;
|
|
92
|
+
queryEntry.records[key] = path;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!Object.keys(queryEntry.records).length && !queryEntry.fallback) continue;
|
|
96
|
+
manifest[definition.name] = queryEntry;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
manifest,
|
|
100
|
+
files
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/node/cli-commands.ts
|
|
105
|
+
async function start(options) {
|
|
106
|
+
const { host } = options;
|
|
107
|
+
const port = await getPort({
|
|
108
|
+
host,
|
|
109
|
+
port: options.port == null ? void 0 : +options.port,
|
|
110
|
+
portRange: [9999, 15e3]
|
|
111
|
+
});
|
|
112
|
+
const devtools = await startStandaloneDevTools({ cwd: options.root });
|
|
113
|
+
const { h3 } = await createDevToolsMiddleware({
|
|
114
|
+
cwd: devtools.config.root,
|
|
115
|
+
hostWebSocket: host,
|
|
116
|
+
context: devtools.context
|
|
117
|
+
});
|
|
118
|
+
const app = createApp();
|
|
119
|
+
for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) app.use(baseUrl, fromNodeMiddleware(sirv(distDir, {
|
|
120
|
+
dev: true,
|
|
121
|
+
single: true
|
|
122
|
+
})));
|
|
123
|
+
app.use(DEVTOOLS_MOUNT_PATH, h3.handler);
|
|
124
|
+
app.use("/", eventHandler(async (event) => {
|
|
125
|
+
if (event.node.req.url === "/") return sendRedirect(event, DEVTOOLS_MOUNT_PATH);
|
|
126
|
+
}));
|
|
127
|
+
createServer(toNodeListener(app)).listen(port, host, async () => {
|
|
128
|
+
console.log(ansis_default.green`${"⬢"} Vite DevTools started at`, ansis_default.green(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`), "\n");
|
|
129
|
+
if (options.open) await open(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async function build(options) {
|
|
133
|
+
console.log(ansis_default.cyan`${"⬢"} Building static Vite DevTools...`);
|
|
134
|
+
const devtools = await startStandaloneDevTools({
|
|
135
|
+
cwd: options.root,
|
|
136
|
+
config: options.config
|
|
137
|
+
});
|
|
138
|
+
const outDir = resolve(devtools.config.root, options.outDir);
|
|
139
|
+
if (existsSync(outDir)) await fs$1.rm(outDir, { recursive: true });
|
|
140
|
+
const devToolsRoot = join(outDir, DEVTOOLS_DIRNAME);
|
|
141
|
+
await fs$1.mkdir(devToolsRoot, { recursive: true });
|
|
142
|
+
await fs$1.cp(dirClientStandalone, devToolsRoot, { recursive: true });
|
|
143
|
+
for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) {
|
|
144
|
+
console.log(ansis_default.cyan`${"⬢"} Copying static files from ${distDir} to ${join(outDir, baseUrl)}`);
|
|
145
|
+
await fs$1.mkdir(join(outDir, baseUrl), { recursive: true });
|
|
146
|
+
await fs$1.cp(distDir, join(outDir, baseUrl), { recursive: true });
|
|
147
|
+
}
|
|
148
|
+
await fs$1.mkdir(resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_DIRNAME), { recursive: true });
|
|
149
|
+
await fs$1.writeFile(resolve(devToolsRoot, DEVTOOLS_CONNECTION_META_FILENAME), JSON.stringify({ backend: "static" }, null, 2), "utf-8");
|
|
150
|
+
await fs$1.writeFile(resolve(devToolsRoot, DEVTOOLS_DOCK_IMPORTS_FILENAME), renderDockImportsMap(devtools.context.docks.values()), "utf-8");
|
|
151
|
+
console.log(ansis_default.cyan`${"⬢"} Writing RPC dump to ${resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME)}`);
|
|
152
|
+
const dump = await collectStaticRpcDump(devtools.context.rpc.definitions.values(), devtools.context);
|
|
153
|
+
for (const [filepath, data] of Object.entries(dump.files)) {
|
|
154
|
+
const fullpath = resolve(devToolsRoot, filepath);
|
|
155
|
+
await fs$1.mkdir(dirname(fullpath), { recursive: true });
|
|
156
|
+
await fs$1.writeFile(fullpath, JSON.stringify(data, null, 2), "utf-8");
|
|
157
|
+
}
|
|
158
|
+
await fs$1.writeFile(resolve(devToolsRoot, DEVTOOLS_RPC_DUMP_MANIFEST_FILENAME), JSON.stringify(dump.manifest, null, 2), "utf-8");
|
|
159
|
+
await fs$1.writeFile(resolve(outDir, "index.html"), [
|
|
160
|
+
"<!doctype html>",
|
|
161
|
+
"<html lang=\"en\">",
|
|
162
|
+
"<head>",
|
|
163
|
+
" <meta charset=\"UTF-8\">",
|
|
164
|
+
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
|
|
165
|
+
" <title>Vite DevTools</title>",
|
|
166
|
+
` <meta http-equiv="refresh" content="0; url=${DEVTOOLS_MOUNT_PATH}">`,
|
|
167
|
+
"</head>",
|
|
168
|
+
"<body>",
|
|
169
|
+
` <script>location.replace(${JSON.stringify(DEVTOOLS_MOUNT_PATH)})<\/script>`,
|
|
170
|
+
"</body>",
|
|
171
|
+
"</html>"
|
|
172
|
+
].join("\n"), "utf-8");
|
|
173
|
+
console.log(ansis_default.green`${"⬢"} Built to ${relative(devtools.config.root, outDir)}`);
|
|
174
|
+
console.warn(ansis_default.yellow`${"⬢"} Static build is still experimental and not yet complete.`);
|
|
175
|
+
console.warn(ansis_default.yellow`${"⬢"} Generated output may be missing features and can change without notice.`);
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
export { start as n, build as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/node/cli-commands.d.ts
|
|
2
|
+
interface StartOptions {
|
|
3
|
+
root?: string;
|
|
4
|
+
config?: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port?: string | number;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function start(options: StartOptions): Promise<void>;
|
|
10
|
+
interface BuildOptions {
|
|
11
|
+
root: string;
|
|
12
|
+
config?: string;
|
|
13
|
+
outDir: string;
|
|
14
|
+
base: string;
|
|
15
|
+
}
|
|
16
|
+
declare function build(options: BuildOptions): Promise<void>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BuildOptions, StartOptions, build, start };
|
package/dist/cli.js
CHANGED
|
@@ -1,103 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import sirv from "sirv";
|
|
1
|
+
import "./plugins-6tW2SoNv.js";
|
|
2
|
+
import { n as start, t as build } from "./cli-commands-DRp01A04.js";
|
|
5
3
|
import process from "node:process";
|
|
6
|
-
import { loadConfigFromFile, resolveConfig } from "vite";
|
|
7
|
-
import fs from "node:fs/promises";
|
|
8
|
-
import { createServer } from "node:http";
|
|
9
4
|
import cac from "cac";
|
|
10
|
-
import open from "open";
|
|
11
|
-
import { join, relative, resolve } from "pathe";
|
|
12
|
-
|
|
13
|
-
//#region src/node/standalone.ts
|
|
14
|
-
async function startStandaloneDevTools(options = {}) {
|
|
15
|
-
const { cwd = process.cwd(), command = "build", mode = "production" } = options;
|
|
16
|
-
const config = (await loadConfigFromFile({
|
|
17
|
-
command,
|
|
18
|
-
mode
|
|
19
|
-
}, options.config, cwd))?.config || {};
|
|
20
|
-
config.plugins ||= [];
|
|
21
|
-
config.plugins.push(DevTools());
|
|
22
|
-
dedupeVitePlugins(config.plugins, (plugin) => plugin.name?.startsWith("vite:devtools"));
|
|
23
|
-
const resolved = await resolveConfig(config, command, mode);
|
|
24
|
-
return {
|
|
25
|
-
config: resolved,
|
|
26
|
-
context: await createDevToolsContext(resolved)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function dedupeVitePlugins(plugins, include) {
|
|
30
|
-
const toDelete = [];
|
|
31
|
-
const map = /* @__PURE__ */ new Map();
|
|
32
|
-
for (let i = 0; i < plugins.length; i++) {
|
|
33
|
-
const plugin = plugins[i];
|
|
34
|
-
if (!plugin || !include(plugin)) continue;
|
|
35
|
-
if (map.has(plugin.name)) toDelete.push(i);
|
|
36
|
-
else map.set(plugin.name, plugin);
|
|
37
|
-
}
|
|
38
|
-
toDelete.sort((a, b) => b - a);
|
|
39
|
-
for (const i of toDelete) plugins.splice(i, 1);
|
|
40
|
-
return plugins;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
5
|
//#region src/node/cli.ts
|
|
45
6
|
const cli = cac("vite-devtools");
|
|
46
7
|
process.on("SIGINT", () => {
|
|
47
8
|
process.exit(0);
|
|
48
9
|
});
|
|
49
|
-
cli.command("build", "Build devtools with current config file for static hosting").option("--root <root>", "Root directory", { default: process.cwd() }).option("--config <config>", "Vite config file").option("--base <baseURL>", "Base URL for deployment", { default: "/" }).option("--outDir <dir>", "Output directory", { default: ".vite-devtools" }).action(
|
|
50
|
-
|
|
51
|
-
const devtools = await startStandaloneDevTools({
|
|
52
|
-
cwd: options.root,
|
|
53
|
-
config: options.config
|
|
54
|
-
});
|
|
55
|
-
const outDir = resolve(devtools.config.root, options.outDir);
|
|
56
|
-
if (existsSync(outDir)) await fs.rm(outDir, { recursive: true });
|
|
57
|
-
const devToolsRoot = join(outDir, ".devtools");
|
|
58
|
-
await fs.mkdir(devToolsRoot, { recursive: true });
|
|
59
|
-
await fs.cp(dirClientStandalone, devToolsRoot, { recursive: true });
|
|
60
|
-
for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) {
|
|
61
|
-
console.log(ansis_default.cyan`${MARK_NODE} Copying static files from ${distDir} to ${join(outDir, baseUrl)}`);
|
|
62
|
-
await fs.mkdir(join(outDir, baseUrl), { recursive: true });
|
|
63
|
-
await fs.cp(distDir, join(outDir, baseUrl), { recursive: true });
|
|
64
|
-
}
|
|
65
|
-
await fs.mkdir(resolve(devToolsRoot, "api"), { recursive: true });
|
|
66
|
-
await fs.writeFile(resolve(devToolsRoot, ".vdt-connection.json"), JSON.stringify({ backend: "static" }, null, 2), "utf-8");
|
|
67
|
-
console.log(ansis_default.cyan`${MARK_NODE} Writing RPC dump to ${resolve(devToolsRoot, ".vdt-rpc-dump.json")}`);
|
|
68
|
-
const dump = {};
|
|
69
|
-
for (const [key, value] of Object.entries(devtools.context.rpc.functions)) if (value.type === "static") dump[key] = await value.handler?.();
|
|
70
|
-
await fs.writeFile(resolve(devToolsRoot, ".vdt-rpc-dump.json"), JSON.stringify(dump, null, 2), "utf-8");
|
|
71
|
-
console.log(ansis_default.green`${MARK_NODE} Built to ${relative(devtools.config.root, outDir)}`);
|
|
72
|
-
throw new Error("[Vite DevTools] Build mode of Vite DevTools is not yet complete");
|
|
73
|
-
});
|
|
74
|
-
cli.command("", "Start devtools").option("--root <root>", "Root directory", { default: process.cwd() }).option("--config <config>", "Vite config file").option("--host <host>", "Host", { default: process.env.HOST || "127.0.0.1" }).option("--port <port>", "Port", { default: process.env.PORT || 9999 }).option("--open", "Open browser", { default: true }).action(async (options) => {
|
|
75
|
-
const host = options.host;
|
|
76
|
-
const port = await getPort({
|
|
77
|
-
port: options.port,
|
|
78
|
-
portRange: [9999, 15e3],
|
|
79
|
-
host
|
|
80
|
-
});
|
|
81
|
-
const devtools = await startStandaloneDevTools({ cwd: options.root });
|
|
82
|
-
const { h3 } = await createDevToolsMiddleware({
|
|
83
|
-
cwd: devtools.config.root,
|
|
84
|
-
context: devtools.context
|
|
85
|
-
});
|
|
86
|
-
const app = createApp();
|
|
87
|
-
for (const { baseUrl, distDir } of devtools.context.views.buildStaticDirs) app.use(baseUrl, fromNodeMiddleware(sirv(distDir, {
|
|
88
|
-
dev: true,
|
|
89
|
-
single: true
|
|
90
|
-
})));
|
|
91
|
-
app.use("/.devtools/", h3.handler);
|
|
92
|
-
app.use("/", eventHandler(async (event) => {
|
|
93
|
-
if (event.node.req.url === "/") return sendRedirect(event, "/.devtools/");
|
|
94
|
-
}));
|
|
95
|
-
createServer(toNodeListener(app)).listen(port, host, async () => {
|
|
96
|
-
console.log(ansis_default.green`${MARK_NODE} Vite DevTools started at`, ansis_default.green(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`), "\n");
|
|
97
|
-
if (options.open) await open(`http://${host === "127.0.0.1" ? "localhost" : host}:${port}`);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
10
|
+
cli.command("build", "Build devtools with current config file for static hosting").option("--root <root>", "Root directory", { default: process.cwd() }).option("--config <config>", "Vite config file").option("--base <baseURL>", "Base URL for deployment", { default: "/" }).option("--outDir <dir>", "Output directory", { default: ".vite-devtools" }).action(build);
|
|
11
|
+
cli.command("", "Start devtools").option("--root <root>", "Root directory", { default: process.cwd() }).option("--config <config>", "Vite config file").option("--host <host>", "Host", { default: process.env.HOST || "127.0.0.1" }).option("--port <port>", "Port", { default: process.env.PORT || 9999 }).option("--open", "Open browser", { default: true }).action(start);
|
|
100
12
|
cli.help();
|
|
101
13
|
cli.parse();
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
14
|
+
//#endregion
|
package/dist/client/inject.js
CHANGED
|
@@ -1,33 +1,185 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { G as toRefs, H as reactive, R as watchEffect, U as ref, V as markRaw, i as useLocalStorage, y as computed } from "../dist-3NIYLDlS.js";
|
|
2
|
+
import { _ as useDocksEntries, a as requestDockPopupOpen, b as BUILTIN_ENTRIES, g as sharedStateToRef, h as createDockEntryState, i as registerMainFrameDockActionHandler, m as DEFAULT_DOCK_PANEL_STORE, o as triggerMainFrameDockAction, v as docksGroupByCategories } from "../popup-EDv_a9nQ.js";
|
|
3
|
+
import { DEFAULT_STATE_USER_SETTINGS, DEVTOOLS_DOCK_IMPORTS_FILENAME, DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID, DEVTOOLS_MOUNT_PATH } from "@vitejs/devtools-kit/constants";
|
|
2
4
|
import { getDevToolsRpcClient } from "@vitejs/devtools-kit/client";
|
|
3
|
-
|
|
5
|
+
//#region src/client/webcomponents/state/logs-client.ts
|
|
6
|
+
function createRpcHandle(rpc, initialEntry) {
|
|
7
|
+
let entry = initialEntry;
|
|
8
|
+
return {
|
|
9
|
+
get entry() {
|
|
10
|
+
return entry;
|
|
11
|
+
},
|
|
12
|
+
get id() {
|
|
13
|
+
return entry.id;
|
|
14
|
+
},
|
|
15
|
+
async update(patch) {
|
|
16
|
+
const updated = await rpc.call("devtoolskit:internal:logs:update", entry.id, patch);
|
|
17
|
+
if (updated) entry = updated;
|
|
18
|
+
return updated ?? void 0;
|
|
19
|
+
},
|
|
20
|
+
async dismiss() {
|
|
21
|
+
await rpc.call("devtoolskit:internal:logs:remove", entry.id);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function createClientLogsClient(rpc) {
|
|
26
|
+
return {
|
|
27
|
+
async add(input) {
|
|
28
|
+
return createRpcHandle(rpc, await rpc.call("devtoolskit:internal:logs:add", input));
|
|
29
|
+
},
|
|
30
|
+
async remove(id) {
|
|
31
|
+
await rpc.call("devtoolskit:internal:logs:remove", id);
|
|
32
|
+
},
|
|
33
|
+
async clear() {
|
|
34
|
+
await rpc.call("devtoolskit:internal:logs:clear");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/client/webcomponents/state/setup-script.ts
|
|
40
|
+
async function loadImportsMapModule(context) {
|
|
41
|
+
const candidates = context.rpc.connectionMeta.backend === "static" ? [`${DEVTOOLS_MOUNT_PATH}${DEVTOOLS_DOCK_IMPORTS_FILENAME}`, DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID] : [DEVTOOLS_DOCK_IMPORTS_VIRTUAL_ID];
|
|
42
|
+
const errors = [];
|
|
43
|
+
for (const id of candidates) try {
|
|
44
|
+
return await import(
|
|
45
|
+
/* @vite-ignore */
|
|
46
|
+
id
|
|
47
|
+
);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
errors.push(error);
|
|
50
|
+
}
|
|
51
|
+
throw new Error("[VITE DEVTOOLS] Failed to load imports map module", { cause: errors });
|
|
52
|
+
}
|
|
53
|
+
function _executeSetupScript(entry, context) {
|
|
54
|
+
const id = `${entry.type}:${entry.id}`;
|
|
55
|
+
return loadImportsMapModule(context).then((module) => {
|
|
56
|
+
const importFn = module.importsMap[id];
|
|
57
|
+
if (!importFn) return Promise.reject(/* @__PURE__ */ new Error(`[VITE DEVTOOLS] No import found for id: ${id}`));
|
|
58
|
+
return importFn().then((fn) => fn(context));
|
|
59
|
+
}).catch((error) => {
|
|
60
|
+
console.error("[VITE DEVTOOLS] Error executing import action", error);
|
|
61
|
+
return Promise.reject(error);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const _setupPromises = /* @__PURE__ */ new Map();
|
|
65
|
+
function executeSetupScript(entry, context) {
|
|
66
|
+
if (entry.type !== "action" && _setupPromises.has(entry.id)) return _setupPromises.get(entry.id);
|
|
67
|
+
const promise = _executeSetupScript(entry, context);
|
|
68
|
+
if (entry.type !== "action") _setupPromises.set(entry.id, promise);
|
|
69
|
+
return promise;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/client/webcomponents/state/context.ts
|
|
73
|
+
const docksContextByRpc = /* @__PURE__ */ new WeakMap();
|
|
74
|
+
async function createDocksContext(clientType, rpc, panelStore) {
|
|
75
|
+
if (docksContextByRpc.has(rpc)) return docksContextByRpc.get(rpc);
|
|
76
|
+
const dockEntries = await useDocksEntries(rpc);
|
|
77
|
+
const selectedId = ref(null);
|
|
78
|
+
const selected = computed(() => dockEntries.value.find((entry) => entry.id === selectedId.value) ?? BUILTIN_ENTRIES.find((entry) => entry.id === selectedId.value) ?? null);
|
|
79
|
+
const dockEntryStateMap = reactive(/* @__PURE__ */ new Map());
|
|
80
|
+
watchEffect(() => {
|
|
81
|
+
for (const entry of dockEntries.value) {
|
|
82
|
+
if (dockEntryStateMap.has(entry.id)) {
|
|
83
|
+
dockEntryStateMap.get(entry.id).entryMeta = entry;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
dockEntryStateMap.set(entry.id, createDockEntryState(entry, selected));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
panelStore ||= ref(DEFAULT_DOCK_PANEL_STORE());
|
|
90
|
+
let docksContext;
|
|
91
|
+
const switchEntry = async (id = null) => {
|
|
92
|
+
if (id == null) {
|
|
93
|
+
selectedId.value = null;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (id === "~client-auth-notice") {
|
|
97
|
+
selectedId.value = id;
|
|
98
|
+
panelStore.value.open = true;
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (id === "~popup") {
|
|
102
|
+
requestDockPopupOpen(docksContext);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
const entry = dockEntries.value.find((e) => e.id === id);
|
|
106
|
+
if (!entry) return false;
|
|
107
|
+
if (entry.type === "action") {
|
|
108
|
+
if (await triggerMainFrameDockAction(clientType, entry.id) != null) return false;
|
|
109
|
+
}
|
|
110
|
+
if (entry.type === "action" || entry.type === "custom-render" || entry.type === "iframe" && entry.clientScript) {
|
|
111
|
+
const current = dockEntryStateMap.get(id);
|
|
112
|
+
await executeSetupScript(entry, reactive({
|
|
113
|
+
...toRefs(docksContext),
|
|
114
|
+
current,
|
|
115
|
+
logs: createClientLogsClient(rpc)
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
selectedId.value = entry.id;
|
|
119
|
+
panelStore.value.open = true;
|
|
120
|
+
return true;
|
|
121
|
+
};
|
|
122
|
+
const toggleEntry = async (id) => {
|
|
123
|
+
if (selectedId.value === id) return switchEntry(null);
|
|
124
|
+
return switchEntry(id);
|
|
125
|
+
};
|
|
126
|
+
let _settingsStorePromise;
|
|
127
|
+
const getSettingsStore = async () => {
|
|
128
|
+
if (!_settingsStorePromise) _settingsStorePromise = rpc.sharedState.get("devtoolskit:internal:user-settings", { initialValue: DEFAULT_STATE_USER_SETTINGS() });
|
|
129
|
+
return _settingsStorePromise;
|
|
130
|
+
};
|
|
131
|
+
const settingsStore = markRaw(await getSettingsStore());
|
|
132
|
+
const settings = sharedStateToRef(settingsStore);
|
|
133
|
+
const groupedEntries = computed(() => {
|
|
134
|
+
return docksGroupByCategories(dockEntries.value, settings.value);
|
|
135
|
+
});
|
|
136
|
+
docksContext = reactive({
|
|
137
|
+
panel: {
|
|
138
|
+
store: panelStore,
|
|
139
|
+
isDragging: false,
|
|
140
|
+
isResizing: false,
|
|
141
|
+
isVertical: computed(() => panelStore.value.position === "left" || panelStore.value.position === "right")
|
|
142
|
+
},
|
|
143
|
+
docks: {
|
|
144
|
+
selectedId,
|
|
145
|
+
selected,
|
|
146
|
+
entries: dockEntries,
|
|
147
|
+
entryToStateMap: markRaw(dockEntryStateMap),
|
|
148
|
+
groupedEntries,
|
|
149
|
+
settings: settingsStore,
|
|
150
|
+
getStateById: (id) => dockEntryStateMap.get(id),
|
|
151
|
+
switchEntry,
|
|
152
|
+
toggleEntry
|
|
153
|
+
},
|
|
154
|
+
rpc,
|
|
155
|
+
clientType
|
|
156
|
+
});
|
|
157
|
+
registerMainFrameDockActionHandler(clientType, async (id) => {
|
|
158
|
+
const entry = dockEntries.value.find((e) => e.id === id);
|
|
159
|
+
if (!entry || entry.type !== "action") return false;
|
|
160
|
+
return switchEntry(entry.id);
|
|
161
|
+
});
|
|
162
|
+
docksContextByRpc.set(rpc, docksContext);
|
|
163
|
+
return docksContext;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
4
166
|
//#region src/client/inject/index.ts
|
|
5
167
|
async function init() {
|
|
6
168
|
console.log("[VITE DEVTOOLS] Client injected");
|
|
7
|
-
const
|
|
8
|
-
console.log("[VITE DEVTOOLS] RPC", rpc);
|
|
9
|
-
const docks = await rpc["vite:core:list-dock-entries"]();
|
|
10
|
-
console.log("[VITE DEVTOOLS] Docks", docks);
|
|
11
|
-
const rpcFunctions = await rpc["vite:core:list-rpc-functions"]();
|
|
12
|
-
console.log("[VITE DEVTOOLS] RPC Functions", rpcFunctions);
|
|
13
|
-
const state = useLocalStorage("vite-devtools-dock-state", {
|
|
169
|
+
const context = await createDocksContext("embedded", await getDevToolsRpcClient(), useLocalStorage("vite-devtools-dock-state", {
|
|
14
170
|
width: 80,
|
|
15
171
|
height: 80,
|
|
16
172
|
top: 0,
|
|
17
173
|
left: 0,
|
|
18
174
|
position: "left",
|
|
19
175
|
open: false,
|
|
20
|
-
|
|
21
|
-
}, { mergeDefaults: true });
|
|
22
|
-
const { DockEmbedded } = await import("
|
|
23
|
-
const dockEl = new DockEmbedded({
|
|
24
|
-
state,
|
|
25
|
-
docks
|
|
26
|
-
});
|
|
176
|
+
inactiveTimeout: 3e3
|
|
177
|
+
}, { mergeDefaults: true }));
|
|
178
|
+
const { DockEmbedded } = await import("@vitejs/devtools/client/webcomponents");
|
|
179
|
+
const dockEl = new DockEmbedded({ context });
|
|
27
180
|
document.body.appendChild(dockEl);
|
|
28
181
|
}
|
|
29
182
|
if (window.parent !== window) console.log("[VITE DEVTOOLS] Skipping in iframe");
|
|
30
183
|
else init();
|
|
31
|
-
|
|
32
184
|
//#endregion
|
|
33
|
-
export { init };
|
|
185
|
+
export { init };
|