@parcel/logger 2.0.0-beta.1 → 2.0.0-nightly.1002
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/lib/Logger.js +58 -29
- package/package.json +9 -5
- package/src/Logger.js +21 -7
- package/test/Logger.test.js +1 -1
package/lib/Logger.js
CHANGED
@@ -3,34 +3,51 @@
|
|
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
|
-
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");
|
22
|
+
|
23
|
+
_util = function () {
|
24
|
+
return data;
|
25
|
+
};
|
13
26
|
|
14
|
-
|
27
|
+
return data;
|
28
|
+
}
|
29
|
+
|
30
|
+
function _diagnostic() {
|
31
|
+
const data = require("@parcel/diagnostic");
|
15
32
|
|
16
|
-
|
33
|
+
_diagnostic = function () {
|
34
|
+
return data;
|
35
|
+
};
|
17
36
|
|
18
|
-
|
37
|
+
return data;
|
38
|
+
}
|
19
39
|
|
20
40
|
class Logger {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
value: new _events.ValueEmitter()
|
25
|
-
});
|
26
|
-
}
|
41
|
+
#logEmitter
|
42
|
+
/*: ValueEmitter<LogEvent> */
|
43
|
+
= new (_events().ValueEmitter)();
|
27
44
|
|
28
45
|
onLog(cb) {
|
29
|
-
return
|
46
|
+
return this.#logEmitter.addListener(cb);
|
30
47
|
}
|
31
48
|
|
32
49
|
verbose(diagnostic) {
|
33
|
-
|
50
|
+
this.#logEmitter.emit({
|
34
51
|
type: 'log',
|
35
52
|
level: 'verbose',
|
36
53
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -42,7 +59,7 @@ class Logger {
|
|
42
59
|
}
|
43
60
|
|
44
61
|
log(diagnostic) {
|
45
|
-
|
62
|
+
this.#logEmitter.emit({
|
46
63
|
type: 'log',
|
47
64
|
level: 'info',
|
48
65
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -50,7 +67,7 @@ class Logger {
|
|
50
67
|
}
|
51
68
|
|
52
69
|
warn(diagnostic) {
|
53
|
-
|
70
|
+
this.#logEmitter.emit({
|
54
71
|
type: 'log',
|
55
72
|
level: 'warn',
|
56
73
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -58,7 +75,7 @@ class Logger {
|
|
58
75
|
}
|
59
76
|
|
60
77
|
error(input, realOrigin) {
|
61
|
-
let diagnostic = (0, _diagnostic.anyToDiagnostic)(input);
|
78
|
+
let diagnostic = (0, _diagnostic().anyToDiagnostic)(input);
|
62
79
|
|
63
80
|
if (typeof realOrigin === 'string') {
|
64
81
|
diagnostic = Array.isArray(diagnostic) ? diagnostic.map(d => {
|
@@ -70,7 +87,7 @@ class Logger {
|
|
70
87
|
};
|
71
88
|
}
|
72
89
|
|
73
|
-
|
90
|
+
this.#logEmitter.emit({
|
74
91
|
type: 'log',
|
75
92
|
level: 'error',
|
76
93
|
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
|
@@ -78,7 +95,7 @@ class Logger {
|
|
78
95
|
}
|
79
96
|
|
80
97
|
progress(message) {
|
81
|
-
|
98
|
+
this.#logEmitter.emit({
|
82
99
|
type: 'log',
|
83
100
|
level: 'progress',
|
84
101
|
message
|
@@ -87,18 +104,21 @@ class Logger {
|
|
87
104
|
|
88
105
|
}
|
89
106
|
|
90
|
-
var _logEmitter = new WeakMap();
|
91
|
-
|
92
107
|
const logger = new Logger();
|
93
108
|
var _default = logger;
|
109
|
+
/** @private */
|
110
|
+
|
94
111
|
exports.default = _default;
|
95
112
|
|
96
113
|
class PluginLogger {
|
97
|
-
|
98
|
-
_defineProperty(this, "origin", void 0);
|
114
|
+
/** @private */
|
99
115
|
|
116
|
+
/** @private */
|
117
|
+
constructor(opts) {
|
100
118
|
this.origin = opts.origin;
|
101
119
|
}
|
120
|
+
/** @private */
|
121
|
+
|
102
122
|
|
103
123
|
updateOrigin(diagnostic) {
|
104
124
|
return Array.isArray(diagnostic) ? diagnostic.map(d => {
|
@@ -129,20 +149,27 @@ class PluginLogger {
|
|
129
149
|
error(input) {
|
130
150
|
logger.error(input, this.origin);
|
131
151
|
}
|
152
|
+
/** @private */
|
153
|
+
|
132
154
|
|
133
155
|
progress(message) {
|
134
156
|
logger.progress(message);
|
135
157
|
}
|
136
158
|
|
137
159
|
}
|
160
|
+
/** @private */
|
161
|
+
|
138
162
|
|
139
163
|
exports.PluginLogger = PluginLogger;
|
140
|
-
let consolePatched = false;
|
141
164
|
const INTERNAL_ORIGINAL_CONSOLE = { ...console
|
142
|
-
};
|
143
|
-
// at the appropriate levels.
|
144
|
-
|
165
|
+
};
|
145
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
|
+
*/
|
146
173
|
|
147
174
|
function patchConsole() {
|
148
175
|
// Skip if console is already patched...
|
@@ -174,6 +201,8 @@ function patchConsole() {
|
|
174
201
|
|
175
202
|
consolePatched = true;
|
176
203
|
}
|
204
|
+
/** @private */
|
205
|
+
|
177
206
|
|
178
207
|
function unpatchConsole() {
|
179
208
|
// Skip if console isn't patched...
|
@@ -198,7 +227,7 @@ function unpatchConsole() {
|
|
198
227
|
function messagesToDiagnostic(messages) {
|
199
228
|
if (messages.length === 1 && messages[0] instanceof Error) {
|
200
229
|
let error = messages[0];
|
201
|
-
let diagnostic = (0, _diagnostic.errorToDiagnostic)(error);
|
230
|
+
let diagnostic = (0, _diagnostic().errorToDiagnostic)(error);
|
202
231
|
|
203
232
|
if (Array.isArray(diagnostic)) {
|
204
233
|
return diagnostic.map(d => {
|
@@ -221,5 +250,5 @@ function messagesToDiagnostic(messages) {
|
|
221
250
|
}
|
222
251
|
|
223
252
|
function joinLogMessages(messages) {
|
224
|
-
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(' ');
|
225
254
|
}
|
package/package.json
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/logger",
|
3
|
-
"version": "2.0.0-
|
3
|
+
"version": "2.0.0-nightly.1002+5530a6ef",
|
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-
|
20
|
-
"@parcel/events": "2.0.0-
|
23
|
+
"@parcel/diagnostic": "2.0.0-nightly.1002+5530a6ef",
|
24
|
+
"@parcel/events": "2.0.0-nightly.1002+5530a6ef"
|
21
25
|
},
|
22
|
-
"gitHead": "
|
26
|
+
"gitHead": "5530a6eff8b619873353baeb0457ae4ec591e9fa"
|
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);
|
@@ -75,20 +79,24 @@ class Logger {
|
|
75
79
|
}
|
76
80
|
}
|
77
81
|
|
78
|
-
const logger = new Logger();
|
82
|
+
const logger: Logger = new Logger();
|
79
83
|
export default logger;
|
80
84
|
|
85
|
+
/** @private */
|
81
86
|
export type PluginLoggerOpts = {|
|
82
87
|
origin: string,
|
83
88
|
|};
|
84
89
|
|
85
|
-
export class PluginLogger {
|
90
|
+
export class PluginLogger implements IPluginLogger {
|
91
|
+
/** @private */
|
86
92
|
origin: string;
|
87
93
|
|
94
|
+
/** @private */
|
88
95
|
constructor(opts: PluginLoggerOpts) {
|
89
96
|
this.origin = opts.origin;
|
90
97
|
}
|
91
98
|
|
99
|
+
/** @private */
|
92
100
|
updateOrigin(
|
93
101
|
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
|
94
102
|
): Diagnostic | Array<Diagnostic> {
|
@@ -132,16 +140,21 @@ export class PluginLogger {
|
|
132
140
|
logger.error(input, this.origin);
|
133
141
|
}
|
134
142
|
|
143
|
+
/** @private */
|
135
144
|
progress(message: string): void {
|
136
145
|
logger.progress(message);
|
137
146
|
}
|
138
147
|
}
|
139
148
|
|
140
|
-
|
149
|
+
/** @private */
|
141
150
|
export const INTERNAL_ORIGINAL_CONSOLE = {...console};
|
151
|
+
let consolePatched = false;
|
142
152
|
|
143
|
-
|
144
|
-
|
153
|
+
/**
|
154
|
+
* Patch `console` APIs within workers to forward their messages to the Logger
|
155
|
+
* at the appropriate levels.
|
156
|
+
* @private
|
157
|
+
*/
|
145
158
|
export function patchConsole() {
|
146
159
|
// Skip if console is already patched...
|
147
160
|
if (consolePatched) return;
|
@@ -172,6 +185,7 @@ export function patchConsole() {
|
|
172
185
|
consolePatched = true;
|
173
186
|
}
|
174
187
|
|
188
|
+
/** @private */
|
175
189
|
export function unpatchConsole() {
|
176
190
|
// Skip if console isn't patched...
|
177
191
|
if (!consolePatched) return;
|
package/test/Logger.test.js
CHANGED