@gxp-dev/tools 2.0.13 → 2.0.15

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.
@@ -451,30 +451,33 @@ export default function App({ autoStart, args }: AppProps) {
451
451
  };
452
452
 
453
453
  const addSystemLog = (message: string) => {
454
- // Find or create system service for general messages
455
- let systemService = services.find(s => s.id === 'system');
456
- if (!systemService) {
457
- const newService: Service = {
458
- id: 'system',
459
- name: 'System',
460
- status: 'running',
461
- logs: [message],
462
- };
463
- setServices(prev => {
464
- const updated = [...prev, newService];
465
- return updated;
466
- });
467
- if (services.length === 0) setActiveTab(0);
468
- } else {
469
- setServices(prev => prev.map(s =>
470
- s.id === 'system' ? { ...s, logs: [...s.logs, message] } : s
471
- ));
472
- }
454
+ // Use functional update to properly handle rapid successive calls
455
+ setServices(prev => {
456
+ const existingSystem = prev.find(s => s.id === 'system');
457
+ if (existingSystem) {
458
+ // Add message to existing system service
459
+ return prev.map(s =>
460
+ s.id === 'system' ? { ...s, logs: [...s.logs, message] } : s
461
+ );
462
+ } else {
463
+ // Create new system service with the message
464
+ const newService: Service = {
465
+ id: 'system',
466
+ name: 'System',
467
+ status: 'running',
468
+ logs: [message],
469
+ };
470
+ return [...prev, newService];
471
+ }
472
+ });
473
473
 
474
474
  // Switch to system tab
475
475
  setTimeout(() => {
476
- const sysIdx = services.findIndex(s => s.id === 'system');
477
- if (sysIdx >= 0) setActiveTab(sysIdx);
476
+ setServices(current => {
477
+ const sysIdx = current.findIndex(s => s.id === 'system');
478
+ if (sysIdx >= 0) setActiveTab(sysIdx);
479
+ return current; // Don't modify, just read
480
+ });
478
481
  }, 50);
479
482
  };
480
483
 
@@ -524,11 +527,21 @@ export default function App({ autoStart, args }: AppProps) {
524
527
  // Use dynamic imports for ES modules
525
528
  const path = await import('path');
526
529
  const fs = await import('fs');
530
+ const url = await import('url');
527
531
  const { createRequire } = await import('module');
528
532
 
533
+ // Get the directory of this file and resolve to the utils directory
534
+ const __filename = url.fileURLToPath(import.meta.url);
535
+ const __dirname = path.dirname(__filename);
536
+
537
+ // The compiled JS is in dist/tui/, utils is in bin/lib/utils/
538
+ // From dist/tui/ we need to go up to package root, then into bin/lib/utils/
539
+ const packageRoot = path.resolve(__dirname, '..', '..');
540
+ const utilsPath = path.join(packageRoot, 'bin', 'lib', 'utils', 'extract-config.js');
541
+
529
542
  // Create a require function to load CommonJS modules
530
- const require = createRequire(import.meta.url);
531
- const extractConfigUtils = require('../utils/extract-config.js') as {
543
+ const requireCjs = createRequire(import.meta.url);
544
+ const extractConfigUtils = requireCjs(utilsPath) as {
532
545
  extractConfigFromSource: (srcDir: string) => ExtractedConfig;
533
546
  mergeConfig: (existing: Record<string, unknown>, extracted: ExtractedConfig, options: { overwrite: boolean }) => Record<string, unknown>;
534
547
  generateSummary: (config: ExtractedConfig) => string;
@@ -20,6 +20,37 @@ function getToolkitRoot(): string {
20
20
  return path.resolve(__dirname, '..', '..', '..');
21
21
  }
22
22
 
23
+ /**
24
+ * Generate extension defaults based on environment variables
25
+ * This creates a defaults.json file that the popup.js reads on load
26
+ */
27
+ function generateExtensionDefaults(extensionPath: string, useHttps: boolean, port: number | string): void {
28
+ const protocol = useHttps ? 'https' : 'http';
29
+ const baseUrl = `${protocol}://localhost:${port}`;
30
+
31
+ const defaults = {
32
+ // Extension should be enabled by default when launched from CLI
33
+ enabled: true,
34
+ // JS redirect URL based on env
35
+ jsRedirectUrl: `${baseUrl}/src/Plugin.vue`,
36
+ // CSS redirect URL (empty by default, uses blank CSS)
37
+ cssRedirectUrl: '',
38
+ // CSS override should be enabled by default
39
+ cssRuleEnabled: true,
40
+ // Return blank CSS by default
41
+ cssReturnBlank: true,
42
+ // Use custom URL pattern by default
43
+ jsUseCustomPattern: true,
44
+ cssUseCustomPattern: true,
45
+ // Cache settings
46
+ clearCacheOnEnable: true,
47
+ disableCacheForRedirects: true,
48
+ };
49
+
50
+ const defaultsPath = path.join(extensionPath, 'defaults.json');
51
+ fs.writeFileSync(defaultsPath, JSON.stringify(defaults, null, 2));
52
+ }
53
+
23
54
  // Find the extension path (project-local or toolkit built-in)
24
55
  function findExtensionPath(browser: BrowserType, cwd: string): string | null {
25
56
  // Check local project first
@@ -64,6 +95,9 @@ export function startExtension(options: ExtensionOptions): void {
64
95
  return;
65
96
  }
66
97
 
98
+ // Generate defaults.json for the extension based on environment
99
+ generateExtensionDefaults(extensionPath, useHttps, port);
100
+
67
101
  if (browser === 'firefox') {
68
102
  const config: ServiceConfig = {
69
103
  id: serviceId,
@@ -56,7 +56,7 @@
56
56
  },
57
57
 
58
58
  "web_accessible_resources": [{
59
- "resources": ["content.js", "inspector.js", "panel.html", "panel.js"],
59
+ "resources": ["content.js", "inspector.js", "panel.html", "panel.js", "defaults.json"],
60
60
  "matches": ["<all_urls>"]
61
61
  }],
62
62