smoonb 0.0.35 → 0.0.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smoonb",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "description": "Complete Supabase backup and migration tool - EXPERIMENTAL VERSION - USE AT YOUR OWN RISK",
5
5
  "preferGlobal": false,
6
6
  "preventGlobalInstall": true,
@@ -414,23 +414,40 @@ async function backupEdgeFunctionsWithDocker(projectId, accessToken, backupDir)
414
414
  let successCount = 0;
415
415
  let errorCount = 0;
416
416
 
417
- // ✅ Baixar cada Edge Function usando Supabase CLI via Docker
417
+ // ✅ Baixar cada Edge Function DIRETAMENTE para o backup (sem tocar em ./supabase/functions)
418
418
  for (const func of functions) {
419
419
  try {
420
420
  console.log(chalk.gray(` - Baixando: ${func.name}...`));
421
421
 
422
- // Usar comando oficial do Supabase CLI via Docker
423
- await execAsync(`supabase functions download ${func.name}`, {
424
- cwd: process.cwd(),
425
- timeout: 60000 // 60 segundos timeout
422
+ // Criar diretório da função DIRETAMENTE no backup
423
+ const functionTargetDir = path.join(functionsDir, func.name);
424
+ await ensureDir(functionTargetDir);
425
+
426
+ // Baixar Edge Function via Supabase CLI DIRETAMENTE para o backup
427
+ const { execSync } = require('child_process');
428
+ const tempBackupDir = path.join(backupDir, 'temp-supabase-download');
429
+
430
+ // Criar estrutura temp para download sem contaminar ./supabase/
431
+ await ensureDir(tempBackupDir);
432
+
433
+ // Download para diretório temporário
434
+ execSync(`supabase functions download ${func.name}`, {
435
+ cwd: tempBackupDir,
436
+ timeout: 60000,
437
+ stdio: 'pipe'
426
438
  });
427
439
 
428
- // Mover arquivos baixados para o diretório de backup
429
- const sourceDir = path.join(process.cwd(), 'supabase', 'functions', func.name);
430
- const targetDir = path.join(functionsDir, func.name);
440
+ // Mover de temp para o backup final
441
+ const tempFunctionDir = path.join(tempBackupDir, 'supabase', 'functions', func.name);
431
442
 
432
- if (await fs.access(sourceDir).then(() => true).catch(() => false)) {
433
- await copyDir(sourceDir, targetDir);
443
+ // Verificar se existe usando fs.promises.access
444
+ try {
445
+ await fs.access(tempFunctionDir);
446
+ await copyDir(tempFunctionDir, functionTargetDir);
447
+
448
+ // Limpar diretório temporário
449
+ await fs.rm(tempBackupDir, { recursive: true, force: true }).catch(() => {});
450
+
434
451
  console.log(chalk.green(` ✅ ${func.name} baixada com sucesso`));
435
452
  successCount++;
436
453
 
@@ -438,9 +455,9 @@ async function backupEdgeFunctionsWithDocker(projectId, accessToken, backupDir)
438
455
  name: func.name,
439
456
  slug: func.name,
440
457
  version: func.version || 'unknown',
441
- files: await fs.access(targetDir).then(() => fs.readdir(targetDir)).catch(() => [])
458
+ files: await fs.readdir(functionTargetDir).catch(() => [])
442
459
  });
443
- } else {
460
+ } catch (innerError) {
444
461
  throw new Error('Diretório não encontrado após download');
445
462
  }
446
463