@nuxt/devtools-kit 4.0.0-alpha.1 → 4.0.0-alpha.11

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
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,9 +118,17 @@ 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() {
@@ -21,6 +138,7 @@ function startSubprocess(execaOptions, tabOptions, nuxt = useNuxt()) {
21
138
  {
22
139
  nodeOptions: {
23
140
  ...execaOptions.nodeOptions,
141
+ cwd: execaOptions.cwd ?? execaOptions.nodeOptions?.cwd,
24
142
  env: {
25
143
  ...process.env,
26
144
  COLORS: "true",
@@ -86,7 +204,10 @@ function startSubprocess(execaOptions, tabOptions, nuxt = useNuxt()) {
86
204
  return {
87
205
  /** @deprecated Use `getResult()` instead */
88
206
  getProcess: () => {
89
- console.warn("[nuxt-devtools] `getProcess()` is deprecated, use `getResult()` instead.");
207
+ deprecate(nuxt, "NDT_DEP_0001", {
208
+ api: "startSubprocess().getProcess()",
209
+ replacement: "getResult()"
210
+ }, { key: id });
90
211
  return result.process;
91
212
  },
92
213
  getResult: () => result,
@@ -104,8 +225,11 @@ function extendServerRpc(namespace, functions, nuxt = useNuxt()) {
104
225
  function onDevToolsInitialized(fn, nuxt = useNuxt()) {
105
226
  nuxt.hook("devtools:initialized", fn);
106
227
  }
228
+ function onDevtoolsReady(fn, nuxt = useNuxt()) {
229
+ nuxt.hook("devtools:ready", fn);
230
+ }
107
231
  function _getContext(nuxt = useNuxt()) {
108
232
  return nuxt?.devtools;
109
233
  }
110
234
 
111
- 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();