@eventra_dev/eventra-cli 0.1.12 → 0.1.14

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.
@@ -13,6 +13,7 @@ const config_1 = require("../utils/config");
13
13
  const engine_1 = require("../engine/engine");
14
14
  const processFile_1 = require("../utils/processFile");
15
15
  async function watch() {
16
+ process.env.EVENTRA_WATCH = "1";
16
17
  const config = await (0, config_1.loadConfig)();
17
18
  if (!config)
18
19
  return;
@@ -42,27 +43,34 @@ async function watch() {
42
43
  config.events = engine.getAllEvents().sort();
43
44
  await (0, config_1.saveConfig)(config);
44
45
  console.log(chalk_1.default.gray(`Initial: ${config.events.length} events\n`));
45
- // WATCH STATE
46
46
  let locked = false;
47
47
  let queued = new Set();
48
48
  let timer = null;
49
- // RUN BATCH
50
49
  const run = async () => {
51
50
  if (locked)
52
51
  return;
53
52
  locked = true;
54
53
  const batch = [...queued];
55
54
  queued.clear();
55
+ const touched = new Set();
56
56
  for (const file of batch) {
57
57
  try {
58
- const raw = await promises_1.default.readFile(file, "utf-8");
59
- const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
60
- engine.updateFile(virtualFile, content, config);
58
+ const abs = path_1.default.resolve(file);
59
+ const raw = await promises_1.default.readFile(abs, "utf-8");
60
+ const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
61
+ engine["ts"].updateFile(virtualFile, content);
62
+ touched.add(virtualFile);
61
63
  }
62
64
  catch {
63
65
  console.log(chalk_1.default.gray(`skip: ${file}`));
64
66
  }
65
67
  }
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
+ }
66
74
  const next = engine.getAllEvents();
67
75
  const added = next.filter(e => !config.events.includes(e));
68
76
  const removed = config.events.filter(e => !next.includes(e));
@@ -75,7 +83,6 @@ async function watch() {
75
83
  }
76
84
  locked = false;
77
85
  };
78
- // SCHEDULER
79
86
  const schedule = (file) => {
80
87
  const abs = path_1.default.resolve(file);
81
88
  queued.add(abs);
@@ -83,7 +90,6 @@ async function watch() {
83
90
  clearTimeout(timer);
84
91
  timer = setTimeout(run, 100);
85
92
  };
86
- // WATCHER
87
93
  const watcher = chokidar_1.default.watch(config.sync.include, {
88
94
  ignored: config.sync.exclude,
89
95
  ignoreInitial: true,
@@ -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.12",
3
+ "version": "0.1.14",
4
4
  "description": "Eventra CLI",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -9,6 +9,8 @@ import { EventraEngine } from "../engine/engine";
9
9
  import { processFile } from "../utils/processFile";
10
10
 
11
11
  export async function watch() {
12
+ process.env.EVENTRA_WATCH = "1";
13
+
12
14
  const config = await loadConfig();
13
15
  if (!config) return;
14
16
 
@@ -50,12 +52,10 @@ export async function watch() {
50
52
  chalk.gray(`Initial: ${config.events.length} events\n`)
51
53
  );
52
54
 
53
- // WATCH STATE
54
55
  let locked = false;
55
56
  let queued = new Set<string>();
56
57
  let timer: NodeJS.Timeout | null = null;
57
58
 
58
- // RUN BATCH
59
59
  const run = async () => {
60
60
  if (locked) return;
61
61
  locked = true;
@@ -63,18 +63,31 @@ export async function watch() {
63
63
  const batch = [...queued];
64
64
  queued.clear();
65
65
 
66
+ const touched = new Set<string>();
67
+
66
68
  for (const file of batch) {
67
69
  try {
68
- const raw = await fs.readFile(file, "utf-8");
69
- const { content, virtualFile } = processFile(file, raw);
70
+ const abs = path.resolve(file);
71
+
72
+ const raw = await fs.readFile(abs, "utf-8");
73
+ const { content, virtualFile } = processFile(abs, raw);
74
+
75
+ engine["ts"].updateFile(virtualFile, content);
70
76
 
71
- engine.updateFile(virtualFile, content, config);
77
+ touched.add(virtualFile);
72
78
 
73
79
  } catch {
74
80
  console.log(chalk.gray(`skip: ${file}`));
75
81
  }
76
82
  }
77
83
 
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
+
78
91
  const next = engine.getAllEvents();
79
92
 
80
93
  const added = next.filter(e => !config.events.includes(e));
@@ -95,17 +108,14 @@ export async function watch() {
95
108
  locked = false;
96
109
  };
97
110
 
98
- // SCHEDULER
99
111
  const schedule = (file: string) => {
100
112
  const abs = path.resolve(file);
101
-
102
113
  queued.add(abs);
103
114
 
104
115
  if (timer) clearTimeout(timer);
105
116
  timer = setTimeout(run, 100);
106
117
  };
107
118
 
108
- // WATCHER
109
119
  const watcher = chokidar.watch(config.sync.include, {
110
120
  ignored: config.sync.exclude,
111
121
  ignoreInitial: true,
@@ -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