@vitejs/devtools-vitest 0.7.3 → 0.7.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +20 -4
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -4,7 +4,8 @@ import process from "node:process";
4
4
  import { createProcessLauncher } from "@vitejs/devtools-kit/node";
5
5
  import { getPort } from "devframe/utils/get-port";
6
6
  import { isPackageExists } from "local-pkg";
7
- import { addDependency } from "nypm";
7
+ import { resolveCommand } from "package-manager-detector/commands";
8
+ import { detect } from "package-manager-detector/detect";
8
9
  import { glob } from "tinyglobby";
9
10
  import { createConsoleReporter, defineDiagnostics } from "nostics";
10
11
  //#region src/node/diagnostics.ts
@@ -29,6 +30,8 @@ const VITEST_DEVTOOLS_BASE = "/__devtools-vitest/";
29
30
  const VITEST_UI_PATH = "__vitest__/";
30
31
  /** Fixed terminal-session id so re-launches are idempotent. */
31
32
  const SESSION_ID = "vitest:ui";
33
+ /** Terminal-session id for the on-demand `@vitest/ui` install. */
34
+ const INSTALL_SESSION_ID = "vitest:install";
32
35
  const DOCK_ID = "vitest";
33
36
  const PREFERRED_PORT = 51204;
34
37
  const READY_TIMEOUT = 3e4;
@@ -55,6 +58,7 @@ function DevToolsVitestUI() {
55
58
  const hasUi = isPackageExists("@vitest/ui", { paths: [installRoot] });
56
59
  const roots = await discoverRoots(cwd, ctx.workspaceRoot ?? cwd);
57
60
  let url;
61
+ let installSession;
58
62
  await createProcessLauncher({
59
63
  id: DOCK_ID,
60
64
  title: "Vitest",
@@ -77,10 +81,22 @@ function DevToolsVitestUI() {
77
81
  },
78
82
  prepare: async () => {
79
83
  if (!isPackageExists("@vitest/ui", { paths: [installRoot] })) try {
80
- await addDependency("@vitest/ui", {
81
- cwd: installRoot,
82
- dev: true
84
+ if (installSession) await installSession.terminate().catch(() => {});
85
+ installSession = void 0;
86
+ ctx.terminals.sessions.delete(INSTALL_SESSION_ID);
87
+ const agent = (await detect({ cwd: installRoot }))?.agent ?? "npm";
88
+ const { command, args } = resolveCommand(agent, "add", ["-D", "@vitest/ui"]);
89
+ installSession = await ctx.terminals.startChildProcess({
90
+ command,
91
+ args,
92
+ cwd: installRoot
93
+ }, {
94
+ id: INSTALL_SESSION_ID,
95
+ title: "Install @vitest/ui",
96
+ icon: "ph:terminal-window-duotone"
83
97
  });
98
+ const result = await installSession.getResult();
99
+ if (result.exitCode !== 0) throw new Error(`\`${command} ${args.join(" ")}\` exited with code ${result.exitCode ?? "null"}.`);
84
100
  } catch (error) {
85
101
  throw diagnostics.VTDT0001({ error: error instanceof Error ? error.message : String(error) });
86
102
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitejs/devtools-vitest",
3
3
  "type": "module",
4
- "version": "0.7.3",
4
+ "version": "0.7.4",
5
5
  "description": "DevTools for Vitest",
6
6
  "author": "VoidZero Inc.",
7
7
  "license": "MIT",
@@ -36,11 +36,11 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@vitejs/devtools-kit": "0.7.3",
40
- "devframe": "^0.9.16",
39
+ "@vitejs/devtools-kit": "0.7.4",
40
+ "devframe": "^0.10.0",
41
41
  "local-pkg": "^1.2.1",
42
42
  "nostics": "^1.2.0",
43
- "nypm": "^0.6.9",
43
+ "package-manager-detector": "^1.8.0",
44
44
  "tinyglobby": "^0.2.17"
45
45
  },
46
46
  "devDependencies": {