@eventra_dev/eventra-cli 0.0.17 → 0.0.19

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.
@@ -4,14 +4,17 @@ import {
4
4
  Node,
5
5
  } from "ts-morph";
6
6
 
7
+ import path from "path";
8
+
7
9
  import { ExtractedEvent, EventraConfig } from "../../types";
8
10
  import { extractExpression } from "../extract";
9
11
 
10
12
  export function scanTrack(
11
13
  source: SourceFile,
12
- config: EventraConfig
14
+ config: EventraConfig,
15
+ aliases: Record<string, string>
13
16
  ) {
14
- const events = new Set<ExtractedEvent>();
17
+ const events = new Map<string, ExtractedEvent>();
15
18
 
16
19
  const calls = source.getDescendantsOfKind(
17
20
  SyntaxKind.CallExpression
@@ -34,6 +37,7 @@ export function scanTrack(
34
37
 
35
38
  if (!isTrack) continue;
36
39
 
40
+ // ❗ skip wrapper functions
37
41
  const func =
38
42
  call.getFirstAncestorByKind(SyntaxKind.FunctionDeclaration) ||
39
43
  call.getFirstAncestorByKind(SyntaxKind.ArrowFunction) ||
@@ -69,16 +73,27 @@ export function scanTrack(
69
73
  const arg = call.getArguments()[0];
70
74
  if (!arg) continue;
71
75
 
72
- const result = extractExpression(arg);
76
+ const result = extractExpression(arg, aliases);
73
77
  if (!result) continue;
74
78
 
75
- result.values.forEach((value) =>
76
- events.add({
79
+ const line = call.getStartLineNumber();
80
+
81
+ const file = path.relative(
82
+ process.cwd(),
83
+ source.getFilePath()
84
+ );
85
+
86
+ for (const value of result.values) {
87
+ const key = `${value}:${file}:${line}`;
88
+
89
+ events.set(key, {
77
90
  value,
78
91
  dynamic: result.dynamic,
79
- })
80
- );
92
+ file,
93
+ line
94
+ });
95
+ }
81
96
  }
82
97
 
83
- return events;
98
+ return [...events.values()];
84
99
  }