@parcel/logger 2.0.0-nightly.137 → 2.0.0-nightly.1373

Sign up to get free protection for your applications and to get access to all the features.
package/lib/Logger.js CHANGED
@@ -3,216 +3,215 @@
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
- var _events = require("@parcel/events");
11
-
12
- var _util = require("util");
13
-
14
- var _diagnostic = require("@parcel/diagnostic");
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
-
20
- 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; }
21
-
22
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = privateMap.get(receiver); if (!descriptor) { throw new TypeError("attempted to get private field on non-instance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
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
- constructor() {
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 _classPrivateFieldGet(this, _logEmitter).addListener(cb);
33
+ return this.#logEmitter.addListener(cb);
34
34
  }
35
-
36
35
  verbose(diagnostic) {
37
- _classPrivateFieldGet(this, _logEmitter).emit({
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
- _classPrivateFieldGet(this, _logEmitter).emit({
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
- _classPrivateFieldGet(this, _logEmitter).emit({
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
- // $FlowFixMe origin is undefined on PluginInputDiagnostic
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 _objectSpread({}, d, {
63
+ return {
64
+ ...d,
71
65
  origin: realOrigin
72
- });
73
- }) : _objectSpread({}, diagnostic, {
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
- _classPrivateFieldGet(this, _logEmitter).emit({
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
87
  var _default = logger;
88
+ /** @private */
99
89
  exports.default = _default;
100
-
101
90
  class PluginLogger {
102
- constructor(opts) {
103
- _defineProperty(this, "origin", void 0);
91
+ /** @private */
104
92
 
93
+ /** @private */
94
+ constructor(opts) {
105
95
  this.origin = opts.origin;
106
96
  }
107
97
 
98
+ /** @private */
108
99
  updateOrigin(diagnostic) {
109
100
  return Array.isArray(diagnostic) ? diagnostic.map(d => {
110
- return _objectSpread({}, d, {
101
+ return {
102
+ ...d,
111
103
  origin: this.origin
112
- });
113
- }) : _objectSpread({}, diagnostic, {
104
+ };
105
+ }) : {
106
+ ...diagnostic,
114
107
  origin: this.origin
115
- });
108
+ };
116
109
  }
117
-
118
110
  verbose(diagnostic) {
119
111
  logger.verbose(this.updateOrigin(diagnostic));
120
112
  }
121
-
122
113
  info(diagnostic) {
123
114
  logger.info(this.updateOrigin(diagnostic));
124
115
  }
125
-
126
116
  log(diagnostic) {
127
117
  logger.log(this.updateOrigin(diagnostic));
128
118
  }
129
-
130
119
  warn(diagnostic) {
131
120
  logger.warn(this.updateOrigin(diagnostic));
132
121
  }
133
-
134
122
  error(input) {
135
- // $FlowFixMe it should work, don't really wanna mess with the types of logger.error though...
136
123
  logger.error(input, this.origin);
137
124
  }
138
125
 
126
+ /** @private */
139
127
  progress(message) {
140
128
  logger.progress(message);
141
129
  }
142
-
143
130
  }
144
131
 
132
+ /** @private */
145
133
  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.
150
-
151
-
134
+ const INTERNAL_ORIGINAL_CONSOLE = {
135
+ ...console
136
+ };
152
137
  exports.INTERNAL_ORIGINAL_CONSOLE = INTERNAL_ORIGINAL_CONSOLE;
138
+ let consolePatched = false;
153
139
 
140
+ /**
141
+ * Patch `console` APIs within workers to forward their messages to the Logger
142
+ * at the appropriate levels.
143
+ * @private
144
+ */
154
145
  function patchConsole() {
155
146
  // Skip if console is already patched...
156
147
  if (consolePatched) return;
148
+
157
149
  /* eslint-disable no-console */
158
150
  // $FlowFixMe
159
-
160
151
  console.log = console.info = (...messages) => {
161
152
  logger.info(messagesToDiagnostic(messages));
162
- }; // $FlowFixMe
163
-
153
+ };
164
154
 
155
+ // $FlowFixMe
165
156
  console.debug = (...messages) => {
166
157
  // TODO: dedicated debug level?
167
158
  logger.verbose(messagesToDiagnostic(messages));
168
- }; // $FlowFixMe
169
-
159
+ };
170
160
 
161
+ // $FlowFixMe
171
162
  console.warn = (...messages) => {
172
163
  logger.warn(messagesToDiagnostic(messages));
173
- }; // $FlowFixMe
174
-
164
+ };
175
165
 
166
+ // $FlowFixMe
176
167
  console.error = (...messages) => {
177
168
  logger.error(messagesToDiagnostic(messages));
178
169
  };
179
- /* eslint-enable no-console */
180
-
181
170
 
171
+ /* eslint-enable no-console */
182
172
  consolePatched = true;
183
173
  }
184
174
 
175
+ /** @private */
185
176
  function unpatchConsole() {
186
177
  // Skip if console isn't patched...
187
- if (!consolePatched) return; // $FlowFixMe
178
+ if (!consolePatched) return;
188
179
 
189
- console.log = INTERNAL_ORIGINAL_CONSOLE.log; // $FlowFixMe
180
+ /* eslint-disable no-console */
181
+ // $FlowFixMe
182
+ console.log = INTERNAL_ORIGINAL_CONSOLE.log;
190
183
 
191
- console.info = INTERNAL_ORIGINAL_CONSOLE.info; // $FlowFixMe
184
+ // $FlowFixMe
185
+ console.info = INTERNAL_ORIGINAL_CONSOLE.info;
192
186
 
193
- console.debug = INTERNAL_ORIGINAL_CONSOLE.debug; // $FlowFixMe
187
+ // $FlowFixMe
188
+ console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
194
189
 
195
- console.warn = INTERNAL_ORIGINAL_CONSOLE.warn; // $FlowFixMe
190
+ // $FlowFixMe
191
+ console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
196
192
 
193
+ // $FlowFixMe
197
194
  console.error = INTERNAL_ORIGINAL_CONSOLE.error;
195
+
196
+ /* eslint-enable no-console */
198
197
  consolePatched = false;
199
198
  }
200
-
201
199
  function messagesToDiagnostic(messages) {
202
200
  if (messages.length === 1 && messages[0] instanceof Error) {
203
201
  let error = messages[0];
204
- let diagnostic = (0, _diagnostic.errorToDiagnostic)(error);
205
-
202
+ let diagnostic = (0, _diagnostic().errorToDiagnostic)(error);
206
203
  if (Array.isArray(diagnostic)) {
207
204
  return diagnostic.map(d => {
208
- return _objectSpread({}, d, {
205
+ return {
206
+ ...d,
209
207
  skipFormatting: true
210
- });
208
+ };
211
209
  });
212
210
  } else {
213
- return _objectSpread({}, diagnostic, {
211
+ return {
212
+ ...diagnostic,
214
213
  skipFormatting: true
215
- });
214
+ };
216
215
  }
217
216
  } else {
218
217
  return {
@@ -222,7 +221,6 @@ function messagesToDiagnostic(messages) {
222
221
  };
223
222
  }
224
223
  }
225
-
226
224
  function joinLogMessages(messages) {
227
- return messages.map(m => typeof m === 'string' ? m : (0, _util.inspect)(m)).join(' ');
225
+ return messages.map(m => typeof m === 'string' ? m : (0, _util().inspect)(m)).join(' ');
228
226
  }
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@parcel/logger",
3
- "version": "2.0.0-nightly.137+a07a8b84",
3
+ "version": "2.0.0-nightly.1373+6dcba3606",
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": ">= 10.0.0"
20
+ "node": ">= 12.0.0"
17
21
  },
18
22
  "dependencies": {
19
- "@parcel/diagnostic": "2.0.0-nightly.137+a07a8b84",
20
- "@parcel/events": "2.0.0-nightly.137+a07a8b84"
23
+ "@parcel/diagnostic": "2.0.0-nightly.1373+6dcba3606",
24
+ "@parcel/events": "2.0.0-nightly.1373+6dcba3606"
21
25
  },
22
- "gitHead": "a07a8b84923a74077b70a4d2fcbc5a9f17736f3b"
26
+ "gitHead": "6dcba3606107eb02f3008e30678538f81a4fc902"
23
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,
@@ -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<LogEvent>();
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
- let consolePatched = false;
149
+ /** @private */
143
150
  export const INTERNAL_ORIGINAL_CONSOLE = {...console};
151
+ let consolePatched = false;
144
152
 
145
- // Patch `console` APIs within workers to forward their messages to the Logger
146
- // at the appropriate levels.
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
 
@@ -1,4 +1,4 @@
1
- // @flow
1
+ // @flow strict-local
2
2
 
3
3
  import assert from 'assert';
4
4
  import sinon from 'sinon';