@vitejs/devtools-vitest 0.4.2 → 0.4.3
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/index.mjs +48 -5
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { clientPublicDir } from "./dirs.mjs";
|
|
2
|
+
import { dirname, relative, resolve } from "node:path";
|
|
2
3
|
import process from "node:process";
|
|
3
4
|
import { DEVTOOLS_VITEPLUS_GROUP_ID } from "@vitejs/devtools-kit/constants";
|
|
4
5
|
import { createProcessLauncher } from "@vitejs/devtools-kit/node";
|
|
5
6
|
import { getPort } from "get-port-please";
|
|
6
7
|
import { isPackageExists } from "local-pkg";
|
|
7
8
|
import { addDependency } from "nypm";
|
|
9
|
+
import { glob } from "tinyglobby";
|
|
8
10
|
import { createConsoleReporter, defineDiagnostics } from "nostics";
|
|
9
11
|
//#region src/node/diagnostics.ts
|
|
10
12
|
const diagnostics = /* #__PURE__ */ defineDiagnostics({
|
|
@@ -47,10 +49,12 @@ function DevToolsVitestUI() {
|
|
|
47
49
|
name: "vite:devtools:vitest-ui",
|
|
48
50
|
devtools: { async setup(ctx) {
|
|
49
51
|
const cwd = ctx.cwd ?? process.cwd();
|
|
52
|
+
const installRoot = ctx.workspaceRoot ?? cwd;
|
|
50
53
|
if (!isPackageExists("vitest", { paths: [cwd] })) return;
|
|
51
54
|
ctx.views.hostStatic(VITEST_DEVTOOLS_BASE, clientPublicDir);
|
|
52
55
|
const icon = `${VITEST_DEVTOOLS_BASE}favicon.svg`;
|
|
53
|
-
const hasUi = isPackageExists("@vitest/ui", { paths: [
|
|
56
|
+
const hasUi = isPackageExists("@vitest/ui", { paths: [installRoot] });
|
|
57
|
+
const roots = await discoverRoots(cwd, ctx.workspaceRoot ?? cwd);
|
|
54
58
|
let url;
|
|
55
59
|
await createProcessLauncher({
|
|
56
60
|
id: DOCK_ID,
|
|
@@ -61,6 +65,7 @@ function DevToolsVitestUI() {
|
|
|
61
65
|
description: hasUi ? "Start the Vitest UI and view it inside DevTools." : "Install `@vitest/ui` (as a devDependency) and view it inside DevTools.",
|
|
62
66
|
buttonStart: hasUi ? "Start Vitest UI" : "Install @vitest/ui & start",
|
|
63
67
|
buttonLoading: "Starting Vitest UI…",
|
|
68
|
+
roots,
|
|
64
69
|
command: {
|
|
65
70
|
id: "vite:devtools:vitest:start-ui",
|
|
66
71
|
title: "Start Vitest UI",
|
|
@@ -72,16 +77,16 @@ function DevToolsVitestUI() {
|
|
|
72
77
|
icon: "ph:terminal-window-duotone"
|
|
73
78
|
},
|
|
74
79
|
prepare: async () => {
|
|
75
|
-
if (!isPackageExists("@vitest/ui", { paths: [
|
|
80
|
+
if (!isPackageExists("@vitest/ui", { paths: [installRoot] })) try {
|
|
76
81
|
await addDependency("@vitest/ui", {
|
|
77
|
-
cwd,
|
|
82
|
+
cwd: installRoot,
|
|
78
83
|
dev: true
|
|
79
84
|
});
|
|
80
85
|
} catch (error) {
|
|
81
86
|
throw diagnostics.VTDT0001({ error: error instanceof Error ? error.message : String(error) });
|
|
82
87
|
}
|
|
83
88
|
},
|
|
84
|
-
process: async () => {
|
|
89
|
+
process: async ({ root }) => {
|
|
85
90
|
const port = await getPort({
|
|
86
91
|
port: PREFERRED_PORT,
|
|
87
92
|
portRange: [PREFERRED_PORT, 51704]
|
|
@@ -92,10 +97,11 @@ function DevToolsVitestUI() {
|
|
|
92
97
|
args: [
|
|
93
98
|
"--ui",
|
|
94
99
|
"--no-open",
|
|
100
|
+
"--watch",
|
|
95
101
|
"--api.port",
|
|
96
102
|
String(port)
|
|
97
103
|
],
|
|
98
|
-
cwd
|
|
104
|
+
cwd: root ?? cwd
|
|
99
105
|
};
|
|
100
106
|
},
|
|
101
107
|
serve: { onReady: async () => {
|
|
@@ -109,6 +115,43 @@ function DevToolsVitestUI() {
|
|
|
109
115
|
} }
|
|
110
116
|
};
|
|
111
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Build the list of launch roots the user can run Vitest from: every directory
|
|
120
|
+
* holding a Vitest/Vite config in the workspace, with the project and workspace
|
|
121
|
+
* roots relabelled for clarity. The project root is only offered when it
|
|
122
|
+
* actually holds a config — running Vitest from a config-less directory isn't
|
|
123
|
+
* meaningful. Deduped by absolute path, first label wins.
|
|
124
|
+
*/
|
|
125
|
+
async function discoverRoots(cwd, workspaceRoot) {
|
|
126
|
+
const roots = /* @__PURE__ */ new Map();
|
|
127
|
+
const add = (path, label) => {
|
|
128
|
+
const abs = resolve(path);
|
|
129
|
+
if (!roots.has(abs)) roots.set(abs, {
|
|
130
|
+
value: abs,
|
|
131
|
+
label,
|
|
132
|
+
description: abs
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
let configDirs = [];
|
|
136
|
+
try {
|
|
137
|
+
configDirs = (await glob([
|
|
138
|
+
"**/vitest.config.*",
|
|
139
|
+
"**/vitest.workspace.*",
|
|
140
|
+
"**/vite.config.*"
|
|
141
|
+
], {
|
|
142
|
+
cwd: workspaceRoot,
|
|
143
|
+
absolute: true,
|
|
144
|
+
ignore: ["**/node_modules/**", "**/dist/**"]
|
|
145
|
+
})).map((file) => resolve(dirname(file)));
|
|
146
|
+
} catch {}
|
|
147
|
+
if (configDirs.includes(resolve(cwd))) add(cwd, "Project root");
|
|
148
|
+
if (resolve(workspaceRoot) !== resolve(cwd)) add(workspaceRoot, "Workspace root");
|
|
149
|
+
for (const dir of [...configDirs].sort((a, b) => a.localeCompare(b))) {
|
|
150
|
+
const rel = relative(workspaceRoot, dir);
|
|
151
|
+
add(dir, rel === "" ? "Workspace root" : rel);
|
|
152
|
+
}
|
|
153
|
+
return [...roots.values()];
|
|
154
|
+
}
|
|
112
155
|
async function waitForServer(url, timeout) {
|
|
113
156
|
const start = Date.now();
|
|
114
157
|
while (Date.now() - start < timeout) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitejs/devtools-vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"description": "DevTools for Vitest",
|
|
6
6
|
"author": "VoidZero Inc.",
|
|
7
7
|
"license": "MIT",
|
|
@@ -40,10 +40,11 @@
|
|
|
40
40
|
"local-pkg": "^1.2.1",
|
|
41
41
|
"nostics": "^1.2.0",
|
|
42
42
|
"nypm": "^0.6.8",
|
|
43
|
-
"
|
|
43
|
+
"tinyglobby": "^0.2.17",
|
|
44
|
+
"@vitejs/devtools-kit": "0.4.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"tsdown": "^0.22.
|
|
47
|
+
"tsdown": "^0.22.13"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
50
|
"build": "tsdown"
|