@nuxt/devtools-kit 3.4.0 → 4.0.0-alpha.10

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 CHANGED
@@ -1,7 +1,116 @@
1
1
  import { useNuxt } from '@nuxt/kit';
2
- import { execa } from 'execa';
2
+ import { x } from 'tinyexec';
3
+ import { defineDiagnostics, createConsoleReporter } from 'nostics';
4
+ export { createConsoleReporter, defineDiagnostics } from 'nostics';
3
5
 
6
+ function diagnosticsDocsBase(code) {
7
+ return `https://devtools.nuxt.com/module/migration-v4#${String(code).toLowerCase()}`;
8
+ }
9
+ const diagnosticCodes = {
10
+ /** `startSubprocess().getProcess()` → `getResult()`. */
11
+ NDT_DEP_0001: {
12
+ why: (p) => `\`${p.api}\` is deprecated.`,
13
+ fix: (p) => `Use \`${p.replacement}\` instead.`
14
+ },
15
+ // NDT_DEP_0002 is retired (was `disableAuthorization`, now a supported
16
+ // first-class option). The code is left unused so numbers stay stable.
17
+ /** `extendServerRpc` → `onDevtoolsReady((ctx) => ctx.rpc.register(...))`. */
18
+ NDT_DEP_0003: {
19
+ why: (p) => `\`${p.api}\` is deprecated.`,
20
+ fix: (p) => `Use \`${p.replacement}\` instead.`
21
+ },
22
+ /** `startSubprocess` → `onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))`. */
23
+ NDT_DEP_0004: {
24
+ why: (p) => `\`${p.api}\` is deprecated.`,
25
+ fix: (p) => `Use \`${p.replacement}\` instead.`
26
+ },
27
+ /** `addCustomTab` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
28
+ NDT_DEP_0005: {
29
+ why: (p) => `\`${p.api}\` is deprecated.`,
30
+ fix: (p) => `Use \`${p.replacement}\` instead.`
31
+ },
32
+ /** `refreshCustomTabs` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
33
+ NDT_DEP_0006: {
34
+ why: (p) => `\`${p.api}\` is deprecated.`,
35
+ fix: (p) => `Use \`${p.replacement}\` instead.`
36
+ },
37
+ /** Direct `nuxt.devtools.rpc` access (`broadcast` / `functions`). */
38
+ NDT_DEP_0007: {
39
+ why: (p) => `\`${p.api}\` is deprecated.`,
40
+ fix: (p) => `Use \`${p.replacement}\` instead.`
41
+ },
42
+ /** Removed `vscode` module option → `codeServer`. */
43
+ NDT_DEP_0008: {
44
+ why: (p) => `\`${p.api}\` is deprecated and its legacy modes are no longer supported.`,
45
+ fix: (p) => `Use \`${p.replacement}\` instead. The legacy value is ignored rather than partially translated.`
46
+ },
47
+ /** `getServerData()` RPC → the Data Inspector panel's `Nuxt Application` source. */
48
+ NDT_DEP_0009: {
49
+ why: (p) => `\`${p.api}\` is deprecated.`,
50
+ fix: (p) => `Use \`${p.replacement}\` instead.`
51
+ }
52
+ };
53
+ const consoleDiagnostics = defineDiagnostics({
54
+ docsBase: diagnosticsDocsBase,
55
+ reporters: [createConsoleReporter()],
56
+ codes: diagnosticCodes
57
+ });
58
+ const stateByCtx = /* @__PURE__ */ new WeakMap();
59
+ const fallbackState = { emitted: /* @__PURE__ */ new Set() };
60
+ function getState(ctx) {
61
+ if (!ctx)
62
+ return fallbackState;
63
+ let state = stateByCtx.get(ctx);
64
+ if (!state) {
65
+ state = { emitted: /* @__PURE__ */ new Set() };
66
+ stateByCtx.set(ctx, state);
67
+ }
68
+ return state;
69
+ }
70
+ function getServerContext(nuxt) {
71
+ return nuxt?.devtools;
72
+ }
73
+ function registerHostDiagnostics(ctx) {
74
+ const host = ctx.devtoolsKit?.diagnostics;
75
+ if (!host)
76
+ return;
77
+ const catalog = host.defineDiagnostics({
78
+ docsBase: diagnosticsDocsBase,
79
+ codes: diagnosticCodes
80
+ });
81
+ host.register(catalog);
82
+ getState(ctx).hostCatalog = catalog;
83
+ }
84
+ function deprecate(nuxt, code, params, options = {}) {
85
+ const ctx = getServerContext(nuxt);
86
+ const state = getState(ctx);
87
+ const dedupeKey = `${code}:${options.key ?? code}`;
88
+ if (state.emitted.has(dedupeKey))
89
+ return;
90
+ state.emitted.add(dedupeKey);
91
+ const method = options.method ?? "warn";
92
+ const hostHandle = state.hostCatalog?.[code];
93
+ if (hostHandle)
94
+ return hostHandle(params, { method });
95
+ const handle = consoleDiagnostics[code];
96
+ return handle(params, { method });
97
+ }
98
+ function defineStandaloneDiagnostics(options) {
99
+ return defineDiagnostics({
100
+ ...options,
101
+ reporters: options.reporters ?? [createConsoleReporter()]
102
+ });
103
+ }
104
+ function deprecateWithNuxt(code, params, options) {
105
+ return deprecate(useNuxt(), code, params, options);
106
+ }
107
+
108
+ const NUXT_DEVTOOLS_GROUP_ID = "nuxt";
4
109
  function addCustomTab(tab, nuxt = useNuxt()) {
110
+ deprecate(nuxt, "NDT_DEP_0005", {
111
+ api: "addCustomTab",
112
+ replacement: "onDevtoolsReady((ctx) => ctx.docks.register(...))"
113
+ }, { key: typeof tab === "function" ? void 0 : tab.name });
5
114
  nuxt.hook("devtools:customTabs", async (tabs) => {
6
115
  if (typeof tab === "function")
7
116
  tab = await tab();
@@ -9,56 +118,67 @@ function addCustomTab(tab, nuxt = useNuxt()) {
9
118
  });
10
119
  }
11
120
  function refreshCustomTabs(nuxt = useNuxt()) {
121
+ deprecate(nuxt, "NDT_DEP_0006", {
122
+ api: "refreshCustomTabs",
123
+ replacement: "onDevtoolsReady((ctx) => ctx.docks.register(...).update(...))"
124
+ });
12
125
  return nuxt.callHook("devtools:customTabs:refresh");
13
126
  }
14
127
  function startSubprocess(execaOptions, tabOptions, nuxt = useNuxt()) {
128
+ deprecate(nuxt, "NDT_DEP_0004", {
129
+ api: "startSubprocess",
130
+ replacement: "onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))"
131
+ }, { key: tabOptions.id });
15
132
  const id = tabOptions.id;
16
133
  let restarting = false;
17
134
  function start() {
18
- const process2 = execa(
135
+ const proc = x(
19
136
  execaOptions.command,
20
137
  execaOptions.args,
21
138
  {
22
- reject: false,
23
- ...execaOptions,
24
- env: {
25
- COLORS: "true",
26
- FORCE_COLOR: "true",
27
- ...execaOptions.env,
28
- // Force disable Nuxi CLI override
29
- __CLI_ARGV__: void 0
139
+ nodeOptions: {
140
+ ...execaOptions.nodeOptions,
141
+ cwd: execaOptions.cwd ?? execaOptions.nodeOptions?.cwd,
142
+ env: {
143
+ ...process.env,
144
+ COLORS: "true",
145
+ FORCE_COLOR: "true",
146
+ ...execaOptions.env,
147
+ ...execaOptions.nodeOptions?.env,
148
+ __CLI_ARGV__: void 0
149
+ }
30
150
  }
31
151
  }
32
152
  );
33
153
  nuxt.callHook("devtools:terminal:write", { id, data: `> ${[execaOptions.command, ...execaOptions.args || []].join(" ")}
34
154
 
35
155
  ` });
36
- process2.stdout.on("data", (data) => {
156
+ proc.process?.stdout?.on("data", (data) => {
37
157
  nuxt.callHook("devtools:terminal:write", { id, data: data.toString() });
38
158
  });
39
- process2.stderr.on("data", (data) => {
159
+ proc.process?.stderr?.on("data", (data) => {
40
160
  nuxt.callHook("devtools:terminal:write", { id, data: data.toString() });
41
161
  });
42
- process2.on("exit", (code) => {
162
+ proc.process?.on("exit", (code) => {
43
163
  if (!restarting) {
44
164
  nuxt.callHook("devtools:terminal:write", { id, data: `
45
- > process terminalated with ${code}
165
+ > process terminated with ${code}
46
166
  ` });
47
167
  nuxt.callHook("devtools:terminal:exit", { id, code: code || 0 });
48
168
  }
49
169
  });
50
- return process2;
170
+ return proc;
51
171
  }
52
172
  register();
53
173
  nuxt.hook("close", () => {
54
174
  terminate();
55
175
  });
56
- let process = start();
176
+ let result = start();
57
177
  function restart() {
58
178
  restarting = true;
59
- process?.kill();
179
+ result.kill();
60
180
  clear();
61
- process = start();
181
+ result = start();
62
182
  restarting = false;
63
183
  }
64
184
  function clear() {
@@ -68,7 +188,7 @@ function startSubprocess(execaOptions, tabOptions, nuxt = useNuxt()) {
68
188
  function terminate() {
69
189
  restarting = false;
70
190
  try {
71
- process?.kill();
191
+ result.kill();
72
192
  } catch {
73
193
  }
74
194
  nuxt.callHook("devtools:terminal:remove", { id });
@@ -82,7 +202,15 @@ function startSubprocess(execaOptions, tabOptions, nuxt = useNuxt()) {
82
202
  });
83
203
  }
84
204
  return {
85
- getProcess: () => process,
205
+ /** @deprecated Use `getResult()` instead */
206
+ getProcess: () => {
207
+ deprecate(nuxt, "NDT_DEP_0001", {
208
+ api: "startSubprocess().getProcess()",
209
+ replacement: "getResult()"
210
+ }, { key: id });
211
+ return result.process;
212
+ },
213
+ getResult: () => result,
86
214
  terminate,
87
215
  restart,
88
216
  clear
@@ -97,8 +225,11 @@ function extendServerRpc(namespace, functions, nuxt = useNuxt()) {
97
225
  function onDevToolsInitialized(fn, nuxt = useNuxt()) {
98
226
  nuxt.hook("devtools:initialized", fn);
99
227
  }
228
+ function onDevtoolsReady(fn, nuxt = useNuxt()) {
229
+ nuxt.hook("devtools:ready", fn);
230
+ }
100
231
  function _getContext(nuxt = useNuxt()) {
101
232
  return nuxt?.devtools;
102
233
  }
103
234
 
104
- export { addCustomTab, extendServerRpc, onDevToolsInitialized, refreshCustomTabs, startSubprocess };
235
+ export { NUXT_DEVTOOLS_GROUP_ID, addCustomTab, consoleDiagnostics, defineStandaloneDiagnostics, deprecate, deprecateWithNuxt, diagnosticCodes, diagnosticsDocsBase, extendServerRpc, onDevToolsInitialized, onDevtoolsReady, refreshCustomTabs, registerHostDiagnostics, startSubprocess };
@@ -1,4 +1,22 @@
1
+ import type { DevToolsRpcClient } from '@vitejs/devtools-kit/client';
1
2
  import type { Ref } from 'vue';
2
3
  import type { NuxtDevtoolsIframeClient } from '../types';
3
4
  export declare function onDevtoolsClientConnected(fn: (client: NuxtDevtoolsIframeClient) => void): (() => void) | undefined;
5
+ /**
6
+ * Run a callback once the Vite DevTools client is ready, receiving the connected
7
+ * `DevToolsRpcClient` — the client-side mirror of the server's
8
+ * `onDevtoolsReady((ctx) => …)`.
9
+ *
10
+ * This is the recommended way to do client-side DevTools integration (register
11
+ * client RPC functions, call server functions, shared state, streaming, …):
12
+ *
13
+ * ```ts
14
+ * import { onDevtoolsReady } from '@nuxt/devtools-kit/iframe-client'
15
+ *
16
+ * onDevtoolsReady((kit) => {
17
+ * kit.client.register({ name: 'my-module:on-update', type: 'event', handler })
18
+ * })
19
+ * ```
20
+ */
21
+ export declare function onDevtoolsReady(fn: (kit: DevToolsRpcClient) => void): (() => void) | undefined;
4
22
  export declare function useDevtoolsClient(): Ref<NuxtDevtoolsIframeClient | undefined, NuxtDevtoolsIframeClient | undefined>;
@@ -25,6 +25,13 @@ export function onDevtoolsClientConnected(fn) {
25
25
  fns.splice(fns.indexOf(fn), 1);
26
26
  };
27
27
  }
28
+ export function onDevtoolsReady(fn) {
29
+ return onDevtoolsClientConnected((client) => {
30
+ const kit = client.devtools.devtoolsKit;
31
+ if (kit)
32
+ fn(kit);
33
+ });
34
+ }
28
35
  export function useDevtoolsClient() {
29
36
  if (!clientRef) {
30
37
  clientRef = shallowRef();