@eventra_dev/eventra-cli 0.1.21 → 0.1.22

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.
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.processFile = processFile;
7
7
  const path_1 = __importDefault(require("path"));
8
- const universal_1 = require("./parsers/universal");
8
+ const universal_1 = require("./universal");
9
9
  function processFile(file, content) {
10
10
  const { code, deps } = (0, universal_1.parseUniversal)(content, file);
11
11
  const ext = path_1.default.extname(file);
@@ -5,6 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.parseUniversal = parseUniversal;
7
7
  const path_1 = __importDefault(require("path"));
8
+ /**
9
+ * exact JS:
10
+ * - {...}
11
+ * - attr="..."
12
+ * - Vue / Svelte handlers
13
+ */
8
14
  function extractJS(input) {
9
15
  const result = [];
10
16
  let i = 0;
@@ -29,7 +35,7 @@ function extractJS(input) {
29
35
  i++;
30
36
  continue;
31
37
  }
32
- // { ... }
38
+ // { ... }
33
39
  if (ch === "{") {
34
40
  let depth = 1;
35
41
  let j = i + 1;
@@ -66,7 +72,7 @@ function extractJS(input) {
66
72
  continue;
67
73
  }
68
74
  }
69
- // attr="..."
75
+ // attr="..."
70
76
  if (ch === "=" && (input[i + 1] === '"' || input[i + 1] === "'")) {
71
77
  const quote = input[i + 1];
72
78
  let j = i + 2;
@@ -90,7 +96,7 @@ function extractJS(input) {
90
96
  }
91
97
  i++;
92
98
  }
93
- // Vue / Svelte handlers
99
+ // Vue / Svelte / JSX handlers
94
100
  const extra = [
95
101
  /@[\w-]+\s*=\s*["']([\s\S]*?)["']/g,
96
102
  /v-on:[\w-]+\s*=\s*["']([\s\S]*?)["']/g,
@@ -107,17 +113,37 @@ function extractJS(input) {
107
113
  }
108
114
  return result;
109
115
  }
116
+ function extractLooseJS(input) {
117
+ const result = [];
118
+ const lines = input.split("\n");
119
+ for (const line of lines) {
120
+ const l = line.trim();
121
+ if (!l)
122
+ continue;
123
+ if (l.startsWith("<"))
124
+ continue;
125
+ if (l.includes("(") ||
126
+ l.includes("=") ||
127
+ l.includes("=>") ||
128
+ l.includes("function") ||
129
+ l.includes("track")) {
130
+ result.push(l);
131
+ }
132
+ }
133
+ return result;
134
+ }
110
135
  /**
136
+ * Universal:
111
137
  * - Astro
112
138
  * - Vue
113
139
  * - Svelte
114
- * - HTML + JS
115
- * - SSR / mixed files
140
+ * - React / JSX
141
+ * - Node / backend
116
142
  */
117
143
  function parseUniversal(content, file) {
118
144
  const parts = [];
119
145
  const deps = [];
120
- // Astro frontmatter
146
+ // Astro frontmatter ---
121
147
  const fm = content.match(/^---([\s\S]*?)---/);
122
148
  if (fm?.[1])
123
149
  parts.push(fm[1]);
@@ -136,13 +162,11 @@ function parseUniversal(content, file) {
136
162
  if (m[1].trim())
137
163
  parts.push(m[1]);
138
164
  }
139
- // JS <script>
140
165
  const noScripts = content.replace(/<script[\s\S]*?<\/script>/g, "");
141
- const noHtml = noScripts
142
- .replace(/<[^>]+>/g, "\n")
143
- .replace(/\n+/g, "\n");
144
- if (noHtml.trim())
145
- parts.push(noHtml);
166
+ const loose = extractLooseJS(noScripts);
167
+ for (const l of loose) {
168
+ parts.push(l);
169
+ }
146
170
  // expressions
147
171
  const extracted = extractJS(content);
148
172
  for (const e of extracted) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/eventra-cli",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "Eventra CLI",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { parseUniversal } from "./parsers/universal";
2
+ import { parseUniversal } from "./universal";
3
3
 
4
4
  export function processFile(file: string, content: string) {
5
5
  const { code, deps } = parseUniversal(content, file);
@@ -1,6 +1,12 @@
1
1
  import path from "path";
2
- import { ParseResult } from "../../types";
2
+ import { ParseResult } from "../types";
3
3
 
4
+ /**
5
+ * exact JS:
6
+ * - {...}
7
+ * - attr="..."
8
+ * - Vue / Svelte handlers
9
+ */
4
10
  function extractJS(input: string): string[] {
5
11
  const result: string[] = [];
6
12
 
@@ -29,7 +35,7 @@ function extractJS(input: string): string[] {
29
35
  continue;
30
36
  }
31
37
 
32
- // { ... }
38
+ // { ... }
33
39
  if (ch === "{") {
34
40
  let depth = 1;
35
41
  let j = i + 1;
@@ -68,7 +74,7 @@ function extractJS(input: string): string[] {
68
74
  }
69
75
  }
70
76
 
71
- // attr="..."
77
+ // attr="..."
72
78
  if (ch === "=" && (input[i + 1] === '"' || input[i + 1] === "'")) {
73
79
  const quote = input[i + 1];
74
80
  let j = i + 2;
@@ -98,7 +104,7 @@ function extractJS(input: string): string[] {
98
104
  i++;
99
105
  }
100
106
 
101
- // Vue / Svelte handlers
107
+ // Vue / Svelte / JSX handlers
102
108
  const extra = [
103
109
  /@[\w-]+\s*=\s*["']([\s\S]*?)["']/g,
104
110
  /v-on:[\w-]+\s*=\s*["']([\s\S]*?)["']/g,
@@ -117,12 +123,38 @@ function extractJS(input: string): string[] {
117
123
  return result;
118
124
  }
119
125
 
126
+ function extractLooseJS(input: string): string[] {
127
+ const result: string[] = [];
128
+
129
+ const lines = input.split("\n");
130
+
131
+ for (const line of lines) {
132
+ const l = line.trim();
133
+
134
+ if (!l) continue;
135
+ if (l.startsWith("<")) continue;
136
+
137
+ if (
138
+ l.includes("(") ||
139
+ l.includes("=") ||
140
+ l.includes("=>") ||
141
+ l.includes("function") ||
142
+ l.includes("track")
143
+ ) {
144
+ result.push(l);
145
+ }
146
+ }
147
+
148
+ return result;
149
+ }
150
+
120
151
  /**
152
+ * Universal:
121
153
  * - Astro
122
154
  * - Vue
123
155
  * - Svelte
124
- * - HTML + JS
125
- * - SSR / mixed files
156
+ * - React / JSX
157
+ * - Node / backend
126
158
  */
127
159
 
128
160
  export function parseUniversal(
@@ -132,7 +164,7 @@ export function parseUniversal(
132
164
  const parts: string[] = [];
133
165
  const deps: string[] = [];
134
166
 
135
- // Astro frontmatter
167
+ // Astro frontmatter ---
136
168
  const fm = content.match(/^---([\s\S]*?)---/);
137
169
  if (fm?.[1]) parts.push(fm[1]);
138
170
 
@@ -160,17 +192,16 @@ export function parseUniversal(
160
192
  if (m[1].trim()) parts.push(m[1]);
161
193
  }
162
194
 
163
- // JS <script>
164
195
  const noScripts = content.replace(
165
196
  /<script[\s\S]*?<\/script>/g,
166
197
  ""
167
198
  );
168
199
 
169
- const noHtml = noScripts
170
- .replace(/<[^>]+>/g, "\n")
171
- .replace(/\n+/g, "\n");
200
+ const loose = extractLooseJS(noScripts);
172
201
 
173
- if (noHtml.trim()) parts.push(noHtml);
202
+ for (const l of loose) {
203
+ parts.push(l);
204
+ }
174
205
 
175
206
  // expressions
176
207
  const extracted = extractJS(content);
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectParser = detectParser;
4
- const universal_1 = require("./universal");
5
- function detectParser() {
6
- return universal_1.parseUniversal;
7
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveImport = resolveImport;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- function resolveImport(from, src) {
10
- if (!src.startsWith("."))
11
- return null;
12
- const base = path_1.default.resolve(path_1.default.dirname(from), src);
13
- const exts = [".ts", ".tsx", ".js", ".jsx"];
14
- for (const ext of exts) {
15
- if (fs_1.default.existsSync(base + ext))
16
- return base + ext;
17
- }
18
- if (fs_1.default.existsSync(base))
19
- return base;
20
- return null;
21
- }
@@ -1,6 +0,0 @@
1
- import { Parser } from "../../types";
2
- import { parseUniversal } from "./universal";
3
-
4
- export function detectParser(): Parser {
5
- return parseUniversal;
6
- }
@@ -1,18 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export function resolveImport(from: string, src: string): string | null {
5
- if (!src.startsWith(".")) return null;
6
-
7
- const base = path.resolve(path.dirname(from), src);
8
-
9
- const exts = [".ts", ".tsx", ".js", ".jsx"];
10
-
11
- for (const ext of exts) {
12
- if (fs.existsSync(base + ext)) return base + ext;
13
- }
14
-
15
- if (fs.existsSync(base)) return base;
16
-
17
- return null;
18
- }