Skip to content

Commit 89f57ac

Browse files
fix naming of stuff
1 parent 43780a7 commit 89f57ac

File tree

6 files changed

+29
-444
lines changed

6 files changed

+29
-444
lines changed

src/SandboxClient.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,14 @@ export class SandboxClient {
8888
}
8989
);
9090

91-
await session.shells.run(
92-
[
93-
"rm -rf .git",
94-
"git init",
95-
`git remote add origin ${opts.url}`,
96-
"git fetch origin",
97-
`git checkout -b ${opts.branch}`,
98-
`git reset --hard origin/${opts.branch}`,
99-
].join(" && ")
100-
);
91+
await session.commands.run([
92+
"rm -rf .git",
93+
"git init",
94+
`git remote add origin ${opts.url}`,
95+
"git fetch origin",
96+
`git checkout -b ${opts.branch}`,
97+
`git reset --hard origin/${opts.branch}`,
98+
]);
10199

102100
await opts.setup?.(session);
103101

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ function ensure<T>(value: T | undefined, message: string): T {
2424
}
2525

2626
export class CodeSandbox {
27+
public readonly sandboxes: SandboxClient;
28+
/**
29+
* @deprecated Use `sandboxes` instead
30+
*/
2731
public readonly sandbox: SandboxClient;
2832

2933
/**
@@ -39,7 +43,7 @@ export class CodeSandbox {
3943
*/
4044
public readonly previewTokens: PreviewTokens;
4145

42-
constructor(apiToken?: string, readonly opts: ClientOpts = {}) {
46+
constructor(apiToken?: string, opts: ClientOpts = {}) {
4347
const evaluatedApiToken =
4448
apiToken ||
4549
ensure(
@@ -63,7 +67,8 @@ export class CodeSandbox {
6367
})
6468
);
6569

66-
this.sandbox = new SandboxClient(apiClient);
70+
this.sandboxes = new SandboxClient(apiClient);
71+
this.sandbox = this.sandboxes;
6772
this.previewTokens = new PreviewTokens(apiClient);
6873
}
6974
}

src/previews/Preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class Preview<
8484
return iframe;
8585
}
8686

87-
private sendMessage(message: MessageToPreview | BaseMessageToPreview) {
87+
sendMessage(message: MessageToPreview | BaseMessageToPreview) {
8888
if (this.status === "CONNECTED") {
8989
this.iframe.contentWindow?.postMessage(message, "*");
9090
}

src/sessions/WebSocketSession/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { initPitcherClient } from "@codesandbox/pitcher-client";
21
import { Disposable } from "../../utils/disposable";
32
import {
43
protocol as _protocol,
@@ -8,10 +7,7 @@ import {
87
import { FileSystem } from "./filesystem";
98
import { Ports } from "./ports";
109
import { Setup } from "./setup";
11-
import { Shells } from "./shells";
1210
import { Tasks } from "./tasks";
13-
import { DEFAULT_SUBSCRIPTIONS, SandboxSession } from "../../types";
14-
import { Client } from "@hey-api/client-fetch";
1511
import { Interpreters } from "./interpreters";
1612
import { Terminals } from "./terminals";
1713
import { Commands } from "./commands";
@@ -20,7 +16,6 @@ import { Git } from "./git";
2016
export * from "./filesystem";
2117
export * from "./ports";
2218
export * from "./setup";
23-
export * from "./shells";
2419
export * from "./tasks";
2520
export * from "./terminals";
2621
export * from "./commands";
@@ -35,11 +30,6 @@ export class WebSocketSession {
3530
*/
3631
public readonly fs = new FileSystem(this.disposable, this.pitcherClient);
3732

38-
/**
39-
* Namespace for running shell commands on this sandbox.
40-
*/
41-
public readonly shells = new Shells(this.disposable, this.pitcherClient);
42-
4333
public readonly terminals: Terminals;
4434
public readonly commands: Commands;
4535

src/sessions/WebSocketSession/ports.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import type { IPitcherClient, protocol } from "@codesandbox/pitcher-client";
1+
import type { IPitcherClient } from "@codesandbox/pitcher-client";
22

33
import { Disposable } from "../../utils/disposable";
44
import { Emitter } from "../../utils/event";
55

6+
export type Port = {
7+
port: number;
8+
host: string;
9+
};
10+
611
export class Ports {
712
private disposable = new Disposable();
813
private onDidPortOpenEmitter = this.disposable.addDisposable(
9-
new Emitter<protocol.port.Port>()
14+
new Emitter<Port>()
1015
);
1116
get onDidPortOpen() {
1217
return this.onDidPortOpenEmitter.event;
@@ -44,7 +49,7 @@ export class Ports {
4449

4550
if (openedPorts.length) {
4651
for (const port of openedPorts) {
47-
this.onDidPortOpenEmitter.fire(port);
52+
this.onDidPortOpenEmitter.fire({ port: port.port, host: port.url });
4853
}
4954
}
5055

@@ -63,8 +68,10 @@ export class Ports {
6368
return this.getOpenedPorts().find((p) => p.port === port);
6469
}
6570

66-
getOpenedPorts() {
67-
return this.pitcherClient.clients.port.getPorts();
71+
getOpenedPorts(): Port[] {
72+
return this.pitcherClient.clients.port
73+
.getPorts()
74+
.map(({ port, url }) => ({ host: url, port }));
6875
}
6976

7077
/**
@@ -79,7 +86,7 @@ export class Ports {
7986
async waitForPort(
8087
port: number,
8188
options?: { timeoutMs?: number }
82-
): Promise<protocol.port.Port> {
89+
): Promise<Port> {
8390
await this.pitcherClient.clients.port.readyPromise;
8491

8592
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)