Skip to content

Commit c077192

Browse files
authored
Merge pull request #16 from appwrite/feat-workDir-update
chore: add updateWorkDir to individual instance
2 parents 162bc74 + cf9fd31 commit c077192

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@appwrite.io/synapse",
3-
"version": "0.4.4",
3+
"version": "0.4.5",
44
"description": "Operating system gateway for remote serverless environments",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/services/filesystem.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,17 @@ export class Filesystem {
464464
}
465465
}
466466

467+
/**
468+
* Updates the working directory
469+
* @param workDir - The new working directory
470+
*/
471+
updateWorkDir(workDir: string): void {
472+
if (!fsSync.existsSync(workDir)) {
473+
fsSync.mkdirSync(workDir, { recursive: true });
474+
}
475+
this.workDir = workDir;
476+
}
477+
467478
/**
468479
* Cleans up all folder watchers and releases resources.
469480
*/

src/services/git.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,15 @@ export class Git {
190190
async push(): Promise<GitOperationResult> {
191191
return this.execute(["push"]);
192192
}
193+
194+
/**
195+
* Updates the working directory
196+
* @param workDir - The new working directory
197+
*/
198+
updateWorkDir(workDir: string): void {
199+
if (!fs.existsSync(workDir)) {
200+
fs.mkdirSync(workDir, { recursive: true });
201+
}
202+
this.workDir = workDir;
203+
}
193204
}

src/services/terminal.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from "fs";
12
import * as pty from "node-pty";
23
import * as os from "os";
34
import { Synapse } from "../synapse";
@@ -150,6 +151,10 @@ export class Terminal {
150151
*/
151152
updateWorkDir(workDir: string): void {
152153
try {
154+
if (!fs.existsSync(workDir)) {
155+
fs.mkdirSync(workDir, { recursive: true });
156+
}
157+
153158
this.checkTerminal();
154159
this.createCommand(`cd "${workDir}"\n`);
155160
} catch (error) {

tests/services/terminal.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from "fs";
12
import * as pty from "node-pty";
23
import { Terminal, TerminalOptions } from "../../src/services/terminal";
34
import { Synapse } from "../../src/synapse";
@@ -9,7 +10,6 @@ describe("Terminal", () => {
910
let mockSynapse: Synapse;
1011
let mockPty: jest.Mocked<pty.IPty>;
1112
let onDataHandler: (data: string) => void;
12-
let onExitHandler: () => void;
1313

1414
beforeEach(() => {
1515
mockSynapse = new Synapse();
@@ -18,8 +18,7 @@ describe("Terminal", () => {
1818
onDataHandler = callback;
1919
return mockPty;
2020
}),
21-
onExit: jest.fn((callback) => {
22-
onExitHandler = callback;
21+
onExit: jest.fn(() => {
2322
return mockPty;
2423
}),
2524
write: jest.fn(),
@@ -35,6 +34,7 @@ describe("Terminal", () => {
3534
describe("basic terminal functionality", () => {
3635
beforeEach(() => {
3736
terminal = new Terminal(mockSynapse);
37+
jest.spyOn(fs, "existsSync").mockReturnValue(true);
3838
});
3939

4040
it("should initialize with correct state", () => {
@@ -60,6 +60,7 @@ describe("Terminal", () => {
6060
describe("terminal operations", () => {
6161
beforeEach(() => {
6262
terminal = new Terminal(mockSynapse);
63+
jest.spyOn(fs, "existsSync").mockReturnValue(true);
6364
});
6465

6566
it("should update working directory", () => {

0 commit comments

Comments
 (0)