@nexiq/extension-sdk 1.0.3 → 1.0.7

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.
@@ -1,520 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { componentTask } from "./componentTask.js";
3
- describe("componentTask", () => {
4
- const mockData = {
5
- files: [
6
- {
7
- id: 1,
8
- path: "/src/App.tsx",
9
- hash: "1",
10
- fingerprint: "1",
11
- default_export: null,
12
- star_exports_json: null,
13
- },
14
- {
15
- id: 2,
16
- path: "/src/Comp.tsx",
17
- hash: "2",
18
- fingerprint: "2",
19
- default_export: null,
20
- star_exports_json: null,
21
- },
22
- ],
23
- entities: [
24
- {
25
- id: "e-comp",
26
- scope_id: "s-comp-module",
27
- kind: "component",
28
- name: "Comp",
29
- type: "function",
30
- line: 1,
31
- column: 1,
32
- end_line: 10,
33
- end_column: 1,
34
- declaration_kind: "const",
35
- data_json: null,
36
- },
37
- {
38
- id: "e-import",
39
- scope_id: "s-app-module",
40
- kind: "import",
41
- name: "Comp",
42
- type: "data",
43
- line: 1,
44
- column: 1,
45
- end_line: 1,
46
- end_column: 1,
47
- declaration_kind: null,
48
- data_json: JSON.stringify({
49
- source: "/src/Comp.tsx",
50
- importedName: "Comp",
51
- type: "named",
52
- }),
53
- },
54
- {
55
- id: "e-app",
56
- scope_id: "s-app-module",
57
- kind: "component",
58
- name: "App",
59
- type: "function",
60
- line: 5,
61
- column: 1,
62
- end_line: 15,
63
- end_column: 1,
64
- declaration_kind: "const",
65
- data_json: null,
66
- },
67
- ],
68
- scopes: [
69
- {
70
- id: "s-comp-module",
71
- file_id: 2,
72
- parent_id: null,
73
- kind: "module",
74
- entity_id: null,
75
- data_json: null,
76
- },
77
- {
78
- id: "s-comp-block",
79
- file_id: 2,
80
- parent_id: "s-comp-module",
81
- kind: "block",
82
- entity_id: "e-comp",
83
- data_json: null,
84
- },
85
- {
86
- id: "s-app-module",
87
- file_id: 1,
88
- parent_id: null,
89
- kind: "module",
90
- entity_id: null,
91
- data_json: null,
92
- },
93
- {
94
- id: "s-app-block",
95
- file_id: 1,
96
- parent_id: "s-app-module",
97
- kind: "block",
98
- entity_id: "e-app",
99
- data_json: null,
100
- },
101
- ],
102
- symbols: [
103
- {
104
- id: "sym-comp",
105
- entity_id: "e-comp",
106
- scope_id: "s-comp-module",
107
- name: "Comp",
108
- path: null,
109
- is_alias: 0,
110
- has_default: 0,
111
- data_json: null,
112
- },
113
- {
114
- id: "sym-import",
115
- entity_id: "e-import",
116
- scope_id: "s-app-module",
117
- name: "Comp",
118
- path: null,
119
- is_alias: 0,
120
- has_default: 0,
121
- data_json: null,
122
- },
123
- {
124
- id: "sym-app",
125
- entity_id: "e-app",
126
- scope_id: "s-app-module",
127
- name: "App",
128
- path: null,
129
- is_alias: 0,
130
- has_default: 0,
131
- data_json: null,
132
- },
133
- ],
134
- renders: [
135
- {
136
- id: "r-1",
137
- file_id: 1,
138
- parent_entity_id: "e-app",
139
- parent_render_id: null,
140
- render_index: 0,
141
- tag: "Comp",
142
- symbol_id: "sym-import",
143
- line: 10,
144
- column: 5,
145
- kind: "jsx",
146
- data_json: null,
147
- },
148
- {
149
- id: "r-2",
150
- file_id: 1,
151
- parent_entity_id: "e-app",
152
- parent_render_id: "r-1",
153
- render_index: 0,
154
- tag: "div",
155
- symbol_id: null,
156
- line: 11,
157
- column: 10,
158
- kind: "jsx",
159
- data_json: null,
160
- },
161
- ],
162
- exports: [
163
- {
164
- id: "exp-1",
165
- scope_id: "s-comp-module",
166
- symbol_id: "sym-comp",
167
- entity_id: "e-comp",
168
- name: "Comp",
169
- is_default: 0,
170
- },
171
- ],
172
- relations: [
173
- {
174
- from_id: "sym-app",
175
- to_id: "sym-import",
176
- kind: "usage",
177
- line: 10,
178
- column: 5,
179
- data_json: null,
180
- },
181
- ],
182
- };
183
- const initialResult = {
184
- nodes: [],
185
- combos: [],
186
- edges: [],
187
- typeData: {},
188
- };
189
- it("should skip automatic JSX symbols and their scopes", () => {
190
- const dataWithJsx = {
191
- ...mockData,
192
- symbols: [
193
- ...mockData.symbols,
194
- {
195
- id: "sym-jsx",
196
- entity_id: "e-jsx",
197
- scope_id: "s-app-block",
198
- name: "jsx@8:4",
199
- path: null,
200
- is_alias: 0,
201
- has_default: 0,
202
- data_json: null,
203
- },
204
- ],
205
- entities: [
206
- ...mockData.entities,
207
- {
208
- id: "e-jsx",
209
- scope_id: "s-app-block",
210
- kind: "normal",
211
- name: "jsx@8:4",
212
- type: "jsx",
213
- line: 8,
214
- column: 4,
215
- end_line: 8,
216
- end_column: 10,
217
- declaration_kind: null,
218
- data_json: null,
219
- },
220
- ],
221
- scopes: [
222
- ...mockData.scopes,
223
- {
224
- id: "s-jsx-block",
225
- file_id: 1,
226
- parent_id: "s-app-block",
227
- kind: "block",
228
- entity_id: "e-jsx",
229
- data_json: null,
230
- },
231
- ],
232
- };
233
- const result = componentTask.run(dataWithJsx, initialResult);
234
- // Verify symbol node is skipped
235
- const jsxNode = result.nodes.find((n) => n.name === "jsx@8:4");
236
- expect(jsxNode).toBeUndefined();
237
- // Verify scope combo is skipped
238
- const jsxScope = result.combos.find((c) => c.id === "s-jsx-block");
239
- expect(jsxScope).toBeUndefined();
240
- });
241
- it("should hide import nodes and redirect relations", () => {
242
- const result = componentTask.run(mockData, initialResult);
243
- // Verify import node is NOT present
244
- const importNode = result.nodes.find((n) => n.id === "sym-import");
245
- const importCombo = result.combos.find((c) => c.id === "sym-import");
246
- expect(importNode).toBeUndefined();
247
- expect(importCombo).toBeUndefined();
248
- // Verify relation is redirected from sym-app to sym-comp
249
- // Step 4 logic: const edgeId = `${sourceId}-${targetId}-${rel.kind}`;
250
- const edgeId = "sym-app-sym-comp-usage";
251
- const edge = result.edges.find((e) => e.id === edgeId);
252
- expect(edge).toBeDefined();
253
- expect(edge?.source).toBe("sym-app");
254
- expect(edge?.target).toBe("sym-comp");
255
- });
256
- it("should use tag name for top-level JSX label and stack correctly", () => {
257
- const result = componentTask.run(mockData, initialResult);
258
- const renderGroup = result.combos.find((c) => c.id === "render-group-s-app-block");
259
- expect(renderGroup).toBeDefined();
260
- expect(renderGroup?.name).toBe("render");
261
- expect(renderGroup?.combo).toBe("s-app-block");
262
- const compRender = result.combos.find((c) => c.id === "r-1");
263
- expect(compRender).toBeDefined();
264
- expect(compRender?.label?.text).toBe("Comp");
265
- expect(compRender?.combo).toBe("render-group-s-app-block");
266
- const divRender = result.combos.find((c) => c.id === "r-2");
267
- expect(divRender).toBeDefined();
268
- expect(divRender?.label?.text).toBe("div");
269
- expect(divRender?.combo).toBe("r-1"); // Nested inside r-1
270
- });
271
- it("should show effect nodes and their dependencies", () => {
272
- const dataWithEffect = {
273
- ...mockData,
274
- entities: mockData.entities.map((e) => {
275
- if (e.id === "e-app") {
276
- return {
277
- ...e,
278
- data_json: JSON.stringify({
279
- effects: {
280
- "e-app:effect:10:5": {
281
- id: "e-app:effect:10:5",
282
- loc: { line: 10, column: 5 },
283
- reactDeps: [{ id: "sym-import", name: "Comp" }],
284
- },
285
- },
286
- }),
287
- };
288
- }
289
- return e;
290
- }),
291
- };
292
- const result = componentTask.run(dataWithEffect, initialResult);
293
- const effectNode = result.nodes.find((n) => n.id === "e-app:effect:10:5");
294
- expect(effectNode).toBeDefined();
295
- expect(effectNode?.name).toBe("useEffect");
296
- expect(effectNode?.combo).toBe("s-app-block");
297
- // Verify dependency edge (sym-import should be redirected to sym-comp, arrow points FROM dependency TO consumer)
298
- const depEdge = result.edges.find((e) => e.id === "sym-comp-e-app:effect:10:5-effect-dep");
299
- expect(depEdge).toBeDefined();
300
- expect(depEdge?.source).toBe("sym-comp");
301
- expect(depEdge?.target).toBe("e-app:effect:10:5");
302
- });
303
- it("should show dependencies for hooks like useMemo", () => {
304
- const dataWithMemo = {
305
- ...mockData,
306
- entities: [
307
- ...mockData.entities,
308
- {
309
- id: "e-memo",
310
- scope_id: "s-app-block",
311
- kind: "hook",
312
- name: "memoVal",
313
- type: "data",
314
- line: 12,
315
- column: 5,
316
- end_line: 12,
317
- end_column: 20,
318
- declaration_kind: "const",
319
- data_json: JSON.stringify({
320
- reactDeps: [{ id: "sym-import", name: "Comp" }],
321
- }),
322
- },
323
- ],
324
- symbols: [
325
- ...mockData.symbols,
326
- {
327
- id: "sym-memo",
328
- entity_id: "e-memo",
329
- scope_id: "s-app-block",
330
- name: "memoVal",
331
- path: null,
332
- is_alias: 0,
333
- has_default: 0,
334
- data_json: null,
335
- },
336
- ],
337
- };
338
- const result = componentTask.run(dataWithMemo, initialResult);
339
- const memoNode = result.nodes.find((n) => n.id === "sym-memo");
340
- expect(memoNode).toBeDefined();
341
- // Verify dependency edge (arrow points FROM dependency TO consumer)
342
- const depEdge = result.edges.find((e) => e.id === "sym-comp-sym-memo-react-dep");
343
- expect(depEdge).toBeDefined();
344
- expect(depEdge?.source).toBe("sym-comp");
345
- expect(depEdge?.target).toBe("sym-memo");
346
- });
347
- it("should show useLayoutEffect nodes", () => {
348
- const dataWithEffect = {
349
- ...mockData,
350
- entities: mockData.entities.map((e) => {
351
- if (e.id === "e-app") {
352
- return {
353
- ...e,
354
- data_json: JSON.stringify({
355
- effects: {
356
- "e-app:effect:10:5": {
357
- id: "e-app:effect:10:5",
358
- name: "useLayoutEffect",
359
- loc: { line: 10, column: 5 },
360
- reactDeps: [],
361
- },
362
- },
363
- }),
364
- };
365
- }
366
- return e;
367
- }),
368
- };
369
- const result = componentTask.run(dataWithEffect, initialResult);
370
- const effectNode = result.nodes.find((n) => n.id === "e-app:effect:10:5");
371
- expect(effectNode).toBeDefined();
372
- expect(effectNode?.name).toBe("useLayoutEffect");
373
- expect(effectNode?.label?.text).toBe("useLayoutEffect");
374
- });
375
- it("should show improved labels for useState and useRef", () => {
376
- const dataWithState = {
377
- ...mockData,
378
- entities: [
379
- ...mockData.entities,
380
- {
381
- id: "e-state",
382
- scope_id: "s-app-block",
383
- kind: "state",
384
- name: "count",
385
- type: "data",
386
- line: 6,
387
- column: 5,
388
- end_line: 6,
389
- end_column: 15,
390
- declaration_kind: "const",
391
- data_json: JSON.stringify({ setter: "setCount" }),
392
- },
393
- {
394
- id: "e-ref",
395
- scope_id: "s-app-block",
396
- kind: "ref",
397
- name: "myRef",
398
- type: "data",
399
- line: 7,
400
- column: 5,
401
- end_line: 7,
402
- end_column: 15,
403
- declaration_kind: "const",
404
- data_json: JSON.stringify({}),
405
- },
406
- ],
407
- symbols: [
408
- ...mockData.symbols,
409
- {
410
- id: "sym-state",
411
- entity_id: "e-state",
412
- scope_id: "s-app-block",
413
- name: "count",
414
- path: JSON.stringify(["0"]),
415
- is_alias: 0,
416
- has_default: 0,
417
- data_json: null,
418
- },
419
- {
420
- id: "sym-setter",
421
- entity_id: "e-state",
422
- scope_id: "s-app-block",
423
- name: "setCount",
424
- path: JSON.stringify(["1"]),
425
- is_alias: 0,
426
- has_default: 0,
427
- data_json: null,
428
- },
429
- {
430
- id: "sym-ref",
431
- entity_id: "e-ref",
432
- scope_id: "s-app-block",
433
- name: "myRef",
434
- path: null,
435
- is_alias: 0,
436
- has_default: 0,
437
- data_json: null,
438
- },
439
- ],
440
- };
441
- const result = componentTask.run(dataWithState, initialResult);
442
- const stateNode = result.nodes.filter((n) => n.id === "sym-state" || n.id === "sym-setter");
443
- expect(stateNode.length).toBe(1);
444
- expect(stateNode[0].id).toBe("sym-state");
445
- expect(stateNode[0].label?.text).toBe("count");
446
- const refNode = result.nodes.find((n) => n.id === "sym-ref");
447
- expect(refNode).toBeDefined();
448
- expect(refNode?.label?.text).toBe("myRef");
449
- });
450
- it("should group destructured variables by their path", () => {
451
- const dataWithDestructuring = {
452
- ...mockData,
453
- entities: [
454
- ...mockData.entities,
455
- {
456
- id: "e-hook-call",
457
- scope_id: "s-app-block",
458
- kind: "hook",
459
- name: "useTable",
460
- type: "data",
461
- line: 20,
462
- column: 5,
463
- end_line: 20,
464
- end_column: 30,
465
- declaration_kind: "const",
466
- data_json: null,
467
- },
468
- ],
469
- symbols: [
470
- ...mockData.symbols,
471
- {
472
- id: "sym-rows",
473
- entity_id: "e-hook-call",
474
- scope_id: "s-app-block",
475
- name: "rows",
476
- path: JSON.stringify(["rows"]),
477
- is_alias: 0,
478
- has_default: 0,
479
- data_json: null,
480
- },
481
- {
482
- id: "sym-orig",
483
- entity_id: "e-hook-call",
484
- scope_id: "s-app-block",
485
- name: "original",
486
- path: JSON.stringify(["rows", "0", "original"]),
487
- is_alias: 0,
488
- has_default: 0,
489
- data_json: null,
490
- },
491
- ],
492
- };
493
- const result = componentTask.run(dataWithDestructuring, initialResult);
494
- // Verify 'rows' node
495
- const rowsNode = result.nodes.find((n) => n.id === "sym-rows");
496
- expect(rowsNode).toBeDefined();
497
- expect(rowsNode?.combo).toBe("s-app-block:source:e-hook-call"); // First layer grouped under source
498
- // Verify source combo
499
- const sourceCombo = result.combos.find((c) => c.id === "s-app-block:source:e-hook-call");
500
- expect(sourceCombo).toBeDefined();
501
- expect(sourceCombo?.name).toBe("useTable");
502
- expect(sourceCombo?.combo).toBe("s-app-block");
503
- // Verify 'original' node and intermediate combos
504
- const origNode = result.nodes.find((n) => n.id === "sym-orig");
505
- expect(origNode).toBeDefined();
506
- // Path ["rows", "0", "original"]
507
- // Source: s-app-block:source:e-hook-call
508
- // Combo 1: s-app-block:source:e-hook-call:path:rows
509
- // Combo 2: s-app-block:source:e-hook-call:path:rows/0
510
- expect(origNode?.combo).toBe("s-app-block:source:e-hook-call:path:rows/0");
511
- const combo0 = result.combos.find((c) => c.id === "s-app-block:source:e-hook-call:path:rows/0");
512
- expect(combo0).toBeDefined();
513
- expect(combo0?.name).toBe("0");
514
- expect(combo0?.combo).toBe("s-app-block:source:e-hook-call:path:rows");
515
- const comboRows = result.combos.find((c) => c.id === "s-app-block:source:e-hook-call:path:rows");
516
- expect(comboRows).toBeDefined();
517
- expect(comboRows?.name).toBe("rows");
518
- expect(comboRows?.combo).toBe("s-app-block:source:e-hook-call");
519
- });
520
- });
@@ -1,6 +0,0 @@
1
- import { type GraphViewTask } from "../index.js";
2
- /**
3
- * Task that applies Git status (added, modified, deleted) to nodes and combos.
4
- * This runs after the base graph has been generated.
5
- */
6
- export declare const gitTask: GraphViewTask;
@@ -1,69 +0,0 @@
1
- /**
2
- * Task that applies Git status (added, modified, deleted) to nodes and combos.
3
- * This runs after the base graph has been generated.
4
- */
5
- export const gitTask = {
6
- id: "git-status",
7
- priority: 100, // Run late to ensure all nodes/combos are present
8
- run: (graphData, result) => {
9
- const { added = [], modified = [], deleted = [] } = graphData.diff || {};
10
- // Skip if no diff data
11
- if (added.length === 0 && modified.length === 0 && deleted.length === 0) {
12
- return result;
13
- }
14
- const combos = [...result.combos];
15
- const nodes = [...result.nodes];
16
- const applyStatus = (item) => {
17
- // Find the base ID for mapping (e.g., stripping '-render-instanceId')
18
- let baseId = item.id;
19
- if (item.id.includes("-render-")) {
20
- baseId = item.id.split("-render-")[0];
21
- }
22
- else if (item.id.includes("-props")) {
23
- baseId = item.id.split("-props")[0];
24
- }
25
- else if (item.id.includes(":")) {
26
- // Handle virtual variables (parent:id)
27
- baseId = item.id.split(":")[0];
28
- }
29
- if (added.includes(item.id) || added.includes(baseId)) {
30
- item.gitStatus = "added";
31
- }
32
- else if (modified.includes(item.id) || modified.includes(baseId)) {
33
- item.gitStatus = "modified";
34
- }
35
- else if (deleted.includes(item.id) || deleted.includes(baseId)) {
36
- item.gitStatus = "deleted";
37
- }
38
- };
39
- nodes.forEach(applyStatus);
40
- combos.forEach(applyStatus);
41
- // Aggregate statuses for specialized combos (like 'props')
42
- combos.forEach((combo) => {
43
- if (combo.id.endsWith("-props")) {
44
- const childStatuses = [
45
- ...nodes
46
- .filter((n) => n.combo === combo.id)
47
- .map((n) => n.gitStatus),
48
- ...combos
49
- .filter((c) => c.combo === combo.id)
50
- .map((c) => c.gitStatus),
51
- ].filter(Boolean);
52
- if (childStatuses.length > 0) {
53
- const unique = new Set(childStatuses);
54
- if (unique.size === 1) {
55
- combo.gitStatus = childStatuses[0];
56
- }
57
- else {
58
- combo.gitStatus = "modified";
59
- }
60
- }
61
- }
62
- });
63
- return {
64
- ...result,
65
- nodes,
66
- combos,
67
- };
68
- },
69
- };