@eventra_dev/eventra-cli 0.1.11 → 0.1.13

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.
@@ -8,10 +8,12 @@ const chokidar_1 = __importDefault(require("chokidar"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const promises_1 = __importDefault(require("fs/promises"));
10
10
  const fast_glob_1 = __importDefault(require("fast-glob"));
11
+ const path_1 = __importDefault(require("path"));
11
12
  const config_1 = require("../utils/config");
12
13
  const engine_1 = require("../engine/engine");
13
14
  const processFile_1 = require("../utils/processFile");
14
15
  async function watch() {
16
+ process.env.EVENTRA_WATCH = "1";
15
17
  const config = await (0, config_1.loadConfig)();
16
18
  if (!config)
17
19
  return;
@@ -20,16 +22,24 @@ async function watch() {
20
22
  ignore: config.sync.exclude,
21
23
  });
22
24
  const engine = new engine_1.EventraEngine(process.cwd());
25
+ const fileCache = [];
26
+ // PRELOAD TS
23
27
  for (const file of files) {
24
28
  try {
25
- const raw = await promises_1.default.readFile(file, "utf-8");
26
- const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
27
- engine.scanFile(virtualFile, content, config);
29
+ const abs = path_1.default.resolve(file);
30
+ const raw = await promises_1.default.readFile(abs, "utf-8");
31
+ const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
32
+ fileCache.push({ file: virtualFile, content });
33
+ engine["ts"].updateFile(virtualFile, content);
28
34
  }
29
35
  catch {
30
36
  console.log(chalk_1.default.gray(`skip: ${file}`));
31
37
  }
32
38
  }
39
+ // INITIAL SCAN
40
+ for (const { file, content } of fileCache) {
41
+ engine.scanFile(file, content, config);
42
+ }
33
43
  config.events = engine.getAllEvents().sort();
34
44
  await (0, config_1.saveConfig)(config);
35
45
  console.log(chalk_1.default.gray(`Initial: ${config.events.length} events\n`));
@@ -44,8 +54,10 @@ async function watch() {
44
54
  queued.clear();
45
55
  for (const file of batch) {
46
56
  try {
47
- const raw = await promises_1.default.readFile(file, "utf-8");
48
- const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
57
+ const abs = path_1.default.resolve(file);
58
+ const raw = await promises_1.default.readFile(abs, "utf-8");
59
+ const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
60
+ engine["ts"].updateFile(virtualFile, content);
49
61
  engine.updateFile(virtualFile, content, config);
50
62
  }
51
63
  catch {
@@ -65,7 +77,8 @@ async function watch() {
65
77
  locked = false;
66
78
  };
67
79
  const schedule = (file) => {
68
- queued.add(file);
80
+ const abs = path_1.default.resolve(file);
81
+ queued.add(abs);
69
82
  if (timer)
70
83
  clearTimeout(timer);
71
84
  timer = setTimeout(run, 100);
@@ -78,12 +91,14 @@ async function watch() {
78
91
  .on("add", schedule)
79
92
  .on("change", schedule)
80
93
  .on("unlink", async (file) => {
94
+ const abs = path_1.default.resolve(file);
81
95
  console.log(chalk_1.default.gray(`remove: ${file}`));
82
- const { virtualFile } = (0, processFile_1.processFile)(file, "");
83
- engine.removeFile(virtualFile);
96
+ const { virtualFile } = (0, processFile_1.processFile)(abs, "");
97
+ engine.removeFile(virtualFile, config);
84
98
  const next = engine.getAllEvents();
85
99
  config.events = next.sort();
86
100
  await (0, config_1.saveConfig)(config);
101
+ console.log(chalk_1.default.gray(`Total: ${config.events.length} events\n`));
87
102
  });
88
103
  process.on("SIGINT", async () => {
89
104
  console.log(chalk_1.default.yellow("\nStopping watcher..."));
@@ -19,8 +19,9 @@ 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";
22
23
  // skip unchanged
23
- if (this.fileHash.get(file) === h) {
24
+ if (this.fileHash.get(file) === h && !isWatch) {
24
25
  return (this.fileResults.get(file) ?? {
25
26
  events: new Set(),
26
27
  detectedFunctionWrappers: new Set(),
@@ -60,8 +61,9 @@ class EventraEngine {
60
61
  if (!depContent)
61
62
  continue;
62
63
  const h = (0, hash_1.hash)(depContent);
64
+ const isWatch = process.env.EVENTRA_WATCH === "1";
63
65
  // skip unchanged dependents
64
- if (this.fileHash.get(dep) === h)
66
+ if (this.fileHash.get(dep) === h && !isWatch)
65
67
  continue;
66
68
  this.fileHash.set(dep, h);
67
69
  this.graph.update(dep, source);
@@ -96,8 +98,9 @@ class EventraEngine {
96
98
  if (!content)
97
99
  continue;
98
100
  const h = (0, hash_1.hash)(content);
101
+ const isWatch = process.env.EVENTRA_WATCH === "1";
99
102
  // skip unchanged
100
- if (this.fileHash.get(dep) === h)
103
+ if (this.fileHash.get(dep) === h && !isWatch)
101
104
  continue;
102
105
  this.fileHash.set(dep, h);
103
106
  const r = (0, scanner_1.scanSource)(source, checker, config ?? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/eventra-cli",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Eventra CLI",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -2,12 +2,15 @@ import chokidar from "chokidar";
2
2
  import chalk from "chalk";
3
3
  import fs from "fs/promises";
4
4
  import fg from "fast-glob";
5
+ import path from "path";
5
6
 
6
7
  import { loadConfig, saveConfig } from "../utils/config";
7
8
  import { EventraEngine } from "../engine/engine";
8
9
  import { processFile } from "../utils/processFile";
9
10
 
10
11
  export async function watch() {
12
+ process.env.EVENTRA_WATCH = "1";
13
+
11
14
  const config = await loadConfig();
12
15
  if (!config) return;
13
16
 
@@ -19,19 +22,29 @@ export async function watch() {
19
22
 
20
23
  const engine = new EventraEngine(process.cwd());
21
24
 
25
+ const fileCache: { file: string; content: string }[] = [];
26
+
27
+ // PRELOAD TS
22
28
  for (const file of files) {
23
29
  try {
24
- const raw = await fs.readFile(file, "utf-8");
30
+ const abs = path.resolve(file);
31
+ const raw = await fs.readFile(abs, "utf-8");
25
32
 
26
- const { content, virtualFile } = processFile(file, raw);
33
+ const { content, virtualFile } = processFile(abs, raw);
27
34
 
28
- engine.scanFile(virtualFile, content, config);
35
+ fileCache.push({ file: virtualFile, content });
29
36
 
37
+ engine["ts"].updateFile(virtualFile, content);
30
38
  } catch {
31
39
  console.log(chalk.gray(`skip: ${file}`));
32
40
  }
33
41
  }
34
42
 
43
+ // INITIAL SCAN
44
+ for (const { file, content } of fileCache) {
45
+ engine.scanFile(file, content, config);
46
+ }
47
+
35
48
  config.events = engine.getAllEvents().sort();
36
49
  await saveConfig(config);
37
50
 
@@ -52,10 +65,13 @@ export async function watch() {
52
65
 
53
66
  for (const file of batch) {
54
67
  try {
55
- const raw = await fs.readFile(file, "utf-8");
68
+ const abs = path.resolve(file);
69
+
70
+ const raw = await fs.readFile(abs, "utf-8");
56
71
 
57
- const { content, virtualFile } = processFile(file, raw);
72
+ const { content, virtualFile } = processFile(abs, raw);
58
73
 
74
+ engine["ts"].updateFile(virtualFile, content);
59
75
  engine.updateFile(virtualFile, content, config);
60
76
 
61
77
  } catch {
@@ -84,10 +100,10 @@ export async function watch() {
84
100
  };
85
101
 
86
102
  const schedule = (file: string) => {
87
- queued.add(file);
103
+ const abs = path.resolve(file);
104
+ queued.add(abs);
88
105
 
89
106
  if (timer) clearTimeout(timer);
90
-
91
107
  timer = setTimeout(run, 100);
92
108
  };
93
109
 
@@ -100,16 +116,22 @@ export async function watch() {
100
116
  .on("add", schedule)
101
117
  .on("change", schedule)
102
118
  .on("unlink", async (file) => {
119
+ const abs = path.resolve(file);
120
+
103
121
  console.log(chalk.gray(`remove: ${file}`));
104
122
 
105
- const { virtualFile } = processFile(file, "");
123
+ const { virtualFile } = processFile(abs, "");
106
124
 
107
- engine.removeFile(virtualFile);
125
+ engine.removeFile(virtualFile, config);
108
126
 
109
127
  const next = engine.getAllEvents();
110
128
 
111
129
  config.events = next.sort();
112
130
  await saveConfig(config);
131
+
132
+ console.log(
133
+ chalk.gray(`Total: ${config.events.length} events\n`)
134
+ );
113
135
  });
114
136
 
115
137
  process.on("SIGINT", async () => {
@@ -26,9 +26,10 @@ export class EventraEngine {
26
26
  config: EventraConfig
27
27
  ): ScanResult {
28
28
  const h = hash(content);
29
+ const isWatch = process.env.EVENTRA_WATCH === "1";
29
30
 
30
31
  // skip unchanged
31
- if (this.fileHash.get(file) === h) {
32
+ if (this.fileHash.get(file) === h && !isWatch) {
32
33
  return (
33
34
  this.fileResults.get(file) ?? {
34
35
  events: new Set(),
@@ -85,9 +86,10 @@ export class EventraEngine {
85
86
  if (!depContent) continue;
86
87
 
87
88
  const h = hash(depContent);
89
+ const isWatch = process.env.EVENTRA_WATCH === "1";
88
90
 
89
91
  // skip unchanged dependents
90
- if (this.fileHash.get(dep) === h) continue;
92
+ if (this.fileHash.get(dep) === h && !isWatch) continue;
91
93
 
92
94
  this.fileHash.set(dep, h);
93
95
 
@@ -131,9 +133,10 @@ export class EventraEngine {
131
133
  if (!content) continue;
132
134
 
133
135
  const h = hash(content);
136
+ const isWatch = process.env.EVENTRA_WATCH === "1";
134
137
 
135
138
  // skip unchanged
136
- if (this.fileHash.get(dep) === h) continue;
139
+ if (this.fileHash.get(dep) === h && !isWatch) continue;
137
140
 
138
141
  this.fileHash.set(dep, h);
139
142