first commit
This commit is contained in:
13
node_modules/concurrently/dist/src/flow-control/flow-controller.d.ts
generated
vendored
Normal file
13
node_modules/concurrently/dist/src/flow-control/flow-controller.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Command } from '../command';
|
||||
/**
|
||||
* Interface for a class that controls and/or watches the behavior of commands.
|
||||
*
|
||||
* This may include logging their output, creating interactions between them, or changing when they
|
||||
* actually finish.
|
||||
*/
|
||||
export interface FlowController {
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
onFinish?: () => void;
|
||||
};
|
||||
}
|
||||
2
node_modules/concurrently/dist/src/flow-control/flow-controller.js
generated
vendored
Normal file
2
node_modules/concurrently/dist/src/flow-control/flow-controller.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
30
node_modules/concurrently/dist/src/flow-control/input-handler.d.ts
generated
vendored
Normal file
30
node_modules/concurrently/dist/src/flow-control/input-handler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/// <reference types="node" />
|
||||
import { Readable } from 'stream';
|
||||
import { Command, CommandIdentifier } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
/**
|
||||
* Sends input from concurrently through to commands.
|
||||
*
|
||||
* Input can start with a command identifier, in which case it will be sent to that specific command.
|
||||
* For instance, `0:bla` will send `bla` to command at index `0`, and `server:stop` will send `stop`
|
||||
* to command with name `server`.
|
||||
*
|
||||
* If the input doesn't start with a command identifier, it is then always sent to the default target.
|
||||
*/
|
||||
export declare class InputHandler implements FlowController {
|
||||
private readonly logger;
|
||||
private readonly defaultInputTarget;
|
||||
private readonly inputStream?;
|
||||
private readonly pauseInputStreamOnFinish;
|
||||
constructor({ defaultInputTarget, inputStream, pauseInputStreamOnFinish, logger, }: {
|
||||
inputStream?: Readable;
|
||||
logger: Logger;
|
||||
defaultInputTarget?: CommandIdentifier;
|
||||
pauseInputStreamOnFinish?: boolean;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
onFinish?: () => void | undefined;
|
||||
};
|
||||
}
|
||||
90
node_modules/concurrently/dist/src/flow-control/input-handler.js
generated
vendored
Normal file
90
node_modules/concurrently/dist/src/flow-control/input-handler.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InputHandler = void 0;
|
||||
const Rx = __importStar(require("rxjs"));
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const defaults = __importStar(require("../defaults"));
|
||||
/**
|
||||
* Sends input from concurrently through to commands.
|
||||
*
|
||||
* Input can start with a command identifier, in which case it will be sent to that specific command.
|
||||
* For instance, `0:bla` will send `bla` to command at index `0`, and `server:stop` will send `stop`
|
||||
* to command with name `server`.
|
||||
*
|
||||
* If the input doesn't start with a command identifier, it is then always sent to the default target.
|
||||
*/
|
||||
class InputHandler {
|
||||
constructor({ defaultInputTarget, inputStream, pauseInputStreamOnFinish, logger, }) {
|
||||
this.logger = logger;
|
||||
this.defaultInputTarget = defaultInputTarget || defaults.defaultInputTarget;
|
||||
this.inputStream = inputStream;
|
||||
this.pauseInputStreamOnFinish = pauseInputStreamOnFinish !== false;
|
||||
}
|
||||
handle(commands) {
|
||||
const { inputStream } = this;
|
||||
if (!inputStream) {
|
||||
return { commands };
|
||||
}
|
||||
const commandsMap = new Map();
|
||||
for (const command of commands) {
|
||||
commandsMap.set(command.index.toString(), command);
|
||||
commandsMap.set(command.name, command);
|
||||
}
|
||||
Rx.fromEvent(inputStream, 'data')
|
||||
.pipe((0, operators_1.map)((data) => String(data)))
|
||||
.subscribe((data) => {
|
||||
let command, input;
|
||||
const dataParts = data.split(/:(.+)/s);
|
||||
let target = dataParts[0];
|
||||
if (dataParts.length > 1 && (command = commandsMap.get(target))) {
|
||||
input = dataParts[1];
|
||||
}
|
||||
else {
|
||||
// If `target` does not match a registered command,
|
||||
// fallback to `defaultInputTarget` and forward the whole input data
|
||||
target = this.defaultInputTarget.toString();
|
||||
command = commandsMap.get(target);
|
||||
input = data;
|
||||
}
|
||||
if (command && command.stdin) {
|
||||
command.stdin.write(input);
|
||||
}
|
||||
else {
|
||||
this.logger.logGlobalEvent(`Unable to find command "${target}", or it has no stdin open\n`);
|
||||
}
|
||||
});
|
||||
return {
|
||||
commands,
|
||||
onFinish: () => {
|
||||
if (this.pauseInputStreamOnFinish) {
|
||||
// https://github.com/kimmobrunfeldt/concurrently/issues/252
|
||||
inputStream.pause();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.InputHandler = InputHandler;
|
||||
17
node_modules/concurrently/dist/src/flow-control/kill-on-signal.d.ts
generated
vendored
Normal file
17
node_modules/concurrently/dist/src/flow-control/kill-on-signal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference types="node" />
|
||||
import EventEmitter from 'events';
|
||||
import { Command } from '../command';
|
||||
import { FlowController } from './flow-controller';
|
||||
/**
|
||||
* Watches the main concurrently process for signals and sends the same signal down to each spawned
|
||||
* command.
|
||||
*/
|
||||
export declare class KillOnSignal implements FlowController {
|
||||
private readonly process;
|
||||
constructor({ process }: {
|
||||
process: EventEmitter;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
};
|
||||
}
|
||||
36
node_modules/concurrently/dist/src/flow-control/kill-on-signal.js
generated
vendored
Normal file
36
node_modules/concurrently/dist/src/flow-control/kill-on-signal.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KillOnSignal = void 0;
|
||||
const operators_1 = require("rxjs/operators");
|
||||
/**
|
||||
* Watches the main concurrently process for signals and sends the same signal down to each spawned
|
||||
* command.
|
||||
*/
|
||||
class KillOnSignal {
|
||||
constructor({ process }) {
|
||||
this.process = process;
|
||||
}
|
||||
handle(commands) {
|
||||
let caughtSignal;
|
||||
['SIGINT', 'SIGTERM', 'SIGHUP'].forEach((signal) => {
|
||||
this.process.on(signal, () => {
|
||||
caughtSignal = signal;
|
||||
commands.forEach((command) => command.kill(signal));
|
||||
});
|
||||
});
|
||||
return {
|
||||
commands: commands.map((command) => {
|
||||
const closeStream = command.close.pipe((0, operators_1.map)((exitInfo) => {
|
||||
const exitCode = caughtSignal === 'SIGINT' ? 0 : exitInfo.exitCode;
|
||||
return { ...exitInfo, exitCode };
|
||||
}));
|
||||
return new Proxy(command, {
|
||||
get(target, prop) {
|
||||
return prop === 'close' ? closeStream : target[prop];
|
||||
},
|
||||
});
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.KillOnSignal = KillOnSignal;
|
||||
20
node_modules/concurrently/dist/src/flow-control/kill-others.d.ts
generated
vendored
Normal file
20
node_modules/concurrently/dist/src/flow-control/kill-others.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Command } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
export type ProcessCloseCondition = 'failure' | 'success';
|
||||
/**
|
||||
* Sends a SIGTERM signal to all commands when one of the commands exits with a matching condition.
|
||||
*/
|
||||
export declare class KillOthers implements FlowController {
|
||||
private readonly logger;
|
||||
private readonly conditions;
|
||||
private readonly killSignal;
|
||||
constructor({ logger, conditions, killSignal, }: {
|
||||
logger: Logger;
|
||||
conditions: ProcessCloseCondition | ProcessCloseCondition[];
|
||||
killSignal: string | undefined;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
};
|
||||
}
|
||||
35
node_modules/concurrently/dist/src/flow-control/kill-others.js
generated
vendored
Normal file
35
node_modules/concurrently/dist/src/flow-control/kill-others.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KillOthers = void 0;
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const command_1 = require("../command");
|
||||
/**
|
||||
* Sends a SIGTERM signal to all commands when one of the commands exits with a matching condition.
|
||||
*/
|
||||
class KillOthers {
|
||||
constructor({ logger, conditions, killSignal, }) {
|
||||
this.logger = logger;
|
||||
this.conditions = lodash_1.default.castArray(conditions);
|
||||
this.killSignal = killSignal;
|
||||
}
|
||||
handle(commands) {
|
||||
const conditions = this.conditions.filter((condition) => condition === 'failure' || condition === 'success');
|
||||
if (!conditions.length) {
|
||||
return { commands };
|
||||
}
|
||||
const closeStates = commands.map((command) => command.close.pipe((0, operators_1.map)(({ exitCode }) => exitCode === 0 ? 'success' : 'failure'), (0, operators_1.filter)((state) => conditions.includes(state))));
|
||||
closeStates.forEach((closeState) => closeState.subscribe(() => {
|
||||
const killableCommands = commands.filter((command) => command_1.Command.canKill(command));
|
||||
if (killableCommands.length) {
|
||||
this.logger.logGlobalEvent(`Sending ${this.killSignal || 'SIGTERM'} to other processes..`);
|
||||
killableCommands.forEach((command) => command.kill(this.killSignal));
|
||||
}
|
||||
}));
|
||||
return { commands };
|
||||
}
|
||||
}
|
||||
exports.KillOthers = KillOthers;
|
||||
15
node_modules/concurrently/dist/src/flow-control/log-error.d.ts
generated
vendored
Normal file
15
node_modules/concurrently/dist/src/flow-control/log-error.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Command } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
/**
|
||||
* Logs when commands failed executing, e.g. due to the executable not existing in the system.
|
||||
*/
|
||||
export declare class LogError implements FlowController {
|
||||
private readonly logger;
|
||||
constructor({ logger }: {
|
||||
logger: Logger;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
};
|
||||
}
|
||||
20
node_modules/concurrently/dist/src/flow-control/log-error.js
generated
vendored
Normal file
20
node_modules/concurrently/dist/src/flow-control/log-error.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LogError = void 0;
|
||||
/**
|
||||
* Logs when commands failed executing, e.g. due to the executable not existing in the system.
|
||||
*/
|
||||
class LogError {
|
||||
constructor({ logger }) {
|
||||
this.logger = logger;
|
||||
}
|
||||
handle(commands) {
|
||||
commands.forEach((command) => command.error.subscribe((event) => {
|
||||
this.logger.logCommandEvent(`Error occurred when executing command: ${command.command}`, command);
|
||||
const errorText = String(event instanceof Error ? event.stack || event : event);
|
||||
this.logger.logCommandEvent(errorText, command);
|
||||
}));
|
||||
return { commands };
|
||||
}
|
||||
}
|
||||
exports.LogError = LogError;
|
||||
15
node_modules/concurrently/dist/src/flow-control/log-exit.d.ts
generated
vendored
Normal file
15
node_modules/concurrently/dist/src/flow-control/log-exit.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Command } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
/**
|
||||
* Logs the exit code/signal of commands.
|
||||
*/
|
||||
export declare class LogExit implements FlowController {
|
||||
private readonly logger;
|
||||
constructor({ logger }: {
|
||||
logger: Logger;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
};
|
||||
}
|
||||
18
node_modules/concurrently/dist/src/flow-control/log-exit.js
generated
vendored
Normal file
18
node_modules/concurrently/dist/src/flow-control/log-exit.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LogExit = void 0;
|
||||
/**
|
||||
* Logs the exit code/signal of commands.
|
||||
*/
|
||||
class LogExit {
|
||||
constructor({ logger }) {
|
||||
this.logger = logger;
|
||||
}
|
||||
handle(commands) {
|
||||
commands.forEach((command) => command.close.subscribe(({ exitCode }) => {
|
||||
this.logger.logCommandEvent(`${command.command} exited with code ${exitCode}`, command);
|
||||
}));
|
||||
return { commands };
|
||||
}
|
||||
}
|
||||
exports.LogExit = LogExit;
|
||||
15
node_modules/concurrently/dist/src/flow-control/log-output.d.ts
generated
vendored
Normal file
15
node_modules/concurrently/dist/src/flow-control/log-output.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Command } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
/**
|
||||
* Logs the stdout and stderr output of commands.
|
||||
*/
|
||||
export declare class LogOutput implements FlowController {
|
||||
private readonly logger;
|
||||
constructor({ logger }: {
|
||||
logger: Logger;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
};
|
||||
}
|
||||
19
node_modules/concurrently/dist/src/flow-control/log-output.js
generated
vendored
Normal file
19
node_modules/concurrently/dist/src/flow-control/log-output.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LogOutput = void 0;
|
||||
/**
|
||||
* Logs the stdout and stderr output of commands.
|
||||
*/
|
||||
class LogOutput {
|
||||
constructor({ logger }) {
|
||||
this.logger = logger;
|
||||
}
|
||||
handle(commands) {
|
||||
commands.forEach((command) => {
|
||||
command.stdout.subscribe((text) => this.logger.logCommandText(text.toString(), command));
|
||||
command.stderr.subscribe((text) => this.logger.logCommandText(text.toString(), command));
|
||||
});
|
||||
return { commands };
|
||||
}
|
||||
}
|
||||
exports.LogOutput = LogOutput;
|
||||
31
node_modules/concurrently/dist/src/flow-control/log-timings.d.ts
generated
vendored
Normal file
31
node_modules/concurrently/dist/src/flow-control/log-timings.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { CloseEvent, Command } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
type TimingInfo = {
|
||||
name: string;
|
||||
duration: string;
|
||||
'exit code': string | number;
|
||||
killed: boolean;
|
||||
command: string;
|
||||
};
|
||||
/**
|
||||
* Logs timing information about commands as they start/stop and then a summary when all commands finish.
|
||||
*/
|
||||
export declare class LogTimings implements FlowController {
|
||||
static mapCloseEventToTimingInfo({ command, timings, killed, exitCode, }: CloseEvent): TimingInfo;
|
||||
private readonly logger?;
|
||||
private readonly timestampFormat;
|
||||
constructor({ logger, timestampFormat, }: {
|
||||
logger?: Logger;
|
||||
timestampFormat?: string;
|
||||
});
|
||||
private printExitInfoTimingTable;
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
onFinish?: undefined;
|
||||
} | {
|
||||
commands: Command[];
|
||||
onFinish: () => void;
|
||||
};
|
||||
}
|
||||
export {};
|
||||
92
node_modules/concurrently/dist/src/flow-control/log-timings.js
generated
vendored
Normal file
92
node_modules/concurrently/dist/src/flow-control/log-timings.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LogTimings = void 0;
|
||||
const assert = __importStar(require("assert"));
|
||||
const format_1 = __importDefault(require("date-fns/format"));
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
const Rx = __importStar(require("rxjs"));
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const defaults = __importStar(require("../defaults"));
|
||||
/**
|
||||
* Logs timing information about commands as they start/stop and then a summary when all commands finish.
|
||||
*/
|
||||
class LogTimings {
|
||||
static mapCloseEventToTimingInfo({ command, timings, killed, exitCode, }) {
|
||||
const readableDurationMs = (timings.endDate.getTime() - timings.startDate.getTime()).toLocaleString();
|
||||
return {
|
||||
name: command.name,
|
||||
duration: readableDurationMs,
|
||||
'exit code': exitCode,
|
||||
killed,
|
||||
command: command.command,
|
||||
};
|
||||
}
|
||||
constructor({ logger, timestampFormat = defaults.timestampFormat, }) {
|
||||
this.logger = logger;
|
||||
this.timestampFormat = timestampFormat;
|
||||
}
|
||||
printExitInfoTimingTable(exitInfos) {
|
||||
assert.ok(this.logger);
|
||||
const exitInfoTable = (0, lodash_1.default)(exitInfos)
|
||||
.sortBy(({ timings }) => timings.durationSeconds)
|
||||
.reverse()
|
||||
.map(LogTimings.mapCloseEventToTimingInfo)
|
||||
.value();
|
||||
this.logger.logGlobalEvent('Timings:');
|
||||
this.logger.logTable(exitInfoTable);
|
||||
return exitInfos;
|
||||
}
|
||||
handle(commands) {
|
||||
const { logger } = this;
|
||||
if (!logger) {
|
||||
return { commands };
|
||||
}
|
||||
// individual process timings
|
||||
commands.forEach((command) => {
|
||||
command.timer.subscribe(({ startDate, endDate }) => {
|
||||
if (!endDate) {
|
||||
const formattedStartDate = (0, format_1.default)(startDate, this.timestampFormat);
|
||||
logger.logCommandEvent(`${command.command} started at ${formattedStartDate}`, command);
|
||||
}
|
||||
else {
|
||||
const durationMs = endDate.getTime() - startDate.getTime();
|
||||
const formattedEndDate = (0, format_1.default)(endDate, this.timestampFormat);
|
||||
logger.logCommandEvent(`${command.command} stopped at ${formattedEndDate} after ${durationMs.toLocaleString()}ms`, command);
|
||||
}
|
||||
});
|
||||
});
|
||||
// overall summary timings
|
||||
const closeStreams = commands.map((command) => command.close);
|
||||
const finished = new Rx.Subject();
|
||||
const allProcessesClosed = Rx.merge(...closeStreams).pipe((0, operators_1.bufferCount)(closeStreams.length), (0, operators_1.take)(1), (0, operators_1.combineLatestWith)(finished));
|
||||
allProcessesClosed.subscribe(([exitInfos]) => this.printExitInfoTimingTable(exitInfos));
|
||||
return { commands, onFinish: () => finished.next() };
|
||||
}
|
||||
}
|
||||
exports.LogTimings = LogTimings;
|
||||
22
node_modules/concurrently/dist/src/flow-control/restart-process.d.ts
generated
vendored
Normal file
22
node_modules/concurrently/dist/src/flow-control/restart-process.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import * as Rx from 'rxjs';
|
||||
import { Command } from '../command';
|
||||
import { Logger } from '../logger';
|
||||
import { FlowController } from './flow-controller';
|
||||
/**
|
||||
* Restarts commands that fail up to a defined number of times.
|
||||
*/
|
||||
export declare class RestartProcess implements FlowController {
|
||||
private readonly logger;
|
||||
private readonly scheduler?;
|
||||
readonly delay: number;
|
||||
readonly tries: number;
|
||||
constructor({ delay, tries, logger, scheduler, }: {
|
||||
delay?: number;
|
||||
tries?: number;
|
||||
logger: Logger;
|
||||
scheduler?: Rx.SchedulerLike;
|
||||
});
|
||||
handle(commands: Command[]): {
|
||||
commands: Command[];
|
||||
};
|
||||
}
|
||||
76
node_modules/concurrently/dist/src/flow-control/restart-process.js
generated
vendored
Normal file
76
node_modules/concurrently/dist/src/flow-control/restart-process.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RestartProcess = void 0;
|
||||
const Rx = __importStar(require("rxjs"));
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const defaults = __importStar(require("../defaults"));
|
||||
/**
|
||||
* Restarts commands that fail up to a defined number of times.
|
||||
*/
|
||||
class RestartProcess {
|
||||
constructor({ delay, tries, logger, scheduler, }) {
|
||||
this.logger = logger;
|
||||
this.delay = delay != null ? +delay : defaults.restartDelay;
|
||||
this.tries = tries != null ? +tries : defaults.restartTries;
|
||||
this.tries = this.tries < 0 ? Infinity : this.tries;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
handle(commands) {
|
||||
if (this.tries === 0) {
|
||||
return { commands };
|
||||
}
|
||||
commands
|
||||
.map((command) => command.close.pipe((0, operators_1.take)(this.tries), (0, operators_1.takeWhile)(({ exitCode }) => exitCode !== 0)))
|
||||
.map((failure, index) => Rx.merge(
|
||||
// Delay the emission (so that the restarts happen on time),
|
||||
// explicitly telling the subscriber that a restart is needed
|
||||
failure.pipe((0, operators_1.delay)(this.delay, this.scheduler), (0, operators_1.map)(() => true)),
|
||||
// Skip the first N emissions (as these would be duplicates of the above),
|
||||
// meaning it will be empty because of success, or failed all N times,
|
||||
// and no more restarts should be attempted.
|
||||
failure.pipe((0, operators_1.skip)(this.tries), (0, operators_1.map)(() => false), (0, operators_1.defaultIfEmpty)(false))).subscribe((restart) => {
|
||||
const command = commands[index];
|
||||
if (restart) {
|
||||
this.logger.logCommandEvent(`${command.command} restarted`, command);
|
||||
command.start();
|
||||
}
|
||||
}));
|
||||
return {
|
||||
commands: commands.map((command) => {
|
||||
const closeStream = command.close.pipe((0, operators_1.filter)(({ exitCode }, emission) => {
|
||||
// We let all success codes pass, and failures only after restarting won't happen again
|
||||
return exitCode === 0 || emission >= this.tries;
|
||||
}));
|
||||
return new Proxy(command, {
|
||||
get(target, prop) {
|
||||
return prop === 'close' ? closeStream : target[prop];
|
||||
},
|
||||
});
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.RestartProcess = RestartProcess;
|
||||
Reference in New Issue
Block a user