socket-function 0.146.0 → 0.148.0

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": "socket-function",
3
- "version": "0.146.0",
3
+ "version": "0.148.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -419,8 +419,12 @@ async function compressCached(bufferKey: string, buffer: () => Buffer): Promise<
419
419
  }
420
420
 
421
421
  export function getIsAllowClient(module: NodeJS.Module) {
422
+ if (module.serveronly) return false;
422
423
  // IMPORTANT! We do not allow everything in node modules by default, as most things in node modules, you don't want to import client-side, and it will break if you import it client-side. Many of these are imported, but will never end up being called client-side, so it's fine to exclude them.
423
- return module.allowclient && !module.serveronly;
424
+ if (allowAllNodeModulesFlag && module.filename.includes("node_modules")) {
425
+ return true;
426
+ }
427
+ return module.allowclient;
424
428
  }
425
429
 
426
430
  type ClientRemapCallback = (args: GetModulesArgs) => Promise<GetModulesArgs>;
@@ -441,6 +445,11 @@ export function setRequireBootRequire(dir: string) {
441
445
  baseController.rootResolvePath = dir;
442
446
  }
443
447
 
448
+ let allowAllNodeModulesFlag = false;
449
+ export function allowAllNodeModules() {
450
+ allowAllNodeModulesFlag = true;
451
+ }
452
+
444
453
  export const RequireController = SocketFunction.register(
445
454
  "RequireController-e2f811f3-14b8-4759-b0d6-73f14516cf1d",
446
455
  baseController,
@@ -457,6 +466,7 @@ export const RequireController = SocketFunction.register(
457
466
  injectHTMLBeforeStartup,
458
467
  addMapGetModules,
459
468
  addStaticRoot,
469
+ allowAllNodeModules,
460
470
  }
461
471
  }
462
472
  );
@@ -2,7 +2,6 @@ import https from "https";
2
2
  import http from "http";
3
3
  import net from "net";
4
4
  import tls from "tls";
5
- import * as ws from "ws";
6
5
  import { getNodeIdsFromRequest, httpCallHandler } from "./callHTTPHandler";
7
6
  import { SocketFunction } from "../SocketFunction";
8
7
  import { getTrustedCertificates, watchTrustedCertificates } from "./certStore";
@@ -60,6 +59,7 @@ export type SocketServerConfig = (
60
59
  export async function startSocketServer(
61
60
  config: SocketServerConfig
62
61
  ): Promise<string> {
62
+ const ws = await import("ws");
63
63
 
64
64
  const webSocketServer = new ws.Server({
65
65
  noServer: true,
@@ -1,4 +1,3 @@
1
- import ws from "ws";
2
1
  import tls from "tls";
3
2
  import { isNode } from "./misc";
4
3
  import { SenderInterface } from "./CallFactory";
@@ -6,6 +5,7 @@ import { getTrustedCertificates } from "./certStore";
6
5
  import { getNodeIdLocation } from "./nodeCache";
7
6
  import debugbreak from "debugbreak";
8
7
  import { SocketFunction } from "../SocketFunction";
8
+ import type * as ws from "ws";
9
9
 
10
10
  export function getTLSSocket(webSocket: ws.WebSocket) {
11
11
  return (webSocket as any)._socket as tls.TLSSocket;
@@ -36,6 +36,7 @@ export function createWebsocketFactory(): (nodeId: string) => SenderInterface {
36
36
  if (!SocketFunction.silent) {
37
37
  console.log(`Connecting to ${address}:${port}`);
38
38
  }
39
+ const ws = require("ws") as typeof import("ws");
39
40
  let webSocket = new ws.WebSocket(`wss://${address}:${port}`, undefined, {
40
41
  ca: getTrustedCertificates(),
41
42
  });