@eventra_dev/eventra-cli 0.1.14 → 0.1.16
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/commands/sync.js +1 -1
- package/dist/commands/watch.js +10 -16
- package/dist/engine/engine.js +14 -18
- package/package.json +1 -1
- package/src/commands/sync.ts +1 -3
- package/src/commands/watch.ts +11 -23
- package/src/engine/engine.ts +17 -21
package/dist/commands/sync.js
CHANGED
|
@@ -30,8 +30,8 @@ async function sync() {
|
|
|
30
30
|
try {
|
|
31
31
|
const raw = await promises_1.default.readFile(file, "utf-8");
|
|
32
32
|
const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
|
|
33
|
-
fileCache.push({ file: virtualFile, content });
|
|
34
33
|
engine["ts"].updateFile(virtualFile, content);
|
|
34
|
+
fileCache.push({ file: virtualFile, content });
|
|
35
35
|
}
|
|
36
36
|
catch {
|
|
37
37
|
// ignore
|
package/dist/commands/watch.js
CHANGED
|
@@ -12,6 +12,11 @@ const path_1 = __importDefault(require("path"));
|
|
|
12
12
|
const config_1 = require("../utils/config");
|
|
13
13
|
const engine_1 = require("../engine/engine");
|
|
14
14
|
const processFile_1 = require("../utils/processFile");
|
|
15
|
+
const toVirtual = async (file) => {
|
|
16
|
+
const abs = path_1.default.resolve(file);
|
|
17
|
+
const raw = await promises_1.default.readFile(abs, "utf-8");
|
|
18
|
+
return (0, processFile_1.processFile)(abs, raw);
|
|
19
|
+
};
|
|
15
20
|
async function watch() {
|
|
16
21
|
process.env.EVENTRA_WATCH = "1";
|
|
17
22
|
const config = await (0, config_1.loadConfig)();
|
|
@@ -29,8 +34,8 @@ async function watch() {
|
|
|
29
34
|
const abs = path_1.default.resolve(file);
|
|
30
35
|
const raw = await promises_1.default.readFile(abs, "utf-8");
|
|
31
36
|
const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
|
|
32
|
-
fileCache.push({ file: virtualFile, content });
|
|
33
37
|
engine["ts"].updateFile(virtualFile, content);
|
|
38
|
+
fileCache.push({ file: virtualFile, content });
|
|
34
39
|
}
|
|
35
40
|
catch {
|
|
36
41
|
console.log(chalk_1.default.gray(`skip: ${file}`));
|
|
@@ -52,25 +57,15 @@ async function watch() {
|
|
|
52
57
|
locked = true;
|
|
53
58
|
const batch = [...queued];
|
|
54
59
|
queued.clear();
|
|
55
|
-
const touched = new Set();
|
|
56
60
|
for (const file of batch) {
|
|
57
61
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
|
|
61
|
-
engine["ts"].updateFile(virtualFile, content);
|
|
62
|
-
touched.add(virtualFile);
|
|
62
|
+
const { content, virtualFile } = await toVirtual(file);
|
|
63
|
+
engine.updateFile(virtualFile, content, config);
|
|
63
64
|
}
|
|
64
65
|
catch {
|
|
65
66
|
console.log(chalk_1.default.gray(`skip: ${file}`));
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
for (const file of engine["ts"]["fileNames"]) {
|
|
69
|
-
const content = engine["ts"].getFileContent(file);
|
|
70
|
-
if (!content)
|
|
71
|
-
continue;
|
|
72
|
-
engine.scanFile(file, content, config);
|
|
73
|
-
}
|
|
74
69
|
const next = engine.getAllEvents();
|
|
75
70
|
const added = next.filter(e => !config.events.includes(e));
|
|
76
71
|
const removed = config.events.filter(e => !next.includes(e));
|
|
@@ -84,11 +79,10 @@ async function watch() {
|
|
|
84
79
|
locked = false;
|
|
85
80
|
};
|
|
86
81
|
const schedule = (file) => {
|
|
87
|
-
|
|
88
|
-
queued.add(abs);
|
|
82
|
+
queued.add(path_1.default.resolve(file));
|
|
89
83
|
if (timer)
|
|
90
84
|
clearTimeout(timer);
|
|
91
|
-
timer = setTimeout(run,
|
|
85
|
+
timer = setTimeout(run, 200);
|
|
92
86
|
};
|
|
93
87
|
const watcher = chokidar_1.default.watch(config.sync.include, {
|
|
94
88
|
ignored: config.sync.exclude,
|
package/dist/engine/engine.js
CHANGED
|
@@ -19,9 +19,8 @@ class EventraEngine {
|
|
|
19
19
|
// SCAN FILE
|
|
20
20
|
scanFile(file, content, config) {
|
|
21
21
|
const h = (0, hash_1.hash)(content);
|
|
22
|
-
const isWatch = process.env.EVENTRA_WATCH === "1";
|
|
23
22
|
// skip unchanged
|
|
24
|
-
if (this.fileHash.get(file) === h
|
|
23
|
+
if (this.fileHash.get(file) === h) {
|
|
25
24
|
return (this.fileResults.get(file) ?? {
|
|
26
25
|
events: new Set(),
|
|
27
26
|
detectedFunctionWrappers: new Set(),
|
|
@@ -39,7 +38,6 @@ class EventraEngine {
|
|
|
39
38
|
detectedComponentWrappers: new Map(),
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
|
-
// update dependency graph
|
|
43
41
|
this.graph.update(file, source);
|
|
44
42
|
const res = (0, scanner_1.scanSource)(source, checker, config);
|
|
45
43
|
this.fileResults.set(file, res);
|
|
@@ -47,25 +45,24 @@ class EventraEngine {
|
|
|
47
45
|
}
|
|
48
46
|
// UPDATE FILE (incremental)
|
|
49
47
|
updateFile(file, content, config) {
|
|
48
|
+
// сначала обновляем текущий файл
|
|
50
49
|
const res = this.scanFile(file, content, config);
|
|
51
50
|
const dependents = this.graph.getAllDependentsDeep(file);
|
|
52
51
|
for (const dep of dependents) {
|
|
53
|
-
// skip external files
|
|
54
52
|
if ((0, boundary_1.isExternalFile)(dep))
|
|
55
53
|
continue;
|
|
56
|
-
const source = this.ts.getSourceFile(dep);
|
|
57
|
-
const checker = this.ts.getChecker();
|
|
58
|
-
if (!source || !checker)
|
|
59
|
-
continue;
|
|
60
54
|
const depContent = this.ts.getFileContent(dep);
|
|
61
55
|
if (!depContent)
|
|
62
56
|
continue;
|
|
63
57
|
const h = (0, hash_1.hash)(depContent);
|
|
64
|
-
|
|
65
|
-
// skip unchanged dependents
|
|
66
|
-
if (this.fileHash.get(dep) === h && !isWatch)
|
|
58
|
+
if (this.fileHash.get(dep) === h)
|
|
67
59
|
continue;
|
|
68
60
|
this.fileHash.set(dep, h);
|
|
61
|
+
this.ts.updateFile(dep, depContent);
|
|
62
|
+
const source = this.ts.getSourceFile(dep);
|
|
63
|
+
const checker = this.ts.getChecker();
|
|
64
|
+
if (!source || !checker)
|
|
65
|
+
continue;
|
|
69
66
|
this.graph.update(dep, source);
|
|
70
67
|
const r = (0, scanner_1.scanSource)(source, checker, config);
|
|
71
68
|
this.fileResults.set(dep, r);
|
|
@@ -90,19 +87,18 @@ class EventraEngine {
|
|
|
90
87
|
for (const dep of dependents) {
|
|
91
88
|
if ((0, boundary_1.isExternalFile)(dep))
|
|
92
89
|
continue;
|
|
93
|
-
const source = this.ts.getSourceFile(dep);
|
|
94
|
-
const checker = this.ts.getChecker();
|
|
95
|
-
if (!source || !checker)
|
|
96
|
-
continue;
|
|
97
90
|
const content = this.ts.getFileContent(dep);
|
|
98
91
|
if (!content)
|
|
99
92
|
continue;
|
|
100
93
|
const h = (0, hash_1.hash)(content);
|
|
101
|
-
|
|
102
|
-
// skip unchanged
|
|
103
|
-
if (this.fileHash.get(dep) === h && !isWatch)
|
|
94
|
+
if (this.fileHash.get(dep) === h)
|
|
104
95
|
continue;
|
|
105
96
|
this.fileHash.set(dep, h);
|
|
97
|
+
this.ts.updateFile(dep, content);
|
|
98
|
+
const source = this.ts.getSourceFile(dep);
|
|
99
|
+
const checker = this.ts.getChecker();
|
|
100
|
+
if (!source || !checker)
|
|
101
|
+
continue;
|
|
106
102
|
const r = (0, scanner_1.scanSource)(source, checker, config ?? {
|
|
107
103
|
events: [],
|
|
108
104
|
wrappers: [],
|
package/package.json
CHANGED
package/src/commands/sync.ts
CHANGED
|
@@ -32,10 +32,8 @@ export async function sync() {
|
|
|
32
32
|
try {
|
|
33
33
|
const raw = await fs.readFile(file, "utf-8");
|
|
34
34
|
const { content, virtualFile } = processFile(file, raw);
|
|
35
|
-
|
|
36
|
-
fileCache.push({ file: virtualFile, content });
|
|
37
|
-
|
|
38
35
|
engine["ts"].updateFile(virtualFile, content);
|
|
36
|
+
fileCache.push({ file: virtualFile, content });
|
|
39
37
|
} catch {
|
|
40
38
|
// ignore
|
|
41
39
|
}
|
package/src/commands/watch.ts
CHANGED
|
@@ -8,6 +8,12 @@ import { loadConfig, saveConfig } from "../utils/config";
|
|
|
8
8
|
import { EventraEngine } from "../engine/engine";
|
|
9
9
|
import { processFile } from "../utils/processFile";
|
|
10
10
|
|
|
11
|
+
const toVirtual = async (file: string) => {
|
|
12
|
+
const abs = path.resolve(file);
|
|
13
|
+
const raw = await fs.readFile(abs, "utf-8");
|
|
14
|
+
return processFile(abs, raw);
|
|
15
|
+
};
|
|
16
|
+
|
|
11
17
|
export async function watch() {
|
|
12
18
|
process.env.EVENTRA_WATCH = "1";
|
|
13
19
|
|
|
@@ -29,12 +35,9 @@ export async function watch() {
|
|
|
29
35
|
try {
|
|
30
36
|
const abs = path.resolve(file);
|
|
31
37
|
const raw = await fs.readFile(abs, "utf-8");
|
|
32
|
-
|
|
33
38
|
const { content, virtualFile } = processFile(abs, raw);
|
|
34
|
-
|
|
35
|
-
fileCache.push({ file: virtualFile, content });
|
|
36
|
-
|
|
37
39
|
engine["ts"].updateFile(virtualFile, content);
|
|
40
|
+
fileCache.push({ file: virtualFile, content });
|
|
38
41
|
} catch {
|
|
39
42
|
console.log(chalk.gray(`skip: ${file}`));
|
|
40
43
|
}
|
|
@@ -63,31 +66,17 @@ export async function watch() {
|
|
|
63
66
|
const batch = [...queued];
|
|
64
67
|
queued.clear();
|
|
65
68
|
|
|
66
|
-
const touched = new Set<string>();
|
|
67
|
-
|
|
68
69
|
for (const file of batch) {
|
|
69
70
|
try {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const raw = await fs.readFile(abs, "utf-8");
|
|
73
|
-
const { content, virtualFile } = processFile(abs, raw);
|
|
74
|
-
|
|
75
|
-
engine["ts"].updateFile(virtualFile, content);
|
|
71
|
+
const { content, virtualFile } = await toVirtual(file);
|
|
76
72
|
|
|
77
|
-
|
|
73
|
+
engine.updateFile(virtualFile, content, config);
|
|
78
74
|
|
|
79
75
|
} catch {
|
|
80
76
|
console.log(chalk.gray(`skip: ${file}`));
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
for (const file of engine["ts"]["fileNames"]) {
|
|
85
|
-
const content = engine["ts"].getFileContent(file);
|
|
86
|
-
if (!content) continue;
|
|
87
|
-
|
|
88
|
-
engine.scanFile(file, content, config);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
80
|
const next = engine.getAllEvents();
|
|
92
81
|
|
|
93
82
|
const added = next.filter(e => !config.events.includes(e));
|
|
@@ -109,11 +98,10 @@ export async function watch() {
|
|
|
109
98
|
};
|
|
110
99
|
|
|
111
100
|
const schedule = (file: string) => {
|
|
112
|
-
|
|
113
|
-
queued.add(abs);
|
|
101
|
+
queued.add(path.resolve(file));
|
|
114
102
|
|
|
115
103
|
if (timer) clearTimeout(timer);
|
|
116
|
-
timer = setTimeout(run,
|
|
104
|
+
timer = setTimeout(run, 200);
|
|
117
105
|
};
|
|
118
106
|
|
|
119
107
|
const watcher = chokidar.watch(config.sync.include, {
|
package/src/engine/engine.ts
CHANGED
|
@@ -26,10 +26,9 @@ export class EventraEngine {
|
|
|
26
26
|
config: EventraConfig
|
|
27
27
|
): ScanResult {
|
|
28
28
|
const h = hash(content);
|
|
29
|
-
const isWatch = process.env.EVENTRA_WATCH === "1";
|
|
30
29
|
|
|
31
30
|
// skip unchanged
|
|
32
|
-
if (this.fileHash.get(file) === h
|
|
31
|
+
if (this.fileHash.get(file) === h) {
|
|
33
32
|
return (
|
|
34
33
|
this.fileResults.get(file) ?? {
|
|
35
34
|
events: new Set(),
|
|
@@ -53,11 +52,9 @@ export class EventraEngine {
|
|
|
53
52
|
};
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
// update dependency graph
|
|
57
55
|
this.graph.update(file, source);
|
|
58
56
|
|
|
59
57
|
const res = scanSource(source, checker, config);
|
|
60
|
-
|
|
61
58
|
this.fileResults.set(file, res);
|
|
62
59
|
|
|
63
60
|
return res;
|
|
@@ -69,29 +66,28 @@ export class EventraEngine {
|
|
|
69
66
|
content: string,
|
|
70
67
|
config: EventraConfig
|
|
71
68
|
) {
|
|
69
|
+
// сначала обновляем текущий файл
|
|
72
70
|
const res = this.scanFile(file, content, config);
|
|
73
71
|
|
|
74
72
|
const dependents = this.graph.getAllDependentsDeep(file);
|
|
75
73
|
|
|
76
74
|
for (const dep of dependents) {
|
|
77
|
-
// skip external files
|
|
78
75
|
if (isExternalFile(dep)) continue;
|
|
79
76
|
|
|
80
|
-
const source = this.ts.getSourceFile(dep);
|
|
81
|
-
const checker = this.ts.getChecker();
|
|
82
|
-
|
|
83
|
-
if (!source || !checker) continue;
|
|
84
|
-
|
|
85
77
|
const depContent = this.ts.getFileContent(dep);
|
|
86
78
|
if (!depContent) continue;
|
|
87
79
|
|
|
88
80
|
const h = hash(depContent);
|
|
89
|
-
const isWatch = process.env.EVENTRA_WATCH === "1";
|
|
90
81
|
|
|
91
|
-
|
|
92
|
-
if (this.fileHash.get(dep) === h && !isWatch) continue;
|
|
82
|
+
if (this.fileHash.get(dep) === h) continue;
|
|
93
83
|
|
|
94
84
|
this.fileHash.set(dep, h);
|
|
85
|
+
this.ts.updateFile(dep, depContent);
|
|
86
|
+
|
|
87
|
+
const source = this.ts.getSourceFile(dep);
|
|
88
|
+
const checker = this.ts.getChecker();
|
|
89
|
+
|
|
90
|
+
if (!source || !checker) continue;
|
|
95
91
|
|
|
96
92
|
this.graph.update(dep, source);
|
|
97
93
|
|
|
@@ -119,26 +115,26 @@ export class EventraEngine {
|
|
|
119
115
|
this.fileResults.delete(file);
|
|
120
116
|
this.fileHash.delete(file);
|
|
121
117
|
this.graph.remove(file);
|
|
118
|
+
|
|
122
119
|
const dependents = this.graph.getAllDependentsDeep(file);
|
|
123
120
|
|
|
124
121
|
for (const dep of dependents) {
|
|
125
122
|
if (isExternalFile(dep)) continue;
|
|
126
123
|
|
|
127
|
-
const source = this.ts.getSourceFile(dep);
|
|
128
|
-
const checker = this.ts.getChecker();
|
|
129
|
-
|
|
130
|
-
if (!source || !checker) continue;
|
|
131
|
-
|
|
132
124
|
const content = this.ts.getFileContent(dep);
|
|
133
125
|
if (!content) continue;
|
|
134
126
|
|
|
135
127
|
const h = hash(content);
|
|
136
|
-
const isWatch = process.env.EVENTRA_WATCH === "1";
|
|
137
128
|
|
|
138
|
-
|
|
139
|
-
if (this.fileHash.get(dep) === h && !isWatch) continue;
|
|
129
|
+
if (this.fileHash.get(dep) === h) continue;
|
|
140
130
|
|
|
141
131
|
this.fileHash.set(dep, h);
|
|
132
|
+
this.ts.updateFile(dep, content);
|
|
133
|
+
|
|
134
|
+
const source = this.ts.getSourceFile(dep);
|
|
135
|
+
const checker = this.ts.getChecker();
|
|
136
|
+
|
|
137
|
+
if (!source || !checker) continue;
|
|
142
138
|
|
|
143
139
|
const r = scanSource(
|
|
144
140
|
source,
|