@paimaexample/npm-midnight-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 +58 -16
- package/index.js +5 -5
- package/package.json +1 -1
- package/run_midnight_node.js +3 -5
package/binary.js
CHANGED
|
@@ -4,7 +4,8 @@ const axios = require("axios");
|
|
|
4
4
|
const extract = require("extract-zip");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
|
|
7
|
-
const CURRENT_BINARY_VERSION = "0.12.
|
|
7
|
+
const CURRENT_BINARY_VERSION = "0.12.1";
|
|
8
|
+
const FINAL_BINARY_NAME = "midnight-node";
|
|
8
9
|
|
|
9
10
|
/*
|
|
10
11
|
@returns {string} The platform and architecture of the current machine.
|
|
@@ -64,25 +65,66 @@ async function downloadAndSaveBinary() {
|
|
|
64
65
|
/*
|
|
65
66
|
@returns {Promise<void>} Unzips the binary for the current platform.
|
|
66
67
|
*/
|
|
68
|
+
function findExtractedBinary(binaryDir, platform) {
|
|
69
|
+
const candidateNames = new Set([
|
|
70
|
+
FINAL_BINARY_NAME,
|
|
71
|
+
`midnight-node-${platform}`,
|
|
72
|
+
`midnight-node-${platform}-${CURRENT_BINARY_VERSION}`,
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
const explore = (dir) => {
|
|
76
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
77
|
+
const entryPath = path.join(dir, entry);
|
|
78
|
+
const entryStats = fs.statSync(entryPath);
|
|
79
|
+
|
|
80
|
+
if (entryStats.isFile() && candidateNames.has(entry)) {
|
|
81
|
+
return entryPath;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (entryStats.isDirectory()) {
|
|
85
|
+
for (const candidate of candidateNames) {
|
|
86
|
+
const nestedPath = path.join(entryPath, candidate);
|
|
87
|
+
if (fs.existsSync(nestedPath) && fs.statSync(nestedPath).isFile()) {
|
|
88
|
+
return nestedPath;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const nestedResult = explore(entryPath);
|
|
92
|
+
if (nestedResult) return nestedResult;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return explore(binaryDir);
|
|
99
|
+
}
|
|
100
|
+
|
|
67
101
|
async function unzipBinary() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
102
|
+
const binaryDir = path.join(__dirname, "midnight-node");
|
|
103
|
+
await extract(path.join(__dirname, FILE_NAME), { dir: binaryDir });
|
|
71
104
|
const platform = getPlatform();
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
const finalBinaryPath = path.join(binaryDir, FINAL_BINARY_NAME);
|
|
106
|
+
const extractedBinaryPath = findExtractedBinary(binaryDir, platform);
|
|
107
|
+
|
|
108
|
+
if (!extractedBinaryPath) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Expected binary not found after extraction in ${binaryDir}`,
|
|
78
111
|
);
|
|
79
112
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
113
|
+
|
|
114
|
+
if (extractedBinaryPath !== finalBinaryPath) {
|
|
115
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
116
|
+
fs.unlinkSync(finalBinaryPath);
|
|
117
|
+
}
|
|
118
|
+
fs.renameSync(extractedBinaryPath, finalBinaryPath);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!fs.existsSync(finalBinaryPath)) {
|
|
122
|
+
throw new Error(`Expected binary not found: ${finalBinaryPath}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fs.chmodSync(finalBinaryPath, 0o755);
|
|
126
|
+
|
|
127
|
+
fs.unlinkSync(path.join(__dirname, FILE_NAME));
|
|
86
128
|
}
|
|
87
129
|
|
|
88
130
|
async function binary() {
|
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
const { binary } = require("./binary");
|
|
2
2
|
const { runMidnightNode } = require("./run_midnight_node");
|
|
3
|
-
const { getPlatform } = require("./binary");
|
|
4
3
|
const fs = require("fs");
|
|
5
4
|
const path = require("path");
|
|
6
5
|
|
|
6
|
+
const FINAL_BINARY_NAME = "midnight-node";
|
|
7
|
+
|
|
7
8
|
function checkIfBinaryExists() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return fs.existsSync(path.join(__dirname, "midnight-node", binaryName));
|
|
9
|
+
return fs.existsSync(
|
|
10
|
+
path.join(__dirname, "midnight-node", FINAL_BINARY_NAME),
|
|
11
|
+
);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
async function main(args) {
|
package/package.json
CHANGED
package/run_midnight_node.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { spawn } = require("child_process");
|
|
2
2
|
const path = require("path");
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
const BINARY_NAME = "midnight-node";
|
|
4
5
|
/**
|
|
5
6
|
* Executes the midnight-node binary as a child process
|
|
6
7
|
* @param {Object} env - Environment variables to pass to the child process
|
|
@@ -8,10 +9,7 @@ const { getPlatform } = require("./binary");
|
|
|
8
9
|
* @returns {ChildProcess} The spawned child process
|
|
9
10
|
*/
|
|
10
11
|
function runMidnightNode(env = process.env, args = []) {
|
|
11
|
-
const
|
|
12
|
-
const parts = platform.split("-");
|
|
13
|
-
const binaryName = `midnight-node-${platform}`;
|
|
14
|
-
const binaryPath = path.join(__dirname, "midnight-node", binaryName);
|
|
12
|
+
const binaryPath = path.join(__dirname, "midnight-node", BINARY_NAME);
|
|
15
13
|
|
|
16
14
|
console.log(
|
|
17
15
|
`Starting midnight-node binary at: ${binaryPath} ${args.join(" ")}`,
|