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

@sewing-kit/ui

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sewing-kit/ui - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

54

build/cjs/errors.js

@@ -8,48 +8,16 @@ "use strict";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var DiagnosticError =
/*#__PURE__*/
function (_Error) {
_inherits(DiagnosticError, _Error);
function DiagnosticError(_ref) {
var _this;
var title = _ref.title,
content = _ref.content,
suggestion = _ref.suggestion;
_classCallCheck(this, DiagnosticError);
_this = _possibleConstructorReturn(this, _getPrototypeOf(DiagnosticError).call(this, title));
_this.title = title;
_this.content = content;
_this.suggestion = suggestion;
return _this;
class DiagnosticError extends Error {
constructor({
title,
content,
suggestion
}) {
super(title);
this.title = title;
this.content = content;
this.suggestion = suggestion;
}
return DiagnosticError;
}(_wrapNativeSuper(Error));
}
exports.DiagnosticError = DiagnosticError;

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

enumerable: true,
get: function get() {
get: function () {
return _types.Step;

@@ -21,3 +21,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _types.Formatter;

@@ -28,3 +28,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _types.Loggable;

@@ -35,3 +35,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _types.LogLevel;

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

enumerable: true,
get: function get() {
get: function () {
return _runner[key];

@@ -62,3 +62,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _steps[key];

@@ -76,3 +76,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _errors[key];

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

enumerable: true,
get: function get() {
get: function () {
return _ui[key];

@@ -93,0 +93,0 @@ }

@@ -14,778 +14,302 @@ "use strict";

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _templateObject23() {
var data = _taggedTemplateLiteral(["\uD83E\uDDF5 The following unexpected error occurred. We want to provide more useful suggestions when errors occur, so please open an issue on {link the sewing-kit repo https://github.com/Shopify/sewing-kit} so that we can improve this message."]);
const symbols = '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆';
var PersistentLineState;
_templateObject23 = function _templateObject23() {
return data;
};
(function (PersistentLineState) {
PersistentLineState[PersistentLineState["Default"] = 0] = "Default";
PersistentLineState[PersistentLineState["Error"] = 1] = "Error";
})(PersistentLineState || (PersistentLineState = {}));
return data;
}
async function run(ui, run) {
let tick = 0;
let hasLoggedSection = false;
let lastPersistentContentSize = 0;
const isInteractive = process.stdout.isTTY;
const logQueue = [];
const persistentLines = new Set();
function _templateObject22() {
var data = _taggedTemplateLiteral(["{subdued ", "}"]);
const update = () => {
if (!isInteractive) return;
_templateObject22 = function _templateObject22() {
return data;
};
if (lastPersistentContentSize > 0) {
ui.stdout.moveCursor(0, -1 * Math.max(0, lastPersistentContentSize - 1));
ui.stdout.clearDown();
}
return data;
}
for (const queued of logQueue) {
ui.log(...queued);
}
function _templateObject21() {
var data = _taggedTemplateLiteral(["{emphasis What do I do next?}"]);
logQueue.length = 0;
const persistentLineText = [ui.stdout.stringify(fmt => fmt`{subdued -------------------------------------------------------------------------------------}`), ...[...persistentLines].map(({
loggable,
state
}) => ui.stdout.stringify(fmt => fmt`${state === PersistentLineState.Default ? fmt`{info ${symbols[tick % symbols.length]}}` : fmt`{error ✕}`} ${loggable}`))].join('\n');
lastPersistentContentSize = persistentLineText.split('\n').length;
_templateObject21 = function _templateObject21() {
return data;
if (persistentLineText.length > 0) {
ui.stdout.write(persistentLineText);
}
};
return data;
}
const log = (loggable, options) => {
var _ref;
function _templateObject20() {
var data = _taggedTemplateLiteral(["{error Error} ", ""]);
if (!ui.canLogLevel((_ref = options === null || options === void 0 ? void 0 : options.level) !== null && _ref !== void 0 ? _ref : _types.LogLevel.Info)) {
return;
}
_templateObject20 = function _templateObject20() {
return data;
if (isInteractive) {
logQueue.push([loggable, options]);
} else {
ui.log(loggable, options);
}
};
return data;
}
function _templateObject19() {
var data = _taggedTemplateLiteral(["\uD83E\uDDF5 {title ", "}\n"], ["\uD83E\uDDF5 {title ", "}\\n"]);
_templateObject19 = function _templateObject19() {
return data;
const frame = () => {
update();
tick += 1;
};
return data;
}
const addPersistentLine = loggable => {
if (!isInteractive) {
log(loggable);
return {
remove: () => {},
fail: () => {},
update: () => {}
};
}
function _templateObject18() {
var data = _taggedTemplateLiteral(["failed during step: {info ", "}"]);
_templateObject18 = function _templateObject18() {
return data;
const persistentLine = {
loggable,
state: PersistentLineState.Default
};
persistentLines.add(persistentLine);
return {
remove: () => persistentLines.delete(persistentLine),
fail: () => {
persistentLine.state = PersistentLineState.Error;
},
update: loggable => {
persistentLine.loggable = loggable;
}
};
};
return data;
}
const logSeparator = () => {
if (!hasLoggedSection) {
return;
}
function _templateObject17() {
var data = _taggedTemplateLiteral(["finished step: {info ", "}"]);
_templateObject17 = function _templateObject17() {
return data;
log(fmt => fmt`{subdued ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}`);
};
return data;
}
const runNested = async ({
id,
persistentLine: initialPersistentLine
}, run) => {
const nestedLog = (loggable, options) => {
log(fmt => fmt`{emphasis [${id}]} {subdued [${timestamp()}]} ${loggable}`, options);
};
function _templateObject16() {
var data = _taggedTemplateLiteral(["starting step: {info ", "}"]);
const persistentLine = addPersistentLine(initialPersistentLine);
_templateObject16 = function _templateObject16() {
return data;
};
try {
const result = await run({
log: nestedLog,
persistentLine,
stepRunner: () => ({
exec: _execa.default,
return data;
}
log(loggable, options) {
log(fmt => fmt`{emphasis [${id}]} {subdued [${timestamp()}]} {info info}`, options);
log(fmt => fmt`{subdued └} ${loggable}`, options);
}
function _templateObject15() {
var data = _taggedTemplateLiteral(["skipped step: {info ", "}"]);
_templateObject15 = function _templateObject15() {
return data;
})
});
persistentLine.remove();
return result;
} catch (error) {
persistentLine.fail();
throw error;
} finally {
hasLoggedSection = true;
}
};
return data;
}
const runSteps = async (steps, {
id,
skip,
separator
}) => {
if (steps.length === 0) {
return;
}
function _templateObject14() {
var data = _taggedTemplateLiteral(["{subdued , }"]);
const stepOrSteps = steps.length === 1 ? 'step' : 'steps';
let skippedPreSteps = 0;
let finishedPreSteps = 0;
let failedPreSteps = 0;
_templateObject14 = function _templateObject14() {
return data;
};
const createPersistentLabel = () => {
const resolvedSteps = skippedPreSteps + finishedPreSteps + failedPreSteps;
return data;
}
if (resolvedSteps === 0) {
return fmt => fmt`{emphasis [${id}]} running ${steps.length.toLocaleString()} ${stepOrSteps}`;
}
function _templateObject13() {
var data = _taggedTemplateLiteral(["{emphasis [", "]} ", " ", " {subdued (}", "{subdued )}"]);
return fmt => {
const remainingSteps = steps.length - resolvedSteps;
const errorPart = failedPreSteps > 0 ? fmt`{error ${failedPreSteps.toLocaleString()} failed}` : false;
const finishedPart = finishedPreSteps > 0 ? fmt`{success ${finishedPreSteps.toLocaleString()} finished}` : false;
const skippedPart = skippedPreSteps > 0 ? fmt`{subdued ${skippedPreSteps.toLocaleString()} skipped}` : false;
const runningPart = remainingSteps > 0 ? `running ${remainingSteps.toLocaleString()}` : 'finished running';
return fmt`{emphasis [${id}]} ${runningPart} ${remainingSteps === 1 ? 'step' : 'steps'} {subdued (}${[errorPart, finishedPart, skippedPart].filter(Boolean).join(fmt`{subdued , }`)}{subdued )}`;
};
};
_templateObject13 = function _templateObject13() {
return data;
};
if (separator) {
logSeparator();
}
return data;
}
await runNested({
id,
persistentLine: createPersistentLabel()
}, async ({
log,
stepRunner,
persistentLine
}) => {
log(`starting ${stepOrSteps}`);
function _templateObject12() {
var data = _taggedTemplateLiteral(["{subdued ", " skipped}"]);
for (const step of steps) {
var _step$skip;
_templateObject12 = function _templateObject12() {
return data;
};
if (skip && ((_step$skip = step.skip) === null || _step$skip === void 0 ? void 0 : _step$skip.call(step, skip))) {
skippedPreSteps += 1;
return data;
}
if (step.label) {
log(fmt => fmt`skipped step: {info ${step.label}}`);
} else {
log(`skipped unlabeled step`);
}
function _templateObject11() {
var data = _taggedTemplateLiteral(["{success ", " finished}"]);
persistentLine.update(createPersistentLabel());
continue;
}
_templateObject11 = function _templateObject11() {
return data;
};
if (step.label) {
log(fmt => fmt`starting step: {info ${step.label}}`);
} else {
log(`starting unlabeled step`);
}
return data;
}
try {
await step.run(stepRunner(step));
finishedPreSteps += 1;
persistentLine.update(createPersistentLabel());
function _templateObject10() {
var data = _taggedTemplateLiteral(["{error ", " failed}"]);
if (step.label) {
log(fmt => fmt`finished step: {info ${step.label}}`);
}
} catch (error) {
failedPreSteps += 1;
persistentLine.update(createPersistentLabel());
_templateObject10 = function _templateObject10() {
return data;
};
if (step.label) {
log(fmt => fmt`failed during step: {info ${step.label}}`);
} else {
log(`failed during unlabeled step`);
}
return data;
}
throw error;
}
}
function _templateObject9() {
var data = _taggedTemplateLiteral(["{emphasis [", "]} running ", " ", ""]);
_templateObject9 = function _templateObject9() {
return data;
log(`finished ${stepOrSteps}`);
});
};
return data;
}
let interval;
function _templateObject8() {
var data = _taggedTemplateLiteral(["{subdued \u2514} ", ""]);
if (isInteractive) {
interval = setInterval(frame, 60);
}
_templateObject8 = function _templateObject8() {
return data;
};
try {
const result = await run({
log,
nested: runNested,
steps: runSteps,
separator: logSeparator,
epilogue: loggable => {
logSeparator();
log(loggable);
},
title: title => log(fmt => fmt`🧵 {title ${title}}\n`),
pre: (steps, skip) => runSteps(steps, {
id: 'pre',
skip,
separator: false
}),
post: (steps, skip) => runSteps(steps, {
id: 'post',
skip,
separator: true
})
});
update();
return result;
} catch (error) {
update();
return data;
}
if (error instanceof _errors.DiagnosticError) {
ui.error('\n');
ui.error(fmt => fmt`{error Error} ${error.title || 'An unexpected error occurred'}`);
function _templateObject7() {
var data = _taggedTemplateLiteral(["{emphasis [", "]} {subdued [", "]} {info info}"]);
if (error.content) {
ui.error('\n');
ui.error(error.content);
}
_templateObject7 = function _templateObject7() {
return data;
};
if (error.suggestion) {
ui.error('\n');
ui.error(fmt => fmt`{emphasis What do I do next?}`);
ui.error(error.suggestion);
}
return data;
}
if (error.stack) {
ui.error('\n');
ui.error(fmt => fmt`{subdued ${error.stack}}`);
}
} else {
ui.error(fmt => fmt`🧵 The following unexpected error occurred. We want to provide more useful suggestions when errors occur, so please open an issue on {link the sewing-kit repo https://github.com/Shopify/sewing-kit} so that we can improve this message.`); // ui.log(error.message);
function _templateObject6() {
var data = _taggedTemplateLiteral(["{emphasis [", "]} {subdued [", "]} ", ""]);
_templateObject6 = function _templateObject6() {
return data;
};
return data;
}
function _templateObject5() {
var data = _taggedTemplateLiteral(["{subdued ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}"]);
_templateObject5 = function _templateObject5() {
return data;
};
return data;
}
function _templateObject4() {
var data = _taggedTemplateLiteral(["{error \u2715}"]);
_templateObject4 = function _templateObject4() {
return data;
};
return data;
}
function _templateObject3() {
var data = _taggedTemplateLiteral(["{info ", "}"]);
_templateObject3 = function _templateObject3() {
return data;
};
return data;
}
function _templateObject2() {
var data = _taggedTemplateLiteral(["", " ", ""]);
_templateObject2 = function _templateObject2() {
return data;
};
return data;
}
function _templateObject() {
var data = _taggedTemplateLiteral(["{subdued -------------------------------------------------------------------------------------}"]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
var symbols = '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆';
var PersistentLineState;
(function (PersistentLineState) {
PersistentLineState[PersistentLineState["Default"] = 0] = "Default";
PersistentLineState[PersistentLineState["Error"] = 1] = "Error";
})(PersistentLineState || (PersistentLineState = {}));
function run(ui, run) {
var tick, hasLoggedSection, lastPersistentContentSize, isInteractive, logQueue, persistentLines, update, log, frame, addPersistentLine, logSeparator, runNested, runSteps, interval, result;
return regeneratorRuntime.async(function run$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
tick = 0;
hasLoggedSection = false;
lastPersistentContentSize = 0;
isInteractive = process.stdout.isTTY;
logQueue = [];
persistentLines = new Set();
update = function update() {
if (!isInteractive) return;
if (lastPersistentContentSize > 0) {
ui.stdout.moveCursor(0, -1 * Math.max(0, lastPersistentContentSize - 1));
ui.stdout.clearDown();
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = logQueue[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var queued = _step.value;
ui.log.apply(ui, _toConsumableArray(queued));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
logQueue.length = 0;
var persistentLineText = [ui.stdout.stringify(function (fmt) {
return fmt(_templateObject());
})].concat(_toConsumableArray(_toConsumableArray(persistentLines).map(function (_ref) {
var loggable = _ref.loggable,
state = _ref.state;
return ui.stdout.stringify(function (fmt) {
return fmt(_templateObject2(), state === PersistentLineState.Default ? fmt(_templateObject3(), symbols[tick % symbols.length]) : fmt(_templateObject4()), loggable);
});
}))).join('\n');
lastPersistentContentSize = persistentLineText.split('\n').length;
if (persistentLineText.length > 0) {
ui.stdout.write(persistentLineText);
}
};
log = function log(loggable, options) {
var _ref2;
if (!ui.canLogLevel((_ref2 = options === null || options === void 0 ? void 0 : options.level) !== null && _ref2 !== void 0 ? _ref2 : _types.LogLevel.Info)) {
return;
}
if (isInteractive) {
logQueue.push([loggable, options]);
} else {
ui.log(loggable, options);
}
};
frame = function frame() {
update();
tick += 1;
};
addPersistentLine = function addPersistentLine(loggable) {
if (!isInteractive) {
log(loggable);
return {
remove: function remove() {},
fail: function fail() {},
update: function update() {}
};
}
var persistentLine = {
loggable: loggable,
state: PersistentLineState.Default
};
persistentLines.add(persistentLine);
return {
remove: function remove() {
return persistentLines["delete"](persistentLine);
},
fail: function fail() {
persistentLine.state = PersistentLineState.Error;
},
update: function update(loggable) {
persistentLine.loggable = loggable;
}
};
};
logSeparator = function logSeparator() {
if (!hasLoggedSection) {
return;
}
log(function (fmt) {
return fmt(_templateObject5());
});
};
runNested = function runNested(_ref3, run) {
var id, initialPersistentLine, nestedLog, persistentLine, result;
return regeneratorRuntime.async(function runNested$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
id = _ref3.id, initialPersistentLine = _ref3.persistentLine;
nestedLog = function nestedLog(loggable, options) {
log(function (fmt) {
return fmt(_templateObject6(), id, timestamp(), loggable);
}, options);
};
persistentLine = addPersistentLine(initialPersistentLine);
_context.prev = 3;
_context.next = 6;
return regeneratorRuntime.awrap(run({
log: nestedLog,
persistentLine: persistentLine,
stepRunner: function stepRunner() {
return {
exec: _execa["default"],
log: function (_log) {
function log(_x, _x2) {
return _log.apply(this, arguments);
}
log.toString = function () {
return _log.toString();
};
return log;
}(function (loggable, options) {
log(function (fmt) {
return fmt(_templateObject7(), id, timestamp());
}, options);
log(function (fmt) {
return fmt(_templateObject8(), loggable);
}, options);
})
};
}
}));
case 6:
result = _context.sent;
persistentLine.remove();
return _context.abrupt("return", result);
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](3);
persistentLine.fail();
throw _context.t0;
case 15:
_context.prev = 15;
hasLoggedSection = true;
return _context.finish(15);
case 18:
case "end":
return _context.stop();
}
}
}, null, null, [[3, 11, 15, 18]]);
};
runSteps = function runSteps(steps, _ref4) {
var id, skip, separator, stepOrSteps, skippedPreSteps, finishedPreSteps, failedPreSteps, createPersistentLabel;
return regeneratorRuntime.async(function runSteps$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
id = _ref4.id, skip = _ref4.skip, separator = _ref4.separator;
if (!(steps.length === 0)) {
_context4.next = 3;
break;
}
return _context4.abrupt("return");
case 3:
stepOrSteps = steps.length === 1 ? 'step' : 'steps';
skippedPreSteps = 0;
finishedPreSteps = 0;
failedPreSteps = 0;
createPersistentLabel = function createPersistentLabel() {
var resolvedSteps = skippedPreSteps + finishedPreSteps + failedPreSteps;
if (resolvedSteps === 0) {
return function (fmt) {
return fmt(_templateObject9(), id, steps.length.toLocaleString(), stepOrSteps);
};
}
return function (fmt) {
var remainingSteps = steps.length - resolvedSteps;
var errorPart = failedPreSteps > 0 ? fmt(_templateObject10(), failedPreSteps.toLocaleString()) : false;
var finishedPart = finishedPreSteps > 0 ? fmt(_templateObject11(), finishedPreSteps.toLocaleString()) : false;
var skippedPart = skippedPreSteps > 0 ? fmt(_templateObject12(), skippedPreSteps.toLocaleString()) : false;
var runningPart = remainingSteps > 0 ? "running ".concat(remainingSteps.toLocaleString()) : 'finished running';
return fmt(_templateObject13(), id, runningPart, remainingSteps === 1 ? 'step' : 'steps', [errorPart, finishedPart, skippedPart].filter(Boolean).join(fmt(_templateObject14())));
};
};
if (separator) {
logSeparator();
}
_context4.next = 11;
return regeneratorRuntime.awrap(runNested({
id: id,
persistentLine: createPersistentLabel()
}, function _callee(_ref5) {
var log, stepRunner, persistentLine, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _loop, _iterator2, _step2, _ret;
return regeneratorRuntime.async(function _callee$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
log = _ref5.log, stepRunner = _ref5.stepRunner, persistentLine = _ref5.persistentLine;
log("starting ".concat(stepOrSteps));
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_iteratorError2 = undefined;
_context3.prev = 5;
_loop = function _loop() {
var _step$skip;
var step;
return regeneratorRuntime.async(function _loop$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
step = _step2.value;
if (!(skip && ((_step$skip = step.skip) === null || _step$skip === void 0 ? void 0 : _step$skip.call(step, skip)))) {
_context2.next = 6;
break;
}
skippedPreSteps += 1;
if (step.label) {
log(function (fmt) {
return fmt(_templateObject15(), step.label);
});
} else {
log("skipped unlabeled step");
}
persistentLine.update(createPersistentLabel());
return _context2.abrupt("return", "continue");
case 6:
if (step.label) {
log(function (fmt) {
return fmt(_templateObject16(), step.label);
});
} else {
log("starting unlabeled step");
}
_context2.prev = 7;
_context2.next = 10;
return regeneratorRuntime.awrap(step.run(stepRunner(step)));
case 10:
finishedPreSteps += 1;
persistentLine.update(createPersistentLabel());
if (step.label) {
log(function (fmt) {
return fmt(_templateObject17(), step.label);
});
}
_context2.next = 21;
break;
case 15:
_context2.prev = 15;
_context2.t0 = _context2["catch"](7);
failedPreSteps += 1;
persistentLine.update(createPersistentLabel());
if (step.label) {
log(function (fmt) {
return fmt(_templateObject18(), step.label);
});
} else {
log("failed during unlabeled step");
}
throw _context2.t0;
case 21:
case "end":
return _context2.stop();
}
}
}, null, null, [[7, 15]]);
};
_iterator2 = steps[Symbol.iterator]();
case 8:
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
_context3.next = 17;
break;
}
_context3.next = 11;
return regeneratorRuntime.awrap(_loop());
case 11:
_ret = _context3.sent;
if (!(_ret === "continue")) {
_context3.next = 14;
break;
}
return _context3.abrupt("continue", 14);
case 14:
_iteratorNormalCompletion2 = true;
_context3.next = 8;
break;
case 17:
_context3.next = 23;
break;
case 19:
_context3.prev = 19;
_context3.t0 = _context3["catch"](5);
_didIteratorError2 = true;
_iteratorError2 = _context3.t0;
case 23:
_context3.prev = 23;
_context3.prev = 24;
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
_iterator2["return"]();
}
case 26:
_context3.prev = 26;
if (!_didIteratorError2) {
_context3.next = 29;
break;
}
throw _iteratorError2;
case 29:
return _context3.finish(26);
case 30:
return _context3.finish(23);
case 31:
log("finished ".concat(stepOrSteps));
case 32:
case "end":
return _context3.stop();
}
}
}, null, null, [[5, 19, 23, 31], [24,, 26, 30]]);
}));
case 11:
case "end":
return _context4.stop();
}
}
});
};
if (isInteractive) {
interval = setInterval(frame, 60);
}
_context5.prev = 14;
_context5.next = 17;
return regeneratorRuntime.awrap(run({
log: log,
nested: runNested,
steps: runSteps,
separator: logSeparator,
epilogue: function epilogue(loggable) {
logSeparator();
log(loggable);
},
title: function (_title) {
function title(_x3) {
return _title.apply(this, arguments);
}
title.toString = function () {
return _title.toString();
};
return title;
}(function (title) {
return log(function (fmt) {
return fmt(_templateObject19(), title);
});
}),
pre: function pre(steps, skip) {
return runSteps(steps, {
id: 'pre',
skip: skip,
separator: false
});
},
post: function post(steps, skip) {
return runSteps(steps, {
id: 'post',
skip: skip,
separator: true
});
}
}));
case 17:
result = _context5.sent;
update();
return _context5.abrupt("return", result);
case 22:
_context5.prev = 22;
_context5.t0 = _context5["catch"](14);
update();
if (_context5.t0 instanceof _errors.DiagnosticError) {
ui.error('\n');
ui.error(function (fmt) {
return fmt(_templateObject20(), _context5.t0.title || 'An unexpected error occurred');
});
if (_context5.t0.content) {
ui.error('\n');
ui.error(_context5.t0.content);
}
if (_context5.t0.suggestion) {
ui.error('\n');
ui.error(function (fmt) {
return fmt(_templateObject21());
});
ui.error(_context5.t0.suggestion);
}
if (_context5.t0.stack) {
ui.error('\n');
ui.error(function (fmt) {
return fmt(_templateObject22(), _context5.t0.stack);
});
}
} else {
ui.error(function (fmt) {
return fmt(_templateObject23());
}); // ui.log(error.message);
if (_context5.t0.all != null) {
ui.error(_context5.t0.all);
ui.error(_context5.t0.stack);
} else if (_context5.t0.stderr != null) {
ui.error(_context5.t0.stderr);
ui.error(_context5.t0.stack);
} else if (_context5.t0.stdout == null) {
ui.error(_context5.t0.stack);
} else {
ui.error(_context5.t0.stdout);
ui.error(_context5.t0.stack);
}
}
process.exitCode = 1;
case 27:
_context5.prev = 27;
if (interval) clearInterval(interval);
return _context5.finish(27);
case 30:
case "end":
return _context5.stop();
if (error.all != null) {
ui.error(error.all);
ui.error(error.stack);
} else if (error.stderr != null) {
ui.error(error.stderr);
ui.error(error.stack);
} else if (error.stdout == null) {
ui.error(error.stack);
} else {
ui.error(error.stdout);
ui.error(error.stack);
}
}
}, null, null, [[14, 22, 27, 30]]);
process.exitCode = 1;
} finally {
if (interval) clearInterval(interval);
}
}
function timestamp() {
var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Date();
var milliseconds = date.getMilliseconds();
return "".concat(date.getHours().toString().padStart(2, '0'), ":").concat(date.getMinutes().toString().padStart(2, '0'), ":").concat(date.getSeconds().toString().padStart(2, '0'), ".").concat(milliseconds.toString().padStart(3, '0'));
function timestamp(date = new Date()) {
const milliseconds = date.getMilliseconds();
return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}.${milliseconds.toString().padStart(3, '0')}`;
}

@@ -8,16 +8,4 @@ "use strict";

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
const defaultSkip = () => false;
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
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(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(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; }
var defaultSkip = function defaultSkip() {
return false;
};
function createStep(runOrStep, run) {

@@ -27,22 +15,19 @@ return typeof runOrStep === 'function' ? {

skip: defaultSkip
} : _objectSpread({
run: run
}, normalizeOptions(runOrStep));
} : {
run: run,
...normalizeOptions(runOrStep)
};
}
function normalizeOptions(_ref) {
var skip = _ref.skip,
rest = _objectWithoutProperties(_ref, ["skip"]);
return _objectSpread({}, rest, {
function normalizeOptions({
skip,
...rest
}) {
return { ...rest,
skip: skip ? normalizeSkip(skip) : defaultSkip
});
};
}
function normalizeSkip(skipper) {
return typeof skipper === 'function' ? skipper : function (skipped) {
return skipped.some(function (skip) {
return skipper.test(skip);
});
};
return typeof skipper === 'function' ? skipper : skipped => skipped.some(skip => skipper.test(skip));
}

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

exports.LogLevel = void 0;
var LogLevel;
let LogLevel;
exports.LogLevel = LogLevel;

@@ -10,0 +10,0 @@

@@ -18,46 +18,27 @@ "use strict";

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
const CHALK_MAPPINGS = new Map([['success', 'green'], ['error', 'red'], ['info', 'blue'], ['subdued', 'dim'], ['emphasis', 'bold'], ['code', 'inverse'], ['command', 'bold'], ['title', 'bold.underline']]);
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
var CHALK_MAPPINGS = new Map([['success', 'green'], ['error', 'red'], ['info', 'blue'], ['subdued', 'dim'], ['emphasis', 'bold'], ['code', 'inverse'], ['command', 'bold'], ['title', 'bold.underline']]);
function createFormatter(stream) {
var supportsLinks = (0, _supportsHyperlinks.supportsHyperlink)(stream);
const supportsLinks = (0, _supportsHyperlinks.supportsHyperlink)(stream);
var formatString = function formatString(str) {
var formattingRegex = /\{(success|error|info|subdued|emphasis|code|command|title)/g;
var linkRegex = /\{link\s+(.*?)(?=http)([^}])*\}/;
return str.replace(formattingRegex, function (_, format) {
return "{".concat(CHALK_MAPPINGS.get(format));
}).replace(linkRegex, function (_, text, url) {
return supportsLinks ? (0, _ansiEscapes.link)(text.trim(), url) : "".concat(text.trim(), " (").concat(url, ")");
const formatString = str => {
const formattingRegex = /\{(success|error|info|subdued|emphasis|code|command|title)/g;
const linkRegex = /\{link\s+(.*?)(?=http)([^}])*\}/;
return str.replace(formattingRegex, (_, format) => {
return `{${CHALK_MAPPINGS.get(format)}`;
}).replace(linkRegex, (_, text, url) => {
return supportsLinks ? (0, _ansiEscapes.link)(text.trim(), url) : `${text.trim()} (${url})`;
});
};
var processInterpolation = function processInterpolation(interpolated) {
const processInterpolation = interpolated => {
return typeof interpolated === 'function' ? interpolated(formatter) : interpolated || '';
};
var formatter = function formatter(strings) {
var newStrings = strings.map(formatString);
const formatter = (strings, ...interpolated) => {
const newStrings = strings.map(formatString);
newStrings.raw = newStrings;
for (var _len = arguments.length, interpolated = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
interpolated[_key - 1] = arguments[_key];
}
return _chalk["default"].apply(void 0, [newStrings].concat(_toConsumableArray(interpolated.map(processInterpolation))));
return (0, _chalk.default)(newStrings, ...interpolated.map(processInterpolation));
};

@@ -68,8 +49,4 @@

var FormattedStream =
/*#__PURE__*/
function () {
function FormattedStream(stream) {
_classCallCheck(this, FormattedStream);
class FormattedStream {
constructor(stream) {
this.stream = stream;

@@ -79,47 +56,30 @@ this.formatter = createFormatter(stream);

_createClass(FormattedStream, [{
key: "stringify",
value: function stringify(value) {
return typeof value === 'function' ? value(this.formatter) : String(value);
}
}, {
key: "write",
value: function write(value) {
var stringified = this.stringify(value);
this.stream.write(stringified);
return stringified;
}
}, {
key: "moveCursor",
value: function moveCursor() {
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
(0, _readline.moveCursor)(this.stream, x, y);
(0, _readline.cursorTo)(this.stream, x);
}
}, {
key: "clearDown",
value: function clearDown() {
(0, _readline.clearScreenDown)(this.stream);
(0, _readline.clearLine)(this.stream, 0);
}
}]);
stringify(value) {
return typeof value === 'function' ? value(this.formatter) : String(value);
}
return FormattedStream;
}();
write(value) {
const stringified = this.stringify(value);
this.stream.write(stringified);
return stringified;
}
var Ui =
/*#__PURE__*/
function () {
function Ui() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$stdout = _ref.stdout,
stdout = _ref$stdout === void 0 ? process.stdout : _ref$stdout,
_ref$stderr = _ref.stderr,
stderr = _ref$stderr === void 0 ? process.stderr : _ref$stderr,
_ref$level = _ref.level,
level = _ref$level === void 0 ? _types.LogLevel.Info : _ref$level;
moveCursor(x = 0, y = 0) {
(0, _readline.moveCursor)(this.stream, x, y);
(0, _readline.cursorTo)(this.stream, x);
}
_classCallCheck(this, Ui);
clearDown() {
(0, _readline.clearScreenDown)(this.stream);
(0, _readline.clearLine)(this.stream, 0);
}
}
class Ui {
constructor({
stdout = process.stdout,
stderr = process.stderr,
level = _types.LogLevel.Info
} = {}) {
this.stdout = new FormattedStream(stdout);

@@ -130,40 +90,30 @@ this.stderr = new FormattedStream(stderr);

_createClass(Ui, [{
key: "log",
value: function log(value) {
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref2$level = _ref2.level,
level = _ref2$level === void 0 ? _types.LogLevel.Info : _ref2$level;
log(value, {
level = _types.LogLevel.Info
} = {}) {
if (!this.canLogLevel(level)) {
return;
}
if (!this.canLogLevel(level)) {
return;
}
this.stdout.write(value);
this.stdout.write('\n');
}
this.stdout.write(value);
this.stdout.write('\n');
error(value, {
level = _types.LogLevel.Info
} = {}) {
if (!this.canLogLevel(level)) {
return;
}
}, {
key: "error",
value: function error(value) {
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref3$level = _ref3.level,
level = _ref3$level === void 0 ? _types.LogLevel.Info : _ref3$level;
if (!this.canLogLevel(level)) {
return;
}
this.stderr.write(value);
this.stderr.write('\n');
}
this.stderr.write(value);
this.stderr.write('\n');
}
}, {
key: "canLogLevel",
value: function canLogLevel(level) {
return this.level >= level;
}
}]);
canLogLevel(level) {
return this.level >= level;
}
return Ui;
}();
}
exports.Ui = Ui;
{
"name": "@sewing-kit/ui",
"version": "0.0.13",
"version": "0.0.14",
"sideEffects": false,

@@ -15,3 +15,3 @@ "publishConfig": {

},
"gitHead": "b10516a3b50627d57e128a1af99818dc78f65d68"
"gitHead": "75439e801a34ecd042ae3347183736f42d0f9eea"
}
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