Skip to content

Commit

Permalink
fix: add module check and config file match (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrysShan authored Sep 15, 2022
1 parent d171511 commit bc7fdbb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const DEFAULT_EXCLUDES = [

export const FRAMEWORK_PATTERN = 'framework.*';
export const PLUGIN_CONFIG_PATTERN = 'plugin.*';
export const CONFIG_PATTERN = 'config.*';
export const PACKAGE_JSON = 'package.json';
export const PLUGIN_META_FILENAME = 'meta.json';
export const EXCEPTION_FILENAME = 'exception.json';
Expand Down
11 changes: 6 additions & 5 deletions src/loader/impl/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import { Container } from '@artus/injection';
import ConfigurationHandler from '../../configuration';
import { ArtusInjectEnum, CONFIG_PATTERN } from '../../constant';
import { ArtusInjectEnum, PLUGIN_CONFIG_PATTERN, FRAMEWORK_PATTERN } from '../../constant';
import { DefineLoader } from '../decorator';
import { ManifestItem, Loader, LoaderFindOptions } from '../types';
import compatibleRequire from '../../utils/compatible_require';
Expand All @@ -26,10 +26,11 @@ class ConfigLoader implements Loader {
}

static async is(opts: LoaderFindOptions): Promise<boolean> {
if (this.isConfigDir(opts)) {
return isMatch(opts.filename, CONFIG_PATTERN);
}
return false;
return (
this.isConfigDir(opts) &&
!isMatch(opts.filename, PLUGIN_CONFIG_PATTERN) &&
!isMatch(opts.filename, FRAMEWORK_PATTERN)
);
}

protected static isConfigDir(opts: LoaderFindOptions): boolean {
Expand Down
3 changes: 3 additions & 0 deletions src/loader/impl/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class ModuleLoader implements Loader {

for (const name of state.exportNames) {
const moduleClazz = origin[name];
if (typeof moduleClazz !== 'function') {
continue;
}
const opts: Partial<InjectableDefinition> = {
type: moduleClazz,
scope: ScopeEnum.EXECUTION, // The class used with @artus/core will have default scope EXECUTION, can be overwritten by Injectable decorator
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Application {
}

export interface TriggerType {
use(...args): Promise<void>;
initContext(...args): Promise<BaseContext>;
use(...args): void | Promise<void>;
initContext(...args): BaseContext | Promise<BaseContext>;
startPipeline(...args): Promise<void>;
}
2 changes: 1 addition & 1 deletion test/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('test/loader.test.ts', () => {
filename: 'test_clazz.ts',
root: path.resolve(__dirname, './fixtures/module_with_custom_loader/src'),
baseDir: path.resolve(__dirname, './fixtures/module_with_custom_loader/src'),
configDir: '',
configDir: 'src/config',
});
expect(loaderName).toBe('test-custom-loader');
jest.spyOn(console, 'log');
Expand Down

0 comments on commit bc7fdbb

Please sign in to comment.