@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.
Files changed (3) hide show
  1. package/binary.js +51 -14
  2. package/index.js +1 -1
  3. 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
- console.log('Extracting binary...');
91
- tar.x({
92
- file: tarPath,
93
- cwd: binDir,
94
- strip: 0,
95
- }).then(() => {
96
- const binaryPath = path.join(binDir, 'avail-node')
97
- fs.chmodSync(binaryPath, '755')
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(binaryPath);
100
- }).catch((e) => {
101
- console.log("error", e);
102
- reject(e);
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
@@ -22,7 +22,7 @@ const main = async () => {
22
22
 
23
23
  for (let i = 0; i < rawArgs.length; i++) {
24
24
  const arg = rawArgs[i]
25
- if (arg === '--docker') {
25
+ if (arg === '--docker' || arg === '--binary') {
26
26
  continue
27
27
  }
28
28
  if (arg === '--docker-tag') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paimaexample/npm-avail-node",
3
- "version": "0.3.122",
3
+ "version": "0.3.124",
4
4
  "description": "A wrapper for the Avail node binary",
5
5
  "main": "index.js",
6
6
  "bin": {