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

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.
@@ -12,7 +12,14 @@ import { join } from 'node:path';
12
12
  import { performance } from 'node:perf_hooks';
13
13
  import { MessageChannel } from 'node:worker_threads';
14
14
  const require = createRequire(join(process.cwd(), 'node_modules', '_'));
15
- const { tracingChannels } = require('@adonisjs/application');
15
+ let tracingChannels = null;
16
+ try {
17
+ const adonisApp = require('@adonisjs/application');
18
+ tracingChannels = adonisApp.tracingChannels;
19
+ }
20
+ catch {
21
+ // @adonisjs/application not available - provider tracing will be disabled
22
+ }
16
23
  /**
17
24
  * Module timing data collected via ESM hooks
18
25
  */
@@ -53,31 +60,33 @@ function record(provider, phase, endTime) {
53
60
  starts.delete(`${provider}:${phase}`);
54
61
  }
55
62
  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
- });
63
+ if (tracingChannels) {
64
+ for (const phase of phases) {
65
+ const channelKey = `provider${phase[0].toUpperCase()}${phase.slice(1)}`;
66
+ tracingChannels[channelKey].subscribe({
67
+ start(msg) {
68
+ starts.set(`${name(msg)}:${phase}`, performance.now());
69
+ },
70
+ end(msg) {
71
+ const provider = name(msg);
72
+ const endTime = performance.now();
73
+ const key = `${provider}:${phase}`;
74
+ setTimeout(() => {
75
+ if (!asyncPhases.has(key))
76
+ record(provider, phase, endTime);
77
+ }, 0);
78
+ },
79
+ asyncStart(msg) {
80
+ asyncPhases.add(`${name(msg)}:${phase}`);
81
+ },
82
+ asyncEnd(msg) {
83
+ const provider = name(msg);
84
+ record(provider, phase, performance.now());
85
+ asyncPhases.delete(`${provider}:${phase}`);
86
+ },
87
+ error() { },
88
+ });
89
+ }
81
90
  }
82
91
  /**
83
92
  * 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.6",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
7
7
  },