@eventra_dev/eventra-cli 0.1.31 → 0.1.32
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/engine/callResolver.js +56 -25
- package/dist/engine/languageService.js +36 -11
- package/dist/engine/scanner.js +74 -71
- package/dist/utils/universal.js +73 -21
- package/package.json +1 -1
- package/src/engine/callResolver.ts +61 -28
- package/src/engine/languageService.ts +50 -16
- package/src/engine/scanner.ts +83 -94
- package/src/utils/universal.ts +90 -21
package/src/utils/universal.ts
CHANGED
|
@@ -1,28 +1,48 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { ParseResult } from "../types";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/* ---------------------------------- */
|
|
5
|
+
/* COMMENT STRIP (SAFE) */
|
|
6
|
+
/* ---------------------------------- */
|
|
5
7
|
function stripComments(input: string): string {
|
|
6
8
|
return input
|
|
7
9
|
.replace(/<!--[\s\S]*?-->/g, "")
|
|
8
10
|
.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
/* ---------------------------------- */
|
|
14
|
+
/* TRACK DETECTOR */
|
|
15
|
+
/* ---------------------------------- */
|
|
12
16
|
function looksLikeTracking(code: string) {
|
|
13
|
-
return /\btrack\
|
|
17
|
+
return /\btrack\s*\(|\.track\s*\(/.test(code);
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
/* ---------------------------------- */
|
|
21
|
+
/* SAFE {} PARSER (JSX / TEMPLATES) */
|
|
22
|
+
/* ---------------------------------- */
|
|
17
23
|
function extractBracedExpressions(input: string): string[] {
|
|
18
24
|
const result: string[] = [];
|
|
19
25
|
|
|
20
26
|
let depth = 0;
|
|
21
27
|
let start = -1;
|
|
28
|
+
let inString: string | null = null;
|
|
22
29
|
|
|
23
30
|
for (let i = 0; i < input.length; i++) {
|
|
24
31
|
const char = input[i];
|
|
25
32
|
|
|
33
|
+
// handle strings
|
|
34
|
+
if (inString) {
|
|
35
|
+
if (char === inString && input[i - 1] !== "\\") {
|
|
36
|
+
inString = null;
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
42
|
+
inString = char;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
26
46
|
if (char === "{") {
|
|
27
47
|
if (depth === 0) start = i + 1;
|
|
28
48
|
depth++;
|
|
@@ -30,9 +50,11 @@ function extractBracedExpressions(input: string): string[] {
|
|
|
30
50
|
depth--;
|
|
31
51
|
if (depth === 0 && start !== -1) {
|
|
32
52
|
const expr = input.slice(start, i);
|
|
53
|
+
|
|
33
54
|
if (looksLikeTracking(expr)) {
|
|
34
55
|
result.push(expr);
|
|
35
56
|
}
|
|
57
|
+
|
|
36
58
|
start = -1;
|
|
37
59
|
}
|
|
38
60
|
}
|
|
@@ -41,7 +63,9 @@ function extractBracedExpressions(input: string): string[] {
|
|
|
41
63
|
return result;
|
|
42
64
|
}
|
|
43
65
|
|
|
44
|
-
|
|
66
|
+
/* ---------------------------------- */
|
|
67
|
+
/* HTML HANDLERS */
|
|
68
|
+
/* ---------------------------------- */
|
|
45
69
|
function extractHTMLHandlers(input: string): string[] {
|
|
46
70
|
const result: string[] = [];
|
|
47
71
|
|
|
@@ -56,7 +80,9 @@ function extractHTMLHandlers(input: string): string[] {
|
|
|
56
80
|
return result;
|
|
57
81
|
}
|
|
58
82
|
|
|
59
|
-
|
|
83
|
+
/* ---------------------------------- */
|
|
84
|
+
/* VUE HANDLERS */
|
|
85
|
+
/* ---------------------------------- */
|
|
60
86
|
function extractVueHandlers(input: string): string[] {
|
|
61
87
|
const result: string[] = [];
|
|
62
88
|
|
|
@@ -71,29 +97,34 @@ function extractVueHandlers(input: string): string[] {
|
|
|
71
97
|
return result;
|
|
72
98
|
}
|
|
73
99
|
|
|
74
|
-
|
|
100
|
+
/* ---------------------------------- */
|
|
101
|
+
/* SVELTE HANDLERS */
|
|
102
|
+
/* ---------------------------------- */
|
|
75
103
|
function extractSvelteHandlers(input: string): string[] {
|
|
76
104
|
const result: string[] = [];
|
|
77
105
|
|
|
78
|
-
const regex = /\bon:[\w]+\s*=\s*{([
|
|
106
|
+
const regex = /\bon:[\w]+\s*=\s*{([\s\S]*?)}/g;
|
|
79
107
|
|
|
80
108
|
for (const m of input.matchAll(regex)) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
109
|
+
const expr = m[1];
|
|
110
|
+
|
|
111
|
+
const nested = extractBracedExpressions(`{${expr}}`);
|
|
112
|
+
result.push(...nested);
|
|
84
113
|
}
|
|
85
114
|
|
|
86
115
|
return result;
|
|
87
116
|
}
|
|
88
117
|
|
|
89
|
-
|
|
118
|
+
/* ---------------------------------- */
|
|
119
|
+
/* SCRIPT EXTRACTION */
|
|
120
|
+
/* ---------------------------------- */
|
|
90
121
|
function extractScripts(input: string, file: string) {
|
|
91
122
|
const scripts: string[] = [];
|
|
92
123
|
const deps: string[] = [];
|
|
93
124
|
|
|
94
|
-
// src
|
|
125
|
+
// <script src="">
|
|
95
126
|
const srcRegex =
|
|
96
|
-
/<script\b[^>]*?\bsrc=["'](.+?)["'][^>]*>/
|
|
127
|
+
/<script\b[^>]*?\bsrc=["'](.+?)["'][^>]*>/gi;
|
|
97
128
|
|
|
98
129
|
for (const m of input.matchAll(srcRegex)) {
|
|
99
130
|
const src = m[1];
|
|
@@ -105,9 +136,9 @@ function extractScripts(input: string, file: string) {
|
|
|
105
136
|
deps.push(resolved);
|
|
106
137
|
}
|
|
107
138
|
|
|
108
|
-
// inline
|
|
139
|
+
// inline <script>
|
|
109
140
|
const scriptRegex =
|
|
110
|
-
/<script\b[^>]*>([\s\S]*?)<\/script>/
|
|
141
|
+
/<script\b[^>]*>([\s\S]*?)<\/script>/gi;
|
|
111
142
|
|
|
112
143
|
for (const m of input.matchAll(scriptRegex)) {
|
|
113
144
|
if (m[1]?.trim()) {
|
|
@@ -120,9 +151,37 @@ function extractScripts(input: string, file: string) {
|
|
|
120
151
|
return { scripts, deps, noScripts };
|
|
121
152
|
}
|
|
122
153
|
|
|
123
|
-
|
|
154
|
+
/* ---------------------------------- */
|
|
155
|
+
/* STATIC IMPORTS */
|
|
156
|
+
/* ---------------------------------- */
|
|
157
|
+
function extractStaticImports(input: string, file: string) {
|
|
158
|
+
const deps: string[] = [];
|
|
159
|
+
|
|
160
|
+
const regex =
|
|
161
|
+
/import\s+(?:.+?\s+from\s+)?["'](.+?)["']/g;
|
|
162
|
+
|
|
163
|
+
for (const m of input.matchAll(regex)) {
|
|
164
|
+
const mod = m[1];
|
|
165
|
+
|
|
166
|
+
if (!mod.startsWith(".") && !mod.startsWith("/")) continue;
|
|
167
|
+
|
|
168
|
+
const resolved = path.resolve(
|
|
169
|
+
path.dirname(file),
|
|
170
|
+
mod
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
deps.push(resolved);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return deps;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* ---------------------------------- */
|
|
180
|
+
/* DYNAMIC IMPORTS */
|
|
181
|
+
/* ---------------------------------- */
|
|
124
182
|
function extractDynamicImports(input: string, file: string) {
|
|
125
183
|
const deps: string[] = [];
|
|
184
|
+
const calls: string[] = [];
|
|
126
185
|
|
|
127
186
|
const regex = /import\(\s*["'](.+?)["']\s*\)/g;
|
|
128
187
|
|
|
@@ -134,12 +193,18 @@ function extractDynamicImports(input: string, file: string) {
|
|
|
134
193
|
: path.resolve(path.dirname(file), mod);
|
|
135
194
|
|
|
136
195
|
deps.push(resolved);
|
|
196
|
+
|
|
197
|
+
if (looksLikeTracking(mod)) {
|
|
198
|
+
calls.push(`import("${mod}")`);
|
|
199
|
+
}
|
|
137
200
|
}
|
|
138
201
|
|
|
139
|
-
return deps;
|
|
202
|
+
return { deps, calls };
|
|
140
203
|
}
|
|
141
204
|
|
|
142
|
-
|
|
205
|
+
/* ---------------------------------- */
|
|
206
|
+
/* MAIN */
|
|
207
|
+
/* ---------------------------------- */
|
|
143
208
|
export function parseUniversal(
|
|
144
209
|
content: string,
|
|
145
210
|
file: string
|
|
@@ -150,7 +215,7 @@ export function parseUniversal(
|
|
|
150
215
|
const clean = stripComments(content);
|
|
151
216
|
|
|
152
217
|
/* ---------- ASTRO FRONTMATTER ---------- */
|
|
153
|
-
const fm = clean.match(
|
|
218
|
+
const fm = clean.match(/^\s*---([\s\S]*?)---/);
|
|
154
219
|
if (fm?.[1]) {
|
|
155
220
|
parts.push(fm[1]);
|
|
156
221
|
}
|
|
@@ -171,7 +236,11 @@ export function parseUniversal(
|
|
|
171
236
|
parts.push(...extractBracedExpressions(clean));
|
|
172
237
|
|
|
173
238
|
/* ---------- IMPORTS ---------- */
|
|
174
|
-
deps.push(...
|
|
239
|
+
deps.push(...extractStaticImports(clean, file));
|
|
240
|
+
|
|
241
|
+
const dyn = extractDynamicImports(clean, file);
|
|
242
|
+
deps.push(...dyn.deps);
|
|
243
|
+
parts.push(...dyn.calls);
|
|
175
244
|
|
|
176
245
|
return {
|
|
177
246
|
code: [...new Set(parts)].join("\n"),
|