@tanstack/devtools-vite 0.8.0 → 0.8.1

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/devtools-vite",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "TanStack Vite plugin used to enhance the core devtools with additional functionalities",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -10,6 +10,9 @@
10
10
  "directory": "packages/devtools-vite"
11
11
  },
12
12
  "homepage": "https://tanstack.com/devtools",
13
+ "bugs": {
14
+ "url": "https://github.com/TanStack/devtools/issues"
15
+ },
13
16
  "funding": {
14
17
  "type": "github",
15
18
  "url": "https://github.com/sponsors/tannerlinsley"
@@ -51,7 +54,7 @@
51
54
  "magic-string": "^0.30.0",
52
55
  "oxc-parser": "^0.120.0",
53
56
  "picomatch": "^4.0.3",
54
- "@tanstack/devtools-client": "0.0.7",
57
+ "@tanstack/devtools-client": "0.0.8",
55
58
  "@tanstack/devtools-event-bus": "0.4.2"
56
59
  },
57
60
  "devDependencies": {
@@ -0,0 +1,109 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { forEachChild, walk } from './ast-utils'
3
+ import type { Node } from 'oxc-parser'
4
+
5
+ describe('forEachChild', () => {
6
+ it('visits only direct typed children, skipping null and non-type values', () => {
7
+ const childA = { type: 'ChildA', start: 0, end: 1 }
8
+ const childB = { type: 'ChildB', start: 1, end: 2 }
9
+ const nested = { type: 'Nested', start: 2, end: 3 }
10
+ const root = {
11
+ type: 'ForEachRoot',
12
+ start: 0,
13
+ end: 10,
14
+ // array-valued key holding two typed children
15
+ items: [childA, childB],
16
+ // object-valued typed child
17
+ body: nested,
18
+ // null field: skipped
19
+ optional: null,
20
+ // primitive string value: not a child (and excluded from child keys)
21
+ name: 'hello',
22
+ // primitive number value: not a child
23
+ count: 5,
24
+ } as unknown as Node
25
+
26
+ const visited: Array<Node> = []
27
+ forEachChild(root, (child) => visited.push(child))
28
+
29
+ expect(visited).toEqual([childA, childB, nested])
30
+ expect(visited).toHaveLength(3)
31
+ })
32
+
33
+ it('skips non-object array items and array items without a type', () => {
34
+ const real = { type: 'RealItem', start: 0, end: 1 }
35
+ const root = {
36
+ type: 'ForEachArrayRoot',
37
+ start: 0,
38
+ end: 10,
39
+ items: [real, null, 'string-item', 42, { noType: true }],
40
+ } as unknown as Node
41
+
42
+ const visited: Array<Node> = []
43
+ forEachChild(root, (child) => visited.push(child))
44
+
45
+ expect(visited).toEqual([real])
46
+ })
47
+ })
48
+
49
+ describe('walk', () => {
50
+ it('visits every node depth-first with the correct parentNode', () => {
51
+ const grandchild = { type: 'WalkGrandchild', start: 4, end: 5 }
52
+ const childA = {
53
+ type: 'WalkChildA',
54
+ start: 1,
55
+ end: 6,
56
+ inner: grandchild,
57
+ }
58
+ const childB = { type: 'WalkChildB', start: 6, end: 7 }
59
+ const root = {
60
+ type: 'WalkRoot',
61
+ start: 0,
62
+ end: 10,
63
+ children: [childA, childB],
64
+ } as unknown as Node
65
+
66
+ const visits: Array<{ node: Node; parent: Node | undefined }> = []
67
+ walk(root, (node, parentNode) => {
68
+ visits.push({ node, parent: parentNode })
69
+ })
70
+
71
+ // Depth-first order: root, childA, grandchild, childB
72
+ expect(visits.map((v) => v.node.type)).toEqual([
73
+ 'WalkRoot',
74
+ 'WalkChildA',
75
+ 'WalkGrandchild',
76
+ 'WalkChildB',
77
+ ])
78
+
79
+ // Correct parent for each node
80
+ expect(visits[0]!.parent).toBeUndefined()
81
+ expect(visits[1]!.parent).toBe(root)
82
+ expect(visits[2]!.parent).toBe(childA)
83
+ expect(visits[3]!.parent).toBe(root)
84
+ })
85
+
86
+ it('passes the provided parentNode through to the root visit', () => {
87
+ const fakeParent = {
88
+ type: 'WalkExternalParent',
89
+ start: 0,
90
+ end: 1,
91
+ } as unknown as Node
92
+ const root = {
93
+ type: 'WalkRootWithParent',
94
+ start: 1,
95
+ end: 2,
96
+ } as unknown as Node
97
+
98
+ const visits: Array<{ node: Node; parent: Node | undefined }> = []
99
+ walk(
100
+ root,
101
+ (node, parentNode) => visits.push({ node, parent: parentNode }),
102
+ fakeParent,
103
+ )
104
+
105
+ expect(visits).toHaveLength(1)
106
+ expect(visits[0]!.node).toBe(root)
107
+ expect(visits[0]!.parent).toBe(fakeParent)
108
+ })
109
+ })
@@ -0,0 +1,58 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ TANSTACK_DEVTOOLS_PACKAGES,
4
+ isTanStackDevtoolsImport,
5
+ } from './devtools-packages'
6
+
7
+ describe('TANSTACK_DEVTOOLS_PACKAGES', () => {
8
+ it('contains exactly 7 entries', () => {
9
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toHaveLength(7)
10
+ })
11
+
12
+ it('includes the known framework-specific devtools packages', () => {
13
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/react-devtools')
14
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/preact-devtools')
15
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/solid-devtools')
16
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/vue-devtools')
17
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/svelte-devtools')
18
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/angular-devtools')
19
+ })
20
+
21
+ it('includes the framework-agnostic @tanstack/devtools entry', () => {
22
+ expect(TANSTACK_DEVTOOLS_PACKAGES).toContain('@tanstack/devtools')
23
+ })
24
+ })
25
+
26
+ describe('isTanStackDevtoolsImport', () => {
27
+ it('returns true for @tanstack/react-devtools', () => {
28
+ expect(isTanStackDevtoolsImport('@tanstack/react-devtools')).toBe(true)
29
+ })
30
+
31
+ it('returns true for @tanstack/devtools', () => {
32
+ expect(isTanStackDevtoolsImport('@tanstack/devtools')).toBe(true)
33
+ })
34
+
35
+ it('returns true for every entry in TANSTACK_DEVTOOLS_PACKAGES', () => {
36
+ for (const pkg of TANSTACK_DEVTOOLS_PACKAGES) {
37
+ expect(isTanStackDevtoolsImport(pkg)).toBe(true)
38
+ }
39
+ })
40
+
41
+ it('returns false for an unrelated package', () => {
42
+ expect(isTanStackDevtoolsImport('react')).toBe(false)
43
+ })
44
+
45
+ it('returns false for an empty string', () => {
46
+ expect(isTanStackDevtoolsImport('')).toBe(false)
47
+ })
48
+
49
+ it('returns false for a @tanstack package that is not in the devtools list', () => {
50
+ expect(isTanStackDevtoolsImport('@tanstack/other-thing')).toBe(false)
51
+ })
52
+
53
+ it('returns false for a prefix-only match (no partial matching)', () => {
54
+ expect(isTanStackDevtoolsImport('@tanstack/react-devtools/extra')).toBe(
55
+ false,
56
+ )
57
+ })
58
+ })
@@ -0,0 +1,75 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import { handleOpenSource } from './editor'
3
+
4
+ describe('handleOpenSource', () => {
5
+ it('calls openInEditor with source, stringified line and column when all provided', async () => {
6
+ const openInEditor = vi.fn().mockResolvedValue(undefined)
7
+ await handleOpenSource({
8
+ data: {
9
+ type: 'open-source',
10
+ data: { source: '/app/routes/foo.tsx', line: 10, column: 5 },
11
+ },
12
+ openInEditor,
13
+ })
14
+ expect(openInEditor).toHaveBeenCalledOnce()
15
+ expect(openInEditor).toHaveBeenCalledWith('/app/routes/foo.tsx', '10', '5')
16
+ })
17
+
18
+ it('calls openInEditor with source only when line and column are undefined', async () => {
19
+ const openInEditor = vi.fn().mockResolvedValue(undefined)
20
+ await handleOpenSource({
21
+ data: { type: 'open-source', data: { source: '/app/routes/bar.tsx' } },
22
+ openInEditor,
23
+ })
24
+ expect(openInEditor).toHaveBeenCalledOnce()
25
+ expect(openInEditor).toHaveBeenCalledWith(
26
+ '/app/routes/bar.tsx',
27
+ undefined,
28
+ undefined,
29
+ )
30
+ })
31
+
32
+ it('does NOT call openInEditor and returns undefined when source is absent', async () => {
33
+ const openInEditor = vi.fn()
34
+ const result = await handleOpenSource({
35
+ data: { type: 'open-source', data: { line: 1, column: 2 } },
36
+ openInEditor,
37
+ })
38
+ expect(openInEditor).not.toHaveBeenCalled()
39
+ expect(result).toBeUndefined()
40
+ })
41
+
42
+ it('treats falsy line: 0 and column: 0 as undefined (truthy check in impl)', async () => {
43
+ const openInEditor = vi.fn().mockResolvedValue(undefined)
44
+ await handleOpenSource({
45
+ data: {
46
+ type: 'open-source',
47
+ data: { source: '/app/routes/baz.tsx', line: 0, column: 0 },
48
+ },
49
+ openInEditor,
50
+ })
51
+ expect(openInEditor).toHaveBeenCalledOnce()
52
+ expect(openInEditor).toHaveBeenCalledWith(
53
+ '/app/routes/baz.tsx',
54
+ undefined,
55
+ undefined,
56
+ )
57
+ })
58
+
59
+ it('calls openInEditor with stringified line and undefined column when only line is provided', async () => {
60
+ const openInEditor = vi.fn().mockResolvedValue(undefined)
61
+ await handleOpenSource({
62
+ data: {
63
+ type: 'open-source',
64
+ data: { source: '/app/routes/qux.tsx', line: 42 },
65
+ },
66
+ openInEditor,
67
+ })
68
+ expect(openInEditor).toHaveBeenCalledOnce()
69
+ expect(openInEditor).toHaveBeenCalledWith(
70
+ '/app/routes/qux.tsx',
71
+ '42',
72
+ undefined,
73
+ )
74
+ })
75
+ })
@@ -0,0 +1,34 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { createLocMapper } from './offset-to-loc'
3
+
4
+ describe('createLocMapper', () => {
5
+ // Source: "ab\ncde\nf"
6
+ // Indices: 0 1 2 3 4 5 6 7
7
+ // lineStarts: [0, 3, 7]
8
+ const source = 'ab\ncde\nf'
9
+ const toLoc = createLocMapper(source)
10
+
11
+ it('maps offset 0 to line 1, column 0', () => {
12
+ expect(toLoc(0)).toEqual({ line: 1, column: 0 })
13
+ })
14
+
15
+ it('maps the start of line 2 (offset 3, just after first \\n) to line 2, column 0', () => {
16
+ expect(toLoc(3)).toEqual({ line: 2, column: 0 })
17
+ })
18
+
19
+ it('maps a mid-line-2 offset (offset 5, "e") to line 2, column 2', () => {
20
+ expect(toLoc(5)).toEqual({ line: 2, column: 2 })
21
+ })
22
+
23
+ it('maps the final offset (offset 7, "f") to line 3, column 0', () => {
24
+ expect(toLoc(7)).toEqual({ line: 3, column: 0 })
25
+ })
26
+
27
+ it('maps an offset on a \\n boundary char (offset 2) to line 1, column 2', () => {
28
+ expect(toLoc(2)).toEqual({ line: 1, column: 2 })
29
+ })
30
+
31
+ it('maps the second \\n boundary (offset 6) to line 2, column 3', () => {
32
+ expect(toLoc(6)).toEqual({ line: 2, column: 3 })
33
+ })
34
+ })