@densetsuuu/docteur 0.1.1-beta.5 → 0.1.1-beta.7

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.
@@ -11,8 +11,25 @@ import { createRequire, register } from 'node:module';
11
11
  import { join } from 'node:path';
12
12
  import { performance } from 'node:perf_hooks';
13
13
  import { MessageChannel } from 'node:worker_threads';
14
- const require = createRequire(join(process.cwd(), 'node_modules', '_'));
15
- const { tracingChannels } = require('@adonisjs/application');
14
+ const projectRequire = createRequire(join(process.cwd(), 'node_modules', '_'));
15
+ let tracingChannels = null;
16
+ try {
17
+ // Try direct require first (works when @adonisjs/application is a direct dependency)
18
+ const adonisApp = projectRequire('@adonisjs/application');
19
+ tracingChannels = adonisApp.tracingChannels;
20
+ }
21
+ catch {
22
+ // Try to resolve through @adonisjs/core (for pnpm strict mode)
23
+ try {
24
+ const corePath = projectRequire.resolve('@adonisjs/core');
25
+ const coreRequire = createRequire(corePath);
26
+ const adonisApp = coreRequire('@adonisjs/application');
27
+ tracingChannels = adonisApp.tracingChannels;
28
+ }
29
+ catch {
30
+ // @adonisjs/application not available - provider tracing will be disabled
31
+ }
32
+ }
16
33
  /**
17
34
  * Module timing data collected via ESM hooks
18
35
  */
@@ -53,31 +70,33 @@ function record(provider, phase, endTime) {
53
70
  starts.delete(`${provider}:${phase}`);
54
71
  }
55
72
  const phases = ['register', 'boot', 'start', 'ready', 'shutdown'];
56
- for (const phase of phases) {
57
- const channelKey = `provider${phase[0].toUpperCase()}${phase.slice(1)}`;
58
- tracingChannels[channelKey].subscribe({
59
- start(msg) {
60
- starts.set(`${name(msg)}:${phase}`, performance.now());
61
- },
62
- end(msg) {
63
- const provider = name(msg);
64
- const endTime = performance.now();
65
- const key = `${provider}:${phase}`;
66
- setTimeout(() => {
67
- if (!asyncPhases.has(key))
68
- record(provider, phase, endTime);
69
- }, 0);
70
- },
71
- asyncStart(msg) {
72
- asyncPhases.add(`${name(msg)}:${phase}`);
73
- },
74
- asyncEnd(msg) {
75
- const provider = name(msg);
76
- record(provider, phase, performance.now());
77
- asyncPhases.delete(`${provider}:${phase}`);
78
- },
79
- error() { },
80
- });
73
+ if (tracingChannels) {
74
+ for (const phase of phases) {
75
+ const channelKey = `provider${phase[0].toUpperCase()}${phase.slice(1)}`;
76
+ tracingChannels[channelKey].subscribe({
77
+ start(msg) {
78
+ starts.set(`${name(msg)}:${phase}`, performance.now());
79
+ },
80
+ end(msg) {
81
+ const provider = name(msg);
82
+ const endTime = performance.now();
83
+ const key = `${provider}:${phase}`;
84
+ setTimeout(() => {
85
+ if (!asyncPhases.has(key))
86
+ record(provider, phase, endTime);
87
+ }, 0);
88
+ },
89
+ asyncStart(msg) {
90
+ asyncPhases.add(`${name(msg)}:${phase}`);
91
+ },
92
+ asyncEnd(msg) {
93
+ const provider = name(msg);
94
+ record(provider, phase, performance.now());
95
+ asyncPhases.delete(`${provider}:${phase}`);
96
+ },
97
+ error() { },
98
+ });
99
+ }
81
100
  }
82
101
  /**
83
102
  * IPC: send collected results to parent process
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@densetsuuu/docteur",
3
3
  "description": "AdonisJS cold start profiler - analyze and optimize your application boot time",
4
- "version": "0.1.1-beta.5",
4
+ "version": "0.1.1-beta.7",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
7
7
  },