@atlaspack/logger 2.14.14-typescript-b27501580.0 → 2.14.14-typescript-5b4d3ad41.0

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,69 @@
1
+ import type { IDisposable, LogEvent, PluginLogger as IPluginLogger } from '@atlaspack/types';
2
+ import type { Diagnostic, Diagnostifiable, DiagnosticWithoutOrigin } from '@atlaspack/diagnostic';
3
+ import { ValueEmitter } from '@atlaspack/events';
4
+ export { 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 Console: console.ConsoleConstructor;
39
+ readonly assert: (value: any, message?: string, ...optionalParams: any[]) => void;
40
+ readonly clear: () => void;
41
+ readonly count: (label?: string) => void;
42
+ readonly countReset: (label?: string) => void;
43
+ readonly debug: (message?: any, ...optionalParams: any[]) => void;
44
+ readonly dir: (obj: any, options?: import("util").InspectOptions) => void;
45
+ readonly dirxml: (...data: any[]) => void;
46
+ readonly error: (message?: any, ...optionalParams: any[]) => void;
47
+ readonly group: (...label: any[]) => void;
48
+ readonly groupCollapsed: (...label: any[]) => void;
49
+ readonly groupEnd: () => void;
50
+ readonly info: (message?: any, ...optionalParams: any[]) => void;
51
+ readonly log: (message?: any, ...optionalParams: any[]) => void;
52
+ readonly table: (tabularData: any, properties?: readonly string[]) => void;
53
+ readonly time: (label?: string) => void;
54
+ readonly timeEnd: (label?: string) => void;
55
+ readonly timeLog: (label?: string, ...data: any[]) => void;
56
+ readonly trace: (message?: any, ...optionalParams: any[]) => void;
57
+ readonly warn: (message?: any, ...optionalParams: any[]) => void;
58
+ readonly profile: (label?: string) => void;
59
+ readonly profileEnd: (label?: string) => void;
60
+ readonly timeStamp: (label?: string) => void;
61
+ };
62
+ /**
63
+ * Patch `console` APIs within workers to forward their messages to the Logger
64
+ * at the appropriate levels.
65
+ * @private
66
+ */
67
+ export declare function patchConsole(): void;
68
+ /** @private */
69
+ export declare function unpatchConsole(): void;
package/lib/Logger.js ADDED
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.PluginLogger = exports.INTERNAL_ORIGINAL_CONSOLE = void 0;
7
+ Object.defineProperty(exports, "instrument", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _tracer.instrument;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "instrumentAsync", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _tracer.instrumentAsync;
17
+ }
18
+ });
19
+ exports.patchConsole = patchConsole;
20
+ exports.unpatchConsole = unpatchConsole;
21
+ function _events() {
22
+ const data = require("@atlaspack/events");
23
+ _events = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _util() {
29
+ const data = require("util");
30
+ _util = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _diagnostic() {
36
+ const data = require("@atlaspack/diagnostic");
37
+ _diagnostic = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ var _tracer = require("./tracer");
43
+ class Logger {
44
+ logEmitter = new (_events().ValueEmitter)();
45
+ onLog(cb) {
46
+ return this.logEmitter.addListener(cb);
47
+ }
48
+ verbose(diagnostic) {
49
+ this.logEmitter.emit({
50
+ type: 'log',
51
+ level: 'verbose',
52
+ diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
53
+ });
54
+ }
55
+ info(diagnostic) {
56
+ this.log(diagnostic);
57
+ }
58
+ log(diagnostic) {
59
+ this.logEmitter.emit({
60
+ type: 'log',
61
+ level: 'info',
62
+ diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
63
+ });
64
+ }
65
+ warn(diagnostic) {
66
+ this.logEmitter.emit({
67
+ type: 'log',
68
+ level: 'warn',
69
+ diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
70
+ });
71
+ }
72
+ error(input, realOrigin) {
73
+ let diagnostic = (0, _diagnostic().anyToDiagnostic)(input);
74
+ if (typeof realOrigin === 'string') {
75
+ diagnostic = Array.isArray(diagnostic) ? diagnostic.map(d => {
76
+ return {
77
+ ...d,
78
+ origin: realOrigin
79
+ };
80
+ }) : {
81
+ ...diagnostic,
82
+ origin: realOrigin
83
+ };
84
+ }
85
+ this.logEmitter.emit({
86
+ type: 'log',
87
+ level: 'error',
88
+ diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
89
+ });
90
+ }
91
+ progress(message) {
92
+ this.logEmitter.emit({
93
+ type: 'log',
94
+ level: 'progress',
95
+ message
96
+ });
97
+ }
98
+ }
99
+ const logger = new Logger();
100
+ var _default = exports.default = logger;
101
+ /** @private */
102
+ class PluginLogger {
103
+ /** @private */
104
+
105
+ /** @private */
106
+ constructor(opts) {
107
+ this.origin = opts.origin;
108
+ }
109
+
110
+ /** @private */
111
+ updateOrigin(diagnostic) {
112
+ return Array.isArray(diagnostic) ? diagnostic.map(d => {
113
+ return {
114
+ ...d,
115
+ origin: this.origin
116
+ };
117
+ }) : {
118
+ ...diagnostic,
119
+ origin: this.origin
120
+ };
121
+ }
122
+ verbose(diagnostic) {
123
+ logger.verbose(this.updateOrigin(diagnostic));
124
+ }
125
+ info(diagnostic) {
126
+ logger.info(this.updateOrigin(diagnostic));
127
+ }
128
+ log(diagnostic) {
129
+ logger.log(this.updateOrigin(diagnostic));
130
+ }
131
+ warn(diagnostic) {
132
+ logger.warn(this.updateOrigin(diagnostic));
133
+ }
134
+ error(input) {
135
+ logger.error(input, this.origin);
136
+ }
137
+
138
+ /** @private */
139
+ progress(message) {
140
+ logger.progress(message);
141
+ }
142
+ }
143
+
144
+ /** @private */
145
+ exports.PluginLogger = PluginLogger;
146
+ const INTERNAL_ORIGINAL_CONSOLE = exports.INTERNAL_ORIGINAL_CONSOLE = {
147
+ ...console
148
+ };
149
+ let consolePatched = false;
150
+
151
+ /**
152
+ * Patch `console` APIs within workers to forward their messages to the Logger
153
+ * at the appropriate levels.
154
+ * @private
155
+ */
156
+ function patchConsole() {
157
+ // Skip if console is already patched...
158
+ if (consolePatched) return;
159
+
160
+ /* eslint-disable no-console */
161
+ console.log = console.info = (...messages) => {
162
+ logger.info(messagesToDiagnostic(messages));
163
+ };
164
+ console.debug = (...messages) => {
165
+ // TODO: dedicated debug level?
166
+ logger.verbose(messagesToDiagnostic(messages));
167
+ };
168
+ console.warn = (...messages) => {
169
+ logger.warn(messagesToDiagnostic(messages));
170
+ };
171
+ console.error = (...messages) => {
172
+ logger.error(messagesToDiagnostic(messages));
173
+ };
174
+
175
+ /* eslint-enable no-console */
176
+ consolePatched = true;
177
+ }
178
+
179
+ /** @private */
180
+ function unpatchConsole() {
181
+ // Skip if console isn't patched...
182
+ if (!consolePatched) return;
183
+
184
+ /* eslint-disable no-console */
185
+ console.log = INTERNAL_ORIGINAL_CONSOLE.log;
186
+ console.info = INTERNAL_ORIGINAL_CONSOLE.info;
187
+ console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
188
+ console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
189
+ console.error = INTERNAL_ORIGINAL_CONSOLE.error;
190
+
191
+ /* eslint-enable no-console */
192
+ consolePatched = false;
193
+ }
194
+ function messagesToDiagnostic(messages) {
195
+ if (messages.length === 1 && messages[0] instanceof Error) {
196
+ let error = messages[0];
197
+ let diagnostic = (0, _diagnostic().errorToDiagnostic)(error);
198
+ if (Array.isArray(diagnostic)) {
199
+ return diagnostic.map(d => {
200
+ return {
201
+ ...d,
202
+ skipFormatting: true
203
+ };
204
+ });
205
+ } else {
206
+ return {
207
+ ...diagnostic,
208
+ skipFormatting: true
209
+ };
210
+ }
211
+ } else {
212
+ return {
213
+ message: joinLogMessages(messages),
214
+ origin: 'console',
215
+ skipFormatting: true
216
+ };
217
+ }
218
+ }
219
+ function joinLogMessages(messages) {
220
+ return messages.map(m => typeof m === 'string' ? m : (0, _util().inspect)(m)).join(' ');
221
+ }
@@ -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/lib/tracer.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.instrument = instrument;
7
+ exports.instrumentAsync = instrumentAsync;
8
+ exports.tracer = void 0;
9
+ function _rust() {
10
+ const data = require("@atlaspack/rust");
11
+ _rust = function () {
12
+ return data;
13
+ };
14
+ return data;
15
+ }
16
+ const tracer = exports.tracer = new (_rust().AtlaspackTracer)();
17
+ function instrument(label, fn) {
18
+ const span = tracer.enter(label);
19
+ try {
20
+ const result = fn();
21
+ return result;
22
+ } finally {
23
+ tracer.exit(span);
24
+ }
25
+ }
26
+ async function instrumentAsync(label, fn) {
27
+ const span = tracer.enter(label);
28
+ let result;
29
+ try {
30
+ result = await fn();
31
+ } finally {
32
+ tracer.exit(span);
33
+ }
34
+ return result;
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/logger",
3
- "version": "2.14.14-typescript-b27501580.0",
3
+ "version": "2.14.14-typescript-5b4d3ad41.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -17,13 +17,13 @@
17
17
  "node": ">= 16.0.0"
18
18
  },
19
19
  "dependencies": {
20
- "@atlaspack/diagnostic": "2.14.2-typescript-b27501580.0",
21
- "@atlaspack/events": "2.14.2-typescript-b27501580.0",
22
- "@atlaspack/rust": "3.4.2-typescript-b27501580.0"
20
+ "@atlaspack/diagnostic": "2.14.2-typescript-5b4d3ad41.0",
21
+ "@atlaspack/events": "2.14.2-typescript-5b4d3ad41.0",
22
+ "@atlaspack/rust": "3.4.2-typescript-5b4d3ad41.0"
23
23
  },
24
24
  "type": "commonjs",
25
25
  "scripts": {
26
26
  "check-ts": "tsc --emitDeclarationOnly --rootDir src"
27
27
  },
28
- "gitHead": "b275015805a058452afb6fb48c078ecd4de925f2"
28
+ "gitHead": "5b4d3ad41ffa002b989ba77271bb3010a1f05b2a"
29
29
  }