@tanstack/devtools-vite 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/enhance-logs.d.ts +1 -3
- package/dist/esm/enhance-logs.js +2 -2
- package/dist/esm/enhance-logs.js.map +1 -1
- package/dist/esm/inject-source.d.ts +1 -3
- package/dist/esm/inject-source.js +2 -2
- package/dist/esm/inject-source.js.map +1 -1
- package/dist/esm/plugin.d.ts +6 -1
- package/dist/esm/plugin.js +17 -8
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/remove-devtools.d.ts +1 -3
- package/dist/esm/remove-devtools.js +2 -2
- package/dist/esm/remove-devtools.js.map +1 -1
- package/package.json +1 -1
- package/src/enhance-logs.test.ts +32 -72
- package/src/enhance-logs.ts +2 -2
- package/src/inject-source.test.ts +108 -268
- package/src/inject-source.ts +2 -2
- package/src/plugin.ts +23 -10
- package/src/remove-devtools.test.ts +10 -10
- package/src/remove-devtools.ts +2 -2
package/src/inject-source.ts
CHANGED
|
@@ -228,7 +228,7 @@ export function addSourceToJsx(code: string, id: string) {
|
|
|
228
228
|
})
|
|
229
229
|
const didTransform = transform(ast, location)
|
|
230
230
|
if (!didTransform) {
|
|
231
|
-
return
|
|
231
|
+
return
|
|
232
232
|
}
|
|
233
233
|
return gen(ast, {
|
|
234
234
|
sourceMaps: true,
|
|
@@ -237,6 +237,6 @@ export function addSourceToJsx(code: string, id: string) {
|
|
|
237
237
|
sourceFileName: filePath,
|
|
238
238
|
})
|
|
239
239
|
} catch (e) {
|
|
240
|
-
return
|
|
240
|
+
return
|
|
241
241
|
}
|
|
242
242
|
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ServerEventBus } from '@tanstack/devtools-event-bus/server'
|
|
2
|
+
import { normalizePath } from 'vite'
|
|
3
|
+
import chalk from 'chalk'
|
|
2
4
|
import { handleDevToolsViteRequest } from './utils'
|
|
3
5
|
import { DEFAULT_EDITOR_CONFIG, handleOpenSource } from './editor'
|
|
4
6
|
import { removeDevtools } from './remove-devtools'
|
|
5
7
|
import { addSourceToJsx } from './inject-source'
|
|
6
8
|
import { enhanceConsoleLog } from './enhance-logs'
|
|
9
|
+
import type { Plugin } from 'vite'
|
|
7
10
|
import type { EditorConfig } from './editor'
|
|
8
11
|
import type { ServerEventBusConfig } from '@tanstack/devtools-event-bus/server'
|
|
9
|
-
import type { Plugin } from 'vite'
|
|
10
12
|
|
|
11
13
|
export type TanStackDevtoolsViteConfig = {
|
|
12
14
|
/**
|
|
@@ -32,6 +34,12 @@ export type TanStackDevtoolsViteConfig = {
|
|
|
32
34
|
* @default true
|
|
33
35
|
*/
|
|
34
36
|
removeDevtoolsOnBuild?: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Whether to log information to the console.
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
logging?: boolean
|
|
35
43
|
/**
|
|
36
44
|
* Configuration for source injection.
|
|
37
45
|
*/
|
|
@@ -49,6 +57,7 @@ export const defineDevtoolsConfig = (config: TanStackDevtoolsViteConfig) =>
|
|
|
49
57
|
|
|
50
58
|
export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
51
59
|
let port = 5173
|
|
60
|
+
const logging = args?.logging ?? true
|
|
52
61
|
const enhancedLogsConfig = args?.enhancedLogs ?? { enabled: true }
|
|
53
62
|
const injectSourceConfig = args?.injectSource ?? { enabled: true }
|
|
54
63
|
const removeDevtoolsOnBuild = args?.removeDevtoolsOnBuild ?? true
|
|
@@ -68,7 +77,7 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
|
68
77
|
id.includes('dist') ||
|
|
69
78
|
id.includes('build')
|
|
70
79
|
)
|
|
71
|
-
return
|
|
80
|
+
return
|
|
72
81
|
|
|
73
82
|
return addSourceToJsx(code, id)
|
|
74
83
|
},
|
|
@@ -135,9 +144,15 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
|
135
144
|
id.includes('dist') ||
|
|
136
145
|
id.includes('build')
|
|
137
146
|
)
|
|
138
|
-
return
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
return
|
|
148
|
+
const transform = removeDevtools(code, id)
|
|
149
|
+
if (!transform) return
|
|
150
|
+
if (logging) {
|
|
151
|
+
console.log(
|
|
152
|
+
`\n${chalk.greenBright(`[@tanstack/devtools-vite]`)} Removed devtools code from: ${id.replace(normalizePath(process.cwd()), '')}\n`,
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
return transform
|
|
141
156
|
},
|
|
142
157
|
},
|
|
143
158
|
{
|
|
@@ -152,13 +167,11 @@ export const devtools = (args?: TanStackDevtoolsViteConfig): Array<Plugin> => {
|
|
|
152
167
|
id.includes('node_modules') ||
|
|
153
168
|
id.includes('?raw') ||
|
|
154
169
|
id.includes('dist') ||
|
|
155
|
-
id.includes('build')
|
|
170
|
+
id.includes('build') ||
|
|
171
|
+
!code.includes('console.')
|
|
156
172
|
)
|
|
157
|
-
return
|
|
173
|
+
return
|
|
158
174
|
|
|
159
|
-
if (!code.includes('console.')) {
|
|
160
|
-
return code
|
|
161
|
-
}
|
|
162
175
|
return enhanceConsoleLog(code, id, port)
|
|
163
176
|
},
|
|
164
177
|
},
|
|
@@ -53,7 +53,7 @@ export default function DevtoolsExample() {
|
|
|
53
53
|
|
|
54
54
|
`,
|
|
55
55
|
'test.jsx',
|
|
56
|
-
)
|
|
56
|
+
)!.code,
|
|
57
57
|
)
|
|
58
58
|
expect(output).toBe(
|
|
59
59
|
removeEmptySpace(`
|
|
@@ -125,7 +125,7 @@ export default function DevtoolsExample() {
|
|
|
125
125
|
|
|
126
126
|
`,
|
|
127
127
|
'test.jsx',
|
|
128
|
-
)
|
|
128
|
+
)!.code,
|
|
129
129
|
)
|
|
130
130
|
expect(output).toBe(
|
|
131
131
|
removeEmptySpace(`
|
|
@@ -197,7 +197,7 @@ export default function DevtoolsExample() {
|
|
|
197
197
|
|
|
198
198
|
`,
|
|
199
199
|
'test.jsx',
|
|
200
|
-
)
|
|
200
|
+
)!.code,
|
|
201
201
|
)
|
|
202
202
|
expect(output).toBe(
|
|
203
203
|
removeEmptySpace(`
|
|
@@ -268,7 +268,7 @@ export default function DevtoolsExample() {
|
|
|
268
268
|
)
|
|
269
269
|
}`,
|
|
270
270
|
'test.jsx',
|
|
271
|
-
)
|
|
271
|
+
)!.code,
|
|
272
272
|
)
|
|
273
273
|
|
|
274
274
|
expect(output).toBe(
|
|
@@ -325,7 +325,7 @@ export default function DevtoolsExample() {
|
|
|
325
325
|
)
|
|
326
326
|
}`,
|
|
327
327
|
'test.jsx',
|
|
328
|
-
)
|
|
328
|
+
)!.code,
|
|
329
329
|
)
|
|
330
330
|
|
|
331
331
|
expect(output).toBe(
|
|
@@ -372,7 +372,7 @@ export default function DevtoolsExample() {
|
|
|
372
372
|
)
|
|
373
373
|
}`,
|
|
374
374
|
'test.jsx',
|
|
375
|
-
)
|
|
375
|
+
)!.code,
|
|
376
376
|
)
|
|
377
377
|
|
|
378
378
|
expect(output).toBe(
|
|
@@ -416,7 +416,7 @@ export default function DevtoolsExample() {
|
|
|
416
416
|
)
|
|
417
417
|
}`,
|
|
418
418
|
'test.jsx',
|
|
419
|
-
)
|
|
419
|
+
)!.code,
|
|
420
420
|
)
|
|
421
421
|
|
|
422
422
|
expect(output).toBe(
|
|
@@ -458,7 +458,7 @@ export default function DevtoolsExample() {
|
|
|
458
458
|
)
|
|
459
459
|
}`,
|
|
460
460
|
'test.jsx',
|
|
461
|
-
)
|
|
461
|
+
)!.code,
|
|
462
462
|
)
|
|
463
463
|
|
|
464
464
|
expect(output).toBe(
|
|
@@ -500,7 +500,7 @@ export default function DevtoolsExample() {
|
|
|
500
500
|
)
|
|
501
501
|
}`,
|
|
502
502
|
'test.jsx',
|
|
503
|
-
)
|
|
503
|
+
)!.code,
|
|
504
504
|
)
|
|
505
505
|
|
|
506
506
|
expect(output).toBe(
|
|
@@ -542,7 +542,7 @@ export default function DevtoolsExample() {
|
|
|
542
542
|
)
|
|
543
543
|
}`,
|
|
544
544
|
'test.jsx',
|
|
545
|
-
)
|
|
545
|
+
)!.code,
|
|
546
546
|
)
|
|
547
547
|
|
|
548
548
|
expect(output).toBe(
|
package/src/remove-devtools.ts
CHANGED
|
@@ -180,7 +180,7 @@ export function removeDevtools(code: string, id: string) {
|
|
|
180
180
|
})
|
|
181
181
|
const didTransform = transform(ast)
|
|
182
182
|
if (!didTransform) {
|
|
183
|
-
return
|
|
183
|
+
return
|
|
184
184
|
}
|
|
185
185
|
return gen(ast, {
|
|
186
186
|
sourceMaps: true,
|
|
@@ -189,6 +189,6 @@ export function removeDevtools(code: string, id: string) {
|
|
|
189
189
|
sourceFileName: filePath,
|
|
190
190
|
})
|
|
191
191
|
} catch (e) {
|
|
192
|
-
return
|
|
192
|
+
return
|
|
193
193
|
}
|
|
194
194
|
}
|