@nuxt/devtools-kit 4.0.0-alpha.7 → 4.0.0-alpha.8

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.cjs CHANGED
@@ -2,8 +2,112 @@
2
2
 
3
3
  const kit = require('@nuxt/kit');
4
4
  const tinyexec = require('tinyexec');
5
+ const nostics = require('nostics');
5
6
 
7
+ function diagnosticsDocsBase(code) {
8
+ return `https://devtools.nuxt.com/module/migration-v4#${String(code).toLowerCase()}`;
9
+ }
10
+ const diagnosticCodes = {
11
+ /** `startSubprocess().getProcess()` → `getResult()`. */
12
+ NDT_DEP_0001: {
13
+ why: (p) => `\`${p.api}\` is deprecated.`,
14
+ fix: (p) => `Use \`${p.replacement}\` instead.`
15
+ },
16
+ // NDT_DEP_0002 is retired (was `disableAuthorization`, now a supported
17
+ // first-class option). The code is left unused so numbers stay stable.
18
+ /** `extendServerRpc` → `onDevtoolsReady((ctx) => ctx.rpc.register(...))`. */
19
+ NDT_DEP_0003: {
20
+ why: (p) => `\`${p.api}\` is deprecated.`,
21
+ fix: (p) => `Use \`${p.replacement}\` instead.`
22
+ },
23
+ /** `startSubprocess` → `onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))`. */
24
+ NDT_DEP_0004: {
25
+ why: (p) => `\`${p.api}\` is deprecated.`,
26
+ fix: (p) => `Use \`${p.replacement}\` instead.`
27
+ },
28
+ /** `addCustomTab` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
29
+ NDT_DEP_0005: {
30
+ why: (p) => `\`${p.api}\` is deprecated.`,
31
+ fix: (p) => `Use \`${p.replacement}\` instead.`
32
+ },
33
+ /** `refreshCustomTabs` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
34
+ NDT_DEP_0006: {
35
+ why: (p) => `\`${p.api}\` is deprecated.`,
36
+ fix: (p) => `Use \`${p.replacement}\` instead.`
37
+ },
38
+ /** Direct `nuxt.devtools.rpc` access (`broadcast` / `functions`). */
39
+ NDT_DEP_0007: {
40
+ why: (p) => `\`${p.api}\` is deprecated.`,
41
+ fix: (p) => `Use \`${p.replacement}\` instead.`
42
+ },
43
+ // NDT_DEP_0008 is reserved for the removed `vscode` module option.
44
+ /** `getServerData()` RPC → the Data Inspector panel's `Nuxt Application` source. */
45
+ NDT_DEP_0009: {
46
+ why: (p) => `\`${p.api}\` is deprecated.`,
47
+ fix: (p) => `Use \`${p.replacement}\` instead.`
48
+ }
49
+ };
50
+ const consoleDiagnostics = nostics.defineDiagnostics({
51
+ docsBase: diagnosticsDocsBase,
52
+ reporters: [nostics.createConsoleReporter()],
53
+ codes: diagnosticCodes
54
+ });
55
+ const stateByCtx = /* @__PURE__ */ new WeakMap();
56
+ const fallbackState = { emitted: /* @__PURE__ */ new Set() };
57
+ function getState(ctx) {
58
+ if (!ctx)
59
+ return fallbackState;
60
+ let state = stateByCtx.get(ctx);
61
+ if (!state) {
62
+ state = { emitted: /* @__PURE__ */ new Set() };
63
+ stateByCtx.set(ctx, state);
64
+ }
65
+ return state;
66
+ }
67
+ function getServerContext(nuxt) {
68
+ return nuxt?.devtools;
69
+ }
70
+ function registerHostDiagnostics(ctx) {
71
+ const host = ctx.devtoolsKit?.diagnostics;
72
+ if (!host)
73
+ return;
74
+ const catalog = host.defineDiagnostics({
75
+ docsBase: diagnosticsDocsBase,
76
+ codes: diagnosticCodes
77
+ });
78
+ host.register(catalog);
79
+ getState(ctx).hostCatalog = catalog;
80
+ }
81
+ function deprecate(nuxt, code, params, options = {}) {
82
+ const ctx = getServerContext(nuxt);
83
+ const state = getState(ctx);
84
+ const dedupeKey = `${code}:${options.key ?? code}`;
85
+ if (state.emitted.has(dedupeKey))
86
+ return;
87
+ state.emitted.add(dedupeKey);
88
+ const method = options.method ?? "warn";
89
+ const hostHandle = state.hostCatalog?.[code];
90
+ if (hostHandle)
91
+ return hostHandle(params, { method });
92
+ const handle = consoleDiagnostics[code];
93
+ return handle(params, { method });
94
+ }
95
+ function defineStandaloneDiagnostics(options) {
96
+ return nostics.defineDiagnostics({
97
+ ...options,
98
+ reporters: options.reporters ?? [nostics.createConsoleReporter()]
99
+ });
100
+ }
101
+ function deprecateWithNuxt(code, params, options) {
102
+ return deprecate(kit.useNuxt(), code, params, options);
103
+ }
104
+
105
+ const NUXT_DEVTOOLS_GROUP_ID = "nuxt";
6
106
  function addCustomTab(tab, nuxt = kit.useNuxt()) {
107
+ deprecate(nuxt, "NDT_DEP_0005", {
108
+ api: "addCustomTab",
109
+ replacement: "onDevtoolsReady((ctx) => ctx.docks.register(...))"
110
+ }, { key: typeof tab === "function" ? void 0 : tab.name });
7
111
  nuxt.hook("devtools:customTabs", async (tabs) => {
8
112
  if (typeof tab === "function")
9
113
  tab = await tab();
@@ -11,9 +115,17 @@ function addCustomTab(tab, nuxt = kit.useNuxt()) {
11
115
  });
12
116
  }
13
117
  function refreshCustomTabs(nuxt = kit.useNuxt()) {
118
+ deprecate(nuxt, "NDT_DEP_0006", {
119
+ api: "refreshCustomTabs",
120
+ replacement: "onDevtoolsReady((ctx) => ctx.docks.register(...).update(...))"
121
+ });
14
122
  return nuxt.callHook("devtools:customTabs:refresh");
15
123
  }
16
124
  function startSubprocess(execaOptions, tabOptions, nuxt = kit.useNuxt()) {
125
+ deprecate(nuxt, "NDT_DEP_0004", {
126
+ api: "startSubprocess",
127
+ replacement: "onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))"
128
+ }, { key: tabOptions.id });
17
129
  const id = tabOptions.id;
18
130
  let restarting = false;
19
131
  function start() {
@@ -89,7 +201,10 @@ function startSubprocess(execaOptions, tabOptions, nuxt = kit.useNuxt()) {
89
201
  return {
90
202
  /** @deprecated Use `getResult()` instead */
91
203
  getProcess: () => {
92
- console.warn("[nuxt-devtools] `getProcess()` is deprecated, use `getResult()` instead.");
204
+ deprecate(nuxt, "NDT_DEP_0001", {
205
+ api: "startSubprocess().getProcess()",
206
+ replacement: "getResult()"
207
+ }, { key: id });
93
208
  return result.process;
94
209
  },
95
210
  getResult: () => result,
@@ -107,12 +222,26 @@ function extendServerRpc(namespace, functions, nuxt = kit.useNuxt()) {
107
222
  function onDevToolsInitialized(fn, nuxt = kit.useNuxt()) {
108
223
  nuxt.hook("devtools:initialized", fn);
109
224
  }
225
+ function onDevtoolsReady(fn, nuxt = kit.useNuxt()) {
226
+ nuxt.hook("devtools:ready", fn);
227
+ }
110
228
  function _getContext(nuxt = kit.useNuxt()) {
111
229
  return nuxt?.devtools;
112
230
  }
113
231
 
232
+ exports.createConsoleReporter = nostics.createConsoleReporter;
233
+ exports.defineDiagnostics = nostics.defineDiagnostics;
234
+ exports.NUXT_DEVTOOLS_GROUP_ID = NUXT_DEVTOOLS_GROUP_ID;
114
235
  exports.addCustomTab = addCustomTab;
236
+ exports.consoleDiagnostics = consoleDiagnostics;
237
+ exports.defineStandaloneDiagnostics = defineStandaloneDiagnostics;
238
+ exports.deprecate = deprecate;
239
+ exports.deprecateWithNuxt = deprecateWithNuxt;
240
+ exports.diagnosticCodes = diagnosticCodes;
241
+ exports.diagnosticsDocsBase = diagnosticsDocsBase;
115
242
  exports.extendServerRpc = extendServerRpc;
116
243
  exports.onDevToolsInitialized = onDevToolsInitialized;
244
+ exports.onDevtoolsReady = onDevtoolsReady;
117
245
  exports.refreshCustomTabs = refreshCustomTabs;
246
+ exports.registerHostDiagnostics = registerHostDiagnostics;
118
247
  exports.startSubprocess = startSubprocess;
package/dist/index.d.cts CHANGED
@@ -1,44 +1,266 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { ViteDevToolsNodeContext } from '@vitejs/devtools-kit';
2
3
  import { BirpcGroup } from 'birpc';
3
4
  import { ChildProcess } from 'node:child_process';
4
5
  import { Result } from 'tinyexec';
5
- import { r as ModuleCustomTab, O as NuxtDevtoolsInfo, a4 as SubprocessOptions, a9 as TerminalState } from './shared/devtools-kit.BwQLAI1z.cjs';
6
+ import { N as NuxtDevtoolsServerContext, M as ModuleCustomTab, a as NuxtDevtoolsInfo, S as SubprocessOptions, T as TerminalState } from './shared/devtools-kit.CC-eVeXW.cjs';
7
+ import * as nostics from 'nostics';
8
+ import { defineDiagnostics } from 'nostics';
9
+ export { createConsoleReporter, defineDiagnostics } from 'nostics';
10
+ import { Nuxt } from 'nuxt/schema';
6
11
  import 'vue';
7
- import '@vitejs/devtools-kit';
8
- import 'nuxt/schema';
9
12
  import 'unimport';
10
13
  import 'vue-router';
11
14
  import 'nitropack';
12
15
  import 'unstorage';
13
16
  import 'vite';
14
17
 
18
+ /**
19
+ * Canonical docs URL for a Nuxt DevTools diagnostic code.
20
+ *
21
+ * Each code links to a per-code anchor in the v4 migration guide, e.g.
22
+ * `NDT_DEP_0001` → `.../module/migration-v4#ndt_dep_0001`.
23
+ */
24
+ declare function diagnosticsDocsBase(code: string | number): string;
25
+ /**
26
+ * Parameters shared by every deprecation code: the API being used and its
27
+ * recommended replacement. Interpolated into the `why`/`fix` messages.
28
+ */
29
+ interface DeprecationParams {
30
+ /** The deprecated API / option being used. */
31
+ api: string;
32
+ /** The recommended replacement to migrate to. */
33
+ replacement: string;
34
+ }
35
+ /**
36
+ * The Nuxt DevTools diagnostics catalog.
37
+ *
38
+ * Codes are grouped by prefix:
39
+ * - `NDT_DEP_xxxx` — soft/hard deprecations (this is the only range used today).
40
+ *
41
+ * Severity is **not** encoded here; it is chosen per emission via the reporter
42
+ * `method` (`warn` by default, `error` for hard breaks).
43
+ */
44
+ declare const diagnosticCodes: {
45
+ /** `startSubprocess().getProcess()` → `getResult()`. */
46
+ NDT_DEP_0001: {
47
+ why: (p: DeprecationParams) => string;
48
+ fix: (p: DeprecationParams) => string;
49
+ };
50
+ /** `extendServerRpc` → `onDevtoolsReady((ctx) => ctx.rpc.register(...))`. */
51
+ NDT_DEP_0003: {
52
+ why: (p: DeprecationParams) => string;
53
+ fix: (p: DeprecationParams) => string;
54
+ };
55
+ /** `startSubprocess` → `onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))`. */
56
+ NDT_DEP_0004: {
57
+ why: (p: DeprecationParams) => string;
58
+ fix: (p: DeprecationParams) => string;
59
+ };
60
+ /** `addCustomTab` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
61
+ NDT_DEP_0005: {
62
+ why: (p: DeprecationParams) => string;
63
+ fix: (p: DeprecationParams) => string;
64
+ };
65
+ /** `refreshCustomTabs` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
66
+ NDT_DEP_0006: {
67
+ why: (p: DeprecationParams) => string;
68
+ fix: (p: DeprecationParams) => string;
69
+ };
70
+ /** Direct `nuxt.devtools.rpc` access (`broadcast` / `functions`). */
71
+ NDT_DEP_0007: {
72
+ why: (p: DeprecationParams) => string;
73
+ fix: (p: DeprecationParams) => string;
74
+ };
75
+ /** `getServerData()` RPC → the Data Inspector panel's `Nuxt Application` source. */
76
+ NDT_DEP_0009: {
77
+ why: (p: DeprecationParams) => string;
78
+ fix: (p: DeprecationParams) => string;
79
+ };
80
+ };
81
+ type NuxtDiagnosticCode = keyof typeof diagnosticCodes;
82
+ /**
83
+ * Standalone catalog that prints to the terminal via nostics'
84
+ * {@link createConsoleReporter} (default method `warn`). Works before the Vite
85
+ * DevTools kit connects, so it is the fallback sink for pre-connect emissions.
86
+ */
87
+ declare const consoleDiagnostics: nostics.Diagnostics<{
88
+ /** `startSubprocess().getProcess()` → `getResult()`. */
89
+ NDT_DEP_0001: {
90
+ why: (p: DeprecationParams) => string;
91
+ fix: (p: DeprecationParams) => string;
92
+ };
93
+ /** `extendServerRpc` → `onDevtoolsReady((ctx) => ctx.rpc.register(...))`. */
94
+ NDT_DEP_0003: {
95
+ why: (p: DeprecationParams) => string;
96
+ fix: (p: DeprecationParams) => string;
97
+ };
98
+ /** `startSubprocess` → `onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))`. */
99
+ NDT_DEP_0004: {
100
+ why: (p: DeprecationParams) => string;
101
+ fix: (p: DeprecationParams) => string;
102
+ };
103
+ /** `addCustomTab` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
104
+ NDT_DEP_0005: {
105
+ why: (p: DeprecationParams) => string;
106
+ fix: (p: DeprecationParams) => string;
107
+ };
108
+ /** `refreshCustomTabs` → `onDevtoolsReady((ctx) => ctx.docks.register(...))`. */
109
+ NDT_DEP_0006: {
110
+ why: (p: DeprecationParams) => string;
111
+ fix: (p: DeprecationParams) => string;
112
+ };
113
+ /** Direct `nuxt.devtools.rpc` access (`broadcast` / `functions`). */
114
+ NDT_DEP_0007: {
115
+ why: (p: DeprecationParams) => string;
116
+ fix: (p: DeprecationParams) => string;
117
+ };
118
+ /** `getServerData()` RPC → the Data Inspector panel's `Nuxt Application` source. */
119
+ NDT_DEP_0009: {
120
+ why: (p: DeprecationParams) => string;
121
+ fix: (p: DeprecationParams) => string;
122
+ };
123
+ }, readonly [nostics.DiagnosticReporter<{
124
+ method?: nostics.ConsoleMethod;
125
+ }>]>;
126
+ /**
127
+ * Register the Nuxt deprecation codes into the connected Vite DevTools kit's
128
+ * diagnostics host so they are known to DevTools and post-connect emissions
129
+ * surface in the DevTools diagnostics UI. Safe to call when no host is present.
130
+ *
131
+ * Called from `connectDevToolsKit`.
132
+ */
133
+ declare function registerHostDiagnostics(ctx: NuxtDevtoolsServerContext): void;
134
+ /**
135
+ * Options for {@link deprecate}.
136
+ */
137
+ interface DeprecateOptions {
138
+ /**
139
+ * Dedupe key appended to the code. Defaults to the code itself, i.e. the
140
+ * deprecation warns once per process. Pass a finer key (e.g. a subprocess id)
141
+ * to warn once per distinct call site instead.
142
+ */
143
+ key?: string;
144
+ /**
145
+ * Reporter method / severity. `warn` (default) for soft deprecations, `error`
146
+ * for hard breaks. The returned {@link Diagnostic} can be thrown to abort.
147
+ */
148
+ method?: 'warn' | 'error';
149
+ }
150
+ /**
151
+ * Emit a Nuxt DevTools deprecation diagnostic.
152
+ *
153
+ * Routing: when the Vite DevTools kit is connected the emission goes through the
154
+ * DevTools host catalog (terminal **and** the DevTools diagnostics UI); before
155
+ * connect it falls back to the terminal-only console catalog. A single emission
156
+ * per call — no double printing.
157
+ *
158
+ * Deduped per `${code}:${key ?? code}` on the resolved server context, so a hot
159
+ * path warns only once.
160
+ *
161
+ * @returns the built `Diagnostic` (which extends `Error`, so it can be thrown
162
+ * for hard breaks), or `undefined` if the emission was deduped.
163
+ */
164
+ declare function deprecate(nuxt: Nuxt, code: NuxtDiagnosticCode, params: DeprecationParams, options?: DeprecateOptions): Error | undefined;
165
+ /**
166
+ * Build a standalone nostics catalog that prints to the terminal.
167
+ *
168
+ * Used by the connect-safe `nuxt.devtools.diagnostics` accessor so module
169
+ * authors can define + emit diagnostics before the Vite DevTools kit connects.
170
+ * A `createConsoleReporter()` is added automatically unless the caller supplies
171
+ * its own `reporters`.
172
+ */
173
+ declare function defineStandaloneDiagnostics(options: Parameters<typeof defineDiagnostics>[0]): ReturnType<typeof defineDiagnostics>;
174
+ /**
175
+ * Convenience wrapper for call sites that don't already hold the Nuxt instance.
176
+ */
177
+ declare function deprecateWithNuxt(code: NuxtDiagnosticCode, params: DeprecationParams, options?: DeprecateOptions): Error | undefined;
178
+
179
+ /**
180
+ * The public `Nuxt` dock group id registered on the Vite DevTools framework
181
+ * category. Module authors join the group natively by pointing their own
182
+ * dock entries at it — no special Nuxt API required:
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import { NUXT_DEVTOOLS_GROUP_ID, onDevtoolsReady } from '@nuxt/devtools-kit'
187
+ *
188
+ * onDevtoolsReady((ctx) => {
189
+ * ctx.docks.register({
190
+ * id: 'my-module',
191
+ * type: 'iframe',
192
+ * title: 'My Module',
193
+ * icon: 'i-ph-puzzle-piece',
194
+ * url: '/my-module/',
195
+ * groupId: NUXT_DEVTOOLS_GROUP_ID,
196
+ * })
197
+ * })
198
+ * ```
199
+ */
200
+ declare const NUXT_DEVTOOLS_GROUP_ID = "nuxt";
15
201
  /**
16
202
  * Hooks to extend a custom tab in devtools.
17
203
  *
18
204
  * Provide a function to pass a factory that can be updated dynamically.
205
+ *
206
+ * @deprecated Register a dock entry from the `devtools:ready` hook instead:
207
+ * `onDevtoolsReady((ctx) => ctx.docks.register(...))`. Still works as a shim, but
208
+ * emits the `NDT_DEP_0005` deprecation diagnostic. Note the docks host does not
209
+ * yet cover `vnode` views or tab categories.
19
210
  */
20
211
  declare function addCustomTab(tab: ModuleCustomTab | (() => ModuleCustomTab | Promise<ModuleCustomTab>), nuxt?: _nuxt_schema.Nuxt): void;
21
212
  /**
22
213
  * Retrigger update for custom tabs, `devtools:customTabs` will be called again.
214
+ *
215
+ * @deprecated Update dock entries directly via the handle returned by
216
+ * `ctx.docks.register(...)` inside the `devtools:ready` hook. Still works as a
217
+ * shim, but emits the `NDT_DEP_0006` deprecation diagnostic.
23
218
  */
24
219
  declare function refreshCustomTabs(nuxt?: _nuxt_schema.Nuxt): void | Promise<any>;
25
- /**
26
- * Create a subprocess that handled by the DevTools.
27
- */
28
- declare function startSubprocess(execaOptions: SubprocessOptions, tabOptions: TerminalState, nuxt?: _nuxt_schema.Nuxt): {
220
+ interface StartSubprocessReturn {
29
221
  /** @deprecated Use `getResult()` instead */
30
222
  getProcess: () => ChildProcess | undefined;
31
223
  getResult: () => Result;
32
224
  terminate: () => void;
33
225
  restart: () => void;
34
226
  clear: () => void;
35
- };
227
+ }
228
+ /**
229
+ * Create a subprocess that handled by the DevTools.
230
+ *
231
+ * @deprecated Use the Vite DevTools terminals host from the `devtools:ready`
232
+ * hook instead: `onDevtoolsReady((ctx) => ctx.terminals.startChildProcess(...))`.
233
+ * Still works as a shim, but emits the `NDT_DEP_0004` deprecation diagnostic.
234
+ */
235
+ declare function startSubprocess(execaOptions: SubprocessOptions, tabOptions: TerminalState, nuxt?: _nuxt_schema.Nuxt): StartSubprocessReturn;
36
236
  /**
37
237
  * Extend server RPC with namespaced functions.
38
238
  *
39
239
  * Returns an object with a `broadcast` proxy for calling client functions.
240
+ *
241
+ * @deprecated Register RPC functions from the `devtools:ready` hook instead:
242
+ * `onDevtoolsReady((ctx) => ctx.rpc.register(defineRpcFunction(...)))`. Still
243
+ * works as a shim, but emits the `NDT_DEP_0003` deprecation diagnostic.
40
244
  */
41
245
  declare function extendServerRpc<ClientFunctions extends object = Record<string, unknown>, ServerFunctions extends object = Record<string, unknown>>(namespace: string, functions: ServerFunctions, nuxt?: _nuxt_schema.Nuxt): BirpcGroup<ClientFunctions, ServerFunctions>;
42
246
  declare function onDevToolsInitialized(fn: (info: NuxtDevtoolsInfo) => void, nuxt?: _nuxt_schema.Nuxt): void;
247
+ /**
248
+ * Run a callback once the Vite DevTools kit has connected, receiving the
249
+ * connected `ViteDevToolsNodeContext`.
250
+ *
251
+ * This is the recommended entry point for DevTools integration: the kit is
252
+ * guaranteed available, so you can use `ctx.docks` / `ctx.terminals` /
253
+ * `ctx.messages` / `ctx.commands` / `ctx.rpc` / `ctx.diagnostics` directly
254
+ * without the connect-safe accessors on `nuxt.devtools`.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * onDevtoolsReady((ctx) => {
259
+ * ctx.docks.register({ id: 'my-module', title: 'My Module', type: 'iframe', url: '/…' })
260
+ * })
261
+ * ```
262
+ */
263
+ declare function onDevtoolsReady(fn: (ctx: ViteDevToolsNodeContext) => void | Promise<void>, nuxt?: _nuxt_schema.Nuxt): void;
43
264
 
44
- export { addCustomTab, extendServerRpc, onDevToolsInitialized, refreshCustomTabs, startSubprocess };
265
+ export { NUXT_DEVTOOLS_GROUP_ID, addCustomTab, consoleDiagnostics, defineStandaloneDiagnostics, deprecate, deprecateWithNuxt, diagnosticCodes, diagnosticsDocsBase, extendServerRpc, onDevToolsInitialized, onDevtoolsReady, refreshCustomTabs, registerHostDiagnostics, startSubprocess };
266
+ export type { DeprecateOptions, DeprecationParams, NuxtDiagnosticCode, StartSubprocessReturn };