New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

batch-cluster

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

batch-cluster - npm Package Compare versions

Comparing version 7.1.0 to 7.2.0

4

CHANGELOG.md

@@ -21,2 +21,6 @@ # Changelog

## v7.2.0
- 📦 Upgrade all dev dependencies. Pulling in new TypeScript 4.4 required [redoing all node imports](https://github.com/microsoft/TypeScript/issues/46027#issuecomment-926019016).
## v7.1.0

@@ -23,0 +27,0 @@

2

dist/Async.d.ts

@@ -8,3 +8,3 @@ export declare function delay(millis: number, unref?: boolean): Promise<void>;

/**
* Return a thunk that will call the underlying thunk at most every `minDelayMs`
* @return a thunk that will call the underlying thunk at most every `minDelayMs`
* milliseconds. The thunk will accept a boolean, that, when set, will force the

@@ -11,0 +11,0 @@ * underlying thunk to be called (mostly useful for tests)

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = exports.ratelimit = exports.until = exports.delay = void 0;
const timers_1 = require("timers");
const timers_1 = __importDefault(require("timers"));
function delay(millis, unref = false) {
return new Promise((resolve) => {
const t = timers_1.setTimeout(() => resolve(), millis);
const t = timers_1.default.setTimeout(() => resolve(), millis);
if (unref)

@@ -33,3 +36,3 @@ t.unref();

/**
* Return a thunk that will call the underlying thunk at most every `minDelayMs`
* @return a thunk that will call the underlying thunk at most every `minDelayMs`
* milliseconds. The thunk will accept a boolean, that, when set, will force the

@@ -58,4 +61,4 @@ * underlying thunk to be called (mostly useful for tests)

if (lastTimeout != null)
clearTimeout(lastTimeout);
lastTimeout = timers_1.setTimeout(f, timeoutMs);
timers_1.default.clearTimeout(lastTimeout);
lastTimeout = timers_1.default.setTimeout(f, timeoutMs);
};

@@ -62,0 +65,0 @@ }

/// <reference types="node" />
import { ChildProcess } from "child_process";
import child_process from "child_process";
import { BatchClusterEmitter } from "./BatchClusterEmitter";

@@ -8,10 +8,11 @@ import { AllOpts, BatchClusterOptions } from "./BatchClusterOptions";

import { Deferred } from "./Deferred";
import { Parser } from "./Parser";
import { Task } from "./Task";
export { BatchClusterOptions } from "./BatchClusterOptions";
export { BatchProcessOptions } from "./BatchProcessOptions";
export { Deferred } from "./Deferred";
export * from "./Logger";
export { Parser, SimpleParser } from "./Parser";
export { SimpleParser } from "./Parser";
export { kill, pidExists, pids } from "./Pids";
export { Task } from "./Task";
export type { BatchProcessOptions, Parser };
/**

@@ -26,3 +27,3 @@ * These are required parameters for a given BatchCluster.

*/
readonly processFactory: () => ChildProcess | Promise<ChildProcess>;
readonly processFactory: () => child_process.ChildProcess | Promise<child_process.ChildProcess>;
}

@@ -48,3 +49,3 @@ /**

private readonly tasks;
private onIdleInterval?;
private onIdleInterval;
private readonly startErrorRate;

@@ -51,0 +52,0 @@ private _spawnedProcs;

@@ -12,6 +12,9 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchCluster = exports.Task = exports.pids = exports.pidExists = exports.kill = exports.SimpleParser = exports.Deferred = exports.BatchClusterOptions = void 0;
const _p = require("process");
const timers_1 = require("timers");
const process_1 = __importDefault(require("process"));
const timers_1 = __importDefault(require("timers"));
const Array_1 = require("./Array");

@@ -62,5 +65,5 @@ const BatchClusterEmitter_1 = require("./BatchClusterEmitter");

this.exitListener = () => this.end(false);
this.options = Object.freeze(BatchClusterOptions_1.verifyOptions(opts));
this.options = Object.freeze((0, BatchClusterOptions_1.verifyOptions)(opts));
if (this.options.onIdleIntervalMillis > 0) {
this.onIdleInterval = timers_1.setInterval(() => this.onIdle(), this.options.onIdleIntervalMillis);
this.onIdleInterval = timers_1.default.setInterval(() => this.onIdle(), this.options.onIdleIntervalMillis);
this.onIdleInterval.unref(); // < don't prevent node from exiting

@@ -89,4 +92,4 @@ }

};
_p.once("beforeExit", this.beforeExitListener);
_p.once("exit", this.exitListener);
process_1.default.once("beforeExit", this.beforeExitListener);
process_1.default.once("exit", this.exitListener);
}

@@ -105,6 +108,6 @@ get ended() {

this.emitter.emit("beforeEnd");
Object_1.map(this.onIdleInterval, timers_1.clearInterval);
(0, Object_1.map)(this.onIdleInterval, timers_1.default.clearInterval);
this.onIdleInterval = undefined;
_p.removeListener("beforeExit", this.beforeExitListener);
_p.removeListener("exit", this.exitListener);
process_1.default.removeListener("beforeExit", this.beforeExitListener);
process_1.default.removeListener("exit", this.exitListener);
this.endPromise = new Deferred_1.Deferred().observe(this.closeChildProcesses(gracefully)

@@ -228,3 +231,3 @@ .catch((err) => {

get childEndCounts() {
return Object_1.fromEntries([...this._childEndCounts.entries()]);
return (0, Object_1.fromEntries)([...this._childEndCounts.entries()]);
}

@@ -242,3 +245,3 @@ /**

}
catch (_a) {
catch {
// ignore: make sure all procs are ended

@@ -268,3 +271,3 @@ }

this.maybeCheckPids();
Array_1.filterInPlace(this._procs, (proc) => {
(0, Array_1.filterInPlace)(this._procs, (proc) => {
// Don't bother running procs:

@@ -271,0 +274,0 @@ if (!proc.ending && !proc.idle)

/// <reference types="node" />
import { ChildProcess } from "child_process";
import { EventEmitter } from "events";
import child_process from "child_process";
import events from "events";
import { BatchProcess } from "./BatchProcess";
import { Task } from "./Task";
export declare class BatchClusterEmitter {
readonly emitter: EventEmitter;
readonly emitter: events;
/**
* Emitted when a child process has started
*/
on(event: "childStart", listener: (childProcess: ChildProcess) => void): void;
on(event: "childStart", listener: (childProcess: child_process.ChildProcess) => void): void;
/**
* Emitted when a child process has exitted
*/
on(event: "childExit", listener: (childProcess: ChildProcess) => void): void;
on(event: "childExit", listener: (childProcess: child_process.ChildProcess) => void): void;
/**

@@ -17,0 +17,0 @@ * Emitted when a child process has an error when spawning

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchClusterEmitter = void 0;
const events_1 = require("events");
const events_1 = __importDefault(require("events"));
class BatchClusterEmitter {
constructor() {
this.emitter = new events_1.EventEmitter();
this.emitter = new events_1.default.EventEmitter();
}

@@ -9,0 +12,0 @@ on(event, listener) {

@@ -169,4 +169,4 @@ "use strict";

function notBlank(fieldName) {
const v = String_1.toS(result[fieldName]);
if (String_1.blank(v)) {
const v = (0, String_1.toS)(result[fieldName]);
if ((0, String_1.blank)(v)) {
errors.push(fieldName + " must not be blank");

@@ -173,0 +173,0 @@ }

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

stdout.on("data", (d) => this.onStdout(d));
Object_1.map(this.proc.stderr, (stderr) => {
(0, Object_1.map)(this.proc.stderr, (stderr) => {
stderr.on("error", (err) => this.onError("stderr.error", err));
stderr.on("data", (err) => this.onStderr(err));
});
this.streamDebouncer = Async_1.debounce(opts.streamFlushMillis);
this.streamDebouncer = (0, Async_1.debounce)(opts.streamFlushMillis);
const startupTask = new Task_1.Task(opts.versionCommand, Parser_1.SimpleParser);

@@ -154,3 +154,3 @@ this.startupTaskId = startupTask.taskId;

else {
const alive = await Pids_1.pidExists(this.pid);
const alive = await (0, Pids_1.pidExists)(this.pid);
if (!alive) {

@@ -210,3 +210,3 @@ // once a PID leaves the process table, it's gone for good:

this._currentTask = task;
const cmd = String_1.ensureSuffix(task.command, "\n");
const cmd = (0, String_1.ensureSuffix)(task.command, "\n");
const isStartupTask = task.taskId === this.startupTaskId;

@@ -287,5 +287,5 @@ const timeoutMs = isStartupTask

// to complete successfully. Let's not wait forever, though.
await Promise.race([lastTask.promise, Async_1.delay(gracefully ? 2000 : 250)]);
await Promise.race([lastTask.promise, (0, Async_1.delay)(gracefully ? 2000 : 250)]);
}
catch (_a) {
catch {
//

@@ -300,8 +300,8 @@ }

}
const cmd = Object_1.map(this.opts.exitCommand, (ea) => String_1.ensureSuffix(ea, "\n"));
const cmd = (0, Object_1.map)(this.opts.exitCommand, (ea) => (0, String_1.ensureSuffix)(ea, "\n"));
// proc cleanup:
Error_1.tryEach([
() => Stream_1.mapNotDestroyed(this.proc.stdin, (ea) => ea.end(cmd)),
() => Stream_1.mapNotDestroyed(this.proc.stdout, (ea) => ea.destroy()),
() => Stream_1.mapNotDestroyed(this.proc.stderr, (ea) => ea.destroy()),
(0, Error_1.tryEach)([
() => (0, Stream_1.mapNotDestroyed)(this.proc.stdin, (ea) => ea.end(cmd)),
() => (0, Stream_1.mapNotDestroyed)(this.proc.stdout, (ea) => ea.destroy()),
() => (0, Stream_1.mapNotDestroyed)(this.proc.stderr, (ea) => ea.destroy()),
() => this.proc.disconnect(),

@@ -317,3 +317,3 @@ ]);

if ((await this.running()) && this.proc.pid != null)
await Pids_1.kill(this.proc.pid);
await (0, Pids_1.kill)(this.proc.pid);
// Wait for the signal handler to work:

@@ -326,3 +326,3 @@ await this.awaitNotRunning(this.opts.endGracefulWaitTimeMillis / 2);

this.logger().warn(this.name + ".end(): force-killing still-running child.");
await Pids_1.kill(this.proc.pid, true);
await (0, Pids_1.kill)(this.proc.pid, true);
}

@@ -332,3 +332,3 @@ return this.resolvedOnExit;

awaitNotRunning(timeout) {
return Async_1.until(() => this.notRunning(), timeout);
return (0, Async_1.until)(() => this.notRunning(), timeout);
}

@@ -354,6 +354,6 @@ onTimeout(task, timeoutMs) {

}
const error = new Error(source + ": " + Error_1.cleanError(_error.message));
const error = new Error(source + ": " + (0, Error_1.cleanError)(_error.message));
this.logger().warn(this.name + ".onError()", {
source,
task: Object_1.map(task, (t) => t.command),
task: (0, Object_1.map)(task, (t) => t.command),
error,

@@ -363,3 +363,3 @@ });

// Error stacks, if set, will not be redefined from a rethrow:
error.stack = Error_1.cleanError(_error.stack);
error.stack = (0, Error_1.cleanError)(_error.stack);
}

@@ -388,3 +388,3 @@ // clear the task before ending so the onExit from end() doesn't retry the task:

onStderr(data) {
if (String_1.blank(data))
if ((0, String_1.blank)(data))
return;

@@ -424,7 +424,7 @@ this.logger().info("onStderr(" + this.pid + "):" + data);

if (pass != null) {
return this.resolveCurrentTask(task, String_1.toS(pass[1]).trim(), task.stderr, true);
return this.resolveCurrentTask(task, (0, String_1.toS)(pass[1]).trim(), task.stderr, true);
}
const failout = this.opts.failRE.exec(task.stdout);
if (failout != null) {
const msg = String_1.toS(failout[1]).trim();
const msg = (0, String_1.toS)(failout[1]).trim();
return this.resolveCurrentTask(task, msg, task.stderr, false);

@@ -434,3 +434,3 @@ }

if (failerr != null) {
const msg = String_1.toS(failerr[1]).trim();
const msg = (0, String_1.toS)(failerr[1]).trim();
return this.resolveCurrentTask(task, task.stdout, msg, false);

@@ -445,3 +445,3 @@ }

return;
Object_1.map(this.currentTaskTimeout, (ea) => clearTimeout(ea));
(0, Object_1.map)(this.currentTaskTimeout, (ea) => clearTimeout(ea));
this.currentTaskTimeout = undefined;

@@ -448,0 +448,0 @@ this._currentTask = undefined;

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

}
catch (_b) {
catch {
d.resolve(undefined);

@@ -101,0 +101,0 @@ }

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Log = exports.logger = exports.setLogger = exports.NoLogger = exports.ConsoleLogger = exports.LogLevels = void 0;
const util_1 = require("util");
const util_1 = __importDefault(require("util"));
const Object_1 = require("./Object");

@@ -14,3 +17,3 @@ const String_1 = require("./String");

];
const _debuglog = util_1.debuglog("batch-cluster");
const _debuglog = util_1.default.debuglog("batch-cluster");
const noop = () => undefined;

@@ -74,3 +77,3 @@ /**

timestamped[ea] = (message, ...optionalParams) => {
if (String_1.notBlank(message)) {
if ((0, String_1.notBlank)(message)) {
delegate[ea](prefix + message, ...optionalParams);

@@ -84,3 +87,3 @@ }

const timestamped = {};
exports.LogLevels.forEach((level) => (timestamped[level] = (message, ...optionalParams) => Object_1.map(message, (ea) => delegate[level](new Date().toISOString() + " | " + ea, ...optionalParams))));
exports.LogLevels.forEach((level) => (timestamped[level] = (message, ...optionalParams) => (0, Object_1.map)(message, (ea) => delegate[level](new Date().toISOString() + " | " + ea, ...optionalParams))));
return timestamped;

@@ -87,0 +90,0 @@ },

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

get arr() {
Array_1.filterInPlace(this._arr, (ea) => ea.pending);
(0, Array_1.filterInPlace)(this._arr, (ea) => ea.pending);
return this._arr;

@@ -18,0 +18,0 @@ }

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

throw new Error("task failed");
if (String_1.notBlank(stderr))
if ((0, String_1.notBlank)(stderr))
throw new Error(stderr);

@@ -11,0 +11,0 @@ return stdout;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.kill = exports.pids = exports.pidExists = void 0;
const _cp = require("child_process");
const _p = require("process");
const child_process_1 = __importDefault(require("child_process"));
const process_1 = __importDefault(require("process"));
const Object_1 = require("./Object");
const Platform_1 = require("./Platform");

@@ -60,3 +64,3 @@ function safePid(pid) {

return new Promise((resolve) => {
_cp.execFile(cmd, ...args, (error, stdout) => {
child_process_1.default.execFile(cmd, ...args, (error, stdout) => {
const result = error == null &&

@@ -79,3 +83,3 @@ new RegExp(Platform_1.isWin ? '"' + needle + '"' : "^\\s*" + needle + "\\b",

return new Promise((resolve, reject) => {
_cp.execFile(Platform_1.isWin ? "tasklist" : "ps",
child_process_1.default.execFile(Platform_1.isWin ? "tasklist" : "ps",
// NoHeader, FOrmat CSV

@@ -94,3 +98,4 @@ Platform_1.isWin ? ["/NH", "/FO", "CSV"] : ["-e"], (error, stdout, stderr) => {

.map((ea) => ea.match(Platform_1.isWin ? winRe : posixRe))
.filter((m) => m != null).map((m) => parseInt(m[1])));
.map((m) => (0, Object_1.map)(m === null || m === void 0 ? void 0 : m[0], parseInt))
.filter((ea) => ea != null));
});

@@ -111,3 +116,3 @@ });

return;
if (pid === _p.pid || pid === _p.ppid) {
if (pid === process_1.default.pid || pid === process_1.default.ppid) {
throw new Error("cannot self-terminate");

@@ -120,7 +125,7 @@ }

}
_cp.execFile("taskkill", args);
child_process_1.default.execFile("taskkill", args);
}
else {
try {
_p.kill(pid, force ? "SIGKILL" : "SIGTERM");
process_1.default.kill(pid, force ? "SIGKILL" : "SIGTERM");
}

@@ -127,0 +132,0 @@ catch (err) {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isWin = void 0;
const os_1 = require("os");
exports.isWin = ["win32", "cygwin"].includes(os_1.platform());
const os_1 = __importDefault(require("os"));
exports.isWin = ["win32", "cygwin"].includes(os_1.default.platform());
//# sourceMappingURL=Platform.js.map
/// <reference types="node" />
import { Readable, Writable } from "stream";
export declare function end(endable: Writable, contents?: string): Promise<void>;
export declare function mapNotDestroyed<T extends Readable | Writable, R>(obj: T | undefined | null, f: (t: T) => R): R | undefined;
import stream from "stream";
export declare function end(endable: stream.Writable, contents?: string): Promise<void>;
export declare function mapNotDestroyed<T extends stream.Readable | stream.Writable, R>(obj: T | undefined | null, f: (t: T) => R): R | undefined;

@@ -18,5 +18,5 @@ "use strict";

function toS(s) {
return s == null ? "" : Object_1.isFunction(s.toString) ? s.toString() : String(s);
return s == null ? "" : (0, Object_1.isFunction)(s.toString) ? s.toString() : String(s);
}
exports.toS = toS;
//# sourceMappingURL=String.js.map
{
"name": "batch-cluster",
"version": "7.1.0",
"version": "7.2.0",
"description": "Manage a cluster of child processes",

@@ -37,9 +37,9 @@ "main": "dist/BatchCluster.js",

"devDependencies": {
"@types/chai": "^4.2.21",
"@types/chai": "^4.2.22",
"@types/chai-as-promised": "^7.1.4",
"@types/chai-string": "^1.4.2",
"@types/mocha": "^8.2.3",
"@types/node": "^16.3.1",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"@types/mocha": "^9.0.0",
"@types/node": "^16.9.6",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"chai": "^4.3.4",

@@ -49,15 +49,15 @@ "chai-as-promised": "^7.1.1",

"chai-withintoleranceof": "^1.0.1",
"eslint": "^7.30.0",
"eslint-plugin-import": "^2.23.4",
"mocha": "^9.0.2",
"prettier": "^2.3.2",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.24.2",
"mocha": "^9.1.1",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"seedrandom": "^3.0.5",
"serve": "^12.0.0",
"source-map-support": "^0.5.19",
"serve": "^12.0.1",
"source-map-support": "^0.5.20",
"split2": "^3.2.2",
"timekeeper": "^2.2.0",
"typedoc": "^0.21.4",
"typescript": "^4.3.5"
"typedoc": "^0.22.4",
"typescript": "^4.4.3"
}
}

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

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

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

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