feat(filetree): add filesystem watch support to WebContainer environment and auto-refresh file tree; improve icon handling and context menu behavior

This commit is contained in:
2025-12-31 08:53:01 +00:00
parent 9e229543eb
commit e193e28fe9
7 changed files with 345 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
import * as webcontainer from '@webcontainer/api';
import type { IExecutionEnvironment, IFileEntry, IProcessHandle } from '../interfaces/IExecutionEnvironment.js';
import type { IExecutionEnvironment, IFileEntry, IFileWatcher, IProcessHandle } from '../interfaces/IExecutionEnvironment.js';
/**
* WebContainer-based execution environment.
@@ -123,6 +123,22 @@ export class WebContainerEnvironment implements IExecutionEnvironment {
}
}
public watch(
path: string,
callback: (event: 'rename' | 'change', filename: string | null) => void,
options?: { recursive?: boolean }
): IFileWatcher {
this.ensureReady();
const watcher = this.container!.fs.watch(
path,
{ recursive: options?.recursive ?? false },
callback
);
return {
stop: () => watcher.close(),
};
}
// ============ Process Execution ============
public async spawn(command: string, args: string[] = []): Promise<IProcessHandle> {