Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
fix: invoke user runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar committed Dec 31, 2019
1 parent 3ab1b5f commit 7e5ab36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/command-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export = class CommandHookCore implements ICommandHooksCore {
if (commandInstance.commands) {
this.loadCommands(
instance,
commandsMap[command].command,
commandsMap[command].commands,
commandInstance.commands,
(parentCommandList || []).concat(command)
);
Expand Down
27 changes: 21 additions & 6 deletions packages/faas-plugin-common/src/plugins/invoke/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Local {
};
handler?: string;
layers?: any;
runtime?: string;
}) {
this.opts = opts;
this.baseDir = opts.baseDir = opts.baseDir || process.cwd();
Expand Down Expand Up @@ -117,18 +118,32 @@ export class Local {
return wrapFun(...args);
};

let handler = null;
let othRuntime = null;
if (this.opts.starter) {
try {
const starter = require(this.opts.starter);
runtime = createRuntime({
handler: starter.asyncWrapper(async (...args) => {
const innerRuntime = await starter.start({});
return innerRuntime.asyncEvent(innerFun)(...args);
}),
layers: this.extensions || []
handler = starter.asyncWrapper(async (...args) => {
const innerRuntime = await starter.start({});
return innerRuntime.asyncEvent(innerFun)(...args);
});
} catch (e) {}
}

if (this.opts.runtime) {
try {
const runtimeClass = require(this.opts.runtime);
othRuntime = new runtimeClass();
} catch (e) {}
}

if (handler || othRuntime) {
runtime = createRuntime({
handler,
runtime: othRuntime,
layers: this.extensions || []
});
}
if (this.opts.event) {
try {
const EventModule = require(this.opts.event.path);
Expand Down
10 changes: 10 additions & 0 deletions packages/faas-plugin-common/test/invoke.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { invoke } from '../src/plugins/invoke/main';
// import * as assert from 'assert';
describe('/test/invoke.test.ts', () => {
it('default invoke', async () => {
await invoke({
functionDir: __dirname,
functionName: 'index'
});
});
});

0 comments on commit 7e5ab36

Please sign in to comment.