lsh-framework 1.3.0 → 1.3.1

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.
@@ -543,6 +543,42 @@ API_KEY=
543
543
  process.exit(1);
544
544
  }
545
545
  });
546
+ /**
547
+ * Detect if file should use 'export' prefix based on file type
548
+ */
549
+ function shouldUseExport(filePath) {
550
+ const filename = path.basename(filePath);
551
+ const ext = path.extname(filePath);
552
+ // Shell script files - use export
553
+ if (['.sh', '.bash', '.zsh'].includes(ext)) {
554
+ return true;
555
+ }
556
+ // Shell profile/rc files - use export
557
+ if (['.bashrc', '.zshrc', '.profile', '.bash_profile', '.zprofile'].includes(filename)) {
558
+ return true;
559
+ }
560
+ // .envrc files (direnv) - use export
561
+ if (filename === '.envrc' || filename.endsWith('.envrc')) {
562
+ return true;
563
+ }
564
+ // .env files - do NOT use export
565
+ if (filename === '.env' || filename.startsWith('.env.')) {
566
+ return false;
567
+ }
568
+ // Default: no export (safest for most env files)
569
+ return false;
570
+ }
571
+ /**
572
+ * Format a line based on file type
573
+ */
574
+ function formatEnvLine(key, value, filePath) {
575
+ const needsQuotes = /[\s#]/.test(value);
576
+ const quotedValue = needsQuotes ? `"${value}"` : value;
577
+ const useExport = shouldUseExport(filePath);
578
+ return useExport
579
+ ? `export ${key}=${quotedValue}`
580
+ : `${key}=${quotedValue}`;
581
+ }
546
582
  /**
547
583
  * Set a single secret value
548
584
  */
@@ -563,12 +599,11 @@ API_KEY=
563
599
  newLines.push(line);
564
600
  continue;
565
601
  }
566
- const match = line.match(/^([^=]+)=(.*)$/);
602
+ // Match both with and without export
603
+ const match = line.match(/^(?:export\s+)?([^=]+)=(.*)$/);
567
604
  if (match && match[1].trim() === key) {
568
- // Quote values with spaces or special characters
569
- const needsQuotes = /[\s#]/.test(value);
570
- const quotedValue = needsQuotes ? `"${value}"` : value;
571
- newLines.push(`${key}=${quotedValue}`);
605
+ // Use appropriate format for this file type
606
+ newLines.push(formatEnvLine(key, value, envPath));
572
607
  found = true;
573
608
  }
574
609
  else {
@@ -579,9 +614,8 @@ API_KEY=
579
614
  }
580
615
  // If key wasn't found, append it
581
616
  if (!found) {
582
- const needsQuotes = /[\s#]/.test(value);
583
- const quotedValue = needsQuotes ? `"${value}"` : value;
584
- content = content.trimRight() + `\n${key}=${quotedValue}\n`;
617
+ const formattedLine = formatEnvLine(key, value, envPath);
618
+ content = content.trimRight() + `\n${formattedLine}\n`;
585
619
  }
586
620
  fs.writeFileSync(envPath, content, 'utf8');
587
621
  console.log(`✅ Set ${key}`);
@@ -638,8 +672,8 @@ API_KEY=
638
672
  // Skip comments and empty lines
639
673
  if (trimmed.startsWith('#') || !trimmed)
640
674
  continue;
641
- // Parse KEY=VALUE format
642
- const match = trimmed.match(/^([^=]+)=(.*)$/);
675
+ // Parse KEY=VALUE format (with or without export)
676
+ const match = trimmed.match(/^(?:export\s+)?([^=]+)=(.*)$/);
643
677
  if (!match) {
644
678
  errors.push(`Invalid format: ${trimmed}`);
645
679
  continue;
@@ -671,15 +705,14 @@ API_KEY=
671
705
  newLines.push(line);
672
706
  continue;
673
707
  }
674
- const match = line.match(/^([^=]+)=(.*)$/);
708
+ // Match both with and without export
709
+ const match = line.match(/^(?:export\s+)?([^=]+)=(.*)$/);
675
710
  if (match) {
676
711
  const key = match[1].trim();
677
712
  if (newKeys.has(key)) {
678
- // Update existing key
713
+ // Update existing key with appropriate format
679
714
  const value = newKeys.get(key);
680
- const needsQuotes = /[\s#]/.test(value);
681
- const quotedValue = needsQuotes ? `"${value}"` : value;
682
- newLines.push(`${key}=${quotedValue}`);
715
+ newLines.push(formatEnvLine(key, value, envPath));
683
716
  newKeys.delete(key); // Mark as processed
684
717
  hasContent = true;
685
718
  }
@@ -696,13 +729,12 @@ API_KEY=
696
729
  }
697
730
  // Add new keys that weren't in the existing file
698
731
  for (const [key, value] of newKeys.entries()) {
699
- const needsQuotes = /[\s#]/.test(value);
700
- const quotedValue = needsQuotes ? `"${value}"` : value;
732
+ const formattedLine = formatEnvLine(key, value, envPath);
701
733
  if (hasContent) {
702
- newLines.push(`${key}=${quotedValue}`);
734
+ newLines.push(formattedLine);
703
735
  }
704
736
  else {
705
- newLines.push(`${key}=${quotedValue}`);
737
+ newLines.push(formattedLine);
706
738
  hasContent = true;
707
739
  }
708
740
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lsh-framework",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Simple, cross-platform encrypted secrets manager with automatic sync and multi-environment support. Just run lsh sync and start managing your secrets.",
5
5
  "main": "dist/app.js",
6
6
  "bin": {