@eventra_dev/eventra-cli 0.1.25 → 0.1.27

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,19 +1,10 @@
1
- import path from "path";
2
1
  import { parseUniversal } from "./universal";
3
2
 
4
3
  export function processFile(file: string, content: string) {
5
4
  const { code, deps } = parseUniversal(content, file);
6
5
 
7
- const ext = path.extname(file);
8
-
9
- const virtualFile =
10
- /\.(vue|svelte|astro|html)$/i.test(file)
11
- ? file.replace(ext, "") + ".tsx"
12
- : file;
13
-
14
6
  return {
15
7
  content: code || "",
16
- virtualFile,
17
8
  deps: [...new Set(deps.filter(Boolean))],
18
9
  };
19
10
  }
@@ -12,7 +12,7 @@ function stripComments(input: string): string {
12
12
  }
13
13
 
14
14
  /**
15
- * Extract JS expressions safely
15
+ * Extract JS expressions
16
16
  */
17
17
  function extractJS(input: string): string[] {
18
18
  const result: string[] = [];
@@ -26,7 +26,6 @@ function extractJS(input: string): string[] {
26
26
  while (i < len) {
27
27
  const ch = input[i];
28
28
 
29
- // STRING
30
29
  if (inString) {
31
30
  if (escape) escape = false;
32
31
  else if (ch === "\\") escape = true;
@@ -41,47 +40,20 @@ function extractJS(input: string): string[] {
41
40
  continue;
42
41
  }
43
42
 
44
- // { ... }
45
43
  if (ch === "{") {
46
44
  let depth = 1;
47
45
  let j = i + 1;
48
46
 
49
- let innerStr: '"' | "'" | "`" | null = null;
50
- let innerEsc = false;
51
-
52
47
  while (j < len && depth > 0) {
53
- const c = input[j];
54
-
55
- if (innerStr) {
56
- if (innerEsc) innerEsc = false;
57
- else if (c === "\\") innerEsc = true;
58
- else if (c === innerStr) innerStr = null;
59
- j++;
60
- continue;
61
- }
62
-
63
- if (c === '"' || c === "'" || c === "`") {
64
- innerStr = c;
65
- j++;
66
- continue;
67
- }
68
-
69
- if (c === "{") depth++;
70
- else if (c === "}") depth--;
71
-
48
+ if (input[j] === "{") depth++;
49
+ else if (input[j] === "}") depth--;
72
50
  j++;
73
51
  }
74
52
 
75
53
  if (depth === 0) {
76
54
  const expr = input.slice(i + 1, j - 1).trim();
77
55
 
78
- if (
79
- expr &&
80
- (expr.includes("(") ||
81
- expr.includes("=") ||
82
- expr.includes(".") ||
83
- expr.includes("track"))
84
- ) {
56
+ if (expr && /[a-zA-Z0-9_$]\s*\(/.test(expr)) {
85
57
  result.push(expr);
86
58
  }
87
59
 
@@ -90,64 +62,14 @@ function extractJS(input: string): string[] {
90
62
  }
91
63
  }
92
64
 
93
- // attr="..."
94
- if (ch === "=" && (input[i + 1] === '"' || input[i + 1] === "'")) {
95
- const quote = input[i + 1];
96
- let j = i + 2;
97
- let val = "";
98
-
99
- while (j < len) {
100
- const c = input[j];
101
-
102
- if (c === "\\" && input[j + 1]) {
103
- val += c + input[j + 1];
104
- j += 2;
105
- continue;
106
- }
107
-
108
- if (c === quote) break;
109
-
110
- val += c;
111
- j++;
112
- }
113
-
114
- if (
115
- val.trim() &&
116
- (val.includes("(") ||
117
- val.includes("=>") ||
118
- val.includes("track"))
119
- ) {
120
- result.push(val.trim());
121
- }
122
-
123
- i = j + 1;
124
- continue;
125
- }
126
-
127
65
  i++;
128
66
  }
129
67
 
130
- // Vue / Svelte / JSX handlers
131
- const extra = [
132
- /@[\w-]+\s*=\s*["']([\s\S]*?)["']/g,
133
- /v-on:[\w-]+\s*=\s*["']([\s\S]*?)["']/g,
134
- /on:[\w-]+\s*=\s*{([\s\S]*?)}/g,
135
- /on\w+\s*=\s*{([\s\S]*?)}/g,
136
- ];
137
-
138
- for (const r of extra) {
139
- const m = input.matchAll(r);
140
- for (const x of m) {
141
- const v = x[1]?.trim();
142
- if (v) result.push(v);
143
- }
144
- }
145
-
146
68
  return result;
147
69
  }
148
70
 
149
71
  /**
150
- * Extract loose JS but less noisy
72
+ * Loose JS extractor
151
73
  */
152
74
  function extractLooseJS(input: string): string[] {
153
75
  const result: string[] = [];
@@ -160,14 +82,7 @@ function extractLooseJS(input: string): string[] {
160
82
  if (!l) continue;
161
83
  if (l.startsWith("<")) continue;
162
84
 
163
- // strict filter
164
- if (
165
- l.includes("track") ||
166
- l.includes(".track(") ||
167
- l.includes("=>") ||
168
- l.startsWith("function") ||
169
- l.includes("(")
170
- ) {
85
+ if (/[a-zA-Z0-9_$]\s*\(/.test(l)) {
171
86
  result.push(l);
172
87
  }
173
88
  }
@@ -176,7 +91,14 @@ function extractLooseJS(input: string): string[] {
176
91
  }
177
92
 
178
93
  /**
179
- * Universal parser
94
+ * UNIVERSAL PARSER
95
+ * Support:
96
+ * - React / JSX
97
+ * - Vue
98
+ * - Svelte
99
+ * - Astro
100
+ * - HTML + JS
101
+ * - SSR
180
102
  */
181
103
  export function parseUniversal(
182
104
  content: string,
@@ -187,9 +109,11 @@ export function parseUniversal(
187
109
 
188
110
  const clean = stripComments(content);
189
111
 
190
- // Astro frontmatter
112
+ // ASTRO FRONTMATTER
191
113
  const fm = clean.match(/^---([\s\S]*?)---/);
192
- if (fm?.[1]) parts.push(fm[1]);
114
+ if (fm?.[1]) {
115
+ parts.push(fm[1]);
116
+ }
193
117
 
194
118
  // <script src="">
195
119
  const scriptSrc = clean.matchAll(
@@ -206,7 +130,7 @@ export function parseUniversal(
206
130
  deps.push(resolved);
207
131
  }
208
132
 
209
- // inline <script>
133
+ // INLINE <script>
210
134
  const scripts = clean.matchAll(
211
135
  /<script\b([^>]*)>([\s\S]*?)<\/script>/g
212
136
  );
@@ -214,7 +138,7 @@ export function parseUniversal(
214
138
  for (const m of scripts) {
215
139
  const attrs = m[1];
216
140
 
217
- // skip JSON / data
141
+ // skip JSON
218
142
  if (/type=["']application\/json/.test(attrs)) continue;
219
143
 
220
144
  if (m[2].trim()) {
@@ -222,24 +146,24 @@ export function parseUniversal(
222
146
  }
223
147
  }
224
148
 
225
- // remove scripts
149
+ // REMOVE SCRIPTS → TEMPLATE PART
226
150
  const noScripts = clean.replace(
227
151
  /<script[\s\S]*?<\/script>/g,
228
152
  ""
229
153
  );
230
154
 
231
- // loose JS
232
- const loose = extractLooseJS(noScripts);
233
- parts.push(...loose);
155
+ // LOOSE JS
156
+ parts.push(...extractLooseJS(noScripts));
234
157
 
235
- // expressions
158
+ // EXPRESSIONS
236
159
  const extracted = extractJS(clean);
237
160
  for (const e of extracted) {
238
161
  parts.push(e + ";");
239
162
  }
240
163
 
164
+ // RESULT
241
165
  return {
242
166
  code: [...new Set(parts)].join("\n"),
243
- deps,
167
+ deps: [...new Set(deps.filter(Boolean))],
244
168
  };
245
169
  }