satoridb 1.1.2 β†’ 1.1.3

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