@oclif/core 3.0.0-beta.21 → 3.0.0-beta.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/lib/cli-ux/index.d.ts +2 -2
- package/lib/cli-ux/index.js +9 -2
- package/lib/cli-ux/styled/index.d.ts +0 -1
- package/lib/cli-ux/styled/index.js +1 -3
- package/lib/config/config.js +10 -11
- 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 +2 -2
- package/lib/cli-ux/styled/json.d.ts +0 -1
- package/lib/cli-ux/styled/json.js +0 -18
package/lib/cli-ux/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class ux {
|
|
|
15
15
|
static get action(): ActionBase;
|
|
16
16
|
static styledObject(obj: any, keys?: string[]): void;
|
|
17
17
|
static styledHeader(header: string): void;
|
|
18
|
-
static
|
|
18
|
+
static styledJSON(obj: unknown): void;
|
|
19
19
|
static get table(): typeof styled.Table.table;
|
|
20
20
|
static get tree(): typeof styled.tree;
|
|
21
21
|
static get wait(): typeof uxWait;
|
|
@@ -29,7 +29,7 @@ export declare class ux {
|
|
|
29
29
|
static annotation(text: string, annotation: string): void;
|
|
30
30
|
static flush(ms?: number): Promise<void>;
|
|
31
31
|
}
|
|
32
|
-
declare const action: ActionBase, annotation: typeof ux.annotation, anykey: typeof uxPrompt.anykey, confirm: typeof uxPrompt.confirm, debug: typeof ux.debug, done: typeof ux.done, flush: typeof ux.flush, info: typeof ux.info, log: typeof ux.log, progress: typeof styled.progress, prompt: typeof uxPrompt.prompt, styledHeader: typeof ux.styledHeader, styledJSON: typeof
|
|
32
|
+
declare const action: ActionBase, annotation: typeof ux.annotation, anykey: typeof uxPrompt.anykey, confirm: typeof uxPrompt.confirm, debug: typeof ux.debug, done: typeof ux.done, flush: typeof ux.flush, info: typeof ux.info, log: typeof ux.log, progress: typeof styled.progress, prompt: typeof uxPrompt.prompt, styledHeader: typeof ux.styledHeader, styledJSON: typeof ux.styledJSON, styledObject: typeof ux.styledObject, table: typeof styled.Table.table, trace: typeof ux.trace, tree: typeof styled.tree, url: typeof ux.url, wait: (ms?: number) => Promise<void>;
|
|
33
33
|
declare const error: typeof Errors.error, exit: typeof Errors.exit, warn: typeof Errors.warn;
|
|
34
34
|
export { action, annotation, anykey, confirm, debug, done, error, exit, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, warn, };
|
|
35
35
|
export { ExitError } from './exit';
|
package/lib/cli-ux/index.js
CHANGED
|
@@ -35,8 +35,15 @@ class ux {
|
|
|
35
35
|
static styledHeader(header) {
|
|
36
36
|
this.info(chalk_1.default.dim('=== ') + chalk_1.default.bold(header) + '\n');
|
|
37
37
|
}
|
|
38
|
-
static
|
|
39
|
-
|
|
38
|
+
static styledJSON(obj) {
|
|
39
|
+
const json = JSON.stringify(obj, null, 2);
|
|
40
|
+
if (!chalk_1.default.level) {
|
|
41
|
+
info(json);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const cardinal = require('cardinal');
|
|
45
|
+
const theme = require('cardinal/themes/jq');
|
|
46
|
+
this.info(cardinal.highlight(json, { json: true, theme }));
|
|
40
47
|
}
|
|
41
48
|
static get table() {
|
|
42
49
|
return styled.Table.table;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tree = exports.styledObject = exports.
|
|
3
|
+
exports.tree = exports.styledObject = exports.progress = exports.Table = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
exports.Table = tslib_1.__importStar(require("./table"));
|
|
6
6
|
var progress_1 = require("./progress");
|
|
7
7
|
Object.defineProperty(exports, "progress", { enumerable: true, get: function () { return tslib_1.__importDefault(progress_1).default; } });
|
|
8
|
-
var json_1 = require("./json");
|
|
9
|
-
Object.defineProperty(exports, "styledJSON", { enumerable: true, get: function () { return tslib_1.__importDefault(json_1).default; } });
|
|
10
8
|
var object_1 = require("./object");
|
|
11
9
|
Object.defineProperty(exports, "styledObject", { enumerable: true, get: function () { return tslib_1.__importDefault(object_1).default; } });
|
|
12
10
|
var tree_1 = require("./tree");
|
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");
|
|
@@ -132,9 +132,8 @@ class Config {
|
|
|
132
132
|
}
|
|
133
133
|
// eslint-disable-next-line complexity
|
|
134
134
|
async load() {
|
|
135
|
-
settings_1.settings.performanceEnabled =
|
|
136
|
-
|
|
137
|
-
const marker = performance_1.Performance.mark('config.load');
|
|
135
|
+
settings_1.settings.performanceEnabled = (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
|
|
136
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.load');
|
|
138
137
|
this.pluginLoader = new plugin_loader_1.default({ root: this.options.root, plugins: this.options.plugins });
|
|
139
138
|
Config._rootPlugin = await this.pluginLoader.loadRoot();
|
|
140
139
|
this.root = Config._rootPlugin.root;
|
|
@@ -204,7 +203,7 @@ class Config {
|
|
|
204
203
|
marker?.stop();
|
|
205
204
|
}
|
|
206
205
|
async loadPluginsAndCommands(opts) {
|
|
207
|
-
const pluginsMarker = performance_1.Performance.mark('config.loadAllPlugins');
|
|
206
|
+
const pluginsMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.loadAllPlugins');
|
|
208
207
|
const { plugins, errors } = await this.pluginLoader.loadChildren({
|
|
209
208
|
devPlugins: this.options.devPlugins,
|
|
210
209
|
userPlugins: this.options.userPlugins,
|
|
@@ -214,7 +213,7 @@ class Config {
|
|
|
214
213
|
});
|
|
215
214
|
this.plugins = plugins;
|
|
216
215
|
pluginsMarker?.stop();
|
|
217
|
-
const commandsMarker = performance_1.Performance.mark('config.loadAllCommands');
|
|
216
|
+
const commandsMarker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.loadAllCommands');
|
|
218
217
|
for (const plugin of this.plugins.values()) {
|
|
219
218
|
this.loadCommands(plugin);
|
|
220
219
|
this.loadTopics(plugin);
|
|
@@ -225,7 +224,7 @@ class Config {
|
|
|
225
224
|
}
|
|
226
225
|
}
|
|
227
226
|
async runHook(event, opts, timeout, captureErrors) {
|
|
228
|
-
const marker = performance_1.Performance.mark(`config.runHook#${event}`);
|
|
227
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runHook#${event}`);
|
|
229
228
|
debug('start %s hook', event);
|
|
230
229
|
const search = (m) => {
|
|
231
230
|
if (typeof m === 'function')
|
|
@@ -270,7 +269,7 @@ class Config {
|
|
|
270
269
|
};
|
|
271
270
|
const hooks = p.hooks[event] || [];
|
|
272
271
|
for (const hook of hooks) {
|
|
273
|
-
const marker = performance_1.Performance.mark(`config.runHook#${p.name}(${hook})`);
|
|
272
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runHook#${p.name}(${hook})`);
|
|
274
273
|
try {
|
|
275
274
|
/* eslint-disable no-await-in-loop */
|
|
276
275
|
const { isESM, module, filePath } = await (0, module_loader_1.loadWithData)(p, (0, node_path_1.join)(p.root, hook));
|
|
@@ -304,7 +303,7 @@ class Config {
|
|
|
304
303
|
return final;
|
|
305
304
|
}
|
|
306
305
|
async runCommand(id, argv = [], cachedCommand = null) {
|
|
307
|
-
const marker = performance_1.Performance.mark(`config.runCommand#${id}`);
|
|
306
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runCommand#${id}`);
|
|
308
307
|
debug('runCommand %s %o', id, argv);
|
|
309
308
|
let c = cachedCommand ?? this.findCommand(id);
|
|
310
309
|
if (!c) {
|
|
@@ -586,7 +585,7 @@ class Config {
|
|
|
586
585
|
return id;
|
|
587
586
|
}
|
|
588
587
|
loadCommands(plugin) {
|
|
589
|
-
const marker = performance_1.Performance.mark(`config.loadCommands#${plugin.name}`, { plugin: plugin.name });
|
|
588
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadCommands#${plugin.name}`, { plugin: plugin.name });
|
|
590
589
|
for (const command of plugin.commands) {
|
|
591
590
|
// set canonical command id
|
|
592
591
|
if (this._commands.has(command.id)) {
|
|
@@ -630,7 +629,7 @@ class Config {
|
|
|
630
629
|
marker?.stop();
|
|
631
630
|
}
|
|
632
631
|
loadTopics(plugin) {
|
|
633
|
-
const marker = performance_1.Performance.mark(`config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
632
|
+
const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.loadTopics#${plugin.name}`, { plugin: plugin.name });
|
|
634
633
|
for (const topic of (0, util_2.compact)(plugin.topics)) {
|
|
635
634
|
const existing = this._topics.get(topic.name);
|
|
636
635
|
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.23",
|
|
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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function styledJSON(obj: unknown): void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
|
-
const node_util_1 = require("node:util");
|
|
6
|
-
const stream_1 = require("../stream");
|
|
7
|
-
const info = (output) => stream_1.stdout.write((0, node_util_1.format)(output) + '\n');
|
|
8
|
-
function styledJSON(obj) {
|
|
9
|
-
const json = JSON.stringify(obj, null, 2);
|
|
10
|
-
if (!chalk_1.default.level) {
|
|
11
|
-
info(json);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const cardinal = require('cardinal');
|
|
15
|
-
const theme = require('cardinal/themes/jq');
|
|
16
|
-
info(cardinal.highlight(json, { json: true, theme }));
|
|
17
|
-
}
|
|
18
|
-
exports.default = styledJSON;
|