Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from browserfs to OPFS #14263

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)

<!--
- ## 1.55.0 - XX/XX/2024

<a name="breaking_changes_1.55.0">[Breaking Changes:](#breaking_changes_1.55.0)</a>
- [dependencies] remove browserfs dependency (replaced by OPFS)

-->

## 1.54.0 - 09/26/2024

- [ai] add Theia AI LLM Support [Experimental] [#14048](https://github.com/eclipse-theia/theia/pull/14048)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
// *****************************************************************************

import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
import { bindBrowserFSInitialization } from './filesystem/example-filesystem-initialization';
import { bindOPFSInitialization } from './filesystem/example-filesystem-initialization';

export default new ContainerModule((
bind: interfaces.Bind,
_unbind: interfaces.Unbind,
_isBound: interfaces.IsBound,
rebind: interfaces.Rebind,
) => {
bindBrowserFSInitialization(bind, rebind);
bindOPFSInitialization(bind, rebind);
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,40 @@
import { URI } from '@theia/core';
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
import { EncodingService } from '@theia/core/lib/common/encoding-service';
import { BrowserFSInitialization, DefaultBrowserFSInitialization } from '@theia/filesystem/lib/browser-only/browserfs-filesystem-initialization';
import { BrowserFSFileSystemProvider } from '@theia/filesystem/lib/browser-only/browserfs-filesystem-provider';
import type { FSModule } from 'browserfs/dist/node/core/FS';
import { OPFSInitialization, DefaultOPFSInitialization } from '@theia/filesystem/lib/browser-only/opfs-filesystem-initialization';
import { OPFSFileSystemProvider } from '@theia/filesystem/lib/browser-only/opfs-filesystem-provider';

@injectable()
export class ExampleBrowserFSInitialization extends DefaultBrowserFSInitialization {
export class ExampleOPFSInitialization extends DefaultOPFSInitialization {

@inject(EncodingService)
protected encodingService: EncodingService;

override async initializeFS(fs: FSModule, provider: BrowserFSFileSystemProvider): Promise<void> {
override async initializeFS(dir: FileSystemDirectoryHandle, provider: OPFSFileSystemProvider): Promise<void> {
try {
if (!fs.existsSync('/home/workspace')) {
// Check whether the directory exists
try {
await provider.readdir(new URI('/home/workspace'));
} catch (e) {
console.error('An error occurred while reading the demo workspaces', e);
robertjndw marked this conversation as resolved.
Show resolved Hide resolved
await provider.mkdir(new URI('/home/workspace'));
await provider.writeFile(new URI('/home/workspace/my-file.txt'), this.encodingService.encode('foo').buffer, { create: true, overwrite: false });
await provider.writeFile(new URI('/home/workspace/my-file2.txt'), this.encodingService.encode('bar').buffer, { create: true, overwrite: false });
}
if (!fs.existsSync('/home/workspace2')) {

try {
await provider.readdir(new URI('/home/workspace2'));
} catch (e) {
console.error('An error occurred while reading the demo workspaces', e);
await provider.mkdir(new URI('/home/workspace2'));
await provider.writeFile(new URI('/home/workspace2/my-file.json'), this.encodingService.encode('{ foo: true }').buffer, { create: true, overwrite: false });
await provider.writeFile(new URI('/home/workspace2/my-file2.json'), this.encodingService.encode('{ bar: false }').buffer, { create: true, overwrite: false });
}
} catch (e) {
console.error('An error occurred while initializing the demo workspaces', e);
}
}
}

export const bindBrowserFSInitialization = (bind: interfaces.Bind, rebind: interfaces.Rebind): void => {
bind(ExampleBrowserFSInitialization).toSelf();
rebind(BrowserFSInitialization).toService(ExampleBrowserFSInitialization);
export const bindOPFSInitialization = (bind: interfaces.Bind, rebind: interfaces.Rebind): void => {
bind(ExampleOPFSInitialization).toSelf();
rebind(OPFSInitialization).toService(ExampleOPFSInitialization);
};
1 change: 0 additions & 1 deletion packages/filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@types/tar-fs": "^1.16.1",
"async-mutex": "^0.3.1",
"body-parser": "^1.18.3",
"browserfs": "^1.4.3",
robertjndw marked this conversation as resolved.
Show resolved Hide resolved
"http-status-codes": "^1.3.0",
"minimatch": "^5.1.0",
"multer": "1.4.4-lts.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

import { ContainerModule } from '@theia/core/shared/inversify';
import { FileSystemProvider } from '../common/files';
import { BrowserFSFileSystemProvider } from './browserfs-filesystem-provider';
import { OPFSFileSystemProvider } from './opfs-filesystem-provider';
import { RemoteFileSystemProvider, RemoteFileSystemServer } from '../common/remote-file-system-provider';
import { BrowserFSInitialization, DefaultBrowserFSInitialization } from './browserfs-filesystem-initialization';
import { OPFSInitialization, DefaultOPFSInitialization } from './opfs-filesystem-initialization';
import { BrowserOnlyFileSystemProviderServer } from './browser-only-filesystem-provider-server';

export default new ContainerModule((bind, _unbind, isBound, rebind) => {
bind(DefaultBrowserFSInitialization).toSelf();
bind(BrowserFSFileSystemProvider).toSelf();
bind(BrowserFSInitialization).toService(DefaultBrowserFSInitialization);
bind(DefaultOPFSInitialization).toSelf();
bind(OPFSFileSystemProvider).toSelf();
bind(OPFSInitialization).toService(DefaultOPFSInitialization);
if (isBound(FileSystemProvider)) {
rebind(FileSystemProvider).to(BrowserFSFileSystemProvider).inSingletonScope();
rebind(FileSystemProvider).to(OPFSFileSystemProvider).inSingletonScope();
} else {
bind(FileSystemProvider).to(BrowserFSFileSystemProvider).inSingletonScope();
bind(FileSystemProvider).to(OPFSFileSystemProvider).inSingletonScope();
}
if (isBound(RemoteFileSystemProvider)) {
rebind(RemoteFileSystemServer).to(BrowserOnlyFileSystemProviderServer).inSingletonScope();
Expand Down

This file was deleted.

Loading
Loading