Skip to content

Commit

Permalink
fix(react-query): easier to know constraint @tanstack/react-query v4 …
Browse files Browse the repository at this point in the history
…runtimely (#893)

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

We expect version of @tanstack/react-query's as only v4. so we warn it
with this change to promote installing correct version

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md)
2. I added documents and tests.
  • Loading branch information
manudeli committed May 25, 2024
1 parent 988e73b commit 39b4f1b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-bees-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@suspensive/react-query": patch
---

fix(react-query): easier to know constraint @tanstack/react-query v4 runtimely
11 changes: 11 additions & 0 deletions packages/react-query/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import TanStackReactQuery from '@tanstack/react-query/package.json'
import { isVersion } from './utils'

if (process.env.NODE_ENV === 'development') {
if (!isVersion(4).of(TanStackReactQuery.version)) {
console.warn(
`@suspensive/react-query: We support only @tanstack/react-query v4. but you installed @tanstack/react-query@${TanStackReactQuery.version}. Please install @tanstack/react-query v4 correctly`
)
}
}

export { queryOptions } from './queryOptions'
export { SuspenseQuery } from './SuspenseQuery'
export { SuspenseInfiniteQuery } from './SuspenseInfiniteQuery'
Expand Down
1 change: 1 addition & 0 deletions packages/react-query/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { isVersion } from './isVersion'
17 changes: 17 additions & 0 deletions packages/react-query/src/utils/isVersion.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { isVersion } from './isVersion'

describe('isVersion', () => {
it('should check the version correctly', () => {
expect(isVersion(4).of('4.32.1')).toBe(true)
expect(isVersion(4).of('5.32.1')).toBe(false)
expect(isVersion(4).of('3.32.1')).toBe(false)

expect(isVersion(4).of('4.32.1-beta.32')).toBe(true)
expect(isVersion(4).of('5.32.1-beta.32')).toBe(false)
expect(isVersion(4).of('3.32.1-beta.32')).toBe(false)

expect(isVersion(4).of('4')).toBe(true)
expect(isVersion(4).of('5')).toBe(false)
expect(isVersion(4).of('3')).toBe(false)
})
})
6 changes: 6 additions & 0 deletions packages/react-query/src/utils/isVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const isVersion = (version: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7) => ({
of: (packageVersion: string) => {
const [major] = packageVersion.split('.').map(Number)
return major === version
},
})

0 comments on commit 39b4f1b

Please sign in to comment.