@nuxt/devtools 0.2.5 → 0.3.1

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 (134) hide show
  1. package/README.md +3 -3
  2. package/dist/chunks/module-main.mjs +692 -258
  3. package/dist/chunks/plugin-metrics.mjs +56 -0
  4. package/dist/chunks/vite-inspect.mjs +12 -13
  5. package/dist/chunks/vscode.mjs +44 -26
  6. package/dist/chunks/vue-inspector.mjs +2 -2
  7. package/dist/cli.mjs +5 -4
  8. package/dist/client/200.html +2 -2
  9. package/dist/client/404.html +2 -2
  10. package/dist/client/__inspecting/index.html +2 -2
  11. package/dist/client/_nuxt/Badge.ec308af3.js +1 -0
  12. package/dist/client/_nuxt/DrawerRight.vue.a85afa62.js +1 -0
  13. package/dist/client/_nuxt/DurationDisplay.vue.9b5b62d4.js +1 -0
  14. package/dist/client/_nuxt/FilepathItem.vue.178a1de3.js +1 -0
  15. package/dist/client/_nuxt/LaunchPage.vue.a0bbd67e.js +1 -0
  16. package/dist/client/_nuxt/NCheckbox.vue.4a02f339.js +1 -0
  17. package/dist/client/_nuxt/NCodeBlock.vue.593cb41f.js +1 -0
  18. package/dist/client/_nuxt/NIconButton.vue.a83f99ea.js +1 -0
  19. package/dist/client/_nuxt/NIconTitle.vue.ce90e41b.js +1 -0
  20. package/dist/client/_nuxt/NMarkdown.vue.11f68fad.js +1 -0
  21. package/dist/client/_nuxt/NSectionBlock.c955e75e.js +1 -0
  22. package/dist/client/_nuxt/NSelect.vue.e19311d6.js +1 -0
  23. package/dist/client/_nuxt/NSwitch.vue.76c93e66.js +1 -0
  24. package/dist/client/_nuxt/NTextInput.vue.d770ca6c.js +1 -0
  25. package/dist/client/_nuxt/NTip.vue.ac67cde4.js +1 -0
  26. package/dist/client/_nuxt/NpmVersionCheck.vue.0eab98c7.js +1 -0
  27. package/dist/client/_nuxt/{NuxtLogo.8111403f.js → NuxtLogo.38adb408.js} +1 -1
  28. package/dist/client/_nuxt/{PanelLeftRight.vue.56b5906c.js → PanelLeftRight.vue.90cdedcf.js} +1 -1
  29. package/dist/client/_nuxt/StateEditor.vue.c57dfe46.js +1 -0
  30. package/dist/client/_nuxt/{TabIcon.vue.30ae65eb.js → TabIcon.vue.8236980c.js} +1 -1
  31. package/dist/client/_nuxt/{__inspecting.8819ade8.js → __inspecting.143a746c.js} +1 -1
  32. package/dist/client/_nuxt/assets.d6a1ab2b.js +16 -0
  33. package/dist/client/_nuxt/components.1b7f02b2.js +1 -0
  34. package/dist/client/_nuxt/context.fe69916a.js +1 -0
  35. package/dist/client/_nuxt/custom-_name_.02ebd30e.js +1 -0
  36. package/dist/client/_nuxt/default.e6b60844.js +1 -0
  37. package/dist/client/_nuxt/editor.e10c09a2.js +1 -0
  38. package/dist/client/_nuxt/entry.216b69f8.js +259 -0
  39. package/dist/client/_nuxt/entry.654353dc.css +32 -0
  40. package/dist/client/_nuxt/error-404.51bdc645.js +1 -0
  41. package/dist/client/_nuxt/{error-500.8f6cefc5.js → error-500.15ac1dfe.js} +1 -1
  42. package/dist/client/_nuxt/error-component.0a7a48e4.js +3 -0
  43. package/dist/client/_nuxt/hooks.aa487478.js +1 -0
  44. package/dist/client/_nuxt/icons.43eaabec.js +1 -0
  45. package/dist/client/_nuxt/imports.01c0f8be.js +1 -0
  46. package/dist/client/_nuxt/{index.a6656ecb.js → index.3b3b7aca.js} +5 -5
  47. package/dist/client/_nuxt/index.517491fb.js +1 -0
  48. package/dist/client/_nuxt/index.c769634a.js +3 -0
  49. package/dist/client/_nuxt/layouts.e447e192.js +1 -0
  50. package/dist/client/_nuxt/middleware.e73473f1.js +1 -0
  51. package/dist/client/_nuxt/modules.304ea21e.js +1 -0
  52. package/dist/client/_nuxt/{none.394b52e6.js → none.3e2499ec.js} +1 -1
  53. package/dist/client/_nuxt/overview.b79bf694.js +1 -0
  54. package/dist/client/_nuxt/pages.fafa9fe0.js +1 -0
  55. package/dist/client/_nuxt/payload.ee430f3a.js +1 -0
  56. package/dist/client/_nuxt/plugins.5095ec46.js +1 -0
  57. package/dist/client/_nuxt/runtime-configs.b20fbeb6.js +1 -0
  58. package/dist/client/_nuxt/server-routes.7352d340.js +1 -0
  59. package/dist/client/_nuxt/settings.b6d3cae9.js +1 -0
  60. package/dist/client/_nuxt/storage.2e73159a.js +1 -0
  61. package/dist/client/_nuxt/terminals.4329aeb9.css +1 -0
  62. package/dist/client/_nuxt/terminals.65080a19.js +1 -0
  63. package/dist/client/_nuxt/{unocss-runtime.daeb320e.js → unocss-runtime.5708ce83.js} +2 -2
  64. package/dist/client/_nuxt/virtual-files.9eb05502.js +1 -0
  65. package/dist/client/index.html +2 -2
  66. package/dist/client/modules/assets/index.html +7 -0
  67. package/dist/client/modules/components/index.html +2 -2
  68. package/dist/client/modules/hooks/index.html +2 -2
  69. package/dist/client/modules/imports/index.html +2 -2
  70. package/dist/client/modules/layouts/index.html +2 -2
  71. package/dist/client/modules/middleware/index.html +2 -2
  72. package/dist/client/modules/modules/index.html +2 -2
  73. package/dist/client/modules/overview/index.html +2 -2
  74. package/dist/client/modules/pages/index.html +2 -2
  75. package/dist/client/modules/payload/index.html +2 -2
  76. package/dist/client/modules/plugins/index.html +2 -2
  77. package/dist/client/modules/runtime-configs/index.html +2 -2
  78. package/dist/client/modules/server-routes/index.html +2 -2
  79. package/dist/client/modules/storage/index.html +2 -2
  80. package/dist/client/modules/terminals/index.html +7 -0
  81. package/dist/client/modules/virtual-files/index.html +2 -2
  82. package/dist/client/settings/index.html +7 -0
  83. package/dist/dirs.mjs +2 -2
  84. package/dist/module.d.ts +3 -33
  85. package/dist/module.json +1 -1
  86. package/dist/module.mjs +2 -2
  87. package/dist/runtime/plugins/devtools.client.mjs +7 -1
  88. package/dist/shared/{devtools.258c6e2e.mjs → devtools.696fb428.mjs} +1 -1
  89. package/dist/types.d.ts +4 -337
  90. package/dist/types.mjs +1 -1
  91. package/package.json +36 -35
  92. package/dist/client/_nuxt/Badge.4f16da14.js +0 -1
  93. package/dist/client/_nuxt/FilepathItem.vue.235fa07d.js +0 -1
  94. package/dist/client/_nuxt/LaunchPage.vue.86f00e85.js +0 -1
  95. package/dist/client/_nuxt/NButton.a7fda268.css +0 -1
  96. package/dist/client/_nuxt/NButton.vue.76dccbb9.js +0 -100
  97. package/dist/client/_nuxt/NCheckbox.vue.60126ccb.js +0 -1
  98. package/dist/client/_nuxt/NMarkdown.vue.abb154b8.js +0 -1
  99. package/dist/client/_nuxt/NSectionBlock.58837776.js +0 -1
  100. package/dist/client/_nuxt/NSectionBlock.891fa081.css +0 -1
  101. package/dist/client/_nuxt/NTextInput.vue.1fd15b74.js +0 -1
  102. package/dist/client/_nuxt/StateEditor.vue.bdb7e5c8.js +0 -1
  103. package/dist/client/_nuxt/asyncData.103aad72.js +0 -1
  104. package/dist/client/_nuxt/client.9c41f495.js +0 -1
  105. package/dist/client/_nuxt/components.43dee80b.js +0 -1
  106. package/dist/client/_nuxt/context.55688cca.js +0 -1
  107. package/dist/client/_nuxt/custom-_name_.8832be9d.js +0 -1
  108. package/dist/client/_nuxt/default.c29c3e74.js +0 -1
  109. package/dist/client/_nuxt/editor.66e59505.js +0 -1
  110. package/dist/client/_nuxt/entry.3a404c59.css +0 -1
  111. package/dist/client/_nuxt/entry.883bcfe6.js +0 -11
  112. package/dist/client/_nuxt/error-404.d027ece6.js +0 -1
  113. package/dist/client/_nuxt/error-component.ee11a8ba.js +0 -3
  114. package/dist/client/_nuxt/hooks.427abdcd.js +0 -1
  115. package/dist/client/_nuxt/icons.7b11eba5.js +0 -1
  116. package/dist/client/_nuxt/imports.2dc7174b.js +0 -1
  117. package/dist/client/_nuxt/index.0d6abd2a.js +0 -1
  118. package/dist/client/_nuxt/json-editor-vue.a65019ca.js +0 -137
  119. package/dist/client/_nuxt/layouts.4db8e1e6.js +0 -1
  120. package/dist/client/_nuxt/middleware.c4f2a57b.js +0 -1
  121. package/dist/client/_nuxt/modules.a2209d2d.js +0 -1
  122. package/dist/client/_nuxt/nuxt-link.a34a1045.js +0 -1
  123. package/dist/client/_nuxt/overview.5053fd45.js +0 -1
  124. package/dist/client/_nuxt/pages.9a1a9ac3.js +0 -1
  125. package/dist/client/_nuxt/payload.ed4c5688.js +0 -1
  126. package/dist/client/_nuxt/plugins.95c9e3e6.js +0 -1
  127. package/dist/client/_nuxt/runtime-configs.7ebddf6f.js +0 -1
  128. package/dist/client/_nuxt/server-routes.5337ffc6.js +0 -1
  129. package/dist/client/_nuxt/state.1f523208.js +0 -1
  130. package/dist/client/_nuxt/storage.4459d7bf.js +0 -1
  131. package/dist/client/_nuxt/virtual-files.a15894d9.js +0 -3
  132. package/dist/iframe-client.d.ts +0 -15
  133. package/dist/iframe-client.mjs +0 -32
  134. package/iframe-client.d.ts +0 -1
@@ -1,26 +1,35 @@
1
- import { resolve, join, normalize } from 'path';
2
- import * as fs from 'fs';
3
- import fs__default, { readdirSync, statSync, existsSync } from 'fs';
4
- import { logger, getNuxtVersion, addPlugin } from '@nuxt/kit';
5
- import require$$0$2 from 'stream';
6
- import require$$0 from 'zlib';
7
- import require$$0$1 from 'buffer';
1
+ import { join as join$3 } from 'node:path';
2
+ import fs, { existsSync } from 'node:fs';
3
+ import { useNuxt, logger, addPlugin } from '@nuxt/kit';
4
+ import require$$0$3 from 'stream';
5
+ import require$$0$1 from 'zlib';
6
+ import require$$0$2 from 'buffer';
8
7
  import require$$3 from 'net';
9
8
  import require$$4 from 'tls';
10
9
  import require$$5 from 'crypto';
11
- import require$$0$3 from 'events';
10
+ import require$$0$4 from 'events';
12
11
  import require$$2 from 'https';
13
12
  import require$$1 from 'http';
14
- import require$$0$4 from 'url';
13
+ import require$$0$5 from 'url';
15
14
  import { searchForWorkspaceRoot } from 'vite';
15
+ import * as require$$0 from 'fs';
16
+ import { readdirSync, statSync } from 'fs';
17
+ import { resolve, join as join$1, normalize as normalize$1 } from 'path';
16
18
  import * as qs from 'querystring';
17
- import require$$0$5 from 'tty';
18
- import { v as version } from '../shared/devtools.258c6e2e.mjs';
19
+ import require$$0$6 from 'tty';
20
+ import { v as version } from '../shared/devtools.696fb428.mjs';
19
21
  import { createBirpcGroup } from 'birpc';
20
- import { resolvePreset } from 'unimport';
21
- import { join as join$1, dirname, resolve as resolve$1 } from 'pathe';
22
- import fsp from 'fs/promises';
22
+ import fsp, { readFile } from 'node:fs/promises';
23
+ import { resolve as resolve$1, join as join$2, dirname } from 'pathe';
24
+ import { imageMeta } from 'image-meta';
25
+ import fg from 'fast-glob';
26
+ import { startSubprocess } from '@nuxt/devtools-kit';
27
+ import isInstalledGlobally from 'is-installed-globally';
28
+ import 'node:child_process';
29
+ import { createRequire } from 'node:module';
23
30
  import 'pkg-types';
31
+ import { getPackageInfo } from 'local-pkg';
32
+ import { resolvePreset } from 'unimport';
24
33
  import { runtimeDir, clientDir, packageDir, isGlobalInstall } from '../dirs.mjs';
25
34
  import { R as ROUTE_ENTRY, a as ROUTE_CLIENT } from '../shared/devtools.95cf6023.mjs';
26
35
 
@@ -237,7 +246,7 @@ let Limiter$1 = class Limiter {
237
246
 
238
247
  var limiter = Limiter$1;
239
248
 
240
- const zlib = require$$0;
249
+ const zlib = require$$0$1;
241
250
 
242
251
  const bufferUtil = bufferUtilExports;
243
252
  const Limiter = limiter;
@@ -758,7 +767,7 @@ var validation = {
758
767
 
759
768
  var isValidUTF8_1;
760
769
 
761
- const { isUtf8 } = require$$0$1;
770
+ const { isUtf8 } = require$$0$2;
762
771
 
763
772
  //
764
773
  // Allowed token characters:
@@ -887,7 +896,7 @@ if (isUtf8) {
887
896
  }
888
897
  }
889
898
 
890
- const { Writable } = require$$0$2;
899
+ const { Writable } = require$$0$3;
891
900
 
892
901
  const PerMessageDeflate$3 = permessageDeflate;
893
902
  const {
@@ -2482,13 +2491,13 @@ var extension$1 = { format: format$1, parse: parse$b };
2482
2491
 
2483
2492
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Readable$" }] */
2484
2493
 
2485
- const EventEmitter$1 = require$$0$3;
2494
+ const EventEmitter$1 = require$$0$4;
2486
2495
  const https = require$$2;
2487
2496
  const http$1 = require$$1;
2488
2497
  const net = require$$3;
2489
2498
  const tls = require$$4;
2490
2499
  const { randomBytes, createHash: createHash$1 } = require$$5;
2491
- const { URL } = require$$0$4;
2500
+ const { URL } = require$$0$5;
2492
2501
 
2493
2502
  const PerMessageDeflate$1 = permessageDeflate;
2494
2503
  const Receiver = receiver;
@@ -3468,7 +3477,11 @@ function initAsClient(websocket, address, protocols, options) {
3468
3477
  });
3469
3478
  });
3470
3479
 
3471
- req.end();
3480
+ if (opts.finishRequest) {
3481
+ opts.finishRequest(req, websocket);
3482
+ } else {
3483
+ req.end();
3484
+ }
3472
3485
  }
3473
3486
 
3474
3487
  /**
@@ -3848,7 +3861,7 @@ var subprotocol$1 = { parse: parse$9 };
3848
3861
 
3849
3862
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls|https$" }] */
3850
3863
 
3851
- const EventEmitter = require$$0$3;
3864
+ const EventEmitter = require$$0$4;
3852
3865
  const http = require$$1;
3853
3866
  const { createHash } = require$$5;
3854
3867
 
@@ -4384,11 +4397,11 @@ function totalist(dir, callback, pre='') {
4384
4397
  let arr = readdirSync(dir);
4385
4398
  let i=0, abs, stats;
4386
4399
  for (; i < arr.length; i++) {
4387
- abs = join(dir, arr[i]);
4400
+ abs = join$1(dir, arr[i]);
4388
4401
  stats = statSync(abs);
4389
4402
  stats.isDirectory()
4390
- ? totalist(abs, callback, join(pre, arr[i]))
4391
- : callback(join(pre, arr[i]), abs, stats);
4403
+ ? totalist(abs, callback, join$1(pre, arr[i]))
4404
+ : callback(join$1(pre, arr[i]), abs, stats);
4392
4405
  }
4393
4406
  }
4394
4407
 
@@ -4881,9 +4894,9 @@ function viaLocal(dir, isEtag, uri, extns) {
4881
4894
  let i=0, arr=toAssume(uri, extns);
4882
4895
  let abs, stats, name, headers;
4883
4896
  for (; i < arr.length; i++) {
4884
- abs = normalize(join(dir, name=arr[i]));
4885
- if (abs.startsWith(dir) && fs.existsSync(abs)) {
4886
- stats = fs.statSync(abs);
4897
+ abs = normalize$1(join$1(dir, name=arr[i]));
4898
+ if (abs.startsWith(dir) && require$$0.existsSync(abs)) {
4899
+ stats = require$$0.statSync(abs);
4887
4900
  if (stats.isDirectory()) continue;
4888
4901
  headers = toHeaders(name, stats, isEtag);
4889
4902
  headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
@@ -4927,7 +4940,7 @@ function send(req, res, file, stats, headers) {
4927
4940
  }
4928
4941
 
4929
4942
  res.writeHead(code, headers);
4930
- fs.createReadStream(file, opts).pipe(res);
4943
+ require$$0.createReadStream(file, opts).pipe(res);
4931
4944
  }
4932
4945
 
4933
4946
  const ENCODING = {
@@ -5037,7 +5050,7 @@ var picocolors = {
5037
5050
  set exports(v){ picocolorsExports = v; },
5038
5051
  };
5039
5052
 
5040
- let tty = require$$0$5;
5053
+ let tty = require$$0$6;
5041
5054
 
5042
5055
  let isColorSupported =
5043
5056
  !("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
@@ -5188,74 +5201,290 @@ const stringify = (value, replacer, space) => {
5188
5201
  }
5189
5202
  };
5190
5203
 
5191
- function setupHooksDebug(hooks) {
5192
- const serverHooks = {};
5193
- const now = typeof globalThis.performance === "undefined" ? () => Date.now() : () => performance.now();
5194
- hooks.beforeEach((event) => {
5195
- if (!serverHooks[event.name]) {
5196
- serverHooks[event.name] = {
5197
- name: event.name,
5198
- start: now(),
5199
- // @ts-expect-error private field
5200
- listeners: hooks._hooks[event.name]?.length || 0,
5201
- executions: []
5202
- };
5203
- } else {
5204
- const hook = serverHooks[event.name];
5205
- if (hook.duration != null)
5206
- hook.executions.push(hook.duration);
5207
- hook.start = now();
5208
- hook.end = void 0;
5209
- hook.duration = void 0;
5204
+ const IGNORE_STORAGE_MOUNTS = ["root", "build", "src", "cache"];
5205
+ const shouldIgnoreStorageKey = (key) => IGNORE_STORAGE_MOUNTS.includes(key.split(":")[0]);
5206
+ function setupStorageRPC({
5207
+ nuxt,
5208
+ rpc
5209
+ }) {
5210
+ const storageMounts = {};
5211
+ let storage;
5212
+ nuxt.hook("nitro:init", (nitro) => {
5213
+ storage = nitro.storage;
5214
+ nuxt.hook("ready", () => {
5215
+ storage.watch((event, key) => {
5216
+ if (shouldIgnoreStorageKey(key))
5217
+ return;
5218
+ rpc.broadcast.callHook.asEvent("storage:key:update", key, event);
5219
+ });
5220
+ });
5221
+ const mounts = {
5222
+ ...nitro.options.storage,
5223
+ ...nitro.options.devStorage
5224
+ };
5225
+ for (const name of Object.keys(mounts)) {
5226
+ if (shouldIgnoreStorageKey(name))
5227
+ continue;
5228
+ storageMounts[name] = mounts[name];
5210
5229
  }
5211
5230
  });
5212
- hooks.afterEach((event) => {
5213
- const hook = serverHooks[event.name];
5214
- if (!hook)
5215
- return;
5216
- hook.end = now();
5217
- hook.duration = hook.end - hook.start;
5218
- const listeners = hooks._hooks[event.name]?.length;
5219
- if (listeners != null)
5220
- hook.listeners = listeners;
5221
- });
5222
- return serverHooks;
5231
+ return {
5232
+ async getStorageMounts() {
5233
+ return storageMounts;
5234
+ },
5235
+ async getStorageKeys(base) {
5236
+ if (!storage)
5237
+ return [];
5238
+ try {
5239
+ const keys = await storage.getKeys(base);
5240
+ return keys.filter((key) => !shouldIgnoreStorageKey(key));
5241
+ } catch (err) {
5242
+ console.error(`Cloud not fetch storage keys for ${base}:`, err);
5243
+ return [];
5244
+ }
5245
+ },
5246
+ async getStorageItem(key) {
5247
+ if (!storage)
5248
+ return null;
5249
+ return await storage.getItem(key);
5250
+ },
5251
+ async setStorageItem(key, value) {
5252
+ if (!storage)
5253
+ return;
5254
+ return await storage.setItem(key, value);
5255
+ },
5256
+ async removeStorageItem(key) {
5257
+ if (!storage)
5258
+ return;
5259
+ return await storage.removeItem(key);
5260
+ }
5261
+ };
5223
5262
  }
5224
5263
 
5225
- const pagesIndexTemplate = `<script setup lang="ts">
5226
- const route = useRoute()
5227
- <\/script>
5264
+ function setupAssetsRPC({ nuxt }) {
5265
+ const _imageMetaCache = /* @__PURE__ */ new Map();
5266
+ return {
5267
+ async getStaticAssets() {
5268
+ const dir = resolve$1(nuxt.options.srcDir, nuxt.options.dir.public);
5269
+ const baseURL = nuxt.options.app.baseURL;
5270
+ const files = await fg(["**/*"], {
5271
+ cwd: dir,
5272
+ onlyFiles: true
5273
+ });
5274
+ function guessType(path) {
5275
+ if (/\.(png|jpe?g|gif|svg|webp|avif|ico|bmp|tiff?)$/i.test(path))
5276
+ return "image";
5277
+ if (/\.(mp4|webm|ogv|mov|avi|flv|wmv|mpg|mpeg|mkv|3gp|3g2|ts|mts|m2ts|vob|ogm|ogx|rm|rmvb|asf|amv|divx|m4v|svi|viv|f4v|f4p|f4a|f4b)$/i.test(path))
5278
+ return "video";
5279
+ if (/\.(mp3|wav|ogg|flac|aac|wma|alac|ape|ac3|dts|tta|opus|amr|aiff|au|mid|midi|ra|rm|wv|weba|dss|spx|vox|tak|dsf|dff|dsd|cda)$/i.test(path))
5280
+ return "audio";
5281
+ if (/\.(woff2?|eot|ttf|otf|ttc|pfa|pfb|pfm|afm)/i.test(path))
5282
+ return "font";
5283
+ if (/\.(json[5c]?|te?xt|[mc]?[jt]sx?|md[cx]?|markdown)/i.test(path))
5284
+ return "text";
5285
+ return "other";
5286
+ }
5287
+ return await Promise.all(files.map(async (path) => {
5288
+ const filePath = resolve$1(dir, path);
5289
+ const stat = await fsp.lstat(filePath);
5290
+ return {
5291
+ path,
5292
+ publicPath: join$2(baseURL, path),
5293
+ filePath,
5294
+ type: guessType(path),
5295
+ size: stat.size,
5296
+ mtime: stat.mtimeMs
5297
+ };
5298
+ }));
5299
+ },
5300
+ async getImageMeta(filepath) {
5301
+ if (_imageMetaCache.has(filepath))
5302
+ return _imageMetaCache.get(filepath);
5303
+ try {
5304
+ const meta = imageMeta(await fsp.readFile(filepath));
5305
+ _imageMetaCache.set(filepath, meta);
5306
+ return meta;
5307
+ } catch (e) {
5308
+ _imageMetaCache.set(filepath, void 0);
5309
+ console.error(e);
5310
+ return void 0;
5311
+ }
5312
+ },
5313
+ async getTextAssetContent(filepath, limit = 300) {
5314
+ try {
5315
+ const content = await fsp.readFile(filepath, "utf-8");
5316
+ return content.slice(0, limit);
5317
+ } catch (e) {
5318
+ console.error(e);
5319
+ return void 0;
5320
+ }
5321
+ }
5322
+ };
5323
+ }
5228
5324
 
5229
- <template>
5230
- <div>
5231
- <h1>Nuxt Routing set up successfully!</h1>
5232
- <p>Current route: {{ route.path }}</p>
5233
- <a href="https://nuxt.com/docs/getting-started/routing" target="_blank">Learn more about Nuxt Routing</a>
5234
- </div>
5235
- </template>
5236
- `;
5237
- async function enablePages(nuxt) {
5238
- const pathApp = join$1(nuxt.options.srcDir, "app.vue");
5239
- const pathPageIndex = join$1(nuxt.options.srcDir, "pages/index.vue");
5240
- if (fs__default.existsSync(pathPageIndex)) {
5241
- logger.warn("pages/index.vue already exists, skipping");
5242
- return;
5243
- }
5244
- let appContent = fs__default.existsSync(pathApp) ? await fsp.readFile(pathApp, "utf-8") : void 0;
5245
- await fsp.mkdir(dirname(pathPageIndex), { recursive: true });
5246
- await fsp.writeFile(pathPageIndex, pagesIndexTemplate, "utf-8");
5247
- if (appContent && !appContent.includes("<NuxtPage")) {
5248
- appContent = appContent.replace("</template>", " <NuxtPage />\n</template>").replace(/<NuxtWelcome\s*\/>/, "");
5249
- await fsp.writeFile(pathApp, appContent, "utf-8");
5325
+ function normalizeWindowsPath(input = "") {
5326
+ if (!input || !input.includes("\\")) {
5327
+ return input;
5250
5328
  }
5251
- logger.success("Routing creation wizard completed");
5329
+ return input.replace(/\\/g, "/");
5252
5330
  }
5253
5331
 
5254
- const wizard = {
5255
- enablePages
5332
+ const _UNC_REGEX = /^[/\\]{2}/;
5333
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
5334
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
5335
+ const normalize = function(path) {
5336
+ if (path.length === 0) {
5337
+ return ".";
5338
+ }
5339
+ path = normalizeWindowsPath(path);
5340
+ const isUNCPath = path.match(_UNC_REGEX);
5341
+ const isPathAbsolute = isAbsolute(path);
5342
+ const trailingSeparator = path[path.length - 1] === "/";
5343
+ path = normalizeString(path, !isPathAbsolute);
5344
+ if (path.length === 0) {
5345
+ if (isPathAbsolute) {
5346
+ return "/";
5347
+ }
5348
+ return trailingSeparator ? "./" : ".";
5349
+ }
5350
+ if (trailingSeparator) {
5351
+ path += "/";
5352
+ }
5353
+ if (_DRIVE_LETTER_RE.test(path)) {
5354
+ path += "/";
5355
+ }
5356
+ if (isUNCPath) {
5357
+ if (!isPathAbsolute) {
5358
+ return `//./${path}`;
5359
+ }
5360
+ return `//${path}`;
5361
+ }
5362
+ return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
5363
+ };
5364
+ const join = function(...arguments_) {
5365
+ if (arguments_.length === 0) {
5366
+ return ".";
5367
+ }
5368
+ let joined;
5369
+ for (const argument of arguments_) {
5370
+ if (argument && argument.length > 0) {
5371
+ if (joined === void 0) {
5372
+ joined = argument;
5373
+ } else {
5374
+ joined += `/${argument}`;
5375
+ }
5376
+ }
5377
+ }
5378
+ if (joined === void 0) {
5379
+ return ".";
5380
+ }
5381
+ return normalize(joined.replace(/\/\/+/g, "/"));
5382
+ };
5383
+ function normalizeString(path, allowAboveRoot) {
5384
+ let res = "";
5385
+ let lastSegmentLength = 0;
5386
+ let lastSlash = -1;
5387
+ let dots = 0;
5388
+ let char = null;
5389
+ for (let index = 0; index <= path.length; ++index) {
5390
+ if (index < path.length) {
5391
+ char = path[index];
5392
+ } else if (char === "/") {
5393
+ break;
5394
+ } else {
5395
+ char = "/";
5396
+ }
5397
+ if (char === "/") {
5398
+ if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
5399
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
5400
+ if (res.length > 2) {
5401
+ const lastSlashIndex = res.lastIndexOf("/");
5402
+ if (lastSlashIndex === -1) {
5403
+ res = "";
5404
+ lastSegmentLength = 0;
5405
+ } else {
5406
+ res = res.slice(0, lastSlashIndex);
5407
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
5408
+ }
5409
+ lastSlash = index;
5410
+ dots = 0;
5411
+ continue;
5412
+ } else if (res.length > 0) {
5413
+ res = "";
5414
+ lastSegmentLength = 0;
5415
+ lastSlash = index;
5416
+ dots = 0;
5417
+ continue;
5418
+ }
5419
+ }
5420
+ if (allowAboveRoot) {
5421
+ res += res.length > 0 ? "/.." : "..";
5422
+ lastSegmentLength = 2;
5423
+ }
5424
+ } else {
5425
+ if (res.length > 0) {
5426
+ res += `/${path.slice(lastSlash + 1, index)}`;
5427
+ } else {
5428
+ res = path.slice(lastSlash + 1, index);
5429
+ }
5430
+ lastSegmentLength = index - lastSlash - 1;
5431
+ }
5432
+ lastSlash = index;
5433
+ dots = 0;
5434
+ } else if (char === "." && dots !== -1) {
5435
+ ++dots;
5436
+ } else {
5437
+ dots = -1;
5438
+ }
5439
+ }
5440
+ return res;
5441
+ }
5442
+ const isAbsolute = function(p) {
5443
+ return _IS_ABSOLUTE_RE.test(p);
5256
5444
  };
5257
5445
 
5258
- const LOG_PREFIX = picocolorsExports.cyan("Nuxt DevTools:");
5446
+ const packageManagerLocks = {
5447
+ "yarn.lock": "yarn",
5448
+ "package-lock.json": "npm",
5449
+ "pnpm-lock.yaml": "pnpm"
5450
+ };
5451
+ async function detectPackageManager(cwd, options = {}) {
5452
+ const detected = await findup(cwd, async (path) => {
5453
+ if (!options.ignorePackageJSON) {
5454
+ const packageJSONPath = join(path, "package.json");
5455
+ if (existsSync(packageJSONPath)) {
5456
+ const packageJSON = JSON.parse(await readFile(packageJSONPath, "utf8"));
5457
+ if (packageJSON?.packageManager) {
5458
+ const [name, version] = packageJSON.packageManager.split("@");
5459
+ return { name, version };
5460
+ }
5461
+ }
5462
+ }
5463
+ if (!options.ignoreLockFile) {
5464
+ for (const lockFile in packageManagerLocks) {
5465
+ if (existsSync(join(path, lockFile))) {
5466
+ return { name: packageManagerLocks[lockFile] };
5467
+ }
5468
+ }
5469
+ }
5470
+ });
5471
+ return {
5472
+ name: "npm",
5473
+ version: "latest",
5474
+ ...detected
5475
+ };
5476
+ }
5477
+ async function findup(cwd, match) {
5478
+ const segments = normalize(cwd).split("/");
5479
+ while (segments.length > 0) {
5480
+ const path = segments.join("/");
5481
+ const result = await match(path);
5482
+ if (result) {
5483
+ return result;
5484
+ }
5485
+ segments.pop();
5486
+ }
5487
+ }
5259
5488
 
5260
5489
  var reExports = {};
5261
5490
  var re$3 = {
@@ -8164,165 +8393,98 @@ var semver = {
8164
8393
  rcompareIdentifiers: identifiers.rcompareIdentifiers,
8165
8394
  };
8166
8395
 
8167
- async function checkForUpdateOf(info) {
8396
+ async function checkForUpdateOf(name, current, nuxt = useNuxt()) {
8397
+ if (!current) {
8398
+ const require = createRequire(nuxt.options.rootDir);
8399
+ const info = await getPackageInfo(name, { paths: require.resolve.paths(name) || void 0 });
8400
+ if (!info)
8401
+ return;
8402
+ current = info.packageJson.version;
8403
+ }
8168
8404
  const packument = await import('pacote').then((r) => r.default?.packument || r.packument);
8169
- const manifest = await packument(info.name);
8405
+ const manifest = await packument(name);
8170
8406
  const latest = manifest["dist-tags"].latest;
8171
- const needsUpdate = latest !== info.current && semver.lt(info.current, latest);
8407
+ const needsUpdate = latest !== current && semver.lt(current, latest);
8172
8408
  return {
8173
- ...info,
8409
+ name,
8410
+ current,
8174
8411
  latest,
8175
8412
  needsUpdate
8176
8413
  };
8177
8414
  }
8178
- function usePackageVersions() {
8179
- return [
8180
- { name: "nuxt", current: getNuxtVersion() },
8181
- { name: "@nuxt/devtools-edge", current: version }
8182
- ];
8183
- }
8184
- async function checkForUpdates() {
8185
- const versions = usePackageVersions();
8186
- const updates = await Promise.all(versions.map(checkForUpdateOf));
8187
- return updates;
8415
+
8416
+ function setupNpmRPC({ nuxt }) {
8417
+ let detectPromise;
8418
+ const updatesPromise = /* @__PURE__ */ new Map();
8419
+ function getPackageManager() {
8420
+ detectPromise || (detectPromise = detectPackageManager(nuxt.options.rootDir).then((r) => r.name));
8421
+ return detectPromise;
8422
+ }
8423
+ async function getNpmCommand(command, packageName, options = {}) {
8424
+ const {
8425
+ dev = true,
8426
+ global = packageName === "@nuxt/devtools" && isInstalledGlobally
8427
+ } = options;
8428
+ const agent = await getPackageManager();
8429
+ if (command === "install" || command === "update")
8430
+ return [agent, agent === "npm" ? "install" : "add", `${packageName}@latest`, dev ? "-D" : "", global ? "-g" : "", "--ignore-scripts"].filter(Boolean);
8431
+ }
8432
+ async function runNpmCommand(command, packageName, options = {}) {
8433
+ const args = await getNpmCommand(command, packageName, options);
8434
+ if (!args)
8435
+ return;
8436
+ const processId = `npm:${command}:${packageName}`;
8437
+ startSubprocess({
8438
+ command: args[0],
8439
+ args: args.slice(1)
8440
+ }, {
8441
+ id: processId,
8442
+ name: `${command} ${packageName}`,
8443
+ icon: "i-mdi-npm-variant-outline text-rose",
8444
+ restartable: false
8445
+ });
8446
+ return {
8447
+ processId
8448
+ };
8449
+ }
8450
+ return {
8451
+ checkForUpdateFor(name) {
8452
+ if (!updatesPromise.has(name))
8453
+ updatesPromise.set(name, checkForUpdateOf(name, void 0, nuxt));
8454
+ return updatesPromise.get(name);
8455
+ },
8456
+ getPackageManager,
8457
+ getNpmCommand,
8458
+ runNpmCommand
8459
+ };
8188
8460
  }
8189
8461
 
8190
- const IGNORE_STORAGE_MOUNTS = ["root", "build", "src", "cache"];
8191
- const shouldIgnoreStorageKey = (key) => IGNORE_STORAGE_MOUNTS.includes(key.split(":")[0]);
8192
- function setupRPC(nuxt, _options) {
8193
- const components = [];
8194
- const imports = [];
8195
- const importPresets = [];
8196
- const serverPages = [];
8462
+ function setupCustomTabRPC({ nuxt, options, refresh }) {
8197
8463
  const iframeTabs = [];
8198
8464
  const customTabs = [];
8199
- const serverHooks = setupHooksDebug(nuxt.hooks);
8200
- let storage;
8201
- const storageMounts = {};
8202
- let unimport;
8203
- let app;
8204
- let checkForUpdatePromise;
8205
- let versions = usePackageVersions();
8206
- const serverFunctions = {};
8207
- const clients = /* @__PURE__ */ new Set();
8208
- const birpc = createBirpcGroup(serverFunctions, []);
8209
- function refresh(event) {
8210
- birpc.broadcast.refresh.asEvent(event);
8465
+ if (options.customTabs?.length)
8466
+ customTabs.push(...options.customTabs);
8467
+ async function initHooks() {
8468
+ nuxt.hook("devtools:customTabs:refresh", initCustomTabs);
8469
+ await initCustomTabs();
8211
8470
  }
8212
- nuxt.hook("nitro:init", (nitro) => {
8213
- storage = nitro.storage;
8214
- nuxt.hook("ready", () => {
8215
- storage.watch((event, key) => {
8216
- if (shouldIgnoreStorageKey(key))
8217
- return;
8218
- birpc.broadcast.callHook.asEvent("storage:key:update", key, event);
8219
- });
8220
- });
8221
- const mounts = {
8222
- ...nitro.options.storage,
8223
- ...nitro.options.devStorage
8224
- };
8225
- for (const name of Object.keys(mounts)) {
8226
- if (shouldIgnoreStorageKey(name))
8227
- continue;
8228
- storageMounts[name] = mounts[name];
8229
- }
8471
+ async function initCustomTabs() {
8472
+ customTabs.length = 0;
8473
+ if (options.customTabs?.length)
8474
+ customTabs.push(...options.customTabs);
8475
+ await nuxt.callHook("devtools:customTabs", customTabs);
8476
+ refresh("getCustomTabs");
8477
+ }
8478
+ nuxt.hook("app:resolve", async () => {
8479
+ await initHooks();
8230
8480
  });
8231
- Object.assign(serverFunctions, {
8232
- async getStorageMounts() {
8233
- return storageMounts;
8234
- },
8235
- async getStorageKeys(base) {
8236
- if (!storage)
8237
- return [];
8238
- try {
8239
- const keys = await storage.getKeys(base);
8240
- return keys.filter((key) => !shouldIgnoreStorageKey(key));
8241
- } catch (err) {
8242
- console.error(`Cloud not fetch storage keys for ${base}:`, err);
8243
- return [];
8244
- }
8245
- },
8246
- async getStorageItem(key) {
8247
- if (!storage)
8248
- return null;
8249
- return await storage.getItem(key);
8250
- },
8251
- async setStorageItem(key, value) {
8252
- if (!storage)
8253
- return;
8254
- return await storage.setItem(key, value);
8255
- },
8256
- async removeStorageItem(key) {
8257
- if (!storage)
8258
- return;
8259
- return await storage.removeItem(key);
8260
- },
8261
- getServerConfig() {
8262
- return nuxt.options;
8263
- },
8264
- getComponents() {
8265
- return components;
8266
- },
8267
- async getComponentsRelationships() {
8268
- return [];
8269
- },
8270
- getServerPages() {
8271
- return serverPages;
8272
- },
8273
- getAutoImports() {
8274
- return {
8275
- imports: [
8276
- ...imports,
8277
- ...importPresets
8278
- ],
8279
- metadata: unimport?.getMetadata()
8280
- };
8281
- },
8481
+ return {
8282
8482
  getCustomTabs() {
8283
8483
  return [
8284
8484
  ...iframeTabs,
8285
8485
  ...customTabs
8286
8486
  ];
8287
8487
  },
8288
- getServerLayouts() {
8289
- return Object.values(app?.layouts || []);
8290
- },
8291
- getServerHooks() {
8292
- return Object.values(serverHooks);
8293
- },
8294
- usePackageVersions() {
8295
- checkForUpdatePromise = checkForUpdatePromise || checkForUpdates().then((v) => {
8296
- versions = v;
8297
- refresh("usePackageVersions");
8298
- });
8299
- return versions;
8300
- },
8301
- runWizard(name, ...args) {
8302
- logger.info(LOG_PREFIX, `Running wizard ${picocolorsExports.green(name)}...`);
8303
- return wizard[name](nuxt, ...args);
8304
- },
8305
- async openInEditor(input) {
8306
- if (input.startsWith("./"))
8307
- input = resolve$1(process.cwd(), input);
8308
- const match = input.match(/^(.*?)([:\d]*)$/);
8309
- let suffix = "";
8310
- if (match) {
8311
- input = match[1];
8312
- suffix = match[2];
8313
- }
8314
- const file = [
8315
- input,
8316
- `${input}.js`,
8317
- `${input}.mjs`,
8318
- `${input}.ts`
8319
- ].find((i) => existsSync(i));
8320
- if (file) {
8321
- await import('launch-editor').then((r) => (r.default || r)(file + suffix));
8322
- } else {
8323
- console.error("File not found:", input);
8324
- }
8325
- },
8326
8488
  async customTabAction(name, actionIndex) {
8327
8489
  const tab = customTabs.find((i) => i.name === name);
8328
8490
  if (!tab)
@@ -8341,7 +8503,51 @@ function setupRPC(nuxt, _options) {
8341
8503
  nuxt.callHook("devtools:customTabs:refresh");
8342
8504
  return true;
8343
8505
  }
8506
+ };
8507
+ }
8508
+
8509
+ function setupHooksDebug(hooks) {
8510
+ const serverHooks = {};
8511
+ const now = typeof globalThis.performance === "undefined" ? () => Date.now() : () => performance.now();
8512
+ hooks.beforeEach((event) => {
8513
+ if (!serverHooks[event.name]) {
8514
+ serverHooks[event.name] = {
8515
+ name: event.name,
8516
+ start: now(),
8517
+ // @ts-expect-error private field
8518
+ listeners: hooks._hooks[event.name]?.length || 0,
8519
+ executions: []
8520
+ };
8521
+ } else {
8522
+ const hook = serverHooks[event.name];
8523
+ if (hook.duration != null)
8524
+ hook.executions.push(hook.duration);
8525
+ hook.start = now();
8526
+ hook.end = void 0;
8527
+ hook.duration = void 0;
8528
+ }
8529
+ });
8530
+ hooks.afterEach((event) => {
8531
+ const hook = serverHooks[event.name];
8532
+ if (!hook)
8533
+ return;
8534
+ hook.end = now();
8535
+ hook.duration = hook.end - hook.start;
8536
+ const listeners = hooks._hooks[event.name]?.length;
8537
+ if (listeners != null)
8538
+ hook.listeners = listeners;
8344
8539
  });
8540
+ return serverHooks;
8541
+ }
8542
+
8543
+ function setupGeneralRPC({ nuxt, refresh }) {
8544
+ const components = [];
8545
+ const imports = [];
8546
+ const importPresets = [];
8547
+ const serverPages = [];
8548
+ const serverHooks = setupHooksDebug(nuxt.hooks);
8549
+ let unimport;
8550
+ let app;
8345
8551
  nuxt.hook("components:extend", (v) => {
8346
8552
  components.length = 0;
8347
8553
  components.push(...v);
@@ -8363,7 +8569,7 @@ function setupRPC(nuxt, _options) {
8363
8569
  page.children?.forEach(searchChildren);
8364
8570
  }
8365
8571
  v.forEach(searchChildren);
8366
- serverPages.push(...Array.from(pagesSet).sort((a, b) => a.file.localeCompare(b.file)));
8572
+ serverPages.push(...Array.from(pagesSet).sort((a, b) => a.path.localeCompare(b.path)));
8367
8573
  refresh("getServerPages");
8368
8574
  });
8369
8575
  nuxt.hook("imports:sources", async (v) => {
@@ -8378,43 +8584,270 @@ function setupRPC(nuxt, _options) {
8378
8584
  nuxt.hook("app:resolve", (v) => {
8379
8585
  app = v;
8380
8586
  });
8381
- const middleware = async (req, _res) => {
8587
+ return {
8588
+ getServerConfig() {
8589
+ return nuxt.options;
8590
+ },
8591
+ getComponents() {
8592
+ return components;
8593
+ },
8594
+ async getComponentsRelationships() {
8595
+ return [];
8596
+ },
8597
+ getServerPages() {
8598
+ return serverPages;
8599
+ },
8600
+ getAutoImports() {
8601
+ return {
8602
+ imports: [
8603
+ ...imports,
8604
+ ...importPresets
8605
+ ],
8606
+ metadata: unimport?.getMetadata()
8607
+ };
8608
+ },
8609
+ getServerLayouts() {
8610
+ return Object.values(app?.layouts || []);
8611
+ },
8612
+ getServerHooks() {
8613
+ return Object.values(serverHooks);
8614
+ },
8615
+ async openInEditor(input) {
8616
+ if (input.startsWith("./"))
8617
+ input = resolve$1(process.cwd(), input);
8618
+ const match = input.match(/^(.*?)([:\d]*)$/);
8619
+ let suffix = "";
8620
+ if (match) {
8621
+ input = match[1];
8622
+ suffix = match[2];
8623
+ }
8624
+ const path = [
8625
+ input,
8626
+ `${input}.js`,
8627
+ `${input}.mjs`,
8628
+ `${input}.ts`
8629
+ ].find((i) => existsSync(i));
8630
+ if (path) {
8631
+ await import('launch-editor').then((r) => (r.default || r)(path + suffix));
8632
+ } else {
8633
+ console.error("File not found:", input);
8634
+ }
8635
+ },
8636
+ restartNuxt(hard = true) {
8637
+ logger.info("Restarting Nuxt...");
8638
+ return nuxt.callHook("restart", { hard });
8639
+ }
8640
+ };
8641
+ }
8642
+
8643
+ const pagesIndexTemplate = `<script setup lang="ts">
8644
+ const route = useRoute()
8645
+ <\/script>
8646
+
8647
+ <template>
8648
+ <div>
8649
+ <h1>Nuxt Routing set up successfully!</h1>
8650
+ <p>Current route: {{ route.path }}</p>
8651
+ <a href="https://nuxt.com/docs/getting-started/routing" target="_blank">Learn more about Nuxt Routing</a>
8652
+ </div>
8653
+ </template>
8654
+ `;
8655
+ async function enablePages(nuxt) {
8656
+ const pathApp = join$2(nuxt.options.srcDir, "app.vue");
8657
+ const pathPageIndex = join$2(nuxt.options.srcDir, "pages/index.vue");
8658
+ if (fs.existsSync(pathPageIndex)) {
8659
+ logger.warn("pages/index.vue already exists, skipping");
8660
+ return;
8661
+ }
8662
+ let appContent = fs.existsSync(pathApp) ? await fsp.readFile(pathApp, "utf-8") : void 0;
8663
+ await fsp.mkdir(dirname(pathPageIndex), { recursive: true });
8664
+ await fsp.writeFile(pathPageIndex, pagesIndexTemplate, "utf-8");
8665
+ if (appContent && !appContent.includes("<NuxtPage")) {
8666
+ appContent = appContent.replace("</template>", " <NuxtPage />\n</template>").replace(/<NuxtWelcome\s*\/>/, "");
8667
+ await fsp.writeFile(pathApp, appContent, "utf-8");
8668
+ }
8669
+ logger.success("Routing creation wizard completed");
8670
+ }
8671
+
8672
+ const wizard = {
8673
+ enablePages
8674
+ };
8675
+
8676
+ const LOG_PREFIX = picocolorsExports.cyan("Nuxt DevTools:");
8677
+
8678
+ function setupWizardRPC({ nuxt }) {
8679
+ return {
8680
+ runWizard(name, ...args) {
8681
+ logger.info(LOG_PREFIX, `Running wizard ${picocolorsExports.green(name)}...`);
8682
+ return wizard[name](nuxt, ...args);
8683
+ }
8684
+ };
8685
+ }
8686
+
8687
+ function setupTerminalRPC({ nuxt, rpc, refresh }) {
8688
+ const terminals = /* @__PURE__ */ new Map();
8689
+ nuxt.hook("devtools:terminal:register", (terminal) => {
8690
+ terminals.set(terminal.id, terminal);
8691
+ refresh("getTerminals");
8692
+ return terminal.id;
8693
+ });
8694
+ nuxt.hook("devtools:terminal:remove", ({ id }) => {
8695
+ if (!terminals.has(id))
8696
+ return false;
8697
+ terminals.delete(id);
8698
+ refresh("getTerminals");
8699
+ return true;
8700
+ });
8701
+ nuxt.hook("devtools:terminal:write", ({ id, data }) => {
8702
+ const terminal = terminals.get(id);
8703
+ if (!terminal)
8704
+ return false;
8705
+ terminal.buffer || (terminal.buffer = "");
8706
+ terminal.buffer += data;
8707
+ rpc.broadcast.onTerminalData.asEvent({ id, data });
8708
+ return true;
8709
+ });
8710
+ nuxt.hook("devtools:terminal:exit", ({ id, code }) => {
8711
+ const terminal = terminals.get(id);
8712
+ if (!terminal)
8713
+ return false;
8714
+ terminal.isTerminated = true;
8715
+ rpc.broadcast.onTerminalExit.asEvent({ id, code });
8716
+ refresh("getTerminals");
8717
+ return true;
8718
+ });
8719
+ function serializeTerminal(terminal, buffer = false) {
8720
+ if (!terminal)
8721
+ return;
8722
+ return {
8723
+ id: terminal.id,
8724
+ name: terminal.name,
8725
+ description: terminal.description,
8726
+ icon: terminal.icon,
8727
+ terminatable: terminal.terminatable ?? !!terminal.onActionTerminate,
8728
+ restartable: terminal.restartable ?? !!terminal.onActionRestart,
8729
+ isTerminated: terminal.isTerminated,
8730
+ buffer: buffer ? terminal.buffer : void 0
8731
+ };
8732
+ }
8733
+ return {
8734
+ getTerminals() {
8735
+ return Array.from(terminals.values()).map((i) => serializeTerminal(i));
8736
+ },
8737
+ getTerminalDetail(id) {
8738
+ return serializeTerminal(terminals.get(id), true);
8739
+ },
8740
+ async runTerminalAction(id, action) {
8741
+ const terminal = terminals.get(id);
8742
+ if (!terminal)
8743
+ return false;
8744
+ switch (action) {
8745
+ case "restart":
8746
+ if (!terminal.onActionRestart)
8747
+ return false;
8748
+ await terminal.onActionRestart();
8749
+ return true;
8750
+ case "terminate":
8751
+ if (!terminal.onActionTerminate)
8752
+ return false;
8753
+ await terminal.onActionTerminate();
8754
+ return true;
8755
+ case "remove":
8756
+ if (!terminal.isTerminated)
8757
+ terminal.onActionTerminate?.();
8758
+ terminals.delete(id);
8759
+ refresh("getTerminals");
8760
+ return true;
8761
+ case "clear":
8762
+ terminal.buffer = "";
8763
+ refresh("getTerminals");
8764
+ return true;
8765
+ }
8766
+ }
8767
+ };
8768
+ }
8769
+
8770
+ function setupRPC(nuxt, options) {
8771
+ const serverFunctions = {};
8772
+ const extendedRpcMap = /* @__PURE__ */ new Map();
8773
+ const rpc = createBirpcGroup(
8774
+ serverFunctions,
8775
+ [],
8776
+ {
8777
+ resolver: (name, fn) => {
8778
+ if (fn)
8779
+ return fn;
8780
+ if (!name.includes(":"))
8781
+ return;
8782
+ const [namespace, fnName] = name.split(":");
8783
+ return extendedRpcMap.get(namespace)?.[fnName];
8784
+ },
8785
+ onError(error, name) {
8786
+ console.error(`[nuxt-devtools] RPC error on executing "${name}":`, error);
8787
+ }
8788
+ }
8789
+ );
8790
+ function refresh(event) {
8791
+ rpc.broadcast.refresh.asEvent(event);
8792
+ }
8793
+ function extendServerRpc(namespace, functions) {
8794
+ extendedRpcMap.set(namespace, functions);
8795
+ return {
8796
+ broadcast: new Proxy({}, {
8797
+ get: (_, key) => {
8798
+ if (typeof key !== "string")
8799
+ return;
8800
+ return rpc.broadcast[`${namespace}:${key}`];
8801
+ }
8802
+ })
8803
+ };
8804
+ }
8805
+ const ctx = {
8806
+ nuxt,
8807
+ options,
8808
+ rpc,
8809
+ refresh,
8810
+ extendServerRpc
8811
+ };
8812
+ nuxt.devtools = ctx;
8813
+ Object.assign(serverFunctions, {
8814
+ ...setupGeneralRPC(ctx),
8815
+ ...setupCustomTabRPC(ctx),
8816
+ ...setupStorageRPC(ctx),
8817
+ ...setupAssetsRPC(ctx),
8818
+ ...setupNpmRPC(ctx),
8819
+ ...setupWizardRPC(ctx),
8820
+ ...setupTerminalRPC(ctx)
8821
+ });
8822
+ const wsClients = /* @__PURE__ */ new Set();
8823
+ const middleware = async (req, _res, next) => {
8382
8824
  if (req.ws) {
8383
8825
  const ws = await req.ws();
8384
- clients.add(ws);
8826
+ wsClients.add(ws);
8385
8827
  const channel = {
8386
8828
  post: (d) => ws.send(d),
8387
8829
  on: (fn) => ws.on("message", fn),
8388
8830
  serialize: stringify,
8389
8831
  deserialize: parse$7
8390
8832
  };
8391
- birpc.updateChannels((c2) => {
8392
- c2.push(channel);
8833
+ rpc.updateChannels((c) => {
8834
+ c.push(channel);
8393
8835
  });
8394
8836
  ws.on("close", () => {
8395
- clients.delete(ws);
8396
- birpc.updateChannels((c2) => {
8397
- const index = c2.indexOf(channel);
8837
+ wsClients.delete(ws);
8838
+ rpc.updateChannels((c) => {
8839
+ const index = c.indexOf(channel);
8398
8840
  if (index >= 0)
8399
- c2.splice(index, 1);
8841
+ c.splice(index, 1);
8400
8842
  });
8401
8843
  });
8844
+ } else {
8845
+ next();
8402
8846
  }
8403
8847
  };
8404
- async function initHooks() {
8405
- nuxt.hook("devtools:customTabs:refresh", initCustomTabs);
8406
- await initCustomTabs();
8407
- }
8408
- async function initCustomTabs() {
8409
- customTabs.length = 0;
8410
- await nuxt.callHook("devtools:customTabs", customTabs);
8411
- refresh("getCustomTabs");
8412
- }
8413
8848
  return {
8414
- serverFunctions,
8415
8849
  middleware,
8416
- initHooks,
8417
- birpc
8850
+ ...ctx
8418
8851
  };
8419
8852
  }
8420
8853
 
@@ -8430,14 +8863,13 @@ async function enableModule(options, nuxt) {
8430
8863
  await nuxt.callHook("devtools:before");
8431
8864
  nuxt.options.imports.collectMeta = true;
8432
8865
  addPlugin({
8433
- src: join(runtimeDir, "plugins/devtools.client"),
8866
+ src: join$3(runtimeDir, "plugins/devtools.client"),
8434
8867
  mode: "client"
8435
8868
  });
8436
8869
  const {
8437
8870
  middleware: rpcMiddleware,
8438
- initHooks,
8439
- serverFunctions
8440
- } = setupRPC(nuxt);
8871
+ ...ctx
8872
+ } = setupRPC(nuxt, options);
8441
8873
  const clientDirExists = existsSync(clientDir);
8442
8874
  nuxt.hook("vite:extendConfig", (config) => {
8443
8875
  var _a, _b;
@@ -8455,15 +8887,17 @@ async function enableModule(options, nuxt) {
8455
8887
  server.middlewares.use(ROUTE_CLIENT, sirv(clientDir, { single: true, dev: true }));
8456
8888
  });
8457
8889
  const integrations = [
8458
- options.viteInspect !== false ? import('./vite-inspect.mjs').then(({ setup }) => setup(nuxt, serverFunctions)) : null,
8459
- options.componentInspector !== false ? import('./vue-inspector.mjs').then(({ setup }) => setup(nuxt, serverFunctions)) : null,
8460
- options.vscode?.enabled ? import('./vscode.mjs').then(({ setup }) => setup(nuxt, serverFunctions, options.vscode || {})) : null
8890
+ import('./plugin-metrics.mjs').then(({ setup }) => setup(ctx)),
8891
+ options.viteInspect !== false ? import('./vite-inspect.mjs').then(({ setup }) => setup(ctx)) : null,
8892
+ options.componentInspector !== false ? import('./vue-inspector.mjs').then(({ setup }) => setup(ctx)) : null,
8893
+ options.vscode?.enabled ? import('./vscode.mjs').then(({ setup }) => setup(ctx)) : null
8461
8894
  ];
8462
8895
  await Promise.all(integrations);
8463
- nuxt.hook("app:resolve", async () => {
8464
- await initHooks();
8896
+ await nuxt.callHook("devtools:initialized", {
8897
+ version,
8898
+ packagePath: packageDir,
8899
+ isGlobalInstall: isGlobalInstall()
8465
8900
  });
8466
- await nuxt.callHook("devtools:initialized");
8467
8901
  logger.success(`Nuxt Devtools is enabled ${picocolorsExports.dim(`v${version}`)}${isGlobalInstall() ? picocolorsExports.dim("[global]") : ""} ${picocolorsExports.yellow("(experimental)")}`);
8468
8902
  }
8469
8903