Skip to content

Commit

Permalink
Merge branch 'feat/deno-runtime' into deno/logger
Browse files Browse the repository at this point in the history
  • Loading branch information
tapiarafael authored Nov 27, 2023
2 parents c04c9a5 + 419ae51 commit 6629e57
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 42 deletions.
2 changes: 1 addition & 1 deletion deno-runtime/acorn-walk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ export function findNodeAround<TState>(
*/
export const findNodeAfter: typeof findNodeAround

export const base: RecursiveVisitors<any>
export const base: RecursiveVisitors<unknown>
2 changes: 1 addition & 1 deletion deno-runtime/lib/ast/tests/data/ast_blocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @deno-types="../../../../acorn.d.ts"
import { AnyNode, CallExpression, ClassDeclaration, ExpressionStatement, FunctionDeclaration, VariableDeclaration } from 'acorn';
import { AnyNode, ClassDeclaration, ExpressionStatement, FunctionDeclaration, VariableDeclaration } from 'acorn';

/**
* Partial AST blocks to support testing.
Expand Down
20 changes: 5 additions & 15 deletions src/server/runtime/AppsEngineDenoRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ export function getDenoWrapperPath(): string {
}
}

type ControllerDeps = {
accessors: AppAccessorManager;
api: AppApiManager;
};

export class DenoRuntimeSubprocessController extends EventEmitter {
private readonly deno: child_process.ChildProcess;

Expand Down Expand Up @@ -90,9 +85,9 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
this.state = 'invalid';
}

// this.accessors = manager.getAccessorManager();
// this.api = manager.getApiManager();
// this.logStorage = manager.getLogStorage();
this.accessors = manager.getAccessorManager();
this.api = manager.getApiManager();
this.logStorage = manager.getLogStorage();
}

emit(eventName: string | symbol, ...args: any[]): boolean {
Expand Down Expand Up @@ -328,19 +323,14 @@ type ExecRequestContext = {
export class AppsEngineDenoRuntime {
private readonly subprocesses: Record<string, DenoRuntimeSubprocessController> = {};

private readonly appManager: AppManager;

// constructor(manager: AppManager) {
// this.accessorManager = manager.getAccessorManager();
// this.apiManager = manager.getApiManager();
// }
constructor(private readonly manager: AppManager) {}

public async startRuntimeForApp({ appId, appSource }: AppRuntimeParams, options = { force: false }): Promise<void> {
if (appId in this.subprocesses && !options.force) {
throw new Error('App already has an associated runtime');
}

this.subprocesses[appId] = new DenoRuntimeSubprocessController(appId, appSource, this.appManager);
this.subprocesses[appId] = new DenoRuntimeSubprocessController(appId, appSource, this.manager);

await this.subprocesses[appId].setupApp();
}
Expand Down
15 changes: 0 additions & 15 deletions src/server/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AppsEngineDenoRuntime } from './AppsEngineDenoRuntime';
import { AppsEngineNodeRuntime } from './AppsEngineNodeRuntime';
import { AppsEngineVM2Runtime } from './AppsEngineVM2Runtime';

Expand All @@ -16,17 +15,3 @@ export function _getRuntime(requiredEnv = 'vm2'): AvailableRuntime {
export function getRuntime() {
return _getRuntime(process.env?.ROCKETCHAT_APPS_ENGINE_RUNTIME);
}

export function _getDenoRuntime() {
const runtime = new AppsEngineDenoRuntime();

runtime.startRuntimeForApp({
appId: 'appId',
appSource: 'module.exports={ default: new class { constructor() { this.name = "parangarico" } } };console.log("hi from app")',
});
}

// Used for testing during dev cycle
if (process.argv.includes('bruh')) {
_getDenoRuntime();
}
19 changes: 9 additions & 10 deletions tests/server/runtime/DenoRuntimeSubprocessController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@ import { TestFixture, Setup, SetupFixture, Expect, AsyncTest } from 'alsatian';
import { AppAccessorManager, AppApiManager } from '../../../src/server/managers';
import { TestData, TestInfastructureSetup } from '../../test-data/utilities';
import { DenoRuntimeSubprocessController } from '../../../src/server/runtime/AppsEngineDenoRuntime';
import type { AppManager } from '../../../src/server/AppManager';

@TestFixture('DenoRuntimeSubprocessController')
export class DenuRuntimeSubprocessControllerTestFixture {
private accessors: AppAccessorManager;

private api: AppApiManager;

private simpleAppSource = 'module.exports={ default: new class { constructor() { this.name = "parangarico" } } };console.log("hi from app")';

private manager: AppManager;

private controller: DenoRuntimeSubprocessController;

@SetupFixture
public fixture() {
const infrastructure = new TestInfastructureSetup();
const manager = infrastructure.getMockManager();
this.manager = infrastructure.getMockManager();

this.accessors = new AppAccessorManager(manager);
const accessors = new AppAccessorManager(this.manager);

manager.getAccessorManager = () => this.accessors;
this.manager.getAccessorManager = () => accessors;

this.api = new AppApiManager(manager);
const api = new AppApiManager(this.manager);

manager.getApiManager = () => this.api;
this.manager.getApiManager = () => api;
}

@Setup
public setup() {
const app = TestData.getMockApp('deno-controller', 'Deno Controller test');

this.controller = new DenoRuntimeSubprocessController(app.getID(), this.simpleAppSource, { accessors: this.accessors, api: this.api });
this.controller = new DenoRuntimeSubprocessController(app.getID(), this.simpleAppSource, this.manager);
}

@AsyncTest('correctly identifies a call to the HTTP accessor')
Expand Down

0 comments on commit 6629e57

Please sign in to comment.