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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user