baseguard 1.0.2 → 1.0.4

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 +628 -613
  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 +44 -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 +2 -1
  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 +2 -0
  67. package/dist/core/startup-optimizer.d.ts.map +1 -1
  68. package/dist/core/startup-optimizer.js +19 -12
  69. package/dist/core/startup-optimizer.js.map +1 -1
  70. package/dist/core/system-error-handler.d.ts.map +1 -1
  71. package/dist/core/system-error-handler.js +18 -11
  72. package/dist/core/system-error-handler.js.map +1 -1
  73. package/dist/git/automation-engine.d.ts.map +1 -1
  74. package/dist/git/automation-engine.js +5 -4
  75. package/dist/git/automation-engine.js.map +1 -1
  76. package/dist/git/github-manager.d.ts.map +1 -1
  77. package/dist/git/github-manager.js.map +1 -1
  78. package/dist/git/hook-manager.js +5 -5
  79. package/dist/git/hook-manager.js.map +1 -1
  80. package/dist/parsers/parser-manager.d.ts.map +1 -1
  81. package/dist/parsers/parser-manager.js +1 -1
  82. package/dist/parsers/parser-manager.js.map +1 -1
  83. package/dist/parsers/svelte-parser.js +1 -1
  84. package/dist/parsers/svelte-parser.js.map +1 -1
  85. package/dist/parsers/vanilla-parser.d.ts.map +1 -1
  86. package/dist/parsers/vanilla-parser.js.map +1 -1
  87. package/dist/parsers/vue-parser.d.ts.map +1 -1
  88. package/dist/parsers/vue-parser.js.map +1 -1
  89. package/dist/ui/components.d.ts +1 -1
  90. package/dist/ui/components.d.ts.map +1 -1
  91. package/dist/ui/components.js +11 -11
  92. package/dist/ui/components.js.map +1 -1
  93. package/dist/ui/terminal-header.js +14 -14
  94. package/package.json +105 -105
  95. package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
  96. package/src/ai/agentkit-orchestrator.ts +533 -533
  97. package/src/ai/fix-manager.ts +362 -362
  98. package/src/ai/gemini-analyzer.ts +665 -671
  99. package/src/ai/gemini-code-fixer.ts +539 -540
  100. package/src/ai/index.ts +3 -3
  101. package/src/ai/jules-implementer.ts +504 -460
  102. package/src/ai/unified-code-fixer.ts +347 -347
  103. package/src/commands/automation.ts +343 -343
  104. package/src/commands/check.ts +298 -299
  105. package/src/commands/config.ts +584 -583
  106. package/src/commands/fix.ts +264 -238
  107. package/src/commands/index.ts +6 -6
  108. package/src/commands/init.ts +155 -155
  109. package/src/commands/status.ts +306 -306
  110. package/src/core/api-key-manager.ts +298 -298
  111. package/src/core/baseguard.ts +757 -756
  112. package/src/core/baseline-checker.ts +564 -563
  113. package/src/core/cache-manager.ts +271 -271
  114. package/src/core/configuration-recovery.ts +672 -673
  115. package/src/core/configuration.ts +595 -595
  116. package/src/core/debug-logger.ts +590 -590
  117. package/src/core/directory-filter.ts +420 -420
  118. package/src/core/error-handler.ts +518 -517
  119. package/src/core/file-processor.ts +337 -337
  120. package/src/core/gitignore-manager.ts +168 -168
  121. package/src/core/graceful-degradation-manager.ts +596 -596
  122. package/src/core/index.ts +16 -16
  123. package/src/core/lazy-loader.ts +317 -307
  124. package/src/core/memory-manager.ts +290 -295
  125. package/src/core/parser-worker.ts +33 -0
  126. package/src/core/startup-optimizer.ts +246 -243
  127. package/src/core/system-error-handler.ts +755 -750
  128. package/src/git/automation-engine.ts +361 -361
  129. package/src/git/github-manager.ts +190 -192
  130. package/src/git/hook-manager.ts +210 -210
  131. package/src/git/index.ts +3 -3
  132. package/src/index.ts +7 -7
  133. package/src/parsers/feature-validator.ts +558 -558
  134. package/src/parsers/index.ts +7 -7
  135. package/src/parsers/parser-manager.ts +418 -419
  136. package/src/parsers/parser.ts +25 -25
  137. package/src/parsers/react-parser-optimized.ts +160 -160
  138. package/src/parsers/react-parser.ts +358 -358
  139. package/src/parsers/svelte-parser.ts +510 -510
  140. package/src/parsers/vanilla-parser.ts +685 -686
  141. package/src/parsers/vue-parser.ts +476 -478
  142. package/src/types/index.ts +95 -95
  143. package/src/ui/components.ts +567 -567
  144. package/src/ui/help.ts +192 -192
  145. package/src/ui/index.ts +3 -3
  146. package/src/ui/prompts.ts +680 -680
  147. package/src/ui/terminal-header.ts +58 -58
  148. package/test-build.js +40 -40
  149. package/test-config-commands.js +55 -55
  150. package/test-header-simple.js +32 -32
  151. package/test-terminal-header.js +11 -11
  152. package/test-ui.js +28 -28
  153. package/tests/e2e/baseguard.e2e.test.ts +515 -515
  154. package/tests/e2e/cross-platform.e2e.test.ts +419 -419
  155. package/tests/e2e/git-integration.e2e.test.ts +486 -486
  156. package/tests/fixtures/react-project/package.json +13 -13
  157. package/tests/fixtures/react-project/src/App.css +75 -75
  158. package/tests/fixtures/react-project/src/App.tsx +76 -76
  159. package/tests/fixtures/svelte-project/package.json +10 -10
  160. package/tests/fixtures/svelte-project/src/App.svelte +368 -368
  161. package/tests/fixtures/vanilla-project/index.html +75 -75
  162. package/tests/fixtures/vanilla-project/script.js +330 -330
  163. package/tests/fixtures/vanilla-project/styles.css +358 -358
  164. package/tests/fixtures/vue-project/package.json +11 -11
  165. package/tests/fixtures/vue-project/src/App.vue +215 -215
  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
package/src/core/index.ts CHANGED
@@ -1,17 +1,17 @@
1
- // Core engine exports
2
- export * from './baseguard.js';
3
- export * from './baseline-checker.js';
4
- export { ConfigurationManager, BROWSER_TARGET_PRESETS } from './configuration.js';
5
- export type { PresetName } from './configuration.js';
6
- export { ApiKeyManager } from './api-key-manager.js';
7
- export { GitignoreManager } from './gitignore-manager.js';
8
- export { CacheManager, LRUCache } from './cache-manager.js';
9
- export { FileProcessor } from './file-processor.js';
10
- export { DirectoryFilter } from './directory-filter.js';
11
- export { LazyLoader } from './lazy-loader.js';
12
- export { MemoryManager } from './memory-manager.js';
13
- export { StartupOptimizer } from './startup-optimizer.js';
14
- export { SystemErrorHandler } from './system-error-handler.js';
15
- export { GracefulDegradationManager } from './graceful-degradation-manager.js';
16
- export { ConfigurationRecovery } from './configuration-recovery.js';
1
+ // Core engine exports
2
+ export * from './baseguard.js';
3
+ export * from './baseline-checker.js';
4
+ export { ConfigurationManager, BROWSER_TARGET_PRESETS } from './configuration.js';
5
+ export type { PresetName } from './configuration.js';
6
+ export { ApiKeyManager } from './api-key-manager.js';
7
+ export { GitignoreManager } from './gitignore-manager.js';
8
+ export { CacheManager, LRUCache } from './cache-manager.js';
9
+ export { FileProcessor } from './file-processor.js';
10
+ export { DirectoryFilter } from './directory-filter.js';
11
+ export { LazyLoader } from './lazy-loader.js';
12
+ export { MemoryManager } from './memory-manager.js';
13
+ export { StartupOptimizer } from './startup-optimizer.js';
14
+ export { SystemErrorHandler } from './system-error-handler.js';
15
+ export { GracefulDegradationManager } from './graceful-degradation-manager.js';
16
+ export { ConfigurationRecovery } from './configuration-recovery.js';
17
17
  export { logger, DebugLogger } from './debug-logger.js';
@@ -1,307 +1,317 @@
1
- /**
2
- * Lazy loading system for heavy dependencies and parsers
3
- */
4
- export class LazyLoader {
5
- private static instances = new Map<string, any>();
6
- private static loadPromises = new Map<string, Promise<any>>();
7
-
8
- /**
9
- * Lazy load web-features package
10
- */
11
- static async getWebFeatures(): Promise<any> {
12
- const key = 'web-features';
13
-
14
- if (this.instances.has(key)) {
15
- return this.instances.get(key);
16
- }
17
-
18
- if (this.loadPromises.has(key)) {
19
- return this.loadPromises.get(key);
20
- }
21
-
22
- const loadPromise = this.loadWebFeatures();
23
- this.loadPromises.set(key, loadPromise);
24
-
25
- try {
26
- const webFeatures = await loadPromise;
27
- this.instances.set(key, webFeatures);
28
- this.loadPromises.delete(key);
29
- return webFeatures;
30
- } catch (error) {
31
- this.loadPromises.delete(key);
32
- throw error;
33
- }
34
- }
35
-
36
- /**
37
- * Lazy load Babel parser
38
- */
39
- static async getBabelParser(): Promise<any> {
40
- const key = 'babel-parser';
41
-
42
- if (this.instances.has(key)) {
43
- return this.instances.get(key);
44
- }
45
-
46
- if (this.loadPromises.has(key)) {
47
- return this.loadPromises.get(key);
48
- }
49
-
50
- const loadPromise = import('@babel/parser');
51
- this.loadPromises.set(key, loadPromise);
52
-
53
- try {
54
- const parser = await loadPromise;
55
- this.instances.set(key, parser);
56
- this.loadPromises.delete(key);
57
- return parser;
58
- } catch (error) {
59
- this.loadPromises.delete(key);
60
- throw error;
61
- }
62
- }
63
-
64
- /**
65
- * Lazy load Babel traverse
66
- */
67
- static async getBabelTraverse(): Promise<any> {
68
- const key = 'babel-traverse';
69
-
70
- if (this.instances.has(key)) {
71
- return this.instances.get(key);
72
- }
73
-
74
- if (this.loadPromises.has(key)) {
75
- return this.loadPromises.get(key);
76
- }
77
-
78
- const loadPromise = import('@babel/traverse');
79
- this.loadPromises.set(key, loadPromise);
80
-
81
- try {
82
- const traverse = await loadPromise;
83
- this.instances.set(key, traverse.default || traverse);
84
- this.loadPromises.delete(key);
85
- return this.instances.get(key);
86
- } catch (error) {
87
- this.loadPromises.delete(key);
88
- throw error;
89
- }
90
- }
91
-
92
- /**
93
- * Lazy load PostCSS
94
- */
95
- static async getPostCSS(): Promise<any> {
96
- const key = 'postcss';
97
-
98
- if (this.instances.has(key)) {
99
- return this.instances.get(key);
100
- }
101
-
102
- if (this.loadPromises.has(key)) {
103
- return this.loadPromises.get(key);
104
- }
105
-
106
- const loadPromise = import('postcss');
107
- this.loadPromises.set(key, loadPromise);
108
-
109
- try {
110
- const postcss = await loadPromise;
111
- this.instances.set(key, postcss.default || postcss);
112
- this.loadPromises.delete(key);
113
- return this.instances.get(key);
114
- } catch (error) {
115
- this.loadPromises.delete(key);
116
- throw error;
117
- }
118
- }
119
-
120
- /**
121
- * Lazy load Vue compiler
122
- */
123
- static async getVueCompiler(): Promise<any> {
124
- const key = 'vue-compiler';
125
-
126
- if (this.instances.has(key)) {
127
- return this.instances.get(key);
128
- }
129
-
130
- if (this.loadPromises.has(key)) {
131
- return this.loadPromises.get(key);
132
- }
133
-
134
- const loadPromise = import('@vue/compiler-sfc');
135
- this.loadPromises.set(key, loadPromise);
136
-
137
- try {
138
- const compiler = await loadPromise;
139
- this.instances.set(key, compiler);
140
- this.loadPromises.delete(key);
141
- return compiler;
142
- } catch (error) {
143
- this.loadPromises.delete(key);
144
- throw error;
145
- }
146
- }
147
-
148
- /**
149
- * Lazy load Svelte compiler
150
- */
151
- static async getSvelteCompiler(): Promise<any> {
152
- const key = 'svelte-compiler';
153
-
154
- if (this.instances.has(key)) {
155
- return this.instances.get(key);
156
- }
157
-
158
- if (this.loadPromises.has(key)) {
159
- return this.loadPromises.get(key);
160
- }
161
-
162
- const loadPromise = import('svelte/compiler');
163
- this.loadPromises.set(key, loadPromise);
164
-
165
- try {
166
- const compiler = await loadPromise;
167
- this.instances.set(key, compiler);
168
- this.loadPromises.delete(key);
169
- return compiler;
170
- } catch (error) {
171
- this.loadPromises.delete(key);
172
- throw error;
173
- }
174
- }
175
-
176
- /**
177
- * Preload commonly used dependencies
178
- */
179
- static async preloadCommon(): Promise<void> {
180
- // Preload in background without blocking
181
- Promise.all([
182
- this.getWebFeatures().catch(() => {}),
183
- this.getBabelParser().catch(() => {}),
184
- this.getPostCSS().catch(() => {})
185
- ]);
186
- }
187
-
188
- /**
189
- * Clear all cached instances (for testing)
190
- */
191
- static clearCache(): void {
192
- this.instances.clear();
193
- this.loadPromises.clear();
194
- }
195
-
196
- /**
197
- * Get memory usage statistics
198
- */
199
- static getStats(): {
200
- loadedModules: string[];
201
- pendingLoads: string[];
202
- memoryUsage?: NodeJS.MemoryUsage;
203
- } {
204
- return {
205
- loadedModules: Array.from(this.instances.keys()),
206
- pendingLoads: Array.from(this.loadPromises.keys()),
207
- memoryUsage: process.memoryUsage ? process.memoryUsage() : undefined
208
- };
209
- }
210
-
211
- /**
212
- * Load web-features with optimized loading
213
- */
214
- private static async loadWebFeatures(): Promise<any> {
215
- try {
216
- // Try to load web-features package
217
- const webFeatures = await import('web-features');
218
-
219
- // Extract only the data we need to reduce memory usage
220
- const optimizedData = this.optimizeWebFeaturesData(webFeatures.default || webFeatures);
221
-
222
- return optimizedData;
223
- } catch (error) {
224
- console.warn('Failed to load web-features package:', error);
225
- // Return minimal fallback data
226
- return {
227
- features: {},
228
- browsers: {},
229
- groups: {}
230
- };
231
- }
232
- }
233
-
234
- /**
235
- * Optimize web-features data to reduce memory usage
236
- */
237
- private static optimizeWebFeaturesData(webFeatures: any): any {
238
- if (!webFeatures) {
239
- return { features: {}, browsers: {}, groups: {} };
240
- }
241
-
242
- // Handle both direct export and features property
243
- const featuresData = webFeatures.features || webFeatures;
244
-
245
- if (!featuresData || typeof featuresData !== 'object') {
246
- return { features: {}, browsers: {}, groups: {} };
247
- }
248
-
249
- // Create optimized structure with only essential data
250
- const optimized = {
251
- features: {} as any,
252
- browsers: webFeatures.browsers || {},
253
- groups: webFeatures.groups || {}
254
- };
255
-
256
- // Only keep essential feature data to reduce memory footprint
257
- for (const [featureId, feature] of Object.entries(featuresData)) {
258
- const f = feature as any;
259
-
260
- // Skip if not a valid feature object
261
- if (!f || typeof f !== 'object') {
262
- continue;
263
- }
264
-
265
- // Only store essential compatibility data
266
- optimized.features[featureId] = {
267
- name: f.name,
268
- status: f.status ? {
269
- baseline: f.status.baseline,
270
- support: f.status.support
271
- } : null,
272
- // Skip heavy data like descriptions, specs, caniuse data, etc.
273
- };
274
- }
275
-
276
- return optimized;
277
- }
278
-
279
- /**
280
- * Get startup performance statistics
281
- */
282
- static getStartupStats(): {
283
- loadedModules: string[];
284
- pendingLoads: string[];
285
- startupTime?: number;
286
- } {
287
- return {
288
- loadedModules: Array.from(this.instances.keys()),
289
- pendingLoads: Array.from(this.loadPromises.keys()),
290
- startupTime: process.uptime ? Math.round(process.uptime() * 1000) : undefined
291
- };
292
- }
293
-
294
- /**
295
- * Optimize startup by preloading critical dependencies
296
- */
297
- static async optimizeStartup(): Promise<void> {
298
- // Start loading critical dependencies in background
299
- const criticalLoads = [
300
- this.getWebFeatures().catch(() => {}),
301
- this.getBabelParser().catch(() => {})
302
- ];
303
-
304
- // Don't wait for all to complete, just start the process
305
- Promise.all(criticalLoads);
306
- }
307
- }
1
+ /**
2
+ * Lazy loading system for heavy dependencies and parsers
3
+ */
4
+ export class LazyLoader {
5
+ private static instances = new Map<string, any>();
6
+ private static loadPromises = new Map<string, Promise<any>>();
7
+
8
+ /**
9
+ * Lazy load web-features package
10
+ */
11
+ static async getWebFeatures(): Promise<any> {
12
+ const key = 'web-features';
13
+
14
+ if (this.instances.has(key)) {
15
+ return this.instances.get(key);
16
+ }
17
+
18
+ if (this.loadPromises.has(key)) {
19
+ return this.loadPromises.get(key);
20
+ }
21
+
22
+ const loadPromise = this.loadWebFeatures();
23
+ this.loadPromises.set(key, loadPromise);
24
+
25
+ try {
26
+ const webFeatures = await loadPromise;
27
+ this.instances.set(key, webFeatures);
28
+ this.loadPromises.delete(key);
29
+ return webFeatures;
30
+ } catch (error) {
31
+ this.loadPromises.delete(key);
32
+ throw error;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Lazy load Babel parser
38
+ */
39
+ static async getBabelParser(): Promise<any> {
40
+ const key = 'babel-parser';
41
+
42
+ if (this.instances.has(key)) {
43
+ return this.instances.get(key);
44
+ }
45
+
46
+ if (this.loadPromises.has(key)) {
47
+ return this.loadPromises.get(key);
48
+ }
49
+
50
+ const loadPromise = import('@babel/parser');
51
+ this.loadPromises.set(key, loadPromise);
52
+
53
+ try {
54
+ const parser = await loadPromise;
55
+ this.instances.set(key, parser);
56
+ this.loadPromises.delete(key);
57
+ return parser;
58
+ } catch (error) {
59
+ this.loadPromises.delete(key);
60
+ throw error;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Lazy load Babel traverse
66
+ */
67
+ static async getBabelTraverse(): Promise<any> {
68
+ const key = 'babel-traverse';
69
+
70
+ if (this.instances.has(key)) {
71
+ return this.instances.get(key);
72
+ }
73
+
74
+ if (this.loadPromises.has(key)) {
75
+ return this.loadPromises.get(key);
76
+ }
77
+
78
+ const loadPromise = import('@babel/traverse');
79
+ this.loadPromises.set(key, loadPromise);
80
+
81
+ try {
82
+ const traverseModule = await loadPromise;
83
+ const traverseExport = traverseModule.default || traverseModule;
84
+ const traverse =
85
+ typeof traverseExport === 'function'
86
+ ? traverseExport
87
+ : (traverseExport as any)?.default;
88
+
89
+ if (typeof traverse !== 'function') {
90
+ throw new Error('Failed to resolve @babel/traverse default export');
91
+ }
92
+
93
+ this.instances.set(key, traverse);
94
+ this.loadPromises.delete(key);
95
+ return this.instances.get(key);
96
+ } catch (error) {
97
+ this.loadPromises.delete(key);
98
+ throw error;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Lazy load PostCSS
104
+ */
105
+ static async getPostCSS(): Promise<any> {
106
+ const key = 'postcss';
107
+
108
+ if (this.instances.has(key)) {
109
+ return this.instances.get(key);
110
+ }
111
+
112
+ if (this.loadPromises.has(key)) {
113
+ return this.loadPromises.get(key);
114
+ }
115
+
116
+ const loadPromise = import('postcss');
117
+ this.loadPromises.set(key, loadPromise);
118
+
119
+ try {
120
+ const postcss = await loadPromise;
121
+ this.instances.set(key, postcss.default || postcss);
122
+ this.loadPromises.delete(key);
123
+ return this.instances.get(key);
124
+ } catch (error) {
125
+ this.loadPromises.delete(key);
126
+ throw error;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Lazy load Vue compiler
132
+ */
133
+ static async getVueCompiler(): Promise<any> {
134
+ const key = 'vue-compiler';
135
+
136
+ if (this.instances.has(key)) {
137
+ return this.instances.get(key);
138
+ }
139
+
140
+ if (this.loadPromises.has(key)) {
141
+ return this.loadPromises.get(key);
142
+ }
143
+
144
+ const loadPromise = import('@vue/compiler-sfc');
145
+ this.loadPromises.set(key, loadPromise);
146
+
147
+ try {
148
+ const compiler = await loadPromise;
149
+ this.instances.set(key, compiler);
150
+ this.loadPromises.delete(key);
151
+ return compiler;
152
+ } catch (error) {
153
+ this.loadPromises.delete(key);
154
+ throw error;
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Lazy load Svelte compiler
160
+ */
161
+ static async getSvelteCompiler(): Promise<any> {
162
+ const key = 'svelte-compiler';
163
+
164
+ if (this.instances.has(key)) {
165
+ return this.instances.get(key);
166
+ }
167
+
168
+ if (this.loadPromises.has(key)) {
169
+ return this.loadPromises.get(key);
170
+ }
171
+
172
+ const loadPromise = import('svelte/compiler');
173
+ this.loadPromises.set(key, loadPromise);
174
+
175
+ try {
176
+ const compiler = await loadPromise;
177
+ this.instances.set(key, compiler);
178
+ this.loadPromises.delete(key);
179
+ return compiler;
180
+ } catch (error) {
181
+ this.loadPromises.delete(key);
182
+ throw error;
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Preload commonly used dependencies
188
+ */
189
+ static async preloadCommon(): Promise<void> {
190
+ // Preload in background without blocking
191
+ Promise.all([
192
+ this.getWebFeatures().catch(() => {}),
193
+ this.getBabelParser().catch(() => {}),
194
+ this.getPostCSS().catch(() => {})
195
+ ]);
196
+ }
197
+
198
+ /**
199
+ * Clear all cached instances (for testing)
200
+ */
201
+ static clearCache(): void {
202
+ this.instances.clear();
203
+ this.loadPromises.clear();
204
+ }
205
+
206
+ /**
207
+ * Get memory usage statistics
208
+ */
209
+ static getStats(): {
210
+ loadedModules: string[];
211
+ pendingLoads: string[];
212
+ memoryUsage?: NodeJS.MemoryUsage;
213
+ } {
214
+ return {
215
+ loadedModules: Array.from(this.instances.keys()),
216
+ pendingLoads: Array.from(this.loadPromises.keys()),
217
+ memoryUsage: process.memoryUsage ? process.memoryUsage() : undefined
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Load web-features with optimized loading
223
+ */
224
+ private static async loadWebFeatures(): Promise<any> {
225
+ try {
226
+ // Try to load web-features package
227
+ const webFeatures = await import('web-features');
228
+
229
+ // Extract only the data we need to reduce memory usage
230
+ const optimizedData = this.optimizeWebFeaturesData(webFeatures.default || webFeatures);
231
+
232
+ return optimizedData;
233
+ } catch (error) {
234
+ console.warn('Failed to load web-features package:', error);
235
+ // Return minimal fallback data
236
+ return {
237
+ features: {},
238
+ browsers: {},
239
+ groups: {}
240
+ };
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Optimize web-features data to reduce memory usage
246
+ */
247
+ private static optimizeWebFeaturesData(webFeatures: any): any {
248
+ if (!webFeatures) {
249
+ return { features: {}, browsers: {}, groups: {} };
250
+ }
251
+
252
+ // Handle both direct export and features property
253
+ const featuresData = webFeatures.features || webFeatures;
254
+
255
+ if (!featuresData || typeof featuresData !== 'object') {
256
+ return { features: {}, browsers: {}, groups: {} };
257
+ }
258
+
259
+ // Create optimized structure with only essential data
260
+ const optimized = {
261
+ features: {} as any,
262
+ browsers: webFeatures.browsers || {},
263
+ groups: webFeatures.groups || {}
264
+ };
265
+
266
+ // Only keep essential feature data to reduce memory footprint
267
+ for (const [featureId, feature] of Object.entries(featuresData)) {
268
+ const f = feature as any;
269
+
270
+ // Skip if not a valid feature object
271
+ if (!f || typeof f !== 'object') {
272
+ continue;
273
+ }
274
+
275
+ // Only store essential compatibility data
276
+ optimized.features[featureId] = {
277
+ name: f.name,
278
+ status: f.status ? {
279
+ baseline: f.status.baseline,
280
+ support: f.status.support
281
+ } : null,
282
+ // Skip heavy data like descriptions, specs, caniuse data, etc.
283
+ };
284
+ }
285
+
286
+ return optimized;
287
+ }
288
+
289
+ /**
290
+ * Get startup performance statistics
291
+ */
292
+ static getStartupStats(): {
293
+ loadedModules: string[];
294
+ pendingLoads: string[];
295
+ startupTime?: number;
296
+ } {
297
+ return {
298
+ loadedModules: Array.from(this.instances.keys()),
299
+ pendingLoads: Array.from(this.loadPromises.keys()),
300
+ startupTime: process.uptime ? Math.round(process.uptime() * 1000) : undefined
301
+ };
302
+ }
303
+
304
+ /**
305
+ * Optimize startup by preloading critical dependencies
306
+ */
307
+ static async optimizeStartup(): Promise<void> {
308
+ // Start loading critical dependencies in background
309
+ const criticalLoads = [
310
+ this.getWebFeatures().catch(() => {}),
311
+ this.getBabelParser().catch(() => {})
312
+ ];
313
+
314
+ // Don't wait for all to complete, just start the process
315
+ Promise.all(criticalLoads);
316
+ }
317
+ }