@umijs/utils 4.0.28 → 4.0.30

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/dist/logger.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare const prefixes: {
7
7
  info: string;
8
8
  event: string;
9
9
  debug: string;
10
+ profile: string;
10
11
  };
11
12
  export declare function wait(...message: any[]): void;
12
13
  export declare function error(...message: any[]): void;
@@ -16,4 +17,5 @@ export declare function info(...message: any[]): void;
16
17
  export declare function event(...message: any[]): void;
17
18
  export declare function debug(...message: any[]): void;
18
19
  export declare function fatal(...message: any[]): void;
20
+ export declare function profile(id: string, ...message: any[]): void;
19
21
  export declare function getLatestLogFilePath(): string | null;
package/dist/logger.js CHANGED
@@ -29,6 +29,7 @@ __export(logger_exports, {
29
29
  getLatestLogFilePath: () => getLatestLogFilePath,
30
30
  info: () => info,
31
31
  prefixes: () => prefixes,
32
+ profile: () => profile,
32
33
  ready: () => ready,
33
34
  wait: () => wait,
34
35
  warn: () => warn
@@ -39,6 +40,7 @@ var import_chalk = __toESM(require("../compiled/chalk"));
39
40
  var import_fs_extra = __toESM(require("../compiled/fs-extra"));
40
41
  var import_importLazy = require("./importLazy");
41
42
  var enableFSLogger = process.env.FS_LOGGER !== "none" && !process.versions.webcontainer;
43
+ var profilers = {};
42
44
  var loggerDir = (0, import_path.join)(process.cwd(), "node_modules/.cache/logger");
43
45
  var loggerPath = (0, import_path.join)(loggerDir, "umi.log");
44
46
  var prefixes = {
@@ -49,7 +51,8 @@ var prefixes = {
49
51
  ready: import_chalk.default.green("ready") + " -",
50
52
  info: import_chalk.default.cyan("info") + " -",
51
53
  event: import_chalk.default.magenta("event") + " -",
52
- debug: import_chalk.default.gray("debug") + " -"
54
+ debug: import_chalk.default.gray("debug") + " -",
55
+ profile: import_chalk.default.blue("profile") + " -"
53
56
  };
54
57
  var logger;
55
58
  if (enableFSLogger) {
@@ -115,6 +118,22 @@ function fatal(...message) {
115
118
  console.error(prefixes.fatal, ...message);
116
119
  logger.fatal(message[0]);
117
120
  }
121
+ function profile(id, ...message) {
122
+ if (process.env.IS_UMI_BUILD_WORKER && !process.env.DEBUG) {
123
+ return;
124
+ }
125
+ if (!profilers[id]) {
126
+ profilers[id] = {
127
+ startTime: Date.now()
128
+ };
129
+ console.log(prefixes.profile, import_chalk.default.green(id), ...message);
130
+ return;
131
+ }
132
+ const endTime = Date.now();
133
+ const { startTime } = profilers[id];
134
+ console.log(prefixes.profile, import_chalk.default.green(id), `Completed in ${import_chalk.default.cyan(`${endTime - startTime}ms`)}`, ...message);
135
+ delete profilers[id];
136
+ }
118
137
  function getLatestLogFilePath() {
119
138
  return enableFSLogger ? loggerPath : null;
120
139
  }
@@ -127,6 +146,7 @@ function getLatestLogFilePath() {
127
146
  getLatestLogFilePath,
128
147
  info,
129
148
  prefixes,
149
+ profile,
130
150
  ready,
131
151
  wait,
132
152
  warn
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/utils",
3
- "version": "4.0.28",
3
+ "version": "4.0.30",
4
4
  "homepage": "https://github.com/umijs/umi/tree/master/packages/utils#readme",
5
5
  "bugs": "https://github.com/umijs/umi/issues",
6
6
  "repository": {