From 47d336778eea80ccb01c5edd5d84d3f202133068 Mon Sep 17 00:00:00 2001 From: yoshi2no <57059705+yoshi2no@users.noreply.github.com> Date: Sat, 7 Sep 2024 20:48:03 +0900 Subject: [PATCH] fix: import react deps when tags have mutator (#1614) * fix: import react deps when tags have mutator * chore: update root yarn.lock * chore: fix format --- packages/core/src/types.ts | 2 + packages/core/src/writers/single-mode.ts | 3 + packages/core/src/writers/split-mode.ts | 3 + packages/core/src/writers/split-tags-mode.ts | 3 + packages/core/src/writers/tags-mode.ts | 3 + packages/orval/src/client.ts | 2 + packages/query/src/index.ts | 3 +- yarn.lock | 58 ++++++++++---------- 8 files changed, 47 insertions(+), 30 deletions(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 8f2c3d464..2ba8d9a3a 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -815,6 +815,7 @@ export type ClientDependenciesBuilder = ( hasParamsSerializerOptions: boolean, packageJson?: PackageJson, httpClient?: OutputHttpClient, + hasTagsMutator?: boolean, ) => GeneratorDependency[]; export type ClientMockGeneratorImplementation = { @@ -1051,6 +1052,7 @@ export type GeneratorClientImports = (data: { hasSchemaDir: boolean; isAllowSyntheticDefaultImports: boolean; hasGlobalMutator: boolean; + hasTagsMutator: boolean; hasParamsSerializerOptions: boolean; packageJson?: PackageJson; output: NormalizedOutputOptions; diff --git a/packages/core/src/writers/single-mode.ts b/packages/core/src/writers/single-mode.ts index 898c1b864..41ef4d527 100644 --- a/packages/core/src/writers/single-mode.ts +++ b/packages/core/src/writers/single-mode.ts @@ -68,6 +68,9 @@ export const writeSingleMode = async ({ hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, hasGlobalMutator: !!output.override.mutator, + hasTagsMutator: Object.values(output.override.tags).some( + (tag) => !!tag.mutator, + ), hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, output, diff --git a/packages/core/src/writers/split-mode.ts b/packages/core/src/writers/split-mode.ts index 5b140fd6f..241f3f4ca 100644 --- a/packages/core/src/writers/split-mode.ts +++ b/packages/core/src/writers/split-mode.ts @@ -60,6 +60,9 @@ export const writeSplitMode = async ({ hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, hasGlobalMutator: !!output.override.mutator, + hasTagsMutator: Object.values(output.override.tags).some( + (tag) => !!tag.mutator, + ), hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, output, diff --git a/packages/core/src/writers/split-tags-mode.ts b/packages/core/src/writers/split-tags-mode.ts index bce40495c..65a39dad5 100644 --- a/packages/core/src/writers/split-tags-mode.ts +++ b/packages/core/src/writers/split-tags-mode.ts @@ -74,6 +74,9 @@ export const writeSplitTagsMode = async ({ hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, hasGlobalMutator: !!output.override.mutator, + hasTagsMutator: Object.values(output.override.tags).some( + (tag) => !!tag.mutator, + ), hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, output, diff --git a/packages/core/src/writers/tags-mode.ts b/packages/core/src/writers/tags-mode.ts index 87ad830b9..2e6a81d1c 100644 --- a/packages/core/src/writers/tags-mode.ts +++ b/packages/core/src/writers/tags-mode.ts @@ -73,6 +73,9 @@ export const writeTagsMode = async ({ hasSchemaDir: !!output.schemas, isAllowSyntheticDefaultImports, hasGlobalMutator: !!output.override.mutator, + hasTagsMutator: Object.values(output.override.tags).some( + (tag) => !!tag.mutator, + ), hasParamsSerializerOptions: !!output.override.paramsSerializerOptions, packageJson: output.packageJson, output, diff --git a/packages/orval/src/client.ts b/packages/orval/src/client.ts index 59d7d42ae..d4552ec40 100644 --- a/packages/orval/src/client.ts +++ b/packages/orval/src/client.ts @@ -65,6 +65,7 @@ export const generateClientImports: GeneratorClientImports = ({ hasSchemaDir, isAllowSyntheticDefaultImports, hasGlobalMutator, + hasTagsMutator, hasParamsSerializerOptions, packageJson, output, @@ -79,6 +80,7 @@ export const generateClientImports: GeneratorClientImports = ({ hasParamsSerializerOptions, packageJson, output.httpClient, + hasTagsMutator, ), ...imports, ] diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 2b8f37829..2c53d50b6 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -209,6 +209,7 @@ export const getReactQueryDependencies: ClientDependenciesBuilder = ( hasParamsSerializerOptions, packageJson, httpClient, + hasTagsMutator, ) => { const hasReactQuery = packageJson?.dependencies?.['react-query'] ?? @@ -220,7 +221,7 @@ export const getReactQueryDependencies: ClientDependenciesBuilder = ( packageJson?.peerDependencies?.['@tanstack/react-query']; return [ - ...(hasGlobalMutator ? REACT_DEPENDENCIES : []), + ...(hasGlobalMutator || hasTagsMutator ? REACT_DEPENDENCIES : []), ...(!hasGlobalMutator && httpClient === OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : []), diff --git a/yarn.lock b/yarn.lock index 843dcafe4..ebd6d96f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1165,23 +1165,23 @@ __metadata: languageName: node linkType: hard -"@orval/angular@npm:7.0.1, @orval/angular@workspace:packages/angular": +"@orval/angular@npm:7.1.0, @orval/angular@workspace:packages/angular": version: 0.0.0-use.local resolution: "@orval/angular@workspace:packages/angular" dependencies: - "@orval/core": "npm:7.0.1" + "@orval/core": "npm:7.1.0" languageName: unknown linkType: soft -"@orval/axios@npm:7.0.1, @orval/axios@workspace:packages/axios": +"@orval/axios@npm:7.1.0, @orval/axios@workspace:packages/axios": version: 0.0.0-use.local resolution: "@orval/axios@workspace:packages/axios" dependencies: - "@orval/core": "npm:7.0.1" + "@orval/core": "npm:7.1.0" languageName: unknown linkType: soft -"@orval/core@npm:7.0.1, @orval/core@workspace:packages/core": +"@orval/core@npm:7.1.0, @orval/core@workspace:packages/core": version: 0.0.0-use.local resolution: "@orval/core@workspace:packages/core" dependencies: @@ -1219,62 +1219,62 @@ __metadata: languageName: unknown linkType: soft -"@orval/fetch@npm:7.0.1, @orval/fetch@workspace:packages/fetch": +"@orval/fetch@npm:7.1.0, @orval/fetch@workspace:packages/fetch": version: 0.0.0-use.local resolution: "@orval/fetch@workspace:packages/fetch" dependencies: - "@orval/core": "npm:7.0.1" + "@orval/core": "npm:7.1.0" languageName: unknown linkType: soft -"@orval/hono@npm:7.0.1, @orval/hono@workspace:packages/hono": +"@orval/hono@npm:7.1.0, @orval/hono@workspace:packages/hono": version: 0.0.0-use.local resolution: "@orval/hono@workspace:packages/hono" dependencies: - "@orval/core": "npm:7.0.1" - "@orval/zod": "npm:7.0.1" + "@orval/core": "npm:7.1.0" + "@orval/zod": "npm:7.1.0" "@types/lodash.uniq": "npm:^4.5.7" lodash.uniq: "npm:^4.5.0" languageName: unknown linkType: soft -"@orval/mock@npm:7.0.1, @orval/mock@workspace:packages/mock": +"@orval/mock@npm:7.1.0, @orval/mock@workspace:packages/mock": version: 0.0.0-use.local resolution: "@orval/mock@workspace:packages/mock" dependencies: - "@orval/core": "npm:7.0.1" + "@orval/core": "npm:7.1.0" lodash.get: "npm:^4.4.2" lodash.omit: "npm:^4.5.0" openapi3-ts: "npm:^4.2.2" languageName: unknown linkType: soft -"@orval/query@npm:7.0.1, @orval/query@workspace:packages/query": +"@orval/query@npm:7.1.0, @orval/query@workspace:packages/query": version: 0.0.0-use.local resolution: "@orval/query@workspace:packages/query" dependencies: - "@orval/core": "npm:7.0.1" - "@orval/fetch": "npm:7.0.1" + "@orval/core": "npm:7.1.0" + "@orval/fetch": "npm:7.1.0" "@types/lodash.omitby": "npm:^4.6.7" lodash.omitby: "npm:^4.6.0" vitest: "npm:^0.34.6" languageName: unknown linkType: soft -"@orval/swr@npm:7.0.1, @orval/swr@workspace:packages/swr": +"@orval/swr@npm:7.1.0, @orval/swr@workspace:packages/swr": version: 0.0.0-use.local resolution: "@orval/swr@workspace:packages/swr" dependencies: - "@orval/core": "npm:7.0.1" - "@orval/fetch": "npm:7.0.1" + "@orval/core": "npm:7.1.0" + "@orval/fetch": "npm:7.1.0" languageName: unknown linkType: soft -"@orval/zod@npm:7.0.1, @orval/zod@workspace:packages/zod": +"@orval/zod@npm:7.1.0, @orval/zod@workspace:packages/zod": version: 0.0.0-use.local resolution: "@orval/zod@workspace:packages/zod" dependencies: - "@orval/core": "npm:7.0.1" + "@orval/core": "npm:7.1.0" "@types/lodash.uniq": "npm:^4.5.7" lodash.uniq: "npm:^4.5.0" languageName: unknown @@ -7177,15 +7177,15 @@ __metadata: resolution: "orval@workspace:packages/orval" dependencies: "@apidevtools/swagger-parser": "npm:^10.1.0" - "@orval/angular": "npm:7.0.1" - "@orval/axios": "npm:7.0.1" - "@orval/core": "npm:7.0.1" - "@orval/fetch": "npm:7.0.1" - "@orval/hono": "npm:7.0.1" - "@orval/mock": "npm:7.0.1" - "@orval/query": "npm:7.0.1" - "@orval/swr": "npm:7.0.1" - "@orval/zod": "npm:7.0.1" + "@orval/angular": "npm:7.1.0" + "@orval/axios": "npm:7.1.0" + "@orval/core": "npm:7.1.0" + "@orval/fetch": "npm:7.1.0" + "@orval/hono": "npm:7.1.0" + "@orval/mock": "npm:7.1.0" + "@orval/query": "npm:7.1.0" + "@orval/swr": "npm:7.1.0" + "@orval/zod": "npm:7.1.0" "@types/inquirer": "npm:^9.0.6" "@types/js-yaml": "npm:^4.0.8" "@types/lodash.uniq": "npm:^4.5.8"