Socket
Socket
Sign inDemoInstall

@tracerbench/spawn

Package Overview
Dependencies
4
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 1.3.0

dist/tsdoc-metadata.json

2

dist/execa.d.ts
import execa = require("execa");
export default function wrappedExec(command: string, args: string[], opts: execa.Options, debugCallback: (formatter: any, ...args: any[]) => void): execa.ExecaChildProcess<string>;
export default function wrappedExec(command: string, args: string[], opts: execa.Options, debugCallback: (formatter: string, ...args: unknown[]) => void): execa.ExecaChildProcess<string>;
//# sourceMappingURL=execa.d.ts.map

@@ -12,2 +12,3 @@ "use strict";

});
//
return child;

@@ -14,0 +15,0 @@ }

export { default } from "./spawn";
export * from "../types";
export type { DebugCallback, Process, ProcessWithPipeMessageTransport, ProcessWithWebSocketUrl, Stdio, TransportMapping, Transport, } from "../types";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var spawn_1 = require("./spawn");
exports.default = spawn_1.default;
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spawn_1.default; } });
//# sourceMappingURL=index.js.map

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

const enqueue = newTaskQueue_1.default();
const splitter = newBufferSplitter_1.default(0 /* NULL */, split => enqueueMessage(split.toString("utf8")));
const splitter = newBufferSplitter_1.default(0 /* NULL */, (split) => enqueueMessage(split.toString("utf8")));
return sendMessage;

@@ -18,0 +18,0 @@ function enqueueClose(error) {

import * as t from "../types";
export default function newProcess(child: import("execa").ExecaChildProcess, command: string, debugCallback: (formatter: any, ...args: any[]) => void): t.Process;
export default function newProcess(child: import("execa").ExecaChildProcess, command: string, debugCallback: (formatter: unknown, ...args: unknown[]) => void): t.Process;
//# sourceMappingURL=newProcess.d.ts.map

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

const [raceExit, cancel] = race_cancellation_1.cancellableRace();
child.on("error", error => {
void child.on("error", (error) => {
lastError = error;

@@ -16,3 +16,3 @@ debugCallback("%o (pid: %o) 'error' event: %O", command, child.pid, error);

});
child.on("exit", () => {
void child.on("exit", () => {
debugCallback("%o (pid: %o) 'exit' event", command, child.pid);

@@ -60,7 +60,7 @@ onErrorOrExit();

return await race_cancellation_1.disposablePromise((resolve, reject) => {
child.on("exit", resolve);
child.on("error", reject);
void child.on("exit", resolve);
void child.on("error", reject);
return () => {
child.removeListener("exit", resolve);
child.removeListener("error", reject);
void child.removeListener("exit", resolve);
void child.removeListener("error", reject);
};

@@ -67,0 +67,0 @@ }, raceCancellation);

import { ProcessWithPipeMessageTransport, Stdio } from "../types";
export default function newProcessWithPipeMessageTransport(command: string, args: string[], stdio: Stdio, debugCallback: (formatter: any, ...args: any[]) => void): ProcessWithPipeMessageTransport;
export default function newProcessWithPipeMessageTransport(command: string, args: string[], stdio: Stdio, debugCallback: (formatter: unknown, ...args: unknown[]) => void): ProcessWithPipeMessageTransport;
//# sourceMappingURL=newProcessWithPipeMessageTransport.d.ts.map

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

const attach = newPipeMessageTransport_1.default((onRead, onReadEnd, onClose) => {
child.on("error", onClose);
child.on("exit", onClose);
void child.on("error", onClose);
void child.on("exit", onClose);
readStream.on("data", handleReadData);

@@ -23,3 +23,3 @@ readStream.on("end", handleReadEnd);

writeStream.on("error", handleWriteError);
return [data => writeStream.write(data), () => writeStream.end()];
return [(data) => writeStream.write(data), () => writeStream.end()];
function handleReadData(buffer) {

@@ -26,0 +26,0 @@ debugEvent("read", "data", buffer.byteLength);

import { ProcessWithWebSocketUrl, Stdio } from "../types";
export default function newProcessWithWebSocketUrl(command: string, args: string[], stdio: Stdio, debugCallback: (formatter: any, ...args: any[]) => void): ProcessWithWebSocketUrl;
export default function newProcessWithWebSocketUrl(command: string, args: string[], stdio: Stdio, debugCallback: (formatter: unknown, ...args: unknown[]) => void): ProcessWithWebSocketUrl;
//# sourceMappingURL=newProcessWithWebSocketUrl.d.ts.map

@@ -14,2 +14,5 @@ "use strict";

const process = newProcess_1.default(child, command, debugCallback);
if (child.stderr === null) {
throw new Error("missing stderr");
}
return Object.assign(process, {

@@ -26,3 +29,3 @@ url: createUrl(child.stderr, stdio, process.raceExit),

if (promise === undefined) {
promise = new Promise(resolve => parseUrl(stderr, stdio, resolve));
promise = new Promise((resolve) => parseUrl(stderr, stdio, resolve));
}

@@ -43,5 +46,5 @@ return promise;

else {
throw new Error(`invalid stdio arg ${stdio} expected ignore or inherit`);
throw new Error(`invalid stdio arg ${String(stdio)} expected ignore or inherit`);
}
}
//# sourceMappingURL=newProcessWithWebSocketUrl.js.map

@@ -29,2 +29,3 @@ "use strict";

const task = queue[read];
// release memory
queue[read++] = undefined;

@@ -31,0 +32,0 @@ if (read < write) {

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

function newWebSocketUrlParser(onUrlParsed) {
let state = createParsingState(url => {
let state = createParsingState((url) => {
onUrlParsed(url);

@@ -31,3 +31,3 @@ state = PASSTHROUGH;

function createParsingState(onUrlParsed) {
const splitter = newBufferSplitter_1.default(10 /* LF */, split => {
const splitter = newBufferSplitter_1.default(10 /* LF */, (split) => {
const url = findUrl(split);

@@ -34,0 +34,0 @@ if (url !== undefined) {

import { DebugCallback, ProcessWithPipeMessageTransport, ProcessWithWebSocketUrl, Stdio } from "../types";
export default function spawn(executable: string, args: string[], stderr: Stdio | undefined, transport: "websocket", debugCallback?: DebugCallback): ProcessWithWebSocketUrl;
export default function spawn(executable: string, args: string[], stderr?: Stdio, transport?: "pipe", debugCallback?: DebugCallback): ProcessWithPipeMessageTransport;
declare function spawn(executable: string, args: string[], stderr: Stdio | undefined, transport: "websocket", debugCallback?: DebugCallback): ProcessWithWebSocketUrl;
declare function spawn(executable: string, args: string[], stderr?: Stdio, transport?: "pipe", debugCallback?: DebugCallback): ProcessWithPipeMessageTransport;
export default spawn;
//# sourceMappingURL=spawn.d.ts.map

@@ -16,6 +16,6 @@ "use strict";

}
exports.default = spawn;
function invalidTransport(transport) {
return new Error(`invalid transport argument "${transport}"`);
return new Error(`invalid transport argument "${String(transport)}"`);
}
exports.default = spawn;
//# sourceMappingURL=spawn.js.map
{
"name": "@tracerbench/spawn",
"version": "1.2.0",
"version": "1.3.0",
"description": "High level spawn API for spawning process with a connection to the DevTools protocol.",

@@ -17,20 +17,24 @@ "license": "BSD-2-Clause",

"clean": "rm -rf dist tsconfig.tsbuildinfo",
"lint": "tslint -p tsconfig.json",
"fixlint": "eslint --ext .ts src --fix",
"lint": "eslint --ext .ts src",
"prepare": "yarn run build"
},
"dependencies": {
"@tracerbench/message-transport": "^1.2.0",
"@tracerbench/message-transport": "^1.3.0",
"debug": "^4.1.1",
"execa": "^3.3.0",
"execa": "^4.0.2",
"race-cancellation": "^0.4.1"
},
"devDependencies": {
"@types/node": "*",
"prettier": "^1.19.1",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-simple-import-sort": "^5.0.0",
"prettier": "^2.0.5",
"typescript": "^3.7.2"
},
"gitHead": "3318d9cdbd6bce276ebe8e2570bd64c1aaa16046"
"gitHead": "930bc11c8b01620e5095df9249f0647af68235b5"
}

@@ -7,4 +7,4 @@ import execa = require("execa");

opts: execa.Options,
debugCallback: (formatter: any, ...args: any[]) => void,
) {
debugCallback: (formatter: string, ...args: unknown[]) => void,
): execa.ExecaChildProcess<string> {
const child = execa(command, args, opts);

@@ -25,3 +25,4 @@ debugCallback(

//
return child;
}
export { default } from "./spawn";
export * from "../types";
export type {
DebugCallback,
Process,
ProcessWithPipeMessageTransport,
ProcessWithWebSocketUrl,
Stdio,
TransportMapping,
Transport,
} from "../types";

@@ -48,3 +48,3 @@ export type SplitterCallback = (split: Buffer) => void;

function flush() {
function flush(): void {
if (stopped) {

@@ -57,3 +57,3 @@ return;

function stop() {
function stop(): void {
stopped = true;

@@ -64,3 +64,3 @@ byteLength = 0;

function _push(buffer: Buffer, start: number, end: number) {
function _push(buffer: Buffer, start: number, end: number): void {
const length = end - start;

@@ -76,3 +76,3 @@ if (length > 0) {

function _flush() {
function _flush(): void {
let split: Buffer | undefined;

@@ -79,0 +79,0 @@

@@ -6,2 +6,6 @@ import { AttachMessageTransport } from "@tracerbench/message-transport";

const enum Char {
NULL = 0,
}
export type Write = (data: Buffer) => void;

@@ -31,10 +35,6 @@ export type EndWrite = () => void;

const [write, endWrite] = connect(
onRead,
onReadEnd,
enqueueClose,
);
const [write, endWrite] = connect(onRead, onReadEnd, enqueueClose);
const enqueue = newTaskQueue();
const splitter = newBufferSplitter(Char.NULL, split =>
const splitter = newBufferSplitter(Char.NULL, (split) =>
enqueueMessage(split.toString("utf8")),

@@ -45,3 +45,3 @@ );

function enqueueClose(error?: Error) {
function enqueueClose(error?: Error): void {
if (closed) {

@@ -62,15 +62,15 @@ return;

function enqueueMessage(message: string) {
function enqueueMessage(message: string): void {
enqueue(() => onMessage(message));
}
function onRead(data: Buffer) {
function onRead(data: Buffer): void {
splitter.push(data);
}
function onReadEnd() {
function onReadEnd(): void {
splitter.flush();
}
function sendMessage(message: string) {
function sendMessage(message: string): void {
write(Buffer.from(message + "\0", "utf8"));

@@ -80,5 +80,1 @@ }

}
const enum Char {
NULL = 0,
}

@@ -16,3 +16,3 @@ import { EventEmitter } from "events";

command: string,
debugCallback: (formatter: any, ...args: any[]) => void,
debugCallback: (formatter: unknown, ...args: unknown[]) => void,
): t.Process {

@@ -25,3 +25,3 @@ let hasExited = false;

child.on("error", error => {
void child.on("error", (error) => {
lastError = error;

@@ -32,3 +32,3 @@ debugCallback("%o (pid: %o) 'error' event: %O", command, child.pid, error);

child.on("exit", () => {
void child.on("exit", () => {
debugCallback("%o (pid: %o) 'exit' event", command, child.pid);

@@ -57,3 +57,3 @@ onErrorOrExit();

*/
function onErrorOrExit(error?: Error) {
function onErrorOrExit(error?: Error): void {
if (hasExited) {

@@ -86,7 +86,7 @@ return;

return await disposablePromise((resolve, reject) => {
child.on("exit", resolve);
child.on("error", reject);
void child.on("exit", resolve);
void child.on("error", reject);
return () => {
child.removeListener("exit", resolve);
child.removeListener("error", reject);
void child.removeListener("exit", resolve);
void child.removeListener("error", reject);
};

@@ -99,3 +99,3 @@ }, raceCancellation);

raceCancellation?: RaceCancellation,
) {
): Promise<void> {
if (hasExited) {

@@ -111,3 +111,6 @@ return;

async function kill(timeout?: number, raceCancellation?: RaceCancellation) {
async function kill(
timeout?: number,
raceCancellation?: RaceCancellation,
): Promise<void> {
if (!child.killed && child.pid) {

@@ -114,0 +117,0 @@ child.kill();

import { ProcessWithPipeMessageTransport, Stdio } from "../types";
import execa from "./execa";

@@ -11,3 +10,3 @@ import createPipeMessageTransport from "./newPipeMessageTransport";

stdio: Stdio,
debugCallback: (formatter: any, ...args: any[]) => void,
debugCallback: (formatter: unknown, ...args: unknown[]) => void,
): ProcessWithPipeMessageTransport {

@@ -35,4 +34,4 @@ const child = execa(

const attach = createPipeMessageTransport((onRead, onReadEnd, onClose) => {
child.on("error", onClose);
child.on("exit", onClose);
void child.on("error", onClose);
void child.on("exit", onClose);

@@ -46,5 +45,5 @@ readStream.on("data", handleReadData);

return [data => writeStream.write(data), () => writeStream.end()];
return [(data) => writeStream.write(data), () => writeStream.end()];
function handleReadData(buffer: Buffer) {
function handleReadData(buffer: Buffer): void {
debugEvent("read", "data", buffer.byteLength);

@@ -54,3 +53,3 @@ onRead(buffer);

function handleReadEnd() {
function handleReadEnd(): void {
debugEvent("read", "end");

@@ -60,7 +59,7 @@ onReadEnd();

function handleReadError(error: Error) {
function handleReadError(error: Error): void {
debugEvent("read", "error", error);
}
function handleWriteError(error: Error | NodeJS.ErrnoException) {
function handleWriteError(error: Error | NodeJS.ErrnoException): void {
debugEvent("write", "error", error);

@@ -75,3 +74,3 @@ // writes while the other side is closing can cause EPIPE

function handleWriteClose() {
function handleWriteClose(): void {
debugEvent("write", "close");

@@ -81,3 +80,7 @@ onClose();

function debugEvent(pipe: "read" | "write", event: string, arg?: any) {
function debugEvent(
pipe: "read" | "write",
event: string,
arg?: unknown,
): void {
if (arg === undefined) {

@@ -84,0 +87,0 @@ debugCallback("%s pipe (pid: %o) %o event", pipe, child.pid, event);

@@ -8,3 +8,2 @@ import {

import { ProcessWithWebSocketUrl, Stdio } from "../types";
import execa from "./execa";

@@ -18,3 +17,3 @@ import newProcess from "./newProcess";

stdio: Stdio,
debugCallback: (formatter: any, ...args: any[]) => void,
debugCallback: (formatter: unknown, ...args: unknown[]) => void,
): ProcessWithWebSocketUrl {

@@ -33,4 +32,7 @@ const child = execa(

const process = newProcess(child, command, debugCallback);
if (child.stderr === null) {
throw new Error("missing stderr");
}
return Object.assign(process, {
url: createUrl(child.stderr!, stdio, process.raceExit),
url: createUrl(child.stderr, stdio, process.raceExit),
});

@@ -43,11 +45,14 @@ }

raceExit: RaceCancellation,
) {
): (race?: RaceCancellation) => Promise<string> {
let promise: Promise<string> | undefined;
return url;
async function url(raceCancellation?: RaceCancellation) {
async function url(raceCancellation?: RaceCancellation): Promise<string> {
return throwIfCancelled(
await combineRaceCancellation(raceExit, raceCancellation)(() => {
await combineRaceCancellation(
raceExit,
raceCancellation,
)(() => {
if (promise === undefined) {
promise = new Promise(resolve => parseUrl(stderr, stdio, resolve));
promise = new Promise((resolve) => parseUrl(stderr, stdio, resolve));
}

@@ -64,3 +69,3 @@ return promise;

callback: (url: string) => void,
) {
): void {
const parser = newWebSocketUrlParser(callback);

@@ -73,4 +78,6 @@ stderr.pipe(parser);

} else {
throw new Error(`invalid stdio arg ${stdio} expected ignore or inherit`);
throw new Error(
`invalid stdio arg ${String(stdio)} expected ignore or inherit`,
);
}
}

@@ -6,3 +6,3 @@ export type Task = () => void;

*/
export default function newTaskQueue() {
export default function newTaskQueue(): (task: Task) => void {
const queue: Task[] = [];

@@ -14,3 +14,3 @@ let scheduled = false;

function schedule() {
function schedule(): void {
scheduled = true;

@@ -20,3 +20,3 @@ setImmediate(next);

function next() {
function next(): void {
scheduled = false;

@@ -26,3 +26,3 @@ dequeue();

function enqueue(task: Task) {
function enqueue(task: Task): void {
queue[write++] = task;

@@ -35,5 +35,6 @@ if (scheduled) {

function dequeue() {
function dequeue(): void {
const task = queue[read];
queue[read++] = undefined as any;
// release memory
queue[read++] = (undefined as unknown) as Task;
if (read < write) {

@@ -40,0 +41,0 @@ schedule();

@@ -31,3 +31,3 @@ import { Transform, TransformCallback } from "stream";

): NodeJS.ReadWriteStream {
let state = createParsingState(url => {
let state = createParsingState((url) => {
onUrlParsed(url);

@@ -47,3 +47,3 @@ state = PASSTHROUGH;

function createParsingState(onUrlParsed: UrlParsedCallback): ParserState {
const splitter = newBufferSplitter(Char.LF, split => {
const splitter = newBufferSplitter(Char.LF, (split) => {
const url = findUrl(split);

@@ -50,0 +50,0 @@ if (url !== undefined) {

@@ -10,7 +10,6 @@ import debug from "debug";

} from "../types";
import newProcessWithPipeMessageTransport from "./newProcessWithPipeMessageTransport";
import newProcessWithWebSocketUrl from "./newProcessWithWebSocketUrl";
export default function spawn(
function spawn(
executable: string,

@@ -22,3 +21,3 @@ args: string[],

): ProcessWithWebSocketUrl;
export default function spawn(
function spawn(
executable: string,

@@ -30,3 +29,3 @@ args: string[],

): ProcessWithPipeMessageTransport;
export default function spawn(
function spawn(
executable: string,

@@ -58,4 +57,6 @@ args: string[],

function invalidTransport(transport: never) {
return new Error(`invalid transport argument "${transport}"`);
function invalidTransport(transport: never): Error {
return new Error(`invalid transport argument "${String(transport)}"`);
}
export default spawn;

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

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc