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

fix: support resolve plugin path from framework #161

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ pnpm-lock.yaml
lib

# OSX
.DS_Store
.DS_Store

!test/fixtures/frameworks/layer/foo/foo2/node_modules
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = {
],
coverageReporters: ['json', 'json-summary', 'lcov', 'text', 'clover', 'text-summary', 'cobertura'],
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
transformIgnorePatterns: ["/node_modules/(?!(artus_plugin_hbase)/)", "\\.pnp\\.[^\\\/]+$"]
};
3 changes: 2 additions & 1 deletion src/loader/impl/plugin_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class PluginConfigLoader extends ConfigLoader implements Loader {
);
}
if (pluginConfigItem.enable) {
pluginConfigItem.path = ArtusPlugin.getPath(pluginConfigItem.package);
const loaderState = item._loaderState as { baseDir: string };
pluginConfigItem.path = ArtusPlugin.getPath(pluginConfigItem.package, [loaderState.baseDir]);
}
delete pluginConfigItem.package;
configObj[pluginName] = pluginConfigItem;
Expand Down
5 changes: 3 additions & 2 deletions src/plugin/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import path from 'path';
type PluginMap = Map<string, BasePlugin>;

export class BasePlugin implements Plugin {
static getPath(packageName: string): string {
return path.resolve(require.resolve(packageName), '..');
static getPath(packageName: string, paths?: string[]): string {
const opts = paths ? { paths } : undefined;
return path.resolve(require.resolve(packageName, opts), '..');
}

public name: string;
Expand Down
3 changes: 3 additions & 0 deletions src/scanner/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ export class Scanner {
filename,
loader,
source: 'config',
_loaderState: {
baseDir,
},
};
}));
await loaderFactory.loadItemList(configItemList.filter(v => v) as ManifestItem[]);
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/artus_application/src/controller/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Context } from '@artus/pipeline';
export default class Hello {
@Inject('ARTUS_MYSQL')
private client: any;
@Inject('ARTUS_HBASE')
private client2: any;

@HttpMethod({
method: HTTPMethodEnum.GET,
Expand Down Expand Up @@ -36,4 +38,14 @@ export default class Hello {
} : { message: 'plugin redis not enabled' };
return result;
}

@HttpMethod({
method: HTTPMethodEnum.GET,
path: '/plugin-hbase',
})
async getHbaseClient() {
return {
client: await this.client2.getClient(),
};
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/fixtures/frameworks/layer/foo/foo2/src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
hbase: {
enable: true,
package: 'artus_plugin_hbase',
},
};
2 changes: 2 additions & 0 deletions test/framework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe('test/framework.test.ts', () => {
assert(testResponseName4.data.client === 'mysql-ob');
const testResponseName5 = await axios.get(`http://127.0.0.1:${port}/plugin-redis`);
assert(testResponseName5.data.message === 'plugin redis not enabled');
const testResponseName6 = await axios.get(`http://127.0.0.1:${port}/plugin-hbase`);
assert(testResponseName6.data.client === 'foo2-hbase');

await app.artus.close();
assert(!app.isListening());
Expand Down