satoridb 1.1.2 → 1.1.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/postinstall.js +100 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoridb",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Install satori",
5
5
  "bin" : {
6
6
  "satori" : "cli.js"
package/postinstall.js CHANGED
@@ -20,38 +20,113 @@ else {
20
20
  }
21
21
 
22
22
  const tmpDir = path.join(os.tmpdir(), "satori-temp");
23
- fs.mkdirSync(tmpDir, { recursive: true });
24
-
25
23
  const zipPath = path.join(tmpDir, fileName);
26
24
  const installDir = path.join(os.homedir(), ".satori", "bin");
27
25
  const binName = platform === "win32" ? "satori.exe" : "satori";
28
26
  const binFullPath = path.join(installDir, binName);
29
27
 
30
- // Descargar ZIP
28
+
29
+ // Crear directorio temporal y subdirectorios con mejor manejo de errores
30
+ try {
31
+ fs.mkdirSync(tmpDir, { recursive: true });
32
+
33
+ // Crear el subdirectorio específico de la plataforma si es necesario
34
+ const platformSubDir = path.dirname(zipPath);
35
+ if (platformSubDir !== tmpDir) {
36
+ fs.mkdirSync(platformSubDir, { recursive: true });
37
+ }
38
+ } catch (err) {
39
+ console.error("❌ Error creating directories:", err.message);
40
+ process.exit(1);
41
+ }
42
+
43
+ // Descargar ZIP con mejor manejo de errores
31
44
  function downloadZip(url, dest, cb) {
45
+ console.log(`🔽 Downloading from: ${url}`);
46
+
32
47
  const file = fs.createWriteStream(dest);
33
- https.get(url, response => {
48
+
49
+ const request = https.get(url, response => {
50
+ console.log(`📡 Response status: ${response.statusCode}`);
51
+
34
52
  if (response.statusCode !== 200) {
35
53
  console.error("❌ Download failed:", response.statusCode);
54
+ file.close();
55
+ fs.unlink(dest, () => {}); // Limpiar archivo parcial
36
56
  process.exit(1);
37
57
  }
38
58
 
39
59
  response.pipe(file);
60
+
40
61
  file.on("finish", () => {
41
- file.close(cb);
62
+ file.close(() => {
63
+ console.log(`✅ Download completed: ${dest}`);
64
+ // Verificar que el archivo existe y tiene contenido
65
+ try {
66
+ const stats = fs.statSync(dest);
67
+ if (stats.size === 0) {
68
+ console.error("❌ Downloaded file is empty");
69
+ fs.unlink(dest, () => {});
70
+ process.exit(1);
71
+ }
72
+ cb();
73
+ } catch (err) {
74
+ console.error("❌ Error verifying downloaded file:", err.message);
75
+ process.exit(1);
76
+ }
77
+ });
42
78
  });
43
- }).on('error', err => {
79
+
80
+ file.on("error", err => {
81
+ console.error("❌ Error writing file:", err.message);
82
+ fs.unlink(dest, () => {});
83
+ process.exit(1);
84
+ });
85
+ });
86
+
87
+ request.on('error', err => {
44
88
  console.error("❌ Network error:", err.message);
89
+ file.close();
90
+ fs.unlink(dest, () => {});
91
+ process.exit(1);
92
+ });
93
+
94
+ request.setTimeout(30000, () => {
95
+ console.error("❌ Download timeout");
96
+ request.destroy();
97
+ file.close();
98
+ fs.unlink(dest, () => {});
45
99
  process.exit(1);
46
100
  });
47
101
  }
48
102
 
49
- // Extraer ZIP
103
+ // Extraer ZIP con mejor manejo de errores
50
104
  function extractZip(src, dest) {
105
+
106
+
51
107
  try {
108
+ // Verificar que el archivo ZIP existe
109
+ if (!fs.existsSync(src)) {
110
+ console.error(`❌ ZIP file not found: ${src}`);
111
+ process.exit(1);
112
+ }
113
+
52
114
  const zip = new AdmZip(src);
53
115
  zip.extractAllTo(dest, true);
54
- if (platform !== "win32") chmodSync(path.join(dest, binName), 0o755);
116
+
117
+ // Verificar que el binario fue extraído
118
+ const binPath = path.join(dest, binName);
119
+ if (!fs.existsSync(binPath)) {
120
+ console.error(`❌ Binary not found after extraction: ${binPath}`);
121
+ process.exit(1);
122
+ }
123
+
124
+ if (platform !== "win32") {
125
+ chmodSync(binPath, 0o755);
126
+ console.log(`✅ Set executable permissions on: ${binPath}`);
127
+ }
128
+
129
+ console.log(`✅ Extraction completed`);
55
130
  } catch (err) {
56
131
  console.error("❌ Error extracting zip:", err.message);
57
132
  process.exit(1);
@@ -62,16 +137,30 @@ function extractZip(src, dest) {
62
137
  console.log(`🔽 Downloading Satori ${platform}/${arch}...`);
63
138
 
64
139
  downloadZip(`${baseURL}/${fileName}`, zipPath, () => {
65
- fs.mkdirSync(installDir, { recursive: true });
140
+ try {
141
+ fs.mkdirSync(installDir, { recursive: true });
142
+ console.log(`✅ Install directory created/verified`);
143
+ } catch (err) {
144
+ console.error("❌ Error creating install directory:", err.message);
145
+ process.exit(1);
146
+ }
147
+
66
148
  extractZip(zipPath, installDir);
67
149
  console.log(`✅ Binary installed in: ${binFullPath}\n`);
68
150
 
151
+ // Limpiar archivo temporal
152
+ try {
153
+ fs.unlinkSync(zipPath);
154
+ } catch (err) {
155
+ console.warn(`⚠️ Could not clean up temporary file: ${err.message}`);
156
+ }
157
+
69
158
  const shell = process.env.SHELL || "";
70
159
  const profileFile = shell.includes("zsh") ? ".zshrc" : ".bashrc";
71
160
 
72
161
  const exportLine = `export PATH="$HOME/.satori/bin:$PATH"`;
73
162
 
74
- console.log(`💡 Add this to your ~/${profileFile}:\n`);
163
+ /* console.log(`💡 Add this to your ~/${profileFile}:\n`);
75
164
  console.log(` ${exportLine}\n`);
76
- console.log(`Then run: source ~/${profileFile}\n`);
165
+ console.log(`Then run: source ~/${profileFile}\n`);*/
77
166
  });