@paimaexample/npm-avail-node 0.3.122 → 0.3.124
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/binary.js +51 -14
- package/index.js +1 -1
- package/package.json +1 -1
package/binary.js
CHANGED
|
@@ -5,6 +5,8 @@ const fs = require('fs')
|
|
|
5
5
|
const path = require('path')
|
|
6
6
|
const { spawn } = require('child_process')
|
|
7
7
|
|
|
8
|
+
const FINAL_BINARY_NAME = 'avail-node'
|
|
9
|
+
|
|
8
10
|
const downloadLinks = {
|
|
9
11
|
'x86_64-ubuntu-2404': 'https://github.com/availproject/avail/releases/download/v2.3.0.1-rc1/x86_64-ubuntu-2404-avail-node.tar.gz',
|
|
10
12
|
'arm64-ubuntu-2204': 'https://github.com/availproject/avail/releases/download/v2.3.0.1-rc1/arm64-ubuntu-2204-avail-node.tar.gz',
|
|
@@ -61,6 +63,27 @@ const getBinaryKey = () => {
|
|
|
61
63
|
})
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
const findExtractedBinary = (dir) => {
|
|
67
|
+
const stack = [dir]
|
|
68
|
+
while (stack.length > 0) {
|
|
69
|
+
const currentDir = stack.pop()
|
|
70
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true })
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
const entryPath = path.join(currentDir, entry.name)
|
|
73
|
+
if (entry.isDirectory()) {
|
|
74
|
+
stack.push(entryPath)
|
|
75
|
+
} else if (
|
|
76
|
+
entry.isFile() &&
|
|
77
|
+
entry.name.startsWith('avail-node') &&
|
|
78
|
+
!entry.name.endsWith('.tar.gz')
|
|
79
|
+
) {
|
|
80
|
+
return entryPath
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
|
|
64
87
|
const downloadBinary = async (distroKey) => {
|
|
65
88
|
const link = downloadLinks[distroKey]
|
|
66
89
|
if (!link) {
|
|
@@ -86,21 +109,35 @@ const downloadBinary = async (distroKey) => {
|
|
|
86
109
|
dest.end();
|
|
87
110
|
|
|
88
111
|
return new Promise((resolve, reject) => {
|
|
89
|
-
dest.on('finish', () => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
dest.on('finish', async () => {
|
|
113
|
+
try {
|
|
114
|
+
console.log('Extracting binary...');
|
|
115
|
+
await tar.x({
|
|
116
|
+
file: tarPath,
|
|
117
|
+
cwd: binDir,
|
|
118
|
+
strip: 0,
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const extractedBinary = findExtractedBinary(binDir)
|
|
122
|
+
if (!extractedBinary) {
|
|
123
|
+
throw new Error('Failed to locate extracted avail-node binary')
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const finalBinaryPath = path.join(binDir, FINAL_BINARY_NAME)
|
|
127
|
+
if (extractedBinary !== finalBinaryPath) {
|
|
128
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
129
|
+
fs.unlinkSync(finalBinaryPath)
|
|
130
|
+
}
|
|
131
|
+
fs.renameSync(extractedBinary, finalBinaryPath)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fs.chmodSync(finalBinaryPath, 0o755)
|
|
98
135
|
fs.unlinkSync(tarPath);
|
|
99
|
-
resolve(
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
136
|
+
resolve(finalBinaryPath);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
console.log("error", e);
|
|
139
|
+
reject(e);
|
|
140
|
+
}
|
|
104
141
|
});
|
|
105
142
|
dest.on('error', reject);
|
|
106
143
|
});
|
package/index.js
CHANGED