Skip to content

Commit

Permalink
feat(storage): add node storage for memfs
Browse files Browse the repository at this point in the history
  • Loading branch information
JiyuShao committed Jun 20, 2024
1 parent 4457367 commit 7ee1e43
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 59 deletions.
3 changes: 2 additions & 1 deletion packages/configs/typescript-config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"noImplicitReturns": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"experimentalDecorators": true
},
"exclude": ["node_modules", "dist"],
"$schema": "https://json.schemastore.org/tsconfig",
Expand Down
1 change: 1 addition & 0 deletions packages/extensions/js-runner-and-debugger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"process": "^0.11.10",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
"vscode-languageserver": "^9.0.1",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/extensions/js-runner-and-debugger/src/web/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import vscode, { UIKind } from 'vscode';

export const EXTENSION_NAME = 'js-runner-and-debugger';
export const EXTENSION_NAME_SHORT = 'JSRunner';
export const FS_SCHEME = 'memfs';
export const LOGGER_LEVEL = 0; // LogLevel.DEBUG
export const isWebEnv = vscode.env.uiKind === UIKind.Web;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logger } from '../utils/logger';

export async function registerFileSystem(context: vscode.ExtensionContext) {
// init memFs
const memFs = new MemFS();
const memFs = new MemFS(context);

// register a file system provider
context.subscriptions.push(
Expand All @@ -26,6 +26,13 @@ export async function registerFileSystem(context: vscode.ExtensionContext) {

if (!validFlag) {
logger.error(`Only allow single-folder ${FS_SCHEME} workspace`);
await vscode.commands.executeCommand(
'vscode.openFolder',
vscode.Uri.parse(`${FS_SCHEME}:/`),
{
forceReuseWindow: true,
}
);
}

registerCommand(context, `${FS_SCHEME}.importDemoWorkspace`, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { logger } from '../logger';

export function autoInit(
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
const originalMethod = descriptor.value;

descriptor.value = function (...args: any[]) {
const _that = this as AutoInitClass;
if (!_that['_initPromise']) {
_that['_initPromise'] = _that['_init']();
}
return _that['_initPromise']
.then(() => originalMethod.apply(this, args))
.catch((err: Error) => {
logger.debug(
`${target.constructor.name}.${propertyKey} @autoInit failed:`,
err
);
throw err;
});
};

return descriptor;
}

export abstract class AutoInitClass {
protected abstract _init: () => Promise<void>;
protected _initPromise?: Promise<void>;
}
Loading

0 comments on commit 7ee1e43

Please # to comment.