@parcel/logger 2.0.0-beta.3.1 → 2.0.0-dev.1510

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 CHANGED
@@ -3,257 +3,211 @@
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
-
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
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41
-
42
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
43
-
44
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
45
-
46
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
47
-
48
- var _logEmitter = new WeakMap();
49
-
50
30
  class Logger {
51
- constructor() {
52
- _logEmitter.set(this, {
53
- writable: true,
54
- value:
55
- /*: ValueEmitter<LogEvent> */
56
- new (_events().ValueEmitter)()
57
- });
58
- }
59
-
31
+ #logEmitter /*: ValueEmitter<LogEvent> */ = new (_events().ValueEmitter)();
60
32
  onLog(cb) {
61
- return _classPrivateFieldGet(this, _logEmitter).addListener(cb);
33
+ return this.#logEmitter.addListener(cb);
62
34
  }
63
-
64
35
  verbose(diagnostic) {
65
- _classPrivateFieldGet(this, _logEmitter).emit({
36
+ this.#logEmitter.emit({
66
37
  type: 'log',
67
38
  level: 'verbose',
68
39
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
69
40
  });
70
41
  }
71
-
72
42
  info(diagnostic) {
73
43
  this.log(diagnostic);
74
44
  }
75
-
76
45
  log(diagnostic) {
77
- _classPrivateFieldGet(this, _logEmitter).emit({
46
+ this.#logEmitter.emit({
78
47
  type: 'log',
79
48
  level: 'info',
80
49
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
81
50
  });
82
51
  }
83
-
84
52
  warn(diagnostic) {
85
- _classPrivateFieldGet(this, _logEmitter).emit({
53
+ this.#logEmitter.emit({
86
54
  type: 'log',
87
55
  level: 'warn',
88
56
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
89
57
  });
90
58
  }
91
-
92
59
  error(input, realOrigin) {
93
60
  let diagnostic = (0, _diagnostic().anyToDiagnostic)(input);
94
-
95
61
  if (typeof realOrigin === 'string') {
96
62
  diagnostic = Array.isArray(diagnostic) ? diagnostic.map(d => {
97
- return { ...d,
63
+ return {
64
+ ...d,
98
65
  origin: realOrigin
99
66
  };
100
- }) : { ...diagnostic,
67
+ }) : {
68
+ ...diagnostic,
101
69
  origin: realOrigin
102
70
  };
103
71
  }
104
-
105
- _classPrivateFieldGet(this, _logEmitter).emit({
72
+ this.#logEmitter.emit({
106
73
  type: 'log',
107
74
  level: 'error',
108
75
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
109
76
  });
110
77
  }
111
-
112
78
  progress(message) {
113
- _classPrivateFieldGet(this, _logEmitter).emit({
79
+ this.#logEmitter.emit({
114
80
  type: 'log',
115
81
  level: 'progress',
116
82
  message
117
83
  });
118
84
  }
119
-
120
85
  }
121
-
122
86
  const logger = new Logger();
123
- var _default = logger;
87
+ var _default = exports.default = logger;
124
88
  /** @private */
125
-
126
- exports.default = _default;
127
-
128
89
  class PluginLogger {
129
90
  /** @private */
130
91
 
131
92
  /** @private */
132
93
  constructor(opts) {
133
- _defineProperty(this, "origin", void 0);
134
-
135
94
  this.origin = opts.origin;
136
95
  }
137
- /** @private */
138
-
139
96
 
97
+ /** @private */
140
98
  updateOrigin(diagnostic) {
141
99
  return Array.isArray(diagnostic) ? diagnostic.map(d => {
142
- return { ...d,
100
+ return {
101
+ ...d,
143
102
  origin: this.origin
144
103
  };
145
- }) : { ...diagnostic,
104
+ }) : {
105
+ ...diagnostic,
146
106
  origin: this.origin
147
107
  };
148
108
  }
149
-
150
109
  verbose(diagnostic) {
151
110
  logger.verbose(this.updateOrigin(diagnostic));
152
111
  }
153
-
154
112
  info(diagnostic) {
155
113
  logger.info(this.updateOrigin(diagnostic));
156
114
  }
157
-
158
115
  log(diagnostic) {
159
116
  logger.log(this.updateOrigin(diagnostic));
160
117
  }
161
-
162
118
  warn(diagnostic) {
163
119
  logger.warn(this.updateOrigin(diagnostic));
164
120
  }
165
-
166
121
  error(input) {
167
122
  logger.error(input, this.origin);
168
123
  }
169
- /** @private */
170
-
171
124
 
125
+ /** @private */
172
126
  progress(message) {
173
127
  logger.progress(message);
174
128
  }
175
-
176
129
  }
177
- /** @private */
178
-
179
130
 
131
+ /** @private */
180
132
  exports.PluginLogger = PluginLogger;
181
- const INTERNAL_ORIGINAL_CONSOLE = { ...console
133
+ const INTERNAL_ORIGINAL_CONSOLE = exports.INTERNAL_ORIGINAL_CONSOLE = {
134
+ ...console
182
135
  };
183
- exports.INTERNAL_ORIGINAL_CONSOLE = INTERNAL_ORIGINAL_CONSOLE;
184
136
  let consolePatched = false;
137
+
185
138
  /**
186
139
  * Patch `console` APIs within workers to forward their messages to the Logger
187
140
  * at the appropriate levels.
188
141
  * @private
189
142
  */
190
-
191
143
  function patchConsole() {
192
144
  // Skip if console is already patched...
193
145
  if (consolePatched) return;
146
+
194
147
  /* eslint-disable no-console */
195
148
  // $FlowFixMe
196
-
197
149
  console.log = console.info = (...messages) => {
198
150
  logger.info(messagesToDiagnostic(messages));
199
- }; // $FlowFixMe
200
-
151
+ };
201
152
 
153
+ // $FlowFixMe
202
154
  console.debug = (...messages) => {
203
155
  // TODO: dedicated debug level?
204
156
  logger.verbose(messagesToDiagnostic(messages));
205
- }; // $FlowFixMe
206
-
157
+ };
207
158
 
159
+ // $FlowFixMe
208
160
  console.warn = (...messages) => {
209
161
  logger.warn(messagesToDiagnostic(messages));
210
- }; // $FlowFixMe
211
-
162
+ };
212
163
 
164
+ // $FlowFixMe
213
165
  console.error = (...messages) => {
214
166
  logger.error(messagesToDiagnostic(messages));
215
167
  };
216
- /* eslint-enable no-console */
217
-
218
168
 
169
+ /* eslint-enable no-console */
219
170
  consolePatched = true;
220
171
  }
221
- /** @private */
222
-
223
172
 
173
+ /** @private */
224
174
  function unpatchConsole() {
225
175
  // Skip if console isn't patched...
226
176
  if (!consolePatched) return;
177
+
227
178
  /* eslint-disable no-console */
228
179
  // $FlowFixMe
180
+ console.log = INTERNAL_ORIGINAL_CONSOLE.log;
229
181
 
230
- console.log = INTERNAL_ORIGINAL_CONSOLE.log; // $FlowFixMe
231
-
232
- console.info = INTERNAL_ORIGINAL_CONSOLE.info; // $FlowFixMe
182
+ // $FlowFixMe
183
+ console.info = INTERNAL_ORIGINAL_CONSOLE.info;
233
184
 
234
- console.debug = INTERNAL_ORIGINAL_CONSOLE.debug; // $FlowFixMe
185
+ // $FlowFixMe
186
+ console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
235
187
 
236
- console.warn = INTERNAL_ORIGINAL_CONSOLE.warn; // $FlowFixMe
188
+ // $FlowFixMe
189
+ console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
237
190
 
191
+ // $FlowFixMe
238
192
  console.error = INTERNAL_ORIGINAL_CONSOLE.error;
239
- /* eslint-enable no-console */
240
193
 
194
+ /* eslint-enable no-console */
241
195
  consolePatched = false;
242
196
  }
243
-
244
197
  function messagesToDiagnostic(messages) {
245
198
  if (messages.length === 1 && messages[0] instanceof Error) {
246
199
  let error = messages[0];
247
200
  let diagnostic = (0, _diagnostic().errorToDiagnostic)(error);
248
-
249
201
  if (Array.isArray(diagnostic)) {
250
202
  return diagnostic.map(d => {
251
- return { ...d,
203
+ return {
204
+ ...d,
252
205
  skipFormatting: true
253
206
  };
254
207
  });
255
208
  } else {
256
- return { ...diagnostic,
209
+ return {
210
+ ...diagnostic,
257
211
  skipFormatting: true
258
212
  };
259
213
  }
@@ -265,7 +219,6 @@ function messagesToDiagnostic(messages) {
265
219
  };
266
220
  }
267
221
  }
268
-
269
222
  function joinLogMessages(messages) {
270
223
  return messages.map(m => typeof m === 'string' ? m : (0, _util().inspect)(m)).join(' ');
271
224
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/logger",
3
- "version": "2.0.0-beta.3.1",
3
+ "version": "2.0.0-dev.1510+a9bb85adf",
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.0.0-beta.3.1",
24
- "@parcel/events": "2.0.0-beta.3.1"
23
+ "@parcel/diagnostic": "2.0.0-dev.1510+a9bb85adf",
24
+ "@parcel/events": "2.0.0-dev.1510+a9bb85adf"
25
25
  },
26
- "gitHead": "daece49d003ba804bbdaa3a7ed3d6aaf446f166d"
26
+ "gitHead": "a9bb85adf8f3b38631e178b3aacaa30c78696e36"
27
27
  }
package/src/Logger.js CHANGED
@@ -1,6 +1,10 @@
1
1
  // @flow strict-local
2
2
 
3
- import type {IDisposable, LogEvent} from '@parcel/types';
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,
@@ -83,7 +87,7 @@ export type PluginLoggerOpts = {|
83
87
  origin: string,
84
88
  |};
85
89
 
86
- export class PluginLogger {
90
+ export class PluginLogger implements IPluginLogger {
87
91
  /** @private */
88
92
  origin: string;
89
93