@gxp-dev/tools 2.0.13 → 2.0.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.
@@ -524,11 +524,21 @@ export default function App({ autoStart, args }: AppProps) {
524
524
  // Use dynamic imports for ES modules
525
525
  const path = await import('path');
526
526
  const fs = await import('fs');
527
+ const url = await import('url');
527
528
  const { createRequire } = await import('module');
528
529
 
530
+ // Get the directory of this file and resolve to the utils directory
531
+ const __filename = url.fileURLToPath(import.meta.url);
532
+ const __dirname = path.dirname(__filename);
533
+
534
+ // The compiled JS is in dist/tui/, utils is in bin/lib/utils/
535
+ // From dist/tui/ we need to go up to package root, then into bin/lib/utils/
536
+ const packageRoot = path.resolve(__dirname, '..', '..');
537
+ const utilsPath = path.join(packageRoot, 'bin', 'lib', 'utils', 'extract-config.js');
538
+
529
539
  // Create a require function to load CommonJS modules
530
- const require = createRequire(import.meta.url);
531
- const extractConfigUtils = require('../utils/extract-config.js') as {
540
+ const requireCjs = createRequire(import.meta.url);
541
+ const extractConfigUtils = requireCjs(utilsPath) as {
532
542
  extractConfigFromSource: (srcDir: string) => ExtractedConfig;
533
543
  mergeConfig: (existing: Record<string, unknown>, extracted: ExtractedConfig, options: { overwrite: boolean }) => Record<string, unknown>;
534
544
  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