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.4 to 0.0.5

92

build/cjs/errors.js

@@ -6,81 +6,21 @@ "use strict";

});
exports.MissingPluginError = exports.DiagnosticError = void 0;
exports.DiagnosticError = void 0;
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); }
class DiagnosticError extends Error {
constructor({
title,
content,
suggestion
}) {
super(title);
this.suggestion = void 0;
this.title = void 0;
this.content = void 0;
this.title = title;
this.content = content;
this.suggestion = suggestion;
}
function _templateObject() {
var data = _taggedTemplateLiteral(["Run {command yarn add ", "}, import it into your sewing-kit config file, and include it using the {code plugins} option."]);
_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 _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 message = _ref.message,
suggestion = _ref.suggestion;
_classCallCheck(this, DiagnosticError);
_this = _possibleConstructorReturn(this, _getPrototypeOf(DiagnosticError).call(this, message));
_this.suggestion = void 0;
_this.suggestion = suggestion;
return _this;
}
return DiagnosticError;
}(_wrapNativeSuper(Error));
exports.DiagnosticError = DiagnosticError;
var MissingPluginError =
/*#__PURE__*/
function (_DiagnosticError) {
_inherits(MissingPluginError, _DiagnosticError);
function MissingPluginError(plugin) {
_classCallCheck(this, MissingPluginError);
return _possibleConstructorReturn(this, _getPrototypeOf(MissingPluginError).call(this, {
message: "Missing hooks provided by ".concat(plugin),
suggestion: function suggestion(fmt) {
return fmt(_templateObject(), plugin);
}
}));
}
return MissingPluginError;
}(DiagnosticError);
exports.MissingPluginError = MissingPluginError;
exports.DiagnosticError = DiagnosticError;

8

build/cjs/index.js

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

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

@@ -26,3 +26,3 @@ }

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

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

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

@@ -52,3 +52,3 @@ }

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

@@ -55,0 +55,0 @@ }

@@ -12,126 +12,4 @@ "use strict";

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _templateObject11() {
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. Command: {code ", "}.\n"], ["\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. Command: {code ", "}.\\n"]);
_templateObject11 = function _templateObject11() {
return data;
};
return data;
}
function _templateObject10() {
var data = _taggedTemplateLiteral(["\uD83E\uDDF5 {emphasis ", "}\n"], ["\uD83E\uDDF5 {emphasis ", "}\\n"]);
_templateObject10 = function _templateObject10() {
return data;
};
return data;
}
function _templateObject9() {
var data = _taggedTemplateLiteral(["", ""]);
_templateObject9 = function _templateObject9() {
return data;
};
return data;
}
function _templateObject8() {
var data = _taggedTemplateLiteral(["", ""]);
_templateObject8 = function _templateObject8() {
return data;
};
return data;
}
function _templateObject7() {
var data = _taggedTemplateLiteral(["", ""]);
_templateObject7 = function _templateObject7() {
return data;
};
return data;
}
function _templateObject6() {
var data = _taggedTemplateLiteral(["", ""]);
_templateObject6 = function _templateObject6() {
return data;
};
return data;
}
function _templateObject5() {
var data = _taggedTemplateLiteral(["", " ", ""]);
_templateObject5 = function _templateObject5() {
return data;
};
return data;
}
function _templateObject4() {
var data = _taggedTemplateLiteral(["{subdued o}"]);
_templateObject4 = function _templateObject4() {
return data;
};
return data;
}
function _templateObject3() {
var data = _taggedTemplateLiteral(["{error o}"]);
_templateObject3 = function _templateObject3() {
return data;
};
return data;
}
function _templateObject2() {
var data = _taggedTemplateLiteral(["{success \u2713}"]);
_templateObject2 = function _templateObject2() {
return data;
};
return data;
}
function _templateObject() {
var data = _taggedTemplateLiteral(["{info ", "}"]);
_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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
var StepState;

@@ -146,10 +24,6 @@

var symbols = '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆';
const symbols = '⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆';
var StepRunner =
/*#__PURE__*/
function () {
function StepRunner(step, update) {
_classCallCheck(this, StepRunner);
class StepRunner {
constructor(step, update) {
this.step = step;

@@ -161,230 +35,78 @@ this.update = update;

_createClass(StepRunner, [{
key: "run",
value: function () {
var _run = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee2(ui) {
var _this = this;
async run(ui) {
this.setState(StepState.InProgress);
var runner;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
this.setState(StepState.InProgress);
_context2.prev = 1;
runner = {
ui: ui,
exec: _execa["default"],
run: function () {
var _run2 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(steps) {
var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step3, stepRunner, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _stepRunner;
try {
const runner = {
exec: _execa.default,
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 3;
log(loggable, _logLevel) {
ui.log(loggable);
},
for (_iterator = steps[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_step3 = _step.value;
stepRunner = new StepRunner(_step3, _this.update);
run: async steps => {
for (const step of steps) {
const stepRunner = new StepRunner(step, this.update);
this.stepRunners.push(stepRunner);
}
_this.stepRunners.push(stepRunner);
}
for (const stepRunner of this.stepRunners) {
await stepRunner.run(ui);
}
}
};
await this.step.run(runner);
this.setState(StepState.Success);
} catch (error) {
this.setState(StepState.Failure);
throw error;
}
}
_context.next = 11;
break;
toString(tick) {
if (this.step.label == null || this.step.indefinite) {
return '';
}
case 7:
_context.prev = 7;
_context.t0 = _context["catch"](3);
_didIteratorError = true;
_iteratorError = _context.t0;
return fmt => {
let prefix = '';
case 11:
_context.prev = 11;
_context.prev = 12;
switch (this.state) {
case StepState.InProgress:
prefix = fmt`{info ${symbols[tick % symbols.length]}}`;
break;
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
case StepState.Success:
prefix = fmt`{success ✓}`;
break;
case 14:
_context.prev = 14;
case StepState.Failure:
prefix = fmt`{error o}`;
break;
if (!_didIteratorError) {
_context.next = 17;
break;
}
throw _iteratorError;
case 17:
return _context.finish(14);
case 18:
return _context.finish(11);
case 19:
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_iteratorError2 = undefined;
_context.prev = 22;
_iterator2 = _this.stepRunners[Symbol.iterator]();
case 24:
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
_context.next = 31;
break;
}
_stepRunner = _step2.value;
_context.next = 28;
return _stepRunner.run(ui);
case 28:
_iteratorNormalCompletion2 = true;
_context.next = 24;
break;
case 31:
_context.next = 37;
break;
case 33:
_context.prev = 33;
_context.t1 = _context["catch"](22);
_didIteratorError2 = true;
_iteratorError2 = _context.t1;
case 37:
_context.prev = 37;
_context.prev = 38;
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
_iterator2["return"]();
}
case 40:
_context.prev = 40;
if (!_didIteratorError2) {
_context.next = 43;
break;
}
throw _iteratorError2;
case 43:
return _context.finish(40);
case 44:
return _context.finish(37);
case 45:
case "end":
return _context.stop();
}
}
}, _callee, null, [[3, 7, 11, 19], [12,, 14, 18], [22, 33, 37, 45], [38,, 40, 44]]);
}));
function run(_x2) {
return _run2.apply(this, arguments);
}
return run;
}()
};
_context2.next = 5;
return this.step.run(runner);
case 5:
this.setState(StepState.Success);
_context2.next = 12;
break;
case 8:
_context2.prev = 8;
_context2.t0 = _context2["catch"](1);
this.setState(StepState.Failure);
throw _context2.t0;
case 12:
case "end":
return _context2.stop();
}
}
}, _callee2, this, [[1, 8]]);
}));
function run(_x) {
return _run.apply(this, arguments);
case StepState.Pending:
prefix = fmt`{subdued o}`;
break;
}
return run;
}()
}, {
key: "toString",
value: function toString(tick) {
var _this2 = this;
const ownLine = fmt`${prefix} ${fmt`${this.step.label || ''}`}`;
if (this.step.label == null || this.step.indefinite) {
return '';
if (this.state !== StepState.InProgress) {
return ownLine;
}
return function (fmt) {
var prefix = '';
const childLines = this.stepRunners.map(step => fmt`${step.toString(tick)}`).filter(Boolean);
return `${ownLine}${childLines.length > 0 ? '\n ' : ''}${childLines.join('\n ')}`;
};
}
switch (_this2.state) {
case StepState.InProgress:
prefix = fmt(_templateObject(), symbols[tick % symbols.length]);
break;
setState(state) {
this.state = state;
this.update();
}
case StepState.Success:
prefix = fmt(_templateObject2());
break;
}
case StepState.Failure:
prefix = fmt(_templateObject3());
break;
case StepState.Pending:
prefix = fmt(_templateObject4());
break;
}
var ownLine = fmt(_templateObject5(), prefix, fmt(_templateObject6(), _this2.step.label || ''));
var childLines = _this2.stepRunners.map(function (step) {
return fmt(_templateObject7(), step.toString(tick));
}).filter(Boolean);
return "".concat(ownLine).concat(childLines.length > 0 ? '\n ' : '').concat(childLines.join('\n '));
};
}
}, {
key: "setState",
value: function setState(state) {
this.state = state;
this.update();
}
}]);
return StepRunner;
}();
var StepGroupRunner =
/*#__PURE__*/
function () {
function StepGroupRunner(steps, update) {
_classCallCheck(this, StepGroupRunner);
class StepGroupRunner {
constructor(steps, update) {
this.steps = steps;

@@ -395,151 +117,20 @@ this.update = update;

_createClass(StepGroupRunner, [{
key: "run",
value: function () {
var _run3 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee3(ui) {
var _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step4, _step6, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step5, _step7;
async run(ui) {
for (const step of this.steps) {
this.stepRunners.push(new StepRunner(step, this.update));
}
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_iteratorNormalCompletion3 = true;
_didIteratorError3 = false;
_iteratorError3 = undefined;
_context3.prev = 3;
for (_iterator3 = this.steps[Symbol.iterator](); !(_iteratorNormalCompletion3 = (_step4 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
_step6 = _step4.value;
this.stepRunners.push(new StepRunner(_step6, this.update));
}
_context3.next = 11;
break;
case 7:
_context3.prev = 7;
_context3.t0 = _context3["catch"](3);
_didIteratorError3 = true;
_iteratorError3 = _context3.t0;
case 11:
_context3.prev = 11;
_context3.prev = 12;
if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) {
_iterator3["return"]();
}
case 14:
_context3.prev = 14;
if (!_didIteratorError3) {
_context3.next = 17;
break;
}
throw _iteratorError3;
case 17:
return _context3.finish(14);
case 18:
return _context3.finish(11);
case 19:
_iteratorNormalCompletion4 = true;
_didIteratorError4 = false;
_iteratorError4 = undefined;
_context3.prev = 22;
_iterator4 = this.stepRunners[Symbol.iterator]();
case 24:
if (_iteratorNormalCompletion4 = (_step5 = _iterator4.next()).done) {
_context3.next = 31;
break;
}
_step7 = _step5.value;
_context3.next = 28;
return _step7.run(ui);
case 28:
_iteratorNormalCompletion4 = true;
_context3.next = 24;
break;
case 31:
_context3.next = 37;
break;
case 33:
_context3.prev = 33;
_context3.t1 = _context3["catch"](22);
_didIteratorError4 = true;
_iteratorError4 = _context3.t1;
case 37:
_context3.prev = 37;
_context3.prev = 38;
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
_iterator4["return"]();
}
case 40:
_context3.prev = 40;
if (!_didIteratorError4) {
_context3.next = 43;
break;
}
throw _iteratorError4;
case 43:
return _context3.finish(40);
case 44:
return _context3.finish(37);
case 45:
case "end":
return _context3.stop();
}
}
}, _callee3, this, [[3, 7, 11, 19], [12,, 14, 18], [22, 33, 37, 45], [38,, 40, 44]]);
}));
function run(_x3) {
return _run3.apply(this, arguments);
}
return run;
}()
}, {
key: "toString",
value: function toString(tick) {
var _this3 = this;
return function (fmt) {
return _this3.stepRunners.map(function (step) {
return fmt(_templateObject8(), step.toString(tick));
}).filter(Boolean).join('\n');
};
for (const step of this.stepRunners) {
await step.run(ui);
}
}]);
}
return StepGroupRunner;
}();
toString(tick) {
return fmt => this.stepRunners.map(step => fmt`${step.toString(tick)}`).filter(Boolean).join('\n');
}
var RunnerUi =
/*#__PURE__*/
function () {
function RunnerUi(groups, ui) {
var _this4 = this;
}
_classCallCheck(this, RunnerUi);
class RunnerUi {
constructor(groups, ui) {
this.groups = groups;

@@ -551,228 +142,88 @@ this.ui = ui;

this.update = function () {
var content = _this4.ui.stdout.stringify(function (fmt) {
return _this4.groupRunners.map(function (group) {
return fmt(_templateObject9(), group.toString(_this4.tick));
}).filter(Boolean).join('\n\n');
});
_this4.ui.stdout.moveCursor(0, -1 * Math.max(0, _this4.lastContentHeight - 1));
_this4.ui.stdout.clearDown();
_this4.ui.stdout.write(content);
_this4.tick += 1;
_this4.lastContentHeight = content.split('\n').length;
this.update = () => {
const content = this.ui.stdout.stringify(fmt => this.groupRunners.map(group => fmt`${group.toString(this.tick)}`).filter(Boolean).join('\n\n'));
this.ui.stdout.moveCursor(0, -1 * Math.max(0, this.lastContentHeight - 1));
this.ui.stdout.clearDown();
this.ui.stdout.write(content);
this.lastContentHeight = content.split('\n').length;
};
}
_createClass(RunnerUi, [{
key: "run",
value: function () {
var _run4 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee4() {
var _iteratorNormalCompletion5, _didIteratorError5, _iteratorError5, _iterator5, _step8, group, interval, immediate, _iteratorNormalCompletion6, _didIteratorError6, _iteratorError6, _iterator6, _step9, groupRunner;
async run() {
for (const group of this.groups) {
this.groupRunners.push(new StepGroupRunner(group, this.update));
}
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_iteratorNormalCompletion5 = true;
_didIteratorError5 = false;
_iteratorError5 = undefined;
_context4.prev = 3;
const frame = () => {
this.update();
this.tick += 1;
};
for (_iterator5 = this.groups[Symbol.iterator](); !(_iteratorNormalCompletion5 = (_step8 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
group = _step8.value;
this.groupRunners.push(new StepGroupRunner(group, this.update));
}
const interval = setInterval(frame, 60);
const immediate = setImmediate(frame);
_context4.next = 11;
break;
try {
for (const groupRunner of this.groupRunners) {
await groupRunner.run(this.ui);
}
} finally {
clearInterval(interval);
clearImmediate(immediate);
this.update();
case 7:
_context4.prev = 7;
_context4.t0 = _context4["catch"](3);
_didIteratorError5 = true;
_iteratorError5 = _context4.t0;
case 11:
_context4.prev = 11;
_context4.prev = 12;
if (!_iteratorNormalCompletion5 && _iterator5["return"] != null) {
_iterator5["return"]();
}
case 14:
_context4.prev = 14;
if (!_didIteratorError5) {
_context4.next = 17;
break;
}
throw _iteratorError5;
case 17:
return _context4.finish(14);
case 18:
return _context4.finish(11);
case 19:
interval = setInterval(this.update, 60);
immediate = setImmediate(this.update);
_context4.prev = 21;
_iteratorNormalCompletion6 = true;
_didIteratorError6 = false;
_iteratorError6 = undefined;
_context4.prev = 25;
_iterator6 = this.groupRunners[Symbol.iterator]();
case 27:
if (_iteratorNormalCompletion6 = (_step9 = _iterator6.next()).done) {
_context4.next = 34;
break;
}
groupRunner = _step9.value;
_context4.next = 31;
return groupRunner.run(this.ui);
case 31:
_iteratorNormalCompletion6 = true;
_context4.next = 27;
break;
case 34:
_context4.next = 40;
break;
case 36:
_context4.prev = 36;
_context4.t1 = _context4["catch"](25);
_didIteratorError6 = true;
_iteratorError6 = _context4.t1;
case 40:
_context4.prev = 40;
_context4.prev = 41;
if (!_iteratorNormalCompletion6 && _iterator6["return"] != null) {
_iterator6["return"]();
}
case 43:
_context4.prev = 43;
if (!_didIteratorError6) {
_context4.next = 46;
break;
}
throw _iteratorError6;
case 46:
return _context4.finish(43);
case 47:
return _context4.finish(40);
case 48:
_context4.prev = 48;
clearInterval(interval);
clearImmediate(immediate);
this.update();
if (this.lastContentHeight > 0) {
this.ui.stdout.write('\n');
}
return _context4.finish(48);
case 54:
case "end":
return _context4.stop();
}
}
}, _callee4, this, [[3, 7, 11, 19], [12,, 14, 18], [21,, 48, 54], [25, 36, 40, 48], [41,, 43, 47]]);
}));
function run() {
return _run4.apply(this, arguments);
if (this.lastContentHeight > 0) {
this.ui.stdout.write('\n');
}
}
}
return run;
}()
}]);
return RunnerUi;
}();
function run(_x4, _x5) {
return _run5.apply(this, arguments);
}
function _run5() {
_run5 = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee5(steps, _ref) {
var ui, _ref$pre, pre, _ref$post, post, title, runnerUi;
async function run(steps, {
ui,
pre = [],
post = [],
title
}) {
const runnerUi = new RunnerUi([pre, steps, post], ui);
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
ui = _ref.ui, _ref$pre = _ref.pre, pre = _ref$pre === void 0 ? [] : _ref$pre, _ref$post = _ref.post, post = _ref$post === void 0 ? [] : _ref$post, title = _ref.title;
runnerUi = new RunnerUi([pre, steps, post], ui);
_context5.prev = 2;
try {
if (title) {
ui.log(fmt => fmt`🧵 {emphasis ${title}}\n`);
}
if (title) {
ui.log(function (fmt) {
return fmt(_templateObject10(), title);
});
}
await runnerUi.run();
} catch (error) {
if (error instanceof _errors.DiagnosticError) {
ui.error('\n');
ui.error(fmt => fmt`{error Error} ${error.title || 'An unexpected error occurred'}`);
_context5.next = 6;
return runnerUi.run();
if (error.content) {
ui.error('\n');
ui.error(error.content);
}
case 6:
_context5.next = 12;
break;
if (error.suggestion) {
ui.error('\n');
ui.error(fmt => fmt`{emphasis What do I do next?}`);
ui.error(error.suggestion);
}
case 8:
_context5.prev = 8;
_context5.t0 = _context5["catch"](2);
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);
if (_context5.t0 instanceof _errors.DiagnosticError) {
ui.error(_context5.t0.message);
if (error.all == null) {
ui.error(error.stack);
} else {
ui.error(error.all);
ui.error(error.stack);
}
}
if (_context5.t0.suggestion) {
ui.error(_context5.t0.suggestion);
}
} else {
ui.error(function (fmt) {
return fmt(_templateObject11(), process.argv.join(' '));
}); // ui.log(error.message);
if (_context5.t0.all == null) {
ui.error(_context5.t0.stack);
} else {
ui.error(_context5.t0.all);
}
}
process.exitCode = 1;
case 12:
case "end":
return _context5.stop();
}
}
}, _callee5, null, [[2, 8]]);
}));
return _run5.apply(this, arguments);
process.exitCode = 1;
}
}

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function createStep(runOrStep, run) {
return typeof runOrStep === 'function' ? {
run: runOrStep
} : _objectSpread({
run: run
}, runOrStep);
} : {
run,
...runOrStep
};
}

@@ -18,48 +18,25 @@ "use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
const CHALK_MAPPINGS = new Map([['success', 'green'], ['error', 'red'], ['info', 'blue'], ['subdued', 'dim'], ['emphasis', 'bold'], ['code', 'inverse'], ['command', 'bold']]);
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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']]);
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)/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)/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));
};

@@ -70,8 +47,4 @@

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

@@ -82,45 +55,29 @@ this.formatter = void 0;

_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;
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
} = {}) {
this.stdout = void 0;

@@ -132,46 +89,18 @@ this.stderr = void 0;

_createClass(Ui, [{
key: "spin",
value: function () {
var _spin = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(_label, wait) {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return wait();
async spin(_label, wait) {
await wait();
}
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
}));
log(value) {
this.stdout.write(value);
this.stdout.write('\n');
}
function spin(_x, _x2) {
return _spin.apply(this, arguments);
}
error(value) {
this.stderr.write(value);
this.stderr.write('\n');
}
return spin;
}()
}, {
key: "log",
value: function log(value) {
this.stdout.write(value);
this.stdout.write('\n');
}
}, {
key: "error",
value: function error(value) {
this.stderr.write(value);
this.stderr.write('\n');
}
}]);
}
return Ui;
}();
exports.Ui = Ui;
import { FirstArgument } from '@shopify/useful-types';
import { Ui } from './ui';
interface DiagnosticErrorOptions {
message: string;
title?: string;
content?: string;
suggestion?: FirstArgument<Ui['log']>;

@@ -9,8 +10,7 @@ }

readonly suggestion: DiagnosticErrorOptions['suggestion'];
constructor({ message, suggestion }: DiagnosticErrorOptions);
readonly title: DiagnosticErrorOptions['title'];
readonly content: DiagnosticErrorOptions['content'];
constructor({ title, content, suggestion }: DiagnosticErrorOptions);
}
export declare class MissingPluginError extends DiagnosticError {
constructor(plugin: string);
}
export {};
//# sourceMappingURL=errors.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class DiagnosticError extends Error {
constructor({ message, suggestion }) {
super(message);
constructor({ title, content, suggestion }) {
super(title);
this.title = title;
this.content = content;
this.suggestion = suggestion;

@@ -10,10 +12,1 @@ }

exports.DiagnosticError = DiagnosticError;
class MissingPluginError extends DiagnosticError {
constructor(plugin) {
super({
message: `Missing hooks provided by ${plugin}`,
suggestion: (fmt) => fmt `Run {command yarn add ${plugin}}, import it into your sewing-kit config file, and include it using the {code plugins} option.`,
});
}
}
exports.MissingPluginError = MissingPluginError;

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

import exec from 'execa';
import { Step } from '@sewing-kit/types';
import { Ui } from './ui';
import { Step } from './steps';
export interface NestedStepRunner {
ui: Ui;
exec: typeof exec;
run(steps: Step[]): Promise<void>;
}
export declare function run(steps: Step[], { ui, pre, post, title, }: {

@@ -10,0 +4,0 @@ ui: Ui;

@@ -27,4 +27,6 @@ "use strict";

const runner = {
ui,
exec: execa_1.default,
log(loggable, _logLevel) {
ui.log(loggable);
},
run: async (steps) => {

@@ -69,2 +71,5 @@ for (const step of steps) {

const ownLine = fmt `${prefix} ${fmt `${this.step.label || ''}`}`;
if (this.state !== StepState.InProgress) {
return ownLine;
}
const childLines = this.stepRunners

@@ -117,3 +122,2 @@ .map((step) => fmt `${step.toString(tick)}`)

this.ui.stdout.write(content);
this.tick += 1;
this.lastContentHeight = content.split('\n').length;

@@ -126,4 +130,8 @@ };

}
const interval = setInterval(this.update, 60);
const immediate = setImmediate(this.update);
const frame = () => {
this.update();
this.tick += 1;
};
const interval = setInterval(frame, 60);
const immediate = setImmediate(frame);
try {

@@ -154,9 +162,20 @@ for (const groupRunner of this.groupRunners) {

if (error instanceof errors_1.DiagnosticError) {
ui.error(error.message);
ui.error('\n');
ui.error((fmt) => fmt `{error Error} ${error.title || 'An unexpected error occurred'}`);
if (error.content) {
ui.error('\n');
ui.error(error.content);
}
if (error.suggestion) {
ui.error('\n');
ui.error((fmt) => fmt `{emphasis What do I do next?}`);
ui.error(error.suggestion);
}
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. Command: {code ${process.argv.join(' ')}}.\n`);
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);

@@ -168,2 +187,3 @@ if (error.all == null) {

ui.error(error.all);
ui.error(error.stack);
}

@@ -170,0 +190,0 @@ }

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

import { FirstArgument } from '@shopify/useful-types';
export interface Step {
label?: FirstArgument<import('./ui').Ui['log']>;
indefinite?: boolean;
run(runner: import('./runner').NestedStepRunner): void | Promise<void>;
}
import { Step } from '@sewing-kit/types';
export declare function createStep(run: Step['run']): Step;
export declare function createStep(options: Omit<Step, 'run'>, run: Step['run']): Step;
//# sourceMappingURL=steps.d.ts.map

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

export * from "./build/ts";
export * from "./build/ts/index";
export {default} from "./build/ts/index";
{
"name": "@sewing-kit/ui",
"version": "0.0.4",
"version": "0.0.5",
"sideEffects": false,

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

},
"gitHead": "013c63fcec7455a0d165706a87ee713d7983b5fe"
"gitHead": "b92b7a4350e29b5c1500b895558743767617d725"
}

@@ -5,3 +5,4 @@ import {FirstArgument} from '@shopify/useful-types';

interface DiagnosticErrorOptions {
message: string;
title?: string;
content?: string;
suggestion?: FirstArgument<Ui['log']>;

@@ -12,17 +13,11 @@ }

readonly suggestion: DiagnosticErrorOptions['suggestion'];
readonly title: DiagnosticErrorOptions['title'];
readonly content: DiagnosticErrorOptions['content'];
constructor({message, suggestion}: DiagnosticErrorOptions) {
super(message);
constructor({title, content, suggestion}: DiagnosticErrorOptions) {
super(title);
this.title = title;
this.content = content;
this.suggestion = suggestion;
}
}
export class MissingPluginError extends DiagnosticError {
constructor(plugin: string) {
super({
message: `Missing hooks provided by ${plugin}`,
suggestion: (fmt) =>
fmt`Run {command yarn add ${plugin}}, import it into your sewing-kit config file, and include it using the {code plugins} option.`,
});
}
}
import exec from 'execa';
import {Step, StepRunner as NestedStepRunner} from '@sewing-kit/types';
import {Ui, Loggable} from './ui';
import {Step} from './steps';
import {DiagnosticError} from './errors';
export interface NestedStepRunner {
ui: Ui;
exec: typeof exec;
run(steps: Step[]): Promise<void>;
}
enum StepState {

@@ -34,6 +28,8 @@ InProgress,

try {
const runner = {
ui,
const runner: NestedStepRunner = {
exec,
run: async (steps: Step[]) => {
log(loggable, _logLevel) {
ui.log(loggable);
},
run: async (steps) => {
for (const step of steps) {

@@ -82,2 +78,7 @@ const stepRunner = new StepRunner(step, this.update);

const ownLine = fmt`${prefix} ${fmt`${this.step.label || ''}`}`;
if (this.state !== StepState.InProgress) {
return ownLine;
}
const childLines = this.stepRunners

@@ -137,5 +138,10 @@ .map((step) => fmt`${step.toString(tick)}`)

const interval: any = setInterval(this.update, 60);
const immediate = setImmediate(this.update);
const frame = () => {
this.update();
this.tick += 1;
};
const interval: any = setInterval(frame, 60);
const immediate = setImmediate(frame);
try {

@@ -168,3 +174,2 @@ for (const groupRunner of this.groupRunners) {

this.tick += 1;
this.lastContentHeight = content.split('\n').length;

@@ -193,13 +198,27 @@ };

if (error instanceof DiagnosticError) {
ui.error(error.message);
ui.error('\n');
ui.error(
(fmt) =>
fmt`{error Error} ${error.title || 'An unexpected error occurred'}`,
);
if (error.content) {
ui.error('\n');
ui.error(error.content);
}
if (error.suggestion) {
ui.error('\n');
ui.error((fmt) => fmt`{emphasis What do I do next?}`);
ui.error(error.suggestion);
}
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. Command: {code ${process.argv.join(
' ',
)}}.\n`,
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.`,
);

@@ -212,2 +231,3 @@ // ui.log(error.message);

ui.error(error.all);
ui.error(error.stack);
}

@@ -214,0 +234,0 @@ }

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

import {FirstArgument} from '@shopify/useful-types';
import {Step} from '@sewing-kit/types';
export interface Step {
label?: FirstArgument<import('./ui').Ui['log']>;
indefinite?: boolean;
run(runner: import('./runner').NestedStepRunner): void | Promise<void>;
}
export function createStep(run: Step['run']): Step;

@@ -10,0 +4,0 @@ export function createStep(options: Omit<Step, 'run'>, run: Step['run']): Step;

@@ -15,3 +15,3 @@ {

"include": ["src/**/*.ts"],
"references": []
"references": [{"path": "../types"}]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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