Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more spawn options #115

Merged
merged 1 commit into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
1 change: 1 addition & 0 deletions @tracerbench/message-transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"index.d.ts"
],
"types": "index.d.ts",
"main": "index.js",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
Expand Down
41 changes: 35 additions & 6 deletions @tracerbench/protocol-connection/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { AttachMessageTransport } from "@tracerbench/message-transport";
import newAttachProtocolTransport, {
DebugCallback,
} from "@tracerbench/protocol-transport";
import type { RaceCancellation } from "race-cancellation";
import newAttachProtocolTransport from "@tracerbench/protocol-transport";

import type { EventEmitter, RootConnection } from "../types";
import type {
AttachMessageTransport,
DebugCallback,
EventEmitter,
RaceCancellation,
RootConnection,
} from "../types";
import _newProtocolConnection from "./newProtocolConnection";

/**
Expand All @@ -24,6 +26,33 @@ export default function newProtocolConnection(

export { default as newProtocolConnection } from "./newProtocolConnection";
export type {
AttachJsonRpcTransport,
AttachMessageTransport,
AttachProtocolTransport,
AttachSession,
Cancellation,
DebugCallback,
DetachSession,
ErrorResponse,
Notification,
OnClose,
OnError,
OnEvent,
OnMessage,
OnNotification,
Protocol,
ProtocolMapping,
ProtocolError,
ProtocolTransport,
RaceCancellation,
Request,
Response,
ResponseError,
SendMessage,
SendMethod,
SendRequest,
SuccessResponse,
Task,
ProtocolConnection,
SessionConnection,
RootConnection,
Expand Down
3 changes: 1 addition & 2 deletions @tracerbench/protocol-connection/src/newEventHook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Protocol from "devtools-protocol";

import type {
Protocol,
SessionConnection,
SessionID,
SessionIdentifier,
Expand Down
15 changes: 7 additions & 8 deletions @tracerbench/protocol-connection/src/newProtocolConnection.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {
AttachProtocolTransport,
AttachSession,
} from "@tracerbench/protocol-transport";
import Protocol from "devtools-protocol";
import {
combineRaceCancellation,
disposablePromise,
RaceCancellation,
throwIfCancelled,
} from "race-cancellation";

import {
import type {
AttachProtocolTransport,
AttachSession,
NewEventEmitter,
Protocol,
ProtocolConnection,
RaceCancellation,
RootConnection,
SessionConnection,
SessionID,
TargetID,
} from "../types";
import newEventHook, { Session } from "./newEventHook";
import type { Session } from "./newEventHook";
import newEventHook from "./newEventHook";

/**
* This method adapts a AttachProtocolTransport into higher level
Expand Down
62 changes: 59 additions & 3 deletions @tracerbench/protocol-connection/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
import Protocol from "devtools-protocol";
import { ProtocolMapping } from "devtools-protocol/types/protocol-mapping";
import { RaceCancellation } from "race-cancellation";
import type {
AttachJsonRpcTransport,
AttachMessageTransport,
AttachProtocolTransport,
AttachSession,
Cancellation,
DebugCallback,
DetachSession,
ErrorResponse,
Notification,
OnClose,
OnError,
OnEvent,
OnMessage,
OnNotification,
ProtocolError,
ProtocolTransport,
RaceCancellation,
Request,
Response,
ResponseError,
SendMessage,
SendMethod,
SendRequest,
SuccessResponse,
Task,
} from "@tracerbench/protocol-transport";
import type { Protocol } from "devtools-protocol";
import type { ProtocolMapping } from "devtools-protocol/types/protocol-mapping";

export type {
AttachJsonRpcTransport,
AttachMessageTransport,
AttachProtocolTransport,
AttachSession,
Cancellation,
DebugCallback,
DetachSession,
ErrorResponse,
Notification,
OnClose,
OnError,
OnEvent,
OnMessage,
OnNotification,
Protocol,
ProtocolMapping,
ProtocolError,
ProtocolTransport,
RaceCancellation,
Request,
Response,
ResponseError,
SendMessage,
SendMethod,
SendRequest,
SuccessResponse,
Task,
};

export type ProtocolConnection = SessionConnection | RootConnection;

Expand Down
18 changes: 13 additions & 5 deletions @tracerbench/protocol-transport/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AttachMessageTransport } from "@tracerbench/message-transport";
import { RaceCancellation } from "race-cancellation";

import { AttachProtocolTransport, DebugCallback } from "../types";
import type {
AttachMessageTransport,
AttachProtocolTransport,
DebugCallback,
RaceCancellation,
} from "../types";
import newAttachJsonRpcTransport from "./newAttachJsonRpcTransport";
import _newAttachProtocolTransport from "./newAttachProtocolTransport";

Expand All @@ -19,6 +21,13 @@ export { default as newAttachJsonRpcTransport } from "./newAttachJsonRpcTranspor
export { default as newAttachProtocolTransport } from "./newAttachProtocolTransport";
export { isProtocolError } from "./newProtocolError";
export type {
AttachMessageTransport,
OnClose,
OnMessage,
SendMessage,
Cancellation,
RaceCancellation,
Task,
AttachJsonRpcTransport,
SendRequest,
AttachProtocolTransport,
Expand All @@ -36,6 +45,5 @@ export type {
ProtocolError,
OnNotification,
OnError,
OnClose,
OnEvent,
} from "../types";
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AttachMessageTransport } from "@tracerbench/message-transport";
import {
cancellableRace,
combineRaceCancellation,
RaceCancellation,
throwIfCancelled,
} from "race-cancellation";

import {
import type {
AttachJsonRpcTransport,
AttachMessageTransport,
DebugCallback,
Notification,
RaceCancellation,
Request,
Response,
} from "../types";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { RaceCancellation } from "race-cancellation";

import {
import type {
AttachJsonRpcTransport,
AttachProtocolTransport,
Notification,
RaceCancellation,
} from "../types";
import newProtocolError from "./newProtocolError";
import newSessions from "./newSessions";
Expand Down
2 changes: 1 addition & 1 deletion @tracerbench/protocol-transport/src/newProtocolError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorResponse, ProtocolError, Request } from "../types";
import type { ErrorResponse, ProtocolError, Request } from "../types";

export default function newProtocolError(
request: Request,
Expand Down
5 changes: 3 additions & 2 deletions @tracerbench/protocol-transport/src/newResponses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Complete, oneshot } from "race-cancellation";
import type { Complete } from "race-cancellation";
import { oneshot } from "race-cancellation";

import { Response } from "../types";
import type { Response } from "../types";

export default function newResponses(): [UsingResponse, ResolveResponse] {
let seq = 0;
Expand Down
7 changes: 2 additions & 5 deletions @tracerbench/protocol-transport/src/newSessions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
cancellableRace,
combineRaceCancellation,
RaceCancellation,
} from "race-cancellation";
import { cancellableRace, combineRaceCancellation } from "race-cancellation";

import {
AttachProtocolTransport,
AttachSession,
DetachSession,
RaceCancellation,
} from "../types";

export type DispatchEvent<SessionId> = (
Expand Down
21 changes: 18 additions & 3 deletions @tracerbench/protocol-transport/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { RaceCancellation } from "race-cancellation";
import {
AttachMessageTransport,
OnClose,
OnMessage,
SendMessage,
} from "@tracerbench/message-transport";
import { Cancellation, RaceCancellation, Task } from "race-cancellation";

export type {
AttachMessageTransport,
OnClose,
OnMessage,
SendMessage,
Cancellation,
RaceCancellation,
Task,
};

export type AttachJsonRpcTransport = (
onNotification: OnNotification,
Expand Down Expand Up @@ -92,7 +108,7 @@ export interface Notification<
sessionId?: SessionID;
}

export type DebugCallback = (fmt: string, ...args: any[]) => void;
export type DebugCallback = (formatter: unknown, ...args: unknown[]) => void;

export interface ProtocolError<
Method extends string = string,
Expand All @@ -110,7 +126,6 @@ export type OnNotification = <
notification: Notification<Method, Params>,
) => void;
export type OnError = (error: Error) => void;
export type OnClose = () => void;
export type OnEvent = <
Event extends string = string,
Params extends object = object
Expand Down
29 changes: 23 additions & 6 deletions @tracerbench/spawn-chrome/src/canonicalizeOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SpawnOptions } from "../types";
import type { ChromeSpawnOptions } from "../types";

const CANONICALIZE: {
[K in keyof SpawnOptions]: Canonicalize<SpawnOptions[K]>;
[K in keyof ChromeSpawnOptions]: Canonicalize<ChromeSpawnOptions[K]>;
} & {
[key: string]: Canonicalize<SpawnOptions[keyof SpawnOptions]>;
[key: string]: Canonicalize<ChromeSpawnOptions[keyof ChromeSpawnOptions]>;
} = {
additionalArguments: arrayOf("string"),
chromeExecutable: primitive("string"),
Expand All @@ -13,6 +13,9 @@ const CANONICALIZE: {
url: primitive("string"),
userDataDir: primitive("string"),
userDataRoot: primitive("string"),
cwd: primitive("string"),
extendEnv: primitive("boolean"),
env: env(),
};

type Canonicalize<T> = (value: unknown, key: string) => T;
Expand Down Expand Up @@ -62,9 +65,20 @@ function arrayOf<T extends keyof PrimitiveMapping>(
};
}

export default function canonicalizeOptions(options: unknown): SpawnOptions {
const canonical: SpawnOptions & {
[key: string]: SpawnOptions[keyof SpawnOptions];
function env(): Canonicalize<{ [name: string]: string | undefined }> {
return (value, key) => {
if (isObject(value)) {
return value as { [name: string]: string | undefined };
}
return invalidOption(key, "env");
};
}

export default function canonicalizeOptions(
options: unknown,
): ChromeSpawnOptions {
const canonical: ChromeSpawnOptions & {
[key: string]: ChromeSpawnOptions[keyof ChromeSpawnOptions];
} = {
additionalArguments: undefined,
chromeExecutable: undefined,
Expand All @@ -74,6 +88,9 @@ export default function canonicalizeOptions(options: unknown): SpawnOptions {
url: undefined,
userDataDir: undefined,
userDataRoot: undefined,
cwd: undefined,
extendEnv: undefined,
env: undefined,
};

if (isObject(options)) {
Expand Down
2 changes: 1 addition & 1 deletion @tracerbench/spawn-chrome/src/getArguments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArgumentOptions } from "../types";
import type { ArgumentOptions } from "../types";
import defaultFlags, { headlessFlags } from "./defaultFlags";

export default function getArguments(
Expand Down
21 changes: 20 additions & 1 deletion @tracerbench/spawn-chrome/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
export type { ArgumentOptions, SpawnOptions, Chrome } from "../types";
export type {
AttachMessageTransport,
Cancellation,
DebugCallback,
OnClose,
OnMessage,
Process,
ProcessWithPipeMessageTransport,
ProcessWithWebSocketUrl,
RaceCancellation,
SendMessage,
SpawnOptions,
Stdio,
Task,
Transport,
TransportMapping,
ArgumentOptions,
ChromeSpawnOptions,
Chrome,
} from "../types";
export { default } from "./spawnChrome";
export { defaultFlags, headlessFlags } from "./defaultFlags";
export { default as getArguments } from "./getArguments";
Loading