@atlaspack/logger 2.14.5-canary.38 → 2.14.5-canary.381

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.
@@ -0,0 +1,129 @@
1
+ import type { IDisposable, LogEvent, PluginLogger as IPluginLogger } from '@atlaspack/types-internal';
2
+ import type { Diagnostic, Diagnostifiable, DiagnosticWithoutOrigin } from '@atlaspack/diagnostic';
3
+ import { ValueEmitter } from '@atlaspack/events';
4
+ export { tracer, instrument, instrumentAsync } from './tracer';
5
+ declare class Logger {
6
+ logEmitter: ValueEmitter<LogEvent>;
7
+ onLog(cb: (event: LogEvent) => unknown): IDisposable;
8
+ verbose(diagnostic: Diagnostic | Array<Diagnostic>): void;
9
+ info(diagnostic: Diagnostic | Array<Diagnostic>): void;
10
+ log(diagnostic: Diagnostic | Array<Diagnostic>): void;
11
+ warn(diagnostic: Diagnostic | Array<Diagnostic>): void;
12
+ error(input: Diagnostifiable, realOrigin?: string): void;
13
+ progress(message: string): void;
14
+ }
15
+ declare const logger: Logger;
16
+ export default logger;
17
+ /** @private */
18
+ export type PluginLoggerOpts = {
19
+ origin: string;
20
+ };
21
+ export declare class PluginLogger implements IPluginLogger {
22
+ /** @private */
23
+ origin: string;
24
+ /** @private */
25
+ constructor(opts: PluginLoggerOpts);
26
+ /** @private */
27
+ updateOrigin(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): Diagnostic | Array<Diagnostic>;
28
+ verbose(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
29
+ info(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
30
+ log(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
31
+ warn(diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
32
+ error(input: Diagnostifiable | DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>): void;
33
+ /** @private */
34
+ progress(message: string): void;
35
+ }
36
+ /** @private */
37
+ export declare const INTERNAL_ORIGINAL_CONSOLE: {
38
+ readonly assert: {
39
+ (condition?: boolean, ...data: any[]): void;
40
+ (value: any, message?: string, ...optionalParams: any[]): void;
41
+ };
42
+ readonly clear: {
43
+ (): void;
44
+ (): void;
45
+ };
46
+ readonly count: {
47
+ (label?: string): void;
48
+ (label?: string): void;
49
+ };
50
+ readonly countReset: {
51
+ (label?: string): void;
52
+ (label?: string): void;
53
+ };
54
+ readonly debug: {
55
+ (...data: any[]): void;
56
+ (message?: any, ...optionalParams: any[]): void;
57
+ };
58
+ readonly dir: {
59
+ (item?: any, options?: any): void;
60
+ (obj: any, options?: import("util").InspectOptions): void;
61
+ };
62
+ readonly dirxml: {
63
+ (...data: any[]): void;
64
+ (...data: any[]): void;
65
+ };
66
+ readonly error: {
67
+ (...data: any[]): void;
68
+ (message?: any, ...optionalParams: any[]): void;
69
+ };
70
+ readonly group: {
71
+ (...data: any[]): void;
72
+ (...label: any[]): void;
73
+ };
74
+ readonly groupCollapsed: {
75
+ (...data: any[]): void;
76
+ (...label: any[]): void;
77
+ };
78
+ readonly groupEnd: {
79
+ (): void;
80
+ (): void;
81
+ };
82
+ readonly info: {
83
+ (...data: any[]): void;
84
+ (message?: any, ...optionalParams: any[]): void;
85
+ };
86
+ readonly log: {
87
+ (...data: any[]): void;
88
+ (message?: any, ...optionalParams: any[]): void;
89
+ };
90
+ readonly table: {
91
+ (tabularData?: any, properties?: string[]): void;
92
+ (tabularData: any, properties?: readonly string[]): void;
93
+ };
94
+ readonly time: {
95
+ (label?: string): void;
96
+ (label?: string): void;
97
+ };
98
+ readonly timeEnd: {
99
+ (label?: string): void;
100
+ (label?: string): void;
101
+ };
102
+ readonly timeLog: {
103
+ (label?: string, ...data: any[]): void;
104
+ (label?: string, ...data: any[]): void;
105
+ };
106
+ readonly timeStamp: {
107
+ (label?: string): void;
108
+ (label?: string): void;
109
+ };
110
+ readonly trace: {
111
+ (...data: any[]): void;
112
+ (message?: any, ...optionalParams: any[]): void;
113
+ };
114
+ readonly warn: {
115
+ (...data: any[]): void;
116
+ (message?: any, ...optionalParams: any[]): void;
117
+ };
118
+ readonly Console: console.ConsoleConstructor;
119
+ readonly profile: (label?: string) => void;
120
+ readonly profileEnd: (label?: string) => void;
121
+ };
122
+ /**
123
+ * Patch `console` APIs within workers to forward their messages to the Logger
124
+ * at the appropriate levels.
125
+ * @private
126
+ */
127
+ export declare function patchConsole(): void;
128
+ /** @private */
129
+ export declare function unpatchConsole(): void;
@@ -0,0 +1,4 @@
1
+ import { AtlaspackTracer } from '@atlaspack/rust';
2
+ export declare const tracer: AtlaspackTracer;
3
+ export declare function instrument<T>(label: string, fn: () => T): T;
4
+ export declare function instrumentAsync<T>(label: string, fn: () => Promise<T>): Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/logger",
3
- "version": "2.14.5-canary.38+a1d0dcea5",
3
+ "version": "2.14.5-canary.381+a631dcd96",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -10,22 +10,21 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "lib/Logger.js",
14
- "source": "src/Logger.js",
15
- "exports": {
16
- ".": {
17
- "@atlaspack::sources": "./src/Logger.js",
18
- "default": "./lib/Logger.js"
19
- }
20
- },
13
+ "main": "./lib/Logger.js",
14
+ "source": "./src/Logger.ts",
15
+ "types": "./lib/types/Logger.d.ts",
21
16
  "engines": {
22
17
  "node": ">= 16.0.0"
23
18
  },
24
19
  "dependencies": {
25
- "@atlaspack/diagnostic": "2.14.1-canary.106+a1d0dcea5",
26
- "@atlaspack/events": "2.14.1-canary.106+a1d0dcea5",
27
- "@atlaspack/rust": "3.2.1-canary.38+a1d0dcea5"
20
+ "@atlaspack/diagnostic": "2.14.1-canary.449+a631dcd96",
21
+ "@atlaspack/events": "2.14.1-canary.449+a631dcd96",
22
+ "@atlaspack/rust": "3.2.1-canary.381+a631dcd96",
23
+ "@atlaspack/types-internal": "2.14.1-canary.449+a631dcd96"
28
24
  },
29
25
  "type": "commonjs",
30
- "gitHead": "a1d0dcea5980bde5a3d1907d60359b85eedd8664"
31
- }
26
+ "scripts": {
27
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
28
+ },
29
+ "gitHead": "a631dcd961112db072b0f8de0831efd178f355a7"
30
+ }
@@ -1,10 +1,8 @@
1
- // @flow strict-local
2
-
3
1
  import type {
4
2
  IDisposable,
5
3
  LogEvent,
6
4
  PluginLogger as IPluginLogger,
7
- } from '@atlaspack/types';
5
+ } from '@atlaspack/types-internal';
8
6
  import type {
9
7
  Diagnostic,
10
8
  Diagnostifiable,
@@ -15,17 +13,17 @@ import {ValueEmitter} from '@atlaspack/events';
15
13
  import {inspect} from 'util';
16
14
  import {errorToDiagnostic, anyToDiagnostic} from '@atlaspack/diagnostic';
17
15
 
18
- export {instrument, instrumentAsync} from './tracer';
16
+ export {tracer, instrument, instrumentAsync} from './tracer';
19
17
 
20
18
  class Logger {
21
- #logEmitter /*: ValueEmitter<LogEvent> */ = new ValueEmitter();
19
+ logEmitter: ValueEmitter<LogEvent> = new ValueEmitter();
22
20
 
23
- onLog(cb: (event: LogEvent) => mixed): IDisposable {
24
- return this.#logEmitter.addListener(cb);
21
+ onLog(cb: (event: LogEvent) => unknown): IDisposable {
22
+ return this.logEmitter.addListener(cb);
25
23
  }
26
24
 
27
25
  verbose(diagnostic: Diagnostic | Array<Diagnostic>): void {
28
- this.#logEmitter.emit({
26
+ this.logEmitter.emit({
29
27
  type: 'log',
30
28
  level: 'verbose',
31
29
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
@@ -37,7 +35,7 @@ class Logger {
37
35
  }
38
36
 
39
37
  log(diagnostic: Diagnostic | Array<Diagnostic>): void {
40
- this.#logEmitter.emit({
38
+ this.logEmitter.emit({
41
39
  type: 'log',
42
40
  level: 'info',
43
41
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
@@ -45,7 +43,7 @@ class Logger {
45
43
  }
46
44
 
47
45
  warn(diagnostic: Diagnostic | Array<Diagnostic>): void {
48
- this.#logEmitter.emit({
46
+ this.logEmitter.emit({
49
47
  type: 'log',
50
48
  level: 'warn',
51
49
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
@@ -53,7 +51,7 @@ class Logger {
53
51
  }
54
52
 
55
53
  error(input: Diagnostifiable, realOrigin?: string): void {
56
- let diagnostic = anyToDiagnostic(input);
54
+ let diagnostic = anyToDiagnostic(input) as Diagnostic | Array<Diagnostic>;
57
55
  if (typeof realOrigin === 'string') {
58
56
  diagnostic = Array.isArray(diagnostic)
59
57
  ? diagnostic.map((d) => {
@@ -65,7 +63,7 @@ class Logger {
65
63
  };
66
64
  }
67
65
 
68
- this.#logEmitter.emit({
66
+ this.logEmitter.emit({
69
67
  type: 'log',
70
68
  level: 'error',
71
69
  diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
@@ -73,7 +71,7 @@ class Logger {
73
71
  }
74
72
 
75
73
  progress(message: string): void {
76
- this.#logEmitter.emit({
74
+ this.logEmitter.emit({
77
75
  type: 'log',
78
76
  level: 'progress',
79
77
  message,
@@ -85,9 +83,9 @@ const logger: Logger = new Logger();
85
83
  export default logger;
86
84
 
87
85
  /** @private */
88
- export type PluginLoggerOpts = {|
89
- origin: string,
90
- |};
86
+ export type PluginLoggerOpts = {
87
+ origin: string;
88
+ };
91
89
 
92
90
  export class PluginLogger implements IPluginLogger {
93
91
  /** @private */
@@ -106,7 +104,7 @@ export class PluginLogger implements IPluginLogger {
106
104
  ? diagnostic.map((d) => {
107
105
  return {...d, origin: this.origin};
108
106
  })
109
- : {...diagnostic, origin: this.origin};
107
+ : ({...diagnostic, origin: this.origin} as Diagnostic);
110
108
  }
111
109
 
112
110
  verbose(
@@ -149,7 +147,7 @@ export class PluginLogger implements IPluginLogger {
149
147
  }
150
148
 
151
149
  /** @private */
152
- export const INTERNAL_ORIGINAL_CONSOLE = {...console};
150
+ export const INTERNAL_ORIGINAL_CONSOLE = {...console} as const;
153
151
  let consolePatched = false;
154
152
 
155
153
  /**
@@ -162,24 +160,20 @@ export function patchConsole() {
162
160
  if (consolePatched) return;
163
161
 
164
162
  /* eslint-disable no-console */
165
- // $FlowFixMe
166
- console.log = console.info = (...messages: Array<mixed>) => {
163
+ console.log = console.info = (...messages: Array<unknown>) => {
167
164
  logger.info(messagesToDiagnostic(messages));
168
165
  };
169
166
 
170
- // $FlowFixMe
171
- console.debug = (...messages: Array<mixed>) => {
167
+ console.debug = (...messages: Array<unknown>) => {
172
168
  // TODO: dedicated debug level?
173
169
  logger.verbose(messagesToDiagnostic(messages));
174
170
  };
175
171
 
176
- // $FlowFixMe
177
- console.warn = (...messages: Array<mixed>) => {
172
+ console.warn = (...messages: Array<unknown>) => {
178
173
  logger.warn(messagesToDiagnostic(messages));
179
174
  };
180
175
 
181
- // $FlowFixMe
182
- console.error = (...messages: Array<mixed>) => {
176
+ console.error = (...messages: Array<unknown>) => {
183
177
  logger.error(messagesToDiagnostic(messages));
184
178
  };
185
179
 
@@ -193,19 +187,14 @@ export function unpatchConsole() {
193
187
  if (!consolePatched) return;
194
188
 
195
189
  /* eslint-disable no-console */
196
- // $FlowFixMe
197
190
  console.log = INTERNAL_ORIGINAL_CONSOLE.log;
198
191
 
199
- // $FlowFixMe
200
192
  console.info = INTERNAL_ORIGINAL_CONSOLE.info;
201
193
 
202
- // $FlowFixMe
203
194
  console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
204
195
 
205
- // $FlowFixMe
206
196
  console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
207
197
 
208
- // $FlowFixMe
209
198
  console.error = INTERNAL_ORIGINAL_CONSOLE.error;
210
199
 
211
200
  /* eslint-enable no-console */
@@ -213,11 +202,11 @@ export function unpatchConsole() {
213
202
  }
214
203
 
215
204
  function messagesToDiagnostic(
216
- messages: Array<mixed>,
205
+ messages: Array<unknown>,
217
206
  ): Diagnostic | Array<Diagnostic> {
218
207
  if (messages.length === 1 && messages[0] instanceof Error) {
219
208
  let error: Error = messages[0];
220
- let diagnostic = errorToDiagnostic(error);
209
+ let diagnostic = errorToDiagnostic(error) as Diagnostic | Array<Diagnostic>;
221
210
 
222
211
  if (Array.isArray(diagnostic)) {
223
212
  return diagnostic.map((d) => {
@@ -241,7 +230,7 @@ function messagesToDiagnostic(
241
230
  }
242
231
  }
243
232
 
244
- function joinLogMessages(messages: Array<mixed>): string {
233
+ function joinLogMessages(messages: Array<unknown>): string {
245
234
  return messages
246
235
  .map((m) => (typeof m === 'string' ? m : inspect(m)))
247
236
  .join(' ');
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {AtlaspackTracer} from '@atlaspack/rust';
4
2
 
5
3
  export const tracer: AtlaspackTracer = new AtlaspackTracer();
@@ -1,12 +1,10 @@
1
- // @flow strict-local
2
-
3
1
  import assert from 'assert';
4
2
  import sinon from 'sinon';
5
3
  import Logger from '../src/Logger';
6
4
 
7
5
  describe('Logger', () => {
8
- let onLog;
9
- let logDisposable;
6
+ let onLog: any;
7
+ let logDisposable: any;
10
8
  beforeEach(() => {
11
9
  onLog = sinon.spy();
12
10
  logDisposable = Logger.onLog(onLog);
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../utils/events/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../diagnostic/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../rust/tsconfig.json"
16
+ },
17
+ {
18
+ "path": "../types-internal/tsconfig.json"
19
+ }
20
+ ]
21
+ }