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.
- package/.baseguardrc.example.json +63 -63
- package/.eslintrc.json +24 -24
- package/.prettierrc +7 -7
- package/CHANGELOG.md +195 -195
- package/DEPLOYMENT.md +624 -624
- package/DEPLOYMENT_CHECKLIST.md +239 -239
- package/DEPLOYMENT_SUMMARY_v1.0.2.md +202 -202
- package/QUICK_START.md +134 -134
- package/README.md +488 -488
- package/RELEASE_NOTES_v1.0.2.md +434 -434
- package/bin/base.js +627 -627
- package/dist/ai/fix-manager.d.ts.map +1 -1
- package/dist/ai/fix-manager.js +1 -1
- package/dist/ai/fix-manager.js.map +1 -1
- package/dist/ai/gemini-analyzer.d.ts.map +1 -1
- package/dist/ai/gemini-analyzer.js +29 -35
- package/dist/ai/gemini-analyzer.js.map +1 -1
- package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
- package/dist/ai/gemini-code-fixer.js +58 -58
- package/dist/ai/gemini-code-fixer.js.map +1 -1
- package/dist/ai/jules-implementer.d.ts +3 -0
- package/dist/ai/jules-implementer.d.ts.map +1 -1
- package/dist/ai/jules-implementer.js +63 -32
- package/dist/ai/jules-implementer.js.map +1 -1
- package/dist/ai/unified-code-fixer.js.map +1 -1
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +1 -1
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/config.js +2 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/fix.d.ts.map +1 -1
- package/dist/commands/fix.js +48 -15
- package/dist/commands/fix.js.map +1 -1
- package/dist/core/api-key-manager.js +2 -2
- package/dist/core/api-key-manager.js.map +1 -1
- package/dist/core/baseguard.d.ts +1 -0
- package/dist/core/baseguard.d.ts.map +1 -1
- package/dist/core/baseguard.js +13 -10
- package/dist/core/baseguard.js.map +1 -1
- package/dist/core/baseline-checker.d.ts.map +1 -1
- package/dist/core/baseline-checker.js +8 -5
- package/dist/core/baseline-checker.js.map +1 -1
- package/dist/core/configuration-recovery.d.ts.map +1 -1
- package/dist/core/configuration-recovery.js +1 -1
- package/dist/core/configuration-recovery.js.map +1 -1
- package/dist/core/debug-logger.d.ts.map +1 -1
- package/dist/core/debug-logger.js +1 -1
- package/dist/core/debug-logger.js.map +1 -1
- package/dist/core/error-handler.d.ts.map +1 -1
- package/dist/core/error-handler.js +2 -1
- package/dist/core/error-handler.js.map +1 -1
- package/dist/core/gitignore-manager.js +5 -5
- package/dist/core/graceful-degradation-manager.d.ts.map +1 -1
- package/dist/core/graceful-degradation-manager.js +16 -16
- package/dist/core/graceful-degradation-manager.js.map +1 -1
- package/dist/core/lazy-loader.d.ts.map +1 -1
- package/dist/core/lazy-loader.js +9 -2
- package/dist/core/lazy-loader.js.map +1 -1
- package/dist/core/memory-manager.d.ts +0 -3
- package/dist/core/memory-manager.d.ts.map +1 -1
- package/dist/core/memory-manager.js.map +1 -1
- package/dist/core/parser-worker.d.ts +2 -0
- package/dist/core/parser-worker.d.ts.map +1 -0
- package/dist/core/parser-worker.js +19 -0
- package/dist/core/parser-worker.js.map +1 -0
- package/dist/core/startup-optimizer.d.ts.map +1 -1
- package/dist/core/startup-optimizer.js +4 -8
- package/dist/core/startup-optimizer.js.map +1 -1
- package/dist/core/system-error-handler.d.ts.map +1 -1
- package/dist/core/system-error-handler.js.map +1 -1
- package/dist/git/automation-engine.d.ts.map +1 -1
- package/dist/git/automation-engine.js +5 -4
- package/dist/git/automation-engine.js.map +1 -1
- package/dist/git/github-manager.d.ts.map +1 -1
- package/dist/git/github-manager.js.map +1 -1
- package/dist/git/hook-manager.js +5 -5
- package/dist/git/hook-manager.js.map +1 -1
- package/dist/parsers/parser-manager.d.ts.map +1 -1
- package/dist/parsers/parser-manager.js +1 -1
- package/dist/parsers/parser-manager.js.map +1 -1
- package/dist/parsers/svelte-parser.js +1 -1
- package/dist/parsers/svelte-parser.js.map +1 -1
- package/dist/parsers/vanilla-parser.d.ts.map +1 -1
- package/dist/parsers/vanilla-parser.js.map +1 -1
- package/dist/parsers/vue-parser.d.ts.map +1 -1
- package/dist/parsers/vue-parser.js.map +1 -1
- package/dist/ui/components.d.ts +1 -1
- package/dist/ui/components.d.ts.map +1 -1
- package/dist/ui/components.js +11 -11
- package/dist/ui/components.js.map +1 -1
- package/dist/ui/terminal-header.js +14 -14
- package/package.json +105 -105
- package/src/ai/__tests__/gemini-analyzer.test.ts +180 -180
- package/src/ai/agentkit-orchestrator.ts +533 -533
- package/src/ai/fix-manager.ts +362 -362
- package/src/ai/gemini-analyzer.ts +665 -671
- package/src/ai/gemini-code-fixer.ts +539 -540
- package/src/ai/index.ts +3 -3
- package/src/ai/jules-implementer.ts +504 -460
- package/src/ai/unified-code-fixer.ts +347 -347
- package/src/commands/automation.ts +343 -343
- package/src/commands/check.ts +298 -299
- package/src/commands/config.ts +584 -583
- package/src/commands/fix.ts +269 -238
- package/src/commands/index.ts +6 -6
- package/src/commands/init.ts +155 -155
- package/src/commands/status.ts +306 -306
- package/src/core/api-key-manager.ts +298 -298
- package/src/core/baseguard.ts +757 -756
- package/src/core/baseline-checker.ts +566 -563
- package/src/core/cache-manager.ts +271 -271
- package/src/core/configuration-recovery.ts +672 -673
- package/src/core/configuration.ts +595 -595
- package/src/core/debug-logger.ts +590 -590
- package/src/core/directory-filter.ts +420 -420
- package/src/core/error-handler.ts +518 -517
- package/src/core/file-processor.ts +337 -337
- package/src/core/gitignore-manager.ts +168 -168
- package/src/core/graceful-degradation-manager.ts +596 -596
- package/src/core/index.ts +16 -16
- package/src/core/lazy-loader.ts +317 -307
- package/src/core/memory-manager.ts +290 -295
- package/src/core/parser-worker.ts +33 -0
- package/src/core/startup-optimizer.ts +246 -255
- package/src/core/system-error-handler.ts +755 -756
- package/src/git/automation-engine.ts +361 -361
- package/src/git/github-manager.ts +190 -192
- package/src/git/hook-manager.ts +210 -210
- package/src/git/index.ts +3 -3
- package/src/index.ts +7 -7
- package/src/parsers/feature-validator.ts +558 -558
- package/src/parsers/index.ts +7 -7
- package/src/parsers/parser-manager.ts +418 -419
- package/src/parsers/parser.ts +25 -25
- package/src/parsers/react-parser-optimized.ts +160 -160
- package/src/parsers/react-parser.ts +358 -358
- package/src/parsers/svelte-parser.ts +510 -510
- package/src/parsers/vanilla-parser.ts +685 -686
- package/src/parsers/vue-parser.ts +476 -478
- package/src/types/index.ts +95 -95
- package/src/ui/components.ts +567 -567
- package/src/ui/help.ts +192 -192
- package/src/ui/index.ts +3 -3
- package/src/ui/prompts.ts +680 -680
- package/src/ui/terminal-header.ts +58 -58
- package/test-build.js +40 -40
- package/test-config-commands.js +55 -55
- package/test-header-simple.js +32 -32
- package/test-terminal-header.js +11 -11
- package/test-ui.js +28 -28
- package/tests/e2e/baseguard.e2e.test.ts +515 -515
- package/tests/e2e/cross-platform.e2e.test.ts +419 -419
- package/tests/e2e/git-integration.e2e.test.ts +486 -486
- package/tests/fixtures/react-project/package.json +13 -13
- package/tests/fixtures/react-project/src/App.css +75 -75
- package/tests/fixtures/react-project/src/App.tsx +76 -76
- package/tests/fixtures/svelte-project/package.json +10 -10
- package/tests/fixtures/svelte-project/src/App.svelte +368 -368
- package/tests/fixtures/vanilla-project/index.html +75 -75
- package/tests/fixtures/vanilla-project/script.js +330 -330
- package/tests/fixtures/vanilla-project/styles.css +358 -358
- package/tests/fixtures/vue-project/package.json +11 -11
- package/tests/fixtures/vue-project/src/App.vue +215 -215
- package/tmp-smoke/.baseguard/backups/config-2026-02-19T12-04-11-067Z-auto.json +30 -0
- package/tmp-smoke/src/bad.css +3 -0
- package/tsconfig.json +34 -34
- package/vitest.config.ts +11 -11
- package/dist/terminal-header.d.ts +0 -12
- 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';
|
package/src/core/lazy-loader.ts
CHANGED
|
@@ -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
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return this.
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
+
}
|