New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@parcel/logger

Package Overview
Dependencies
Maintainers
1
Versions
914
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/logger - npm Package Compare versions

Comparing version 2.0.0-alpha.3.1 to 2.0.0-beta.1

76

lib/Logger.js

@@ -7,3 +7,4 @@ "use strict";

exports.patchConsole = patchConsole;
exports.PluginLogger = exports.default = void 0;
exports.unpatchConsole = unpatchConsole;
exports.INTERNAL_ORIGINAL_CONSOLE = exports.PluginLogger = exports.default = void 0;

@@ -16,6 +17,2 @@ var _events = require("@parcel/events");

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; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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; }

@@ -66,3 +63,2 @@

error(input, realOrigin) {
// $FlowFixMe origin is undefined on PluginInputDiagnostic
let diagnostic = (0, _diagnostic.anyToDiagnostic)(input);

@@ -72,8 +68,8 @@

diagnostic = Array.isArray(diagnostic) ? diagnostic.map(d => {
return _objectSpread({}, d, {
return { ...d,
origin: realOrigin
});
}) : _objectSpread({}, diagnostic, {
};
}) : { ...diagnostic,
origin: realOrigin
});
};
}

@@ -113,8 +109,8 @@

return Array.isArray(diagnostic) ? diagnostic.map(d => {
return _objectSpread({}, d, {
return { ...d,
origin: this.origin
});
}) : _objectSpread({}, diagnostic, {
};
}) : { ...diagnostic,
origin: this.origin
});
};
}

@@ -139,3 +135,2 @@

error(input) {
// $FlowFixMe it should work, don't really wanna mess with the types of logger.error though...
logger.error(input, this.origin);

@@ -151,15 +146,15 @@ }

exports.PluginLogger = PluginLogger;
let consolePatched = false; // Patch `console` APIs within workers to forward their messages to the Logger
let consolePatched = false;
const INTERNAL_ORIGINAL_CONSOLE = { ...console
}; // Patch `console` APIs within workers to forward their messages to the Logger
// at the appropriate levels.
// TODO: Implement the rest of the console api as needed.
// TODO: Does this need to be disposable/reversible?
exports.INTERNAL_ORIGINAL_CONSOLE = INTERNAL_ORIGINAL_CONSOLE;
function patchConsole() {
if (consolePatched) {
return;
}
// Skip if console is already patched...
if (consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = console.info = (...messages) => {

@@ -190,10 +185,43 @@ logger.info(messagesToDiagnostic(messages));

function unpatchConsole() {
// Skip if console isn't patched...
if (!consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = INTERNAL_ORIGINAL_CONSOLE.log; // $FlowFixMe
console.info = INTERNAL_ORIGINAL_CONSOLE.info; // $FlowFixMe
console.debug = INTERNAL_ORIGINAL_CONSOLE.debug; // $FlowFixMe
console.warn = INTERNAL_ORIGINAL_CONSOLE.warn; // $FlowFixMe
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
/* eslint-enable no-console */
consolePatched = false;
}
function messagesToDiagnostic(messages) {
if (messages.length === 1 && messages[0] instanceof Error) {
let error = messages[0];
return (0, _diagnostic.errorToDiagnostic)(error);
let diagnostic = (0, _diagnostic.errorToDiagnostic)(error);
if (Array.isArray(diagnostic)) {
return diagnostic.map(d => {
return { ...d,
skipFormatting: true
};
});
} else {
return { ...diagnostic,
skipFormatting: true
};
}
} else {
return {
message: joinLogMessages(messages),
origin: 'console'
origin: 'console',
skipFormatting: true
};

@@ -200,0 +228,0 @@ }

{
"name": "@parcel/logger",
"version": "2.0.0-alpha.3.1",
"version": "2.0.0-beta.1",
"description": "Blazing fast, zero configuration web application bundler",

@@ -19,6 +19,6 @@ "license": "MIT",

"dependencies": {
"@parcel/diagnostic": "^2.0.0-alpha.3.1",
"@parcel/events": "^2.0.0-alpha.3.1"
"@parcel/diagnostic": "2.0.0-beta.1",
"@parcel/events": "2.0.0-beta.1"
},
"gitHead": "291f3e6815a1a857a6165fafb1691ceeb878b8f6"
"gitHead": "74335525be92e23bac4ed1bf30595443cfb238e3"
}
// @flow strict-local
import type {IDisposable, LogEvent} from '@parcel/types';
import type {Diagnostic, Diagnostifiable} from '@parcel/diagnostic';
import type {
Diagnostic,
Diagnostifiable,
DiagnosticWithoutOrigin,
} from '@parcel/diagnostic';

@@ -10,7 +14,2 @@ import {ValueEmitter} from '@parcel/events';

export type PluginInputDiagnostic = {|
...Diagnostic,
origin?: string
|};
class Logger {

@@ -27,3 +26,3 @@ #logEmitter = new ValueEmitter<LogEvent>();

level: 'verbose',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});

@@ -40,3 +39,3 @@ }

level: 'info',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});

@@ -49,3 +48,3 @@ }

level: 'warn',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});

@@ -55,3 +54,2 @@ }

error(input: Diagnostifiable, realOrigin?: string): void {
// $FlowFixMe origin is undefined on PluginInputDiagnostic
let diagnostic = anyToDiagnostic(input);

@@ -65,3 +63,3 @@ if (typeof realOrigin === 'string') {

...diagnostic,
origin: realOrigin
origin: realOrigin,
};

@@ -73,3 +71,3 @@ }

level: 'error',
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic]
diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
});

@@ -82,3 +80,3 @@ }

level: 'progress',
message
message,
});

@@ -92,3 +90,3 @@ }

export type PluginLoggerOpts = {|
origin: string
origin: string,
|};

@@ -104,3 +102,3 @@

updateOrigin(
diagnostic: PluginInputDiagnostic | Array<PluginInputDiagnostic>
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): Diagnostic | Array<Diagnostic> {

@@ -115,3 +113,3 @@ return Array.isArray(diagnostic)

verbose(
diagnostic: PluginInputDiagnostic | Array<PluginInputDiagnostic>
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {

@@ -121,11 +119,17 @@ logger.verbose(this.updateOrigin(diagnostic));

info(diagnostic: PluginInputDiagnostic | Array<PluginInputDiagnostic>): void {
info(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.info(this.updateOrigin(diagnostic));
}
log(diagnostic: PluginInputDiagnostic | Array<PluginInputDiagnostic>): void {
log(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.log(this.updateOrigin(diagnostic));
}
warn(diagnostic: PluginInputDiagnostic | Array<PluginInputDiagnostic>): void {
warn(
diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
): void {
logger.warn(this.updateOrigin(diagnostic));

@@ -137,6 +141,5 @@ }

| Diagnostifiable
| PluginInputDiagnostic
| Array<PluginInputDiagnostic>
| DiagnosticWithoutOrigin
| Array<DiagnosticWithoutOrigin>,
): void {
// $FlowFixMe it should work, don't really wanna mess with the types of logger.error though...
logger.error(input, this.origin);

@@ -151,11 +154,9 @@ }

let consolePatched = false;
export const INTERNAL_ORIGINAL_CONSOLE = {...console};
// Patch `console` APIs within workers to forward their messages to the Logger
// at the appropriate levels.
// TODO: Implement the rest of the console api as needed.
// TODO: Does this need to be disposable/reversible?
export function patchConsole() {
if (consolePatched) {
return;
}
// Skip if console is already patched...
if (consolePatched) return;

@@ -188,13 +189,51 @@ /* eslint-disable no-console */

export function unpatchConsole() {
// Skip if console isn't patched...
if (!consolePatched) return;
/* eslint-disable no-console */
// $FlowFixMe
console.log = INTERNAL_ORIGINAL_CONSOLE.log;
// $FlowFixMe
console.info = INTERNAL_ORIGINAL_CONSOLE.info;
// $FlowFixMe
console.debug = INTERNAL_ORIGINAL_CONSOLE.debug;
// $FlowFixMe
console.warn = INTERNAL_ORIGINAL_CONSOLE.warn;
// $FlowFixMe
console.error = INTERNAL_ORIGINAL_CONSOLE.error;
/* eslint-enable no-console */
consolePatched = false;
}
function messagesToDiagnostic(
messages: Array<mixed>
messages: Array<mixed>,
): Diagnostic | Array<Diagnostic> {
if (messages.length === 1 && messages[0] instanceof Error) {
let error: Error = messages[0];
let diagnostic = errorToDiagnostic(error);
return errorToDiagnostic(error);
if (Array.isArray(diagnostic)) {
return diagnostic.map(d => {
return {
...d,
skipFormatting: true,
};
});
} else {
return {
...diagnostic,
skipFormatting: true,
};
}
} else {
return {
message: joinLogMessages(messages),
origin: 'console'
origin: 'console',
skipFormatting: true,
};

@@ -201,0 +240,0 @@ }

@@ -22,3 +22,3 @@ // @flow

message: 'hello',
origin: 'logger'
origin: 'logger',
};

@@ -32,4 +32,4 @@

diagnostics: [diagnostic],
type: 'log'
})
type: 'log',
}),
);

@@ -41,3 +41,3 @@ });

message: 'zomg',
origin: 'logger'
origin: 'logger',
};

@@ -48,3 +48,3 @@

assert(
onLog.calledWith({level: 'warn', diagnostics: [diagnostic], type: 'log'})
onLog.calledWith({level: 'warn', diagnostics: [diagnostic], type: 'log'}),
);

@@ -56,3 +56,3 @@ });

message: 'oh noes',
origin: 'logger'
origin: 'logger',
};

@@ -63,3 +63,7 @@

assert(
onLog.calledWith({level: 'error', diagnostics: [diagnostic], type: 'log'})
onLog.calledWith({
level: 'error',
diagnostics: [diagnostic],
type: 'log',
}),
);

@@ -71,5 +75,5 @@ });

assert(
onLog.calledWith({level: 'progress', message: 'update', type: 'log'})
onLog.calledWith({level: 'progress', message: 'update', type: 'log'}),
);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc