@tanstack/devtools-vite 0.8.1 → 0.8.2
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/plugin.d.ts +4 -74
- package/dist/esm/plugin.js +2 -12
- package/dist/esm/plugin.js.map +1 -1
- package/package.json +2 -6
- package/src/plugin.ts +25 -97
- package/dist/esm/ast-utils.d.ts +0 -11
- package/dist/esm/ast-utils.js +0 -44
- package/dist/esm/ast-utils.js.map +0 -1
- package/dist/esm/ast-utils.test.d.ts +0 -1
- package/dist/esm/devtools-packages.d.ts +0 -2
- package/dist/esm/devtools-packages.js +0 -15
- package/dist/esm/devtools-packages.js.map +0 -1
- package/dist/esm/devtools-packages.test.d.ts +0 -1
- package/dist/esm/editor.d.ts +0 -25
- package/dist/esm/editor.js +0 -20
- package/dist/esm/editor.js.map +0 -1
- package/dist/esm/editor.test.d.ts +0 -1
- package/dist/esm/enhance-logs.d.ts +0 -4
- package/dist/esm/enhance-logs.js +0 -51
- package/dist/esm/enhance-logs.js.map +0 -1
- package/dist/esm/enhance-logs.test.d.ts +0 -1
- package/dist/esm/inject-plugin.d.ts +0 -22
- package/dist/esm/inject-plugin.js +0 -179
- package/dist/esm/inject-plugin.js.map +0 -1
- package/dist/esm/inject-plugin.test.d.ts +0 -1
- package/dist/esm/inject-source.d.ts +0 -7
- package/dist/esm/inject-source.js +0 -114
- package/dist/esm/inject-source.js.map +0 -1
- package/dist/esm/inject-source.test.d.ts +0 -1
- package/dist/esm/matcher.d.ts +0 -1
- package/dist/esm/matcher.js +0 -13
- package/dist/esm/matcher.js.map +0 -1
- package/dist/esm/matcher.test.d.ts +0 -1
- package/dist/esm/offset-to-loc.d.ts +0 -14
- package/dist/esm/offset-to-loc.js +0 -29
- package/dist/esm/offset-to-loc.js.map +0 -1
- package/dist/esm/offset-to-loc.test.d.ts +0 -1
- package/dist/esm/package-manager.d.ts +0 -16
- package/dist/esm/package-manager.js +0 -98
- package/dist/esm/package-manager.js.map +0 -1
- package/dist/esm/remove-devtools.d.ts +0 -4
- package/dist/esm/remove-devtools.js +0 -96
- package/dist/esm/remove-devtools.js.map +0 -1
- package/dist/esm/remove-devtools.test.d.ts +0 -1
- package/dist/esm/runtime-bridge.d.ts +0 -31
- package/dist/esm/runtime-bridge.js +0 -75
- package/dist/esm/runtime-bridge.js.map +0 -1
- package/dist/esm/runtime-bridge.test.d.ts +0 -1
- package/dist/esm/utils.d.ts +0 -31
- package/dist/esm/utils.js +0 -155
- package/dist/esm/utils.js.map +0 -1
- package/dist/esm/utils.test.d.ts +0 -1
- package/dist/esm/virtual-console.d.ts +0 -19
- package/dist/esm/virtual-console.js +0 -336
- package/dist/esm/virtual-console.js.map +0 -1
- package/dist/esm/virtual-console.test.d.ts +0 -1
- package/src/ast-utils.test.ts +0 -109
- package/src/ast-utils.ts +0 -58
- package/src/devtools-packages.test.ts +0 -58
- package/src/devtools-packages.ts +0 -12
- package/src/editor.test.ts +0 -75
- package/src/editor.ts +0 -53
- package/src/enhance-logs.test.ts +0 -132
- package/src/enhance-logs.ts +0 -71
- package/src/inject-plugin.test.ts +0 -1139
- package/src/inject-plugin.ts +0 -300
- package/src/inject-source.test.ts +0 -939
- package/src/inject-source.ts +0 -235
- package/src/matcher.test.ts +0 -33
- package/src/matcher.ts +0 -19
- package/src/offset-to-loc.test.ts +0 -34
- package/src/offset-to-loc.ts +0 -39
- package/src/package-manager.ts +0 -181
- package/src/remove-devtools.test.ts +0 -607
- package/src/remove-devtools.ts +0 -190
- package/src/runtime-bridge.test.ts +0 -179
- package/src/runtime-bridge.ts +0 -113
- package/src/utils.test.ts +0 -184
- package/src/utils.ts +0 -247
- package/src/virtual-console.test.ts +0 -244
- package/src/virtual-console.ts +0 -341
package/src/editor.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
type OpenSourceData = {
|
|
2
|
-
type: 'open-source'
|
|
3
|
-
data: {
|
|
4
|
-
/** The source file to open */
|
|
5
|
-
source?: string
|
|
6
|
-
/** The react router route ID, usually discovered via the hook useMatches */
|
|
7
|
-
routeID?: string
|
|
8
|
-
/** The line number in the source file */
|
|
9
|
-
line?: number
|
|
10
|
-
/** The column number in the source file */
|
|
11
|
-
column?: number
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type EditorConfig = {
|
|
16
|
-
/** The name of the editor, used for debugging purposes */
|
|
17
|
-
name: string
|
|
18
|
-
/** Callback to open a file in the editor */
|
|
19
|
-
open: (
|
|
20
|
-
path: string,
|
|
21
|
-
lineNumber: string | undefined,
|
|
22
|
-
columnNumber?: string,
|
|
23
|
-
) => Promise<void>
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const DEFAULT_EDITOR_CONFIG: EditorConfig = {
|
|
27
|
-
name: 'VSCode',
|
|
28
|
-
open: async (path, lineNumber, columnNumber) => {
|
|
29
|
-
const launch = (await import('launch-editor')).default
|
|
30
|
-
launch(
|
|
31
|
-
`${path}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}`,
|
|
32
|
-
undefined,
|
|
33
|
-
(filename, err) => {
|
|
34
|
-
console.warn(`Failed to open ${filename} in editor: ${err}`)
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const handleOpenSource = async ({
|
|
41
|
-
data,
|
|
42
|
-
openInEditor,
|
|
43
|
-
}: {
|
|
44
|
-
data: OpenSourceData
|
|
45
|
-
openInEditor: EditorConfig['open']
|
|
46
|
-
}) => {
|
|
47
|
-
const { source, line, column } = data.data
|
|
48
|
-
const lineNum = line ? `${line}` : undefined
|
|
49
|
-
const columnNum = column ? `${column}` : undefined
|
|
50
|
-
if (source) {
|
|
51
|
-
return openInEditor(source, lineNum, columnNum)
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src/enhance-logs.test.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import { enhanceConsoleLog } from './enhance-logs'
|
|
3
|
-
|
|
4
|
-
const removeEmptySpace = (str: string) => {
|
|
5
|
-
return str.replace(/\s/g, '').trim()
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
describe('enhance-logs', () => {
|
|
9
|
-
test('it adds enhanced console.logs to console.log()', () => {
|
|
10
|
-
const output = removeEmptySpace(
|
|
11
|
-
enhanceConsoleLog(
|
|
12
|
-
`
|
|
13
|
-
console.log('This is a log')
|
|
14
|
-
`,
|
|
15
|
-
'test.jsx',
|
|
16
|
-
3000,
|
|
17
|
-
)!.code,
|
|
18
|
-
)
|
|
19
|
-
expect(
|
|
20
|
-
output.includes(
|
|
21
|
-
'http://localhost:3000/__tsd/open-source?source=test.jsx',
|
|
22
|
-
),
|
|
23
|
-
).toEqual(true)
|
|
24
|
-
expect(output.includes('test.jsx:2:9')).toEqual(true)
|
|
25
|
-
expect(output.includes(removeEmptySpace("'This is a log'"))).toEqual(true)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test('it does not add enhanced console.logs to console.log that is not called', () => {
|
|
29
|
-
const output = enhanceConsoleLog(
|
|
30
|
-
`
|
|
31
|
-
console.log
|
|
32
|
-
`,
|
|
33
|
-
'test.jsx',
|
|
34
|
-
3000,
|
|
35
|
-
)
|
|
36
|
-
expect(output).toBe(undefined)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('it does not add enhanced console.logs to console.log that is inside a comment', () => {
|
|
40
|
-
const output = enhanceConsoleLog(
|
|
41
|
-
`
|
|
42
|
-
// console.log('This is a log')
|
|
43
|
-
`,
|
|
44
|
-
'test.jsx',
|
|
45
|
-
3000,
|
|
46
|
-
)
|
|
47
|
-
expect(output).toBe(undefined)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('it does not add enhanced console.logs to console.log that is inside a multiline comment', () => {
|
|
51
|
-
const output = enhanceConsoleLog(
|
|
52
|
-
`
|
|
53
|
-
/*
|
|
54
|
-
console.log('This is a log')
|
|
55
|
-
*/
|
|
56
|
-
`,
|
|
57
|
-
'test.jsx',
|
|
58
|
-
3000,
|
|
59
|
-
)
|
|
60
|
-
expect(output).toBe(undefined)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test('it does not add enhanced console.error to console.error that is inside a comment', () => {
|
|
64
|
-
const output = enhanceConsoleLog(
|
|
65
|
-
`
|
|
66
|
-
// console.error('This is a log')
|
|
67
|
-
`,
|
|
68
|
-
'test.jsx',
|
|
69
|
-
3000,
|
|
70
|
-
)
|
|
71
|
-
expect(output).toBe(undefined)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
test('it does not add enhanced console.error to console.error that is inside a multiline comment', () => {
|
|
75
|
-
const output = enhanceConsoleLog(
|
|
76
|
-
`
|
|
77
|
-
/*
|
|
78
|
-
console.error('This is a log')
|
|
79
|
-
*/
|
|
80
|
-
`,
|
|
81
|
-
'test.jsx',
|
|
82
|
-
3000,
|
|
83
|
-
)
|
|
84
|
-
expect(output).toBe(undefined)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('it adds enhanced console.error to console.error()', () => {
|
|
88
|
-
const output = removeEmptySpace(
|
|
89
|
-
enhanceConsoleLog(
|
|
90
|
-
`
|
|
91
|
-
console.error('This is a log')
|
|
92
|
-
`,
|
|
93
|
-
'test.jsx',
|
|
94
|
-
3000,
|
|
95
|
-
)!.code,
|
|
96
|
-
)
|
|
97
|
-
expect(
|
|
98
|
-
output.includes(
|
|
99
|
-
'http://localhost:3000/__tsd/open-source?source=test.jsx',
|
|
100
|
-
),
|
|
101
|
-
).toEqual(true)
|
|
102
|
-
expect(output.includes('test.jsx:2:9')).toEqual(true)
|
|
103
|
-
expect(output.includes(removeEmptySpace("'This is a log'"))).toEqual(true)
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
test('it does not add enhanced console.error to console.error that is not called', () => {
|
|
107
|
-
const output = enhanceConsoleLog(
|
|
108
|
-
`
|
|
109
|
-
console.log
|
|
110
|
-
`,
|
|
111
|
-
'test.jsx',
|
|
112
|
-
3000,
|
|
113
|
-
)
|
|
114
|
-
expect(output).toBe(undefined)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
test('it adds enhanced console.log with css formatting to console.log()', () => {
|
|
118
|
-
const output = removeEmptySpace(
|
|
119
|
-
enhanceConsoleLog(
|
|
120
|
-
`
|
|
121
|
-
console.log('This is a log')
|
|
122
|
-
`,
|
|
123
|
-
'test.jsx',
|
|
124
|
-
3000,
|
|
125
|
-
)!.code,
|
|
126
|
-
)
|
|
127
|
-
expect(output.includes('color:#A0A')).toEqual(true)
|
|
128
|
-
expect(output.includes('color:#FFF')).toEqual(true)
|
|
129
|
-
expect(output.includes('color:#55F')).toEqual(true)
|
|
130
|
-
expect(output.includes('color:#FFF')).toEqual(true)
|
|
131
|
-
})
|
|
132
|
-
})
|
package/src/enhance-logs.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import { normalizePath } from 'vite'
|
|
3
|
-
import MagicString from 'magic-string'
|
|
4
|
-
import { parseSync } from 'oxc-parser'
|
|
5
|
-
import { createLocMapper } from './offset-to-loc'
|
|
6
|
-
import { walk } from './ast-utils'
|
|
7
|
-
|
|
8
|
-
function escapeForStringLiteral(str: string): string {
|
|
9
|
-
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function enhanceConsoleLog(code: string, id: string, port: number) {
|
|
13
|
-
const filePath = id.split('?')[0]!
|
|
14
|
-
const location = filePath.replace(normalizePath(process.cwd()), '')
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const result = parseSync(filePath, code, {
|
|
18
|
-
sourceType: 'module',
|
|
19
|
-
lang: 'tsx',
|
|
20
|
-
})
|
|
21
|
-
if (result.errors.length > 0) return
|
|
22
|
-
|
|
23
|
-
const offsetToLoc = createLocMapper(code)
|
|
24
|
-
const s = new MagicString(code)
|
|
25
|
-
|
|
26
|
-
walk(result.program, (node) => {
|
|
27
|
-
if (node.type !== 'CallExpression') return
|
|
28
|
-
|
|
29
|
-
const callee = node.callee
|
|
30
|
-
if (
|
|
31
|
-
callee.type === 'MemberExpression' &&
|
|
32
|
-
!callee.computed &&
|
|
33
|
-
callee.object.type === 'Identifier' &&
|
|
34
|
-
callee.object.name === 'console' &&
|
|
35
|
-
callee.property.type === 'Identifier' &&
|
|
36
|
-
(callee.property.name === 'log' || callee.property.name === 'error')
|
|
37
|
-
) {
|
|
38
|
-
const loc = offsetToLoc(node.start)
|
|
39
|
-
const [lineNumber, column] = [loc.line, loc.column]
|
|
40
|
-
const finalPath = `${location}:${lineNumber}:${column + 1}`
|
|
41
|
-
const logMessage = `${chalk.magenta('LOG')} ${chalk.blueBright(`${finalPath}`)}\n → `
|
|
42
|
-
|
|
43
|
-
const serverLogMessage = `["${escapeForStringLiteral(logMessage)}"]`
|
|
44
|
-
const browserLogMessage = `["%c${'LOG'}%c %c${`Go to Source: http://localhost:${port}/__tsd/open-source?source=${encodeURIComponent(finalPath)}`}%c \\n \\u2192 ","color:#A0A","color:#FFF","color:#55F","color:#FFF"]`
|
|
45
|
-
|
|
46
|
-
const spreadStr = `...(typeof window === "undefined" ? ${serverLogMessage} : ${browserLogMessage}), `
|
|
47
|
-
|
|
48
|
-
// Find the opening '(' of the call by scanning forward from callee end
|
|
49
|
-
let parenOffset = callee.end
|
|
50
|
-
while (parenOffset < code.length && code[parenOffset] !== '(') {
|
|
51
|
-
parenOffset++
|
|
52
|
-
}
|
|
53
|
-
// Insert right after '('
|
|
54
|
-
s.appendRight(parenOffset + 1, spreadStr)
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
if (!s.hasChanged()) return
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
code: s.toString(),
|
|
62
|
-
map: s.generateMap({
|
|
63
|
-
source: filePath,
|
|
64
|
-
file: id,
|
|
65
|
-
includeContent: true,
|
|
66
|
-
}),
|
|
67
|
-
}
|
|
68
|
-
} catch (e) {
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
}
|