baseguard 1.0.3 → 1.0.5

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.
Files changed (169) hide show
  1. package/.baseguardrc.example.json +63 -63
  2. package/.eslintrc.json +24 -24
  3. package/.prettierrc +7 -7
  4. package/CHANGELOG.md +195 -195
  5. package/DEPLOYMENT.md +624 -624
  6. package/DEPLOYMENT_CHECKLIST.md +239 -239
  7. package/DEPLOYMENT_SUMMARY_v1.0.2.md +202 -202
  8. package/QUICK_START.md +134 -134
  9. package/README.md +488 -488
  10. package/RELEASE_NOTES_v1.0.2.md +434 -434
  11. package/bin/base.js +627 -627
  12. package/dist/ai/fix-manager.d.ts.map +1 -1
  13. package/dist/ai/fix-manager.js +1 -1
  14. package/dist/ai/fix-manager.js.map +1 -1
  15. package/dist/ai/gemini-analyzer.d.ts.map +1 -1
  16. package/dist/ai/gemini-analyzer.js +29 -35
  17. package/dist/ai/gemini-analyzer.js.map +1 -1
  18. package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
  19. package/dist/ai/gemini-code-fixer.js +58 -58
  20. package/dist/ai/gemini-code-fixer.js.map +1 -1
  21. package/dist/ai/jules-implementer.d.ts +3 -0
  22. package/dist/ai/jules-implementer.d.ts.map +1 -1
  23. package/dist/ai/jules-implementer.js +63 -32
  24. package/dist/ai/jules-implementer.js.map +1 -1
  25. package/dist/ai/unified-code-fixer.js.map +1 -1
  26. package/dist/commands/check.d.ts.map +1 -1
  27. package/dist/commands/check.js +1 -1
  28. package/dist/commands/check.js.map +1 -1
  29. package/dist/commands/config.js +2 -1
  30. package/dist/commands/config.js.map +1 -1
  31. package/dist/commands/fix.d.ts.map +1 -1
  32. package/dist/commands/fix.js +48 -15
  33. package/dist/commands/fix.js.map +1 -1
  34. package/dist/core/api-key-manager.js +2 -2
  35. package/dist/core/api-key-manager.js.map +1 -1
  36. package/dist/core/baseguard.d.ts +1 -0
  37. package/dist/core/baseguard.d.ts.map +1 -1
  38. package/dist/core/baseguard.js +13 -10
  39. package/dist/core/baseguard.js.map +1 -1
  40. package/dist/core/baseline-checker.d.ts.map +1 -1
  41. package/dist/core/baseline-checker.js +8 -5
  42. package/dist/core/baseline-checker.js.map +1 -1
  43. package/dist/core/configuration-recovery.d.ts.map +1 -1
  44. package/dist/core/configuration-recovery.js +1 -1
  45. package/dist/core/configuration-recovery.js.map +1 -1
  46. package/dist/core/debug-logger.d.ts.map +1 -1
  47. package/dist/core/debug-logger.js +1 -1
  48. package/dist/core/debug-logger.js.map +1 -1
  49. package/dist/core/error-handler.d.ts.map +1 -1
  50. package/dist/core/error-handler.js +2 -1
  51. package/dist/core/error-handler.js.map +1 -1
  52. package/dist/core/gitignore-manager.js +5 -5
  53. package/dist/core/graceful-degradation-manager.d.ts.map +1 -1
  54. package/dist/core/graceful-degradation-manager.js +16 -16
  55. package/dist/core/graceful-degradation-manager.js.map +1 -1
  56. package/dist/core/lazy-loader.d.ts.map +1 -1
  57. package/dist/core/lazy-loader.js +9 -2
  58. package/dist/core/lazy-loader.js.map +1 -1
  59. package/dist/core/memory-manager.d.ts +0 -3
  60. package/dist/core/memory-manager.d.ts.map +1 -1
  61. package/dist/core/memory-manager.js.map +1 -1
  62. package/dist/core/parser-worker.d.ts +2 -0
  63. package/dist/core/parser-worker.d.ts.map +1 -0
  64. package/dist/core/parser-worker.js +19 -0
  65. package/dist/core/parser-worker.js.map +1 -0
  66. package/dist/core/startup-optimizer.d.ts.map +1 -1
  67. package/dist/core/startup-optimizer.js +4 -8
  68. package/dist/core/startup-optimizer.js.map +1 -1
  69. package/dist/core/system-error-handler.d.ts.map +1 -1
  70. package/dist/core/system-error-handler.js.map +1 -1
  71. package/dist/git/automation-engine.d.ts.map +1 -1
  72. package/dist/git/automation-engine.js +5 -4
  73. package/dist/git/automation-engine.js.map +1 -1
  74. package/dist/git/github-manager.d.ts.map +1 -1
  75. package/dist/git/github-manager.js.map +1 -1
  76. package/dist/git/hook-manager.js +5 -5
  77. package/dist/git/hook-manager.js.map +1 -1
  78. package/dist/parsers/parser-manager.d.ts.map +1 -1
  79. package/dist/parsers/parser-manager.js +1 -1
  80. package/dist/parsers/parser-manager.js.map +1 -1
  81. package/dist/parsers/svelte-parser.js +1 -1
  82. package/dist/parsers/svelte-parser.js.map +1 -1
  83. package/dist/parsers/vanilla-parser.d.ts.map +1 -1
  84. package/dist/parsers/vanilla-parser.js.map +1 -1
  85. package/dist/parsers/vue-parser.d.ts.map +1 -1
  86. package/dist/parsers/vue-parser.js.map +1 -1
  87. package/dist/ui/components.d.ts +1 -1
  88. package/dist/ui/components.d.ts.map +1 -1
  89. package/dist/ui/components.js +11 -11
  90. package/dist/ui/components.js.map +1 -1
  91. package/dist/ui/terminal-header.js +14 -14
  92. package/package.json +105 -105
  93. package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
  94. package/src/ai/agentkit-orchestrator.ts +533 -533
  95. package/src/ai/fix-manager.ts +362 -362
  96. package/src/ai/gemini-analyzer.ts +665 -671
  97. package/src/ai/gemini-code-fixer.ts +539 -540
  98. package/src/ai/index.ts +3 -3
  99. package/src/ai/jules-implementer.ts +504 -460
  100. package/src/ai/unified-code-fixer.ts +347 -347
  101. package/src/commands/automation.ts +343 -343
  102. package/src/commands/check.ts +298 -299
  103. package/src/commands/config.ts +584 -583
  104. package/src/commands/fix.ts +269 -238
  105. package/src/commands/index.ts +6 -6
  106. package/src/commands/init.ts +155 -155
  107. package/src/commands/status.ts +306 -306
  108. package/src/core/api-key-manager.ts +298 -298
  109. package/src/core/baseguard.ts +757 -756
  110. package/src/core/baseline-checker.ts +566 -563
  111. package/src/core/cache-manager.ts +271 -271
  112. package/src/core/configuration-recovery.ts +672 -673
  113. package/src/core/configuration.ts +595 -595
  114. package/src/core/debug-logger.ts +590 -590
  115. package/src/core/directory-filter.ts +420 -420
  116. package/src/core/error-handler.ts +518 -517
  117. package/src/core/file-processor.ts +337 -337
  118. package/src/core/gitignore-manager.ts +168 -168
  119. package/src/core/graceful-degradation-manager.ts +596 -596
  120. package/src/core/index.ts +16 -16
  121. package/src/core/lazy-loader.ts +317 -307
  122. package/src/core/memory-manager.ts +290 -295
  123. package/src/core/parser-worker.ts +33 -0
  124. package/src/core/startup-optimizer.ts +246 -255
  125. package/src/core/system-error-handler.ts +755 -756
  126. package/src/git/automation-engine.ts +361 -361
  127. package/src/git/github-manager.ts +190 -192
  128. package/src/git/hook-manager.ts +210 -210
  129. package/src/git/index.ts +3 -3
  130. package/src/index.ts +7 -7
  131. package/src/parsers/feature-validator.ts +558 -558
  132. package/src/parsers/index.ts +7 -7
  133. package/src/parsers/parser-manager.ts +418 -419
  134. package/src/parsers/parser.ts +25 -25
  135. package/src/parsers/react-parser-optimized.ts +160 -160
  136. package/src/parsers/react-parser.ts +358 -358
  137. package/src/parsers/svelte-parser.ts +510 -510
  138. package/src/parsers/vanilla-parser.ts +685 -686
  139. package/src/parsers/vue-parser.ts +476 -478
  140. package/src/types/index.ts +95 -95
  141. package/src/ui/components.ts +567 -567
  142. package/src/ui/help.ts +192 -192
  143. package/src/ui/index.ts +3 -3
  144. package/src/ui/prompts.ts +680 -680
  145. package/src/ui/terminal-header.ts +58 -58
  146. package/test-build.js +40 -40
  147. package/test-config-commands.js +55 -55
  148. package/test-header-simple.js +32 -32
  149. package/test-terminal-header.js +11 -11
  150. package/test-ui.js +28 -28
  151. package/tests/e2e/baseguard.e2e.test.ts +515 -515
  152. package/tests/e2e/cross-platform.e2e.test.ts +419 -419
  153. package/tests/e2e/git-integration.e2e.test.ts +486 -486
  154. package/tests/fixtures/react-project/package.json +13 -13
  155. package/tests/fixtures/react-project/src/App.css +75 -75
  156. package/tests/fixtures/react-project/src/App.tsx +76 -76
  157. package/tests/fixtures/svelte-project/package.json +10 -10
  158. package/tests/fixtures/svelte-project/src/App.svelte +368 -368
  159. package/tests/fixtures/vanilla-project/index.html +75 -75
  160. package/tests/fixtures/vanilla-project/script.js +330 -330
  161. package/tests/fixtures/vanilla-project/styles.css +358 -358
  162. package/tests/fixtures/vue-project/package.json +11 -11
  163. package/tests/fixtures/vue-project/src/App.vue +215 -215
  164. package/tmp-smoke/.baseguard/backups/config-2026-02-19T12-04-11-067Z-auto.json +30 -0
  165. package/tmp-smoke/src/bad.css +3 -0
  166. package/tsconfig.json +34 -34
  167. package/vitest.config.ts +11 -11
  168. package/dist/terminal-header.d.ts +0 -12
  169. package/dist/terminal-header.js +0 -45
@@ -1,255 +1,246 @@
1
- /**
2
- * Startup optimization manager to minimize initialization time and memory usage
3
- */
4
- export class StartupOptimizer {
5
- private static startTime = Date.now();
6
- private static initialized = false;
7
- private static gcInterval: NodeJS.Timeout | null = null;
8
- private static memoryInterval: NodeJS.Timeout | null = null;
9
-
10
- /**
11
- * Initialize BaseGuard with optimized startup
12
- */
13
- static async initialize(): Promise<void> {
14
- if (this.initialized) {
15
- return;
16
- }
17
-
18
- const startTime = Date.now();
19
-
20
- try {
21
- // Start critical dependency loading in background
22
- await this.preloadCriticalDependencies();
23
-
24
- // Initialize memory management
25
- this.setupMemoryOptimizations();
26
-
27
- this.initialized = true;
28
-
29
- const initTime = Date.now() - startTime;
30
- if (initTime > 1000) {
31
- console.warn(`Slow startup detected: ${initTime}ms`);
32
- }
33
- } catch (error) {
34
- console.warn('Startup optimization failed:', error);
35
- this.initialized = true; // Continue anyway
36
- }
37
- }
38
-
39
- /**
40
- * Preload critical dependencies without blocking
41
- */
42
- private static async preloadCriticalDependencies(): Promise<void> {
43
- const { LazyLoader } = await import('./lazy-loader.js');
44
-
45
- // Start loading critical dependencies in parallel
46
- const criticalLoads = [
47
- LazyLoader.getWebFeatures().catch(() => {}),
48
- LazyLoader.getBabelParser().catch(() => {})
49
- ];
50
-
51
- // Don't wait for all to complete - just start the loading process
52
- Promise.all(criticalLoads);
53
- }
54
-
55
- /**
56
- * Setup memory optimizations
57
- */
58
- private static setupMemoryOptimizations(): void {
59
- // Enable garbage collection hints if available
60
- if (global.gc) {
61
- // Set up periodic GC for long-running processes
62
- this.gcInterval = setInterval(() => {
63
- const { MemoryManager } = require('./memory-manager.js');
64
- const memCheck = MemoryManager.checkMemoryUsage();
65
-
66
- if (memCheck.warning) {
67
- MemoryManager.tryGarbageCollect();
68
- }
69
- }, 30000); // Check every 30 seconds
70
- }
71
-
72
- // Setup process memory monitoring
73
- process.on('warning', (warning) => {
74
- if (warning.name === 'MaxListenersExceededWarning') {
75
- console.warn('Memory warning: Too many event listeners');
76
- }
77
- });
78
- }
79
-
80
- /**
81
- * Get startup performance metrics
82
- */
83
- static getStartupMetrics(): {
84
- totalStartupTime: number;
85
- memoryUsage: NodeJS.MemoryUsage;
86
- nodeVersion: string;
87
- platform: string;
88
- } {
89
- return {
90
- totalStartupTime: Date.now() - this.startTime,
91
- memoryUsage: process.memoryUsage(),
92
- nodeVersion: process.version,
93
- platform: process.platform
94
- };
95
- }
96
-
97
- /**
98
- * Optimize for specific use cases
99
- */
100
- static async optimizeForUseCase(useCase: 'check' | 'fix' | 'init'): Promise<void> {
101
- const { LazyLoader } = await import('./lazy-loader.js');
102
-
103
- switch (useCase) {
104
- case 'check':
105
- // Preload parsing and baseline checking dependencies
106
- LazyLoader.getWebFeatures().catch(() => {});
107
- LazyLoader.getBabelParser().catch(() => {});
108
- LazyLoader.getPostCSS().catch(() => {});
109
- break;
110
-
111
- case 'fix':
112
- // Preload all dependencies including AI services
113
- LazyLoader.preloadCommon();
114
- break;
115
-
116
- case 'init':
117
- // Minimal loading for initialization
118
- break;
119
- }
120
- }
121
-
122
- /**
123
- * Clean up resources and optimize memory
124
- */
125
- static cleanup(): void {
126
- const { LazyLoader } = require('./lazy-loader.js');
127
- const { MemoryManager } = require('./memory-manager.js');
128
-
129
- // Clear intervals
130
- if (this.gcInterval) {
131
- clearInterval(this.gcInterval);
132
- this.gcInterval = null;
133
- }
134
- if (this.memoryInterval) {
135
- clearInterval(this.memoryInterval);
136
- this.memoryInterval = null;
137
- }
138
-
139
- // Clear caches
140
- LazyLoader.clearCache();
141
-
142
- // Force garbage collection if available
143
- MemoryManager.tryGarbageCollect();
144
- }
145
-
146
- /**
147
- * Check if startup optimizations are working
148
- */
149
- static validateOptimizations(): {
150
- isOptimized: boolean;
151
- issues: string[];
152
- recommendations: string[];
153
- } {
154
- const issues: string[] = [];
155
- const recommendations: string[] = [];
156
-
157
- const metrics = this.getStartupMetrics();
158
-
159
- // Check startup time
160
- if (metrics.totalStartupTime > 2000) {
161
- issues.push(`Slow startup: ${metrics.totalStartupTime}ms`);
162
- recommendations.push('Consider reducing dependencies or using lazy loading');
163
- }
164
-
165
- // Check memory usage
166
- const heapUsedMB = metrics.memoryUsage.heapUsed / 1024 / 1024;
167
- if (heapUsedMB > 50) {
168
- issues.push(`High memory usage: ${Math.round(heapUsedMB)}MB`);
169
- recommendations.push('Consider optimizing data structures or clearing caches');
170
- }
171
-
172
- // Check Node.js version
173
- const nodeVersion = parseInt(metrics.nodeVersion.slice(1));
174
- if (nodeVersion < 18) {
175
- issues.push(`Old Node.js version: ${metrics.nodeVersion}`);
176
- recommendations.push('Upgrade to Node.js 18+ for better performance');
177
- }
178
-
179
- return {
180
- isOptimized: issues.length === 0,
181
- issues,
182
- recommendations
183
- };
184
- }
185
-
186
- /**
187
- * Optimize memory usage by reducing object overhead
188
- */
189
- static optimizeMemoryUsage(): void {
190
- // Enable V8 memory optimizations if available
191
- if (process.env.NODE_ENV !== 'development') {
192
- // Set V8 flags for better memory management
193
- process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ' --max-old-space-size=512 --optimize-for-size';
194
- }
195
-
196
- // Setup memory monitoring
197
- if (global.gc) {
198
- this.memoryInterval = setInterval(() => {
199
- const usage = process.memoryUsage();
200
- const heapUsedMB = usage.heapUsed / 1024 / 1024;
201
-
202
- // Force GC if memory usage is high
203
- if (heapUsedMB > 100 && global.gc) {
204
- global.gc();
205
- }
206
- }, 30000);
207
- }
208
- }
209
-
210
- /**
211
- * Reduce startup time by deferring non-critical operations
212
- */
213
- static async deferNonCriticalOperations(): Promise<void> {
214
- // Defer heavy operations until after startup
215
- setTimeout(async () => {
216
- try {
217
- // Preload remaining dependencies
218
- const { LazyLoader } = await import('./lazy-loader.js');
219
- LazyLoader.preloadCommon();
220
-
221
- // Initialize caches
222
- const { CacheManager } = await import('./cache-manager.js');
223
- // Cache initialization would happen here
224
-
225
- // Cleanup old logs
226
- const { logger } = await import('./debug-logger.js');
227
- logger.cleanupOldLogs().catch(() => {});
228
- } catch (error) {
229
- // Ignore errors in deferred operations
230
- }
231
- }, 100); // Defer by 100ms
232
- }
233
-
234
- /**
235
- * Optimize startup by preloading critical dependencies
236
- */
237
- static async optimizeStartup(): Promise<void> {
238
- // Start loading critical dependencies in background
239
- const { LazyLoader } = await import('./lazy-loader.js');
240
-
241
- const criticalLoads = [
242
- LazyLoader.getWebFeatures().catch(() => {}),
243
- LazyLoader.getBabelParser().catch(() => {})
244
- ];
245
-
246
- // Don't wait for all to complete, just start the process
247
- Promise.all(criticalLoads);
248
-
249
- // Setup memory optimizations
250
- this.optimizeMemoryUsage();
251
-
252
- // Defer non-critical operations
253
- this.deferNonCriticalOperations();
254
- }
255
- }
1
+ /**
2
+ * Startup optimization manager to minimize initialization time and memory usage
3
+ */
4
+ export class StartupOptimizer {
5
+ private static startTime = Date.now();
6
+ private static initialized = false;
7
+ private static gcInterval: NodeJS.Timeout | null = null;
8
+ private static memoryInterval: NodeJS.Timeout | null = null;
9
+
10
+ /**
11
+ * Initialize BaseGuard with optimized startup
12
+ */
13
+ static async initialize(): Promise<void> {
14
+ if (this.initialized) {
15
+ return;
16
+ }
17
+
18
+ const startTime = Date.now();
19
+
20
+ try {
21
+ // Start critical dependency loading in background
22
+ await this.preloadCriticalDependencies();
23
+
24
+ // Initialize memory management
25
+ this.setupMemoryOptimizations();
26
+
27
+ this.initialized = true;
28
+
29
+ const initTime = Date.now() - startTime;
30
+ if (initTime > 1000) {
31
+ console.warn(`Slow startup detected: ${initTime}ms`);
32
+ }
33
+ } catch (error) {
34
+ console.warn('Startup optimization failed:', error);
35
+ this.initialized = true; // Continue anyway
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Preload critical dependencies without blocking
41
+ */
42
+ private static async preloadCriticalDependencies(): Promise<void> {
43
+ // Start loading critical dependencies in parallel
44
+ const criticalLoads = [
45
+ LazyLoader.getWebFeatures().catch(() => {}),
46
+ LazyLoader.getBabelParser().catch(() => {})
47
+ ];
48
+
49
+ // Don't wait for all to complete - just start the loading process
50
+ Promise.all(criticalLoads);
51
+ }
52
+
53
+ /**
54
+ * Setup memory optimizations
55
+ */
56
+ private static setupMemoryOptimizations(): void {
57
+ // Enable garbage collection hints if available
58
+ if (global.gc) {
59
+ // Set up periodic GC for long-running processes
60
+ this.gcInterval = setInterval(() => {
61
+ const memCheck = MemoryManager.checkMemoryUsage();
62
+
63
+ if (memCheck.warning) {
64
+ MemoryManager.tryGarbageCollect();
65
+ }
66
+ }, 30000); // Check every 30 seconds
67
+ this.gcInterval.unref();
68
+ }
69
+
70
+ // Setup process memory monitoring
71
+ process.on('warning', (warning) => {
72
+ if (warning.name === 'MaxListenersExceededWarning') {
73
+ console.warn('Memory warning: Too many event listeners');
74
+ }
75
+ });
76
+ }
77
+
78
+ /**
79
+ * Get startup performance metrics
80
+ */
81
+ static getStartupMetrics(): {
82
+ totalStartupTime: number;
83
+ memoryUsage: NodeJS.MemoryUsage;
84
+ nodeVersion: string;
85
+ platform: string;
86
+ } {
87
+ return {
88
+ totalStartupTime: Date.now() - this.startTime,
89
+ memoryUsage: process.memoryUsage(),
90
+ nodeVersion: process.version,
91
+ platform: process.platform
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Optimize for specific use cases
97
+ */
98
+ static async optimizeForUseCase(useCase: 'check' | 'fix' | 'init'): Promise<void> {
99
+ switch (useCase) {
100
+ case 'check':
101
+ // Preload parsing and baseline checking dependencies
102
+ LazyLoader.getWebFeatures().catch(() => {});
103
+ LazyLoader.getBabelParser().catch(() => {});
104
+ LazyLoader.getPostCSS().catch(() => {});
105
+ break;
106
+
107
+ case 'fix':
108
+ // Preload all dependencies including AI services
109
+ LazyLoader.preloadCommon();
110
+ break;
111
+
112
+ case 'init':
113
+ // Minimal loading for initialization
114
+ break;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Clean up resources and optimize memory
120
+ */
121
+ static cleanup(): void {
122
+ // Clear intervals
123
+ if (this.gcInterval) {
124
+ clearInterval(this.gcInterval);
125
+ this.gcInterval = null;
126
+ }
127
+ if (this.memoryInterval) {
128
+ clearInterval(this.memoryInterval);
129
+ this.memoryInterval = null;
130
+ }
131
+
132
+ // Clear caches
133
+ LazyLoader.clearCache();
134
+
135
+ // Force garbage collection if available
136
+ MemoryManager.tryGarbageCollect();
137
+ }
138
+
139
+ /**
140
+ * Check if startup optimizations are working
141
+ */
142
+ static validateOptimizations(): {
143
+ isOptimized: boolean;
144
+ issues: string[];
145
+ recommendations: string[];
146
+ } {
147
+ const issues: string[] = [];
148
+ const recommendations: string[] = [];
149
+
150
+ const metrics = this.getStartupMetrics();
151
+
152
+ // Check startup time
153
+ if (metrics.totalStartupTime > 2000) {
154
+ issues.push(`Slow startup: ${metrics.totalStartupTime}ms`);
155
+ recommendations.push('Consider reducing dependencies or using lazy loading');
156
+ }
157
+
158
+ // Check memory usage
159
+ const heapUsedMB = metrics.memoryUsage.heapUsed / 1024 / 1024;
160
+ if (heapUsedMB > 50) {
161
+ issues.push(`High memory usage: ${Math.round(heapUsedMB)}MB`);
162
+ recommendations.push('Consider optimizing data structures or clearing caches');
163
+ }
164
+
165
+ // Check Node.js version
166
+ const nodeVersion = parseInt(metrics.nodeVersion.slice(1));
167
+ if (nodeVersion < 18) {
168
+ issues.push(`Old Node.js version: ${metrics.nodeVersion}`);
169
+ recommendations.push('Upgrade to Node.js 18+ for better performance');
170
+ }
171
+
172
+ return {
173
+ isOptimized: issues.length === 0,
174
+ issues,
175
+ recommendations
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Optimize memory usage by reducing object overhead
181
+ */
182
+ static optimizeMemoryUsage(): void {
183
+ // Enable V8 memory optimizations if available
184
+ if (process.env.NODE_ENV !== 'development') {
185
+ // Set V8 flags for better memory management
186
+ process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ' --max-old-space-size=512 --optimize-for-size';
187
+ }
188
+
189
+ // Setup memory monitoring
190
+ if (global.gc) {
191
+ this.memoryInterval = setInterval(() => {
192
+ const usage = process.memoryUsage();
193
+ const heapUsedMB = usage.heapUsed / 1024 / 1024;
194
+
195
+ // Force GC if memory usage is high
196
+ if (heapUsedMB > 100 && global.gc) {
197
+ global.gc();
198
+ }
199
+ }, 30000);
200
+ this.memoryInterval.unref();
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Reduce startup time by deferring non-critical operations
206
+ */
207
+ static async deferNonCriticalOperations(): Promise<void> {
208
+ // Defer heavy operations until after startup
209
+ setTimeout(async () => {
210
+ try {
211
+ // Preload remaining dependencies
212
+ const { LazyLoader } = await import('./lazy-loader.js');
213
+ LazyLoader.preloadCommon();
214
+
215
+ // Initialize caches
216
+ // Cleanup old logs
217
+ const { logger } = await import('./debug-logger.js');
218
+ logger.cleanupOldLogs().catch(() => {});
219
+ } catch (error) {
220
+ // Ignore errors in deferred operations
221
+ }
222
+ }, 100); // Defer by 100ms
223
+ }
224
+
225
+ /**
226
+ * Optimize startup by preloading critical dependencies
227
+ */
228
+ static async optimizeStartup(): Promise<void> {
229
+ // Start loading critical dependencies in background
230
+ const criticalLoads = [
231
+ LazyLoader.getWebFeatures().catch(() => {}),
232
+ LazyLoader.getBabelParser().catch(() => {})
233
+ ];
234
+
235
+ // Don't wait for all to complete, just start the process
236
+ Promise.all(criticalLoads);
237
+
238
+ // Setup memory optimizations
239
+ this.optimizeMemoryUsage();
240
+
241
+ // Defer non-critical operations
242
+ this.deferNonCriticalOperations();
243
+ }
244
+ }
245
+ import { LazyLoader } from './lazy-loader.js';
246
+ import { MemoryManager } from './memory-manager.js';