@docusaurus/logger 2.0.0-beta.21 → 2.0.0
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/README.md +1 -0
- package/lib/__mocks__/chalk.js +1 -0
- package/lib/__mocks__/chalk.js.map +1 -1
- package/lib/index.d.ts +22 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +37 -5
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +50 -5
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ It exports a single object as default export: `logger`. `logger` has the followi
|
|
|
25
25
|
- `warn`: prints a warning that should be payed attention to.
|
|
26
26
|
- `error`: prints an error (not necessarily halting the program) that signals significant problems.
|
|
27
27
|
- `success`: prints a success message.
|
|
28
|
+
- The `report` function. It takes a `ReportingSeverity` value (`ignore`, `log`, `warn`, `throw`) and reports a message according to the severity.
|
|
28
29
|
|
|
29
30
|
### A word on the `error` formatter
|
|
30
31
|
|
package/lib/__mocks__/chalk.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
9
|
const chalk = require('chalk');
|
|
9
10
|
// Force coloring the output even in CI
|
|
10
11
|
module.exports = new chalk.Instance({ level: 3 });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chalk.js","sourceRoot":"","sources":["../../src/__mocks__/chalk.js"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"chalk.js","sourceRoot":"","sources":["../../src/__mocks__/chalk.js"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/B,uCAAuC;AACvC,MAAM,CAAC,OAAO,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,EAAC,KAAK,EAAE,CAAC,EAAC,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import type { ReportingSeverity } from '@docusaurus/types';
|
|
8
8
|
declare type InterpolatableValue = string | number | (string | number)[];
|
|
9
9
|
declare function interpolate(msgs: TemplateStringsArray, ...values: InterpolatableValue[]): string;
|
|
10
10
|
declare function info(msg: unknown): void;
|
|
@@ -16,12 +16,27 @@ declare function error(msg: TemplateStringsArray, ...values: [InterpolatableValu
|
|
|
16
16
|
declare function success(msg: unknown): void;
|
|
17
17
|
declare function success(msg: TemplateStringsArray, ...values: [InterpolatableValue, ...InterpolatableValue[]]): void;
|
|
18
18
|
declare function newLine(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Takes a message and reports it according to the severity that the user wants.
|
|
21
|
+
*
|
|
22
|
+
* - `ignore`: completely no-op
|
|
23
|
+
* - `log`: uses the `INFO` log level
|
|
24
|
+
* - `warn`: uses the `WARN` log level
|
|
25
|
+
* - `throw`: aborts the process, throws the error.
|
|
26
|
+
*
|
|
27
|
+
* Since the logger doesn't have logging level filters yet, these severities
|
|
28
|
+
* mostly just differ by their colors.
|
|
29
|
+
*
|
|
30
|
+
* @throws In addition to throwing when `reportingSeverity === "throw"`, this
|
|
31
|
+
* function also throws if `reportingSeverity` is not one of the above.
|
|
32
|
+
*/
|
|
33
|
+
declare function report(reportingSeverity: ReportingSeverity): typeof success;
|
|
19
34
|
declare const logger: {
|
|
20
|
-
red:
|
|
21
|
-
yellow:
|
|
22
|
-
green:
|
|
23
|
-
bold:
|
|
24
|
-
dim:
|
|
35
|
+
red: (msg: string | number) => string;
|
|
36
|
+
yellow: (msg: string | number) => string;
|
|
37
|
+
green: (msg: string | number) => string;
|
|
38
|
+
bold: (msg: string | number) => string;
|
|
39
|
+
dim: (msg: string | number) => string;
|
|
25
40
|
path: (msg: unknown) => string;
|
|
26
41
|
url: (msg: unknown) => string;
|
|
27
42
|
name: (msg: unknown) => string;
|
|
@@ -33,6 +48,7 @@ declare const logger: {
|
|
|
33
48
|
warn: typeof warn;
|
|
34
49
|
error: typeof error;
|
|
35
50
|
success: typeof success;
|
|
51
|
+
report: typeof report;
|
|
36
52
|
newLine: typeof newLine;
|
|
37
53
|
};
|
|
38
54
|
export = logger;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEzD,aAAK,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AASjE,iBAAS,WAAW,CAClB,IAAI,EAAE,oBAAoB,EAC1B,GAAG,MAAM,EAAE,mBAAmB,EAAE,GAC/B,MAAM,CAkCR;AASD,iBAAS,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;AAClC,iBAAS,IAAI,CACX,GAAG,EAAE,oBAAoB,EACzB,GAAG,MAAM,EAAE,CAAC,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CAAC,GACzD,IAAI,CAAC;AAUR,iBAAS,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;AAClC,iBAAS,IAAI,CACX,GAAG,EAAE,oBAAoB,EACzB,GAAG,MAAM,EAAE,CAAC,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CAAC,GACzD,IAAI,CAAC;AAYR,iBAAS,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;AACnC,iBAAS,KAAK,CACZ,GAAG,EAAE,oBAAoB,EACzB,GAAG,MAAM,EAAE,CAAC,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CAAC,GACzD,IAAI,CAAC;AAYR,iBAAS,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;AACrC,iBAAS,OAAO,CACd,GAAG,EAAE,oBAAoB,EACzB,GAAG,MAAM,EAAE,CAAC,mBAAmB,EAAE,GAAG,mBAAmB,EAAE,CAAC,GACzD,IAAI,CAAC;AAuBR,iBAAS,OAAO,IAAI,IAAI,CAEvB;AAED;;;;;;;;;;;;;GAaG;AACH,iBAAS,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,OAAO,OAAO,CAepE;AAED,QAAA,MAAM,MAAM;eACC,MAAM,GAAG,MAAM,KAAG,MAAM;kBACrB,MAAM,GAAG,MAAM,KAAG,MAAM;iBACzB,MAAM,GAAG,MAAM,KAAG,MAAM;gBACzB,MAAM,GAAG,MAAM,KAAG,MAAM;eACzB,MAAM,GAAG,MAAM,KAAG,MAAM;gBAtKlB,OAAO,KAAG,MAAM;eACjB,OAAO,KAAG,MAAM;gBACf,OAAO,KAAG,MAAM;gBAChB,OAAO,KAAG,MAAM;kBACd,OAAO,KAAG,MAAM;eACnB,OAAO,KAAG,MAAM;;;;;;;;CA+KjC,CAAC;AAIF,SAAS,MAAM,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -72,15 +72,46 @@ function success(msg, ...values) {
|
|
|
72
72
|
? stringify(msg)
|
|
73
73
|
: interpolate(msg, ...values)}`);
|
|
74
74
|
}
|
|
75
|
+
function throwError(msg, ...values) {
|
|
76
|
+
throw new Error(values.length === 0
|
|
77
|
+
? stringify(msg)
|
|
78
|
+
: interpolate(msg, ...values));
|
|
79
|
+
}
|
|
75
80
|
function newLine() {
|
|
76
81
|
console.log();
|
|
77
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Takes a message and reports it according to the severity that the user wants.
|
|
85
|
+
*
|
|
86
|
+
* - `ignore`: completely no-op
|
|
87
|
+
* - `log`: uses the `INFO` log level
|
|
88
|
+
* - `warn`: uses the `WARN` log level
|
|
89
|
+
* - `throw`: aborts the process, throws the error.
|
|
90
|
+
*
|
|
91
|
+
* Since the logger doesn't have logging level filters yet, these severities
|
|
92
|
+
* mostly just differ by their colors.
|
|
93
|
+
*
|
|
94
|
+
* @throws In addition to throwing when `reportingSeverity === "throw"`, this
|
|
95
|
+
* function also throws if `reportingSeverity` is not one of the above.
|
|
96
|
+
*/
|
|
97
|
+
function report(reportingSeverity) {
|
|
98
|
+
const reportingMethods = {
|
|
99
|
+
ignore: () => { },
|
|
100
|
+
log: info,
|
|
101
|
+
warn,
|
|
102
|
+
throw: throwError,
|
|
103
|
+
};
|
|
104
|
+
if (!Object.prototype.hasOwnProperty.call(reportingMethods, reportingSeverity)) {
|
|
105
|
+
throw new Error(`Unexpected "reportingSeverity" value: ${reportingSeverity}.`);
|
|
106
|
+
}
|
|
107
|
+
return reportingMethods[reportingSeverity];
|
|
108
|
+
}
|
|
78
109
|
const logger = {
|
|
79
|
-
red: chalk_1.default.red,
|
|
80
|
-
yellow: chalk_1.default.yellow,
|
|
81
|
-
green: chalk_1.default.green,
|
|
82
|
-
bold: chalk_1.default.bold,
|
|
83
|
-
dim: chalk_1.default.dim,
|
|
110
|
+
red: (msg) => chalk_1.default.red(msg),
|
|
111
|
+
yellow: (msg) => chalk_1.default.yellow(msg),
|
|
112
|
+
green: (msg) => chalk_1.default.green(msg),
|
|
113
|
+
bold: (msg) => chalk_1.default.bold(msg),
|
|
114
|
+
dim: (msg) => chalk_1.default.dim(msg),
|
|
84
115
|
path,
|
|
85
116
|
url,
|
|
86
117
|
name,
|
|
@@ -92,6 +123,7 @@ const logger = {
|
|
|
92
123
|
warn,
|
|
93
124
|
error,
|
|
94
125
|
success,
|
|
126
|
+
report,
|
|
95
127
|
newLine,
|
|
96
128
|
};
|
|
97
129
|
module.exports = logger;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,0DAA0B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,0DAA0B;AAK1B,MAAM,IAAI,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,eAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChF,MAAM,GAAG,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,eAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;AAChE,MAAM,IAAI,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5D,MAAM,IAAI,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,eAAK,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACxE,MAAM,MAAM,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzD,MAAM,GAAG,GAAG,CAAC,GAAY,EAAU,EAAE,CAAC,eAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAExD,SAAS,WAAW,CAClB,IAA0B,EAC1B,GAAG,MAA6B;IAEhC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1C,GAAG,IAAI,IAAI,CAAC,GAAG,CAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAA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IF,iBAAS,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/logger",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "An encapsulated logger for semantically formatting console messages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/supports-color": "^8.1.1"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "2a9e8f5ec807e49a973fc72326f1ef26092e977e"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import chalk from 'chalk';
|
|
9
|
+
import type {ReportingSeverity} from '@docusaurus/types';
|
|
9
10
|
|
|
10
11
|
type InterpolatableValue = string | number | (string | number)[];
|
|
11
12
|
|
|
@@ -122,17 +123,60 @@ function success(msg: unknown, ...values: InterpolatableValue[]): void {
|
|
|
122
123
|
}`,
|
|
123
124
|
);
|
|
124
125
|
}
|
|
126
|
+
function throwError(msg: unknown): void;
|
|
127
|
+
function throwError(
|
|
128
|
+
msg: TemplateStringsArray,
|
|
129
|
+
...values: [InterpolatableValue, ...InterpolatableValue[]]
|
|
130
|
+
): void;
|
|
131
|
+
function throwError(msg: unknown, ...values: InterpolatableValue[]): void {
|
|
132
|
+
throw new Error(
|
|
133
|
+
values.length === 0
|
|
134
|
+
? stringify(msg)
|
|
135
|
+
: interpolate(msg as TemplateStringsArray, ...values),
|
|
136
|
+
);
|
|
137
|
+
}
|
|
125
138
|
|
|
126
139
|
function newLine(): void {
|
|
127
140
|
console.log();
|
|
128
141
|
}
|
|
129
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Takes a message and reports it according to the severity that the user wants.
|
|
145
|
+
*
|
|
146
|
+
* - `ignore`: completely no-op
|
|
147
|
+
* - `log`: uses the `INFO` log level
|
|
148
|
+
* - `warn`: uses the `WARN` log level
|
|
149
|
+
* - `throw`: aborts the process, throws the error.
|
|
150
|
+
*
|
|
151
|
+
* Since the logger doesn't have logging level filters yet, these severities
|
|
152
|
+
* mostly just differ by their colors.
|
|
153
|
+
*
|
|
154
|
+
* @throws In addition to throwing when `reportingSeverity === "throw"`, this
|
|
155
|
+
* function also throws if `reportingSeverity` is not one of the above.
|
|
156
|
+
*/
|
|
157
|
+
function report(reportingSeverity: ReportingSeverity): typeof success {
|
|
158
|
+
const reportingMethods = {
|
|
159
|
+
ignore: () => {},
|
|
160
|
+
log: info,
|
|
161
|
+
warn,
|
|
162
|
+
throw: throwError,
|
|
163
|
+
};
|
|
164
|
+
if (
|
|
165
|
+
!Object.prototype.hasOwnProperty.call(reportingMethods, reportingSeverity)
|
|
166
|
+
) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`Unexpected "reportingSeverity" value: ${reportingSeverity}.`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return reportingMethods[reportingSeverity];
|
|
172
|
+
}
|
|
173
|
+
|
|
130
174
|
const logger = {
|
|
131
|
-
red: chalk.red,
|
|
132
|
-
yellow: chalk.yellow,
|
|
133
|
-
green: chalk.green,
|
|
134
|
-
bold: chalk.bold,
|
|
135
|
-
dim: chalk.dim,
|
|
175
|
+
red: (msg: string | number): string => chalk.red(msg),
|
|
176
|
+
yellow: (msg: string | number): string => chalk.yellow(msg),
|
|
177
|
+
green: (msg: string | number): string => chalk.green(msg),
|
|
178
|
+
bold: (msg: string | number): string => chalk.bold(msg),
|
|
179
|
+
dim: (msg: string | number): string => chalk.dim(msg),
|
|
136
180
|
path,
|
|
137
181
|
url,
|
|
138
182
|
name,
|
|
@@ -144,6 +188,7 @@ const logger = {
|
|
|
144
188
|
warn,
|
|
145
189
|
error,
|
|
146
190
|
success,
|
|
191
|
+
report,
|
|
147
192
|
newLine,
|
|
148
193
|
};
|
|
149
194
|
|