Skip to content

Commit

Permalink
fix: correct imports in Mock handlers without index (#1758)
Browse files Browse the repository at this point in the history
fixes: #1547
  • Loading branch information
AlmarAubel authored Dec 20, 2024
1 parent 5be5cd4 commit 5a1b087
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions packages/core/src/writers/split-tags-mode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import fs from 'fs-extra';
import { generateModelsInline, generateMutatorImports } from '../generators';
import { OutputClient, WriteModeProps } from '../types';
import {
GeneratorImport,
NormalizedOutputOptions,
OutputClient,
WriteModeProps,
} from '../types';
import {
camel,
getFileInfo,
Expand Down Expand Up @@ -58,13 +63,11 @@ export const writeSplitTagsMode = async ({
)
: '../' + filename + '.schemas';

const importsForBuilder =
output.schemas && !output.indexFiles
? uniqBy(imports, 'name').map((i) => ({
exports: [i],
dependency: upath.join(relativeSchemasPath, camel(i.name)),
}))
: [{ exports: imports, dependency: relativeSchemasPath }];
const importsForBuilder = generateImports(
output,
imports,
relativeSchemasPath,
);

implementationData += builder.imports({
client: output.client,
Expand All @@ -81,9 +84,16 @@ export const writeSplitTagsMode = async ({
packageJson: output.packageJson,
output,
});

const importsMockForBuilder = generateImports(
output,
importsMock,
relativeSchemasPath,
);

mockData += builder.importsMock({
implementation: implementationMock,
imports: [{ exports: importsMock, dependency: relativeSchemasPath }],
imports: importsMockForBuilder,
specsName,
hasSchemaDir: !!output.schemas,
isAllowSyntheticDefaultImports,
Expand Down Expand Up @@ -182,3 +192,15 @@ export const writeSplitTagsMode = async ({

return generatedFilePathsArray.flatMap((it) => it);
};

const generateImports = (
output: NormalizedOutputOptions,
imports: GeneratorImport[],
relativeSchemasPath: string,
) =>
output.schemas && !output.indexFiles
? uniqBy(imports, 'name').map((i) => ({
exports: [i],
dependency: upath.join(relativeSchemasPath, camel(i.name)),
}))
: [{ exports: imports, dependency: relativeSchemasPath }];

0 comments on commit 5a1b087

Please sign in to comment.