@paimaexample/npm-midnight-node 0.3.20 → 0.3.22

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 CHANGED
@@ -24,6 +24,8 @@ function getBinaryUrl() {
24
24
  async function downloadAndSaveBinary() {
25
25
  const url = getBinaryUrl();
26
26
  try {
27
+ console.error(`Downloading... ${url}`);
28
+
27
29
  const response = await axios.get(url, { responseType: "stream" });
28
30
  const writer = fs.createWriteStream(
29
31
  path.join(__dirname, "midnight-node.zip"),
@@ -45,6 +47,17 @@ async function unzipBinary() {
45
47
  await extract(path.join(__dirname, "midnight-node.zip"), {
46
48
  dir: path.join(__dirname, "midnight-node"),
47
49
  });
50
+ const platform = getPlatform();
51
+ const parts = platform.split("-");
52
+ const binaryName = (parts[0] === "linux" && parts[1] === "amd64")
53
+ ? `midnight-node-${platform}`
54
+ : "midnight-node";
55
+ if (parts[0] === "linux") {
56
+ fs.chmodSync(
57
+ path.join(__dirname, "midnight-node", binaryName),
58
+ 0o755,
59
+ );
60
+ }
48
61
  fs.unlinkSync(path.join(__dirname, "midnight-node.zip"));
49
62
  }
50
63
 
@@ -55,4 +68,5 @@ async function binary() {
55
68
 
56
69
  module.exports = {
57
70
  binary,
71
+ getPlatform,
58
72
  };
package/index.js CHANGED
@@ -1,13 +1,18 @@
1
1
  const { binary } = require("./binary");
2
2
  const { runMidnightNode } = require("./run_midnight_node");
3
+ const { getPlatform } = require("./binary");
3
4
  const fs = require("fs");
4
5
  const path = require("path");
5
6
 
6
7
  function checkIfBinaryExists() {
7
- return fs.existsSync(path.join(__dirname, "midnight-node", "midnight-node"));
8
+ const platform = getPlatform();
9
+ const parts = platform.split("-");
10
+ const binaryName = (parts[0] === "linux" && parts[1] === "amd64")
11
+ ? `midnight-node-${platform}`
12
+ : "midnight-node";
13
+ return fs.existsSync(path.join(__dirname, "midnight-node", binaryName));
8
14
  }
9
15
 
10
-
11
16
  async function main(args) {
12
17
  if (!checkIfBinaryExists()) {
13
18
  await binary();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paimaexample/npm-midnight-node",
3
- "version": "0.3.20",
3
+ "version": "0.3.22",
4
4
  "description": "Downloads and starts the binary for Midnight Node",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
- const { spawn } = require('child_process');
2
- const path = require('path');
3
-
1
+ const { spawn } = require("child_process");
2
+ const path = require("path");
3
+ const { getPlatform } = require("./binary");
4
4
  /**
5
5
  * Executes the midnight-node binary as a child process
6
6
  * @param {Object} env - Environment variables to pass to the child process
@@ -8,33 +8,40 @@ const path = require('path');
8
8
  * @returns {ChildProcess} The spawned child process
9
9
  */
10
10
  function runMidnightNode(env = process.env, args = []) {
11
- const binaryPath = path.join(__dirname, 'midnight-node', 'midnight-node');
12
-
13
- console.log(`Starting midnight-node binary at: ${binaryPath}`);
14
-
15
- const childProcess = spawn(binaryPath, args, {
16
- env: env,
17
- stdio: 'inherit', // Inherit stdin, stdout, stderr from parent process
18
- cwd: path.join(__dirname, 'midnight-node') // Run from inside the midnight-node directory
19
- });
20
-
21
- childProcess.on('spawn', () => {
22
- console.log(`midnight-node process spawned with PID: ${childProcess.pid}`);
23
- });
24
-
25
- childProcess.on('error', (error) => {
26
- console.error('Failed to start midnight-node:', error);
27
- });
28
-
29
- childProcess.on('exit', (code, signal) => {
30
- if (code !== null) {
31
- console.log(`midnight-node process exited with code: ${code}`);
32
- } else {
33
- console.log(`midnight-node process terminated by signal: ${signal}`);
34
- }
35
- });
36
-
37
- return childProcess;
11
+ const platform = getPlatform();
12
+ const parts = platform.split("-");
13
+ const binaryName = (parts[0] === "linux" && parts[1] === "amd64")
14
+ ? `midnight-node-${platform}`
15
+ : "midnight-node";
16
+ const binaryPath = path.join(__dirname, "midnight-node", binaryName);
17
+
18
+ console.log(
19
+ `Starting midnight-node binary at: ${binaryPath} ${args.join(" ")}`,
20
+ );
21
+
22
+ const childProcess = spawn(binaryPath, args, {
23
+ env: env,
24
+ stdio: "inherit", // Inherit stdin, stdout, stderr from parent process
25
+ cwd: path.join(__dirname, "midnight-node"), // Run from inside the midnight-node directory
26
+ });
27
+
28
+ childProcess.on("spawn", () => {
29
+ console.log(`midnight-node process spawned with PID: ${childProcess.pid}`);
30
+ });
31
+
32
+ childProcess.on("error", (error) => {
33
+ console.error("Failed to start midnight-node:", error);
34
+ });
35
+
36
+ childProcess.on("exit", (code, signal) => {
37
+ if (code !== null) {
38
+ console.log(`midnight-node process exited with code: ${code}`);
39
+ } else {
40
+ console.log(`midnight-node process terminated by signal: ${signal}`);
41
+ }
42
+ });
43
+
44
+ return childProcess;
38
45
  }
39
46
 
40
47
  module.exports = { runMidnightNode };