@oclif/core 3.0.0-beta.22 → 3.0.0-beta.24
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/lib/config/config.js +9 -9
- package/lib/config/plugin-loader.js +4 -4
- package/lib/config/plugin.js +4 -4
- package/lib/main.js +3 -3
- package/lib/performance.d.ts +21 -14
- package/lib/performance.js +78 -60
- package/package.json +3 -2
package/lib/config/config.js
CHANGED
|
@@ -5,12 +5,12 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const ejs = tslib_1.__importStar(require("ejs"));
|
|
6
6
|
const errors_1 = require("../errors");
|
|
7
7
|
const util_1 = require("./util");
|
|
8
|
+
const performance_1 = require("../performance");
|
|
8
9
|
const node_url_1 = require("node:url");
|
|
9
10
|
const node_os_1 = require("node:os");
|
|
10
11
|
const util_2 = require("../util/util");
|
|
11
12
|
const os_1 = require("../util/os");
|
|
12
13
|
const node_path_1 = require("node:path");
|
|
13
|
-
const performance_1 = require("../performance");
|
|
14
14
|
const plugin_loader_1 = tslib_1.__importDefault(require("./plugin-loader"));
|
|
15
15
|
const is_wsl_1 = tslib_1.__importDefault(require("is-wsl"));
|
|
16
16
|
const node_util_1 = require("node:util");
|
|
@@ -134,7 +134,7 @@ class Config {
|
|
|
134
134
|
async load() {
|
|
135
135
|
settings_1.settings.performanceEnabled =
|
|
136
136
|
(settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
|
|
137
|
-
const marker = performance_1.Performance.mark('config.load');
|
|
137
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.load');
|
|
138
138
|
this.pluginLoader = new plugin_loader_1.default({ root: this.options.root, plugins: this.options.plugins });
|
|
139
139
|
Config._rootPlugin = await this.pluginLoader.loadRoot();
|
|
140
140
|
this.root = Config._rootPlugin.root;
|
|
@@ -204,7 +204,7 @@ class Config {
|
|
|
204
204
|
marker?.stop();
|
|
205
205
|
}
|
|
206
206
|
async loadPluginsAndCommands(opts) {
|
|
207
|
-
const pluginsMarker = performance_1.Performance.mark('config.loadAllPlugins');
|
|
207
|
+
const pluginsMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.loadAllPlugins');
|
|
208
208
|
const { plugins, errors } = await this.pluginLoader.loadChildren({
|
|
209
209
|
devPlugins: this.options.devPlugins,
|
|
210
210
|
userPlugins: this.options.userPlugins,
|
|
@@ -214,7 +214,7 @@ class Config {
|
|
|
214
214
|
});
|
|
215
215
|
this.plugins = plugins;
|
|
216
216
|
pluginsMarker?.stop();
|
|
217
|
-
const commandsMarker = performance_1.Performance.mark('config.loadAllCommands');
|
|
217
|
+
const commandsMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.loadAllCommands');
|
|
218
218
|
for (const plugin of this.plugins.values()) {
|
|
219
219
|
this.loadCommands(plugin);
|
|
220
220
|
this.loadTopics(plugin);
|
|
@@ -225,7 +225,7 @@ class Config {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
async runHook(event, opts, timeout, captureErrors) {
|
|
228
|
-
const marker = performance_1.Performance.mark(`config.runHook#${event}`);
|
|
228
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runHook#${event}`);
|
|
229
229
|
debug('start %s hook', event);
|
|
230
230
|
const search = (m) => {
|
|
231
231
|
if (typeof m === 'function')
|
|
@@ -270,7 +270,7 @@ class Config {
|
|
|
270
270
|
};
|
|
271
271
|
const hooks = p.hooks[event] || [];
|
|
272
272
|
for (const hook of hooks) {
|
|
273
|
-
const marker = performance_1.Performance.mark(`config.runHook#${p.name}(${hook})`);
|
|
273
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runHook#${p.name}(${hook})`);
|
|
274
274
|
try {
|
|
275
275
|
/* eslint-disable no-await-in-loop */
|
|
276
276
|
const { isESM, module, filePath } = await (0, module_loader_1.loadWithData)(p, (0, node_path_1.join)(p.root, hook));
|
|
@@ -304,7 +304,7 @@ class Config {
|
|
|
304
304
|
return final;
|
|
305
305
|
}
|
|
306
306
|
async runCommand(id, argv = [], cachedCommand = null) {
|
|
307
|
-
const marker = performance_1.Performance.mark(`config.runCommand#${id}`);
|
|
307
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runCommand#${id}`);
|
|
308
308
|
debug('runCommand %s %o', id, argv);
|
|
309
309
|
let c = cachedCommand ?? this.findCommand(id);
|
|
310
310
|
if (!c) {
|
|
@@ -586,7 +586,7 @@ class Config {
|
|
|
586
586
|
return id;
|
|
587
587
|
}
|
|
588
588
|
loadCommands(plugin) {
|
|
589
|
-
const marker = performance_1.Performance.mark(`config.loadCommands#${plugin.name}`, { plugin: plugin.name });
|
|
589
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadCommands#${plugin.name}`, { plugin: plugin.name });
|
|
590
590
|
for (const command of plugin.commands) {
|
|
591
591
|
// set canonical command id
|
|
592
592
|
if (this._commands.has(command.id)) {
|
|
@@ -630,7 +630,7 @@ class Config {
|
|
|
630
630
|
marker?.stop();
|
|
631
631
|
}
|
|
632
632
|
loadTopics(plugin) {
|
|
633
|
-
const marker = performance_1.Performance.mark(`config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
633
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
634
634
|
for (const topic of (0, util_2.compact)(plugin.topics)) {
|
|
635
635
|
const existing = this._topics.get(topic.name);
|
|
636
636
|
if (existing) {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const Plugin = tslib_1.__importStar(require("./plugin"));
|
|
5
|
-
const util_1 = require("./util");
|
|
6
5
|
const performance_1 = require("../performance");
|
|
6
|
+
const util_1 = require("./util");
|
|
7
7
|
const util_2 = require("../util/util");
|
|
8
8
|
const node_path_1 = require("node:path");
|
|
9
9
|
const fs_1 = require("../util/fs");
|
|
@@ -28,7 +28,7 @@ class PluginLoader {
|
|
|
28
28
|
rootPlugin = plugins.find((p) => p.root === this.options.root) ?? plugins[0];
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
const marker = performance_1.Performance.mark('plugin.load#root');
|
|
31
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
|
|
32
32
|
rootPlugin = new Plugin.Plugin({ root: this.options.root, isRoot: true });
|
|
33
33
|
await rootPlugin.load();
|
|
34
34
|
marker?.addDetails({
|
|
@@ -94,7 +94,7 @@ class PluginLoader {
|
|
|
94
94
|
async loadPlugins(root, type, plugins, parent) {
|
|
95
95
|
if (!plugins || plugins.length === 0)
|
|
96
96
|
return;
|
|
97
|
-
const mark = performance_1.Performance.mark(`config.loadPlugins#${type}`);
|
|
97
|
+
const mark = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadPlugins#${type}`);
|
|
98
98
|
debug('loading plugins', plugins);
|
|
99
99
|
await Promise.all((plugins || []).map(async (plugin) => {
|
|
100
100
|
try {
|
|
@@ -113,7 +113,7 @@ class PluginLoader {
|
|
|
113
113
|
}
|
|
114
114
|
if (this.plugins.has(name))
|
|
115
115
|
return;
|
|
116
|
-
const pluginMarker = performance_1.Performance.mark(`plugin.load#${name}`);
|
|
116
|
+
const pluginMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.load#${name}`);
|
|
117
117
|
const instance = new Plugin.Plugin(opts);
|
|
118
118
|
await instance.load();
|
|
119
119
|
pluginMarker?.addDetails({
|
package/lib/config/plugin.js
CHANGED
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Plugin = void 0;
|
|
4
4
|
const errors_1 = require("../errors");
|
|
5
5
|
const util_1 = require("./util");
|
|
6
|
+
const performance_1 = require("../performance");
|
|
6
7
|
const util_2 = require("../util/util");
|
|
7
8
|
const node_path_1 = require("node:path");
|
|
8
9
|
const fs_1 = require("../util/fs");
|
|
9
10
|
const module_loader_1 = require("../module-loader");
|
|
10
|
-
const performance_1 = require("../performance");
|
|
11
11
|
const cache_command_1 = require("../util/cache-command");
|
|
12
12
|
const node_util_1 = require("node:util");
|
|
13
13
|
const globby_1 = require("globby");
|
|
@@ -179,7 +179,7 @@ class Plugin {
|
|
|
179
179
|
get commandIDs() {
|
|
180
180
|
if (!this.commandsDir)
|
|
181
181
|
return [];
|
|
182
|
-
const marker = performance_1.Performance.mark(`plugin.commandIDs#${this.name}`, { plugin: this.name });
|
|
182
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.commandIDs#${this.name}`, { plugin: this.name });
|
|
183
183
|
this._debug(`loading IDs from ${this.commandsDir}`);
|
|
184
184
|
const patterns = ['**/*.+(js|cjs|mjs|ts|tsx)', '!**/*.+(d.ts|test.ts|test.js|spec.ts|spec.js)?(x)'];
|
|
185
185
|
const ids = (0, globby_1.sync)(patterns, { cwd: this.commandsDir }).map((file) => {
|
|
@@ -195,7 +195,7 @@ class Plugin {
|
|
|
195
195
|
return ids;
|
|
196
196
|
}
|
|
197
197
|
async findCommand(id, opts = {}) {
|
|
198
|
-
const marker = performance_1.Performance.mark(`plugin.findCommand#${this.name}.${id}`, { id, plugin: this.name });
|
|
198
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.findCommand#${this.name}.${id}`, { id, plugin: this.name });
|
|
199
199
|
const fetch = async () => {
|
|
200
200
|
if (!this.commandsDir)
|
|
201
201
|
return;
|
|
@@ -256,7 +256,7 @@ class Plugin {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
|
-
const marker = performance_1.Performance.mark(`plugin.manifest#${this.name}`, { plugin: this.name });
|
|
259
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.manifest#${this.name}`, { plugin: this.name });
|
|
260
260
|
if (!ignoreManifest) {
|
|
261
261
|
const manifest = await readManifest();
|
|
262
262
|
if (manifest) {
|
package/lib/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.run = exports.versionAddition = exports.helpAddition = void 0;
|
|
4
|
+
const performance_1 = require("./performance");
|
|
4
5
|
const node_url_1 = require("node:url");
|
|
5
6
|
const node_util_1 = require("node:util");
|
|
6
7
|
const help_1 = require("./help");
|
|
7
8
|
const config_1 = require("./config");
|
|
8
|
-
const performance_1 = require("./performance");
|
|
9
9
|
const stream_1 = require("./cli-ux/stream");
|
|
10
10
|
const debug = require('debug')('oclif:main');
|
|
11
11
|
const log = (message = '', ...args) => {
|
|
@@ -34,8 +34,8 @@ const versionAddition = (argv, config) => {
|
|
|
34
34
|
};
|
|
35
35
|
exports.versionAddition = versionAddition;
|
|
36
36
|
async function run(argv, options) {
|
|
37
|
-
const marker = performance_1.Performance.mark('main.run');
|
|
38
|
-
const initMarker = performance_1.Performance.mark('main.run#init');
|
|
37
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'main.run');
|
|
38
|
+
const initMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'main.run#init');
|
|
39
39
|
const collectPerf = async () => {
|
|
40
40
|
marker?.stop();
|
|
41
41
|
if (!initMarker?.stopped)
|
package/lib/performance.d.ts
CHANGED
|
@@ -8,21 +8,26 @@ type PerfResult = {
|
|
|
8
8
|
scope: string | undefined;
|
|
9
9
|
};
|
|
10
10
|
type PerfHighlights = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
'oclif.configLoadMs': number;
|
|
12
|
+
'oclif.runMs': number;
|
|
13
|
+
'oclif.initMs': number;
|
|
14
|
+
'oclif.commandLoadMs': number;
|
|
15
|
+
'oclif.initHookMs': number;
|
|
16
|
+
'oclif.prerunHookMs': number;
|
|
17
|
+
'oclif.postrunHookMs': number;
|
|
18
|
+
'oclif.commandRunMs': number;
|
|
19
|
+
'oclif.corePluginsLoadMs': number;
|
|
20
|
+
'oclif.userPluginsLoadMs': number;
|
|
21
|
+
'oclif.linkedPluginsLoadMs': number;
|
|
16
22
|
pluginLoadTimes: Record<string, {
|
|
17
23
|
duration: number;
|
|
18
24
|
details: Details;
|
|
19
25
|
}>;
|
|
20
|
-
corePluginsLoadTime: number;
|
|
21
|
-
userPluginsLoadTime: number;
|
|
22
|
-
linkedPluginsLoadTime: number;
|
|
23
26
|
hookRunTimes: Record<string, Record<string, number>>;
|
|
24
27
|
};
|
|
28
|
+
export declare const OCLIF_MARKER_OWNER = "@oclif/core";
|
|
25
29
|
declare class Marker {
|
|
30
|
+
owner: string;
|
|
26
31
|
name: string;
|
|
27
32
|
details: Details;
|
|
28
33
|
module: string;
|
|
@@ -31,7 +36,7 @@ declare class Marker {
|
|
|
31
36
|
stopped: boolean;
|
|
32
37
|
private startMarker;
|
|
33
38
|
private stopMarker;
|
|
34
|
-
constructor(name: string, details?: Details);
|
|
39
|
+
constructor(owner: string, name: string, details?: Details);
|
|
35
40
|
addDetails(details: Details): void;
|
|
36
41
|
stop(): void;
|
|
37
42
|
measure(): void;
|
|
@@ -39,19 +44,21 @@ declare class Marker {
|
|
|
39
44
|
export declare class Performance {
|
|
40
45
|
private static markers;
|
|
41
46
|
private static _results;
|
|
42
|
-
private static
|
|
47
|
+
private static _oclifPerf;
|
|
43
48
|
static get enabled(): boolean;
|
|
44
|
-
|
|
45
|
-
static
|
|
46
|
-
static
|
|
49
|
+
/** returns a map of owner, PerfResult[]. Excludes oclif PerfResult, which you can get from oclifPerf */
|
|
50
|
+
static get results(): Map<string, PerfResult[]>;
|
|
51
|
+
static getResult(owner: string, name: string): PerfResult | undefined;
|
|
52
|
+
static get oclifPerf(): PerfHighlights | Record<string, never>;
|
|
47
53
|
/**
|
|
48
54
|
* Add a new performance marker
|
|
49
55
|
*
|
|
56
|
+
* @param owner An npm package like `@oclif/core` or `@salesforce/source-tracking`
|
|
50
57
|
* @param name Name of the marker. Use `module.method#scope` format
|
|
51
58
|
* @param details Arbitrary details to attach to the marker
|
|
52
59
|
* @returns Marker instance
|
|
53
60
|
*/
|
|
54
|
-
static mark(name: string, details?: Details): Marker | undefined;
|
|
61
|
+
static mark(owner: string, name: string, details?: Details): Marker | undefined;
|
|
55
62
|
/**
|
|
56
63
|
* Collect performance results into static Performance.results
|
|
57
64
|
*
|
package/lib/performance.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Performance = void 0;
|
|
3
|
+
exports.Performance = exports.OCLIF_MARKER_OWNER = void 0;
|
|
4
4
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
5
5
|
const settings_1 = require("./settings");
|
|
6
|
+
exports.OCLIF_MARKER_OWNER = '@oclif/core';
|
|
6
7
|
class Marker {
|
|
8
|
+
owner;
|
|
7
9
|
name;
|
|
8
10
|
details;
|
|
9
11
|
module;
|
|
@@ -12,7 +14,8 @@ class Marker {
|
|
|
12
14
|
stopped = false;
|
|
13
15
|
startMarker;
|
|
14
16
|
stopMarker;
|
|
15
|
-
constructor(name, details = {}) {
|
|
17
|
+
constructor(owner, name, details = {}) {
|
|
18
|
+
this.owner = owner;
|
|
16
19
|
this.name = name;
|
|
17
20
|
this.details = details;
|
|
18
21
|
this.startMarker = `${this.name}-start`;
|
|
@@ -36,41 +39,43 @@ class Marker {
|
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
class Performance {
|
|
39
|
-
|
|
40
|
-
static
|
|
41
|
-
|
|
42
|
+
/* Key: marker.name */
|
|
43
|
+
static markers = new Map();
|
|
44
|
+
/* Key: marker.owner */
|
|
45
|
+
static _results = new Map();
|
|
46
|
+
static _oclifPerf;
|
|
42
47
|
static get enabled() {
|
|
43
48
|
return settings_1.settings.performanceEnabled ?? false;
|
|
44
49
|
}
|
|
50
|
+
/** returns a map of owner, PerfResult[]. Excludes oclif PerfResult, which you can get from oclifPerf */
|
|
45
51
|
static get results() {
|
|
46
52
|
if (!Performance.enabled)
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
return Performance._results;
|
|
50
|
-
throw new Error('Perf results not available. Did you forget to call await Performance.collect()?');
|
|
53
|
+
return new Map();
|
|
54
|
+
return new Map([...Performance._results.entries()].filter(([owner]) => owner !== exports.OCLIF_MARKER_OWNER));
|
|
51
55
|
}
|
|
52
|
-
static getResult(name) {
|
|
53
|
-
return Performance.
|
|
56
|
+
static getResult(owner, name) {
|
|
57
|
+
return Performance._results.get(owner)?.find(r => r.name === name);
|
|
54
58
|
}
|
|
55
|
-
static get
|
|
59
|
+
static get oclifPerf() {
|
|
56
60
|
if (!Performance.enabled)
|
|
57
61
|
return {};
|
|
58
|
-
if (Performance.
|
|
59
|
-
return Performance.
|
|
62
|
+
if (Performance._oclifPerf)
|
|
63
|
+
return Performance._oclifPerf;
|
|
60
64
|
throw new Error('Perf results not available. Did you forget to call await Performance.collect()?');
|
|
61
65
|
}
|
|
62
66
|
/**
|
|
63
67
|
* Add a new performance marker
|
|
64
68
|
*
|
|
69
|
+
* @param owner An npm package like `@oclif/core` or `@salesforce/source-tracking`
|
|
65
70
|
* @param name Name of the marker. Use `module.method#scope` format
|
|
66
71
|
* @param details Arbitrary details to attach to the marker
|
|
67
72
|
* @returns Marker instance
|
|
68
73
|
*/
|
|
69
|
-
static mark(name, details = {}) {
|
|
74
|
+
static mark(owner, name, details = {}) {
|
|
70
75
|
if (!Performance.enabled)
|
|
71
76
|
return;
|
|
72
|
-
const marker = new Marker(name, details);
|
|
73
|
-
Performance.markers
|
|
77
|
+
const marker = new Marker(owner, name, details);
|
|
78
|
+
Performance.markers.set(marker.name, marker);
|
|
74
79
|
return marker;
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
@@ -81,9 +86,9 @@ class Performance {
|
|
|
81
86
|
static async collect() {
|
|
82
87
|
if (!Performance.enabled)
|
|
83
88
|
return;
|
|
84
|
-
if (Performance._results.
|
|
89
|
+
if (Performance._results.size > 0)
|
|
85
90
|
return;
|
|
86
|
-
const markers =
|
|
91
|
+
const markers = [...Performance.markers.values()];
|
|
87
92
|
if (markers.length === 0)
|
|
88
93
|
return;
|
|
89
94
|
for (const marker of markers.filter((m) => !m.stopped)) {
|
|
@@ -92,28 +97,28 @@ class Performance {
|
|
|
92
97
|
return new Promise((resolve) => {
|
|
93
98
|
const perfObserver = new node_perf_hooks_1.PerformanceObserver((items) => {
|
|
94
99
|
for (const entry of items.getEntries()) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
const marker = Performance.markers.get(entry.name);
|
|
101
|
+
if (marker) {
|
|
102
|
+
const result = {
|
|
98
103
|
name: entry.name,
|
|
99
104
|
module: marker.module,
|
|
100
105
|
method: marker.method,
|
|
101
106
|
scope: marker.scope,
|
|
102
107
|
duration: entry.duration,
|
|
103
108
|
details: marker.details,
|
|
104
|
-
}
|
|
109
|
+
};
|
|
110
|
+
const existing = Performance._results.get(marker.owner) ?? [];
|
|
111
|
+
Performance._results.set(marker.owner, [...existing, result]);
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
: 0;
|
|
112
|
-
const pluginLoadTimes = Object.fromEntries(Performance.results
|
|
114
|
+
const oclifResults = Performance._results.get(exports.OCLIF_MARKER_OWNER) ?? [];
|
|
115
|
+
const command = oclifResults.find(r => r.name.startsWith('config.runCommand'));
|
|
116
|
+
const commandLoadTime = command ? Performance.getResult(exports.OCLIF_MARKER_OWNER, `plugin.findCommand#${command.details.plugin}.${command.details.command}`)?.duration ?? 0 : 0;
|
|
117
|
+
const pluginLoadTimes = Object.fromEntries(oclifResults
|
|
113
118
|
.filter(({ name }) => name.startsWith('plugin.load#'))
|
|
114
119
|
.sort((a, b) => b.duration - a.duration)
|
|
115
120
|
.map(({ scope, duration, details }) => [scope, { duration, details }]));
|
|
116
|
-
const hookRunTimes =
|
|
121
|
+
const hookRunTimes = oclifResults
|
|
117
122
|
.filter(({ name }) => name.startsWith('config.runHook#'))
|
|
118
123
|
.reduce((acc, perfResult) => {
|
|
119
124
|
const event = perfResult.details.event;
|
|
@@ -130,22 +135,24 @@ class Performance {
|
|
|
130
135
|
}
|
|
131
136
|
return acc;
|
|
132
137
|
}, {});
|
|
133
|
-
const pluginLoadTimeByType = Object.fromEntries(
|
|
138
|
+
const pluginLoadTimeByType = Object.fromEntries(oclifResults
|
|
134
139
|
.filter(({ name }) => name.startsWith('config.loadPlugins#'))
|
|
135
140
|
.sort((a, b) => b.duration - a.duration)
|
|
136
141
|
.map(({ scope, duration }) => [scope, duration]));
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
Performance._oclifPerf = {
|
|
143
|
+
'oclif.configLoadMs': Performance.getResult(exports.OCLIF_MARKER_OWNER, 'config.load')?.duration ?? 0,
|
|
144
|
+
'oclif.runMs': Performance.getResult(exports.OCLIF_MARKER_OWNER, 'main.run')?.duration ?? 0,
|
|
145
|
+
'oclif.initMs': Performance.getResult(exports.OCLIF_MARKER_OWNER, 'main.run#init')?.duration ?? 0,
|
|
146
|
+
'oclif.commandRunMs': oclifResults.find(({ name }) => name.startsWith('config.runCommand#'))?.duration ?? 0,
|
|
147
|
+
'oclif.commandLoadMs': commandLoadTime,
|
|
148
|
+
'oclif.corePluginsLoadMs': pluginLoadTimeByType.core ?? 0,
|
|
149
|
+
'oclif.userPluginsLoadMs': pluginLoadTimeByType.user ?? 0,
|
|
150
|
+
'oclif.linkedPluginsLoadMs': pluginLoadTimeByType.link ?? 0,
|
|
151
|
+
'oclif.postrunHookMs': hookRunTimes.postrun?.total ?? 0,
|
|
152
|
+
'oclif.prerunHookMs': hookRunTimes.prerun?.total ?? 0,
|
|
153
|
+
'oclif.initHookMs': hookRunTimes.init?.total ?? 0,
|
|
144
154
|
pluginLoadTimes,
|
|
145
155
|
hookRunTimes,
|
|
146
|
-
corePluginsLoadTime: pluginLoadTimeByType.core ?? 0,
|
|
147
|
-
userPluginsLoadTime: pluginLoadTimeByType.user ?? 0,
|
|
148
|
-
linkedPluginsLoadTime: pluginLoadTimeByType.link ?? 0,
|
|
149
156
|
};
|
|
150
157
|
resolve();
|
|
151
158
|
});
|
|
@@ -168,33 +175,44 @@ class Performance {
|
|
|
168
175
|
static debug() {
|
|
169
176
|
if (!Performance.enabled)
|
|
170
177
|
return;
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
for (const [plugin, result] of Object.entries(Performance.
|
|
178
|
+
const oclifDebug = require('debug')('oclif-perf');
|
|
179
|
+
oclifDebug('Total Time: %sms', Performance.oclifPerf['oclif.runMs'].toFixed(4));
|
|
180
|
+
oclifDebug('Init Time: %sms', Performance.oclifPerf['oclif.initMs'].toFixed(4));
|
|
181
|
+
oclifDebug('Config Load Time: %sms', Performance.oclifPerf['oclif.configLoadMs'].toFixed(4));
|
|
182
|
+
oclifDebug(' • Plugins Load Time: %sms', Performance.getResult(exports.OCLIF_MARKER_OWNER, 'config.loadAllPlugins')?.duration.toFixed(4) ?? 0);
|
|
183
|
+
oclifDebug(' • Commands Load Time: %sms', Performance.getResult(exports.OCLIF_MARKER_OWNER, 'config.loadAllCommands')?.duration.toFixed(4) ?? 0);
|
|
184
|
+
oclifDebug('Core Plugin Load Time: %sms', Performance.oclifPerf['oclif.corePluginsLoadMs'].toFixed(4));
|
|
185
|
+
oclifDebug('User Plugin Load Time: %sms', Performance.oclifPerf['oclif.userPluginsLoadMs'].toFixed(4));
|
|
186
|
+
oclifDebug('Linked Plugin Load Time: %sms', Performance.oclifPerf['oclif.linkedPluginsLoadMs'].toFixed(4));
|
|
187
|
+
oclifDebug('Plugin Load Times:');
|
|
188
|
+
for (const [plugin, result] of Object.entries(Performance.oclifPerf.pluginLoadTimes)) {
|
|
182
189
|
if (result.details.hasManifest) {
|
|
183
|
-
|
|
190
|
+
oclifDebug(` ${plugin}: ${result.duration.toFixed(4)}ms`);
|
|
184
191
|
}
|
|
185
192
|
else {
|
|
186
|
-
|
|
193
|
+
oclifDebug(` ${plugin}: ${result.duration.toFixed(4)}ms (no manifest!)`);
|
|
187
194
|
}
|
|
188
195
|
}
|
|
189
|
-
|
|
190
|
-
for (const [event, runTimes] of Object.entries(Performance.
|
|
191
|
-
|
|
196
|
+
oclifDebug('Hook Run Times:');
|
|
197
|
+
for (const [event, runTimes] of Object.entries(Performance.oclifPerf.hookRunTimes)) {
|
|
198
|
+
oclifDebug(` ${event}:`);
|
|
192
199
|
for (const [plugin, duration] of Object.entries(runTimes)) {
|
|
193
|
-
|
|
200
|
+
oclifDebug(` ${plugin}: ${duration.toFixed(4)}ms`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
oclifDebug('Command Load Time: %sms', Performance.oclifPerf['oclif.commandLoadMs'].toFixed(4));
|
|
204
|
+
oclifDebug('Command Run Time: %sms', Performance.oclifPerf['oclif.commandRunMs'].toFixed(4));
|
|
205
|
+
const nonCoreDebug = require('debug')('non-oclif-perf');
|
|
206
|
+
const nonCorePerf = Performance.results;
|
|
207
|
+
if (nonCorePerf.size > 0) {
|
|
208
|
+
nonCoreDebug('Non-Core Performance Measurements:');
|
|
209
|
+
for (const [owner, results] of nonCorePerf) {
|
|
210
|
+
nonCoreDebug(` ${owner}:`);
|
|
211
|
+
for (const result of results) {
|
|
212
|
+
nonCoreDebug(` ${result.name}: ${result.duration.toFixed(4)}ms`);
|
|
213
|
+
}
|
|
194
214
|
}
|
|
195
215
|
}
|
|
196
|
-
debug('Command Load Time: %sms', Performance.highlights.commandLoadTime.toFixed(4));
|
|
197
|
-
debug('Command Run Time: %sms', Performance.highlights.commandRunTime.toFixed(4));
|
|
198
216
|
}
|
|
199
217
|
}
|
|
200
218
|
exports.Performance = Performance;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/core",
|
|
3
3
|
"description": "base library for oclif CLIs",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.24",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"chai-as-promised": "^7.1.1",
|
|
60
60
|
"commitlint": "^17.7.2",
|
|
61
61
|
"cross-env": "^7.0.3",
|
|
62
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.50.0",
|
|
63
63
|
"eslint-config-oclif": "^5.0.0",
|
|
64
64
|
"eslint-config-oclif-typescript": "^2.0.1",
|
|
65
65
|
"eslint-config-prettier": "^9.0.0",
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"lint": "eslint . --ext .ts",
|
|
113
113
|
"posttest": "yarn lint && yarn test:circular-deps",
|
|
114
114
|
"prepack": "yarn run build",
|
|
115
|
+
"prepare": "husky install",
|
|
115
116
|
"pretest": "yarn build && tsc -p test --noEmit --skipLibCheck",
|
|
116
117
|
"test:circular-deps": "madge lib/ -c",
|
|
117
118
|
"test:e2e": "mocha --forbid-only \"test/**/*.e2e.ts\" --parallel --timeout 1200000",
|