Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Sep 6, 2024
1 parent f949ef9 commit 3878eb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions packages/cli/src/utils/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
RedoclyClient,
} from '@redocly/openapi-core';
import {
isEmptyArray,
isEmptyObject,
isNotEmptyArray,
isNotEmptyObject,
Expand Down Expand Up @@ -49,8 +48,7 @@ export async function getFallbackApisOrExit(
config: ConfigApis
): Promise<Entrypoint[]> {
const { apis } = config;
const shouldFallbackToAllDefinitions =
(!argsApis || isEmptyArray(argsApis)) && isNotEmptyObject(apis);
const shouldFallbackToAllDefinitions = !isNotEmptyArray(argsApis) && isNotEmptyObject(apis);
const res = shouldFallbackToAllDefinitions
? fallbackToAllDefinitions(apis, config)
: await expandGlobsInEntrypoints(argsApis!, config);
Expand Down Expand Up @@ -91,11 +89,12 @@ function fallbackToAllDefinitions(
}

function getAliasOrPath(config: ConfigApis, aliasOrPath: string): Entrypoint {
return config.apis[aliasOrPath]
const aliasApi = config.apis[aliasOrPath];
return aliasApi
? {
path: config.apis[aliasOrPath]?.root,
path: aliasApi.root,
alias: aliasOrPath,
output: config.apis[aliasOrPath]?.output,
output: aliasApi.output,
}
: {
path: aliasOrPath,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function isEmptyArray(value: unknown) {
}

export function isNotEmptyArray<T>(args?: T[]): boolean {
return Array.isArray(args) && !!args.length;
return !!args && Array.isArray(args) && !!args.length;
}

export async function readFileFromUrl(url: string, config: HttpResolveConfig) {
Expand Down

0 comments on commit 3878eb6

Please sign in to comment.