Skip to content

Commit

Permalink
Allow undefined and false in composable array
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Nov 4, 2023
1 parent 90a72fe commit b8f5f08
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/library/boilerplate/composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Composable, File} from '../file/index.js';

export type ComposableModuleDefault =
| Composable
| Composable[]
| (Composable | false | undefined)[]
| undefined
| ComposableBuilder;

Expand All @@ -13,9 +13,11 @@ export type ComposableBuilder<
options: TOptions,
) =>
| Composable<TFile>
| Composable<TFile>[]
| (Composable<TFile> | false | undefined)[]
| undefined
| Promise<Composable<TFile> | Composable<TFile>[] | undefined>;
| Promise<
Composable<TFile> | (Composable<TFile> | false | undefined)[] | undefined
>;

/**
* A utility function that returns the givin composable / composable module function as-is.
Expand Down
39 changes: 23 additions & 16 deletions packages/core/src/library/boilerplate/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,30 @@ export async function composables(
const baseDir = Path.relative(root, Path.dirname(composableModulePath));

allComposables.push(
...composables.map(composable => {
const {path} = composable;

return {
source: composableModulePath,
target: path
? Path.join(baseDir, path)
: Path.join(
baseDir,
Path.basename(
composableModulePath,
Path.extname(composableModulePath),
...composables
.filter(
(
composable,
): composable is Exclude<typeof composable, false | undefined> =>
!!composable,
)
.map(composable => {
const {path} = composable;

return {
source: composableModulePath,
target: path
? Path.join(baseDir, path)
: Path.join(
baseDir,
Path.basename(
composableModulePath,
Path.extname(composableModulePath),
),
),
),
...composable,
};
}),
...composable,
};
}),
);
}

Expand Down

0 comments on commit b8f5f08

Please sign in to comment.