@peerbit/server 5.4.0 → 5.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/server",
3
- "version": "5.4.0",
3
+ "version": "5.4.1",
4
4
  "author": "dao.xyz",
5
5
  "repository": {
6
6
  "type": "git",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@peerbit/test-lib": "^0.0.1",
70
- "@peerbit/test-utils": "2.1.45",
70
+ "@peerbit/test-utils": "2.1.46",
71
71
  "@types/yargs": "17.0.24",
72
72
  "aws-sdk": "^2.1259.0",
73
73
  "dotenv": "^16.1.4",
@@ -78,7 +78,7 @@
78
78
  "dependencies": {
79
79
  "axios": "^1.4.0",
80
80
  "chalk": "^5.3.0",
81
- "peerbit": "4.1.35",
81
+ "peerbit": "4.1.36",
82
82
  "yargs": "^17.7.2",
83
83
  "tar-stream": "^3.1.7",
84
84
  "tmp": "^0.2.1",
package/src/server.ts CHANGED
@@ -9,8 +9,7 @@ import {
9
9
  getProgramFromVariants,
10
10
  } from "@peerbit/program";
11
11
  import { waitFor } from "@peerbit/time";
12
- import { execSync, spawn } from "child_process";
13
- import { spawnSync } from "child_process";
12
+ import { execSync, spawn, spawnSync } from "child_process";
14
13
  import { setMaxListeners } from "events";
15
14
  import fs from "fs";
16
15
  import http from "http";
@@ -52,9 +51,6 @@ import type {
52
51
 
53
52
  const MAX_LISTENER_LIMIT = 1e5;
54
53
 
55
- // eslint-disable-next-line @typescript-eslint/naming-convention
56
- const __dirname = dirname(fileURLToPath(import.meta.url));
57
-
58
54
  const getInstallDir = (): string | null => {
59
55
  return (
60
56
  process.env.PEERBIT_MODULES_PATH ||
@@ -62,6 +58,24 @@ const getInstallDir = (): string | null => {
62
58
  null
63
59
  );
64
60
  };
61
+
62
+ // eslint-disable-next-line @typescript-eslint/naming-convention
63
+ const __dirname = dirname(fileURLToPath(import.meta.url));
64
+
65
+ const extraNodePath = () => {
66
+ const installDir = getInstallDir();
67
+ return installDir ? path.join(installDir, "node_modules") : undefined;
68
+ };
69
+ const extra = extraNodePath();
70
+ if (extra) {
71
+ process.env.NODE_PATH = process.env.NODE_PATH
72
+ ? process.env.NODE_PATH + path.delimiter + extra
73
+ : extra;
74
+
75
+ // always re-parse NODE_PATH for *this* process
76
+ ((await import("module")).default as any)["_initPaths"]();
77
+ }
78
+
65
79
  // add next to execSync
66
80
 
67
81
  const listVersions = (dir: string): Record<string, string> => {
@@ -260,24 +274,36 @@ export const startApiServer = async (
260
274
  const port = properties?.port ?? LOCAL_API_PORT;
261
275
 
262
276
  const restart = async () => {
263
- await client.stop();
264
- await stopAndWait(server);
265
-
266
- // We filter out the reset command, since restarting means that we want to resume something
267
- spawn(
268
- process.argv.shift()!,
269
- [
270
- ...process.execArgv,
271
- ...process.argv.filter((x) => x !== "--reset" && x !== "-r"),
272
- ],
273
- {
274
- cwd: process.cwd(),
275
- detached: true,
276
- stdio: "inherit",
277
- gid: process.getgid!(),
278
- },
277
+ console.log(
278
+ "Process will be lost during restart. Please find it using a process monitor. Or find it from the port e.g. 'lsof -i tcp:8001'",
279
279
  );
280
- process.exit(0);
280
+ process.nextTick(async () => {
281
+ await client.stop();
282
+ await stopAndWait(server);
283
+
284
+ // We filter out the reset command, since restarting means that we want to resume something
285
+ spawn(
286
+ process.argv.shift()!,
287
+ [
288
+ ...process.execArgv,
289
+ ...process.argv.filter((x) => x !== "--reset" && x !== "-r"),
290
+ ],
291
+ {
292
+ cwd: process.cwd(),
293
+ detached: true,
294
+ stdio: "inherit",
295
+ gid: process.getgid!(),
296
+ env: {
297
+ ...process.env,
298
+ NODE_PATH:
299
+ (process.env.NODE_PATH
300
+ ? process.env.NODE_PATH + path.delimiter
301
+ : "") + (extraNodePath() ?? ""),
302
+ },
303
+ },
304
+ );
305
+ process.exit(0);
306
+ });
281
307
  };
282
308
  if (!client.peerId.equals(await client.identity.publicKey.toPeerId())) {
283
309
  throw new Error("Expecting node identity to equal peerId");