nuxt-devtools-observatory 0.1.20 → 0.1.23
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/README.md +37 -6
- package/client/.env +1 -0
- package/client/.env.example +1 -0
- package/dist/module.d.mts +13 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +68 -28
- package/dist/runtime/composables/composable-registry.js +12 -2
- package/dist/runtime/composables/render-registry.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,18 +14,49 @@ Nuxt DevTools extension providing five missing observability features:
|
|
|
14
14
|
pnpm add nuxt-devtools-observatory
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
You can configure all observability features and limits from your consuming project's `nuxt.config.ts` or `.env` file. All options in `.env.example` are supported as either environment variables or as properties under the `observatory` key in your Nuxt config. Options set in `nuxt.config.ts` take precedence over `.env` values.
|
|
18
|
+
|
|
19
|
+
**Available options:**
|
|
20
|
+
|
|
21
|
+
- `instrumentServer` (boolean) — Instrument the server for SSR/Nitro fetch and composable tracking (set via `OBSERVATORY_INSTRUMENT_SERVER` or `VITE_OBSERVATORY_INSTRUMENT_SERVER`)
|
|
22
|
+
- `fetchDashboard` (boolean) — Enable useFetch dashboard
|
|
23
|
+
- `provideInjectGraph` (boolean) — Enable provide/inject graph
|
|
24
|
+
- `composableTracker` (boolean) — Enable composable tracker
|
|
25
|
+
- `renderHeatmap` (boolean) — Enable render heatmap
|
|
26
|
+
- `transitionTracker` (boolean) — Enable transition tracker
|
|
27
|
+
- `heatmapThresholdCount` (number) — Highlight components with N+ renders in heatmap
|
|
28
|
+
- `heatmapThresholdTime` (number) — Highlight components with render time above this (ms)
|
|
29
|
+
- `heatmapHideInternals` (boolean) — Hide node_modules and internal components in the render heatmap for a cleaner view
|
|
30
|
+
- `maxFetchEntries` (number) — Max fetch entries to keep in memory
|
|
31
|
+
- `maxPayloadBytes` (number) — Max payload size (bytes) per fetch entry
|
|
32
|
+
- `maxTransitions` (number) — Max transition entries to keep in memory
|
|
33
|
+
- `maxComposableHistory` (number) — Max composable history events per entry
|
|
34
|
+
- `maxComposableEntries` (number) — Max composable entries to keep in memory
|
|
35
|
+
- `maxRenderTimeline` (number) — Max render timeline events per entry
|
|
36
|
+
|
|
37
|
+
See `.env.example` for all environment variable names.
|
|
38
|
+
|
|
17
39
|
```ts
|
|
18
40
|
// nuxt.config.ts
|
|
19
41
|
export default defineNuxtConfig({
|
|
20
42
|
modules: ['nuxt-devtools-observatory'],
|
|
21
43
|
|
|
22
44
|
observatory: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
instrumentServer: true, // Instrument the server for SSR/Nitro fetch and composable tracking. Enable this when using SSR so server-side composable calls are captured. Disable for SPA projects to avoid double-registration caused by the transform running on both builds.
|
|
46
|
+
fetchDashboard: true, // Enable useFetch dashboard
|
|
47
|
+
provideInjectGraph: true, // Enable provide/inject graph
|
|
48
|
+
composableTracker: true, // Enable composable tracker
|
|
49
|
+
renderHeatmap: true, // Enable render heatmap
|
|
50
|
+
transitionTracker: true, // Enable transition tracker
|
|
51
|
+
heatmapThresholdCount: 5, // Highlight components with 5+ renders
|
|
52
|
+
heatmapThresholdTime: 1600, // Highlight components with render time above this (ms)
|
|
53
|
+
heatmapHideInternals: true, // Hide node_modules and internal components in the render heatmap
|
|
54
|
+
maxFetchEntries: 200, // Max fetch entries to keep in memory
|
|
55
|
+
maxPayloadBytes: 10000, // Max payload size (bytes) per fetch entry
|
|
56
|
+
maxTransitions: 500, // Max transition entries to keep in memory
|
|
57
|
+
maxComposableHistory: 50, // Max composable history events per entry
|
|
58
|
+
maxComposableEntries: 300, // Max composable entries to keep in memory
|
|
59
|
+
maxRenderTimeline: 100, // Max render timeline events per entry
|
|
29
60
|
},
|
|
30
61
|
|
|
31
62
|
devtools: { enabled: true },
|
package/client/.env
CHANGED
package/client/.env.example
CHANGED
package/dist/module.d.mts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
|
|
3
3
|
interface ModuleOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Instrument composables, provide/inject, fetch, and transitions on the
|
|
6
|
+
* server build as well as the client build. Enable this when using SSR so
|
|
7
|
+
* server-side composable calls are captured. Disable for SPA projects to
|
|
8
|
+
* avoid double-registration caused by the transform running on both builds.
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
instrumentServer?: boolean;
|
|
4
12
|
/**
|
|
5
13
|
* Maximum number of fetch entries to keep in memory
|
|
6
14
|
* @default 200
|
|
@@ -56,6 +64,11 @@ interface ModuleOptions {
|
|
|
56
64
|
* @default true
|
|
57
65
|
*/
|
|
58
66
|
transitionTracker?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Hide node_modules/internal components in the render heatmap
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
heatmapHideInternals?: boolean;
|
|
59
72
|
/**
|
|
60
73
|
* Minimum render count / ms threshold to highlight in the heatmap
|
|
61
74
|
* @default 3
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -285,21 +285,42 @@ const traverse = _traverse.default ?? _traverse;
|
|
|
285
285
|
const generate = _generate.default ?? _generate;
|
|
286
286
|
const COMPOSABLE_RE = /\buse[A-Z]/;
|
|
287
287
|
const SKIP_LIST = /* @__PURE__ */ new Set([
|
|
288
|
+
// useFetch family — tracked by the fetch dashboard
|
|
288
289
|
"useFetch",
|
|
289
290
|
"useAsyncData",
|
|
290
291
|
"useLazyFetch",
|
|
291
292
|
"useLazyAsyncData",
|
|
292
|
-
|
|
293
|
-
"
|
|
294
|
-
"
|
|
293
|
+
// Nuxt auto-imports
|
|
294
|
+
"useCookie",
|
|
295
|
+
"useRequestEvent",
|
|
296
|
+
"useRequestHeaders",
|
|
297
|
+
"useRequestURL",
|
|
298
|
+
"useResponseHeader",
|
|
295
299
|
"useNuxtApp",
|
|
296
300
|
"useRuntimeConfig",
|
|
301
|
+
"useRoute",
|
|
302
|
+
"useRouter",
|
|
303
|
+
"useNuxtData",
|
|
304
|
+
"useError",
|
|
305
|
+
"useState",
|
|
306
|
+
"useAppConfig",
|
|
307
|
+
// Nuxt head
|
|
297
308
|
"useHead",
|
|
298
309
|
"useSeoMeta",
|
|
299
310
|
"useServerSeoMeta",
|
|
300
|
-
"
|
|
301
|
-
|
|
302
|
-
"
|
|
311
|
+
"useHeadSafe",
|
|
312
|
+
// Nuxt i18n (common plugin)
|
|
313
|
+
"useI18n",
|
|
314
|
+
"useLocalePath",
|
|
315
|
+
"useLocaleRoute",
|
|
316
|
+
// Vue built-ins
|
|
317
|
+
"useSlots",
|
|
318
|
+
"useAttrs",
|
|
319
|
+
"useModel",
|
|
320
|
+
"useTemplateRef",
|
|
321
|
+
"useId",
|
|
322
|
+
"useCssModule",
|
|
323
|
+
"useCssVars"
|
|
303
324
|
]);
|
|
304
325
|
function composableTrackerPlugin() {
|
|
305
326
|
return {
|
|
@@ -345,6 +366,14 @@ function composableTrackerPlugin() {
|
|
|
345
366
|
if (SKIP_LIST.has(name)) {
|
|
346
367
|
return;
|
|
347
368
|
}
|
|
369
|
+
const binding = path.scope.getBinding(name);
|
|
370
|
+
if (binding?.path.isImportSpecifier() || binding?.path.isImportDefaultSpecifier()) {
|
|
371
|
+
const importDecl = binding.path.parentPath?.node;
|
|
372
|
+
const source = importDecl?.source?.value ?? "";
|
|
373
|
+
if (source && !source.startsWith(".") && !source.startsWith("/")) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
348
377
|
let parent = path.parentPath;
|
|
349
378
|
let isWrapped = false;
|
|
350
379
|
while (parent) {
|
|
@@ -514,27 +543,30 @@ function transitionTrackerPlugin() {
|
|
|
514
543
|
};
|
|
515
544
|
}
|
|
516
545
|
|
|
546
|
+
const defaults = {
|
|
547
|
+
instrumentServer: process.env.OBSERVATORY_INSTRUMENT_SERVER === "true",
|
|
548
|
+
fetchDashboard: process.env.OBSERVATORY_FETCH_DASHBOARD === "true",
|
|
549
|
+
provideInjectGraph: process.env.OBSERVATORY_PROVIDE_INJECT_GRAPH === "true",
|
|
550
|
+
composableTracker: process.env.OBSERVATORY_COMPOSABLE_TRACKER === "true",
|
|
551
|
+
renderHeatmap: process.env.OBSERVATORY_RENDER_HEATMAP === "true",
|
|
552
|
+
transitionTracker: process.env.OBSERVATORY_TRANSITION_TRACKER === "true",
|
|
553
|
+
heatmapThresholdCount: process.env.OBSERVATORY_HEATMAP_THRESHOLD_COUNT ? Number(process.env.OBSERVATORY_HEATMAP_THRESHOLD_COUNT) : 3,
|
|
554
|
+
heatmapThresholdTime: process.env.OBSERVATORY_HEATMAP_THRESHOLD_TIME ? Number(process.env.OBSERVATORY_HEATMAP_THRESHOLD_TIME) : 1600,
|
|
555
|
+
maxFetchEntries: process.env.OBSERVATORY_MAX_FETCH_ENTRIES ? Number(process.env.OBSERVATORY_MAX_FETCH_ENTRIES) : 200,
|
|
556
|
+
maxPayloadBytes: process.env.OBSERVATORY_MAX_PAYLOAD_BYTES ? Number(process.env.OBSERVATORY_MAX_PAYLOAD_BYTES) : 1e4,
|
|
557
|
+
maxTransitions: process.env.OBSERVATORY_MAX_TRANSITIONS ? Number(process.env.OBSERVATORY_MAX_TRANSITIONS) : 500,
|
|
558
|
+
maxComposableHistory: process.env.OBSERVATORY_MAX_COMPOSABLE_HISTORY ? Number(process.env.OBSERVATORY_MAX_COMPOSABLE_HISTORY) : 50,
|
|
559
|
+
maxComposableEntries: process.env.OBSERVATORY_MAX_COMPOSABLE_ENTRIES ? Number(process.env.OBSERVATORY_MAX_COMPOSABLE_ENTRIES) : 300,
|
|
560
|
+
maxRenderTimeline: process.env.OBSERVATORY_MAX_RENDER_TIMELINE ? Number(process.env.OBSERVATORY_MAX_RENDER_TIMELINE) : 100,
|
|
561
|
+
heatmapHideInternals: process.env.OBSERVATORY_HEATMAP_HIDE_INTERNALS === "true"
|
|
562
|
+
};
|
|
517
563
|
const module$1 = defineNuxtModule({
|
|
518
564
|
meta: {
|
|
519
565
|
name: "nuxt-devtools-observatory",
|
|
520
566
|
configKey: "observatory",
|
|
521
567
|
compatibility: { nuxt: "^3.0.0 || ^4.0.0" }
|
|
522
568
|
},
|
|
523
|
-
defaults
|
|
524
|
-
fetchDashboard: true,
|
|
525
|
-
provideInjectGraph: true,
|
|
526
|
-
composableTracker: true,
|
|
527
|
-
renderHeatmap: true,
|
|
528
|
-
transitionTracker: true,
|
|
529
|
-
heatmapThresholdCount: process.env.OBSERVATORY_HEATMAP_THRESHOLD_COUNT ? Number(process.env.OBSERVATORY_HEATMAP_THRESHOLD_COUNT) : 3,
|
|
530
|
-
heatmapThresholdTime: process.env.OBSERVATORY_HEATMAP_THRESHOLD_TIME ? Number(process.env.OBSERVATORY_HEATMAP_THRESHOLD_TIME) : 1600,
|
|
531
|
-
maxFetchEntries: process.env.OBSERVATORY_MAX_FETCH_ENTRIES ? Number(process.env.OBSERVATORY_MAX_FETCH_ENTRIES) : 200,
|
|
532
|
-
maxPayloadBytes: process.env.OBSERVATORY_MAX_PAYLOAD_BYTES ? Number(process.env.OBSERVATORY_MAX_PAYLOAD_BYTES) : 1e4,
|
|
533
|
-
maxTransitions: process.env.OBSERVATORY_MAX_TRANSITIONS ? Number(process.env.OBSERVATORY_MAX_TRANSITIONS) : 500,
|
|
534
|
-
maxComposableHistory: process.env.OBSERVATORY_MAX_COMPOSABLE_HISTORY ? Number(process.env.OBSERVATORY_MAX_COMPOSABLE_HISTORY) : 50,
|
|
535
|
-
maxComposableEntries: process.env.OBSERVATORY_MAX_COMPOSABLE_ENTRIES ? Number(process.env.OBSERVATORY_MAX_COMPOSABLE_ENTRIES) : 300,
|
|
536
|
-
maxRenderTimeline: process.env.OBSERVATORY_MAX_RENDER_TIMELINE ? Number(process.env.OBSERVATORY_MAX_RENDER_TIMELINE) : 100
|
|
537
|
-
},
|
|
569
|
+
defaults,
|
|
538
570
|
setup(options, nuxt) {
|
|
539
571
|
if (!nuxt.options.dev) {
|
|
540
572
|
return;
|
|
@@ -544,11 +576,16 @@ const module$1 = defineNuxtModule({
|
|
|
544
576
|
}
|
|
545
577
|
const resolver = createResolver(import.meta.url);
|
|
546
578
|
const resolved = {
|
|
579
|
+
...defaults,
|
|
580
|
+
...options,
|
|
581
|
+
// Allow runtime overrides via env
|
|
582
|
+
heatmapHideInternals: typeof process.env.OBSERVATORY_HEATMAP_HIDE_INTERNALS !== "undefined" ? process.env.OBSERVATORY_HEATMAP_HIDE_INTERNALS === "true" : typeof options.heatmapHideInternals !== "undefined" ? options.heatmapHideInternals : defaults.heatmapHideInternals,
|
|
547
583
|
fetchDashboard: options.fetchDashboard ?? (process.env.OBSERVATORY_FETCH_DASHBOARD ? process.env.OBSERVATORY_FETCH_DASHBOARD === "true" : true),
|
|
548
584
|
provideInjectGraph: options.provideInjectGraph ?? (process.env.OBSERVATORY_PROVIDE_INJECT_GRAPH ? process.env.OBSERVATORY_PROVIDE_INJECT_GRAPH === "true" : true),
|
|
549
585
|
composableTracker: options.composableTracker ?? (process.env.OBSERVATORY_COMPOSABLE_TRACKER ? process.env.OBSERVATORY_COMPOSABLE_TRACKER === "true" : true),
|
|
550
586
|
renderHeatmap: options.renderHeatmap ?? (process.env.OBSERVATORY_RENDER_HEATMAP ? process.env.OBSERVATORY_RENDER_HEATMAP === "true" : true),
|
|
551
587
|
transitionTracker: options.transitionTracker ?? (process.env.OBSERVATORY_TRANSITION_TRACKER ? process.env.OBSERVATORY_TRANSITION_TRACKER === "true" : true),
|
|
588
|
+
instrumentServer: options.instrumentServer ?? (process.env.OBSERVATORY_INSTRUMENT_SERVER ? process.env.OBSERVATORY_INSTRUMENT_SERVER === "true" : false),
|
|
552
589
|
heatmapThresholdCount: options.heatmapThresholdCount ?? (process.env.OBSERVATORY_HEATMAP_THRESHOLD_COUNT ? Number(process.env.OBSERVATORY_HEATMAP_THRESHOLD_COUNT) : 3),
|
|
553
590
|
heatmapThresholdTime: options.heatmapThresholdTime ?? (process.env.OBSERVATORY_HEATMAP_THRESHOLD_TIME ? Number(process.env.OBSERVATORY_HEATMAP_THRESHOLD_TIME) : 1600),
|
|
554
591
|
maxFetchEntries: options.maxFetchEntries ?? (process.env.OBSERVATORY_MAX_FETCH_ENTRIES ? Number(process.env.OBSERVATORY_MAX_FETCH_ENTRIES) : 200),
|
|
@@ -568,17 +605,18 @@ const module$1 = defineNuxtModule({
|
|
|
568
605
|
aliases["nuxt-devtools-observatory/runtime/fetch-registry"] = resolver.resolve("./runtime/composables/fetch-registry");
|
|
569
606
|
config.resolve = { ...config.resolve, alias: aliases };
|
|
570
607
|
});
|
|
608
|
+
const vitePluginScope = resolved.instrumentServer ? { server: true, client: true } : { server: false, client: true };
|
|
571
609
|
if (resolved.fetchDashboard) {
|
|
572
|
-
addVitePlugin(fetchInstrumentPlugin());
|
|
610
|
+
addVitePlugin(fetchInstrumentPlugin(), vitePluginScope);
|
|
573
611
|
}
|
|
574
612
|
if (resolved.provideInjectGraph) {
|
|
575
|
-
addVitePlugin(provideInjectPlugin());
|
|
613
|
+
addVitePlugin(provideInjectPlugin(), vitePluginScope);
|
|
576
614
|
}
|
|
577
615
|
if (resolved.composableTracker) {
|
|
578
|
-
addVitePlugin(composableTrackerPlugin());
|
|
616
|
+
addVitePlugin(composableTrackerPlugin(), vitePluginScope);
|
|
579
617
|
}
|
|
580
618
|
if (resolved.transitionTracker) {
|
|
581
|
-
addVitePlugin(transitionTrackerPlugin());
|
|
619
|
+
addVitePlugin(transitionTrackerPlugin(), vitePluginScope);
|
|
582
620
|
}
|
|
583
621
|
if (resolved.fetchDashboard || resolved.provideInjectGraph || resolved.composableTracker || resolved.renderHeatmap || resolved.transitionTracker) {
|
|
584
622
|
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
@@ -632,8 +670,7 @@ ${configScript}`);
|
|
|
632
670
|
}
|
|
633
671
|
});
|
|
634
672
|
nuxt.options.runtimeConfig.public.observatory = {
|
|
635
|
-
|
|
636
|
-
heatmapThresholdTime: resolved.heatmapThresholdTime,
|
|
673
|
+
instrumentServer: resolved.instrumentServer,
|
|
637
674
|
clientOrigin,
|
|
638
675
|
fetchDashboard: resolved.fetchDashboard,
|
|
639
676
|
provideInjectGraph: resolved.provideInjectGraph,
|
|
@@ -645,7 +682,10 @@ ${configScript}`);
|
|
|
645
682
|
maxTransitions: resolved.maxTransitions,
|
|
646
683
|
maxComposableHistory: resolved.maxComposableHistory,
|
|
647
684
|
maxComposableEntries: resolved.maxComposableEntries,
|
|
648
|
-
maxRenderTimeline: resolved.maxRenderTimeline
|
|
685
|
+
maxRenderTimeline: resolved.maxRenderTimeline,
|
|
686
|
+
heatmapHideInternals: resolved.heatmapHideInternals,
|
|
687
|
+
heatmapThresholdCount: resolved.heatmapThresholdCount,
|
|
688
|
+
heatmapThresholdTime: resolved.heatmapThresholdTime
|
|
649
689
|
};
|
|
650
690
|
}
|
|
651
691
|
});
|
|
@@ -298,7 +298,7 @@ export function __trackComposable(name, callFn, meta) {
|
|
|
298
298
|
return callFn();
|
|
299
299
|
}
|
|
300
300
|
const instance = getCurrentInstance();
|
|
301
|
-
const id = `${name}::${instance
|
|
301
|
+
const id = instance ? `${name}::${instance.uid}::${meta.file}:${meta.line}::${Date.now()}::${Math.random().toString(36).slice(2, 7)}` : `${name}::global::${meta.file}:${meta.line}`;
|
|
302
302
|
const trackedIntervals = [];
|
|
303
303
|
const clearedIntervals = /* @__PURE__ */ new Set();
|
|
304
304
|
const alreadyPatched = !!window.setInterval.__obs;
|
|
@@ -373,7 +373,17 @@ export function __trackComposable(name, callFn, meta) {
|
|
|
373
373
|
line: meta.line,
|
|
374
374
|
route: registry.getRoute()
|
|
375
375
|
};
|
|
376
|
-
registry.
|
|
376
|
+
if (!instance && registry.getAll().some((e) => e.id === id)) {
|
|
377
|
+
registry.update(id, {
|
|
378
|
+
status: "mounted",
|
|
379
|
+
refs,
|
|
380
|
+
watcherCount: trackedWatchers.length,
|
|
381
|
+
intervalCount: trackedIntervals.length,
|
|
382
|
+
route: registry.getRoute()
|
|
383
|
+
});
|
|
384
|
+
} else {
|
|
385
|
+
registry.register(entry);
|
|
386
|
+
}
|
|
377
387
|
if (instance) {
|
|
378
388
|
registry.registerLiveRefs(id, liveRefMap);
|
|
379
389
|
registry.registerRawRefs(id, rawRefMap);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#app";
|
|
1
2
|
export function setupRenderRegistry(nuxtApp, options = {}) {
|
|
2
3
|
const entries = /* @__PURE__ */ new Map();
|
|
3
4
|
const pendingTriggeredRenders = /* @__PURE__ */ new Set();
|
|
4
5
|
const renderStartTimes = /* @__PURE__ */ new Map();
|
|
5
6
|
let currentRoute = "/";
|
|
6
|
-
const
|
|
7
|
-
const MAX_TIMELINE =
|
|
8
|
-
const HIDE_INTERNALS =
|
|
7
|
+
const config = useRuntimeConfig().public.observatory;
|
|
8
|
+
const MAX_TIMELINE = config.maxRenderTimeline ?? 100;
|
|
9
|
+
const HIDE_INTERNALS = config.heatmapHideInternals ?? false;
|
|
9
10
|
let dirty = true;
|
|
10
11
|
let cachedSnapshot = "[]";
|
|
11
12
|
function markDirty() {
|