Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appwrite.io/synapse",
"version": "0.4.4",
"version": "0.4.5",
"description": "Operating system gateway for remote serverless environments",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
11 changes: 11 additions & 0 deletions src/services/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,17 @@ export class Filesystem {
}
}

/**
* Updates the working directory
* @param workDir - The new working directory
*/
updateWorkDir(workDir: string): void {
if (!fsSync.existsSync(workDir)) {
fsSync.mkdirSync(workDir, { recursive: true });
}
this.workDir = workDir;
}

/**
* Cleans up all folder watchers and releases resources.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/services/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,15 @@ export class Git {
async push(): Promise<GitOperationResult> {
return this.execute(["push"]);
}

/**
* Updates the working directory
* @param workDir - The new working directory
*/
updateWorkDir(workDir: string): void {
if (!fs.existsSync(workDir)) {
fs.mkdirSync(workDir, { recursive: true });
}
this.workDir = workDir;
}
}
5 changes: 5 additions & 0 deletions src/services/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from "fs";
import * as pty from "node-pty";
import * as os from "os";
import { Synapse } from "../synapse";
Expand Down Expand Up @@ -150,6 +151,10 @@ export class Terminal {
*/
updateWorkDir(workDir: string): void {
try {
if (!fs.existsSync(workDir)) {
fs.mkdirSync(workDir, { recursive: true });
}

this.checkTerminal();
this.createCommand(`cd "${workDir}"\n`);
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions tests/services/terminal.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from "fs";
import * as pty from "node-pty";
import { Terminal, TerminalOptions } from "../../src/services/terminal";
import { Synapse } from "../../src/synapse";
Expand All @@ -9,7 +10,6 @@ describe("Terminal", () => {
let mockSynapse: Synapse;
let mockPty: jest.Mocked<pty.IPty>;
let onDataHandler: (data: string) => void;
let onExitHandler: () => void;

beforeEach(() => {
mockSynapse = new Synapse();
Expand All @@ -18,8 +18,7 @@ describe("Terminal", () => {
onDataHandler = callback;
return mockPty;
}),
onExit: jest.fn((callback) => {
onExitHandler = callback;
onExit: jest.fn(() => {
return mockPty;
}),
write: jest.fn(),
Expand All @@ -35,6 +34,7 @@ describe("Terminal", () => {
describe("basic terminal functionality", () => {
beforeEach(() => {
terminal = new Terminal(mockSynapse);
jest.spyOn(fs, "existsSync").mockReturnValue(true);
});

it("should initialize with correct state", () => {
Expand All @@ -60,6 +60,7 @@ describe("Terminal", () => {
describe("terminal operations", () => {
beforeEach(() => {
terminal = new Terminal(mockSynapse);
jest.spyOn(fs, "existsSync").mockReturnValue(true);
});

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