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