Skip to content

Commit 1a2e721

Browse files
Sunny  TyagiSunny  Tyagi
authored andcommitted
feat(core): resolve sonar issues
resolve sonar issues gh-86
1 parent e7d2cba commit 1a2e721

2 files changed

Lines changed: 15 additions & 33 deletions

File tree

packages/core/src/__tests__/unit/booters/core-model.booter.unit.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ describe('CoreModelBooter', () => {
2929
sinon.restore();
3030
});
3131

32-
it('should skip load when component is not found', async () => {
33-
const getSyncSpy = sinon.spy(ctx, 'getSync');
34-
const booter = new DummyBooter(ctx);
35-
await booter.discover();
36-
await booter.load();
37-
38-
// Assert context tried to get the component, but failed silently
39-
sinon.assert.calledWith(getSyncSpy, 'components.MyComponent');
40-
});
41-
4232
it('should skip load when component has no models', async () => {
4333
class NoModelComponent implements Component {}
4434

packages/core/src/booters/base.booter.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,25 @@ export class BaseBooter implements Booter {
5252
* NOTE: All properties are configured even if all aren't used.
5353
*/
5454
async configure() {
55-
if (this.options.dirs) {
56-
this.dirs = Array.isArray(this.options.dirs)
57-
? this.options.dirs
58-
: [this.options.dirs];
59-
} else {
60-
this.dirs = [];
61-
}
55+
this.dirs = this.normalizeToArray(this.options.dirs);
56+
this.extensions = this.normalizeToArray(this.options.extensions);
6257

63-
if (this.options.extensions) {
64-
this.extensions = Array.isArray(this.options.extensions)
65-
? this.options.extensions
66-
: [this.options.extensions];
67-
} else {
68-
this.extensions = [];
69-
}
58+
const joinedDirs = this.formatDirs(this.dirs);
59+
const joinedExts = `@(${this.extensions.join('|')})`;
7060

71-
let joinedDirs = this.dirs.join(',');
72-
if (this.dirs.length > 1) joinedDirs = `{${joinedDirs}}`;
61+
this.glob =
62+
this.options.glob ??
63+
`/${joinedDirs}/${this.options.nested ? '**/*' : '*'}${joinedExts}`;
64+
}
7365

74-
const joinedExts = `@(${this.extensions.join('|')})`;
66+
private normalizeToArray<T>(value: T | T[] | undefined): T[] {
67+
if (!value) return [];
68+
return Array.isArray(value) ? value : [value];
69+
}
7570

76-
if (this.options.glob) {
77-
this.glob = this.options.glob;
78-
} else {
79-
const pattern = this.options.nested ? '**/*' : '*';
80-
this.glob = `/${joinedDirs}/${pattern}${joinedExts}`;
81-
}
71+
private formatDirs(dirs: string[]): string {
72+
if (dirs.length > 1) return `{${dirs.join(',')}}`;
73+
return dirs.join(',');
8274
}
8375

8476
/**

0 commit comments

Comments
 (0)