@parcel/logger 2.0.0-nightly.151 → 2.0.0-nightly.1511

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,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
- 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
- var _default = logger;
99
- exports.default = _default;
100
-
87
+ var _default = exports.default = logger;
88
+ /** @private */
101
89
  class PluginLogger {
102
- constructor(opts) {
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 _objectSpread({}, d, {
100
+ return {
101
+ ...d,
111
102
  origin: this.origin
112
- });
113
- }) : _objectSpread({}, diagnostic, {
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
- 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
-
152
- exports.INTERNAL_ORIGINAL_CONSOLE = INTERNAL_ORIGINAL_CONSOLE;
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
- }; // $FlowFixMe
163
-
151
+ };
164
152
 
153
+ // $FlowFixMe
165
154
  console.debug = (...messages) => {
166
155
  // TODO: dedicated debug level?
167
156
  logger.verbose(messagesToDiagnostic(messages));
168
- }; // $FlowFixMe
169
-
157
+ };
170
158
 
159
+ // $FlowFixMe
171
160
  console.warn = (...messages) => {
172
161
  logger.warn(messagesToDiagnostic(messages));
173
- }; // $FlowFixMe
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; // $FlowFixMe
176
+ if (!consolePatched) return;
188
177
 
189
- console.log = INTERNAL_ORIGINAL_CONSOLE.log; // $FlowFixMe
178
+ /* eslint-disable no-console */
179
+ // $FlowFixMe
180
+ console.log = INTERNAL_ORIGINAL_CONSOLE.log;
190
181
 
191
- console.info = INTERNAL_ORIGINAL_CONSOLE.info; // $FlowFixMe
182
+ // $FlowFixMe
183
+ console.info = INTERNAL_ORIGINAL_CONSOLE.info;
192
184
 
193
- console.debug = INTERNAL_ORIGINAL_CONSOLE.debug; // $FlowFixMe
185
+ // $FlowFixMe
186
+ console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
194
187
 
195
- console.warn = INTERNAL_ORIGINAL_CONSOLE.warn; // $FlowFixMe
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 _objectSpread({}, d, {
203
+ return {
204
+ ...d,
209
205
  skipFormatting: true
210
- });
206
+ };
211
207
  });
212
208
  } else {
213
- return _objectSpread({}, diagnostic, {
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.151+1af603e1",
3
+ "version": "2.0.0-nightly.1511+2059029ee",
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.151+1af603e1",
20
- "@parcel/events": "2.0.0-nightly.151+1af603e1"
23
+ "@parcel/diagnostic": "2.0.0-nightly.1511+2059029ee",
24
+ "@parcel/events": "2.0.0-nightly.1511+2059029ee"
21
25
  },
22
- "gitHead": "1af603e1cfab014585ded8aec4d3dcdb7e685987"
26
+ "gitHead": "2059029ee91e5f03a273b0954d3e629d7375f986"
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';