Skip to content

Commit

Permalink
fix: align decap util typings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidenke committed Oct 21, 2024
1 parent e00ab61 commit b96171b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/modules.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'decap-cms-core/dist/esm/actions/config.js' {
import type { CmsConfig } from 'decap-cms-core';
export function parseConfig(data: string): Partial<CmsConfig>;
export function parseConfig(data: string): Partial<CmsConfig | null>;
export function normalizeConfig(config: Partial<CmsConfig>): CmsConfig;
}
6 changes: 4 additions & 2 deletions src/utils/decap.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function loadDecapConfig(ymlPath: string): Promise<CmsConfig> {
return parseConfig(configRaw);
}

export async function parseConfig(ymlData: string): Promise<CmsConfig> {
export async function parseConfig(ymlData: string): Promise<CmsConfig | undefined> {
// in order to use the config utils from Decap CMS in Node,
// we need to mock some globals first
if (!('window' in globalThis)) {
Expand All @@ -57,7 +57,9 @@ export async function parseConfig(ymlData: string): Promise<CmsConfig> {
'decap-cms-core/dist/esm/actions/config.js'
);

return normalizeConfig(parseConfig(ymlData));
const parsedConfig = parseConfig(ymlData) ?? undefined;
if (parsedConfig) return normalizeConfig(parsedConfig);
return undefined;
}

export function getCollection(config: CmsConfig, name: string): CmsCollection | undefined {
Expand Down

0 comments on commit b96171b

Please sign in to comment.