Skip to content

Commit

Permalink
fix(untyped): use schema module default export if is the only export
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 5, 2024
1 parent f409edb commit cc26726
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/builders/untyped/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ export async function typesBuild(ctx: BuildContext): Promise<void> {
const untypedJiti = createJiti(ctx.options.rootDir, options.jiti);

const distDir = entry.outDir!;
const srcConfig =

let rawSchema =
((await untypedJiti.import(resolve(ctx.options.rootDir, entry.input), {
try: true,
})) as InputObject) || ({} as InputObject);

const rawSchemaKeys = Object.keys(rawSchema);
if (rawSchemaKeys.length === 1 && rawSchemaKeys[0] === "default") {
rawSchema = (rawSchema as any).default;
}

const defaults = entry.defaults || {};
const schema = await resolveSchema(srcConfig, defaults);
const schema = await resolveSchema(rawSchema, defaults);

await ctx.hooks.callHook("untyped:entry:schema", ctx, entry, schema);

Expand Down

0 comments on commit cc26726

Please sign in to comment.