@umijs/utils 4.0.0-canary.20230201.2 → 4.0.0-canary.20230207.1
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.js +39 -17
- package/package.json +1 -1
package/dist/logger.js
CHANGED
|
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
20
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
24
|
|
|
22
25
|
// src/logger.ts
|
|
@@ -38,10 +41,11 @@ module.exports = __toCommonJS(logger_exports);
|
|
|
38
41
|
var import_path = require("path");
|
|
39
42
|
var import_chalk = __toESM(require("../compiled/chalk"));
|
|
40
43
|
var import_fs_extra = __toESM(require("../compiled/fs-extra"));
|
|
44
|
+
var import_pkg_up = require("../compiled/pkg-up");
|
|
41
45
|
var import_importLazy = require("./importLazy");
|
|
42
46
|
var enableFSLogger = process.env.FS_LOGGER !== "none" && !process.versions.webcontainer;
|
|
43
47
|
var profilers = {};
|
|
44
|
-
var loggerDir = (
|
|
48
|
+
var loggerDir = findLoggerDir();
|
|
45
49
|
var loggerPath = (0, import_path.join)(loggerDir, "umi.log");
|
|
46
50
|
var prefixes = {
|
|
47
51
|
wait: import_chalk.default.cyan("wait") + " -",
|
|
@@ -56,7 +60,9 @@ var prefixes = {
|
|
|
56
60
|
};
|
|
57
61
|
var logger;
|
|
58
62
|
if (enableFSLogger) {
|
|
59
|
-
const { default: pino } = (0, import_importLazy.importLazy)(
|
|
63
|
+
const { default: pino } = (0, import_importLazy.importLazy)(
|
|
64
|
+
require.resolve("pino")
|
|
65
|
+
);
|
|
60
66
|
import_fs_extra.default.mkdirpSync(loggerDir);
|
|
61
67
|
const customLevels = {
|
|
62
68
|
ready: 31,
|
|
@@ -64,19 +70,22 @@ if (enableFSLogger) {
|
|
|
64
70
|
wait: 55,
|
|
65
71
|
debug: 30
|
|
66
72
|
};
|
|
67
|
-
logger = pino(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
logger = pino(
|
|
74
|
+
{
|
|
75
|
+
customLevels
|
|
76
|
+
},
|
|
77
|
+
pino.transport({
|
|
78
|
+
targets: [
|
|
79
|
+
{
|
|
80
|
+
target: require.resolve("pino/file"),
|
|
81
|
+
options: {
|
|
82
|
+
destination: loggerPath
|
|
83
|
+
},
|
|
84
|
+
level: "trace"
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
);
|
|
80
89
|
} else {
|
|
81
90
|
logger = {};
|
|
82
91
|
Object.keys(prefixes).forEach((key) => {
|
|
@@ -131,12 +140,25 @@ function profile(id, ...message) {
|
|
|
131
140
|
}
|
|
132
141
|
const endTime = Date.now();
|
|
133
142
|
const { startTime } = profilers[id];
|
|
134
|
-
console.log(
|
|
143
|
+
console.log(
|
|
144
|
+
prefixes.profile,
|
|
145
|
+
import_chalk.default.green(id),
|
|
146
|
+
`Completed in ${import_chalk.default.cyan(`${endTime - startTime}ms`)}`,
|
|
147
|
+
...message
|
|
148
|
+
);
|
|
135
149
|
delete profilers[id];
|
|
136
150
|
}
|
|
137
151
|
function getLatestLogFilePath() {
|
|
138
152
|
return enableFSLogger ? loggerPath : null;
|
|
139
153
|
}
|
|
154
|
+
function findLoggerDir() {
|
|
155
|
+
let baseDir = process.cwd();
|
|
156
|
+
const pkg = (0, import_pkg_up.pkgUpSync)({ cwd: baseDir });
|
|
157
|
+
if (pkg) {
|
|
158
|
+
baseDir = (0, import_path.dirname)(pkg);
|
|
159
|
+
}
|
|
160
|
+
return (0, import_path.join)(baseDir, "node_modules/.cache/logger");
|
|
161
|
+
}
|
|
140
162
|
// Annotate the CommonJS export names for ESM import in node:
|
|
141
163
|
0 && (module.exports = {
|
|
142
164
|
debug,
|
package/package.json
CHANGED