Skip to content

Commit

Permalink
fix(query): check for peer dependencies (#1560)
Browse files Browse the repository at this point in the history
* fix(query): check for peer dependecies

Fix #1559

* Update types.ts

* Update index.ts
  • Loading branch information
melloware authored Aug 3, 2024
1 parent ccc4ff9 commit e67d4b0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ export type TsConfigTarget =
export interface PackageJson {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
}

export type GeneratorSchema = {
Expand Down
67 changes: 38 additions & 29 deletions packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,52 @@ import {
ClientBuilder,
ClientDependenciesBuilder,
ClientHeaderBuilder,
compareVersions,
generateMutator,
generateVerbImports,
GeneratorDependency,
GeneratorMutator,
GeneratorOptions,
GeneratorVerbOptions,
getRouteAsArray,
GetterParams,
GetterProp,
GetterProps,
GetterPropType,
GetterQueryParam,
GetterResponse,
isObject,
jsDoc,
mergeDeep,
NormalizedOutputOptions,
OutputClient,
OutputClientFunc,
OutputHttpClient,
PackageJson,
pascal,
QueryOptions,
stringify,
toObjectString,
Verbs,
jsDoc,
GetterQueryParam,
compareVersions,
getRouteAsArray,
NormalizedOutputOptions,
OutputHttpClient,
} from '@orval/core';
import omitBy from 'lodash.omitby';
import {
normalizeQueryOptions,
isVue,
vueWrapTypeWithMaybeRef,
vueUnRefParams,
} from './utils';
import {
AXIOS_DEPENDENCIES,
getQueryArgumentsRequestType,
getQueryOptions,
generateQueryRequestFunction,
getHookOptions,
getQueryErrorType,
getHooksOptionImplementation,
getMutationRequestArgs,
generateQueryRequestFunction,
getHttpFunctionQueryProps,
getMutationRequestArgs,
getQueryArgumentsRequestType,
getQueryErrorType,
getQueryOptions,
} from './client';
import {
isVue,
normalizeQueryOptions,
vueUnRefParams,
vueWrapTypeWithMaybeRef,
} from './utils';

const REACT_DEPENDENCIES: GeneratorDependency[] = [
{
Expand Down Expand Up @@ -121,14 +121,16 @@ const SVELTE_QUERY_DEPENDENCIES: GeneratorDependency[] = [
];

const isSvelteQueryV3 = (packageJson: PackageJson | undefined) => {
const hasVueQuery =
const hasSvelteQuery =
packageJson?.dependencies?.['@sveltestack/svelte-query'] ??
packageJson?.devDependencies?.['@sveltestack/svelte-query'];
const hasVueQueryV4 =
packageJson?.devDependencies?.['@sveltestack/svelte-query'] ??
packageJson?.peerDependencies?.['@sveltestack/svelte-query'];
const hasSvelteQueryV4 =
packageJson?.dependencies?.['@tanstack/svelte-query'] ??
packageJson?.devDependencies?.['@tanstack/svelte-query'];
packageJson?.devDependencies?.['@tanstack/svelte-query'] ??
packageJson?.peerDependencies?.['@tanstack/svelte-query'];

return !!hasVueQuery && !hasVueQueryV4;
return !!hasSvelteQuery && !hasSvelteQueryV4;
};

export const getSvelteQueryDependencies: ClientDependenciesBuilder = (
Expand Down Expand Up @@ -210,10 +212,12 @@ export const getReactQueryDependencies: ClientDependenciesBuilder = (
) => {
const hasReactQuery =
packageJson?.dependencies?.['react-query'] ??
packageJson?.devDependencies?.['react-query'];
packageJson?.devDependencies?.['react-query'] ??
packageJson?.peerDependencies?.['react-query'];
const hasReactQueryV4 =
packageJson?.dependencies?.['@tanstack/react-query'] ??
packageJson?.devDependencies?.['@tanstack/react-query'];
packageJson?.devDependencies?.['@tanstack/react-query'] ??
packageJson?.peerDependencies?.['@tanstack/react-query'];

return [
...(hasGlobalMutator ? REACT_DEPENDENCIES : []),
Expand Down Expand Up @@ -295,10 +299,12 @@ const VUE_QUERY_DEPENDENCIES: GeneratorDependency[] = [
const isVueQueryV3 = (packageJson: PackageJson | undefined) => {
const hasVueQuery =
packageJson?.dependencies?.['vue-query'] ??
packageJson?.devDependencies?.['vue-query'];
packageJson?.devDependencies?.['vue-query'] ??
packageJson?.peerDependencies?.['vue-query'];
const hasVueQueryV4 =
packageJson?.dependencies?.['@tanstack/vue-query'] ??
packageJson?.devDependencies?.['@tanstack/vue-query'];
packageJson?.devDependencies?.['@tanstack/vue-query'] ??
packageJson?.peerDependencies?.['@tanstack/vue-query'];

return !!hasVueQuery && !hasVueQueryV4;
};
Expand Down Expand Up @@ -343,19 +349,22 @@ const getPackageByQueryClient = (
case 'react-query': {
return (
packageJson?.dependencies?.['@tanstack/react-query'] ??
packageJson?.devDependencies?.['@tanstack/react-query']
packageJson?.devDependencies?.['@tanstack/react-query'] ??
packageJson?.peerDependencies?.['@tanstack/react-query']
);
}
case 'svelte-query': {
return (
packageJson?.dependencies?.['@tanstack/svelte-query'] ??
packageJson?.devDependencies?.['@tanstack/svelte-query']
packageJson?.devDependencies?.['@tanstack/svelte-query'] ??
packageJson?.peerDependencies?.['@tanstack/svelte-query']
);
}
case 'vue-query': {
return (
packageJson?.dependencies?.['@tanstack/vue-query'] ??
packageJson?.devDependencies?.['@tanstack/vue-query']
packageJson?.devDependencies?.['@tanstack/vue-query'] ??
packageJson?.peerDependencies?.['@tanstack/vue-query']
);
}
}
Expand Down

0 comments on commit e67d4b0

Please sign in to comment.