@parcel/logger 2.0.0-nightly.92 → 2.0.0-nightly.926
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/Logger.js +73 -47
- package/package.json +9 -5
- package/src/Logger.js +23 -9
- package/test/Logger.test.js +1 -1
package/lib/Logger.js
CHANGED
@@ -7,34 +7,47 @@ exports.patchConsole = patchConsole;
|
|
7
7
|
exports.unpatchConsole = unpatchConsole;
|
8
8
|
exports.INTERNAL_ORIGINAL_CONSOLE = exports.PluginLogger = exports.default = void 0;
|
9
9
|
|
10
|
-
|
10
|
+
function _events() {
|
11
|
+
const data = require("@parcel/events");
|
11
12
|
|
12
|
-
|
13
|
+
_events = function () {
|
14
|
+
return data;
|
15
|
+
};
|
16
|
+
|
17
|
+
return data;
|
18
|
+
}
|
19
|
+
|
20
|
+
function _util() {
|
21
|
+
const data = require("util");
|
13
22
|
|
14
|
-
|
23
|
+
_util = function () {
|
24
|
+
return data;
|
25
|
+
};
|
15
26
|
|
16
|
-
|
27
|
+
return data;
|
28
|
+
}
|
17
29
|
|
18
|
-
function
|
30
|
+
function _diagnostic() {
|
31
|
+
const data = require("@parcel/diagnostic");
|
19
32
|
|
20
|
-
|
33
|
+
_diagnostic = function () {
|
34
|
+
return data;
|
35
|
+
};
|
21
36
|
|
22
|
-
|
37
|
+
return data;
|
38
|
+
}
|
23
39
|
|
24
40
|
class Logger {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
value: new _events.ValueEmitter()
|
29
|
-
});
|
30
|
-
}
|
41
|
+
#logEmitter
|
42
|
+
/*: ValueEmitter<LogEvent> */
|
43
|
+
= new (_events().ValueEmitter)();
|
31
44
|
|
32
45
|
onLog(cb) {
|
33
|
-
return
|
46
|
+
return this.#logEmitter.addListener(cb);
|
34
47
|
}
|
35
48
|
|
36
49
|
verbose(diagnostic) {
|
37
|
-
|
50
|
+
this.#logEmitter.emit({
|
38
51
|
type: 'log',
|
39
52
|
level: 'verbose',
|
40
53
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -46,7 +59,7 @@ class Logger {
|
|
46
59
|
}
|
47
60
|
|
48
61
|
log(diagnostic) {
|
49
|
-
|
62
|
+
this.#logEmitter.emit({
|
50
63
|
type: 'log',
|
51
64
|
level: 'info',
|
52
65
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -54,7 +67,7 @@ class Logger {
|
|
54
67
|
}
|
55
68
|
|
56
69
|
warn(diagnostic) {
|
57
|
-
|
70
|
+
this.#logEmitter.emit({
|
58
71
|
type: 'log',
|
59
72
|
level: 'warn',
|
60
73
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -62,20 +75,19 @@ class Logger {
|
|
62
75
|
}
|
63
76
|
|
64
77
|
error(input, realOrigin) {
|
65
|
-
|
66
|
-
let diagnostic = (0, _diagnostic.anyToDiagnostic)(input);
|
78
|
+
let diagnostic = (0, _diagnostic().anyToDiagnostic)(input);
|
67
79
|
|
68
80
|
if (typeof realOrigin === 'string') {
|
69
81
|
diagnostic = Array.isArray(diagnostic) ? diagnostic.map(d => {
|
70
|
-
return
|
82
|
+
return { ...d,
|
71
83
|
origin: realOrigin
|
72
|
-
}
|
73
|
-
}) :
|
84
|
+
};
|
85
|
+
}) : { ...diagnostic,
|
74
86
|
origin: realOrigin
|
75
|
-
}
|
87
|
+
};
|
76
88
|
}
|
77
89
|
|
78
|
-
|
90
|
+
this.#logEmitter.emit({
|
79
91
|
type: 'log',
|
80
92
|
level: 'error',
|
81
93
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -83,7 +95,7 @@ class Logger {
|
|
83
95
|
}
|
84
96
|
|
85
97
|
progress(message) {
|
86
|
-
|
98
|
+
this.#logEmitter.emit({
|
87
99
|
type: 'log',
|
88
100
|
level: 'progress',
|
89
101
|
message
|
@@ -92,27 +104,30 @@ class Logger {
|
|
92
104
|
|
93
105
|
}
|
94
106
|
|
95
|
-
var _logEmitter = new WeakMap();
|
96
|
-
|
97
107
|
const logger = new Logger();
|
98
108
|
var _default = logger;
|
109
|
+
/** @private */
|
110
|
+
|
99
111
|
exports.default = _default;
|
100
112
|
|
101
113
|
class PluginLogger {
|
102
|
-
|
103
|
-
_defineProperty(this, "origin", void 0);
|
114
|
+
/** @private */
|
104
115
|
|
116
|
+
/** @private */
|
117
|
+
constructor(opts) {
|
105
118
|
this.origin = opts.origin;
|
106
119
|
}
|
120
|
+
/** @private */
|
121
|
+
|
107
122
|
|
108
123
|
updateOrigin(diagnostic) {
|
109
124
|
return Array.isArray(diagnostic) ? diagnostic.map(d => {
|
110
|
-
return
|
125
|
+
return { ...d,
|
111
126
|
origin: this.origin
|
112
|
-
}
|
113
|
-
}) :
|
127
|
+
};
|
128
|
+
}) : { ...diagnostic,
|
114
129
|
origin: this.origin
|
115
|
-
}
|
130
|
+
};
|
116
131
|
}
|
117
132
|
|
118
133
|
verbose(diagnostic) {
|
@@ -132,24 +147,29 @@ class PluginLogger {
|
|
132
147
|
}
|
133
148
|
|
134
149
|
error(input) {
|
135
|
-
// $FlowFixMe it should work, don't really wanna mess with the types of logger.error though...
|
136
150
|
logger.error(input, this.origin);
|
137
151
|
}
|
152
|
+
/** @private */
|
153
|
+
|
138
154
|
|
139
155
|
progress(message) {
|
140
156
|
logger.progress(message);
|
141
157
|
}
|
142
158
|
|
143
159
|
}
|
144
|
-
|
145
|
-
exports.PluginLogger = PluginLogger;
|
146
|
-
let consolePatched = false;
|
147
|
-
|
148
|
-
const INTERNAL_ORIGINAL_CONSOLE = _objectSpread({}, console); // Patch `console` APIs within workers to forward their messages to the Logger
|
149
|
-
// at the appropriate levels.
|
160
|
+
/** @private */
|
150
161
|
|
151
162
|
|
163
|
+
exports.PluginLogger = PluginLogger;
|
164
|
+
const INTERNAL_ORIGINAL_CONSOLE = { ...console
|
165
|
+
};
|
152
166
|
exports.INTERNAL_ORIGINAL_CONSOLE = INTERNAL_ORIGINAL_CONSOLE;
|
167
|
+
let consolePatched = false;
|
168
|
+
/**
|
169
|
+
* Patch `console` APIs within workers to forward their messages to the Logger
|
170
|
+
* at the appropriate levels.
|
171
|
+
* @private
|
172
|
+
*/
|
153
173
|
|
154
174
|
function patchConsole() {
|
155
175
|
// Skip if console is already patched...
|
@@ -181,10 +201,14 @@ function patchConsole() {
|
|
181
201
|
|
182
202
|
consolePatched = true;
|
183
203
|
}
|
204
|
+
/** @private */
|
205
|
+
|
184
206
|
|
185
207
|
function unpatchConsole() {
|
186
208
|
// Skip if console isn't patched...
|
187
|
-
if (!consolePatched) return;
|
209
|
+
if (!consolePatched) return;
|
210
|
+
/* eslint-disable no-console */
|
211
|
+
// $FlowFixMe
|
188
212
|
|
189
213
|
console.log = INTERNAL_ORIGINAL_CONSOLE.log; // $FlowFixMe
|
190
214
|
|
@@ -195,24 +219,26 @@ function unpatchConsole() {
|
|
195
219
|
console.warn = INTERNAL_ORIGINAL_CONSOLE.warn; // $FlowFixMe
|
196
220
|
|
197
221
|
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
|
222
|
+
/* eslint-enable no-console */
|
223
|
+
|
198
224
|
consolePatched = false;
|
199
225
|
}
|
200
226
|
|
201
227
|
function messagesToDiagnostic(messages) {
|
202
228
|
if (messages.length === 1 && messages[0] instanceof Error) {
|
203
229
|
let error = messages[0];
|
204
|
-
let diagnostic = (0, _diagnostic.errorToDiagnostic)(error);
|
230
|
+
let diagnostic = (0, _diagnostic().errorToDiagnostic)(error);
|
205
231
|
|
206
232
|
if (Array.isArray(diagnostic)) {
|
207
233
|
return diagnostic.map(d => {
|
208
|
-
return
|
234
|
+
return { ...d,
|
209
235
|
skipFormatting: true
|
210
|
-
}
|
236
|
+
};
|
211
237
|
});
|
212
238
|
} else {
|
213
|
-
return
|
239
|
+
return { ...diagnostic,
|
214
240
|
skipFormatting: true
|
215
|
-
}
|
241
|
+
};
|
216
242
|
}
|
217
243
|
} else {
|
218
244
|
return {
|
@@ -224,5 +250,5 @@ function messagesToDiagnostic(messages) {
|
|
224
250
|
}
|
225
251
|
|
226
252
|
function joinLogMessages(messages) {
|
227
|
-
return messages.map(m => typeof m === 'string' ? m : (0, _util.inspect)(m)).join(' ');
|
253
|
+
return messages.map(m => typeof m === 'string' ? m : (0, _util().inspect)(m)).join(' ');
|
228
254
|
}
|
package/package.json
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/logger",
|
3
|
-
"version": "2.0.0-nightly.
|
3
|
+
"version": "2.0.0-nightly.926+8cabeae8",
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
5
5
|
"license": "MIT",
|
6
6
|
"publishConfig": {
|
7
7
|
"access": "public"
|
8
8
|
},
|
9
|
+
"funding": {
|
10
|
+
"type": "opencollective",
|
11
|
+
"url": "https://opencollective.com/parcel"
|
12
|
+
},
|
9
13
|
"repository": {
|
10
14
|
"type": "git",
|
11
15
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
@@ -13,11 +17,11 @@
|
|
13
17
|
"main": "lib/Logger.js",
|
14
18
|
"source": "src/Logger.js",
|
15
19
|
"engines": {
|
16
|
-
"node": ">=
|
20
|
+
"node": ">= 12.0.0"
|
17
21
|
},
|
18
22
|
"dependencies": {
|
19
|
-
"@parcel/diagnostic": "2.0.0-nightly.
|
20
|
-
"@parcel/events": "2.0.0-nightly.
|
23
|
+
"@parcel/diagnostic": "2.0.0-nightly.926+8cabeae8",
|
24
|
+
"@parcel/events": "2.0.0-nightly.926+8cabeae8"
|
21
25
|
},
|
22
|
-
"gitHead": "
|
26
|
+
"gitHead": "8cabeae83ca838134a003a52be468328e15d19ed"
|
23
27
|
}
|
package/src/Logger.js
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
// @flow strict-local
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type {
|
4
|
+
IDisposable,
|
5
|
+
LogEvent,
|
6
|
+
PluginLogger as IPluginLogger,
|
7
|
+
} from '@parcel/types';
|
4
8
|
import type {
|
5
9
|
Diagnostic,
|
6
10
|
Diagnostifiable,
|
@@ -12,7 +16,7 @@ import {inspect} from 'util';
|
|
12
16
|
import {errorToDiagnostic, anyToDiagnostic} from '@parcel/diagnostic';
|
13
17
|
|
14
18
|
class Logger {
|
15
|
-
#logEmitter = new ValueEmitter
|
19
|
+
#logEmitter /*: ValueEmitter<LogEvent> */ = new ValueEmitter();
|
16
20
|
|
17
21
|
onLog(cb: (event: LogEvent) => mixed): IDisposable {
|
18
22
|
return this.#logEmitter.addListener(cb);
|
@@ -47,7 +51,6 @@ class Logger {
|
|
47
51
|
}
|
48
52
|
|
49
53
|
error(input: Diagnostifiable, realOrigin?: string): void {
|
50
|
-
// $FlowFixMe origin is undefined on PluginInputDiagnostic
|
51
54
|
let diagnostic = anyToDiagnostic(input);
|
52
55
|
if (typeof realOrigin === 'string') {
|
53
56
|
diagnostic = Array.isArray(diagnostic)
|
@@ -76,20 +79,24 @@ class Logger {
|
|
76
79
|
}
|
77
80
|
}
|
78
81
|
|
79
|
-
const logger = new Logger();
|
82
|
+
const logger: Logger = new Logger();
|
80
83
|
export default logger;
|
81
84
|
|
85
|
+
/** @private */
|
82
86
|
export type PluginLoggerOpts = {|
|
83
87
|
origin: string,
|
84
88
|
|};
|
85
89
|
|
86
|
-
export class PluginLogger {
|
90
|
+
export class PluginLogger implements IPluginLogger {
|
91
|
+
/** @private */
|
87
92
|
origin: string;
|
88
93
|
|
94
|
+
/** @private */
|
89
95
|
constructor(opts: PluginLoggerOpts) {
|
90
96
|
this.origin = opts.origin;
|
91
97
|
}
|
92
98
|
|
99
|
+
/** @private */
|
93
100
|
updateOrigin(
|
94
101
|
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
|
95
102
|
): Diagnostic | Array<Diagnostic> {
|
@@ -130,20 +137,24 @@ export class PluginLogger {
|
|
130
137
|
| DiagnosticWithoutOrigin
|
131
138
|
| Array<DiagnosticWithoutOrigin>,
|
132
139
|
): void {
|
133
|
-
// $FlowFixMe it should work, don't really wanna mess with the types of logger.error though...
|
134
140
|
logger.error(input, this.origin);
|
135
141
|
}
|
136
142
|
|
143
|
+
/** @private */
|
137
144
|
progress(message: string): void {
|
138
145
|
logger.progress(message);
|
139
146
|
}
|
140
147
|
}
|
141
148
|
|
142
|
-
|
149
|
+
/** @private */
|
143
150
|
export const INTERNAL_ORIGINAL_CONSOLE = {...console};
|
151
|
+
let consolePatched = false;
|
144
152
|
|
145
|
-
|
146
|
-
|
153
|
+
/**
|
154
|
+
* Patch `console` APIs within workers to forward their messages to the Logger
|
155
|
+
* at the appropriate levels.
|
156
|
+
* @private
|
157
|
+
*/
|
147
158
|
export function patchConsole() {
|
148
159
|
// Skip if console is already patched...
|
149
160
|
if (consolePatched) return;
|
@@ -174,10 +185,12 @@ export function patchConsole() {
|
|
174
185
|
consolePatched = true;
|
175
186
|
}
|
176
187
|
|
188
|
+
/** @private */
|
177
189
|
export function unpatchConsole() {
|
178
190
|
// Skip if console isn't patched...
|
179
191
|
if (!consolePatched) return;
|
180
192
|
|
193
|
+
/* eslint-disable no-console */
|
181
194
|
// $FlowFixMe
|
182
195
|
console.log = INTERNAL_ORIGINAL_CONSOLE.log;
|
183
196
|
|
@@ -193,6 +206,7 @@ export function unpatchConsole() {
|
|
193
206
|
// $FlowFixMe
|
194
207
|
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
|
195
208
|
|
209
|
+
/* eslint-enable no-console */
|
196
210
|
consolePatched = false;
|
197
211
|
}
|
198
212
|
|
package/test/Logger.test.js
CHANGED