Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boost

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boost - npm Package Compare versions

Comparing version 0.43.0 to 0.45.0

demos/reporter/index.js

6

lib/ConfigLoader.d.ts

@@ -1,8 +0,7 @@

/// <reference types="debug" />
import { Struct } from 'optimal';
import { ToolInterface } from './Tool';
import { ToolConfig, PackageConfig } from './types';
import { Debugger, ToolConfig, PackageConfig } from './types';
export declare type ConfigPathOrStruct = string | Struct;
export default class ConfigLoader {
debug: debug.IDebugger;
debug: Debugger;
package: PackageConfig;

@@ -13,2 +12,3 @@ parsedFiles: {

tool: ToolInterface;
workspaceRoot: string;
constructor(tool: ToolInterface);

@@ -15,0 +15,0 @@ findConfigInPackageJSON(pkg: PackageConfig): ConfigPathOrStruct | null;

@@ -12,3 +12,3 @@ "use strict";

return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -33,3 +33,4 @@ var chalk_1 = __importDefault(require("chalk"));

this.parsedFiles = {};
this.debug = tool.createDebugger("config-loader");
this.workspaceRoot = '';
this.debug = tool.createDebugger('config-loader');
this.tool = tool;

@@ -40,3 +41,3 @@ }

var config = pkg[camelName];
this.tool.invariant(!!config, "Looking in package.json under \"" + camelName + "\" property", 'Found', 'Not found');
this.debug.invariant(!!config, "Looking in package.json under " + chalk_1.default.yellow(camelName) + " property", 'Found', 'Not found');
if (!config) {

@@ -55,3 +56,3 @@ return null;

});
this.tool.invariant(configPaths.length === 1, "Looking for local config file in order: " + configPaths.join(', '), 'Found', 'Not found');
this.debug.invariant(configPaths.length === 1, "Looking for local config file in order: " + configPaths.map(function (p) { return chalk_1.default.cyan(p); }).join(', '), 'Found', 'Not found');
if (configPaths.length === 1) {

@@ -71,3 +72,3 @@ this.debug('Found %s', path_1.default.basename(configPaths[0]));

}
this.tool.debug('Detecting if in a workspace');
this.debug('Detecting if in a workspace');
var workspaceRoot = '';

@@ -101,10 +102,11 @@ var workspacePackage = {};

if (!workspaceRoot) {
this.tool.debug('No workspace found');
this.debug('No workspace found');
return null;
}
var match = workspacePatterns.some(function (pattern) { return !!root.match(new RegExp(path_1.default.join(workspaceRoot, pattern))); });
this.tool.invariant(match, "Matching patterns: " + workspacePatterns.join(', '), 'Match found', 'Invalid workspace package');
this.debug.invariant(match, "Matching patterns: " + workspacePatterns.map(function (p) { return chalk_1.default.cyan(p); }).join(', '), 'Match found', 'Invalid workspace package');
if (!match) {
return null;
}
this.workspaceRoot = workspaceRoot;
return (this.findConfigInPackageJSON(workspacePackage) ||

@@ -111,0 +113,0 @@ this.findConfigInLocalFiles(workspaceRoot) ||

import Emitter, { EmitterInterface } from './Emitter';
import { TaskInterface } from './Task';
import { ReporterInterface } from './Reporter';
import { ConsoleOptions } from './types';
export interface ConsoleInterface extends EmitterInterface {
options: ConsoleOptions;
reporter: ReporterInterface;
error(message: string, ...args: any[]): void;
exit(message: string | Error | null, code: number): void;
log(message: string, ...args: any[]): void;
start(tasks?: TaskInterface[]): void;
stop(): void;
update(): void;
}
export default class Console<Tr extends ReporterInterface> extends Emitter implements ConsoleInterface {
errors: string[];
interrupted: boolean;
logs: string[];
options: ConsoleOptions;
reporter: Tr;
constructor(reporter: Tr, options?: Partial<ConsoleOptions>);
error(message: string, ...args: any[]): void;
exit(message: string | Error | null, code?: number): void;
log(message: string, ...args: any[]): void;
start(tasks?: TaskInterface[]): void;
stop(): void;
update(): void;
export default class Console extends Emitter {
constructor();
handleFailure: (error: Error) => void;
handleSignal: () => void;
exit(message: string | Error | null, code?: number, force?: boolean): void;
}

@@ -12,106 +12,43 @@ "use strict";

})();
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var chalk_1 = __importDefault(require("chalk"));
var optimal_1 = __importDefault(require("optimal"));
var util_1 = __importDefault(require("util"));
var Emitter_1 = __importDefault(require("./Emitter"));
var ExitError_1 = __importDefault(require("./ExitError"));
var Console = (function (_super) {
__extends(Console, _super);
function Console(reporter, options) {
if (options === void 0) { options = {}; }
function Console() {
var _this = _super.call(this) || this;
_this.errors = [];
_this.interrupted = false;
_this.logs = [];
_this.reporter = reporter;
_this.options = optimal_1.default(options, {
footer: optimal_1.string().empty(),
header: optimal_1.string().empty(),
silent: optimal_1.bool(),
});
if (process.env.NODE_ENV === 'test') {
return _this;
_this.handleFailure = function (error) {
_this.exit(error, 1, true);
};
_this.handleSignal = function () {
_this.exit('Process has been terminated.', 1, true);
};
if (process.env.NODE_ENV !== 'test') {
process
.on('SIGINT', _this.handleSignal)
.on('SIGTERM', _this.handleSignal)
.on('uncaughtException', _this.handleFailure)
.on('unhandledRejection', _this.handleFailure);
}
_this.start();
var signalHandler = function () {
if (_this.interrupted) {
_this.exit('Process has been terminated.');
}
else {
_this.log(chalk_1.default.yellow('Press Ctrl+C again to exit.'));
_this.interrupted = true;
}
};
process
.on('SIGINT', signalHandler)
.on('SIGTERM', signalHandler)
.on('uncaughtException', function (error) {
_this.error(chalk_1.default.yellow('Uncaught exception detected!'));
_this.exit(error);
})
.on('unhandledRejection', function (error) {
_this.error(chalk_1.default.yellow('Unhandled promise rejection detected!'));
_this.exit(error);
});
return _this;
}
Console.prototype.error = function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
this.errors.push(util_1.default.format.apply(util_1.default, [message].concat(args)));
};
Console.prototype.exit = function (message, code) {
Console.prototype.exit = function (message, code, force) {
if (code === void 0) { code = 1; }
var errorCode = code;
if (force === void 0) { force = false; }
var error = null;
if (message !== null) {
var error = message instanceof Error ? message : new ExitError_1.default(message, code);
if (error instanceof ExitError_1.default && typeof error.code === 'number') {
errorCode = error.code;
}
if (this.errors.length === 0) {
this.error(chalk_1.default.red(error.stack || error.message));
}
error = message instanceof Error ? message : new Error(message);
}
this.stop();
(errorCode === 0 ? process.stdout : process.stderr).write(this.reporter.render(errorCode), function () {
process.exitCode = errorCode;
});
};
Console.prototype.log = function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
this.emit('stop', [error, code]);
if (force) {
process.exit(code);
}
this.logs.push(util_1.default.format.apply(util_1.default, [message].concat(args)));
else {
process.exitCode = code;
}
};
Console.prototype.start = function (tasks) {
var _this = this;
if (tasks === void 0) { tasks = []; }
var _a = this, errors = _a.errors, logs = _a.logs;
this.reporter.start(function () { return (__assign({}, _this.options, { errors: errors,
logs: logs,
tasks: tasks })); });
};
Console.prototype.stop = function () {
this.reporter.stop();
};
Console.prototype.update = function () {
this.reporter.update();
};
return Console;
}(Emitter_1.default));
exports.default = Console;

@@ -1,5 +0,5 @@

import Event from './Event';
import { EventArguments, EventListener } from './types';
export declare type EventArguments = any[];
export declare type EventListener = (...args: EventArguments) => false | void;
export interface EmitterInterface {
emit(name: string, args: EventArguments, initialValue?: any): Event;
emit(name: string, args?: EventArguments): this;
off(eventName: string, listener: EventListener): this;

@@ -16,4 +16,3 @@ on(eventName: string, listener: EventListener): this;

createEventName(name: string): string;
emit(name: string, args?: EventArguments, initialValue?: any): Event;
emitCascade(name: string, args?: EventArguments, initialValue?: any): Event;
emit(name: string, args?: EventArguments): this;
getEventNames(): string[];

@@ -20,0 +19,0 @@ getListeners(eventName: string): Set<EventListener>;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
Object.defineProperty(exports, "__esModule", { value: true });
var Event_1 = __importDefault(require("./Event"));
var constants_1 = require("./constants");

@@ -19,37 +15,7 @@ var Emitter = (function () {

};
Emitter.prototype.emit = function (name, args, initialValue) {
Emitter.prototype.emit = function (name, args) {
if (args === void 0) { args = []; }
if (initialValue === void 0) { initialValue = null; }
var event = new Event_1.default(this.createEventName(name), initialValue);
Array.from(this.getListeners(event.name)).some(function (listener) {
listener.apply(void 0, [event].concat(args));
return event.stopped;
});
return event;
Array.from(this.getListeners(this.createEventName(name))).some(function (listener) { return listener.apply(void 0, args) === false; });
return this;
};
Emitter.prototype.emitCascade = function (name, args, initialValue) {
if (args === void 0) { args = []; }
if (initialValue === void 0) { initialValue = null; }
var event = new Event_1.default(this.createEventName(name), initialValue);
var listeners = Array.from(this.getListeners(event.name));
var index = 0;
if (listeners.length === 0) {
return event;
}
function next(nextIndex) {
var nextEventArguments = [];
for (var _i = 1; _i < arguments.length; _i++) {
nextEventArguments[_i - 1] = arguments[_i];
}
index = nextIndex;
var listener = listeners[index];
if (!listener || event.stopped) {
return;
}
event.next = function () { return next.apply(void 0, [index + 1].concat(nextEventArguments)); };
listener.apply(void 0, [event].concat(nextEventArguments));
}
next.apply(void 0, [0].concat(args));
return event;
};
Emitter.prototype.getEventNames = function () {

@@ -56,0 +22,0 @@ return Object.keys(this.listeners);

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var debug_1 = __importDefault(require("debug"));
function enableDebug(namespace) {

@@ -15,3 +19,4 @@ var DEBUG = process.env.DEBUG;

}
debug_1.default.enabled(flag);
}
exports.default = enableDebug;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -6,0 +6,0 @@ var isObject_1 = __importDefault(require("./isObject"));

import ConfigLoader from './ConfigLoader';
import { ConsoleInterface } from './Console';
import Emitter, { EmitterInterface } from './Emitter';
import Event from './Event';
import ExitError from './ExitError';
import Module, { ModuleInterface } from './Module';

@@ -11,5 +9,5 @@ import ModuleLoader from './ModuleLoader';

import Reporter, { ReporterInterface } from './Reporter';
import Routine from './Routine';
import Routine, { RoutineInterface } from './Routine';
import Tool, { ToolInterface } from './Tool';
export { ConfigLoader, ConsoleInterface, Emitter, EmitterInterface, Event, ExitError, Module, ModuleInterface, ModuleLoader, Pipeline, Plugin, PluginInterface, Reporter, ReporterInterface, Routine, Tool, ToolInterface };
export { ConfigLoader, ConsoleInterface, Emitter, EmitterInterface, Module, ModuleInterface, ModuleLoader, Pipeline, Plugin, PluginInterface, Reporter, ReporterInterface, Routine, RoutineInterface, Tool, ToolInterface };
export * from './types';
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -10,6 +10,2 @@ var ConfigLoader_1 = __importDefault(require("./ConfigLoader"));

exports.Emitter = Emitter_1.default;
var Event_1 = __importDefault(require("./Event"));
exports.Event = Event_1.default;
var ExitError_1 = __importDefault(require("./ExitError"));
exports.ExitError = ExitError_1.default;
var Module_1 = __importDefault(require("./Module"));

@@ -16,0 +12,0 @@ exports.Module = Module_1.default;

@@ -1,9 +0,9 @@

/// <reference types="debug" />
import { Struct } from 'optimal';
import { ModuleInterface } from './Module';
import { ToolInterface } from './Tool';
import { Debugger } from './types';
export declare type Constructor<T> = new (...args: any[]) => T;
export default class ModuleLoader<Tm extends ModuleInterface> {
classReference: Constructor<Tm>;
debug: debug.IDebugger;
debug: Debugger;
tool: ToolInterface;

@@ -10,0 +10,0 @@ typeName: string;

@@ -12,3 +12,3 @@ "use strict";

return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -18,2 +18,3 @@ var chalk_1 = __importDefault(require("chalk"));

var upperFirst_1 = __importDefault(require("lodash/upperFirst"));
var pluralize_1 = __importDefault(require("pluralize"));
var formatModuleName_1 = __importDefault(require("./helpers/formatModuleName"));

@@ -28,3 +29,3 @@ var isObject_1 = __importDefault(require("./helpers/isObject"));

this.typeName = typeName;
this.debug('Using alias %s', chalk_1.default.green(typeName));
this.debug('Loading %s', chalk_1.default.green(pluralize_1.default(typeName)));
}

@@ -78,6 +79,6 @@ ModuleLoader.prototype.importModule = function (name, options) {

if (isFilePath) {
this.debug('Found with %s', chalk_1.default.cyan(moduleName));
this.debug('Found with file path %s', chalk_1.default.cyan(moduleName));
}
else {
this.debug('Found with %s', chalk_1.default.yellow(moduleName));
this.debug('Found with module %s', chalk_1.default.yellow(moduleName));
module.name = name;

@@ -84,0 +85,0 @@ module.moduleName = moduleName;

@@ -14,3 +14,3 @@ "use strict";

return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -38,3 +38,3 @@ var Routine_1 = __importDefault(require("./Routine"));

this.context = context;
cli.start(this.subroutines);
cli.emit('start', [this.subroutines]);
return this.serializeSubroutines(initialValue)

@@ -41,0 +41,0 @@ .then(function (result) {

@@ -14,3 +14,3 @@ "use strict";

return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,0 +17,0 @@ var Module_1 = __importDefault(require("./Module"));

/// <reference types="node" />
import { Struct } from 'optimal';
import { ConsoleInterface } from './Console';
import Module, { ModuleInterface } from './Module';
import { TaskInterface } from './Task';
import { ReportLoader } from './types';
export declare const REFRESH_RATE: number;
export declare const CURSOR: string;
export declare const REFRESH_RATE = 100;
export declare const SLOW_THRESHOLD = 10000;
export interface WrappedStream {
(message: string): boolean;
}
export interface ReporterOptions extends Struct {
footer: string;
refreshRate: number;
silent: boolean;
slowThreshold: number;
verbose: 0 | 1 | 2 | 3;
}
export interface ReporterInterface extends ModuleInterface {
render(code: number): string;
start(loader: ReportLoader): this;
stop(): this;
update(): this;
err: WrappedStream;
out: WrappedStream;
}
export default class Reporter<To extends Struct> extends Module<To> implements ReporterInterface {
instance?: NodeJS.Timer;
loader: ReportLoader | null;
indent(length: number): string;
render(code?: number): string;
renderMessage(message: string): string;
renderTask(task: TaskInterface, level?: number, suffix?: string): string[];
renderStatus(task: TaskInterface): string;
start(loader: ReportLoader): this;
stop(): this;
update(): this;
export default class Reporter<T, To extends ReporterOptions> extends Module<To> implements ReporterInterface {
bufferedOutput: string;
bufferedStreams: (() => void)[];
err: WrappedStream;
lastOutputHeight: number;
lines: T[];
options: To;
out: WrappedStream;
renderScheduled: boolean;
renderTimer?: NodeJS.Timer;
restoreCursorOnExit: boolean;
startTime: number;
stopTime: number;
constructor(options?: Partial<To>);
bootstrap(cli: ConsoleInterface): void;
addLine(line: T): this;
clearOutput(): this;
clearLinesOutput(): this;
debounceRender(): this;
displayError(error: Error): void;
displayFinalOutput(error?: Error | null): void;
displayFooter(): void;
flushBufferedOutput(): this;
flushBufferedStreams(): this;
getElapsedTime(start: number, stop: number, highlight?: boolean): string;
handleRender: () => void;
handleBaseStart: () => void;
handleBaseStop: (event: any, error: Error | null) => void;
hideCursor(): this;
indent(length?: number): string;
log(message: string, nl?: number): this;
removeLine(callback: (item: T) => boolean): this;
render(): void;
resetCursor(): this;
showCursor(): this;
wrapStream(stream: NodeJS.WriteStream): WrappedStream;
}

@@ -14,153 +14,195 @@ "use strict";

return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var chalk_1 = __importDefault(require("chalk"));
var figures_1 = __importDefault(require("figures"));
var log_update_1 = __importDefault(require("log-update"));
var optimal_1 = __importDefault(require("optimal"));
var Module_1 = __importDefault(require("./Module"));
var constants_1 = require("./constants");
exports.REFRESH_RATE = 100;
exports.CURSOR = '\x1B[?25h';
exports.SLOW_THRESHOLD = 10000;
var Reporter = (function (_super) {
__extends(Reporter, _super);
function Reporter() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.loader = null;
function Reporter(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options) || this;
_this.bufferedOutput = '';
_this.bufferedStreams = [];
_this.lastOutputHeight = 0;
_this.lines = [];
_this.renderScheduled = false;
_this.restoreCursorOnExit = false;
_this.startTime = 0;
_this.stopTime = 0;
_this.handleRender = function () {
_this.clearLinesOutput();
_this.flushBufferedStreams();
_this.render();
_this.flushBufferedOutput();
_this.renderScheduled = false;
};
_this.handleBaseStart = function () {
_this.startTime = Date.now();
};
_this.handleBaseStop = function (event, error) {
_this.stopTime = Date.now();
_this.displayFinalOutput(error);
};
_this.options = optimal_1.default(options, {
footer: optimal_1.string().empty(),
refreshRate: optimal_1.number(exports.REFRESH_RATE),
silent: optimal_1.bool(),
slowThreshold: optimal_1.number(exports.SLOW_THRESHOLD),
verbose: optimal_1.number(0).between(0, 3, true),
}, {
name: _this.constructor.name,
unknown: true,
});
_this.err = _this.wrapStream(process.stderr);
_this.out = _this.wrapStream(process.stdout);
return _this;
}
Reporter.prototype.indent = function (length) {
return ' '.repeat(length);
Reporter.prototype.bootstrap = function (cli) {
cli.on('start', this.handleBaseStart);
cli.on('stop', this.handleBaseStop);
};
Reporter.prototype.render = function (code) {
var _this = this;
if (code === void 0) { code = 0; }
if (!this.loader) {
return exports.CURSOR;
Reporter.prototype.addLine = function (line) {
this.lines.push(line);
return this;
};
Reporter.prototype.clearOutput = function () {
this.out('\x1Bc');
this.lastOutputHeight = 0;
return this;
};
Reporter.prototype.clearLinesOutput = function () {
this.out('\x1B[1A\x1B[K'.repeat(this.lastOutputHeight));
this.lastOutputHeight = 0;
return this;
};
Reporter.prototype.debounceRender = function () {
if (this.renderScheduled) {
return this;
}
var _a = this.loader(), _b = _a.errors, errors = _b === void 0 ? [] : _b, _c = _a.footer, footer = _c === void 0 ? '' : _c, _d = _a.header, header = _d === void 0 ? '' : _d, _e = _a.logs, logs = _e === void 0 ? [] : _e, _f = _a.silent, silent = _f === void 0 ? false : _f, _g = _a.tasks, tasks = _g === void 0 ? [] : _g;
var output = [];
var verbose = !silent;
if (header && verbose) {
output.push(header);
this.renderScheduled = true;
this.renderTimer = setTimeout(this.handleRender, this.options.refreshRate);
return this;
};
Reporter.prototype.displayError = function (error) {
this.err("\n" + chalk_1.default.red.bold(error.message) + "\n");
if (error.stack) {
var stack = chalk_1.default.gray(error.stack
.split('\n')
.slice(1)
.join('\n'));
this.err("\n" + stack + "\n");
}
if (tasks.length > 0 && verbose) {
tasks.forEach(function (task) {
output.push.apply(output, _this.renderTask(task, 0));
});
this.err('\n');
};
Reporter.prototype.displayFinalOutput = function (error) {
if (this.renderTimer) {
clearTimeout(this.renderTimer);
}
var messages = code === 0 ? logs : errors;
if (messages.length > 0) {
if (messages[0] !== '') {
output.push('');
}
messages.forEach(function (log) {
output.push(_this.renderMessage(log));
});
if (messages[messages.length - 1] !== '') {
output.push('');
}
this.handleRender();
if (error) {
this.displayError(error);
}
if (footer && verbose) {
output.push(footer);
else {
this.displayFooter();
}
output.push(exports.CURSOR);
return output.join('\n').trim();
};
Reporter.prototype.renderMessage = function (message) {
return message;
};
Reporter.prototype.renderTask = function (task, level, suffix) {
var _this = this;
if (level === void 0) { level = 0; }
if (suffix === void 0) { suffix = ''; }
var output = [];
var message = "" + this.indent(level) + this.renderStatus(task) + " " + task.title;
if (task.isSkipped()) {
message += " " + chalk_1.default.yellow('[skipped]');
Reporter.prototype.displayFooter = function () {
var footer = this.options.footer;
var time = this.getElapsedTime(this.startTime, this.stopTime, false);
if (footer) {
this.out(footer + " " + chalk_1.default.gray("(" + time + ")") + "\n");
}
else if (task.hasFailed()) {
message += " " + chalk_1.default.red('[failed]');
else {
this.out(chalk_1.default.gray("Ran in " + time + "\n"));
}
else if (suffix) {
message += " " + suffix;
};
Reporter.prototype.flushBufferedOutput = function () {
var lines = this.bufferedOutput;
if (lines) {
this.out(lines);
this.lastOutputHeight = Math.max(lines.split('\n').length - 1, 0);
}
output.push(message);
if (task.subtasks.length > 0) {
var pendingTask_1 = null;
var runningTask_1 = null;
var failedTask_1 = null;
var passed_1 = 0;
task.subtasks.forEach(function (subTask) {
if (subTask.isPending() && !pendingTask_1) {
pendingTask_1 = subTask;
}
else if (subTask.isRunning() && !runningTask_1) {
runningTask_1 = subTask;
}
else if (subTask.hasFailed() && !failedTask_1) {
failedTask_1 = subTask;
}
else if (subTask.hasPassed() || subTask.isSkipped()) {
passed_1 += 1;
}
this.bufferedOutput = '';
return this;
};
Reporter.prototype.flushBufferedStreams = function () {
this.bufferedStreams.forEach(function (buffer) {
buffer();
});
return this;
};
Reporter.prototype.getElapsedTime = function (start, stop, highlight) {
if (highlight === void 0) { highlight = true; }
var time = stop - start;
var isSlow = time > this.options.slowThreshold;
var elapsed = (time / 1000).toFixed(2) + "s";
return isSlow && highlight ? chalk_1.default.red(elapsed) : elapsed;
};
Reporter.prototype.hideCursor = function () {
var _this = this;
this.out('\x1B[?25l');
if (!this.restoreCursorOnExit) {
this.restoreCursorOnExit = true;
process.on('exit', function () {
_this.showCursor();
});
var activeTask = failedTask_1 || runningTask_1 || pendingTask_1;
var taskSuffix = chalk_1.default.gray("[" + passed_1 + "/" + task.subtasks.length + "]");
if (activeTask && (task.isRunning() || failedTask_1)) {
output.push.apply(output, this.renderTask(activeTask, level + 1, taskSuffix));
}
}
if (task.statusText) {
output.push("" + this.indent(level + 2) + chalk_1.default.gray(task.statusText));
}
if (task.subroutines.length > 0) {
task.subroutines.forEach(function (routine) {
output.push.apply(output, _this.renderTask(routine, level + 1));
});
}
return output;
return this;
};
Reporter.prototype.renderStatus = function (task) {
switch (task.status) {
case constants_1.STATUS_PENDING:
return chalk_1.default.gray(figures_1.default.bullet);
case constants_1.STATUS_RUNNING:
return chalk_1.default.gray(task.spinner());
case constants_1.STATUS_SKIPPED:
return chalk_1.default.yellow(figures_1.default.circleDotted);
case constants_1.STATUS_PASSED:
return chalk_1.default.green(figures_1.default.tick);
case constants_1.STATUS_FAILED:
return chalk_1.default.red(figures_1.default.cross);
default:
return '';
Reporter.prototype.indent = function (length) {
if (length === void 0) { length = 0; }
return ' '.repeat(length);
};
Reporter.prototype.log = function (message, nl) {
if (nl === void 0) { nl = 0; }
if (!this.options.silent) {
this.bufferedOutput += message + '\n'.repeat(nl);
}
return this;
};
Reporter.prototype.start = function (loader) {
Reporter.prototype.removeLine = function (callback) {
this.lines = this.lines.filter(function (line) { return !callback(line); });
return this;
};
Reporter.prototype.render = function () {
var _this = this;
if (this.instance) {
clearInterval(this.instance);
}
if (!loader || typeof loader !== 'function') {
throw new TypeError('A loader is required to render console output.');
}
this.loader = loader;
this.instance = setInterval(function () {
_this.update();
}, exports.REFRESH_RATE);
this.lines.forEach(function (line) {
_this.log(String(line), 1);
});
};
Reporter.prototype.resetCursor = function () {
this.out("\u001B[" + process.stdout.rows + ";0H");
return this;
};
Reporter.prototype.stop = function () {
if (this.instance) {
clearInterval(this.instance);
}
log_update_1.default.clear();
Reporter.prototype.showCursor = function () {
this.out('\x1B[?25h');
return this;
};
Reporter.prototype.update = function () {
var output = this.render();
if (output) {
log_update_1.default(output);
Reporter.prototype.wrapStream = function (stream) {
var originalWrite = stream.write.bind(stream);
if (process.env.NODE_ENV === 'test') {
return originalWrite;
}
return this;
var buffer = '';
var write = function (message) {
if (stream.isTTY) {
originalWrite(message);
}
return true;
};
var flushBuffer = function () {
if (buffer) {
originalWrite(buffer);
}
buffer = '';
};
this.bufferedStreams.push(flushBuffer);
stream.write = function (chunk) {
buffer += String(chunk);
return true;
};
return write;
};

@@ -167,0 +209,0 @@ return Reporter;

@@ -1,4 +0,2 @@

/// <reference types="debug" />
/// <reference types="execa" />
import debug from 'debug';
import { Options as ExecaOptions, SyncOptions as ExecaSyncOptions, ExecaChildProcess, ExecaReturns } from 'execa';

@@ -8,10 +6,16 @@ import { Struct } from 'optimal';

import { ToolInterface } from './Tool';
import { Context } from './types';
import { Debugger, Context } from './types';
export interface CommandOptions extends Struct {
sync?: boolean;
}
export default class Routine<To extends Struct, Tx extends Context> extends Task<To, Tx> {
export interface RoutineInterface extends TaskInterface {
key: string;
subroutines: RoutineInterface[];
tool: ToolInterface;
}
export default class Routine<To extends Struct, Tx extends Context> extends Task<To, Tx> implements RoutineInterface {
exit: boolean;
debug: debug.IDebugger;
debug: Debugger;
key: string;
subroutines: RoutineInterface[];
tool: ToolInterface;

@@ -23,2 +27,3 @@ constructor(key: string, title: string, options?: Partial<To>);

executeCommand(command: string, args: string[], options?: (ExecaOptions | ExecaSyncOptions) & CommandOptions, callback?: ((process: ExecaChildProcess) => void) | null): Promise<ExecaReturns>;
executeSubroutine<T>(task: TaskInterface, value?: T | null): Promise<any>;
executeTask<T>(task: TaskInterface, value?: T | null): Promise<any>;

@@ -25,0 +30,0 @@ parallelizeSubroutines<T>(value?: T | null): Promise<any>;

@@ -14,8 +14,6 @@ "use strict";

return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var chalk_1 = __importDefault(require("chalk"));
var execa_1 = __importDefault(require("execa"));
var split_1 = __importDefault(require("split"));
var ExitError_1 = __importDefault(require("./ExitError"));
var Task_1 = __importDefault(require("./Task"));

@@ -30,2 +28,3 @@ var constants_1 = require("./constants");

_this.key = '';
_this.subroutines = [];
if (!key || typeof key !== 'string') {

@@ -48,3 +47,3 @@ throw new Error('Routine key must be a valid unique string.');

this.debug = this.tool.createDebugger('routine', this.key);
this.debug('Bootstrapping routine %s', chalk_1.default.green(this.key));
this.debug('Bootstrapping routine');
this.bootstrap();

@@ -64,2 +63,3 @@ return this;

: execa_1.default(command, args, options);
this.tool.console.emit('command', [command, this]);
if (!options.sync) {

@@ -70,2 +70,3 @@ var out = stream.stdout;

_this.statusText = line;
_this.tool.console.emit('command.data', [command, line, _this]);
}

@@ -79,10 +80,24 @@ });

};
Routine.prototype.executeTask = function (task, value) {
Routine.prototype.executeSubroutine = function (task, value) {
if (value === void 0) { value = null; }
return this.wrap(task.run(this.context, value));
};
Routine.prototype.executeTask = function (task, value) {
if (value === void 0) { value = null; }
var cli = this.tool.console;
cli.emit('task', [task, value]);
return this.wrap(task.run(this.context, value))
.then(function (result) {
cli.emit('task.pass', [task, result]);
return result;
})
.catch(function (error) {
cli.emit('task.fail', [task, error]);
throw error;
});
};
Routine.prototype.parallelizeSubroutines = function (value) {
var _this = this;
if (value === void 0) { value = null; }
return Promise.all(this.subroutines.map(function (routine) { return _this.executeTask(routine, value); }));
return Promise.all(this.subroutines.map(function (routine) { return _this.executeSubroutine(routine, value); }));
};

@@ -107,12 +122,14 @@ Routine.prototype.parallelizeTasks = function (value) {

if (this.exit) {
return Promise.reject(new ExitError_1.default('Process has been interrupted.'));
return Promise.reject(new Error('Process has been interrupted.'));
}
this.debug('Executing routine %s', chalk_1.default.green(this.key));
this.debug('Executing routine');
var cli = this.tool.console;
cli.emit('routine', [this, value]);
return _super.prototype.run.call(this, context, value)
.then(function (result) {
_this.tool.console.update();
cli.emit('routine.pass', [_this, result]);
return result;
})
.catch(function (error) {
_this.tool.console.update();
cli.emit('routine.fail', [_this, error]);
throw error;

@@ -128,3 +145,5 @@ });

if (value === void 0) { value = null; }
return this.serialize(this.subroutines, value, function (task, val) { return _this.executeTask(task, val); });
return this.serialize(this.subroutines, value, function (task, val) {
return _this.executeSubroutine(task, val);
});
};

@@ -131,0 +150,0 @@ Routine.prototype.serializeTasks = function (value) {

import { Struct } from 'optimal';
import { Context, Status } from './types';
export interface TaskInterface {
startTime: number;
status: Status;
statusText: string;
subroutines: TaskInterface[];
stopTime: number;
subtasks: TaskInterface[];

@@ -16,3 +17,2 @@ title: string;

skip(condition?: boolean): this;
spinner(): string;
}

@@ -26,5 +26,6 @@ export declare type TaskAction<Tx extends Context> = (context: Tx, value: any) => any | Promise<any>;

title: string;
startTime: number;
status: Status;
statusText: string;
subroutines: TaskInterface[];
stopTime: number;
subtasks: TaskInterface[];

@@ -39,4 +40,3 @@ constructor(title: string, action?: TaskAction<Tx> | null, options?: Partial<To>);

skip(condition?: boolean): this;
spinner(): string;
wrap<T>(value: T): Promise<any>;
}

@@ -11,3 +11,2 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var elegant_spinner_1 = require("elegant-spinner");
var constants_1 = require("./constants");

@@ -21,5 +20,6 @@ var Task = (function () {

this.title = '';
this.startTime = 0;
this.status = constants_1.STATUS_PENDING;
this.statusText = '';
this.subroutines = [];
this.stopTime = 0;
this.subtasks = [];

@@ -61,2 +61,3 @@ if (!title || typeof title !== 'string') {

this.status = constants_1.STATUS_RUNNING;
this.startTime = Date.now();
return (Promise.resolve(initialValue)

@@ -66,2 +67,3 @@ .then(function (value) { return _this.action(context, value); })

_this.status = constants_1.STATUS_PASSED;
_this.stopTime = Date.now();
_this.statusText = '';

@@ -71,2 +73,3 @@ return result;

_this.status = constants_1.STATUS_FAILED;
_this.stopTime = Date.now();
throw error;

@@ -82,6 +85,2 @@ }));

};
Task.prototype.spinner = function () {
this.frame = ++this.frame % elegant_spinner_1.frames.length;
return elegant_spinner_1.frames[this.frame];
};
Task.prototype.wrap = function (value) {

@@ -88,0 +87,0 @@ return value instanceof Promise ? value : Promise.resolve(value);

@@ -1,3 +0,2 @@

/// <reference types="debug" />
import debug from 'debug';
import { Blueprint, Struct } from 'optimal';
import { ConsoleInterface } from './Console';

@@ -7,3 +6,14 @@ import Emitter, { EmitterInterface } from './Emitter';

import { ReporterInterface } from './Reporter';
import { ToolConfig, ToolOptions, PackageConfig } from './types';
import { Debugger, ToolConfig, PackageConfig } from './types';
export interface ToolOptions extends Struct {
appName: string;
configBlueprint: Blueprint;
configFolder: string;
extendArgv: string;
footer: string;
pluginAlias: string;
root: string;
scoped: boolean;
workspaceRoot: string;
}
export interface ToolInterface extends EmitterInterface {

@@ -13,18 +23,15 @@ argv: string[];

console: ConsoleInterface;
debug: Debugger;
options: ToolOptions;
package: PackageConfig;
plugins: PluginInterface[];
createDebugger(...namespaces: string[]): debug.IDebugger;
debug(message: string, ...args: any[]): this;
createDebugger(...namespaces: string[]): Debugger;
initialize(): this;
invariant(condition: boolean, message: string, pass: string, fail: string): this;
log(message: string, ...args: any[]): this;
logError(message: string, ...args: any[]): this;
getPlugin(name: string): PluginInterface;
}
export default class Tool<Tp extends PluginInterface, Tr extends ReporterInterface> extends Emitter implements ToolInterface {
export default class Tool<Tp extends PluginInterface> extends Emitter implements ToolInterface {
argv: string[];
config: ToolConfig;
console: ConsoleInterface;
debugger: debug.IDebugger;
debug: Debugger;
initialized: boolean;

@@ -34,14 +41,11 @@ options: ToolOptions;

plugins: Tp[];
constructor({footer, header, ...options}: Partial<ToolOptions>, argv?: string[]);
createDebugger(...namespaces: string[]): debug.IDebugger;
debug(message: string, ...args: any[]): this;
reporter: ReporterInterface | null;
constructor(options: Partial<ToolOptions>, argv?: string[]);
createDebugger(...namespaces: string[]): Debugger;
exit(message: string | Error | null, code?: number): this;
getPlugin(name: string): Tp;
initialize(): this;
invariant(condition: boolean, message: string, pass: string, fail: string): this;
loadConfig(): this;
loadPlugins(): this;
loadReporter(): this;
log(message: string, ...args: any[]): this;
logError(message: string, ...args: any[]): this;
}

@@ -20,14 +20,5 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -44,10 +35,11 @@ var chalk_1 = __importDefault(require("chalk"));

var Reporter_1 = __importDefault(require("./Reporter"));
var DefaultReporter_1 = __importDefault(require("./DefaultReporter"));
var enableDebug_1 = __importDefault(require("./helpers/enableDebug"));
var isEmptyObject_1 = __importDefault(require("./helpers/isEmptyObject"));
var isObject_1 = __importDefault(require("./helpers/isObject"));
var constants_1 = require("./constants");
var Tool = (function (_super) {
__extends(Tool, _super);
function Tool(_a, argv) {
function Tool(options, argv) {
if (argv === void 0) { argv = []; }
var footer = _a.footer, header = _a.header, options = __rest(_a, ["footer", "header"]);
var _this = _super.call(this) || this;

@@ -59,2 +51,3 @@ _this.argv = [];

_this.plugins = [];
_this.reporter = null;
_this.argv = argv;

@@ -66,5 +59,7 @@ _this.options = optimal_1.default(options, {

extendArgv: optimal_1.bool(true),
footer: optimal_1.string().empty(),
pluginAlias: optimal_1.string('plugin'),
root: optimal_1.string(process.cwd()),
scoped: optimal_1.bool(),
workspaceRoot: optimal_1.string().empty(),
}, {

@@ -76,13 +71,9 @@ name: 'Tool',

}
_this.debugger = _this.createDebugger('core');
_this.console = new Console_1.default(new Reporter_1.default(), {
footer: footer,
header: header,
});
if (process.env.NODE_ENV === 'test') {
return _this;
_this.debug = _this.createDebugger('core');
_this.console = new Console_1.default();
if (process.env.NODE_ENV !== 'test') {
process.on('exit', function (code) {
_this.emit('exit', [code]);
});
}
process.on('exit', function (code) {
_this.emit('exit', [code]);
});
return _this;

@@ -95,12 +86,8 @@ }

}
return debug_1.default(this.options.appName + ":" + namespaces.join(':'));
var handler = debug_1.default(this.options.appName + ":" + namespaces.join(':'));
handler.invariant = function (condition, message, pass, fail) {
handler('%s: %s', message, condition ? chalk_1.default.green(pass) : chalk_1.default.red(fail));
};
return handler;
};
Tool.prototype.debug = function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
this.debugger.apply(this, [message].concat(args));
return this;
};
Tool.prototype.exit = function (message, code) {

@@ -113,6 +100,6 @@ if (code === void 0) { code = 1; }

var plugin = this.plugins.find(function (p) { return p.name === name; });
if (!plugin) {
throw new Error("Failed to find " + this.options.pluginAlias + " \"" + name + "\". Have you installed it?");
if (plugin) {
return plugin;
}
return plugin;
throw new Error("Failed to find " + this.options.pluginAlias + " \"" + name + "\". Have you installed it?");
};

@@ -131,6 +118,2 @@ Tool.prototype.initialize = function () {

};
Tool.prototype.invariant = function (condition, message, pass, fail) {
this.debug('%s: %s', message, condition ? chalk_1.default.green(pass) : chalk_1.default.red(fail));
return this;
};
Tool.prototype.loadConfig = function () {

@@ -144,2 +127,3 @@ var _this = this;

this.config = configLoader.loadConfig();
this.options.workspaceRoot = configLoader.workspaceRoot;
if (this.options.extendArgv) {

@@ -150,3 +134,2 @@ this.argv.forEach(function (arg) {

_this.config[name_1] = true;
_this.console.options[name_1] = true;
}

@@ -186,32 +169,28 @@ });

}
var reporter = this.config.reporter;
if (reporter) {
var loader = new ModuleLoader_1.default(this, 'reporter', Reporter_1.default);
this.console.reporter = loader.loadModule(reporter);
var reporterName = this.config.reporter;
var loader = new ModuleLoader_1.default(this, 'reporter', Reporter_1.default);
var options = {
footer: this.options.footer,
silent: this.config.silent,
};
var reporter = null;
if (reporterName) {
if (isObject_1.default(reporterName)) {
reporter = loader.importModuleFromOptions(__assign({}, reporterName, options));
}
else {
reporter = loader.importModule(String(reporterName), options);
}
}
else {
this.debug("Using native " + chalk_1.default.green('boost') + " reporter");
if (!reporter) {
loader.debug('Using default %s reporter', chalk_1.default.yellow('boost'));
reporter = new DefaultReporter_1.default(options);
}
loader.debug('Bootstrapping reporter with console environment');
reporter.bootstrap(this.console);
this.reporter = reporter;
return this;
};
Tool.prototype.log = function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
(_a = this.console).log.apply(_a, [message].concat(args));
return this;
var _a;
};
Tool.prototype.logError = function (message) {
var args = [];
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
(_a = this.console).error.apply(_a, [message].concat(args));
return this;
var _a;
};
return Tool;
}(Emitter_1.default));
exports.default = Tool;

@@ -1,45 +0,28 @@

import { Blueprint, Struct } from 'optimal';
import { TaskInterface } from './Task';
import debug from 'debug';
import { Struct } from 'optimal';
export interface Debugger extends debug.IDebugger {
invariant(condition: boolean, message: string, pass: string, fail: string): void;
}
export interface Context {
[key: string]: any;
}
export interface ConsoleOptions extends Struct {
footer: string;
header: string;
silent: boolean;
export interface PluginConfig {
plugin: string;
[key: string]: any;
}
export interface ReporterConfig {
reporter: string;
[key: string]: any;
}
export interface ToolConfig extends Struct {
debug: boolean;
extends: string | string[];
plugins: string[];
reporter: string;
plugins: (string | PluginConfig)[];
reporter: string | ReporterConfig;
silent: boolean;
[key: string]: any;
}
export interface ToolOptions extends Struct {
appName: string;
configBlueprint: Blueprint;
configFolder: string;
extendArgv: string;
footer: string;
header: string;
pluginAlias: string;
root: string;
scoped: boolean;
}
export interface PackageConfig extends Struct {
name: string;
}
export interface ReportParams {
errors: string[];
footer: string;
header: string;
logs: string[];
silent: boolean;
tasks: TaskInterface[];
}
export declare type ReportLoader = () => ReportParams;
export declare type Status = 'pending' | 'running' | 'skipped' | 'passed' | 'failed';
export declare type EventArguments = any[];
export declare type EventListener = (...args: EventArguments) => void;
export declare type EventNextHandler = (index: number, ...args: EventArguments) => void;
{
"name": "boost",
"version": "0.43.0",
"version": "0.45.0",
"description": "Robust pipeline for creating build tools that separate logic into routines and tasks.",

@@ -9,3 +9,3 @@ "keywords": [],

"scripts": {
"babel": "beemo typescript --node --declaration",
"babel": "beemo typescript --node",
"build": "yarn run babel",

@@ -45,18 +45,14 @@ "clean": "rimraf ./{lib,esm}/",

"@types/execa": "^0.9.0",
"@types/figures": "^2.0.0",
"@types/glob": "^5.0.35",
"@types/json5": "^0.0.29",
"@types/lodash": "^4.14.106",
"@types/log-update": "^2.0.0",
"@types/lodash": "^4.14.108",
"@types/pluralize": "^0.0.28",
"@types/split": "^0.3.28",
"chalk": "^2.3.2",
"chalk": "^2.4.1",
"cli-truncate": "^1.1.0",
"debug": "^3.1.0",
"elegant-spinner": "^1.0.1",
"execa": "^0.10.0",
"figures": "^2.0.0",
"glob": "^7.1.2",
"json5": "^1.0.1",
"lodash": "^4.17.5",
"log-update": "^2.3.0",
"lodash": "^4.17.10",
"optimal": "^0.19.0",

@@ -70,3 +66,3 @@ "pluralize": "^7.0.0",

"devDependencies": {
"@milesj/build-tool-config": "0.82.2",
"@milesj/build-tool-config": "0.87.0",
"fs-extra": "^5.0.0"

@@ -73,0 +69,0 @@ },

Sorry, the diff of this file is not supported yet

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