@juniorsir/vessel 1.0.1 → 1.0.2
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 +1 -1
- package/scripts/install.js +33 -54
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -1,82 +1,61 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const https = require('https');
|
|
4
|
+
const { execSync } = require('child_process');
|
|
4
5
|
|
|
5
|
-
//
|
|
6
|
-
const
|
|
7
|
-
const REPO = process.env.VESSEL_REPO || 'juniorsir/vessel';
|
|
6
|
+
const VERSION = 'v1.0.2'; // Change this to match your GitHub Release tag!
|
|
7
|
+
const REPO = 'juniorsir/vessel';
|
|
8
8
|
const BIN_DIR = path.join(__dirname, '../bin');
|
|
9
9
|
const BIN_PATH = path.join(BIN_DIR, 'vessel-native');
|
|
10
10
|
|
|
11
|
-
//
|
|
11
|
+
// Expanded map to catch Termux (android) and Standard Linux (linux)
|
|
12
12
|
const platforms = {
|
|
13
13
|
'linux-x64': 'vessel-linux-amd64',
|
|
14
14
|
'linux-arm64': 'vessel-linux-arm64',
|
|
15
|
-
'android-arm64': 'vessel-linux-arm64', // Termux
|
|
16
|
-
'android-x64': 'vessel-linux-amd64' //
|
|
15
|
+
'android-arm64': 'vessel-linux-arm64', // Termux identifier!
|
|
16
|
+
'android-x64': 'vessel-linux-amd64' // Android x86 emulators
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const key = `${process.platform}-${process.arch}`;
|
|
20
20
|
const assetName = platforms[key];
|
|
21
21
|
|
|
22
22
|
if (!assetName) {
|
|
23
|
-
console.error(
|
|
24
|
-
console.error(`Vessel relies on low-level Linux namespaces and is only supported on Linux and Android (Termux).`);
|
|
23
|
+
console.error(`[vessel-npm] Unsupported platform/architecture: ${key}`);
|
|
25
24
|
process.exit(1);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
if (!fs.existsSync(BIN_DIR)) {
|
|
29
|
-
fs.mkdirSync(BIN_DIR
|
|
28
|
+
fs.mkdirSync(BIN_DIR);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
const url = `https://github.com/${REPO}/releases/download/${VERSION}/${assetName}`;
|
|
33
|
-
console.log(`\x1b[1m\x1b[36m[vessel-npm]\x1b[0m Fetching native binary for \x1b[33m${key}\x1b[0m...`);
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
function downloadFile(url, dest, redirectCount = 0) {
|
|
37
|
-
if (redirectCount > 5) {
|
|
38
|
-
console.error('\x1b[31m[vessel-npm] Error: Too many redirects.\x1b[0m');
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
https.get(url, (res) => {
|
|
43
|
-
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
44
|
-
return downloadFile(res.headers.location, dest, redirectCount + 1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (res.statusCode !== 200) {
|
|
48
|
-
console.error(`\x1b[31m[vessel-npm] Error downloading binary: HTTP ${res.statusCode}\x1b[0m`);
|
|
49
|
-
console.error(`Attempted URL: ${url}`);
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const totalBytes = parseInt(res.headers['content-length'], 10);
|
|
54
|
-
let downloadedBytes = 0;
|
|
55
|
-
const file = fs.createWriteStream(dest);
|
|
56
|
-
|
|
57
|
-
res.on('data', (chunk) => {
|
|
58
|
-
downloadedBytes += chunk.length;
|
|
59
|
-
if (totalBytes) {
|
|
60
|
-
const percent = ((downloadedBytes / totalBytes) * 100).toFixed(1);
|
|
61
|
-
process.stdout.write(`\r\x1b[36m ↳ Downloading:\x1b[0m ${percent}% (${(downloadedBytes / 1024 / 1024).toFixed(2)} MB)`);
|
|
62
|
-
} else {
|
|
63
|
-
process.stdout.write(`\r\x1b[36m ↳ Downloading:\x1b[0m ${(downloadedBytes / 1024 / 1024).toFixed(2)} MB`);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
res.pipe(file);
|
|
33
|
+
console.log(`[vessel-npm] Fetching native core for ${key}...`);
|
|
68
34
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
35
|
+
const file = fs.createWriteStream(BIN_PATH);
|
|
36
|
+
https.get(url, (response) => {
|
|
37
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
38
|
+
// Follow GitHub redirect
|
|
39
|
+
https.get(response.headers.location, (redirectResponse) => {
|
|
40
|
+
redirectResponse.pipe(file);
|
|
73
41
|
});
|
|
42
|
+
} else {
|
|
43
|
+
response.pipe(file);
|
|
44
|
+
}
|
|
74
45
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
46
|
+
file.on('finish', () => {
|
|
47
|
+
file.close();
|
|
48
|
+
|
|
49
|
+
// Explicitly make the binary executable using native shell commands
|
|
50
|
+
try {
|
|
51
|
+
execSync(`chmod +x "${BIN_PATH}"`);
|
|
52
|
+
console.log('[vessel-npm] Native binary installed successfully.');
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error('[vessel-npm] Warning: Could not chmod binary natively.');
|
|
55
|
+
}
|
|
79
56
|
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
57
|
+
}).on('error', (err) => {
|
|
58
|
+
fs.unlink(BIN_PATH, () => {});
|
|
59
|
+
console.error(`[vessel-npm] Failed to download binary: ${err.message}`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
});
|