@blimu/backend 0.4.9 → 0.4.10

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/bin/blimu CHANGED
Binary file
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "repository": "https://github.com/blimu/blimu-ts",
4
4
  "author": "viniciusdacal",
5
5
  "license": "MIT",
6
- "version": "0.4.9",
6
+ "version": "0.4.10",
7
7
  "description": "TypeScript SDK for Blimu API (auto-generated)",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
@@ -45,6 +45,45 @@ function getPlatformInfo() {
45
45
  };
46
46
  }
47
47
 
48
+ /**
49
+ * Verify that an existing binary matches the current platform/architecture
50
+ * Returns true if the binary is correct, false otherwise
51
+ */
52
+ function verifyBinaryArchitecture(binaryPath) {
53
+ try {
54
+ // Use 'file' command to check binary type (available on macOS and Linux)
55
+ const output = execSync(`file "${binaryPath}"`, { encoding: 'utf8' });
56
+
57
+ const platform = process.platform;
58
+ const arch = process.arch;
59
+
60
+ if (platform === 'darwin') {
61
+ // macOS: should be "Mach-O 64-bit executable arm64" or "Mach-O 64-bit executable x86_64"
62
+ const expectedArch = arch === 'arm64' ? 'arm64' : 'x86_64';
63
+ if (!output.includes('Mach-O') || !output.includes(expectedArch)) {
64
+ return false;
65
+ }
66
+ } else if (platform === 'linux') {
67
+ // Linux: should be "ELF 64-bit LSB executable, x86-64" or "ELF 64-bit LSB executable, ARM aarch64"
68
+ const expectedArch = arch === 'arm64' ? 'ARM aarch64' : 'x86-64';
69
+ if (!output.includes('ELF') || !output.includes(expectedArch)) {
70
+ return false;
71
+ }
72
+ } else if (platform === 'win32') {
73
+ // Windows: should be "PE32+ executable"
74
+ if (!output.includes('PE32+')) {
75
+ return false;
76
+ }
77
+ }
78
+
79
+ return true;
80
+ } catch (err) {
81
+ // If 'file' command fails or is not available, assume binary is incorrect to be safe
82
+ // This will trigger a re-download
83
+ return false;
84
+ }
85
+ }
86
+
48
87
  function downloadFile(url, dest) {
49
88
  return new Promise((resolve, reject) => {
50
89
  const file = fs.createWriteStream(dest);
@@ -162,19 +201,32 @@ async function main(version) {
162
201
 
163
202
  // Check if binary already exists and is executable
164
203
  if (fs.existsSync(binaryPath)) {
165
- try {
166
- // Try to make it executable (Unix only)
167
- if (process.platform !== 'win32') {
168
- fs.chmodSync(binaryPath, 0o755);
204
+ // Verify the binary matches the current platform/architecture
205
+ const isCorrectArchitecture = verifyBinaryArchitecture(binaryPath);
206
+
207
+ if (isCorrectArchitecture) {
208
+ try {
209
+ // Try to make it executable (Unix only)
210
+ if (process.platform !== 'win32') {
211
+ fs.chmodSync(binaryPath, 0o755);
212
+ }
213
+ if (version) {
214
+ console.log(`✅ Blimu CLI binary (v${version}) already exists at ${binaryPath}`);
215
+ } else {
216
+ console.log(`✅ Blimu CLI binary already exists at ${binaryPath}`);
217
+ }
218
+ return;
219
+ } catch (err) {
220
+ // If we can't check/update permissions, continue to download
169
221
  }
170
- if (version) {
171
- console.log(`✅ Blimu CLI binary (v${version}) already exists at ${binaryPath}`);
172
- } else {
173
- console.log(`✅ Blimu CLI binary already exists at ${binaryPath}`);
222
+ } else {
223
+ // Binary exists but is for wrong platform/architecture - delete it
224
+ console.log(`⚠️ Existing binary is for wrong platform/architecture, will re-download...`);
225
+ try {
226
+ fs.unlinkSync(binaryPath);
227
+ } catch (err) {
228
+ console.warn(`Warning: Could not delete incorrect binary: ${err.message}`);
174
229
  }
175
- return;
176
- } catch (err) {
177
- // If we can't check/update permissions, continue to download
178
230
  }
179
231
  }
180
232