Skip to content

Commit 7d3a1a3

Browse files
Newbie012autofix-ci[bot]TkDodo
authored
fix(eslint-plugin): separate legacy and modern dts files (TanStack#8972)
* chore(build): restructure eslint-plugin-query build configuration Aligned the build system with other packages by replacing the custom tsup config with standard modern/legacy build outputs. Moved output files from 'dist' to 'build' directory structure. Removed the patch-missing-export-equals.js script in favor of directly exporting the plugin. Added tsconfig.prod.json for production builds. * chore(example): eslint classic * ci: apply automated fixes * fix: unique name for examples * remove unused import * chore: add eslint test script to react examples and update eslint test command Add `test:eslint` script to react example package.json files to enable linting checks. Update the main `test:eslint` command to remove the exclusion of examples, ensuring linting is applied across the entire project. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: TkDodo <office@dorfmeister.cc>
1 parent 0964fba commit 7d3a1a3

19 files changed

+561
-106
lines changed

examples/react/basic/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"dev": "vite",
77
"build": "vite build",
8-
"preview": "vite preview"
8+
"preview": "vite preview",
9+
"test:eslint": "eslint ./src"
910
},
1011
"dependencies": {
1112
"@tanstack/query-sync-storage-persister": "^5.72.1",
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["plugin:@tanstack/query/recommended"]
3+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
pnpm-lock.yaml
15+
yarn.lock
16+
package-lock.json
17+
18+
# misc
19+
.DS_Store
20+
.env.local
21+
.env.development.local
22+
.env.test.local
23+
.env.production.local
24+
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example
2+
3+
To run this example:
4+
5+
- `npm install`
6+
- `npm run dev`
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" type="image/svg+xml" href="/emblem-light.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
9+
<title>TanStack Query React Basic Example App</title>
10+
</head>
11+
<body>
12+
<noscript>You need to enable JavaScript to run this app.</noscript>
13+
<div id="root"></div>
14+
<script type="module" src="/src/index.tsx"></script>
15+
</body>
16+
</html>
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@tanstack/query-example-eslint-legacy",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build",
8+
"preview": "vite preview",
9+
"test:eslint": "eslint ./src"
10+
},
11+
"dependencies": {
12+
"@tanstack/query-sync-storage-persister": "^5.72.0",
13+
"@tanstack/react-query": "^5.72.0",
14+
"@tanstack/react-query-devtools": "^5.72.0",
15+
"@tanstack/react-query-persist-client": "^5.72.0",
16+
"react": "^19.0.0",
17+
"react-dom": "^19.0.0"
18+
},
19+
"devDependencies": {
20+
"@tanstack/eslint-plugin-query": "^5.72.0",
21+
"eslint": "^8.16.0",
22+
"@types/react": "^18.2.79",
23+
"@types/react-dom": "^18.2.25",
24+
"@vitejs/plugin-react": "^4.3.4",
25+
"typescript": "5.8.2",
26+
"vite": "^6.2.4"
27+
}
28+
}
Loading
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import * as React from 'react'
2+
import ReactDOM from 'react-dom/client'
3+
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'
4+
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
5+
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'
6+
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
7+
8+
const queryClient = new QueryClient({
9+
defaultOptions: {
10+
queries: {
11+
gcTime: 1000 * 60 * 60 * 24, // 24 hours
12+
},
13+
},
14+
})
15+
16+
const persister = createSyncStoragePersister({
17+
storage: window.localStorage,
18+
})
19+
20+
type Post = {
21+
id: number
22+
title: string
23+
body: string
24+
}
25+
26+
function usePosts() {
27+
return useQuery({
28+
queryKey: ['posts'],
29+
queryFn: async (): Promise<Array<Post>> => {
30+
const response = await fetch('https://jsonplaceholder.typicode.com/posts')
31+
return await response.json()
32+
},
33+
})
34+
}
35+
36+
function Posts({
37+
setPostId,
38+
}: {
39+
setPostId: React.Dispatch<React.SetStateAction<number>>
40+
}) {
41+
const queryClient = useQueryClient()
42+
const { status, data, error, isFetching } = usePosts()
43+
44+
return (
45+
<div>
46+
<h1>Posts</h1>
47+
<div>
48+
{status === 'pending' ? (
49+
'Loading...'
50+
) : status === 'error' ? (
51+
<span>Error: {error.message}</span>
52+
) : (
53+
<>
54+
<div>
55+
{data.map((post) => (
56+
<p key={post.id}>
57+
<a
58+
onClick={() => setPostId(post.id)}
59+
href="#"
60+
style={
61+
// We can access the query data here to show bold links for
62+
// ones that are cached
63+
queryClient.getQueryData(['post', post.id])
64+
? {
65+
fontWeight: 'bold',
66+
color: 'green',
67+
}
68+
: {}
69+
}
70+
>
71+
{post.title}
72+
</a>
73+
</p>
74+
))}
75+
</div>
76+
<div>{isFetching ? 'Background Updating...' : ' '}</div>
77+
</>
78+
)}
79+
</div>
80+
</div>
81+
)
82+
}
83+
84+
const getPostById = async (id: number): Promise<Post> => {
85+
const response = await fetch(
86+
`https://jsonplaceholder.typicode.com/posts/${id}`,
87+
)
88+
return await response.json()
89+
}
90+
91+
function usePost(postId: number) {
92+
return useQuery({
93+
queryKey: ['post', postId],
94+
queryFn: () => getPostById(postId),
95+
enabled: !!postId,
96+
})
97+
}
98+
99+
function Post({
100+
postId,
101+
setPostId,
102+
}: {
103+
postId: number
104+
setPostId: React.Dispatch<React.SetStateAction<number>>
105+
}) {
106+
const { status, data, error, isFetching } = usePost(postId)
107+
108+
return (
109+
<div>
110+
<div>
111+
<a onClick={() => setPostId(-1)} href="#">
112+
Back
113+
</a>
114+
</div>
115+
{!postId || status === 'pending' ? (
116+
'Loading...'
117+
) : status === 'error' ? (
118+
<span>Error: {error.message}</span>
119+
) : (
120+
<>
121+
<h1>{data.title}</h1>
122+
<div>
123+
<p>{data.body}</p>
124+
</div>
125+
<div>{isFetching ? 'Background Updating...' : ' '}</div>
126+
</>
127+
)}
128+
</div>
129+
)
130+
}
131+
132+
function App() {
133+
const [postId, setPostId] = React.useState(-1)
134+
135+
return (
136+
<PersistQueryClientProvider
137+
client={queryClient}
138+
persistOptions={{ persister }}
139+
>
140+
<p>
141+
As you visit the posts below, you will notice them in a loading state
142+
the first time you load them. However, after you return to this list and
143+
click on any posts you have already visited again, you will see them
144+
load instantly and background refresh right before your eyes!{' '}
145+
<strong>
146+
(You may need to throttle your network speed to simulate longer
147+
loading sequences)
148+
</strong>
149+
</p>
150+
{postId > -1 ? (
151+
<Post postId={postId} setPostId={setPostId} />
152+
) : (
153+
<Posts setPostId={setPostId} />
154+
)}
155+
<ReactQueryDevtools initialIsOpen />
156+
</PersistQueryClientProvider>
157+
)
158+
}
159+
160+
const rootElement = document.getElementById('root') as HTMLElement
161+
ReactDOM.createRoot(rootElement).render(<App />)
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"useDefineForClassFields": true,
5+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
6+
"module": "ESNext",
7+
"skipLibCheck": true,
8+
9+
/* Bundler mode */
10+
"moduleResolution": "Bundler",
11+
"allowImportingTsExtensions": true,
12+
"resolveJsonModule": true,
13+
"isolatedModules": true,
14+
"noEmit": true,
15+
"jsx": "react-jsx",
16+
17+
/* Linting */
18+
"strict": true,
19+
"noUnusedLocals": true,
20+
"noUnusedParameters": true,
21+
"noFallthroughCasesInSwitch": true
22+
},
23+
"include": ["src", "eslint.config.js"]
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineConfig } from 'vite'
2+
import react from '@vitejs/plugin-react'
3+
4+
export default defineConfig({
5+
plugins: [react()],
6+
})

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test": "pnpm run test:ci",
1414
"test:pr": "nx affected --targets=test:sherif,test:knip,test:eslint,test:lib,test:types,test:build,build",
1515
"test:ci": "nx run-many --targets=test:sherif,test:knip,test:eslint,test:lib,test:types,test:build,build",
16-
"test:eslint": "nx affected --target=test:eslint --exclude=examples/**",
16+
"test:eslint": "nx affected --target=test:eslint",
1717
"test:format": "pnpm run prettier --check",
1818
"test:sherif": "sherif -i typescript -p \"./integrations/*\" -p \"./examples/*\"",
1919
"test:lib": "nx affected --target=test:lib --exclude=examples/**",
@@ -100,8 +100,7 @@
100100
"@tanstack/vue-query": "workspace:*",
101101
"@tanstack/vue-query-devtools": "workspace:*",
102102
"@types/react": "^19.0.1",
103-
"@types/react-dom": "^19.0.2",
104-
"eslint": "$eslint"
103+
"@types/react-dom": "^19.0.2"
105104
}
106105
}
107106
}

packages/eslint-plugin-query/package.json

+12-9
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,32 @@
3131
"test:lib": "vitest",
3232
"test:lib:dev": "pnpm run test:lib --watch",
3333
"test:build": "publint --strict && attw --pack",
34-
"build": "tsup && node ./scripts/patch-missing-export-equals.js"
34+
"build": "tsup --tsconfig tsconfig.prod.json"
3535
},
3636
"type": "module",
37-
"types": "dist/index.d.ts",
38-
"main": "dist/index.cjs",
39-
"module": "dist/index.js",
37+
"types": "build/legacy/index.d.ts",
38+
"main": "build/legacy/index.cjs",
39+
"module": "build/legacy/index.js",
40+
"react-native": "src/index.ts",
4041
"exports": {
4142
".": {
4243
"import": {
4344
"@tanstack/custom-condition": "./src/index.ts",
44-
"types": "./dist/index.d.ts",
45-
"default": "./dist/index.js"
45+
"types": "./build/modern/index.d.ts",
46+
"default": "./build/modern/index.js"
4647
},
4748
"require": {
48-
"types": "./dist/index.d.cts",
49-
"default": "./dist/index.cjs"
49+
"types": "./build/modern/index.d.cts",
50+
"default": "./build/modern/index.cjs"
5051
}
5152
},
5253
"./package.json": "./package.json"
5354
},
5455
"sideEffects": false,
5556
"files": [
56-
"dist"
57+
"build",
58+
"src",
59+
"!src/__tests__"
5760
],
5861
"dependencies": {
5962
"@typescript-eslint/utils": "^8.18.1"

0 commit comments

Comments
 (0)