concurrently 6.5.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +82 -22
  2. package/dist/bin/concurrently.d.ts +2 -0
  3. package/dist/bin/concurrently.js +193 -0
  4. package/dist/bin/epilogue.d.ts +1 -0
  5. package/dist/bin/epilogue.js +69 -0
  6. package/dist/src/command-parser/command-parser.d.ts +19 -0
  7. package/dist/src/command-parser/command-parser.js +2 -0
  8. package/dist/src/command-parser/expand-npm-shortcut.d.ts +8 -0
  9. package/{src → dist/src}/command-parser/expand-npm-shortcut.js +10 -3
  10. package/dist/src/command-parser/expand-npm-wildcard.d.ts +13 -0
  11. package/dist/src/command-parser/expand-npm-wildcard.js +82 -0
  12. package/dist/src/command-parser/strip-quotes.d.ts +10 -0
  13. package/{src → dist/src}/command-parser/strip-quotes.js +10 -4
  14. package/dist/src/command.d.ts +101 -0
  15. package/{src → dist/src}/command.js +53 -29
  16. package/dist/src/completion-listener.d.ts +37 -0
  17. package/dist/src/completion-listener.js +60 -0
  18. package/dist/src/concurrently.d.ts +77 -0
  19. package/dist/src/concurrently.js +120 -0
  20. package/dist/src/defaults.d.ts +52 -0
  21. package/dist/src/defaults.js +58 -0
  22. package/dist/src/flow-control/flow-controller.d.ts +13 -0
  23. package/dist/src/flow-control/flow-controller.js +2 -0
  24. package/dist/src/flow-control/input-handler.d.ts +33 -0
  25. package/dist/src/flow-control/input-handler.js +73 -0
  26. package/dist/src/flow-control/kill-on-signal.d.ts +17 -0
  27. package/{src → dist/src}/flow-control/kill-on-signal.js +13 -11
  28. package/dist/src/flow-control/kill-others.d.ts +18 -0
  29. package/dist/src/flow-control/kill-others.js +35 -0
  30. package/dist/src/flow-control/log-error.d.ts +15 -0
  31. package/dist/src/flow-control/log-error.js +21 -0
  32. package/dist/src/flow-control/log-exit.d.ts +15 -0
  33. package/dist/src/flow-control/log-exit.js +19 -0
  34. package/dist/src/flow-control/log-output.d.ts +15 -0
  35. package/{src → dist/src}/flow-control/log-output.js +13 -5
  36. package/dist/src/flow-control/log-timings.d.ts +27 -0
  37. package/dist/src/flow-control/log-timings.js +88 -0
  38. package/dist/src/flow-control/restart-process.d.ts +22 -0
  39. package/dist/src/flow-control/restart-process.js +71 -0
  40. package/dist/src/get-spawn-opts.d.ts +30 -0
  41. package/dist/src/get-spawn-opts.js +11 -0
  42. package/dist/src/index.d.ts +69 -0
  43. package/dist/src/index.js +69 -0
  44. package/dist/src/logger.d.ts +72 -0
  45. package/{src → dist/src}/logger.js +77 -58
  46. package/dist/src/output-writer.d.ts +19 -0
  47. package/dist/src/output-writer.js +69 -0
  48. package/index.js +6 -68
  49. package/index.mjs +9 -0
  50. package/package.json +38 -11
  51. package/bin/concurrently.js +0 -186
  52. package/bin/concurrently.spec.js +0 -428
  53. package/bin/epilogue.txt +0 -46
  54. package/src/command-parser/expand-npm-shortcut.spec.js +0 -36
  55. package/src/command-parser/expand-npm-wildcard.js +0 -43
  56. package/src/command-parser/expand-npm-wildcard.spec.js +0 -87
  57. package/src/command-parser/strip-quotes.spec.js +0 -20
  58. package/src/command.spec.js +0 -275
  59. package/src/completion-listener.js +0 -39
  60. package/src/completion-listener.spec.js +0 -89
  61. package/src/concurrently.js +0 -116
  62. package/src/concurrently.spec.js +0 -199
  63. package/src/defaults.js +0 -35
  64. package/src/flow-control/base-handler.js +0 -16
  65. package/src/flow-control/base-handler.spec.js +0 -22
  66. package/src/flow-control/input-handler.js +0 -50
  67. package/src/flow-control/input-handler.spec.js +0 -113
  68. package/src/flow-control/kill-on-signal.spec.js +0 -79
  69. package/src/flow-control/kill-others.js +0 -38
  70. package/src/flow-control/kill-others.spec.js +0 -66
  71. package/src/flow-control/log-error.js +0 -18
  72. package/src/flow-control/log-error.spec.js +0 -40
  73. package/src/flow-control/log-exit.js +0 -11
  74. package/src/flow-control/log-exit.spec.js +0 -36
  75. package/src/flow-control/log-output.spec.js +0 -41
  76. package/src/flow-control/log-timings.js +0 -64
  77. package/src/flow-control/log-timings.spec.js +0 -137
  78. package/src/flow-control/restart-process.js +0 -56
  79. package/src/flow-control/restart-process.spec.js +0 -139
  80. package/src/get-spawn-opts.js +0 -16
  81. package/src/get-spawn-opts.spec.js +0 -30
  82. package/src/logger.spec.js +0 -318
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.InputHandler = void 0;
23
+ const Rx = __importStar(require("rxjs"));
24
+ const operators_1 = require("rxjs/operators");
25
+ const defaults = __importStar(require("../defaults"));
26
+ /**
27
+ * Sends input from concurrently through to commands.
28
+ *
29
+ * Input can start with a command identifier, in which case it will be sent to that specific command.
30
+ * For instance, `0:bla` will send `bla` to command at index `0`, and `server:stop` will send `stop`
31
+ * to command with name `server`.
32
+ *
33
+ * If the input doesn't start with a command identifier, it is then always sent to the default target.
34
+ */
35
+ class InputHandler {
36
+ constructor({ defaultInputTarget, inputStream, pauseInputStreamOnFinish, logger }) {
37
+ this.logger = logger;
38
+ this.defaultInputTarget = defaultInputTarget || defaults.defaultInputTarget;
39
+ this.inputStream = inputStream;
40
+ this.pauseInputStreamOnFinish = pauseInputStreamOnFinish !== false;
41
+ }
42
+ handle(commands) {
43
+ if (!this.inputStream) {
44
+ return { commands };
45
+ }
46
+ Rx.fromEvent(this.inputStream, 'data')
47
+ .pipe((0, operators_1.map)(data => data.toString()))
48
+ .subscribe(data => {
49
+ const dataParts = data.split(/:(.+)/);
50
+ const targetId = dataParts.length > 1 ? dataParts[0] : this.defaultInputTarget;
51
+ const input = dataParts[1] || data;
52
+ const command = commands.find(command => (command.name === targetId ||
53
+ command.index.toString() === targetId.toString()));
54
+ if (command && command.stdin) {
55
+ command.stdin.write(input);
56
+ }
57
+ else {
58
+ this.logger.logGlobalEvent(`Unable to find command ${targetId}, or it has no stdin open\n`);
59
+ }
60
+ });
61
+ return {
62
+ commands,
63
+ onFinish: () => {
64
+ if (this.pauseInputStreamOnFinish) {
65
+ // https://github.com/kimmobrunfeldt/concurrently/issues/252
66
+ this.inputStream.pause();
67
+ }
68
+ },
69
+ };
70
+ }
71
+ }
72
+ exports.InputHandler = InputHandler;
73
+ ;
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'events';
3
+ import { Command } from '../command';
4
+ import { FlowController } from './flow-controller';
5
+ /**
6
+ * Watches the main concurrently process for signals and sends the same signal down to each spawned
7
+ * command.
8
+ */
9
+ export declare class KillOnSignal implements FlowController {
10
+ private readonly process;
11
+ constructor({ process }: {
12
+ process: EventEmitter;
13
+ });
14
+ handle(commands: Command[]): {
15
+ commands: Command[];
16
+ };
17
+ }
@@ -1,14 +1,15 @@
1
- const { map } = require('rxjs/operators');
2
-
3
- const BaseHandler = require('./base-handler');
4
-
5
- module.exports = class KillOnSignal extends BaseHandler {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KillOnSignal = void 0;
4
+ const operators_1 = require("rxjs/operators");
5
+ /**
6
+ * Watches the main concurrently process for signals and sends the same signal down to each spawned
7
+ * command.
8
+ */
9
+ class KillOnSignal {
6
10
  constructor({ process }) {
7
- super();
8
-
9
11
  this.process = process;
10
12
  }
11
-
12
13
  handle(commands) {
13
14
  let caughtSignal;
14
15
  ['SIGINT', 'SIGTERM', 'SIGHUP'].forEach(signal => {
@@ -17,10 +18,9 @@ module.exports = class KillOnSignal extends BaseHandler {
17
18
  commands.forEach(command => command.kill(signal));
18
19
  });
19
20
  });
20
-
21
21
  return {
22
22
  commands: commands.map(command => {
23
- const closeStream = command.close.pipe(map(exitInfo => {
23
+ const closeStream = command.close.pipe((0, operators_1.map)(exitInfo => {
24
24
  const exitCode = caughtSignal === 'SIGINT' ? 0 : exitInfo.exitCode;
25
25
  return Object.assign({}, exitInfo, { exitCode });
26
26
  }));
@@ -32,4 +32,6 @@ module.exports = class KillOnSignal extends BaseHandler {
32
32
  })
33
33
  };
34
34
  }
35
- };
35
+ }
36
+ exports.KillOnSignal = KillOnSignal;
37
+ ;
@@ -0,0 +1,18 @@
1
+ import { Command } from '../command';
2
+ import { Logger } from '../logger';
3
+ import { FlowController } from './flow-controller';
4
+ export declare type ProcessCloseCondition = 'failure' | 'success';
5
+ /**
6
+ * Sends a SIGTERM signal to all commands when one of the exits with a matching condition.
7
+ */
8
+ export declare class KillOthers implements FlowController {
9
+ private readonly logger;
10
+ private readonly conditions;
11
+ constructor({ logger, conditions }: {
12
+ logger: Logger;
13
+ conditions: ProcessCloseCondition | ProcessCloseCondition[];
14
+ });
15
+ handle(commands: Command[]): {
16
+ commands: Command[];
17
+ };
18
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KillOthers = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const operators_1 = require("rxjs/operators");
9
+ /**
10
+ * Sends a SIGTERM signal to all commands when one of the exits with a matching condition.
11
+ */
12
+ class KillOthers {
13
+ constructor({ logger, conditions }) {
14
+ this.logger = logger;
15
+ this.conditions = lodash_1.default.castArray(conditions);
16
+ }
17
+ handle(commands) {
18
+ const conditions = this.conditions.filter(condition => (condition === 'failure' ||
19
+ condition === 'success'));
20
+ if (!conditions.length) {
21
+ return { commands };
22
+ }
23
+ 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))));
24
+ closeStates.forEach(closeState => closeState.subscribe(() => {
25
+ const killableCommands = commands.filter(command => command.killable);
26
+ if (killableCommands.length) {
27
+ this.logger.logGlobalEvent('Sending SIGTERM to other processes..');
28
+ killableCommands.forEach(command => command.kill());
29
+ }
30
+ }));
31
+ return { commands };
32
+ }
33
+ }
34
+ exports.KillOthers = KillOthers;
35
+ ;
@@ -0,0 +1,15 @@
1
+ import { Command } from '../command';
2
+ import { Logger } from '../logger';
3
+ import { FlowController } from './flow-controller';
4
+ /**
5
+ * Logs when commands failed executing, e.g. due to the executable not existing in the system.
6
+ */
7
+ export declare class LogError implements FlowController {
8
+ private readonly logger;
9
+ constructor({ logger }: {
10
+ logger: Logger;
11
+ });
12
+ handle(commands: Command[]): {
13
+ commands: Command[];
14
+ };
15
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogError = void 0;
4
+ /**
5
+ * Logs when commands failed executing, e.g. due to the executable not existing in the system.
6
+ */
7
+ class LogError {
8
+ constructor({ logger }) {
9
+ this.logger = logger;
10
+ }
11
+ handle(commands) {
12
+ commands.forEach(command => command.error.subscribe(event => {
13
+ this.logger.logCommandEvent(`Error occurred when executing command: ${command.command}`, command);
14
+ const errorText = String(event instanceof Error ? (event.stack || event) : event);
15
+ this.logger.logCommandEvent(errorText, command);
16
+ }));
17
+ return { commands };
18
+ }
19
+ }
20
+ exports.LogError = LogError;
21
+ ;
@@ -0,0 +1,15 @@
1
+ import { Command } from '../command';
2
+ import { Logger } from '../logger';
3
+ import { FlowController } from './flow-controller';
4
+ /**
5
+ * Logs the exit code/signal of commands.
6
+ */
7
+ export declare class LogExit implements FlowController {
8
+ private readonly logger;
9
+ constructor({ logger }: {
10
+ logger: Logger;
11
+ });
12
+ handle(commands: Command[]): {
13
+ commands: Command[];
14
+ };
15
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogExit = void 0;
4
+ /**
5
+ * Logs the exit code/signal of commands.
6
+ */
7
+ class LogExit {
8
+ constructor({ logger }) {
9
+ this.logger = logger;
10
+ }
11
+ handle(commands) {
12
+ commands.forEach(command => command.close.subscribe(({ exitCode }) => {
13
+ this.logger.logCommandEvent(`${command.command} exited with code ${exitCode}`, command);
14
+ }));
15
+ return { commands };
16
+ }
17
+ }
18
+ exports.LogExit = LogExit;
19
+ ;
@@ -0,0 +1,15 @@
1
+ import { Command } from '../command';
2
+ import { Logger } from '../logger';
3
+ import { FlowController } from './flow-controller';
4
+ /**
5
+ * Logs the stdout and stderr output of commands.
6
+ */
7
+ export declare class LogOutput implements FlowController {
8
+ private readonly logger;
9
+ constructor({ logger }: {
10
+ logger: Logger;
11
+ });
12
+ handle(commands: Command[]): {
13
+ commands: Command[];
14
+ };
15
+ }
@@ -1,12 +1,20 @@
1
- const BaseHandler = require('./base-handler');
2
-
3
- module.exports = class LogOutput extends BaseHandler {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogOutput = void 0;
4
+ /**
5
+ * Logs the stdout and stderr output of commands.
6
+ */
7
+ class LogOutput {
8
+ constructor({ logger }) {
9
+ this.logger = logger;
10
+ }
4
11
  handle(commands) {
5
12
  commands.forEach(command => {
6
13
  command.stdout.subscribe(text => this.logger.logCommandText(text.toString(), command));
7
14
  command.stderr.subscribe(text => this.logger.logCommandText(text.toString(), command));
8
15
  });
9
-
10
16
  return { commands };
11
17
  }
12
- };
18
+ }
19
+ exports.LogOutput = LogOutput;
20
+ ;
@@ -0,0 +1,27 @@
1
+ import { CloseEvent, Command } from '../command';
2
+ import { Logger } from '../logger';
3
+ import { FlowController } from './flow-controller';
4
+ interface TimingInfo {
5
+ name: string;
6
+ duration: string;
7
+ 'exit code': string | number;
8
+ killed: boolean;
9
+ command: string;
10
+ }
11
+ /**
12
+ * Logs timing information about commands as they start/stop and then a summary when all commands finish.
13
+ */
14
+ export declare class LogTimings implements FlowController {
15
+ static mapCloseEventToTimingInfo({ command, timings, killed, exitCode }: CloseEvent): TimingInfo;
16
+ private readonly logger?;
17
+ private readonly timestampFormat;
18
+ constructor({ logger, timestampFormat }: {
19
+ logger?: Logger;
20
+ timestampFormat?: string;
21
+ });
22
+ printExitInfoTimingTable(exitInfos: CloseEvent[]): CloseEvent[];
23
+ handle(commands: Command[]): {
24
+ commands: Command[];
25
+ };
26
+ }
27
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.LogTimings = void 0;
26
+ const format_1 = __importDefault(require("date-fns/format"));
27
+ const lodash_1 = __importDefault(require("lodash"));
28
+ const Rx = __importStar(require("rxjs"));
29
+ const operators_1 = require("rxjs/operators");
30
+ const defaults = __importStar(require("../defaults"));
31
+ /**
32
+ * Logs timing information about commands as they start/stop and then a summary when all commands finish.
33
+ */
34
+ class LogTimings {
35
+ constructor({ logger, timestampFormat = defaults.timestampFormat }) {
36
+ this.logger = logger;
37
+ this.timestampFormat = timestampFormat;
38
+ }
39
+ static mapCloseEventToTimingInfo({ command, timings, killed, exitCode }) {
40
+ const readableDurationMs = (timings.endDate.getTime() - timings.startDate.getTime()).toLocaleString();
41
+ return {
42
+ name: command.name,
43
+ duration: readableDurationMs,
44
+ 'exit code': exitCode,
45
+ killed,
46
+ command: command.command,
47
+ };
48
+ }
49
+ printExitInfoTimingTable(exitInfos) {
50
+ var _a, _b;
51
+ const exitInfoTable = (0, lodash_1.default)(exitInfos)
52
+ .sortBy(({ timings }) => timings.durationSeconds)
53
+ .reverse()
54
+ .map(LogTimings.mapCloseEventToTimingInfo)
55
+ .value();
56
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.logGlobalEvent('Timings:');
57
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.logTable(exitInfoTable);
58
+ return exitInfos;
59
+ }
60
+ ;
61
+ handle(commands) {
62
+ if (!this.logger) {
63
+ return { commands };
64
+ }
65
+ // individual process timings
66
+ commands.forEach(command => {
67
+ command.timer.subscribe(({ startDate, endDate }) => {
68
+ var _a, _b;
69
+ if (!endDate) {
70
+ const formattedStartDate = (0, format_1.default)(startDate, this.timestampFormat);
71
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.logCommandEvent(`${command.command} started at ${formattedStartDate}`, command);
72
+ }
73
+ else {
74
+ const durationMs = endDate.getTime() - startDate.getTime();
75
+ const formattedEndDate = (0, format_1.default)(endDate, this.timestampFormat);
76
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.logCommandEvent(`${command.command} stopped at ${formattedEndDate} after ${durationMs.toLocaleString()}ms`, command);
77
+ }
78
+ });
79
+ });
80
+ // overall summary timings
81
+ const closeStreams = commands.map(command => command.close);
82
+ const allProcessesClosed = Rx.merge(...closeStreams).pipe((0, operators_1.bufferCount)(closeStreams.length), (0, operators_1.take)(1));
83
+ allProcessesClosed.subscribe((exitInfos) => this.printExitInfoTimingTable(exitInfos));
84
+ return { commands };
85
+ }
86
+ }
87
+ exports.LogTimings = LogTimings;
88
+ ;
@@ -0,0 +1,22 @@
1
+ import * as Rx from 'rxjs';
2
+ import { Command } from '../command';
3
+ import { Logger } from '../logger';
4
+ import { FlowController } from './flow-controller';
5
+ /**
6
+ * Restarts commands that fail up to a defined number of times.
7
+ */
8
+ export declare class RestartProcess implements FlowController {
9
+ private readonly logger;
10
+ private readonly scheduler?;
11
+ readonly delay: number;
12
+ readonly tries: number;
13
+ constructor({ delay, tries, logger, scheduler }: {
14
+ delay?: number;
15
+ tries?: number;
16
+ logger: Logger;
17
+ scheduler?: Rx.SchedulerLike;
18
+ });
19
+ handle(commands: Command[]): {
20
+ commands: Command[];
21
+ };
22
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.RestartProcess = void 0;
23
+ const Rx = __importStar(require("rxjs"));
24
+ const operators_1 = require("rxjs/operators");
25
+ const defaults = __importStar(require("../defaults"));
26
+ /**
27
+ * Restarts commands that fail up to a defined number of times.
28
+ */
29
+ class RestartProcess {
30
+ constructor({ delay, tries, logger, scheduler }) {
31
+ this.logger = logger;
32
+ this.delay = delay != null ? +delay : defaults.restartDelay;
33
+ this.tries = tries != null ? +tries : defaults.restartTries;
34
+ this.tries = this.tries < 0 ? Infinity : this.tries;
35
+ this.scheduler = scheduler;
36
+ }
37
+ handle(commands) {
38
+ if (this.tries === 0) {
39
+ return { commands };
40
+ }
41
+ commands.map(command => command.close.pipe((0, operators_1.take)(this.tries), (0, operators_1.takeWhile)(({ exitCode }) => exitCode !== 0))).map((failure, index) => Rx.merge(
42
+ // Delay the emission (so that the restarts happen on time),
43
+ // explicitly telling the subscriber that a restart is needed
44
+ failure.pipe((0, operators_1.delay)(this.delay, this.scheduler), (0, operators_1.mapTo)(true)),
45
+ // Skip the first N emissions (as these would be duplicates of the above),
46
+ // meaning it will be empty because of success, or failed all N times,
47
+ // and no more restarts should be attempted.
48
+ failure.pipe((0, operators_1.skip)(this.tries), (0, operators_1.mapTo)(false), (0, operators_1.defaultIfEmpty)(false))).subscribe(restart => {
49
+ const command = commands[index];
50
+ if (restart) {
51
+ this.logger.logCommandEvent(`${command.command} restarted`, command);
52
+ command.start();
53
+ }
54
+ }));
55
+ return {
56
+ commands: commands.map(command => {
57
+ const closeStream = command.close.pipe((0, operators_1.filter)(({ exitCode }, emission) => {
58
+ // We let all success codes pass, and failures only after restarting won't happen again
59
+ return exitCode === 0 || emission >= this.tries;
60
+ }));
61
+ return new Proxy(command, {
62
+ get(target, prop) {
63
+ return prop === 'close' ? closeStream : target[prop];
64
+ }
65
+ });
66
+ })
67
+ };
68
+ }
69
+ }
70
+ exports.RestartProcess = RestartProcess;
71
+ ;
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" />
2
+ import { SpawnOptions } from 'child_process';
3
+ import supportsColor from 'supports-color';
4
+ export declare const getSpawnOpts: ({ colorSupport, cwd, process, raw, env, }: {
5
+ /**
6
+ * What the color support of the spawned processes should be.
7
+ * If set to `false`, then no colors should be output.
8
+ *
9
+ * Defaults to whatever the terminal's stdout support is.
10
+ */
11
+ colorSupport?: Pick<supportsColor.supportsColor.Level, 'level'> | false;
12
+ /**
13
+ * The NodeJS process.
14
+ */
15
+ process?: Pick<NodeJS.Process, 'cwd' | 'platform' | 'env'>;
16
+ /**
17
+ * A custom working directory to spawn processes in.
18
+ * Defaults to `process.cwd()`.
19
+ */
20
+ cwd?: string;
21
+ /**
22
+ * Whether to customize the options for spawning processes in raw mode.
23
+ * Defaults to false.
24
+ */
25
+ raw?: boolean;
26
+ /**
27
+ * Map of custom environment variables to include in the spawn options.
28
+ */
29
+ env?: Record<string, any>;
30
+ }) => SpawnOptions;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSpawnOpts = void 0;
7
+ const supports_color_1 = __importDefault(require("supports-color"));
8
+ const getSpawnOpts = ({ colorSupport = supports_color_1.default.stdout, cwd, process = global.process, raw = false, env = {}, }) => Object.assign({
9
+ cwd: cwd || process.cwd(),
10
+ }, raw && { stdio: 'inherit' }, /^win/.test(process.platform) && { detached: false }, { env: Object.assign(colorSupport ? { FORCE_COLOR: colorSupport.level } : {}, process.env, env) });
11
+ exports.getSpawnOpts = getSpawnOpts;
@@ -0,0 +1,69 @@
1
+ /// <reference types="node" />
2
+ import { Readable } from 'stream';
3
+ import { CloseEvent, Command, CommandIdentifier, TimerEvent } from './command';
4
+ import { concurrently, ConcurrentlyCommandInput, ConcurrentlyOptions as BaseConcurrentlyOptions, ConcurrentlyResult } from './concurrently';
5
+ import { FlowController } from './flow-control/flow-controller';
6
+ import { InputHandler } from './flow-control/input-handler';
7
+ import { KillOnSignal } from './flow-control/kill-on-signal';
8
+ import { KillOthers, ProcessCloseCondition } from './flow-control/kill-others';
9
+ import { LogError } from './flow-control/log-error';
10
+ import { LogExit } from './flow-control/log-exit';
11
+ import { LogOutput } from './flow-control/log-output';
12
+ import { LogTimings } from './flow-control/log-timings';
13
+ import { RestartProcess } from './flow-control/restart-process';
14
+ import { Logger } from './logger';
15
+ export declare type ConcurrentlyOptions = BaseConcurrentlyOptions & {
16
+ /**
17
+ * Which command(s) should have their output hidden.
18
+ */
19
+ hide?: CommandIdentifier | CommandIdentifier[];
20
+ /**
21
+ * The prefix format to use when logging a command's output.
22
+ * Defaults to the command's index.
23
+ */
24
+ prefix?: string;
25
+ /**
26
+ * How many characters should a prefix have at most, used when the prefix format is `command`.
27
+ */
28
+ prefixLength?: number;
29
+ /**
30
+ * Whether output should be formatted to include prefixes and whether "event" logs will be logged.
31
+ */
32
+ raw?: boolean;
33
+ /**
34
+ * Date format used when logging date/time.
35
+ * @see https://date-fns.org/v2.0.1/docs/format
36
+ */
37
+ timestampFormat?: string;
38
+ defaultInputTarget?: CommandIdentifier;
39
+ inputStream?: Readable;
40
+ handleInput?: boolean;
41
+ pauseInputStreamOnFinish?: boolean;
42
+ /**
43
+ * How much time in milliseconds to wait before restarting a command.
44
+ *
45
+ * @see RestartProcess
46
+ */
47
+ restartDelay?: number;
48
+ /**
49
+ * How many times commands should be restarted when they exit with a failure.
50
+ *
51
+ * @see RestartProcess
52
+ */
53
+ restartTries?: number;
54
+ /**
55
+ * Under which condition(s) should other commands be killed when the first one exits.
56
+ *
57
+ * @see KillOthers
58
+ */
59
+ killOthers?: ProcessCloseCondition | ProcessCloseCondition[];
60
+ /**
61
+ * Whether to output timing information for processes.
62
+ *
63
+ * @see LogTimings
64
+ */
65
+ timings?: boolean;
66
+ };
67
+ declare const _default: (commands: ConcurrentlyCommandInput[], options?: Partial<ConcurrentlyOptions>) => ConcurrentlyResult;
68
+ export default _default;
69
+ export { concurrently, ConcurrentlyCommandInput, ConcurrentlyResult, Logger, Command, CloseEvent, TimerEvent, CommandIdentifier, FlowController, InputHandler, KillOnSignal, KillOthers, LogError, LogExit, LogOutput, LogTimings, RestartProcess, };