@parcel/logger 2.8.4-nightly.0 → 2.9.1

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