refactor(Cypress): Moved Cypress to the main folder of the project, as I don't need a sub project for now.

This commit is contained in:
2021-09-02 16:22:25 +02:00
parent d9226abf85
commit 89ec2d42ac
8402 changed files with 22 additions and 5 deletions

51
node_modules/listr2/dist/lib/task-wrapper.d.ts generated vendored Normal file
View File

@@ -0,0 +1,51 @@
/// <reference types="node" />
import { ListrError } from '../interfaces/listr-error.interface';
import { ListrBaseClassOptions, ListrSubClassOptions, ListrTask } from '../interfaces/listr.interface';
import { ListrRendererFactory } from '../interfaces/renderer.interface';
import { Task } from './task';
import { Listr } from '../listr';
import { PromptOptions } from '../utils/prompt.interface';
/**
* Extend the task to have more functionality while accesing from the outside.
*/
export declare class TaskWrapper<Ctx, Renderer extends ListrRendererFactory> {
task: Task<Ctx, ListrRendererFactory>;
errors: ListrError[];
private options;
constructor(task: Task<Ctx, ListrRendererFactory>, errors: ListrError[], options: ListrBaseClassOptions<Ctx, any, any>);
/** Change the title of the current task. */
set title(data: string);
/** Get the title of the current task. */
get title(): string;
/** Send a output to the output channel. */
set output(data: string);
/** Get the output from the output channel. */
get output(): string;
/** Create a new subtask with given renderer selection from the parent task. */
newListr(task: ListrTask<Ctx, Renderer> | ListrTask<Ctx, Renderer>[] | ((parent: this) => ListrTask<Ctx, Renderer> | ListrTask<Ctx, Renderer>[]), options?: ListrSubClassOptions<Ctx, Renderer>): Listr<Ctx, any, any>;
/** Report a error in process for error collection. */
report(error: Error | ListrError): void;
/** Skip current task. */
skip(message?: string): void;
/** Get the number of retrying, else returns false */
isRetrying(): Task<Ctx, Renderer>['retry'];
/**
* Create a new Enquirer prompt using prompt options.
*
* Since process.stdout is controlled by Listr, this will passthrough all Enquirer data through internal stdout.
*/
prompt<T = any>(options: PromptOptions | PromptOptions<true>[]): Promise<T>;
/** Cancels the current prompt attach to this task. */
cancelPrompt(throwError?: boolean): void;
/**
* Pass stream of data to internal stdout.
*
* Since Listr2 takes control of process.stdout utilizing the default renderer, any data outputted to process.stdout
* will corupt its looks.
*
* This returns a fake stream to pass any stream inside Listr as task data.
*/
stdout(): NodeJS.WriteStream & NodeJS.WritableStream;
/** Run this task. */
run(ctx: Ctx): Promise<void>;
}

110
node_modules/listr2/dist/lib/task-wrapper.js generated vendored Normal file
View File

@@ -0,0 +1,110 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskWrapper = void 0;
const through = require("through");
const clearline_regex_constants_1 = require("../constants/clearline-regex.constants");
const state_constants_1 = require("../constants/state.constants");
const listr_error_interface_1 = require("../interfaces/listr-error.interface");
const listr_1 = require("../listr");
const prompt_1 = require("../utils/prompt");
/**
* Extend the task to have more functionality while accesing from the outside.
*/
class TaskWrapper {
constructor(task, errors, options) {
this.task = task;
this.errors = errors;
this.options = options;
}
/** Change the title of the current task. */
set title(data) {
this.task.title$ = data;
}
/** Get the title of the current task. */
get title() {
return this.task.title;
}
/** Send a output to the output channel. */
set output(data) {
this.task.output$ = data;
}
/** Get the output from the output channel. */
get output() {
return this.task.output;
}
/** Create a new subtask with given renderer selection from the parent task. */
newListr(task, options) {
let tasks;
if (typeof task === 'function') {
tasks = task(this);
}
else {
tasks = task;
}
return new listr_1.Listr(tasks, options);
}
/** Report a error in process for error collection. */
report(error) {
var _a, _b;
/* istanbul ignore if */
if (error instanceof listr_error_interface_1.ListrError) {
for (const err of error.errors) {
this.errors.push(err);
this.task.message$ = { error: err.message || ((_a = this.task) === null || _a === void 0 ? void 0 : _a.title) || 'Task with no title.' };
}
}
else {
this.errors.push(error);
this.task.message$ = { error: error.message || ((_b = this.task) === null || _b === void 0 ? void 0 : _b.title) || 'Task with no title.' };
}
}
/** Skip current task. */
skip(message) {
var _a;
this.task.state$ = state_constants_1.ListrTaskState.SKIPPED;
if (message) {
this.task.message$ = { skip: message || ((_a = this.task) === null || _a === void 0 ? void 0 : _a.title) || 'Task with no title.' };
}
}
/** Get the number of retrying, else returns false */
isRetrying() {
return this.task.isRetrying() ? this.task.retry : { count: 0 };
}
/**
* Create a new Enquirer prompt using prompt options.
*
* Since process.stdout is controlled by Listr, this will passthrough all Enquirer data through internal stdout.
*/
async prompt(options) {
var _a;
return prompt_1.createPrompt.bind(this)(options, { ...(_a = this.options) === null || _a === void 0 ? void 0 : _a.injectWrapper });
}
/** Cancels the current prompt attach to this task. */
cancelPrompt(throwError = false) {
return prompt_1.destroyPrompt.bind(this)(throwError);
}
/**
* Pass stream of data to internal stdout.
*
* Since Listr2 takes control of process.stdout utilizing the default renderer, any data outputted to process.stdout
* will corupt its looks.
*
* This returns a fake stream to pass any stream inside Listr as task data.
*/
stdout() {
return through((chunk) => {
const pattern = new RegExp(clearline_regex_constants_1.CLEAR_LINE_REGEX, 'gmi');
chunk = chunk.toString();
chunk = chunk.replace(pattern, '');
chunk = chunk.replace(new RegExp(clearline_regex_constants_1.BELL_REGEX, 'gmi'), '');
if (chunk !== '') {
this.output = chunk;
}
});
}
/** Run this task. */
run(ctx) {
return this.task.run(ctx, this);
}
}
exports.TaskWrapper = TaskWrapper;

98
node_modules/listr2/dist/lib/task.d.ts generated vendored Normal file
View File

@@ -0,0 +1,98 @@
import { Subject } from 'rxjs';
import { TaskWrapper } from './task-wrapper';
import { ListrTaskState } from '../constants/state.constants';
import { PromptError } from '../interfaces/listr-error.interface';
import { ListrEvent, ListrOptions, ListrTask, ListrTaskResult } from '../interfaces/listr.interface';
import { ListrGetRendererOptions, ListrGetRendererTaskOptions, ListrRendererFactory } from '../interfaces/renderer.interface';
import { Listr } from '../listr';
import { PromptInstance } from '../utils/prompt.interface';
/**
* Create a task from the given set of variables and make it runnable.
*/
export declare class Task<Ctx, Renderer extends ListrRendererFactory> extends Subject<ListrEvent> {
listr: Listr<Ctx, any, any>;
tasks: ListrTask<Ctx, any>;
options: ListrOptions;
rendererOptions: ListrGetRendererOptions<Renderer>;
/** Unique id per task, randomly generated in the uuid v4 format */
id: string;
/** The current state of the task. */
state: string;
/** The task object itself, to further utilize it. */
task: (ctx: Ctx, task: TaskWrapper<Ctx, Renderer>) => void | ListrTaskResult<Ctx>;
/** Extend current task with multiple subtasks. */
subtasks: Task<Ctx, any>[];
/** Title of the task */
title?: string;
/** Untouched unchanged title of the task */
initialTitle?: string;
/** Output data from the task. */
output?: string;
/** Skip current task. */
skip: boolean | string | ((ctx: Ctx) => boolean | string | Promise<boolean | string>);
/** Current retry number of the task if retrying */
retry?: {
count: number;
withError?: any;
};
/**
* A channel for messages.
*
* This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
*/
message: {
/** Run time of the task, if it has been successfully resolved. */
duration?: number;
/** Error message of the task, if it has been failed. */
error?: string;
/** Skip message of the task, if it has been skipped. */
skip?: string;
/** Rollback message of the task, if the rollback finishes */
rollback?: string;
/** Retry messages */
retry?: {
count: number;
withError?: any;
};
};
/** Per task options for the current renderer of the task. */
rendererTaskOptions: ListrGetRendererTaskOptions<Renderer>;
/** This will be triggered each time a new render should happen. */
renderHook$: Subject<void>;
prompt: undefined | PromptInstance | PromptError;
private enabled;
private enabledFn;
constructor(listr: Listr<Ctx, any, any>, tasks: ListrTask<Ctx, any>, options: ListrOptions, rendererOptions: ListrGetRendererOptions<Renderer>);
set state$(state: ListrTaskState);
set output$(data: string);
set message$(data: Task<Ctx, Renderer>['message']);
set title$(title: string);
/**
* A function to check whether this task should run at all via enable.
*/
check(ctx: Ctx): Promise<void>;
/** Returns whether this task has subtasks. */
hasSubtasks(): boolean;
/** Returns whether this task is in progress. */
isPending(): boolean;
/** Returns whether this task is skipped. */
isSkipped(): boolean;
/** Returns whether this task has been completed. */
isCompleted(): boolean;
/** Returns whether this task has been failed. */
hasFailed(): boolean;
/** Returns whether this task has an active rollback task going on. */
isRollingBack(): boolean;
/** Returns whether the rollback action was successful. */
hasRolledBack(): boolean;
/** Returns whether this task has an actively retrying task going on. */
isRetrying(): boolean;
/** Returns whether enabled function resolves to true. */
isEnabled(): boolean;
/** Returns whether this task actually has a title. */
hasTitle(): boolean;
/** Returns whether this task has a prompt inside. */
isPrompt(): boolean;
/** Run the current task. */
run(context: Ctx, wrapper: TaskWrapper<Ctx, Renderer>): Promise<void>;
}

281
node_modules/listr2/dist/lib/task.js generated vendored Normal file
View File

@@ -0,0 +1,281 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Task = void 0;
const rxjs_1 = require("rxjs");
const stream_1 = require("stream");
const event_constants_1 = require("../constants/event.constants");
const state_constants_1 = require("../constants/state.constants");
const listr_error_interface_1 = require("../interfaces/listr-error.interface");
const listr_1 = require("../listr");
const assert_1 = require("../utils/assert");
const renderer_1 = require("../utils/renderer");
const uuid_1 = require("../utils/uuid");
/**
* Create a task from the given set of variables and make it runnable.
*/
class Task extends rxjs_1.Subject {
constructor(listr, tasks, options, rendererOptions) {
var _a, _b, _c, _d, _e, _f;
super();
this.listr = listr;
this.tasks = tasks;
this.options = options;
this.rendererOptions = rendererOptions;
/**
* A channel for messages.
*
* This requires a separate channel for messages like error, skip or runtime messages to further utilize in the renderers.
*/
this.message = {};
// this kind of randomness is enough for task ids
this.id = (0, uuid_1.generateUUID)();
this.title = (_a = this.tasks) === null || _a === void 0 ? void 0 : _a.title;
this.initialTitle = (_b = this.tasks) === null || _b === void 0 ? void 0 : _b.title;
this.task = this.tasks.task;
// parse functions
this.skip = (_d = (_c = this.tasks) === null || _c === void 0 ? void 0 : _c.skip) !== null && _d !== void 0 ? _d : false;
this.enabledFn = (_f = (_e = this.tasks) === null || _e === void 0 ? void 0 : _e.enabled) !== null && _f !== void 0 ? _f : true;
// task options
this.rendererTaskOptions = this.tasks.options;
this.renderHook$ = this.listr.renderHook$;
this.subscribe(() => {
this.renderHook$.next();
});
}
set state$(state) {
this.state = state;
this.next({
type: event_constants_1.ListrEventType.STATE,
data: state
});
// cancel the subtasks if this has already failed
if (this.hasSubtasks() && this.hasFailed()) {
for (const subtask of this.subtasks) {
if (subtask.state === state_constants_1.ListrTaskState.PENDING) {
subtask.state$ = state_constants_1.ListrTaskState.FAILED;
}
}
}
}
set output$(data) {
this.output = data;
this.next({
type: event_constants_1.ListrEventType.DATA,
data
});
}
set message$(data) {
this.message = { ...this.message, ...data };
this.next({
type: event_constants_1.ListrEventType.MESSAGE,
data
});
}
set title$(title) {
this.title = title;
this.next({
type: event_constants_1.ListrEventType.TITLE,
data: title
});
}
/**
* A function to check whether this task should run at all via enable.
*/
async check(ctx) {
// Check if a task is enabled or disabled
if (this.state === undefined) {
this.enabled = await (0, assert_1.assertFunctionOrSelf)(this.enabledFn, ctx);
this.next({
type: event_constants_1.ListrEventType.ENABLED,
data: this.enabled
});
}
}
/** Returns whether this task has subtasks. */
hasSubtasks() {
var _a;
return ((_a = this.subtasks) === null || _a === void 0 ? void 0 : _a.length) > 0;
}
/** Returns whether this task is in progress. */
isPending() {
return this.state === state_constants_1.ListrTaskState.PENDING;
}
/** Returns whether this task is skipped. */
isSkipped() {
return this.state === state_constants_1.ListrTaskState.SKIPPED;
}
/** Returns whether this task has been completed. */
isCompleted() {
return this.state === state_constants_1.ListrTaskState.COMPLETED;
}
/** Returns whether this task has been failed. */
hasFailed() {
return this.state === state_constants_1.ListrTaskState.FAILED;
}
/** Returns whether this task has an active rollback task going on. */
isRollingBack() {
return this.state === state_constants_1.ListrTaskState.ROLLING_BACK;
}
/** Returns whether the rollback action was successful. */
hasRolledBack() {
return this.state === state_constants_1.ListrTaskState.ROLLED_BACK;
}
/** Returns whether this task has an actively retrying task going on. */
isRetrying() {
return this.state === state_constants_1.ListrTaskState.RETRY;
}
/** Returns whether enabled function resolves to true. */
isEnabled() {
return this.enabled;
}
/** Returns whether this task actually has a title. */
hasTitle() {
return typeof (this === null || this === void 0 ? void 0 : this.title) === 'string';
}
/** Returns whether this task has a prompt inside. */
isPrompt() {
return this.prompt ? true : false;
}
/** Run the current task. */
async run(context, wrapper) {
var _a, _b, _c, _d, _e;
const handleResult = (result) => {
if (result instanceof listr_1.Listr) {
// Detect the subtask
// assign options
result.options = { ...this.options, ...result.options };
// switch to silent renderer since already rendering
const rendererClass = (0, renderer_1.getRenderer)('silent');
result.rendererClass = rendererClass.renderer;
result.renderHook$.subscribe(() => {
this.renderHook$.next();
});
// assign subtasks
this.subtasks = result.tasks;
this.next({ type: event_constants_1.ListrEventType.SUBTASK });
result = result.run(context);
}
else if (this.isPrompt()) {
// do nothing, it is already being handled
}
else if (result instanceof Promise) {
// Detect promise
result = result.then(handleResult);
}
else if (result instanceof stream_1.Readable) {
// Detect stream
result = new Promise((resolve, reject) => {
result.on('data', (data) => {
this.output$ = data.toString();
});
result.on('error', (error) => reject(error));
result.on('end', () => resolve(null));
});
}
else if (result instanceof rxjs_1.Observable) {
// Detect Observable
result = new Promise((resolve, reject) => {
result.subscribe({
next: (data) => {
this.output$ = data;
},
error: reject,
complete: resolve
});
});
}
return result;
};
const startTime = Date.now();
// finish the task first
this.state$ = state_constants_1.ListrTaskState.PENDING;
// check if this function wants to be skipped
const skipped = await (0, assert_1.assertFunctionOrSelf)(this.skip, context);
if (skipped) {
if (typeof skipped === 'string') {
this.message$ = { skip: skipped };
}
else if (this.hasTitle()) {
this.message$ = { skip: this.title };
}
else {
this.message$ = { skip: 'Skipped task without a title.' };
}
this.state$ = state_constants_1.ListrTaskState.SKIPPED;
return;
}
try {
// add retry functionality
const retryCount = ((_a = this.tasks) === null || _a === void 0 ? void 0 : _a.retry) && ((_b = this.tasks) === null || _b === void 0 ? void 0 : _b.retry) > 0 ? this.tasks.retry + 1 : 1;
for (let retries = 1; retries <= retryCount; retries++) {
try {
// handle the results
await handleResult(this.task(context, wrapper));
break;
}
catch (err) {
if (retries !== retryCount) {
this.retry = { count: retries, withError: err };
this.message$ = { retry: this.retry };
this.title$ = this.initialTitle;
this.output = undefined;
wrapper.report(err);
this.state$ = state_constants_1.ListrTaskState.RETRY;
}
else {
throw err;
}
}
}
if (this.isPending() || this.isRetrying()) {
this.message$ = { duration: Date.now() - startTime };
this.state$ = state_constants_1.ListrTaskState.COMPLETED;
}
}
catch (error) {
// catch prompt error, this was the best i could do without going crazy
if (this.prompt instanceof listr_error_interface_1.PromptError) {
// eslint-disable-next-line no-ex-assign
error = new Error(this.prompt.message);
}
// execute the task on error function
if ((_c = this.tasks) === null || _c === void 0 ? void 0 : _c.rollback) {
wrapper.report(error);
try {
this.state$ = state_constants_1.ListrTaskState.ROLLING_BACK;
await this.tasks.rollback(context, wrapper);
this.state$ = state_constants_1.ListrTaskState.ROLLED_BACK;
this.message$ = { rollback: this.title };
}
catch (err) {
this.state$ = state_constants_1.ListrTaskState.FAILED;
wrapper.report(err);
throw error;
}
if (((_d = this.listr.options) === null || _d === void 0 ? void 0 : _d.exitAfterRollback) !== false) {
// Do not exit when explicitly set to `false`
throw new Error(this.title);
}
}
else {
/* istanbul ignore if */
if (error instanceof listr_error_interface_1.ListrError) {
return;
}
// mark task as failed
this.state$ = state_constants_1.ListrTaskState.FAILED;
// report error
wrapper.report(error);
if (this.listr.options.exitOnError !== false && await (0, assert_1.assertFunctionOrSelf)((_e = this.tasks) === null || _e === void 0 ? void 0 : _e.exitOnError, context) !== false) {
// Do not exit when explicitly set to `false`
throw error;
}
}
}
finally {
// Mark the observable as completed
this.complete();
}
}
}
exports.Task = Task;