Skip to content

Commit

Permalink
fix: provider check (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar committed Aug 18, 2020
1 parent 3ddef46 commit c2808bf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/faas-cli-command-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class CommandHookCore implements ICommandHooksCore {

// 添加插件
public addPlugin(Plugin: any) {
const provider = this.options.provider;
const provider =
this.options.service?.provider?.name || this.options.provider;
const coreInstance: ICoreInstance = this.coreInstance;
let pluginProvider = '';
// 支持加载npm 或 本地插件(绝对地址)
Expand Down
2 changes: 2 additions & 0 deletions packages/faas-cli-command-core/test/core.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommandHookCore } from '../src';
import TestPlugin from './plugins/test.invoke';
import { PluginTest2 } from './plugins/test-not-provider.invoke';
import * as assert from 'assert';
import { join } from 'path';
import { readFileSync } from 'fs';
Expand All @@ -17,6 +18,7 @@ describe('command-core', () => {
stopLifecycle: 'invoke:one',
});
core.addPlugin(TestPlugin);
core.addPlugin(PluginTest2);
await core.ready();
await core.invoke(['invoke']);
assert(result && result.length === 3);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1597737411780
1597752211550
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BasePlugin } from '../../src';

export class PluginTest2 extends BasePlugin {
provider = 'test2';
hooks = {
'before:invoke:one': () => {
this.core.cli.log('before:invoke:one');
},
'invoke:one': async () => {
this.core.cli.log('invoke:one');
},
'after:invoke:one': () => {
this.core.cli.log('after:invoke:one');
},
'before:invoke:two': async () => {
this.core.cli.log('before:invoke:two');
},
'invoke:two': () => {
this.core.cli.log('invoke:two');
},
'after:invoke:two': async () => {
this.core.cli.log('after:invoke:two');
},
};
}

0 comments on commit c2808bf

Please sign in to comment.