@umijs/core 4.0.47 → 4.0.48

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.
@@ -94,7 +94,7 @@ export declare class Service {
94
94
  config: any;
95
95
  defaultConfig: any;
96
96
  }>;
97
- _baconPlugins(): void;
97
+ _profilePlugins(): void;
98
98
  initPreset(opts: {
99
99
  preset: Plugin;
100
100
  presets: Plugin[];
@@ -301,7 +301,7 @@ var Service = class {
301
301
  });
302
302
  this.stage = import_types.ServiceStage.runCommand;
303
303
  let ret = await command.fn({ args });
304
- this._baconPlugins();
304
+ this._profilePlugins();
305
305
  return ret;
306
306
  }
307
307
  async getPaths() {
@@ -334,13 +334,47 @@ var Service = class {
334
334
  this.config = import_utils.lodash.merge(defaultConfig, config);
335
335
  return { config, defaultConfig };
336
336
  }
337
- _baconPlugins() {
338
- if (this.args.baconPlugins) {
337
+ _profilePlugins() {
338
+ if (this.args.profilePlugins) {
339
339
  console.log();
340
- for (const id of Object.keys(this.plugins)) {
340
+ Object.keys(this.plugins).map((id) => {
341
341
  const plugin = this.plugins[id];
342
- console.log(import_utils.chalk.green("plugin"), plugin.id, plugin.time);
343
- }
342
+ const total = totalTime(plugin);
343
+ return {
344
+ id,
345
+ total,
346
+ register: plugin.time.register || 0,
347
+ hooks: plugin.time.hooks
348
+ };
349
+ }).filter((time) => {
350
+ return time.total > (this.args.profilePluginsLimit ?? 10);
351
+ }).sort((a, b) => b.total > a.total ? 1 : -1).forEach((time) => {
352
+ console.log(import_utils.chalk.green("plugin"), time.id, time.total);
353
+ if (this.args.profilePluginsVerbose) {
354
+ console.log(" ", import_utils.chalk.green("register"), time.register);
355
+ console.log(
356
+ " ",
357
+ import_utils.chalk.green("hooks"),
358
+ JSON.stringify(sortHooks(time.hooks))
359
+ );
360
+ }
361
+ });
362
+ }
363
+ function sortHooks(hooks) {
364
+ const ret = {};
365
+ Object.keys(hooks).sort((a, b) => {
366
+ return add(hooks[b]) - add(hooks[a]);
367
+ }).forEach((key) => {
368
+ ret[key] = hooks[key];
369
+ });
370
+ return ret;
371
+ }
372
+ function totalTime(plugin) {
373
+ const time = plugin.time;
374
+ return (time.register || 0) + Object.values(time.hooks).reduce((a, b) => a + add(b), 0);
375
+ }
376
+ function add(nums) {
377
+ return nums.reduce((a, b) => a + b, 0);
344
378
  }
345
379
  }
346
380
  async initPreset(opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/core",
3
- "version": "4.0.47",
3
+ "version": "4.0.48",
4
4
  "homepage": "https://github.com/umijs/umi/tree/master/packages/core#readme",
5
5
  "bugs": "https://github.com/umijs/umi/issues",
6
6
  "repository": {
@@ -21,8 +21,8 @@
21
21
  "test": "umi-scripts jest-turbo"
22
22
  },
23
23
  "dependencies": {
24
- "@umijs/bundler-utils": "4.0.47",
25
- "@umijs/utils": "4.0.47"
24
+ "@umijs/bundler-utils": "4.0.48",
25
+ "@umijs/utils": "4.0.48"
26
26
  },
27
27
  "devDependencies": {
28
28
  "dotenv": "16.0.0",