Skip to content

Commit da5e3f6

Browse files
Merge pull request #99 from codesandbox/new-version-fixes
fix: fix typo and paths with dedicated sessions
2 parents c60b62e + 437a31d commit da5e3f6

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

src/Sandbox.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class Sandbox {
103103
opts: SessionCreateOptions
104104
): Promise<SandboxSession> {
105105
if (opts.id.length > 20) {
106-
throw new Error("Session ID must be 32 characters or less");
106+
throw new Error("Session ID must be 20 characters or less");
107107
}
108108

109109
const response = await vmCreateSession({
@@ -208,6 +208,10 @@ export class Sandbox {
208208
);
209209

210210
return new WebSocketSession(pitcherClient, {
211+
username: customSession
212+
? // @ts-ignore
213+
pitcherClient["joinResult"].client.username
214+
: undefined,
211215
env: customSession?.env,
212216
hostToken: customSession?.hostToken,
213217
});
@@ -237,6 +241,7 @@ export class Sandbox {
237241
return {
238242
id: this.id,
239243
env: customSession?.env,
244+
sessionId: customSession?.id,
240245
hostToken: customSession?.hostToken,
241246
bootupType: this.bootupType,
242247
cluster: this.cluster,

src/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export async function connectToSandbox(options: {
4646
);
4747

4848
return new WebSocketSession(pitcherClient, {
49+
username: options.session.sessionId
50+
? // @ts-ignore
51+
pitcherClient["joinResult"].client.username
52+
: undefined,
4953
env: options.session.env,
5054
hostToken: options.session.hostToken,
5155
});

src/sessions/WebSocketSession/filesystem.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class FileSystem {
4242
private disposable = new Disposable();
4343
constructor(
4444
sessionDisposable: Disposable,
45-
private pitcherClient: IPitcherClient
45+
private pitcherClient: IPitcherClient,
46+
private username?: string
4647
) {
4748
sessionDisposable.onWillDispose(() => {
4849
this.disposable.dispose();
@@ -212,7 +213,18 @@ export class FileSystem {
212213
const result = await this.pitcherClient.clients.fs.watch(
213214
path,
214215
options,
215-
(event) => emitter.fire(event)
216+
(event) => {
217+
if (this.username) {
218+
emitter.fire({
219+
...event,
220+
paths: event.paths.map((path) =>
221+
path.replace(`home/${this.username}/workspace/`, "sandbox/")
222+
),
223+
});
224+
} else {
225+
emitter.fire(event);
226+
}
227+
}
216228
);
217229

218230
if (result.type === "error") {

src/sessions/WebSocketSession/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class WebSocketSession {
3131
/**
3232
* Namespace for all filesystem operations on this Sandbox
3333
*/
34-
public readonly fs = new FileSystem(this.disposable, this.pitcherClient);
34+
public readonly fs: FileSystem;
3535

3636
/**
3737
* Namespace for hosts
@@ -75,7 +75,15 @@ export class WebSocketSession {
7575

7676
constructor(
7777
protected pitcherClient: IPitcherClient,
78-
{ env, hostToken }: { env?: Record<string, string>; hostToken?: HostToken }
78+
{
79+
env,
80+
hostToken,
81+
username,
82+
}: {
83+
env?: Record<string, string>;
84+
hostToken?: HostToken;
85+
username?: string;
86+
}
7987
) {
8088
// TODO: Bring this back once metrics polling does not reset inactivity
8189
// const metricsDisposable = {
@@ -84,6 +92,7 @@ export class WebSocketSession {
8492
// };
8593

8694
// this.addDisposable(metricsDisposable);
95+
this.fs = new FileSystem(this.disposable, this.pitcherClient, username);
8796
this.terminals = new Terminals(this.disposable, this.pitcherClient, env);
8897
this.commands = new Commands(this.disposable, this.pitcherClient, env);
8998

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export type SandboxOpts = {
237237

238238
export type SandboxBrowserSession = PitcherManagerResponse & {
239239
id: string;
240+
sessionId?: string;
240241
env?: Record<string, string>;
241242
hostToken?: HostToken;
242243
};

0 commit comments

Comments
 (0)