@parcel/logger
Advanced tools
Comparing version 1.11.0 to 2.0.0-alpha.1
{ | ||
"name": "@parcel/logger", | ||
"version": "1.11.0", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Blazing fast, zero configuration web application bundler", | ||
"main": "index.js", | ||
"main": "lib/Logger.js", | ||
"license": "MIT", | ||
@@ -12,3 +12,3 @@ "repository": { | ||
"engines": { | ||
"node": ">= 6.0.0" | ||
"node": ">= 8.0.0" | ||
}, | ||
@@ -19,22 +19,8 @@ "publishConfig": { | ||
"scripts": { | ||
"test": "cross-env NODE_ENV=test mocha", | ||
"test-ci": "yarn build && yarn test", | ||
"format": "prettier --write \"./{src,bin,test}/**/*.{js,json,md}\"", | ||
"lint": "eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different", | ||
"build": "babel src -d lib", | ||
"prepublish": "yarn build" | ||
"test-ci": "yarn test" | ||
}, | ||
"dependencies": { | ||
"@parcel/workers": "^1.11.0", | ||
"chalk": "^2.1.0", | ||
"grapheme-breaker": "^0.3.2", | ||
"ora": "^2.1.0", | ||
"strip-ansi": "^4.0.0" | ||
"@parcel/events": "^2.0.0-alpha.1" | ||
}, | ||
"devDependencies": { | ||
"@parcel/babel-register": "^1.11.0", | ||
"mocha": "^5.2.0", | ||
"sinon": "^5.0.1" | ||
}, | ||
"gitHead": "34eb91e8e6991073e594bff731c333d09b0403b5" | ||
} | ||
"gitHead": "11d21d56b97f1b6ae3cd3671ccbb39adf80c438f" | ||
} |
@@ -1,248 +0,102 @@ | ||
const chalk = require('chalk'); | ||
const readline = require('readline'); | ||
const prettyError = require('./prettyError'); | ||
const emoji = require('./emoji'); | ||
const {countBreaks} = require('grapheme-breaker'); | ||
const stripAnsi = require('strip-ansi'); | ||
const ora = require('ora'); | ||
const WorkerFarm = require('@parcel/workers'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
// @flow strict-local | ||
class Logger { | ||
constructor(options) { | ||
this.lines = 0; | ||
this.spinner = null; | ||
this.setOptions(options); | ||
} | ||
import type {IDisposable, LogEvent} from '@parcel/types'; | ||
setOptions(options) { | ||
this.logLevel = | ||
options && isNaN(options.logLevel) === false | ||
? Number(options.logLevel) | ||
: 3; | ||
this.color = | ||
options && typeof options.color === 'boolean' | ||
? options.color | ||
: chalk.supportsColor; | ||
this.emoji = (options && options.emoji) || emoji; | ||
this.chalk = new chalk.constructor({enabled: this.color}); | ||
this.isTest = | ||
options && typeof options.isTest === 'boolean' | ||
? options.isTest | ||
: process.env.NODE_ENV === 'test'; | ||
} | ||
import {ValueEmitter} from '@parcel/events'; | ||
import {inspect} from 'util'; | ||
countLines(message) { | ||
return stripAnsi(message) | ||
.split('\n') | ||
.reduce((p, line) => { | ||
if (process.stdout.columns) { | ||
return p + Math.ceil((line.length || 1) / process.stdout.columns); | ||
} | ||
class Logger { | ||
#logEmitter = new ValueEmitter<LogEvent>(); | ||
return p + 1; | ||
}, 0); | ||
onLog(cb: (event: LogEvent) => mixed): IDisposable { | ||
return this.#logEmitter.addListener(cb); | ||
} | ||
writeRaw(message) { | ||
this.stopSpinner(); | ||
this.lines += this.countLines(message) - 1; | ||
process.stdout.write(message); | ||
verbose(message: string): void { | ||
this.#logEmitter.emit({ | ||
type: 'log', | ||
level: 'verbose', | ||
message | ||
}); | ||
} | ||
write(message, persistent = false) { | ||
if (this.logLevel > 3) { | ||
return this.verbose(message); | ||
} | ||
if (!persistent) { | ||
this.lines += this.countLines(message); | ||
} | ||
this.stopSpinner(); | ||
this._log(message); | ||
info(message: string): void { | ||
this.log(message); | ||
} | ||
verbose(message) { | ||
if (this.logLevel < 4) { | ||
return; | ||
} | ||
let currDate = new Date(); | ||
message = `[${currDate.toLocaleTimeString()}]: ${message}`; | ||
if (this.logLevel > 4) { | ||
if (!this.logFile) { | ||
this.logFile = fs.createWriteStream( | ||
path.join(process.cwd(), `parcel-debug-${currDate.toISOString()}.log`) | ||
); | ||
} | ||
this.logFile.write(stripAnsi(message) + '\n'); | ||
} | ||
this._log(message); | ||
log(message: string): void { | ||
this.#logEmitter.emit({ | ||
type: 'log', | ||
level: 'info', | ||
message | ||
}); | ||
} | ||
log(message) { | ||
if (this.logLevel < 3) { | ||
return; | ||
} | ||
this.write(message); | ||
warn(err: Error | string): void { | ||
this.#logEmitter.emit({ | ||
type: 'log', | ||
level: 'warn', | ||
message: err | ||
}); | ||
} | ||
persistent(message) { | ||
if (this.logLevel < 3) { | ||
return; | ||
} | ||
this.write(this.chalk.bold(message), true); | ||
error(err: Error | string): void { | ||
this.#logEmitter.emit({ | ||
type: 'log', | ||
level: 'error', | ||
message: err | ||
}); | ||
} | ||
warn(err) { | ||
if (this.logLevel < 2) { | ||
return; | ||
} | ||
this._writeError(err, this.emoji.warning, this.chalk.yellow); | ||
progress(message: string): void { | ||
this.#logEmitter.emit({ | ||
type: 'log', | ||
level: 'progress', | ||
message | ||
}); | ||
} | ||
} | ||
error(err) { | ||
if (this.logLevel < 1) { | ||
return; | ||
} | ||
const logger = new Logger(); | ||
export default logger; | ||
this._writeError(err, this.emoji.error, this.chalk.red.bold); | ||
} | ||
let consolePatched = false; | ||
success(message) { | ||
this.log(`${this.emoji.success} ${this.chalk.green.bold(message)}`); | ||
// 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; | ||
} | ||
formatError(err, opts) { | ||
return prettyError(err, opts); | ||
} | ||
/* eslint-disable no-console */ | ||
// $FlowFixMe | ||
console.log = console.info = (...messages: Array<mixed>) => { | ||
logger.info(joinLogMessages(messages)); | ||
}; | ||
_writeError(err, emoji, color) { | ||
let {message, stack} = this.formatError(err, {color: this.color}); | ||
this.write(color(`${emoji} ${message}`)); | ||
if (stack) { | ||
this.write(stack); | ||
} | ||
} | ||
// $FlowFixMe | ||
console.debug = (...messages: Array<mixed>) => { | ||
// TODO: dedicated debug level? | ||
logger.verbose(joinLogMessages(messages)); | ||
}; | ||
clear() { | ||
if (!this.color || this.isTest || this.logLevel > 3) { | ||
return; | ||
} | ||
// $FlowFixMe | ||
console.warn = (...messages: Array<mixed>) => { | ||
logger.warn(joinLogMessages(messages)); | ||
}; | ||
while (this.lines > 0) { | ||
readline.clearLine(process.stdout, 0); | ||
readline.moveCursor(process.stdout, 0, -1); | ||
this.lines--; | ||
} | ||
// $FlowFixMe | ||
console.error = (...messages: Array<mixed>) => { | ||
logger.error(joinLogMessages(messages)); | ||
}; | ||
readline.cursorTo(process.stdout, 0); | ||
this.stopSpinner(); | ||
} | ||
progress(message) { | ||
if (this.logLevel < 3) { | ||
return; | ||
} | ||
if (this.logLevel > 3) { | ||
return this.verbose(message); | ||
} | ||
let styledMessage = this.chalk.gray.bold(message); | ||
if (!this.spinner) { | ||
this.spinner = ora({ | ||
text: styledMessage, | ||
stream: process.stdout, | ||
enabled: this.isTest ? false : undefined // fall back to ora default unless we need to explicitly disable it. | ||
}).start(); | ||
} else { | ||
this.spinner.text = styledMessage; | ||
} | ||
} | ||
stopSpinner() { | ||
if (this.spinner) { | ||
this.spinner.stop(); | ||
this.spinner = null; | ||
} | ||
} | ||
handleMessage(options) { | ||
this[options.method](...options.args); | ||
} | ||
_log(message) { | ||
// eslint-disable-next-line no-console | ||
console.log(message); | ||
} | ||
table(columns, table) { | ||
// Measure column widths | ||
let colWidths = []; | ||
for (let row of table) { | ||
let i = 0; | ||
for (let item of row) { | ||
colWidths[i] = Math.max(colWidths[i] || 0, stringWidth(item)); | ||
i++; | ||
} | ||
} | ||
// Render rows | ||
for (let row of table) { | ||
let items = row.map((item, i) => { | ||
// Add padding between columns unless the alignment is the opposite to the | ||
// next column and pad to the column width. | ||
let padding = | ||
!columns[i + 1] || columns[i + 1].align === columns[i].align ? 4 : 0; | ||
return pad(item, colWidths[i] + padding, columns[i].align); | ||
}); | ||
this.log(items.join('')); | ||
} | ||
} | ||
/* eslint-enable no-console */ | ||
consolePatched = true; | ||
} | ||
// Pad a string with spaces on either side | ||
function pad(text, length, align = 'left') { | ||
let pad = ' '.repeat(length - stringWidth(text)); | ||
if (align === 'right') { | ||
return pad + text; | ||
} | ||
return text + pad; | ||
function joinLogMessages(messages: Array<mixed>): string { | ||
return messages.map(m => (typeof m === 'string' ? m : inspect(m))).join(' '); | ||
} | ||
// Count visible characters in a string | ||
function stringWidth(string) { | ||
return countBreaks(stripAnsi('' + string)); | ||
} | ||
// If we are in a worker, make a proxy class which will | ||
// send the logger calls to the main process via IPC. | ||
// These are handled in WorkerFarm and directed to handleMessage above. | ||
if (WorkerFarm.isWorker()) { | ||
class LoggerProxy {} | ||
for (let method of Object.getOwnPropertyNames(Logger.prototype)) { | ||
LoggerProxy.prototype[method] = (...args) => { | ||
WorkerFarm.callMaster( | ||
{ | ||
location: __filename, | ||
method, | ||
args | ||
}, | ||
false | ||
); | ||
}; | ||
} | ||
module.exports = new LoggerProxy(); | ||
} else { | ||
module.exports = new Logger(); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
368305
1
0
0
8
234
2
1
+ Added@parcel/events@2.12.0(transitive)
- Removed@parcel/workers@^1.11.0
- Removedchalk@^2.1.0
- Removedgrapheme-breaker@^0.3.2
- Removedora@^2.1.0
- Removedstrip-ansi@^4.0.0
- Removed@parcel/utils@1.11.0(transitive)
- Removed@parcel/workers@1.11.0(transitive)
- Removedacorn@7.4.1(transitive)
- Removedansi-regex@3.0.1(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedbrfs@1.6.1(transitive)
- Removedbuffer-equal@0.0.1(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcli-cursor@2.1.0(transitive)
- Removedcli-spinners@1.3.1(transitive)
- Removedclone@1.0.4(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removeddefaults@1.0.4(transitive)
- Removedduplexer2@0.1.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedescodegen@1.9.12.1.0(transitive)
- Removedesprima@3.1.34.0.1(transitive)
- Removedestraverse@4.3.05.3.0(transitive)
- Removedesutils@2.0.3(transitive)
- Removedfalafel@2.2.5(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgrapheme-breaker@0.3.2(transitive)
- Removedhas@1.0.4(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedisarray@1.0.02.0.5(transitive)
- Removedlevn@0.3.0(transitive)
- Removedlog-symbols@2.2.0(transitive)
- Removedmagic-string@0.22.5(transitive)
- Removedmerge-source-map@1.0.4(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedobject-inspect@1.4.1(transitive)
- Removedonetime@2.0.1(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedora@2.1.0(transitive)
- Removedpako@0.2.9(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedphysical-cpu-count@2.0.0(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedquote-stream@1.0.2(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedresolve@1.22.8(transitive)
- Removedrestore-cursor@2.0.0(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedshallow-copy@0.0.1(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsource-map@0.5.70.6.1(transitive)
- Removedstatic-eval@2.1.1(transitive)
- Removedstatic-module@2.2.5(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedstrip-ansi@4.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtiny-inflate@1.0.3(transitive)
- Removedtype-check@0.3.2(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedunicode-trie@0.3.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvlq@0.2.3(transitive)
- Removedwcwidth@1.0.1(transitive)
- Removedword-wrap@1.2.5(transitive)
- Removedxtend@4.0.2(transitive)